oql_p.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #include <eyedbconfig.h>
00026 #include <eyedblib/machtypes.h>
00027 #include <eyedb/eyedb.h>
00028 #include <eyedb/eyedb_p.h>
00029 #include <string>
00030 #include <time.h>
00031 
00032 #include <sys/types.h>
00033 #include <list>
00034 #include <regex.h>
00035 
00036 // POINTER_INT_TYPE is defined by eyedbconfig.h
00037 typedef POINTER_INT_TYPE pointer_int_t;
00038 
00039 #define OQML_MAX_CPS 6
00040 
00041 namespace eyedb {
00042 
00043   enum oqmlTYPE {
00044 
00045     __oqml__first__ = 0,
00046 
00047     /* atoms */
00048     oqmlTRUE,
00049     oqmlFALSE,
00050     oqmlCHAR,
00051     oqmlINT,
00052     oqmlFLOAT,
00053     oqmlIDENT,
00054     oqmlNULL,
00055     oqmlOID,
00056     oqmlOBJECT,
00057     oqmlSTRING,
00058     oqmlNIL,
00059 
00060     /* standard operators */
00061     oqmlAAND,
00062     oqmlADD,
00063     oqmlAOR,
00064     oqmlARRAY,
00065     oqmlASSIGN,
00066     oqmlCOMMA,
00067     oqmlDIFF,
00068     oqmlDIV,
00069     oqmlINF,
00070     oqmlINFEQ,
00071     oqmlLAND,
00072     oqmlLNOT,
00073     oqmlLOR,
00074     oqmlMOD,
00075     oqmlMUL,
00076     oqmlREGCMP,
00077     oqmlREGDIFF,
00078     oqmlREGICMP,
00079     oqmlREGIDIFF,
00080     oqmlSHL,
00081     oqmlSHR,
00082     oqmlSUB,
00083     oqmlSUP,
00084     oqmlSUPEQ,
00085     oqmlTILDE,
00086     oqmlEQUAL,
00087     oqmlBETWEEN,
00088     oqmlNOTBETWEEN,
00089     oqmlRANGE,
00090     oqmlDOT,
00091     oqmlXOR,
00092 
00093     /* extended operators */
00094     oqmlISSET,
00095     oqmlSET,
00096     oqmlUNSET,
00097     oqmlTYPEOF,
00098     oqmlCLASSOF,
00099     oqmlEVAL,
00100     oqmlTHROW,
00101     oqmlUNVAL,
00102     oqmlREFOF,
00103     oqmlVALOF,
00104     oqmlIMPORT,
00105     oqmlRETURN,
00106 
00107     oqmlPRINT,
00108 
00109     /* set operators */
00110     oqmlUNION,
00111     oqmlINTERSECT,
00112     oqmlEXCEPT,
00113 
00114     /* cast operators */
00115     oqmlSTRINGOP,
00116     oqmlINTOP,
00117     oqmlCHAROP,
00118     oqmlFLOATOP,
00119     oqmlOIDOP,
00120     oqmlIDENTOP,
00121 
00122     /* literal */
00123     oqmlSTRUCT,
00124 
00125     /* list management */
00126     oqmlLISTCOLL,
00127     oqmlBAGCOLL,
00128     oqmlARRAYCOLL,
00129     oqmlSETCOLL,
00130 
00131     oqmlCOUNT,
00132     oqmlFLATTEN,
00133 
00134     oqmlBODYOF,
00135     oqmlSCOPEOF,
00136     oqmlSTRUCTOF,
00137 
00138     /* functions and methods */
00139     oqmlFUNCTION,
00140     oqmlCALL,
00141     oqmlMTHCALL,
00142 
00143     /* flow controls */
00144     oqmlIF,
00145     oqmlFOREACH,
00146     oqmlWHILE,
00147     oqmlDOWHILE,
00148     oqmlBREAK,
00149     oqmlFORDO,
00150 
00151     /* collection management */
00152     oqmlCOLLECTION,
00153     oqmlCONTENTS,
00154     oqmlSUPPRESSFROM,
00155     oqmlADDTO,
00156     oqmlAPPEND,
00157 
00158     oqmlELEMENT,
00159     oqmlEMPTY,
00160     oqmlIN,
00161     oqmlEXISTS,
00162     oqmlFOR,
00163 
00164     /* obsolete */
00165     oqmlSETINAT,
00166     oqmlELEMENTAT,
00167     oqmlUNSETINAT,
00168 
00169     /* query operators */
00170     oqmlSELECT,
00171     oqmlAND,
00172     oqmlOR,
00173 
00174     /* ordonnancing operators */
00175     oqmlSORT,
00176     oqmlISORT,
00177     oqmlPSORT,
00178 
00179     /* constructor/destructor */
00180     oqmlNEW,
00181     oqmlDELETE,
00182 
00183     /* time functions */
00184     oqmlTIMEFORMAT,
00185 
00186     /* misc */
00187     oqmlCOMPOUND_STATEMENT,
00188     oqmlDATABASE,
00189 
00190     /* unused */
00191     oqmlCAST,
00192     oqmlCASTIDENT,
00193     oqmlPUSH,
00194     oqmlPOP,
00195 
00196     __oqml__last__
00197   };
00198 
00199   enum oqmlBool {
00200     oqml_False = 0,
00201     oqml_True = 1
00202   };
00203 
00204   /*
00205    * Forward Declarations
00206    */
00207 
00208   class gbLink;
00209   class oqmlStatus;
00210   class oqmlNode;
00211   class oqmlSymbolEntry;
00212   class oqmlFunctionEntry;
00213   class oqmlDot;
00214   class oqmlIdent;
00215   class oqmlDotContext;
00216   class oqml_ParamList;
00217   class oqml_DeclList;
00218   class oqmlComp;
00219   class oqmlIterator;
00220   class oqml_DeclList;
00221   class oqml_DeclItem;
00222   class oqmlAtomList;
00223   class oqml_Cardinality;
00224   class oqml_EnumList;
00225   class oqmlAtom_nil;
00226   class oqmlAtom_null;
00227   class oqmlAtom_bool;
00228   class oqmlAtom_oid;
00229   class oqmlAtom_obj;
00230   class oqmlAtom_int;
00231   class oqmlAtom_char;
00232   class oqmlAtom_double;
00233   class oqmlAtom_string;
00234   class oqmlAtom_ident;
00235   class oqmlAtom_range;
00236   class oqmlAtom_coll;
00237   class oqmlAtom_list;
00238   class oqmlAtom_bag;
00239   class oqmlAtom_set;
00240   class oqmlAtom_array;
00241   class oqmlAtom_struct;
00242   class oqmlAtom_node;
00243   class oqmlAtom_select;
00244 
00245 #define OQMLBOOL(X) ((X) ? oqml_True : oqml_False)
00246 #define oqml_ESTIM_MIN    ((unsigned int)0)
00247 #define oqml_ESTIM_MIDDLE ((unsigned int)1)
00248 #define oqml_ESTIM_MAX    ((unsigned int)2)
00249 #define oqml_INFINITE     ((unsigned int)~0)
00250 
00251   /*
00252    * Atom Declarations
00253    */
00254 
00255   enum oqmlATOMTYPE {
00256     oqmlATOM_UNKNOWN_TYPE = 0,
00257     oqmlATOM_NIL,
00258     oqmlATOM_NULL,
00259     oqmlATOM_BOOL,
00260     oqmlATOM_OID,
00261     oqmlATOM_OBJ,
00262     oqmlATOM_INT,
00263     oqmlATOM_RANGE,
00264     oqmlATOM_CHAR,
00265     oqmlATOM_DOUBLE,
00266     oqmlATOM_STRING,
00267     oqmlATOM_IDENT,
00268     oqmlATOM_LIST,
00269     oqmlATOM_BAG,
00270     oqmlATOM_SET,
00271     oqmlATOM_ARRAY,
00272     oqmlATOM_STRUCT,
00273     oqmlATOM_NODE,
00274     oqmlATOM_SELECT
00275   };
00276 
00277   class oqmlAtomType {
00278 
00279   public:
00280     oqmlATOMTYPE type;
00281     Class *cls;
00282     oqmlBool comp;
00283 
00284     oqmlAtomType() {type = oqmlATOM_UNKNOWN_TYPE; cls = 0; comp = oqml_False;}
00285 
00286     oqmlAtomType(oqmlATOMTYPE _type, Class *_cls = 0) {
00287       type = _type;
00288       cls = _cls;
00289       comp = (type == oqmlATOM_STRING ? oqml_True : oqml_False);
00290     }       
00291 
00292     oqmlBool cmp(const oqmlAtomType &, Bool autocast = False);
00293     const char *getString() const;
00294   };
00295   
00296   class oqmlAtom {
00297 
00298   public:
00299     oqmlAtomType type;
00300 
00301     int refcnt;
00302     oqmlBool recurs;
00303     gbLink *link;
00304     oqmlAtom *next;
00305     char *string;
00306 
00307     oqmlAtom();
00308     oqmlAtom(const oqmlAtom&);
00309     oqmlAtom &operator =(const oqmlAtom &);
00310 
00311     virtual oqmlNode *toNode() = 0;
00312     void print(FILE *fd = stdout);
00313     char *getString() const;
00314 
00315     virtual char *makeString(FILE *) const = 0;
00316     virtual oqmlBool getData(unsigned char[], Data *, Size&, int&,
00317                              const Class * = 0) const = 0;
00318     virtual int getSize() const = 0;
00319     virtual oqmlBool makeEntry(int, unsigned char *, int,
00320                                const Class * = 0) const;
00321     virtual oqmlAtom *copy() {
00322       return NULL;
00323     }
00324     virtual oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00325     virtual oqmlBool isEqualTo(oqmlAtom &);
00326 
00327     virtual oqmlAtom_nil    *as_nil()    {return 0;}
00328     virtual oqmlAtom_null   *as_null()   {return 0;}
00329     virtual oqmlAtom_bool   *as_bool()   {return 0;}
00330     virtual oqmlAtom_oid    *as_oid()    {return 0;}
00331     virtual oqmlAtom_obj    *as_obj()    {return 0;}
00332     virtual oqmlAtom_int    *as_int()    {return 0;}
00333     virtual oqmlAtom_char   *as_char()   {return 0;}
00334     virtual oqmlAtom_double *as_double() {return 0;}
00335     virtual oqmlAtom_string *as_string() {return 0;}
00336     virtual oqmlAtom_ident  *as_ident()  {return 0;}
00337     virtual oqmlAtom_range  *as_range()  {return 0;}
00338 
00339     virtual oqmlAtom_coll   *as_coll()   {return 0;}
00340     virtual oqmlAtom_list   *as_list()   {return 0;}
00341     virtual oqmlAtom_bag    *as_bag()    {return 0;}
00342     virtual oqmlAtom_set    *as_set()    {return 0;}
00343     virtual oqmlAtom_array  *as_array()  {return 0;}
00344 
00345     virtual oqmlAtom_node   *as_node()   {return 0;}
00346     virtual oqmlAtom_select *as_select() {return 0;}
00347     virtual oqmlAtom_struct *as_struct() {return 0;}
00348 
00349     virtual Value *toValue() const;
00350 
00351     static oqmlAtom *make_atom(const IteratorAtom &atom, Class *cls);
00352     static oqmlAtom *make_atom(Data data, oqmlATOMTYPE type,
00353                                const Class *cls);
00354   
00355     virtual ~oqmlAtom();
00356   };
00357 
00358   class oqmlAtom_null : public oqmlAtom {
00359 
00360   public:
00361 
00362     oqmlAtom_null();
00363 
00364     virtual oqmlBool isEqualTo(oqmlAtom &);
00365     oqmlNode *toNode();
00366     char *makeString(FILE *) const;
00367     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00368                      const Class * = 0) const;
00369     int getSize() const;
00370     oqmlAtom *copy();
00371     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00372     virtual Value *toValue() const;
00373     virtual oqmlAtom_null   *as_null()   {return this;}
00374   };
00375 
00376   class oqmlAtom_nil : public oqmlAtom {
00377 
00378   public:
00379 
00380     oqmlAtom_nil();
00381 
00382     virtual oqmlBool isEqualTo(oqmlAtom &);
00383     oqmlNode *toNode();
00384     char *makeString(FILE *) const;
00385     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00386                      const Class * = 0) const;
00387     int getSize() const;
00388     oqmlAtom *copy();
00389     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00390     virtual oqmlAtom_nil    *as_nil()    {return this;}
00391   };
00392 
00393   class oqmlAtom_oid : public oqmlAtom {
00394 
00395   public:
00396     Oid oid;
00397 
00398     oqmlAtom_oid(const Oid &, Class * = NULL);
00399 
00400     virtual oqmlBool isEqualTo(oqmlAtom &);
00401     oqmlNode *toNode();
00402     char *makeString(FILE *) const;
00403     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00404                      const Class * = 0) const;
00405     int getSize() const;
00406     oqmlAtom *copy();
00407     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00408     virtual Value *toValue() const;
00409     virtual oqmlAtom_oid    *as_oid()    {return this;}
00410   };
00411 
00412   class oqmlSharedString {
00413 
00414   public:
00415     int refcnt;
00416     char *s;
00417     int len;
00418 
00419     oqmlSharedString(const char *_s);
00420 
00421     void set(const char *);
00422     int getLen() const;
00423 
00424     ~oqmlSharedString();
00425   };
00426 
00427   class oqmlAtom_ident : public oqmlAtom {
00428 
00429   public:
00430     oqmlSharedString *shstr;
00431     oqmlSymbolEntry *entry;
00432 
00433     oqmlAtom_ident(const char *, oqmlSymbolEntry * = 0);
00434     oqmlAtom_ident(oqmlSharedString *, oqmlSymbolEntry * = 0);
00435 
00436     void releaseEntry();
00437 
00438     virtual oqmlBool isEqualTo(oqmlAtom &);
00439     oqmlNode *toNode();
00440     char *makeString(FILE *) const;
00441     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00442                      const Class * = 0) const;
00443     int getSize() const;
00444     oqmlAtom *copy();
00445     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00446     virtual Value *toValue() const;
00447     ~oqmlAtom_ident();
00448     virtual oqmlAtom_ident  *as_ident()  {return this;}
00449   };
00450 
00451   class oqmlAtom_obj : public oqmlAtom {
00452 
00453     Object *o;
00454 
00455   public:
00456     pointer_int_t idx;
00457 
00458     oqmlAtom_obj(Object *, pointer_int_t, const Class * = 0);
00459 
00460     virtual oqmlBool isEqualTo(oqmlAtom &);
00461     oqmlNode *toNode();
00462     char *makeString(FILE *) const;
00463     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00464                      const Class * = 0) const;
00465     int getSize() const;
00466     oqmlAtom *copy();
00467 
00468     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00469     virtual Value *toValue() const;
00470     ~oqmlAtom_obj();
00471 
00472     Object *getObject();
00473     oqmlStatus *checkObject();
00474 
00475     virtual oqmlAtom_obj    *as_obj()    {return this;}
00476   };
00477 
00478 #define OQL_CHECK_OBJ(A) \
00479 { \
00480     oqmlStatus *_s = (A)->as_obj()->checkObject(); \
00481     if (_s) \
00482       return _s; \
00483 }
00484 
00485   class oqmlAtom_bool : public oqmlAtom {
00486 
00487   public:
00488     oqmlBool b;
00489 
00490     oqmlAtom_bool(oqmlBool);
00491 
00492     virtual oqmlBool isEqualTo(oqmlAtom &);
00493     oqmlNode *toNode();
00494     char *makeString(FILE *) const;
00495     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00496     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00497                      const Class * = 0) const;
00498     int getSize() const;
00499     virtual Value *toValue() const;
00500     oqmlAtom *copy();
00501     virtual oqmlAtom_bool   *as_bool()   {return this;}
00502   };
00503 
00504   class oqmlAtom_int : public oqmlAtom {
00505 
00506   public:
00507     eyedblib::int64 i;
00508 
00509     oqmlAtom_int(eyedblib::int64);
00510 
00511     virtual oqmlBool isEqualTo(oqmlAtom &);
00512     oqmlNode *toNode();
00513     char *makeString(FILE *) const;
00514     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00515                      const Class * = 0) const;
00516     int getSize() const;
00517     oqmlAtom *copy();
00518     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00519     virtual Value *toValue() const;
00520     virtual oqmlAtom_int    *as_int()    {return this;}
00521   };
00522 
00523   class oqmlAtom_range : public oqmlAtom {
00524 
00525   public:
00526     oqmlATOMTYPE rtype;
00527     oqmlAtom *from, *to;
00528     oqmlBool from_incl, to_incl;
00529 
00530     oqmlAtom_range(oqmlAtom *from, oqmlBool, oqmlAtom *to, oqmlBool);
00531 
00532     virtual oqmlBool isEqualTo(oqmlAtom &);
00533     oqmlNode *toNode();
00534     char *makeString(FILE *) const;
00535     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00536                      const Class * = 0) const;
00537     int getSize() const;
00538     oqmlAtom *copy();
00539     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00540     virtual Value *toValue() const;
00541     virtual oqmlAtom_range    *as_range()    {return this;}
00542   };
00543 
00544   class oqmlAtom_char : public oqmlAtom {
00545 
00546   public:
00547     char c;
00548 
00549     oqmlAtom_char(char);
00550 
00551     virtual oqmlBool isEqualTo(oqmlAtom &);
00552     oqmlNode *toNode();
00553     char *makeString(FILE *) const;
00554     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00555                      const Class * = 0) const;
00556     int getSize() const;
00557     oqmlAtom *copy();
00558     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00559     virtual Value *toValue() const;
00560     virtual oqmlAtom_char   *as_char()   {return this;}
00561   };
00562 
00563   class oqmlAtom_string : public oqmlAtom {
00564 
00565   public:
00566 
00567     oqmlSharedString *shstr;
00568     oqmlAtom_string(const char *);
00569     oqmlAtom_string(oqmlSharedString *);
00570 
00571     int getLen() const;
00572 
00573     virtual oqmlBool isEqualTo(oqmlAtom &);
00574     oqmlNode *toNode();
00575     char *makeString(FILE *) const;
00576     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00577                      const Class * = 0) const;
00578     int getSize() const;
00579     oqmlBool makeEntry(int, unsigned char *, int,
00580                        const Class * = 0) const;
00581     oqmlAtom *copy();
00582     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00583     virtual Value *toValue() const;
00584     ~oqmlAtom_string();
00585     virtual oqmlAtom_string *as_string() {return this;}
00586     void set(const char *);
00587 
00588     oqmlStatus *setAtom(oqmlAtom *, int idx, oqmlNode *);
00589   };
00590 
00591   class oqmlAtom_double : public oqmlAtom {
00592 
00593   public:
00594     double d;
00595 
00596     oqmlAtom_double(double);
00597 
00598     virtual oqmlBool isEqualTo(oqmlAtom &);
00599     oqmlNode *toNode();
00600     char *makeString(FILE *) const;
00601     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00602                      const Class * = 0) const;
00603     int getSize() const;
00604     oqmlAtom *copy();
00605     virtual Value *toValue() const;
00606     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00607     virtual oqmlAtom_double *as_double() {return this;}
00608   };
00609 
00610   class oqml_StructAttr {
00611 
00612   public:
00613     char *name;
00614     oqmlAtom *value;
00615 
00616     oqml_StructAttr() {
00617       name = 0;
00618       value = 0;
00619     }
00620 
00621     oqml_StructAttr(const char *_name, oqmlAtom *_value) {
00622       set(_name, _value);
00623     }
00624 
00625     void set(const char *_name, oqmlAtom *_value) {
00626       name = strdup(_name);
00627       value = _value;
00628     }
00629 
00630     ~oqml_StructAttr() {
00631       free(name);
00632     }
00633 
00634     oqml_StructAttr(const oqml_StructAttr &x) {
00635       *this = x;
00636     }
00637 
00638     oqml_StructAttr& operator=(const oqml_StructAttr &x) {
00639       name = strdup(x.name);
00640       value = (x.value ? x.value->copy() : 0);
00641       return *this;
00642     }
00643 
00644   private:
00645     friend class oqmlAtom_struct;
00646   };
00647 
00648   class oqmlAtom_struct : public oqmlAtom {
00649 
00650   public:
00651     char *name;
00652     int attr_cnt;
00653     oqml_StructAttr *attr;
00654     oqmlNode *toNode();
00655     oqmlAtom_struct();
00656     oqmlAtom_struct(oqml_StructAttr *, int cnt);
00657     char *makeString(FILE *) const;
00658     oqmlAtom *copy();
00659     oqmlAtom *getAtom(const char *name, int &);
00660     oqmlAtom *getAtom(unsigned int);
00661     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00662     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00663                      const Class * = 0) const;
00664     virtual oqmlBool isEqualTo(oqmlAtom &);
00665     int getSize() const;
00666     virtual oqmlAtom_struct *as_struct() {return this;}
00667     oqmlStatus *setAtom(oqmlAtom *, int idx, oqmlNode *);
00668     virtual Value *toValue() const;
00669 
00670     ~oqmlAtom_struct();
00671   };
00672 
00673   class oqmlAtom_node : public oqmlAtom {
00674 
00675   public:
00676     oqmlNode *node;
00677     //  oqmlAtomList *list;
00678     oqmlBool evaluated;
00679 
00680     oqmlAtom_node(oqmlNode *);
00681     oqmlNode *toNode();
00682     char *makeString(FILE *) const;
00683     oqmlAtom *copy();
00684     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00685                      const Class * = 0) const;
00686     int getSize() const;
00687     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00688     virtual oqmlAtom_node *as_node() {return this;}
00689     ~oqmlAtom_node();
00690   };
00691 
00692   class oqmlContext;
00693 
00694   class oqmlAtom_select : public oqmlAtom {
00695 
00696   public:
00697     oqmlNode *node;
00698     oqmlNode *node_orig;
00699     oqmlAtomList *list;
00700     oqmlBool evaluated;
00701     oqmlBool indexed;
00702     oqmlAtom_coll *collatom;
00703     int cpcnt;
00704     oqmlAtomList *cplists[OQML_MAX_CPS];
00705 
00706     oqmlAtom_select(oqmlNode *, oqmlNode *);
00707     oqmlNode *toNode();
00708     char *makeString(FILE *) const;
00709     oqmlAtom *copy();
00710     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00711                      const Class * = 0) const;
00712     int getSize() const;
00713     oqmlBool isPopulated () const {return OQMLBOOL(list);}
00714     oqmlBool isIndexed () const {return indexed;}
00715     oqmlBool compare(unsigned char *, int, Bool, oqmlTYPE) const;
00716     virtual oqmlAtom_select *as_select() {return this;}
00717     void appendCP(oqmlContext *);
00718     void setCP(oqmlContext *);
00719     ~oqmlAtom_select();
00720   };
00721 
00722   class oqmlAtom_coll : public oqmlAtom {
00723 
00724   public:
00725     oqmlAtomList *list;
00726 
00727     oqmlAtom_coll(oqmlAtomList *);
00728     char *makeString(FILE *) const;
00729     oqmlBool getData(unsigned char[], Data *, Size&, int&,
00730                      const Class * = 0) const;
00731     int getSize() const;
00732     virtual oqmlBool isEqualTo(oqmlAtom &);
00733     virtual oqmlAtom_coll   *as_coll()   {return this;}
00734     oqmlStatus *setAtom(oqmlAtom *, int idx, oqmlNode *);
00735     virtual Value::Type getValueType() const;
00736     virtual Value *toValue() const;
00737     virtual const char *getTypeName() const = 0;
00738     oqmlAtom_coll *suppressDoubles();
00739   };
00740 
00741   class oqmlAtom_list : public oqmlAtom_coll {
00742   public:
00743     oqmlAtom_list(oqmlAtomList *);
00744     oqmlNode *toNode();
00745     virtual oqmlAtom_list   *as_list()   {return this;}
00746     virtual Value::Type getValueType() const;
00747     oqmlAtom *copy();
00748     const char *getTypeName() const {return "list";}
00749   };
00750 
00751   class oqmlAtom_bag : public oqmlAtom_coll {
00752   public:
00753     oqmlAtom_bag(oqmlAtomList *);
00754     oqmlNode *toNode();
00755     virtual oqmlAtom_bag   *as_bag()   {return this;}
00756     virtual Value::Type getValueType() const;
00757     const char *getTypeName() const {return "bag";}
00758     oqmlAtom *copy();
00759   };
00760 
00761   class oqmlAtom_set : public oqmlAtom_coll {
00762   public:
00763     oqmlAtom_set(oqmlAtomList *, oqmlBool suppressDoubles = oqml_True);
00764     oqmlNode *toNode();
00765     const char *getTypeName() const {return "set";}
00766     virtual oqmlAtom_set   *as_set()   {return this;}
00767     virtual Value::Type getValueType() const;
00768     oqmlAtom *copy();
00769   };
00770 
00771   class oqmlAtom_array : public oqmlAtom_coll {
00772   public:
00773     oqmlAtom_array(oqmlAtomList *);
00774     oqmlNode *toNode();
00775     virtual oqmlAtom_array   *as_array()   {return this;}
00776     virtual Value::Type getValueType() const;
00777     const char *getTypeName() const {return "array";}
00778     oqmlAtom *copy();
00779   };
00780 
00781   class oqmlContext;
00782 
00783   class oqmlAtomList {
00784 
00785   public:
00786     unsigned int cnt;
00787     oqmlAtom *first;
00788     oqmlAtom *last;
00789 
00790     int refcnt;
00791     oqmlBool recurs;
00792     gbLink *link;
00793     char *string;
00794 
00795     oqmlAtomList();
00796     oqmlAtomList(oqmlAtomList *);
00797     oqmlAtomList(oqmlAtom *);
00798 
00799     oqmlAtomList *copy();
00800     oqmlAtom **toArray();
00801 
00802     void print(FILE *fd = stdout);
00803     char *getString() const;
00804 
00805     static oqmlAtomList *andOids(oqmlAtomList *, oqmlAtomList *);
00806     oqmlAtom *getAtom(unsigned int idx);
00807     oqmlStatus *setAtom(oqmlAtom *, int idx, oqmlNode *);
00808     int getFlattenCount() const;
00809 
00810     bool append(oqmlAtom *, bool incref = true, bool detect_cycle = false);
00811     oqmlBool isIn(oqmlAtom *);
00812     oqmlStatus *suppress(oqmlAtom *);
00813     void empty();
00814 
00815     bool append(oqmlAtomList *, oqmlBool = oqml_True, bool detect_cycle = false);
00816     void suppressDoubles();
00817     oqmlStatus *compare(oqmlNode *node, oqmlContext *ctx, oqmlAtomList *, const char *, oqmlTYPE, oqmlBool &) const;
00818     oqmlBool isEqualTo(oqmlAtomList &);
00819     void convert(IteratorAtom *, int&);
00820     ~oqmlAtomList();
00821   };
00822 
00823 #define OQML_ATOM_STRVAL(X)   ((X)->as_string()->shstr->s)
00824 #define OQML_ATOM_STRLEN(X)   ((X)->as_string()->getLen())
00825 #define OQML_ATOM_INTVAL(X)   ((X)->as_int()->i)
00826 #define OQML_ATOM_BOOLVAL(X)  ((X)->as_bool()->b)
00827 #define OQML_ATOM_CHARVAL(X)  ((X)->as_char()->c)
00828 #define OQML_ATOM_DBLVAL(X)   ((X)->as_double()->d)
00829 #define OQML_ATOM_OIDVAL(X)   ((X)->as_oid()->oid)
00830 #define OQML_ATOM_COLLVAL(X)  ((X)->as_coll()->list)
00831 #define OQML_ATOM_LISTVAL(X)  ((X)->as_list()->list)
00832 #define OQML_ATOM_SETVAL(X)   ((X)->as_set()->list)
00833 #define OQML_ATOM_BAGVAL(X)   ((X)->as_bag()->list)
00834 #define OQML_ATOM_ARRVAL(X)   ((X)->as_array()->list)
00835 #define OQML_ATOM_IDENTVAL(X) ((X)->as_ident()->shstr->s)
00836 #define OQML_ATOM_OBJVAL(X)   ((X)->as_obj()->getObject())
00837 
00838 #define OQML_IS(X, AS) ((X)->AS())
00839 
00840 #define OQML_IS_STR(X)    OQML_IS(X, as_string)
00841 #define OQML_IS_INT(X)    OQML_IS(X, as_int)
00842 #define OQML_IS_CHAR(X)   OQML_IS(X, as_char)
00843 #define OQML_IS_BOOL(X)   OQML_IS(X, as_bool)
00844 #define OQML_IS_DBL(X)    OQML_IS(X, as_double)
00845 #define OQML_IS_OID(X)    OQML_IS(X, as_oid)
00846 #define OQML_IS_OBJ(X)    OQML_IS(X, as_obj)
00847 #define OQML_IS_OBJECT(X) (OQML_IS_OBJ(X) || OQML_IS_OID(X))
00848 #define OQML_IS_COLL(X)   OQML_IS(X, as_coll)
00849 #define OQML_IS_LIST(X)   OQML_IS(X, as_list)
00850 #define OQML_IS_BAG(X)    OQML_IS(X, as_bag)
00851 #define OQML_IS_SET(X)    OQML_IS(X, as_set)
00852 #define OQML_IS_ARRAY(X)  OQML_IS(X, as_array)
00853 #define OQML_IS_NODE(X)   OQML_IS(X, as_node)
00854 #define OQML_IS_STRUCT(X) OQML_IS(X, as_struct)
00855 #define OQML_IS_IDENT(X)  OQML_IS(X, as_ident)
00856 #define OQML_IS_NULL(X)   OQML_IS(X, as_null)
00857 
00858 #define OQML_IS_STRING OQML_IS_STR
00859 #define OQML_IS_DOUBLE OQML_IS_DBL
00860 
00861   /* end atom declarations */
00862 
00863   struct gbContext {
00864     gbLink *link;
00865     gbContext(gbLink *link) : link(link) {}
00866   };
00867 
00868   class oqmlGarbManager {
00869     static gbLink *first, *last;
00870     static gbLink *add_realize(gbLink *);
00871     static oqmlBool garbaging;
00872     static unsigned int count;
00873     static LinkedList str_list;
00874     static std::list<gbContext *> ctx_l;
00875 
00876   public:
00877     static void garbage();
00878     static gbLink *add(oqmlAtom *);
00879     static gbLink *add(oqmlAtomList *);
00880     static void remove(gbLink *);
00881     static void add(char *);
00882     static unsigned int getCount() {return count;}
00883 
00884     static void garbage(gbLink *l, bool full = false);
00885     static gbContext *peek();
00886     static void garbage(gbContext *ctx);
00887   };
00888 
00889   class oqml_Location {
00890 
00891   public:
00892     int from, to;
00893   };
00894 
00895   /* status */
00896   class oqmlStatus {
00897 
00898   public:
00899     char *msg;
00900     oqmlAtom *returnAtom;
00901     oqmlStatus(const char *, ...);
00902     oqmlStatus(Status);
00903     oqmlStatus(oqmlNode *, const char *, ...);
00904     oqmlStatus(oqmlNode *, Status);
00905     static oqmlStatus *expected(oqmlNode *node, const char *expected,
00906                                 const char *got);
00907     static oqmlStatus *expected(oqmlNode *node, oqmlAtomType *expected,
00908                                 oqmlAtomType *got);
00909     static void purge();
00910     void set();
00911 
00912     ~oqmlStatus();
00913   };
00914 
00915 #define oqmlSuccess ((oqmlStatus *)0)
00916 
00917   /* syntax list */
00918   class oqml_Link {
00919 
00920   public:
00921     oqmlNode *ql;
00922     oqml_Link *next;
00923 
00924     oqml_Link(oqmlNode *);
00925     ~oqml_Link();
00926   };
00927 
00928   class oqml_List {
00929 
00930   public:
00931     int cnt;
00932     oqml_Link *first;
00933     oqml_Link *last;
00934 
00935     oqml_List();
00936     ~oqml_List();
00937 
00938     void lock();
00939     void unlock();
00940 
00941     std::string toString() const;
00942 
00943     oqmlBool hasIdent(const char *);
00944 
00945     void add(oqmlNode *);
00946   };
00947 
00948   class oqml_IdentLink {
00949 
00950   public:
00951     char *ident; 
00952     oqmlNode *left;
00953     oqmlNode *ql;
00954     oqmlBool skipIdent;
00955     oqmlBool requalified;
00956     const Class *cls;
00957     oqml_IdentLink *next;
00958     oqml_IdentLink(const char *, oqmlNode *);
00959     oqml_IdentLink(oqmlNode *, oqmlNode *);
00960     void lock();
00961     void unlock();
00962     ~oqml_IdentLink();
00963   };
00964 
00965   class oqml_IdentList {
00966 
00967   public:
00968     int cnt;
00969     oqml_IdentLink *first;
00970     oqml_IdentLink *last;
00971 
00972     oqml_IdentList();
00973     ~oqml_IdentList();
00974     void lock();
00975     void unlock();
00976     void add(const char *, oqmlNode *);
00977     void add(oqmlNode *, oqmlNode *);
00978   };
00979 
00980   /* context */
00981 
00982   class oqmlSymbolEntry {
00983 
00984   public:
00985     char *ident;
00986     oqmlAtomType type;
00987     oqmlAtom *at;
00988     oqmlBool global;
00989     oqmlSymbolEntry *prev, *next;
00990     oqmlBool system;
00991     oqmlAtomList *list;
00992     int level;
00993     oqmlBool popped;
00994 
00995     oqmlSymbolEntry(oqmlContext *, const char *_ident, oqmlAtomType *_type,
00996                     oqmlAtom *_at, oqmlBool _global, oqmlBool _system);
00997 
00998     void set(oqmlAtomType *_type, oqmlAtom *_at, oqmlBool force = oqml_False,
00999              oqmlBool tofree = oqml_False);
01000 
01001     void addEntry(oqmlAtom_ident *ident);
01002 
01003     void releaseEntries();
01004 
01005     ~oqmlSymbolEntry();
01006   };
01007 
01008   class oqmlSymbolTable {
01009 
01010   public:
01011     oqmlSymbolEntry *sfirst, *slast;
01012     oqmlFunctionEntry *ffirst, *flast;
01013     oqmlSymbolTable() {sfirst = slast = 0; ffirst = flast = 0;}
01014   };
01015 
01016   class oqmlSelect;
01017 
01018   class oqmlContext {
01019     oqmlSymbolTable *symtab;
01020     oqmlDotContext *dot_ctx;
01021     oqmlAtomList *and_list_ctx;
01022     int lastTempSymb;
01023     int or_ctx, and_ctx, preval_ctx, where_ctx;
01024     unsigned int maxatoms;
01025     oqmlBool overMaxAtoms;
01026     oqmlBool oneatom;
01027     int local_cnt;
01028     int arg_level;
01029     int local_alloc;
01030     oqmlBool is_popping;
01031     LinkedList **locals;
01032     int select_ctx_cnt;
01033     int hidden_select_ctx_cnt;
01034     oqmlSelect *select_ctx[64];
01035     oqmlSelect *hidden_select_ctx[64];
01036     // cp for Cartesian Product
01037     int cpatom_cnt;
01038     oqmlAtom *cpatoms[OQML_MAX_CPS];
01039 
01040     oqmlStatus *pushSymbolRealize(const char *, oqmlAtomType *, oqmlAtom *,
01041                                   oqmlBool global, oqmlBool system);
01042     oqmlStatus *setSymbolRealize(const char *, oqmlAtomType *, oqmlAtom *,
01043                                  oqmlBool global, oqmlBool system,
01044                                  oqmlBool to_free);
01045     oqmlStatus *popSymbolRealize(const char *, oqmlBool global);
01046     static std::string makeTempSymb(int idx);
01047 
01048   public:
01049     static oqmlSymbolTable stsymtab;
01050 
01051     oqmlContext(oqmlSymbolTable * = 0);
01052     oqmlStatus *pushSymbol(const char *, oqmlAtomType *, oqmlAtom * = 0,
01053                            oqmlBool global = oqml_False,
01054                            oqmlBool system = oqml_False);
01055     oqmlStatus *setSymbol(const char *, oqmlAtomType *, oqmlAtom * = 0,
01056                           oqmlBool global = oqml_False,
01057                           oqmlBool system = oqml_False);
01058     oqmlStatus *popSymbol(const char *, oqmlBool global = oqml_False);
01059 
01060     oqmlStatus *pushCPAtom(oqmlNode *, oqmlAtom *);
01061     oqmlStatus *popCPAtom(oqmlNode *);
01062     int getCPAtomCount() const {return cpatom_cnt;}
01063     oqmlAtom **getCPAtoms() {return cpatoms;}
01064 
01065     LinkedList *getLocalTable() {return local_cnt > 0 ? locals[local_cnt-1] : 0;}
01066 
01067     int getLocalDepth() const {return local_cnt;}
01068 
01069     void push() {local_cnt++;}
01070     void pop() {local_cnt--;}
01071 
01072     void pushArgLevel() {arg_level++;}
01073     void popArgLevel() {arg_level--;}
01074 
01075     int getArgLevel() const {return arg_level;}
01076 
01077     oqmlStatus *pushLocalTable();
01078     oqmlStatus *popLocalTable();
01079 
01080     void displaySymbols();
01081 
01082     oqmlBool getSymbol(const char *, oqmlAtomType * = 0, oqmlAtom ** = 0,
01083                        oqmlBool *global = 0, oqmlBool *system = 0);
01084 
01085     oqmlSymbolEntry *getSymbolEntry(const char *);
01086 
01087     oqmlStatus *setFunction(const char * , oqml_ParamList *, oqmlNode *);
01088     int getFunction(const char *, oqmlFunctionEntry **);
01089     void popFunction(const char *);
01090 
01091     void setDotContext(oqmlDotContext *);
01092     oqmlDotContext *getDotContext();
01093     void setAndContext(oqmlAtomList *);
01094     oqmlAtomList *getAndContext();
01095     oqmlBool isSelectContext() {return select_ctx_cnt ? oqml_True : oqml_False;}
01096 
01097     oqmlSelect *getSelectContext() {
01098       return select_ctx_cnt > 0 ? select_ctx[select_ctx_cnt-1] : (oqmlSelect *)0;
01099     }
01100 
01101     oqmlSelect *getHiddenSelectContext() {
01102       return hidden_select_ctx_cnt > 0 ? hidden_select_ctx[hidden_select_ctx_cnt-1] : (oqmlSelect *)0;
01103     }
01104 
01105     void incrSelectContext(oqmlSelect *);
01106     void decrSelectContext();
01107     void incrHiddenSelectContext(oqmlSelect *);
01108     void decrHiddenSelectContext();
01109 
01110     int getHiddenSelectContextCount() const {return hidden_select_ctx_cnt;}
01111     int getSelectContextCount() const {return select_ctx_cnt;}
01112 
01113     int setSelectContextCount(int _select_ctx_cnt) {
01114       int o_select_ctx_cnt = select_ctx_cnt;
01115       select_ctx_cnt = _select_ctx_cnt;
01116       return o_select_ctx_cnt;
01117     }
01118 
01119     void setMaxAtoms(unsigned int _maxatoms) {maxatoms = _maxatoms;}
01120     unsigned int getMaxAtoms() const {return maxatoms;}
01121     void setOneAtom() {oneatom = oqml_True;}
01122     void setOneAtom(oqmlBool _oneatom) {oneatom = _oneatom;}
01123     oqmlBool isOneAtom() const {return oneatom;}
01124     void setOverMaxAtoms() {overMaxAtoms = oqml_True;}
01125     oqmlBool isOverMaxAtoms() const {return overMaxAtoms;}
01126 
01127     oqmlBool isOrContext() {return or_ctx ? oqml_True : oqml_False;}
01128     void incrOrContext() {or_ctx++;}
01129     void decrOrContext() {or_ctx--;}
01130 
01131     oqmlBool isAndContext() {return and_ctx ? oqml_True : oqml_False;}
01132     void incrAndContext() {and_ctx++;}
01133     void decrAndContext() {and_ctx--;}
01134 
01135     oqmlBool isPrevalContext() {return preval_ctx ? oqml_True : oqml_False;}
01136     void incrPrevalContext() {preval_ctx++;}
01137     void decrPrevalContext() {preval_ctx--;}
01138     oqmlBool isWhereContext() {return where_ctx ? oqml_True : oqml_False;}
01139     void incrWhereContext() {where_ctx++;}
01140     void decrWhereContext() {where_ctx--;}
01141 
01142     int setWhereContext(int _where_ctx) {
01143       int owhere_ctx = where_ctx;
01144       where_ctx = _where_ctx;
01145       return owhere_ctx;
01146     }
01147 
01148     int setPrevalContext(int _preval_ctx) {
01149       int opreval_ctx = preval_ctx;
01150       preval_ctx = _preval_ctx;
01151       return opreval_ctx;
01152     }
01153 
01154     std::string getTempSymb();
01155     ~oqmlContext();
01156   };
01157 
01158 #define OQML_OBJECT_MANAGER
01159 
01160   class oqmlObjectManager {
01161 
01162     static void addToFreeList(Object *o);
01163     static LinkedList freeList;
01164   public:
01165 
01166     static oqmlStatus *getObject(oqmlNode *, Database *, oqmlAtom *,
01167                                  Object *&, oqmlBool addToFreeList,
01168                                  oqmlBool errorIfNull = oqml_True);
01169     static oqmlStatus *getObject(oqmlNode *, Database *db, const Oid &,
01170                                  Object *&, oqmlBool addToFreeList,
01171                                  oqmlBool errorIfNull = oqml_True);
01172     static oqmlStatus *getObject(oqmlNode *, Database *db, const Oid *,
01173                                  Object *&, oqmlBool addToFreeList,
01174                                  oqmlBool errorIfNull = oqml_True);
01175     static oqmlStatus *getObject(oqmlNode *, const char *, Object *&,
01176                                  pointer_int_t &);
01177     static void releaseObject(Object *, oqmlBool = oqml_False);
01178     static oqmlStatus *getIndex(oqmlNode *node, const Object *o,
01179                                 pointer_int_t &idx);
01180 
01181     static oqmlAtom *registerObject(Object *);
01182     static oqmlStatus *unregisterObject(oqmlNode *node, Object *o, bool force = false);
01183     static oqmlBool isRegistered(const Object *, pointer_int_t &);
01184 
01185     static void garbageObjects();
01186 
01187     static ObjCache *objCacheIdx;
01188     static ObjCache *objCacheObj;
01189   };
01190 
01191   enum oqmlBinopType {
01192     oqmlIntOK    = 0x0,
01193     oqmlDoubleOK = 0x1,
01194     oqmlConcatOK = 0x2,
01195     oqmlDoubleConcatOK = oqmlDoubleOK|oqmlConcatOK
01196   };
01197 
01198   extern void
01199   oqmlLock(oqmlAtom *a, oqmlBool lock, oqmlBool rm = oqml_False);
01200 
01201   extern void
01202   oqmlLock(oqmlAtomList *l, oqmlBool lock, oqmlBool rm = oqml_False);
01203 
01204   extern oqmlStatus *
01205   oqml_check_logical(oqmlNode *node, oqmlAtomList *al, oqmlBool &b,
01206                      bool strict = false);
01207   /* base node */
01208   class oqmlNode {
01209   protected:
01210     oqmlTYPE type;
01211     oqmlAtomType eval_type;
01212     oqmlAtomList *cst_list;
01213     oqml_Location loc;
01214     static LinkedList node_list;
01215     oqmlBool locked;
01216     static void init();
01217     oqmlStatus *binopCompile(Database *, oqmlContext *,
01218                              const char *opstr, oqmlNode *, oqmlNode *,
01219                              oqmlAtomType &, oqmlBinopType, oqmlBool &);
01220 
01221     oqmlStatus *binopEval(Database *, oqmlContext *,
01222                           const char *opstr, const oqmlAtomType &,
01223                           oqmlNode *, oqmlNode *, oqmlBinopType,
01224                           oqmlAtomList **, oqmlAtomList **);
01225 
01226     static void swap(oqmlComp *comp, oqmlNode *&qleft, oqmlNode *&qright);
01227     oqmlStatus *compCompile(Database *, oqmlContext *, const char *,
01228                             oqmlNode *&, oqmlNode *&, oqmlComp *, oqmlAtom **,
01229                             oqmlAtomType *);
01230 
01231     oqmlStatus *compEval(Database *, oqmlContext *, const char *, oqmlNode *,
01232                          oqmlNode *, oqmlAtomList **, oqmlComp *, oqmlAtom *);
01233 
01234     oqmlStatus *requalify_node(Database *, oqmlContext *, oqmlNode *&ql, const char *ident, oqmlNode *node, oqmlBool &done);
01235     oqmlStatus *requalify_node_back(Database *, oqmlContext *, oqmlNode *&ql);
01236     oqmlStatus *requalify_node(Database *, oqmlContext *, oqmlNode *&ql, const Attribute **attrs,
01237                                int attr_cnt, const char *ident);
01238 
01239   public:
01240     oqmlNode(oqmlTYPE);
01241     oqmlBool is_statement;
01242     virtual ~oqmlNode();
01243 
01244     virtual oqmlStatus *compile(Database *db, oqmlContext *ctx) = 0;
01245     virtual oqmlStatus *eval(Database *db, oqmlContext *ctx, oqmlAtomList **alist, oqmlComp * = NULL, oqmlAtom * = NULL) = 0;
01246     virtual void evalType(Database *db, oqmlContext *ctx, oqmlAtomType *) = 0;
01247     virtual oqmlBool   isConstant() const = 0;
01248 
01249     virtual oqmlBool mayBeRequalified() const {return oqml_True;}
01250     virtual oqmlStatus *requalify(Database *, oqmlContext *, const char *, oqmlNode *, oqmlBool &done);
01251     virtual oqmlStatus *requalify(Database *, oqmlContext *, const Attribute **, int attr_cnt,
01252                                   const char *ident);
01253     virtual oqmlStatus *requalify_back(Database *, oqmlContext *);
01254 
01255     virtual std::string toString() const {return "";}
01256 
01257     inline oqmlTYPE getType() const {return type;}
01258     virtual oqmlComp *asComp() {return (oqmlComp *)0;}
01259 
01260     virtual oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &r) {
01261       r = oqml_ESTIM_MAX;
01262       return oqmlSuccess;
01263     }
01264 
01265     oqmlStatus *realize(Database *db, oqmlAtomList **);
01266     oqmlStatus *compEval(Database *db, oqmlContext *ctx, oqmlAtomType *);
01267     virtual void lock();
01268     virtual void unlock();
01269     oqmlBool isLocked() const {return locked;}
01270     virtual oqmlStatus *evalLeft(Database *db, oqmlContext *ctx,
01271                                  oqmlAtom **a, int &idx);
01272     static void garbageNodes();
01273     void locate(int, int);
01274     oqmlNode *back;
01275 
01276     virtual oqmlBool hasIdent(const char *) {return oqml_False;}
01277 
01278     virtual oqmlStatus *preEvalSelect(Database *db, oqmlContext *ctx,
01279                                       const char *ident, oqmlBool &done,
01280                                       unsigned int &cnt, oqmlBool firstPass = oqml_True) {
01281       done = oqml_False;
01282       cnt = 0;
01283       return oqmlSuccess;
01284     }
01285 
01286     oqmlBool equals(const oqmlNode *node) const {
01287       return OQMLBOOL(node && type == node->getType() &&
01288                       !strcmp(toString().c_str(), node->toString().c_str()));
01289     }
01290 
01291     virtual oqmlDot   *asDot() {return (oqmlDot *)0;}
01292     virtual oqmlIdent *asIdent() {return (oqmlIdent *)0;}
01293     std::string getOperationName() const;
01294     void requalifyType(oqmlTYPE);
01295     static void registerNode(oqmlNode *);
01296   };
01297 
01298 #define OQML_STD_REQUAL_2() \
01299   virtual oqmlStatus *requalify(Database *db, oqmlContext *ctx, const char *_ident, oqmlNode *_node, oqmlBool &done) { \
01300     oqmlStatus *s = requalify_node(db, ctx, qleft, _ident, _node, done); \
01301     if (s) return s; \
01302     return requalify_node(db, ctx, qright, _ident, _node, done); \
01303   } \
01304   virtual oqmlStatus *requalify(Database *db, oqmlContext *ctx, const Attribute **attrs, int attr_cnt, \
01305                                 const char *_ident) { \
01306     oqmlStatus *s = requalify_node(db, ctx, qleft, attrs, attr_cnt, _ident); \
01307     if (s) return s; \
01308     return requalify_node(db, ctx, qright, attrs, attr_cnt, _ident); \
01309   } \
01310   virtual oqmlStatus *requalify_back(Database *db, oqmlContext *ctx) { \
01311     oqmlStatus *s = requalify_node_back(db, ctx, qleft); \
01312     if (s) return s; \
01313     return requalify_node_back(db, ctx, qright); \
01314   }
01315 
01316 #define OQML_STD_REQUAL_1() \
01317   virtual oqmlStatus *requalify(Database *db, oqmlContext *ctx, const char *_ident, oqmlNode *node, oqmlBool &done) { \
01318     return requalify_node(db, ctx, ql, _ident, node, done); \
01319   } \
01320   virtual oqmlStatus *requalify(Database *db, oqmlContext *ctx, const Attribute **attrs, int attr_cnt, \
01321                                 const char *_ident) { \
01322     return requalify_node(db, ctx, ql, attrs, attr_cnt, _ident); \
01323   }  \
01324   virtual oqmlStatus *requalify_back(Database *db, oqmlContext *ctx) { \
01325     return requalify_node_back(db, ctx, ql); \
01326   }
01327 
01328 #define OQML_STD_REQUAL_0() \
01329   virtual oqmlStatus *requalify(Database *, oqmlContext *, const char *_ident, oqmlNode *node, oqmlBool &) { \
01330     return oqmlSuccess; \
01331   } \
01332   virtual oqmlStatus *requalify(Database *, oqmlContext *, const Attribute **attrs, int attr_cnt, \
01333                                 const char *_ident) { \
01334     return oqmlSuccess; \
01335   } \
01336   virtual oqmlStatus *requalify_back(Database *, oqmlContext *) { \
01337     return oqmlSuccess; \
01338   } \
01339 
01340   class oqmlComp : public oqmlNode {
01341   protected:
01342     oqmlIterator *iter;
01343     oqmlAtom *cst_atom;
01344     oqmlNode * qleft;
01345     oqmlNode * qright;
01346     char *opstr;
01347     oqmlStatus *optimize(Database *db, oqmlContext *ctx);
01348 
01349   public:
01350     oqmlComp(oqmlTYPE, oqmlNode *, oqmlNode *, const char *opstr);
01351     virtual oqmlStatus *makeIterator(Database *, oqmlDotContext *,
01352                                      oqmlAtom *) = 0;
01353     virtual oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
01354     virtual std::string toString() const;
01355     oqmlIterator *getIterator() {return iter;}
01356     virtual oqmlStatus *compile(Database *db, oqmlContext *ctx);
01357     virtual oqmlStatus *eval(Database *db, oqmlContext *ctx, oqmlAtomList **alist, oqmlComp * = NULL, oqmlAtom * = NULL);
01358     virtual void evalType(Database *db, oqmlContext *ctx, oqmlAtomType *);
01359     virtual oqmlBool   isConstant() const;
01360     virtual oqmlStatus *compare(Database *db, oqmlContext *ctx, oqmlAtomList *,
01361                                 oqmlAtomList *, oqmlAtomList **);
01362     oqmlStatus *preEvalSelect(Database *db, oqmlContext *ctx,
01363                               const char *ident, oqmlBool &done,
01364                               unsigned int &cnt, oqmlBool = oqml_True);
01365     oqmlComp *asComp() {return this;}
01366     oqmlBool appearsMoreOftenThan(oqmlComp *) const;
01367     oqmlBool hasDotIdent(const char *);
01368     oqmlStatus *reinit(Database *db, oqmlContext *ctx);
01369     oqmlNode *getLeft() {return qleft;}
01370     oqmlNode *getRight() {return qright;}
01371 
01372     OQML_STD_REQUAL_2()
01373 
01374       oqmlStatus *preEvalSelectRealize(Database *db, oqmlContext *ctx,
01375                                        const char *ident, oqmlBool &done,
01376                                        oqmlAtomList **alist, oqmlBool firstPass);
01377 
01378     oqmlBool evalDone;
01379     oqmlBool needReinit;
01380     void lock();
01381     void unlock();
01382     ~oqmlComp();
01383 
01384     virtual oqmlStatus *complete(Database *, oqmlContext *ctx, oqmlAtom *) {
01385       return oqmlSuccess;
01386     }
01387 
01388     oqmlBool hasIdent(const char *_ident) {
01389       return OQMLBOOL(qleft->hasIdent(_ident) || qright->hasIdent(_ident));
01390     }
01391   };
01392 
01393 
01394 #define OQML_STD_DECL(X) \
01395   ~X(); \
01396   virtual std::string toString() const; \
01397   oqmlStatus *compile(Database *db, oqmlContext *ctx); \
01398   oqmlStatus *eval(Database *db, oqmlContext *ctx, oqmlAtomList **alist, \
01399                   oqmlComp * = NULL, oqmlAtom * = NULL); \
01400   void evalType(Database *db, oqmlContext *ctx, oqmlAtomType *); \
01401   oqmlBool   isConstant() const
01402 
01403 #define OQML_STD_DECL_0(X) \
01404   X(); \
01405   OQML_STD_REQUAL_0() \
01406   OQML_STD_DECL(X)
01407 
01408 #define OQML_STD_DECL_1(X) \
01409   X(oqmlNode *); \
01410   void lock() {oqmlNode::lock(); if (ql) ql->lock();} \
01411   void unlock() {oqmlNode::unlock(); if (ql) ql->unlock();} \
01412   oqmlBool hasIdent(const char *_ident) { \
01413     return OQMLBOOL(ql && ql->hasIdent(_ident)); \
01414   } \
01415   OQML_STD_REQUAL_1() \
01416   OQML_STD_DECL(X)
01417 
01418 #define OQML_STD_DECL_2(X) \
01419   X(oqmlNode *, oqmlNode *); \
01420   void lock() { \
01421      oqmlNode::lock(); if (qleft) qleft->lock(); if (qright) qright->lock(); \
01422   } \
01423   void unlock() { \
01424      oqmlNode::unlock(); if (qleft) qleft->unlock(); if (qright) qright->unlock(); \
01425   } \
01426   oqmlBool hasIdent(const char *_ident) { \
01427      return OQMLBOOL((qleft && qleft->hasIdent(_ident)) || \
01428                      (qright && qright->hasIdent(_ident))); \
01429   } \
01430   OQML_STD_REQUAL_2() \
01431   OQML_STD_DECL(X)
01432 
01433   /* Class.hierarchy */
01434   class oqmlIdent : public oqmlNode {
01435     char * name;
01436     Class *cls, *__class;
01437     oqmlAtom *cst_atom;
01438     oqmlStatus *evalQuery(Database *db, oqmlContext *ctx,
01439                           oqmlAtomList **alist);
01440   public:
01441     oqmlIdent(const char *);
01442     OQML_STD_DECL(oqmlIdent);
01443     oqmlStatus *evalLeft(Database *db, oqmlContext *ctx,
01444                          oqmlAtom **a, int &idx);
01445     const char *getName() const;
01446     oqmlBool hasIdent(const char *_name) {
01447       return _name && !strcmp(_name, name) ? oqml_True : oqml_False;
01448     }
01449 
01450     oqmlIdent *asIdent() {return this;}
01451     static void initEnumValues(Database *, oqmlContext *ctx);
01452   };
01453 
01454   class oqmlString : public oqmlNode {
01455     char * s;
01456 
01457   public:
01458     oqmlString(const char *);
01459     OQML_STD_DECL(oqmlString);
01460     OQML_STD_REQUAL_0()
01461       };
01462 
01463   class oqmlInt : public oqmlNode {
01464     eyedblib::int64 i;
01465     oqmlNode *ql;
01466 
01467   public:
01468     oqmlInt(eyedblib::int64);
01469     OQML_STD_DECL_1(oqmlInt);
01470   };
01471 
01472   class oqmlChar : public oqmlNode {
01473     char c;
01474 
01475   public:
01476     oqmlChar(char);
01477     OQML_STD_DECL(oqmlChar);
01478     OQML_STD_REQUAL_0()
01479       };
01480 
01481   class oqmlFloat : public oqmlNode {
01482     double f;
01483 
01484   public:
01485     oqmlFloat(double);
01486     OQML_STD_DECL(oqmlFloat);
01487     OQML_STD_REQUAL_0()
01488       };
01489 
01490   class oqmlOid : public oqmlNode {
01491     Oid oid;
01492     Class *cls;
01493     oqmlNode *ql;
01494 
01495   public:
01496     oqmlOid(const Oid&);
01497     OQML_STD_DECL_1(oqmlOid);
01498   };
01499 
01500   class oqmlObject : public oqmlNode {
01501     Object *o;
01502     char *s;
01503     pointer_int_t idx;
01504     oqmlNode *ql;
01505 
01506   public:
01507     oqmlObject(const char *);
01508     oqmlObject(Object *, unsigned int);
01509     OQML_STD_DECL_1(oqmlObject);
01510   };
01511 
01512   class oqmlNil : public oqmlNode {
01513 
01514   public:
01515     OQML_STD_DECL_0(oqmlNil);
01516   };
01517 
01518   class oqmlNull : public oqmlNode {
01519 
01520   public:
01521     OQML_STD_DECL_0(oqmlNull);
01522   };
01523 
01524   class oqmlTrue : public oqmlNode {
01525 
01526   public:
01527     OQML_STD_DECL_0(oqmlTrue);
01528   };
01529 
01530   class oqmlFalse : public oqmlNode {
01531 
01532   public:
01533     OQML_STD_DECL_0(oqmlFalse);
01534   };
01535 
01536   class oqmlRange : public oqmlNode {
01537     oqmlNode * qleft;
01538     oqmlNode * qright;
01539     oqmlBool left_incl, right_incl;
01540     oqmlBool is_between;
01541 
01542   public:
01543     oqmlRange(oqmlNode *, oqmlBool, oqmlNode *, oqmlBool, oqmlBool = oqml_False);
01544     OQML_STD_DECL_2(oqmlRange);
01545   };
01546 
01547   class oqmlStringOp : public oqmlNode {
01548     oqmlNode *ql;
01549 
01550   public:
01551     OQML_STD_DECL_1(oqmlStringOp);
01552   };
01553 
01554   class oqmlIntOp : public oqmlNode {
01555     oqmlNode *ql;
01556 
01557   public:
01558     OQML_STD_DECL_1(oqmlIntOp);
01559   };
01560 
01561   class oqmlCharOp : public oqmlNode {
01562     oqmlNode *ql;
01563 
01564   public:
01565     OQML_STD_DECL_1(oqmlCharOp);
01566   };
01567 
01568   class oqmlFloatOp : public oqmlNode {
01569     oqmlNode *ql;
01570 
01571   public:
01572     OQML_STD_DECL_1(oqmlFloatOp);
01573   };
01574 
01575   class oqmlOidOp : public oqmlNode {
01576     oqmlNode *ql;
01577 
01578   public:
01579     OQML_STD_DECL_1(oqmlOidOp);
01580   };
01581 
01582   class oqmlIdentOp : public oqmlNode {
01583     oqmlNode *ql;
01584 
01585   public:
01586     OQML_STD_DECL_1(oqmlIdentOp);
01587   };
01588 
01589   class oqmlMod : public oqmlNode {
01590     oqmlNode * qleft;
01591     oqmlNode * qright;
01592 
01593   public:
01594     OQML_STD_DECL_2(oqmlMod);
01595   };
01596 
01597   class oqmlAbs : public oqmlNode {
01598     oqmlNode * ql;
01599 
01600   public:
01601     OQML_STD_DECL_1(oqmlAbs);
01602   };
01603 
01604   class oqmlUnion : public oqmlNode {
01605     oqmlNode * qleft;
01606     oqmlNode * qright;
01607 
01608   public:
01609     OQML_STD_DECL_2(oqmlUnion);
01610   };
01611 
01612   class oqmlIntersect : public oqmlNode {
01613     oqmlNode * qleft;
01614     oqmlNode * qright;
01615 
01616   public:
01617     OQML_STD_DECL_2(oqmlIntersect);
01618   };
01619 
01620   class oqmlExcept : public oqmlNode {
01621     oqmlNode * qleft;
01622     oqmlNode * qright;
01623 
01624   public:
01625     OQML_STD_DECL_2(oqmlExcept);
01626   };
01627 
01628   class oqml_ParamLink {
01629 
01630   public:
01631     char *ident;
01632     oqmlNode *node;
01633     oqmlBool unval;
01634     oqml_ParamLink *next;
01635     oqml_ParamLink(const char *, oqmlNode * = 0);
01636     ~oqml_ParamLink();
01637   };
01638 
01639   class oqml_ParamList {
01640 
01641   public:
01642     int cnt;
01643     int min_cnt;
01644     oqml_ParamLink *first;
01645     oqml_ParamLink *last;
01646     oqml_ParamList(const char *, oqmlNode * = 0);
01647     void add(const char *, oqmlNode * = 0);
01648     void lock();
01649     void unlock();
01650     std::string toString() const;
01651     ~oqml_ParamList();
01652   };
01653 
01654   class oqmlFunction : public oqmlNode {
01655     char *name;
01656     oqmlNode *ql;
01657     oqml_ParamList *param_list;
01658 
01659   public:
01660     oqmlFunction(const char *, oqml_ParamList *, oqmlNode *);
01661     OQML_STD_DECL(oqmlFunction);
01662     OQML_STD_REQUAL_0()
01663       void lock();
01664     void unlock();
01665   };
01666 
01667   class oqmlCall : public oqmlNode {
01668     char *name;
01669     oqmlFunctionEntry *entry;
01670     oqml_List *list;
01671     oqmlNode *ql;
01672     oqmlNode *qlbuiltin; // context argument
01673     oqmlNode *last_builtin;
01674     oqmlFunctionEntry *last_entry;
01675     oqmlBool deferredEval;
01676     oqmlBool checkBuiltIn(Database *, oqmlNode *, const char *, int);
01677     oqmlBool compiling;
01678     oqmlStatus *realize(Database *db, oqmlContext *, oqmlAtomList **);
01679 
01680   public:
01681     oqmlCall(const char *, oqml_List *);
01682     oqmlCall(const char *, oqmlNode *);
01683     oqmlCall(oqmlNode *, oqml_List *);
01684 
01685     OQML_STD_DECL(oqmlCall);
01686     oqmlBool hasIdent(const char *);
01687 
01688     oqmlNode *getBuiltIn() {return qlbuiltin;}
01689     oqmlStatus *preCompile(Database *, oqmlContext *);
01690     oqmlStatus *postCompile(Database *, oqmlContext *, oqmlBool);
01691     void lock();
01692     void unlock();
01693 
01694     oqmlStatus *requalify(Database *, oqmlContext *, const char *_ident, oqmlNode *node, oqmlBool &done);
01695     oqmlStatus *requalify(Database *, oqmlContext *, const Attribute **attrs, int attr_cnt, 
01696                           const char *_ident);
01697     oqmlStatus *requalify_back(Database *, oqmlContext *);
01698 
01699     static oqmlStatus *realizePostAction(Database *db, oqmlContext *ctx,
01700                                          const char *name,
01701                                          oqmlFunctionEntry *entry, 
01702                                          oqmlAtom_string *rs,
01703                                          oqmlAtom *ra,
01704                                          oqmlAtomList **alist);
01705 
01706     static oqmlStatus *realizeCall(Database *db, oqmlContext *,
01707                                    oqmlFunctionEntry *entry,
01708                                    oqmlAtomList **);
01709     static oqmlBool getBuiltIn(Database *, oqmlNode *, const char *name, int, oqmlNode ** = 0, oqml_List * = 0);
01710 
01711     const char *getName() const {return name;}
01712     oqml_List *getList() {return list;}
01713   };
01714 
01715   class oqmlMethodCall : public oqmlNode {
01716     char *clsname;
01717     char *mthname;
01718     oqml_List * list;
01719     oqmlBool deleteList;
01720     Method *mth;
01721     const Class *cls;
01722     oqmlBool is_compiled;
01723     oqmlNode *call;
01724     struct {
01725       const Class *cls;
01726       Bool isStatic;
01727       Method *xmth;
01728     } last;
01729   public:
01730     enum Match {
01731       no_match = 0,
01732       exact_match,
01733       match
01734     };
01735   private:
01736     void init(const char *, const char *, oqml_List *);
01737     oqmlStatus *checkStaticMethod();
01738     oqmlStatus *findStaticMethod(Database *db, oqmlContext *);
01739     oqmlStatus *evalList(Database *db, oqmlContext *ctx);
01740     const char *getSignature(oqmlContext *);
01741     oqmlStatus *checkArguments(Database *db, oqmlContext *ctx,
01742                                const Method *, Match * = 0);
01743     oqmlStatus *noMethod(Bool isStatic, oqmlContext *,
01744                          const Method **mths = 0,
01745                          int mth_cnt = 0);
01746     oqmlStatus *resolveMethod(Database *db, oqmlContext *ctx,
01747                               Bool isStatic, Object *, Method *&xmth);
01748     unsigned int getArgCount(const Argument *arg, ArgType_Type odl_type);
01749     oqmlStatus *makeArg(Argument &tmp, ArgType_Type odl_type,
01750                         const Argument *arg, int j);
01751     oqmlStatus *buildArgArray(Argument *arg, oqmlAtomList *list,
01752                               ArgType_Type odl_type, int n);
01753     oqmlStatus *fillArgArray(Signature *, Argument *arg, Argument tmp,
01754                              ArgType_Type odl_type, int j);
01755     oqmlStatus *atomToArg(Database *db, oqmlContext *ctx,
01756                           Signature *sign, oqmlAtom *,
01757                           ArgType *, ArgType_Type, Argument *, int);
01758     oqmlStatus *atomsToArgs(Database *db, oqmlContext *ctx,
01759                             Method *xmth, ArgArray &);
01760     oqmlStatus *argToAtom(const Argument *arg, int n, oqmlAtomType &at,
01761                           oqmlAtom *&);
01762     oqmlStatus *argsToAtoms(Database *db, oqmlContext *ctx,
01763                             Method *xmth, const ArgArray &,
01764                             const Argument &retarg, oqmlAtom *&retatom);
01765     oqmlStatus *applyC(Database *db, oqmlContext *ctx,
01766                        Method *xmth, oqmlAtomList **alist,
01767                        Object * = 0, const Oid *oid = 0);
01768     oqmlStatus *applyOQL(Database *db, oqmlContext *ctx,
01769                          Method *xmth, oqmlAtomList **alist,
01770                          Object * = 0, const Oid *oid = 0);
01771     static Match compareType(oqmlContext *ctx, int n, oqmlAtom *x,
01772                              int odl_type, Bool strict);
01773     oqmlStatus *typeMismatch(const Signature *sign, oqmlAtomType &at, int n);
01774     oqmlStatus *typeMismatch(ArgType *type, Object *o, int n);
01775     oqmlBool compareAtomTypes();
01776     oqmlAtom **atoms;
01777     oqmlAtom **tmp_atoms;
01778     oqmlBool noParenthesis;
01779 
01780   public:
01781     oqmlMethodCall(const char *, oqml_List *, oqmlBool = oqml_False);
01782     oqmlMethodCall(const char *, const char *, oqml_List *,
01783                    oqmlNode * = 0);
01784 
01785     OQML_STD_DECL(oqmlMethodCall);
01786     oqmlBool hasIdent(const char *);
01787     static oqmlStatus *applyTrigger(Database *db, Trigger *trig,
01788                                     Object *o, const Oid *oid);
01789 
01790 
01791     void lock();
01792     void unlock();
01793 
01794     oqmlStatus *perform(Database *db, oqmlContext *ctx,
01795                         Object *, const Oid &oid, const Class *cls,
01796                         oqmlAtomList **alist);
01797     oqmlBool isCompiled() const {return is_compiled;}
01798   };
01799 
01800   class oqmlAdd : public oqmlNode {
01801     oqmlNode * qleft;
01802     oqmlNode * qright;
01803     oqmlBool unary;
01804 
01805   public:
01806     oqmlAdd(oqmlNode *, oqmlNode *, oqmlBool unary);
01807     OQML_STD_DECL_2(oqmlAdd);
01808   };
01809 
01810   class oqmlSub : public oqmlNode {
01811     oqmlNode * qleft;
01812     oqmlNode * qright;
01813     oqmlBool unary;
01814 
01815   public:
01816     oqmlSub(oqmlNode *, oqmlNode *, oqmlBool unary);
01817     OQML_STD_DECL_2(oqmlSub);
01818   };
01819 
01820   class oqmlMul : public oqmlNode {
01821     oqmlNode * qleft;
01822     oqmlNode * qright;
01823 
01824   public:
01825     OQML_STD_DECL_2(oqmlMul);
01826   };
01827 
01828   class oqmlDiv : public oqmlNode {
01829     oqmlNode * qleft;
01830     oqmlNode * qright;
01831 
01832   public:
01833     OQML_STD_DECL_2(oqmlDiv);
01834   };
01835 
01836   class oqmlShr : public oqmlNode {
01837     oqmlNode * qleft;
01838     oqmlNode * qright;
01839 
01840   public:
01841     OQML_STD_DECL_2(oqmlShr);
01842   };
01843 
01844   class oqmlShl : public oqmlNode {
01845     oqmlNode * qleft;
01846     oqmlNode * qright;
01847 
01848   public:
01849     OQML_STD_DECL_2(oqmlShl);
01850   };
01851 
01852   class oqmlXor : public oqmlNode {
01853     oqmlNode * qleft;
01854     oqmlNode * qright;
01855 
01856   public:
01857     OQML_STD_DECL_2(oqmlXor);
01858   };
01859 
01860   class oqmlTilde : public oqmlNode {
01861     oqmlNode * ql;
01862 
01863   public:
01864     OQML_STD_DECL_1(oqmlTilde);
01865   };
01866 
01867   class oqmlUnset : public oqmlNode {
01868     oqmlNode * ql;
01869     char *ident;
01870 
01871   public:
01872     OQML_STD_DECL_1(oqmlUnset);
01873   };
01874 
01875   class oqmlIsset : public oqmlNode {
01876     oqmlNode * ql;
01877     char *ident;
01878 
01879   public:
01880     OQML_STD_DECL_1(oqmlIsset);
01881   };
01882 
01883   class oqmlSet : public oqmlNode {
01884     char *ident;
01885     oqmlNode *ql;
01886 
01887   public:
01888     oqmlSet(const char *, oqmlNode *);
01889     OQML_STD_DECL(oqmlSet);
01890 
01891     void lock() {oqmlNode::lock(); ql->lock();}
01892     void unlock() {oqmlNode::unlock(); ql->unlock();}
01893   };
01894 
01895   class oqmlTypeOf : public oqmlNode {
01896     oqmlNode *ql;
01897 
01898   public:
01899     OQML_STD_DECL_1(oqmlTypeOf);
01900   };
01901 
01902   class oqmlBreak : public oqmlNode {
01903     oqmlNode *ql;
01904 
01905   public:
01906     OQML_STD_DECL_1(oqmlBreak);
01907   };
01908 
01909   class oqmlEval : public oqmlNode {
01910     oqmlNode *ql;
01911 
01912   public:
01913     OQML_STD_DECL_1(oqmlEval);
01914   };
01915 
01916   class oqmlUnval : public oqmlNode {
01917     oqmlNode *ql;
01918 
01919   public:
01920     OQML_STD_DECL_1(oqmlUnval);
01921   };
01922 
01923   class oqmlPrint : public oqmlNode {
01924     oqmlNode *ql;
01925 
01926   public:
01927     OQML_STD_DECL_1(oqmlPrint);
01928   };
01929 
01930   class oqmlImport : public oqmlNode {
01931     oqmlNode *ql;
01932     static const char *get_next_path(const char *oqmlpath, int &idx);
01933     oqmlStatus *file_to_buf(const char *file, int fd, char *&);
01934     oqmlStatus *import_realize(Database *db, oqmlAtomList **alist,
01935                                const char *file, const char *dir,
01936                                oqmlBool &check);
01937 
01938   public:
01939     OQML_STD_DECL_1(oqmlImport);
01940   };
01941 
01942   class oqmlValRefOf : public oqmlNode {
01943 
01944   public:
01945     oqmlValRefOf(oqmlNode *, oqmlTYPE, const char *);
01946     void lock() {oqmlNode::lock(); if (ql) ql->lock();}
01947     void unlock() {oqmlNode::unlock(); if (ql) ql->unlock();}
01948     ~oqmlValRefOf();
01949 
01950   protected:
01951     oqmlNode *ql;
01952     char *ident; // context argument
01953     char *opstr;
01954     static char *makeIdent(oqmlContext *ctx, const char *ident);
01955     oqmlStatus *realizeIdent(Database *db, oqmlContext *ctx);
01956   };
01957 
01958   class oqmlRefOf : public oqmlValRefOf {
01959 
01960   public:
01961     oqmlRefOf(oqmlNode *);
01962     oqmlStatus *evalLeft(Database *db, oqmlContext *ctx, oqmlAtom **a,
01963                          int &idx);
01964     OQML_STD_DECL(oqmlRefOf);
01965   };
01966 
01967   class oqmlValOf : public oqmlValRefOf {
01968 
01969   public:
01970     oqmlValOf(oqmlNode *);
01971     oqmlStatus *evalLeft(Database *db, oqmlContext *ctx, oqmlAtom **a,
01972                          int &idx);
01973     OQML_STD_DECL(oqmlValOf);
01974   };
01975 
01976   class oqmlThrow : public oqmlNode {
01977     oqmlNode *ql;
01978 
01979   public:
01980     OQML_STD_DECL_1(oqmlThrow);
01981   };
01982 
01983   class oqmlReturn : public oqmlNode {
01984     oqmlNode *ql;
01985 
01986   public:
01987     OQML_STD_DECL_1(oqmlReturn);
01988   };
01989 
01990   class oqmlWhile : public oqmlNode {
01991     oqmlNode * qleft, * qright;
01992 
01993   public:
01994     OQML_STD_DECL_2(oqmlWhile);
01995   };
01996 
01997   class oqmlDoWhile : public oqmlNode {
01998     oqmlNode * qleft, * qright;
01999 
02000   public:
02001     OQML_STD_DECL_2(oqmlDoWhile);
02002   };
02003 
02004   class oqmlForDo : public oqmlNode {
02005     oqmlNode *start, *cond, *next, *body;
02006     char *ident;
02007 
02008   public:
02009     OQML_STD_DECL(oqmlForDo);
02010     oqmlForDo(oqmlNode *, oqmlNode *, oqmlNode *, oqmlNode *);
02011     oqmlForDo(const char *, oqmlNode *, oqmlNode *, oqmlNode *, oqmlNode *);
02012     oqmlBool hasIdent(const char *);
02013     void lock();
02014     void unlock();
02015   };
02016 
02017   class oqmlStruct : public oqmlNode {
02018     oqml_IdentList *list;
02019 
02020   public:
02021     OQML_STD_DECL(oqmlStruct);
02022     oqmlBool hasIdent(const char *);
02023     oqmlStruct(oqml_IdentList *);
02024     void lock();
02025     void unlock();
02026   };
02027 
02028   class oqmlAAnd : public oqmlNode {
02029     oqmlNode * qleft;
02030     oqmlNode * qright;
02031 
02032   public:
02033     OQML_STD_DECL_2(oqmlAAnd);
02034   };
02035 
02036   class oqmlAOr : public oqmlNode {
02037     oqmlNode * qleft;
02038     oqmlNode * qright;
02039 
02040   public:
02041     OQML_STD_DECL_2(oqmlAOr);
02042   };
02043 
02044   class oqmlEqual : public oqmlComp {
02045 
02046   public:
02047     oqmlEqual(oqmlNode *, oqmlNode *);
02048     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02049     ~oqmlEqual();
02050     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02051   };
02052 
02053   class oqmlDiff : public oqmlComp {
02054 
02055   public:
02056     oqmlDiff(oqmlNode *, oqmlNode *);
02057     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02058     ~oqmlDiff();
02059     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02060   };
02061 
02062   class oqmlInf : public oqmlComp {
02063 
02064   public:
02065     oqmlInf(oqmlNode *, oqmlNode *);
02066     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02067     ~oqmlInf();
02068     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02069   };
02070 
02071   class oqmlInfEq : public oqmlComp {
02072 
02073   public:
02074     oqmlInfEq(oqmlNode *, oqmlNode *);
02075     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02076     ~oqmlInfEq();
02077     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02078   };
02079 
02080   class oqmlSup : public oqmlComp {
02081 
02082   public:
02083     oqmlSup(oqmlNode *, oqmlNode *);
02084     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02085     ~oqmlSup();
02086     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02087   };
02088 
02089   class oqmlSupEq : public oqmlComp {
02090 
02091   public:
02092     oqmlSupEq(oqmlNode *, oqmlNode *);
02093     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02094     ~oqmlSupEq();
02095     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02096   };
02097 
02098   class oqmlBetween : public oqmlComp {
02099 
02100   public:
02101     oqmlBetween(oqmlNode *, oqmlNode *);
02102     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02103     ~oqmlBetween();
02104     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02105     oqmlNode *requalifyNot();
02106   };
02107 
02108   class oqmlNotBetween : public oqmlComp {
02109 
02110   public:
02111     oqmlNotBetween(oqmlNode *, oqmlNode *);
02112     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02113     ~oqmlNotBetween();
02114     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02115   };
02116 
02117   class oqmlRegex : public oqmlComp {
02118 
02119     oqmlStatus *eval_realize(oqmlAtom *, oqmlAtomList **);
02120 
02121   protected:
02122 #ifdef USE_LIBGEN
02123     char *re;
02124 #endif
02125     regex_t *re;
02126 
02127   public:
02128     oqmlRegex(oqmlTYPE t, oqmlNode *_qleft, oqmlNode *_qright, const char *_opstr) :
02129       oqmlComp(t, _qleft, _qright, _opstr), re(0) {
02130     }
02131 
02132     oqmlStatus *estimate(Database *, oqmlContext *, unsigned int &);
02133     oqmlStatus *compile(Database *db, oqmlContext *ctx);
02134     oqmlStatus *eval(Database *db, oqmlContext *ctx, oqmlAtomList **alist, oqmlComp * = NULL, oqmlAtom * = NULL);
02135     ~oqmlRegex()
02136     {
02137 #ifdef USE_LIBGEN
02138       free(re);
02139 #endif
02140       if (re)
02141         regfree( re);
02142     }
02143 
02144     oqmlStatus *complete(Database *, oqmlContext *ctx, oqmlAtom *);
02145 
02146   protected:
02147     oqmlIterator *makeIter(Database *, oqmlDotContext *,
02148                            oqmlAtom *, bool iregcmp);
02149   };
02150 
02151   class oqmlRegCmp : public oqmlRegex {
02152 
02153   public:
02154     oqmlRegCmp(oqmlNode *, oqmlNode *);
02155     ~oqmlRegCmp();
02156     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02157   };
02158 
02159   class oqmlRegICmp : public oqmlRegex {
02160 
02161   public:
02162     oqmlRegICmp(oqmlNode *, oqmlNode *);
02163     ~oqmlRegICmp();
02164     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02165   };
02166 
02167   class oqmlRegDiff : public oqmlRegex {
02168 
02169   public:
02170     oqmlRegDiff(oqmlNode *, oqmlNode *);
02171     ~oqmlRegDiff();
02172     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02173   };
02174 
02175   class oqmlRegIDiff : public oqmlRegex {
02176 
02177   public:
02178     oqmlRegIDiff(oqmlNode *, oqmlNode *);
02179     ~oqmlRegIDiff();
02180     oqmlStatus *makeIterator(Database *, oqmlDotContext *, oqmlAtom *);
02181   };
02182 
02183   class oqmlIf : public oqmlNode {
02184     oqmlNode *qcond, *qthen, *qelse;
02185     oqmlBool qthen_compiled, qelse_compiled;
02186     oqmlBool is_cond_expr;
02187 
02188   public:
02189     oqmlIf(oqmlNode *, oqmlNode *, oqmlNode *, oqmlBool);
02190     OQML_STD_DECL(oqmlIf);
02191     oqmlBool hasIdent(const char *);
02192 
02193     void lock() {
02194       oqmlNode::lock(); 
02195       qcond->lock();
02196       qthen->lock();
02197       if (qelse) qelse->lock();
02198     }
02199 
02200     void unlock() {
02201       oqmlNode::unlock(); 
02202       qcond->unlock();
02203       qthen->unlock();
02204       if (qelse) qelse->unlock();
02205     }
02206   };
02207 
02208   class oqmlLNot : public oqmlNode {
02209     oqmlNode * ql;
02210 
02211   public:
02212     OQML_STD_DECL_1(oqmlLNot);
02213   };
02214 
02215   class oqmlLinkItem;
02216 
02217   class oqml_ArrayLink {
02218 
02219   public:
02220     oqmlBool wholeRange;
02221     oqmlNode *qleft, *qright;
02222     oqml_ArrayLink *next;
02223     oqml_ArrayLink(oqmlBool);
02224     oqml_ArrayLink(oqmlNode *, oqmlNode * = NULL);
02225     oqmlStatus *compile(Database *db, oqmlContext *ctx);
02226     oqmlStatus *eval(oqmlNode *, Database *db, oqmlContext *ctx, oqmlLinkItem &item);
02227     oqmlBool hasIdent(const char *);
02228     virtual std::string toString() const;
02229     void lock();
02230     void unlock();
02231     oqmlBool wholeCount;
02232     oqmlBool isGetCount() const;
02233 
02234     ~oqml_ArrayLink();
02235   };
02236 
02237   class oqml_ArrayList {
02238 
02239   public:
02240     int count;
02241     oqmlBool wholeRange;
02242     oqml_ArrayLink *first;
02243     oqml_ArrayLink *last;
02244     oqml_ArrayList();
02245     oqmlBool is_getcount;
02246     oqmlBool is_wholecount;
02247     oqmlStatus *eval(oqmlNode *, Database *, oqmlContext *, const char *,
02248                      const char *, const TypeModifier*, int *, int *, oqmlBool);
02249     void add(oqml_ArrayLink *);
02250     oqmlStatus *compile(Database *db, oqmlContext *ctx);
02251     oqmlStatus *eval(oqmlNode *, Database *db, oqmlContext *ctx, oqmlLinkItem *&item,
02252                      int &item_cnt);
02253     virtual std::string toString() const;
02254     oqmlBool hasIdent(const char *);
02255     void lock();
02256     void unlock();
02257     oqmlStatus *checkCollArray(oqmlNode *node, const Class *cls,
02258                                const char *attrname);
02259     oqmlStatus *evalCollArray(oqmlNode *node, Database *db,
02260                               oqmlContext *ctx,
02261                               const TypeModifier *tmod, int &ind);
02262 
02263     ~oqml_ArrayList();
02264   };
02265 
02266   class oqmlArray : public oqmlNode {
02267     oqmlNode *ql;
02268     oqml_ArrayList *list;
02269     oqmlStatus *evalRealize(Database *db, oqmlContext *ctx, 
02270                             oqmlAtomList **alist, oqmlAtom **a,
02271                             int *ridx);
02272     oqmlStatus *evalRealize_1(Database *db, oqmlContext *ctx, 
02273                               oqmlAtom *x, oqmlAtomList **alist, oqmlAtom **a,
02274                               int *ridx);
02275     oqmlStatus *evalRealize_2(Database *db, oqmlContext *ctx, 
02276                               oqmlAtom *x, oqmlAtomList **alist, oqmlAtom **a,
02277                               int *ridx);
02278     oqmlStatus *checkRange(oqmlLinkItem *items, int dim, int idx, int len,
02279                            oqmlBool &stop, const char *msg);
02280 
02281     oqmlBool delegationArray, returnStruct;
02282   public:
02283     OQML_STD_DECL(oqmlArray);
02284     oqmlArray(oqmlNode *);
02285     oqmlArray(oqmlNode *, oqml_ArrayList *, oqmlBool);
02286     oqmlBool hasIdent(const char *);
02287 
02288     void lock();
02289     void unlock();
02290 
02291     static oqmlStatus *evalMake(Database *db, oqmlContext *ctx,
02292                                 Object *o, oqml_ArrayList *list,
02293                                 oqmlBool, oqmlAtomList **);
02294 
02295     oqmlStatus *evalLeft(Database *db, oqmlContext *ctx, oqmlAtom **a,
02296                          int &idx);
02297 
02298     void add(oqml_ArrayLink *);
02299     oqmlNode *getLeft();
02300     oqml_ArrayList *getArrayList();
02301   };
02302 
02303   class oqmlCast : public oqmlNode {
02304     char * ident;
02305     oqmlNode * qright;
02306 
02307   public:
02308     oqmlCast(const char *, oqmlNode *);
02309     OQML_STD_DECL(oqmlCast);
02310   };
02311 
02312   class oqmlAnd : public oqmlNode {
02313     oqmlNode * qleft;
02314     oqmlNode * qright;
02315     int xc;
02316     oqmlStatus *check(Database *db, oqmlContext *ctx);
02317     oqmlStatus *eval_0(Database *db, oqmlContext *ctx, oqmlAtomList **alist);
02318     oqmlStatus *eval_1(Database *db, oqmlContext *ctx, oqmlAtomList **alist);
02319     oqmlNode *optimize_realize(Database *, oqmlContext *, oqmlNode *, int &);
02320     void optimize(Database *, oqmlContext *);
02321 
02322   public:
02323     OQML_STD_DECL_2(oqmlAnd);
02324   };
02325 
02326   class oqmlOr : public oqmlNode {
02327     oqmlNode * qleft;
02328     oqmlNode * qright;
02329 
02330   public:
02331     OQML_STD_DECL_2(oqmlOr);
02332   };
02333 
02334   class oqmlLAnd : public oqmlNode {
02335     oqmlNode * qleft;
02336     oqmlNode * qright;
02337     oqmlNode * node;
02338     oqmlBool isLiteral;
02339     oqmlNode *intersect_pred;
02340     oqmlBool must_intersect;
02341     oqmlBool estimated;
02342     oqmlBool requalified;
02343     unsigned int r_first, r_second;
02344 
02345     oqmlStatus *preEvalSelect_optim(Database *db, oqmlContext *ctx,
02346                                     const char *ident, oqmlBool &done,
02347                                     unsigned int &cnt, oqmlBool firstPass);
02348     oqmlStatus *preEvalSelect_nooptim(Database *db, oqmlContext *ctx,
02349                                       const char *ident, oqmlBool &done,
02350                                       unsigned int &cnt, oqmlBool firstPass);
02351     oqmlNode *requalifyRange();
02352     oqmlStatus *estimateLAnd(Database *db, oqmlContext *ctx);
02353     static oqmlBool isAndOptim(oqmlContext *);
02354 
02355   public:
02356     OQML_STD_DECL(oqmlLAnd);
02357     oqmlLAnd(oqmlNode *, oqmlNode *, oqmlBool, oqmlNode *must_intersect = 0);
02358 
02359     void lock();
02360     void unlock();
02361 
02362     oqmlBool hasIdent(const char *_ident) {
02363       return (node ? node->hasIdent(_ident) :
02364               OQMLBOOL(qleft->hasIdent(_ident) ||
02365                        qright->hasIdent(_ident)));
02366     }
02367 
02368     oqmlStatus *preEvalSelect(Database *db, oqmlContext *ctx,
02369                               const char *ident, oqmlBool &done,
02370                               unsigned int &cnt, oqmlBool firstPass = oqml_True);
02371     oqmlStatus *requalify(Database *, oqmlContext *, const char *_ident, oqmlNode *_node, oqmlBool &done);
02372     oqmlStatus *requalify(Database *db, oqmlContext *ctx, const Attribute **attrs, int attr_cnt,
02373                           const char *_ident) {
02374       oqmlStatus *s = requalify_node(db, ctx, qleft, attrs, attr_cnt, _ident);
02375       if (s) return s;
02376       return requalify_node(db, ctx, qright, attrs, attr_cnt, _ident);
02377     }
02378 
02379     oqmlStatus *requalify_back(Database *, oqmlContext *);
02380     static const char *getDefaultRule();
02381   };
02382 
02383   class oqmlLOr : public oqmlNode {
02384     oqmlNode * qleft;
02385     oqmlNode * qright;
02386     oqmlNode * node;
02387     oqmlBool isLiteral;
02388 
02389   public:
02390     OQML_STD_DECL(oqmlLOr);
02391     oqmlLOr(oqmlNode *, oqmlNode *, oqmlBool);
02392 
02393     OQML_STD_REQUAL_2()
02394 
02395       void lock();
02396     void unlock();
02397 
02398     oqmlBool hasIdent(const char *_ident) {
02399       return (node ? node->hasIdent(_ident) :
02400               OQMLBOOL(qleft->hasIdent(_ident) ||
02401                        qright->hasIdent(_ident)));
02402     }
02403 
02404     oqmlStatus *preEvalSelect(Database *db, oqmlContext *ctx,
02405                               const char *ident, oqmlBool &done,
02406                               unsigned int &cnt, oqmlBool firstPass = oqml_True);
02407   };
02408 
02409   class oqmlComma : public oqmlNode {
02410     oqmlNode * qleft;
02411     oqmlNode * qright;
02412 
02413   public:
02414     OQML_STD_DECL_2(oqmlComma);
02415     oqmlComma(oqmlNode *, oqmlNode *, oqmlBool);
02416   };
02417 
02418   class oqmlNew : public oqmlNode {
02419 
02420     oqmlStatus *makeAtom(Database *db, oqmlContext *ctx, Object *o,
02421                          oqmlAtom *&);
02422 
02423     oqmlStatus *compileNode(Database *db, oqmlContext *ctx,
02424                             const Class *cls);
02425     oqmlStatus *compileIdent(Database *db, oqmlContext *ctx,
02426                              const Class *cls, oqmlNode *left,
02427                              int n, int &ndims);
02428     oqmlStatus *compileDot(Database *db, oqmlContext *ctx,
02429                            const Class *cls, oqmlNode *left,
02430                            int n, int &ndims);
02431     oqmlStatus *compileArray(Database *db, oqmlContext *ctx,
02432                              const Class *cls, oqmlNode *left,
02433                              int n, int &ndims);
02434     oqmlStatus *evalNode(Database *db, oqmlContext *ctx,
02435                          oqmlAtomList **alist);
02436 
02437     oqmlStatus *evalItem(Database *db, oqmlContext *ctx,
02438                          Agregat *o, oqml_IdentLink *l, int n,
02439                          oqmlBool &, oqmlAtomList **alist);
02440 
02441   public:
02442     char *ident;
02443     oqml_IdentList *ident_list;
02444     oqmlNode *ql;
02445     oqmlAtom *cst_atom;
02446     Class *_class;
02447     oqmlNode *location;
02448     Database *newdb;
02449     char *quoted_odl;
02450 
02451     class newCompile {
02452 
02453     public:
02454       Class *cls;
02455       int cnt;
02456       Attribute **attr;
02457       char **attrname;
02458       oqml_ArrayList **list;
02459       oqmlDotContext **dot_ctx;
02460     
02461       newCompile(Class *, int);
02462       ~newCompile();
02463     } *comp;
02464 
02465   public:
02466     oqmlNew(oqmlNode *, const char *, oqml_IdentList *);
02467     oqmlNew(oqmlNode *, const char *, oqmlNode *);
02468     oqmlNew(oqmlNode *, const char *);
02469     OQML_STD_DECL(oqmlNew);
02470     void lock();
02471     void unlock();
02472   };
02473 
02474   class oqml_CollSpec {
02475 
02476   public:
02477     char *coll_type;
02478     char *type_spec;
02479     char *ident;
02480     Bool isref;
02481     Bool ishash;
02482     char *impl_hints;
02483     oqml_CollSpec *coll_spec;
02484 
02485     oqml_CollSpec(const char *coll_type, const char *type_spec,
02486                   oqmlBool isref = oqml_True, const char *name = "",
02487                   oqmlBool ishash = oqml_True, const char *impl_hints = 0);
02488     oqml_CollSpec(const char *coll_type, oqml_CollSpec *type_spec,
02489                   oqmlBool isref = oqml_True, const char *name = "",
02490                   oqmlBool ishash = oqml_True, const char *impl_hints = 0);
02491     std::string toString() const;
02492     ~oqml_CollSpec();
02493   };
02494 
02495   class oqmlCollection : public oqmlNode {
02496     oqmlNode *location;
02497     Database *newdb;
02498     oqmlNode *ql;
02499     oqml_CollSpec *coll_spec;
02500     oqmlAtomType atref;
02501 
02502     Class *cls;
02503     enum {
02504       collset,
02505       collbag,
02506       colllist,
02507       collarray
02508     } what;
02509 
02510   public:
02511     oqmlCollection(oqmlNode *location, oqml_CollSpec *, oqmlNode *);
02512     OQML_STD_DECL(oqmlCollection);
02513     void lock();
02514     void unlock();
02515   };
02516 
02517   class oqmlColl : public oqmlNode {
02518 
02519     oqml_List *list;
02520 
02521   public:
02522     oqmlColl(oqml_List *, oqmlTYPE type);
02523     OQML_STD_DECL(oqmlColl);
02524     void lock()   {oqmlNode::lock();   if (list) list->lock();}
02525     void unlock() {oqmlNode::unlock(); if (list) list->unlock();}
02526     virtual const char *getTypeName() const = 0;
02527     virtual oqmlAtom_coll *makeAtomColl(oqmlAtomList *l) = 0;
02528     oqml_List *getList() {return list;}
02529   };
02530 
02531   class oqmlListColl : public oqmlColl {
02532 
02533   public:
02534     oqmlListColl(oqml_List *);
02535     const char *getTypeName() const {return "list";}
02536     oqmlAtom_coll *makeAtomColl(oqmlAtomList *l) {
02537       return new oqmlAtom_list(l);
02538     }
02539   };
02540 
02541   class oqmlSetColl : public oqmlColl {
02542 
02543   public:
02544     oqmlSetColl(oqml_List *);
02545     const char *getTypeName() const {return "set";}
02546     oqmlAtom_coll *makeAtomColl(oqmlAtomList *l) {
02547       return new oqmlAtom_set(l);
02548     }
02549   };
02550 
02551   class oqmlBagColl : public oqmlColl {
02552 
02553   public:
02554     oqmlBagColl(oqml_List *);
02555     const char *getTypeName() const {return "bag";}
02556     oqmlAtom_coll *makeAtomColl(oqmlAtomList *l) {
02557       return new oqmlAtom_bag(l);
02558     }
02559   };
02560 
02561   class oqmlArrayColl : public oqmlColl {
02562 
02563   public:
02564     oqmlArrayColl(oqml_List *);
02565     const char *getTypeName() const {return "array";}
02566     oqmlAtom_coll *makeAtomColl(oqmlAtomList *l) {
02567       return new oqmlAtom_array(l);
02568     }
02569   };
02570 
02571   class oqml_ClassSpec {
02572 
02573   public:
02574     char *classname;
02575     char *parentname;
02576 
02577     oqml_ClassSpec(char *, char *);
02578     ~oqml_ClassSpec();
02579   };
02580 
02581   class oqmlDelete : public oqmlNode {
02582     oqmlNode * ql;
02583 
02584   public:
02585     OQML_STD_DECL_1(oqmlDelete);
02586   };
02587 
02588   class oqmlClassOf : public oqmlNode {
02589     oqmlNode *ql;
02590 
02591   public:
02592     OQML_STD_DECL_1(oqmlClassOf);
02593   };
02594 
02595   class oqmlCastIdent : public oqmlNode {
02596     char *name;
02597     char *modname;
02598 
02599   public:
02600     oqmlCastIdent(const char *, const char *);
02601     OQML_STD_DECL(oqmlCastIdent);
02602     const char *getName(const char **) const;
02603   };
02604 
02605   class oqmlDot : public oqmlNode {
02606     oqmlNode * qleft;
02607     oqmlNode * qright;
02608     oqmlNode * qlmth;
02609     oqmlBool isArrow;
02610     oqmlDotContext *dot_ctx;
02611     oqmlStatus *getAttrRealize(const Class *, const char *,
02612                                const Attribute **);
02613     oqmlStatus * getAttr(Database *db, oqmlContext *ctx,
02614                          const Class *cls, oqmlAtom *,
02615                          const char *name, const Attribute **attr,
02616                          oqmlAtom **curatom);
02617     oqmlStatus *oqmlDot_left(Database *db,
02618                              oqmlContext *ctx,
02619                              const Class *cls,
02620                              oqmlAtom *curatom,
02621                              Attribute **attr,
02622                              oqmlAtom **rcuratom,
02623                              Class **castcls,
02624                              char **attrname);
02625 
02626     oqmlStatus *complete(Database *db, oqmlContext *ctx);
02627     oqmlStatus *eval_realize_list(Database *db, oqmlContext *ctx,
02628                                   oqmlAtomList *,
02629                                   oqmlAtom *value, oqmlAtomList **, int level);
02630     static void makeUnion(oqmlContext *, oqmlAtom_select *, oqmlAtomList *list);
02631     static void makeIntersect(oqmlContext *, oqmlAtom_select *, oqmlAtomList *list);
02632     static void makeSet(oqmlContext *, oqmlAtom_select *, oqmlAtomList *list);
02633 
02634   public:
02635     OQML_STD_DECL(oqmlDot);
02636     oqmlBool hasIdent(const char *);
02637     oqmlDot(oqmlNode *, oqmlNode *, oqmlBool isArrow);
02638     oqmlStatus *isScope(Database *db, const char* x, const char*& attrname,
02639                         const Class *&cls, const Attribute **attr = 0);
02640     oqmlStatus *populate(Database *db, oqmlContext *ctx, oqmlAtomList *,
02641                          oqmlBool makeUnion);
02642     void lock();
02643     void unlock();
02644 
02645     void setIndexHint(oqmlContext *, oqmlBool);
02646     oqmlStatus *hasIndex(Database *db, oqmlContext *ctx, oqmlBool &);
02647     oqmlStatus *reinit(Database *db, oqmlContext *ctx,
02648                        oqmlBool compile = oqml_True);
02649     const char *getLeftIdent() const;
02650     void replaceLeftIdent(const char *ident, oqmlNode *node, oqmlBool &done);
02651     oqmlBool constructed;
02652     oqmlBool populated;
02653     oqmlStatus *construct(Database *, oqmlContext *, const Class *,
02654                           oqmlAtom *, oqmlDotContext **);
02655     oqmlStatus *set(Database *db, oqmlContext *ctx, oqmlAtom *value,
02656                     oqmlAtomList **alist);
02657     oqmlStatus *compile_start(Database *db, oqmlContext *ctx);
02658     oqmlStatus *compile_continue(Database *db, oqmlContext *ctx,
02659                                  oqmlDotContext *);
02660     oqmlStatus *eval_realize(Database *db, oqmlContext *ctx,
02661                              const Class *cls,
02662                              oqmlAtom *atom, oqmlAtom *value, oqmlAtomList **);
02663     oqmlStatus *eval_perform(Database *db, oqmlContext *ctx,
02664                              oqmlAtom *value, oqmlAtomList **alist);
02665     virtual oqmlStatus *requalify_back(Database *db, oqmlContext *ctx);
02666 
02667     oqmlArray *make_right_array();
02668     oqmlDot *make_right_dot(const char *, oqmlBool);
02669     oqmlDot *make_right_call(oqml_List *);
02670     oqmlDotContext *getDotContext();
02671     oqmlStatus *check(Database *, oqmlDotContext *);
02672     Bool boolean_dot;
02673     Bool boolean_node;
02674     char *requal_ident;
02675     oqmlDot *asDot() {return this;}
02676   };
02677 
02678   class oqmlXSort : public oqmlNode {
02679 
02680   protected:
02681     oqml_List * xlist;
02682     oqmlBool reverse;
02683     oqmlNode * tosort;
02684 
02685     oqmlXSort(oqmlTYPE _type, oqml_List *_xlist, oqmlBool _reverse) :
02686       oqmlNode(_type) {
02687       xlist = _xlist;
02688       reverse = _reverse;
02689       tosort = 0;
02690     }
02691   };
02692 
02693   class oqmlSort : public oqmlXSort {
02694 
02695   public:
02696     oqmlSort(oqml_List *, oqmlBool);
02697     OQML_STD_DECL(oqmlSort);
02698   };
02699 
02700   class oqmlISort : public oqmlXSort {
02701     oqmlNode *idxnode;
02702 
02703   public:
02704     oqmlISort(oqml_List *, oqmlBool);
02705     OQML_STD_DECL(oqmlISort);
02706   };
02707 
02708   class oqmlPSort : public oqmlXSort {
02709     oqmlNode *pred;
02710     oqmlNode *predarg;
02711 
02712   public:
02713     oqmlPSort(oqml_List *, oqmlBool);
02714     OQML_STD_DECL(oqmlPSort);
02715   };
02716 
02717   class oqmlCompoundStatement : public oqmlNode {
02718     oqmlNode *node;
02719 
02720   public:
02721     OQML_STD_DECL(oqmlCompoundStatement);
02722     oqmlCompoundStatement(oqmlNode *);
02723 
02724     void lock() {oqmlNode::lock(); if (node) node->lock();}
02725     void unlock() {oqmlNode::unlock(); if (node) node->unlock();}
02726 
02727     oqmlBool hasIdent(const char *_ident) {
02728       return OQMLBOOL(node && node->hasIdent(_ident));
02729     }
02730   };
02731 
02732   class oqmlAssign : public oqmlNode {
02733     oqmlNode * qleft;
02734     oqmlNode * qright;
02735     char *ident; // context argument
02736 
02737   public:
02738     OQML_STD_DECL_2(oqmlAssign);
02739   };
02740 
02741   class oqmlSelfIncr : public oqmlNode {
02742     oqmlNode * ql;
02743     oqmlNode * qlassign;
02744     int incr;
02745     oqmlBool post;
02746 
02747   public:
02748     oqmlSelfIncr(oqmlNode *, int incr, oqmlBool post);
02749     OQML_STD_DECL(oqmlSelfIncr);
02750     void lock() {oqmlNode::lock(); ql->lock(); qlassign->lock();}
02751     void unlock() {oqmlNode::unlock(); ql->unlock(); qlassign->unlock();}
02752   };
02753 
02754   class oqmlFlatten : public oqmlNode {
02755     oqml_List *list;
02756     int flat;
02757 
02758   public:
02759     oqmlFlatten(oqml_List *, int flat = 1);
02760     OQML_STD_DECL(oqmlFlatten);
02761     void lock();
02762     void unlock();
02763     void resetList() {list = NULL;}
02764   };
02765 
02766   class oqmlElement : public oqmlNode {
02767     oqmlNode * ql;
02768 
02769   public:
02770     OQML_STD_DECL_1(oqmlElement);
02771   };
02772 
02773   class oqmlElementAt : public oqmlNode {
02774     oqmlNode * qleft, * qright;
02775 
02776   public:
02777     OQML_STD_DECL_2(oqmlElementAt);
02778   };
02779 
02780   class oqmlSetInAt : public oqmlNode {
02781     oqmlNode * qleft, * qright, * ql3;
02782 
02783   public:
02784     oqmlSetInAt(oqmlNode *, oqmlNode *, oqmlNode *);
02785     OQML_STD_DECL(oqmlSetInAt);
02786     void lock() {oqmlNode::lock(); qleft->lock(); qright->lock(); ql3->lock();}
02787     void unlock() {oqmlNode::unlock(); qleft->unlock(); qright->unlock(); ql3->unlock();}
02788   };
02789 
02790   class oqmlUnsetInAt : public oqmlNode {
02791     oqmlNode * qleft, * qright;
02792 
02793   public:
02794     OQML_STD_DECL_2(oqmlUnsetInAt);
02795   };
02796 
02797   class oqmlIn : public oqmlNode {
02798     oqmlNode * qleft;
02799     oqmlNode * qright;
02800     oqmlBool hasDotIdent(const char *);
02801     oqmlBool evalDone;
02802 
02803   public:
02804     OQML_STD_DECL_2(oqmlIn);
02805     oqmlStatus *preEvalSelect(Database *db, oqmlContext *ctx,
02806                               const char *ident, oqmlBool &done,
02807                               unsigned int &cnt, oqmlBool firstPass = oqml_True);
02808   };
02809 
02810   class oqml_Interval {
02811 
02812     oqmlStatus *evalNode(Database *db, oqmlContext *ctx,
02813                          oqmlNode *node, unsigned int &base);
02814     unsigned int from_base, to_base;
02815     oqmlNode *from, *to;
02816 
02817   public:
02818     enum Status {
02819       Error,
02820       Success,
02821       Continue
02822     };
02823 
02824     oqml_Interval(oqmlNode *_from, oqmlNode *_to);
02825 
02826     oqml_Interval::Status isIn(unsigned int count, unsigned int max) const;
02827     oqmlBool isAll() const;
02828     oqmlStatus *compile(Database *db, oqmlContext *ctx);
02829     oqmlStatus *evalNodes(Database *db, oqmlContext *ctx);
02830 
02831     void lock() {if (from) from->lock(); if (to) to->lock();}
02832     void unlock() {if (from) from->unlock(); if (to) to->unlock();}
02833 
02834     std::string toString() const;
02835   };
02836 
02837   class oqmlFor : public oqmlNode {
02838     oqmlNode * qcoll;
02839     oqmlNode * qpred;
02840     oqml_Interval * interval;
02841     char * ident;
02842     oqmlBool exists;
02843 
02844   public:
02845     oqmlFor(oqml_Interval *, const char *ident, oqmlNode *qcoll,
02846             oqmlNode *qpred, oqmlBool);
02847     OQML_STD_DECL(oqmlFor);
02848 
02849     void lock();
02850     void unlock();
02851   };
02852 
02853   class oqmlAddTo : public oqmlNode {
02854     oqmlNode * qleft;
02855     oqmlNode * qright;
02856 
02857   public:
02858     OQML_STD_DECL_2(oqmlAddTo);
02859   };
02860 
02861   class oqmlSuppressFrom : public oqmlNode {
02862     oqmlNode * qleft;
02863     oqmlNode * qright;
02864 
02865   public:
02866     OQML_STD_DECL_2(oqmlSuppressFrom);
02867   };
02868 
02869   class oqmlAppend : public oqmlNode {
02870     oqmlNode * qleft;
02871     oqmlNode * qright;
02872 
02873   public:
02874     OQML_STD_DECL_2(oqmlAppend);
02875   };
02876 
02877   class oqmlEmpty : public oqmlNode {
02878     oqmlNode * ql;
02879 
02880   public:
02881     OQML_STD_DECL_1(oqmlEmpty);
02882   };
02883 
02884   class oqmlDatabase : public oqmlNode {
02885     char *dbname;
02886     char *mode;
02887     oqmlNode * ql;
02888     Database *cdb;
02889 
02890   public:
02891     oqmlDatabase(const char *, const char *, oqmlNode *);
02892     OQML_STD_DECL(oqmlDatabase);
02893   };
02894 
02895   class oqml_SelectOrder {
02896 
02897   public:
02898     oqml_List *list;
02899     oqmlBool asc;
02900     oqml_SelectOrder(oqml_List *_list, oqmlBool _asc) :
02901       list(_list), asc(_asc) { }
02902   };
02903 
02904   class oqmlSelect : public oqmlNode {
02905     oqmlBool distinct;
02906     oqmlBool one;
02907     int logged[64];
02908     //Database *newdb;
02909     Database *dbs[64];
02910     int dbs_cnt;
02911     oqmlNode *location;
02912     oqmlNode *projection;
02913     oqml_IdentList * ident_from_list;
02914     oqmlNode *where, *group, *having;
02915     oqml_SelectOrder *order;
02916     oqml_IdentLink **idents;
02917     oqmlBool calledFromEval;
02918     int ident_cnt;
02919     oqmlBool databaseStatement;
02920   
02921     oqmlBool makeIdents();
02922     oqmlStatus *processRequalification_1(Database *db, oqmlContext *);
02923     oqmlStatus *processRequalification_2(Database *db, oqmlContext *);
02924     oqmlStatus *processFromListRequalification(Database *db, oqmlContext *);
02925     oqmlStatus *processMissingIdentsRequalification(Database *db, oqmlContext *);
02926     oqmlStatus *evalRequalified(Database *db, oqmlContext *ctx);
02927 
02928     oqmlStatus *processMissingProjRequalification(Database *db, oqmlContext *);
02929 
02930     oqmlStatus *evalCartProdRealize(Database *db, oqmlContext *ctx,
02931                                     oqmlAtomList *rlist, int n,
02932                                     const char * = 0,
02933                                     oqmlAtom ** = 0, int = 0);
02934 
02935     oqmlStatus *evalCartProd(Database *db, oqmlContext *ctx,
02936                              oqmlAtomList **alist);
02937 
02938     int *list_order;
02939     oqmlStatus *check_order();
02940     oqmlStatus *check_order_coll(oqmlNode *);
02941     oqmlStatus *check_order_simple();
02942     oqmlStatus *realize_order(oqmlAtomList **);
02943 
02944   public:
02945     oqmlSelect(oqmlNode *location,
02946                oqmlBool distinct,
02947                oqmlBool one,
02948                oqmlNode *projection,
02949                oqml_IdentList * = 0,
02950                oqmlNode *where = 0,
02951                oqmlNode *group = 0,
02952                oqmlNode *having = 0,
02953                oqml_SelectOrder *order = 0);
02954 
02955     void setDatabaseStatement() {databaseStatement = oqml_True;}
02956     OQML_STD_DECL(oqmlSelect);
02957 
02958     oqmlBool usesFromIdent(oqmlNode *);
02959     void lock();
02960     void unlock();
02961     oqmlBool mayBeRequalified() const {return oqml_False;}
02962   };
02963 
02964   class oqmlCount : public oqmlNode {
02965     oqmlNode * ql;
02966 
02967   public:
02968     OQML_STD_DECL_1(oqmlCount);
02969   };
02970 
02971   class oqmlGetIdent : public oqmlNode {
02972     oqmlNode * ql;
02973 
02974   public:
02975     OQML_STD_DECL_1(oqmlGetIdent);
02976   };
02977 
02978   class oqmlTimeFormat : public oqmlNode {
02979     oqml_List *list;
02980     oqmlNode *time;
02981     oqmlNode *format;
02982 
02983   public:
02984     OQML_STD_DECL(oqmlTimeFormat);
02985     oqmlTimeFormat(oqml_List *);
02986   };
02987 
02988   class oqmlContents : public oqmlNode {
02989     oqmlNode * ql;
02990 
02991   public:
02992     OQML_STD_DECL_1(oqmlContents);
02993   };
02994 
02995   class oqmlBodyOf : public oqmlNode {
02996     oqmlNode * ql;
02997     char *ident;
02998 
02999   public:
03000     OQML_STD_DECL_1(oqmlBodyOf);
03001   };
03002 
03003   class oqmlScopeOf : public oqmlNode {
03004     oqmlNode * ql;
03005     char *ident;
03006 
03007   public:
03008     OQML_STD_DECL_1(oqmlScopeOf);
03009   };
03010 
03011   class oqmlStructOf : public oqmlNode {
03012     oqmlNode * ql;
03013 
03014   public:
03015     OQML_STD_DECL_1(oqmlStructOf);
03016   };
03017 
03018   class oqmlPush : public oqmlNode {
03019     char *ident;
03020 
03021   public:
03022     oqmlPush(const char *);
03023     OQML_STD_DECL(oqmlPush);
03024   };
03025 
03026   class oqmlPop : public oqmlNode {
03027     char *ident;
03028 
03029   public:
03030     oqmlPop(const char *);
03031     OQML_STD_DECL(oqmlPop);
03032   };
03033 
03034   class oqmlForEach : public oqmlNode {
03035     char * ident;
03036     oqmlNode *in;
03037     oqmlNode *action;
03038     oqmlAtomType sym_type;
03039 
03040   public:
03041     oqmlForEach(const char *, oqmlNode *, oqmlNode *);
03042     OQML_STD_DECL(oqmlForEach);
03043     oqmlBool hasIdent(const char *);
03044 
03045     void lock();
03046     void unlock();
03047 
03048     void setAction(oqmlNode *);
03049   };
03050 
03051 #define oqmlMAXDESC 16
03052   class oqmlIterCursor;
03053   class oqmlDotDesc {
03054 
03055   public:
03056     const Class *cls;
03057     const Class *cls_orig;
03058     const Attribute *attr;
03059     char *attrname;
03060     oqmlAtom *curatom;
03061     const TypeModifier *mod;
03062     oqml_ArrayList *array;
03063     int idx_cnt;
03064     Index **idxs;
03065     eyedbsm::Idx **idxse;
03066     Bool isref;
03067     int sz_item;
03068     int mode;
03069     int key_len;
03070     Bool is_union;
03071     eyedbsm::Idx::Key *key;
03072     unsigned char *s_data, *e_data;
03073     oqmlNode *qlmth;
03074     oqmlIterCursor *icurs;
03075     oqmlDotContext *dctx;
03076     oqmlBool is_coll;
03077 
03078     oqmlStatus *evalInd(oqmlNode *, Database *, oqmlContext *,
03079                         int &, int &, oqmlBool, oqmlBool);
03080     oqmlStatus *make(Database *, oqmlContext *, oqmlDot *dot,
03081                      const Attribute *xattr,
03082                      oqml_ArrayList *, const char *attrname,
03083                      const Class *castcls);
03084 
03085     oqmlStatus *getIdx(Database *db, oqmlContext *, oqmlDot *dot);
03086 
03087     void make_key(int);
03088   
03089     oqmlDotDesc();
03090     ~oqmlDotDesc();
03091   };
03092 
03093   class oqmlDotContext {
03094     void init(oqmlDot *p);
03095     oqmlStatus *eval_middle(Database *db, oqmlContext *ctx, Object *o,
03096                             oqmlAtom *value, int n, oqmlAtomList **alist);
03097     oqmlStatus *eval_terminal(Database *db, oqmlContext *ctx, Object *o,
03098                               oqmlAtom *value, int n, oqmlAtomList **alist);
03099     oqmlStatus *eval_terminal(Database *db, oqmlContext *ctx,
03100                               const Oid &oid, int n, oqmlAtomList **alist);
03101     oqmlStatus *eval_middle(Database *db, oqmlContext *ctx, Oid *,
03102                             int offset, Bool, int n, oqmlAtomList **alist);
03103     oqmlStatus *eval_terminal(Database *db, oqmlContext *ctx, Oid *,
03104                               int offset, Bool, int n, oqmlAtomList **alist);
03105 
03106     oqmlStatus *eval_object(Database *db, oqmlContext *ctx, 
03107                             oqmlAtom *, oqmlAtom *value, int from,
03108                             oqmlAtomList **alist);
03109 
03110     oqmlStatus *eval_struct(Database *db, oqmlContext *ctx, 
03111                             oqmlAtom_struct *astruct, oqmlAtom *value,
03112                             int from, oqmlAtomList **alist);
03113 
03114   public:
03115     oqmlDot *dot;
03116     int count;
03117     const char *varname;
03118     oqmlNode *oqml;
03119     oqmlDotContext *tctx;
03120     oqmlAtomList *tlist;
03121     Bool ident_mode;
03122     Bool iscoll;
03123 
03124     oqmlDotDesc *desc;
03125     oqmlAtomType dot_type;
03126     oqmlDotContext(oqmlDot *p, const Class *);
03127     oqmlDotContext(oqmlDot *p, oqmlAtom *);
03128     oqmlDotContext(oqmlDot *p, const char *);
03129     oqmlDotContext(oqmlDot *p, oqmlNode *);
03130     oqmlStatus *setAttrName(Database *db, const char *);
03131 
03132     oqmlStatus *eval(Database *db, oqmlContext *ctx, oqmlAtom *atom,
03133                      oqmlAtom *value, oqmlAtomList **alist);
03134     oqmlStatus *eval_perform(Database *db, oqmlContext *ctx, Object *o,
03135                              oqmlAtom *value, int n, oqmlAtomList **alist);
03136     oqmlStatus *eval_perform(Database *db, oqmlContext *ctx, Oid *,
03137                              int offset, Bool, int n, oqmlAtomList **alist);
03138     void setIdentMode(Bool);
03139     oqmlStatus *add(Database *, oqmlContext *, const Attribute *, oqml_ArrayList *,
03140                     char *, oqmlAtom *, Class *, oqmlNode *qlmth);
03141     void print();
03142     ~oqmlDotContext();
03143   };
03144 
03145   class oqml_Array {
03146 
03147   public:
03148     int oqml_cnt;
03149     int oqml_alloc;
03150     oqmlNode **oqml;
03151 
03152     oqml_Array(oqmlNode *);
03153     void add(oqmlNode *);
03154   };
03155 
03156   // external declarations.
03157 
03158   extern void oqml_capstring(char *);
03159   extern const char *oqml_error(oqml_Location * = NULL);
03160   extern char *oqml_make_error();
03161   extern char *oqml_make_error(oqml_Location *);
03162   extern oqmlStatus *oqml_get_class(Database *db, const Oid &oid,
03163                                     Class **cls);
03164   extern oqmlStatus *oqml_scan(oqmlContext *ctx, Iterator *q, Class *cls,
03165                                oqmlAtomList *alist,
03166                                const oqmlATOMTYPE t = (oqmlATOMTYPE)0);
03167 
03168   extern std::string oqml_binop_string(oqmlNode *qleft, oqmlNode *qright,
03169                                        const char *opstr, oqmlBool);
03170 
03171   extern std::string oqml_unop_string(oqmlNode *ql, const char *opstr,
03172                                       oqmlBool);
03173 
03174   extern oqmlStatus *oqml_realize(Database *, char *, oqmlAtomList **alist,
03175                                   oqmlBool compiling = oqml_False);
03176 
03177   extern Status oqml_realize(Database *, char *,
03178                              Value *&, LinkedList *,
03179                              oqmlBool compiling = oqml_False);
03180 
03181   extern oqmlNode *oqmlMakeSelect(int, oqmlNode *, oqml_IdentList *, oqmlNode *);
03182 
03183 #define OQML_CHECK_INTR() \
03184 if (isBackendInterrupted()) \
03185 { \
03186     setBackendInterrupt(False); \
03187     return new oqmlStatus(Exception::make(IDB_OQL_INTERRUPTED, "")); \
03188 }
03189 
03190   extern oqmlStatus *oqmlstatus;
03191   extern int oqmlLoopLevel, oqmlBreakLevel;
03192   extern const char oqml_global_scope[];
03193   extern const int oqml_global_scope_len;
03194   extern Status
03195   oqml_check_vardim(Database *db, const Attribute *attr, Oid *oid,
03196                     oqmlBool& enough, int from, int nb = 1);
03197 
03198   extern Status
03199   oqml_check_vardim(const Attribute *attr, Object *o, oqmlBool set,
03200                     oqmlBool& enough, int from, int &nb, int pdims,
03201                     oqmlBool isComplete);
03202 
03203 #define OQMLCOMPLETE(V) ((V) && (V)->as_string() ? oqml_True : oqml_False)
03204 
03205 #define OQML_TMP_RLIST(RLIST) tmp_##RLIST
03206 
03207 #define OQML_MAKE_RLIST(XALIST, RLIST) \
03208   oqmlAtomList * RLIST = new oqmlAtomList(); \
03209   oqmlAtom_list * OQML_TMP_RLIST(RLIST) = new oqmlAtom_list(RLIST); \
03210   (*XALIST) = new oqmlAtomList(OQML_TMP_RLIST(RLIST))
03211 
03212 #define OQML_MAKE_RBAG(XALIST, RLIST) \
03213   oqmlAtomList * RLIST = new oqmlAtomList(); \
03214   oqmlAtom_bag * OQML_TMP_RLIST(RLIST) = new oqmlAtom_bag(RLIST); \
03215   (*XALIST) = new oqmlAtomList(OQML_TMP_RLIST(RLIST))
03216 
03217 #define NO_KW
03218 #define SKIP_ERRS
03219 
03220   extern const char oqml_uninit_fmt[];
03221 
03222   extern oqmlAtom_list *oqml_variables;
03223   extern oqmlAtom_list *oqml_functions;
03224   extern oqmlAtom_string *oqml_status;
03225   extern oqmlBool oqml_suppress(oqmlAtomList *, const char *);
03226   extern void oqml_append(oqmlAtomList *, const char *);
03227 
03228   extern oqmlStatus *
03229   oqml_manage_postactions(Database *db, oqmlStatus *s, oqmlAtomList **alist);
03230 
03231   extern oqmlStatus *
03232   oqml_realize_postaction(Database *db, oqmlContext *, const char *ident,
03233                           oqmlAtom_string *rs, oqmlAtom *ra,
03234                           oqmlAtomList **alist);
03235 
03236   extern void oqml_initialize(Database *db);
03237   extern oqmlBool oqml_auto_persist;
03238   class OqlCtbDatabase;
03239   extern OqlCtbDatabase *oqml_default_db;
03240   extern oqmlStatus *oqml_get_location(Database *&, oqmlContext *,
03241                                        oqmlNode *location, oqmlBool * = 0);
03242   extern oqmlStatus *oqml_get_locations(Database *db, oqmlContext *ctx,
03243                                         oqmlNode *location, Database *xdb[],
03244                                         int &xdb_cnt);
03245 
03246   extern oqmlBool oqml_is_getcount(oqml_ArrayList *);
03247   extern oqmlBool oqml_is_wholecount(oqml_ArrayList *);
03248 
03249   extern oqmlStatus *oqmlIndexIter(Database *db, oqmlContext *ctx,
03250                                    oqmlNode *node,
03251                                    oqmlDotContext *dctx, oqmlDotDesc *d,
03252                                    oqmlAtomList **alist);
03253 
03254   extern void
03255   oqml_sort_simple(oqmlAtomList *ilist, oqmlBool reverse,
03256                    oqmlATOMTYPE atom_type, oqmlAtomList **alist);
03257   extern void
03258   oqml_sort_list(oqmlAtomList *ilist, oqmlBool reverse, int idx,
03259                  oqmlATOMTYPE atom_type, oqmlAtomList **alist);
03260 
03261   extern oqmlStatus *
03262   oqml_check_sort_type(oqmlNode *node, oqmlAtomType &type, const char *msg = 0);
03263 
03264   struct oqmlIterCursor {
03265     int s_ind, e_ind;
03266     oqmlIterCursor(int _s_ind, int _e_ind) : s_ind(_s_ind), e_ind(_e_ind) {}
03267     ~oqmlIterCursor() { }
03268   };
03269 
03270   extern oqmlStatus *
03271   oqml_opident_compile(oqmlNode *, Database *db, oqmlContext *ctx,
03272                        oqmlNode *ql, char *&ident);
03273 
03274   extern oqmlStatus *
03275   oqml_opident_preeval(oqmlNode *, Database *db, oqmlContext *ctx,
03276                        oqmlNode *ql, char *&ident);
03277 
03278 #define oqml_isstat() (is_statement ? "; " : "")
03279 
03280 #define OQML_NEW_HINT() (oqml_auto_persist ? new oqmlIdent("oql$db") : (oqmlNode *)0)
03281 
03282   extern oqmlAtom *
03283   oqml_make_struct_array(Database *db, oqmlContext *ctx, int idx, oqmlAtom *);
03284 
03285 #include <eyedb/oqlinline.h>
03286 #include <eyedb/oqliter.h>
03287 
03288 #define OQML_CHECK_MAX_ATOMS(LIST, CTX, GARB) \
03289 do { \
03290   if ((LIST)->cnt && (CTX)->isOneAtom()) \
03291     { \
03292       GARB; \
03293       return oqmlSuccess; \
03294     } \
03295  \
03296   if ((LIST)->cnt >= (CTX)->getMaxAtoms()) \
03297     { \
03298       (CTX)->setOverMaxAtoms(); \
03299       GARB; \
03300       return oqmlSuccess; \
03301     } \
03302 } while (0)
03303 
03304 #define SYNC_GARB
03305 
03306 #define OQL_DELETE(X) do {if ((X) && !(X)->refcnt) delete (X);} while(0)
03307 
03308   extern oqmlBool
03309   oqml_is_symbol(oqmlContext *ctx, const char *sym);
03310 
03311 }

Generated on Mon Dec 22 18:16:01 2008 for eyedb by  doxygen 1.5.3