1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /* vim:set et sw=2 ts=2: */ 17 18 #include <string> 19 #include <sstream> 20 #include <zorba/config.h> 21 #include <zorba/properties_base.h> 22 #include <cstring> 23 24 #ifndef ZORBA_ZORBAPROPERTIES 25 #define ZORBA_ZORBAPROPERTIES 26 namespace zorba 27 { 28 29 class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesGlobal 30 { 31 protected: get_all_options()32 const char** get_all_options() const 33 { 34 static const char* result [] = { 35 "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer", 36 "--result-file", "--debug-file", "--abort", "--query", "--print-query", 37 "--print-time", "--print-ast", "--print-xqdoc", "--print-translated", 38 "--print-normalized", "--print-optimized", "--print-iterator-tree", 39 "--print-item-flow", "--print-static-types", "--dump-lib", 40 "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt", 41 "--print-locations", "--force-gflwor", "--reorder-globals", 42 "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting", 43 "--infer-joins", "--no-copy-optim", "--serialize-only-query", 44 "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug", 45 "--compile-only", "--tz", "--external-var", "--serializer-param", 46 "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth", 47 "--CLASSPATH", NULL }; 48 49 return result; 50 } 51 52 bool theTraceParsing; 53 bool theTraceScanning; 54 bool theUseSerializer; 55 int theOptimizer; 56 std::string theResultFile; 57 std::string theDebugFile; 58 bool theAbort; 59 std::string theQuery; 60 bool thePrintQuery; 61 bool thePrintTime; 62 bool thePrintAst; 63 bool thePrintXqdoc; 64 bool thePrintTranslated; 65 bool thePrintNormalized; 66 bool thePrintOptimized; 67 bool thePrintIteratorTree; 68 bool thePrintItemFlow; 69 bool thePrintStaticTypes; 70 bool theDumpLib; 71 bool theStableIteratorIds; 72 bool theNoTreeIds; 73 bool thePrintIntermediateOpt; 74 bool thePrintLocations; 75 bool theForceGflwor; 76 bool theReorderGlobals; 77 bool theSpecializeNum; 78 bool theSpecializeCmp; 79 bool theInlineUdf; 80 bool theLoopHoisting; 81 bool theInferJoins; 82 bool theNoCopyOptim; 83 int theSerializeOnlyQuery; 84 bool theTraceTranslator; 85 bool theTraceCodegen; 86 bool theTraceFulltext; 87 bool theDebug; 88 bool theCompileOnly; 89 int theTz; 90 std::vector<std::string> theExternalVar; 91 std::vector<std::string> theSerializerParam; 92 bool theIterPlanTest; 93 std::string theDotPlanFile; 94 uint32_t theMaxUdfCallDepth; 95 std::string theCLASSPATH; 96 initialize()97 void initialize() 98 { 99 theTraceParsing = false; 100 theTraceScanning = false; 101 theUseSerializer = false; 102 theOptimizer = 1; 103 theAbort = false; 104 thePrintQuery = false; 105 thePrintTime = false; 106 thePrintAst = false; 107 thePrintXqdoc = false; 108 thePrintTranslated = false; 109 thePrintNormalized = false; 110 thePrintOptimized = false; 111 thePrintIteratorTree = false; 112 thePrintItemFlow = false; 113 thePrintStaticTypes = true; 114 theDumpLib = false; 115 theStableIteratorIds = false; 116 theNoTreeIds = false; 117 thePrintIntermediateOpt = false; 118 thePrintLocations = false; 119 theForceGflwor = false; 120 theReorderGlobals = true; 121 theSpecializeNum = true; 122 theSpecializeCmp = true; 123 theInlineUdf = true; 124 theLoopHoisting = true; 125 theInferJoins = true; 126 theNoCopyOptim = true; 127 theSerializeOnlyQuery = -1; 128 theTraceTranslator = false; 129 theTraceCodegen = false; 130 theTraceFulltext = false; 131 theDebug = false; 132 theCompileOnly = false; 133 theIterPlanTest = false; 134 theMaxUdfCallDepth = 1024; 135 } 136 137 public: traceParsing()138 const bool &traceParsing () const { return theTraceParsing; } traceScanning()139 const bool &traceScanning () const { return theTraceScanning; } useSerializer()140 const bool &useSerializer () const { return theUseSerializer; } optimizer()141 const int &optimizer () const { return theOptimizer; } resultFile()142 const std::string &resultFile () const { return theResultFile; } debugFile()143 const std::string &debugFile () const { return theDebugFile; } abort()144 const bool &abort () const { return theAbort; } query()145 const std::string &query () const { return theQuery; } printQuery()146 const bool &printQuery () const { return thePrintQuery; } printTime()147 const bool &printTime () const { return thePrintTime; } printAst()148 const bool &printAst () const { return thePrintAst; } printXqdoc()149 const bool &printXqdoc () const { return thePrintXqdoc; } printTranslated()150 const bool &printTranslated () const { return thePrintTranslated; } printNormalized()151 const bool &printNormalized () const { return thePrintNormalized; } printOptimized()152 const bool &printOptimized () const { return thePrintOptimized; } printIteratorTree()153 const bool &printIteratorTree () const { return thePrintIteratorTree; } printItemFlow()154 const bool &printItemFlow () const { return thePrintItemFlow; } printStaticTypes()155 const bool &printStaticTypes () const { return thePrintStaticTypes; } dumpLib()156 const bool &dumpLib () const { return theDumpLib; } stableIteratorIds()157 const bool &stableIteratorIds () const { return theStableIteratorIds; } noTreeIds()158 const bool &noTreeIds () const { return theNoTreeIds; } printIntermediateOpt()159 const bool &printIntermediateOpt () const { return thePrintIntermediateOpt; } printLocations()160 const bool &printLocations () const { return thePrintLocations; } forceGflwor()161 const bool &forceGflwor () const { return theForceGflwor; } reorderGlobals()162 const bool &reorderGlobals () const { return theReorderGlobals; } specializeNum()163 const bool &specializeNum () const { return theSpecializeNum; } specializeCmp()164 const bool &specializeCmp () const { return theSpecializeCmp; } inlineUdf()165 const bool &inlineUdf () const { return theInlineUdf; } loopHoisting()166 const bool &loopHoisting () const { return theLoopHoisting; } inferJoins()167 const bool &inferJoins () const { return theInferJoins; } noCopyOptim()168 const bool &noCopyOptim() const { return theNoCopyOptim; } serializeOnlyQuery()169 const int& serializeOnlyQuery() const { return theSerializeOnlyQuery; } traceTranslator()170 const bool &traceTranslator () const { return theTraceTranslator; } traceCodegen()171 const bool &traceCodegen () const { return theTraceCodegen; } traceFulltext()172 const bool &traceFulltext () const { return theTraceFulltext; } debug()173 const bool &debug () const { return theDebug; } compileOnly()174 const bool &compileOnly () const { return theCompileOnly; } tz()175 const int &tz () const { return theTz; } externalVar()176 const std::vector<std::string> &externalVar () const { return theExternalVar; } serializerParam()177 const std::vector<std::string> &serializerParam () const { return theSerializerParam; } iterPlanTest()178 const bool &iterPlanTest () const { return theIterPlanTest; } dotPlanFile()179 const std::string &dotPlanFile () const { return theDotPlanFile; } maxUdfCallDepth()180 const uint32_t &maxUdfCallDepth () const { return theMaxUdfCallDepth; } CLASSPATH()181 const std::string &CLASSPATH () const { return theCLASSPATH; } 182 load_argv(int argc,const char ** argv)183 std::string load_argv (int argc, const char **argv) 184 { 185 if (argv == NULL) return ""; 186 187 std::string result; 188 for (++argv; *argv != NULL; ++argv) { 189 if (strcmp (*argv, "--help") == 0 || strcmp (*argv, "-h") == 0) 190 return "!HELP"; 191 else if (strcmp (*argv, "--version") == 0) 192 return "!VER"; 193 else if (strcmp (*argv, "--trace-parsing") == 0 || strncmp (*argv, "-p", 2) == 0) { 194 theTraceParsing = true; 195 } 196 else if (strcmp (*argv, "--trace-scanning") == 0 || strncmp (*argv, "-s", 2) == 0) { 197 theTraceScanning = true; 198 } 199 else if (strcmp (*argv, "--use-serializer") == 0 || strncmp (*argv, "-r", 2) == 0) { 200 theUseSerializer = true; 201 } 202 else if (strcmp (*argv, "--optimizer") == 0 || strncmp (*argv, "-O", 2) == 0) { 203 int d = 2; 204 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 205 if (*argv == NULL) { result = "No value given for --optimizer option"; break; } 206 init_val (*argv, theOptimizer, d); 207 } 208 else if (strcmp (*argv, "--result-file") == 0 || strncmp (*argv, "-o", 2) == 0) { 209 int d = 2; 210 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 211 if (*argv == NULL) { result = "No value given for --result-file option"; break; } 212 init_val (*argv, theResultFile, d); 213 } 214 else if (strcmp (*argv, "--debug-file") == 0) { 215 int d = 2; 216 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 217 if (*argv == NULL) { result = "No value given for --debug-file option"; break; } 218 219 init_val (*argv, theDebugFile, d); 220 } 221 else if (strcmp (*argv, "--abort") == 0) { 222 theAbort = true; 223 } 224 else if (strcmp (*argv, "--query") == 0 || strncmp (*argv, "-e", 2) == 0) { 225 int d = 2; 226 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 227 if (*argv == NULL) { result = "No value given for --query option"; break; } 228 229 init_val (*argv, theQuery, d); 230 } 231 else if (strcmp (*argv, "--print-query") == 0 || strncmp (*argv, "-q", 2) == 0) { 232 thePrintQuery = true; 233 } 234 else if (strcmp (*argv, "--print-time") == 0 || strncmp (*argv, "-t", 2) == 0) { 235 thePrintTime = true; 236 } 237 else if (strcmp (*argv, "--print-ast") == 0 || strncmp (*argv, "-a", 2) == 0) { 238 thePrintAst = true; 239 } 240 else if (strcmp (*argv, "--print-xqdoc") == 0) { 241 thePrintXqdoc = true; 242 } 243 else if (strcmp (*argv, "--print-translated") == 0) { 244 thePrintTranslated = true; 245 } 246 else if (strcmp (*argv, "--print-normalized") == 0 || strncmp (*argv, "-n", 2) == 0) { 247 thePrintNormalized = true; 248 } 249 else if (strcmp (*argv, "--print-optimized") == 0 || strncmp (*argv, "-P", 2) == 0) { 250 thePrintOptimized = true; 251 } 252 else if (strcmp (*argv, "--print-iterator-tree") == 0 || strncmp (*argv, "-i", 2) == 0) { 253 thePrintIteratorTree = true; 254 } 255 else if (strcmp (*argv, "--print-item-flow") == 0 || strncmp (*argv, "-f", 2) == 0) { 256 thePrintItemFlow = true; 257 } 258 else if (strcmp (*argv, "--print-static-types") == 0) { 259 int d = 2; 260 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 261 if (*argv == NULL) { result = "No value given for --print-static-types option"; break; } 262 263 init_val (*argv, thePrintStaticTypes, d); 264 } 265 else if (strcmp (*argv, "--dump-lib") == 0) { 266 theDumpLib = true; 267 } 268 else if (strcmp (*argv, "--stable-iterator-ids") == 0) { 269 theStableIteratorIds = true; 270 } 271 else if (strcmp (*argv, "--no-tree-ids") == 0) { 272 theNoTreeIds = true; 273 } 274 else if (strcmp (*argv, "--print-intermediate-opt") == 0) { 275 thePrintIntermediateOpt = true; 276 } 277 else if (strcmp (*argv, "--print-locations") == 0) { 278 thePrintLocations = true; 279 } 280 else if (strcmp (*argv, "--force-gflwor") == 0) { 281 theForceGflwor = true; 282 } 283 else if (strcmp (*argv, "--reorder-globals") == 0) { 284 int d = 2; 285 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 286 if (*argv == NULL) { result = "No value given for --reorder-globals option"; break; } 287 288 init_val (*argv, theReorderGlobals, d); 289 } 290 else if (strcmp (*argv, "--specialize-num") == 0) { 291 int d = 2; 292 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 293 if (*argv == NULL) { result = "No value given for --specialize-num option"; break; } 294 295 init_val (*argv, theSpecializeNum, d); 296 } 297 else if (strcmp (*argv, "--specialize-cmp") == 0) { 298 int d = 2; 299 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 300 if (*argv == NULL) { result = "No value given for --specialize-cmp option"; break; } 301 302 init_val (*argv, theSpecializeCmp, d); 303 } 304 else if (strcmp (*argv, "--inline-udf") == 0) { 305 int d = 2; 306 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 307 if (*argv == NULL) { result = "No value given for --inline-udf option"; break; } 308 309 init_val (*argv, theInlineUdf, d); 310 } 311 else if (strcmp (*argv, "--loop-hoisting") == 0) { 312 int d = 2; 313 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 314 if (*argv == NULL) { result = "No value given for --loop-hoisting option"; break; } 315 316 init_val (*argv, theLoopHoisting, d); 317 } 318 else if (strcmp (*argv, "--infer-joins") == 0) { 319 int d = 2; 320 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 321 if (*argv == NULL) { result = "No value given for --infer-joins option"; break; } 322 323 init_val (*argv, theInferJoins, d); 324 } 325 else if (strcmp (*argv, "--no-copy-optim") == 0) 326 { 327 int d = 2; 328 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 329 if (*argv == NULL) { result = "No value given for --no-copy-optim option"; break; } 330 init_val (*argv, theNoCopyOptim, d); 331 } 332 else if (strcmp (*argv, "--serialize-only-query") == 0) 333 { 334 int d = 2; 335 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 336 if (*argv == NULL) 337 { result = "No value given for --serialize-only-query option"; break; } 338 init_val(*argv, theSerializeOnlyQuery, d); 339 } 340 #ifndef NDEBUG 341 else if (strcmp (*argv, "--trace-translator") == 0 || strncmp (*argv, "-l", 2) == 0) { 342 theTraceTranslator = true; 343 } 344 else if (strcmp (*argv, "--trace-codegen") == 0 || strncmp (*argv, "-c", 2) == 0) { 345 theTraceCodegen = true; 346 } 347 else if (strcmp (*argv, "--trace-fulltext") == 0) { 348 theTraceFulltext = true; 349 } 350 #endif 351 else if (strcmp (*argv, "--debug") == 0) { 352 theDebug = true; 353 } 354 else if (strcmp (*argv, "--compile-only") == 0) { 355 theCompileOnly = true; 356 } 357 else if (strcmp (*argv, "--tz") == 0) { 358 int d = 2; 359 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 360 if (*argv == NULL) { result = "No value given for --tz option"; break; } 361 362 init_val (*argv, theTz, d); 363 } 364 else if (strcmp (*argv, "--external-var") == 0 || strncmp (*argv, "-x", 2) == 0) { 365 int d = 2; 366 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 367 if (*argv == NULL) { result = "No value given for --external-var option"; break; } 368 369 init_val (*argv, theExternalVar, d); 370 } 371 else if (strcmp (*argv, "--serializer-param") == 0 || strncmp (*argv, "-z", 2) == 0) { 372 int d = 2; 373 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 374 if (*argv == NULL) { result = "No value given for --serializer-param option"; break; } 375 376 init_val (*argv, theSerializerParam, d); 377 } 378 else if (strcmp (*argv, "--iter-plan-test") == 0) { 379 theIterPlanTest = true; 380 } 381 else if (strcmp (*argv, "--dot-plan-file") == 0) { 382 int d = 2; 383 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 384 if (*argv == NULL) { result = "No value given for --dot-plan-file option"; break; } 385 386 init_val (*argv, theDotPlanFile, d); 387 } 388 else if (strcmp (*argv, "--max-udf-call-depth") == 0) { 389 int d = 2; 390 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 391 if (*argv == NULL) { result = "No value given for --max-udf-call-depth option"; break; } 392 393 init_val (*argv, theMaxUdfCallDepth, d); 394 } 395 else if (strcmp (*argv, "--CLASSPATH") == 0) { 396 int d = 2; 397 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; } 398 if (*argv == NULL) { result = "No value given for --CLASSPATH option"; break; } 399 400 init_val (*argv, theCLASSPATH, d); 401 } 402 else if (strcmp (*argv, "--") == 0) { 403 copy_args (++argv); 404 break; 405 } else if ((*argv) [0] == '-') { 406 result = "unknown command line option "; result += *argv; break; 407 } else { 408 copy_args (argv); 409 break; 410 } 411 } 412 413 return result; 414 } 415 416 get_help_msg()417 const char* get_help_msg() const 418 { 419 return 420 "--trace-parsing, -p\ntrace parsing\n\n" 421 "--trace-scanning, -s\ntrace scanning\n\n" 422 "--use-serializer, -r\nuse serializer\n\n" 423 "--optimizer, -O\noptimization level (0, 1 or 2 - 1 is default)\n\n" 424 "--result-file, -o\nresult file\n\n" 425 "--debug-file\nlog file for debugging information\n\n" 426 "--abort\nabort when fatal error happens\n\n" 427 "--query, -e\nexecute inline query\n\n" 428 "--print-query, -q\nprint the query\n\n" 429 "--print-time, -t\nprint the execution time\n\n" 430 "--print-ast, -a\nprint the parse tree\n\n" 431 "--print-xqdoc\ncreate output for XQDoc\n\n" 432 "--print-translated\nprint the normalized expression tree\n\n" 433 "--print-normalized, -n\nprint the translated expression tree\n\n" 434 "--print-optimized, -P\nprint the optimized expression tree\n\n" 435 "--print-iterator-tree, -i\nprint the iterator tree\n\n" 436 "--print-item-flow, -f\nshow items produced by all iterators\n\n" 437 "--print-static-types\nprint static type inference\n\n" 438 "--dump-lib\ndump function library\n\n" 439 "--stable-iterator-ids\nprint the iterator plan with stable ids\n\n" 440 "--no-tree-ids\nsuppress ids and locations from compiler tree dumps\n\n" 441 "--print-intermediate-opt\nprint intermediate optimizations\n\n" 442 "--print-locations\nprint parser locations for compiler expressions\n\n" 443 "--force-gflwor\nforce compiler to generate GFLWOR iterators\n\n" 444 "--reorder-globals\nreorder global variables (1=enabled (default), 0=off)\n\n" 445 "--specialize-num\nspecialize numerics (1=enabled (default), 0=off)\n\n" 446 "--specialize-cmp\nspecialize generic comparisons (1=enabled (default), 0=off)\n\n" 447 "--inline-udf\ninline functions (1=enabled (default), 0=off)\n\n" 448 "--loop-hoisting\nhoist expressions out of loops (1=enabled (default), 0=off)\n\n" 449 "--infer-joins\ninfer joins (1=enabled (default), 0=off)\n\n" 450 "--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n" 451 "--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n" 452 #ifndef NDEBUG 453 "--trace-translator, -l\ntrace the translator\n\n" 454 "--trace-codegen, -c\ntrace the codegenerator\n\n" 455 "--trace-fulltext\ntrace full-text evaluation\n\n" 456 #endif 457 "--debug\ncompile the query in debug mode\n\n" 458 "--compile-only\nonly compile (don't execute)\n\n" 459 "--tz\nimplicit time zone (in minutes)\n\n" 460 "--external-var, -x\nexternal variables (e.g. -x x=file1.xml -x y:=strValue)\n\n" 461 "--serializer-param, -z\nserializer parameters (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g. -z method=xhtml, -z doctype-system='DTD/xhtml1-strict.dtd', -z indent=yes)\n\n" 462 "--iter-plan-test\nrun as iterator plan test\n\n" 463 "--dot-plan-file\ngenerate the dot iterator plan\n\n" 464 "--max-udf-call-depth\nmaximum stack depth of udf function calls\n\n" 465 "--CLASSPATH\nJVM classpath to be used by modules using Java implementations\n\n" 466 ; 467 } 468 instance()469 static const ZorbaProperties* instance() 470 { 471 static ZorbaProperties result; 472 return &result; 473 } 474 ZorbaProperties()475 ZorbaProperties() { initialize (); } 476 }; 477 478 479 } // namespaces 480 481 #endif // ZORBA_ZORBAPROPERTIES 482