00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "eyedb_p.h"
00026 #include "CollectionBE.h"
00027 #include "Attribute_p.h"
00028 #include "odl.h"
00029 #include <string.h>
00030
00031
00032 #define DEF_PREFIX ""
00033
00034 #define DEF_PREFIX2 ""
00035
00036 #define NEW_ARGARR // 8/02/03
00037 #define NO_COMMENTS
00038 #define NEW_COMP_POLICY
00039 #define IDBBOOL_STR(X) ((X) ? "eyedb::True" : "eyedb::False")
00040
00041 #define ATTR_CACHE_DIRECT
00042
00043
00044 #define SET_COUNT_DIRECT // added the 27/10/98
00045
00046 #define ODL_STD_STRING
00047
00048 namespace eyedb {
00049
00050 extern Bool odl_smartptr;
00051
00052
00053 static const char *getPtrRet()
00054 {
00055 if (odl_smartptr)
00056 return "Ptr ";
00057 return "*";
00058 }
00059
00060
00061 static const char *getPtrSet()
00062 {
00063 if (odl_smartptr)
00064 return "Ptr &";
00065 return "*";
00066 }
00067
00068 static void
00069 gbx_suspend(GenContext *ctx)
00070 {
00071 fprintf(ctx->getFile(), "%seyedb::gbxAutoGarbSuspender _gbxsusp_;\n",
00072 ctx->get());
00073 }
00074
00075 static const char classSuffix[] = "_Class";
00076 static const char __agritems[] = "getClass()->getAttributes()";
00077 static const char __agrdyn[] = "_attr";
00078 static const char downCastPrefix[] = "as";
00079 static Bool class_enums;
00080 static Bool attr_cache;
00081 static const char enum_type[] = "Type";
00082
00083 #define STRBOOL(X) ((X) ? "eyedb::True" : "eyedb::False")
00084
00085 #define IS_STRING() (typmod.ndims == 1 && \
00086 !strcmp(cls->getName(), char_class_name) && \
00087 !isIndirect())
00088
00089 #define IS_RAW() (typmod.ndims == 1 && \
00090 !strcmp(cls->getName(), byte_class_name) && \
00091 !isIndirect())
00092
00093 #define SCLASS() (is_string ? "char" : "unsigned char")
00094 #define SARGIN() (is_string ? "" : ", unsigned int len")
00095 #define SARGOUT() ((is_raw && isVarDim()) ? "unsigned int *len, " : "")
00096
00097 static char *
00098 purge(const char *x)
00099 {
00100 char *s = (char *)malloc(2 * strlen(x) + 1);
00101 char *p = s;
00102 char c;
00103
00104 while (c = *x++)
00105 {
00106 if (c == '"')
00107 {
00108 *p++ = '\\';
00109 *p++ = '"';
00110 }
00111 else if (c == '\\')
00112 {
00113 *p++ = '\\';
00114 *p++ = '\\';
00115 }
00116 else if (c == '\n')
00117 *p++ = ' ';
00118 else
00119 *p++ = c;
00120 }
00121
00122 *p = 0;
00123 return s;
00124 }
00125
00126 static const char *
00127 atc_set(const char *name)
00128 {
00129 static char _set[128];
00130 sprintf(_set, "__%s_isset__", name);
00131 return _set;
00132 }
00133
00134 static const char *
00135 atc_cnt(const char *name)
00136 {
00137 static char _cnt[128];
00138 sprintf(_cnt, "__%s_cnt__", name);
00139 return _cnt;
00140 }
00141
00142 static const char *
00143 atc_name(const char *name)
00144 {
00145 static char _name[128];
00146 sprintf(_name, "__%s__", name);
00147 return _name;
00148 }
00149
00150 static const char *
00151 atc_this(const char *classname)
00152 {
00153 static char _this[128];
00154 sprintf(_this, "((%s *)this)", classname);
00155
00156 return _this;
00157 }
00158
00159 #define RETURN_ERROR(FD, CTX, MCLASS, INDENT) \
00160 do { \
00161 if ((MCLASS)->asEnumClass()) \
00162 fprintf((FD), "%s%sif (s) {if (rs) *rs = s; return (%s)0;}\n", (CTX)->get(), INDENT, \
00163 className(MCLASS, False)); \
00164 else \
00165 fprintf((FD), "%s%sif (s) {if (rs) *rs = s; return 0;}\n", (CTX)->get(), INDENT); \
00166 } while(0)
00167
00168 #define ATTRNAME(NAME, OPTYPE, HINTS) \
00169 (HINTS).style->getString(GenCodeHints::OPTYPE, NAME)
00170
00171 #define ATTRNAME_1(NAME, OPTYPE, HINTS) \
00172 (HINTS).style->getString(OPTYPE, NAME)
00173
00174 #define ATTRGET(CL) ((CL)->asCollectionClass() ? \
00175 GenCodeHints::tGetColl : GenCodeHints::tGet)
00176
00177 #define ATTRSET(CL) ((CL)->asCollectionClass() ? \
00178 GenCodeHints::tSetColl : GenCodeHints::tSet)
00179
00180 static const GenCodeHints *phints;
00181
00182 static const char *
00183 make_int(int i)
00184 {
00185 static char x[16];
00186 sprintf(x, "%d", i);
00187 return x;
00188 }
00189
00190 static int
00191 pre(char *name, const char *pre)
00192 {
00193 int len = strlen(pre);
00194 if (!strncmp(name, pre, len))
00195 {
00196 name[len] += 'A' - 'a';
00197 return 1;
00198 }
00199 return 0;
00200 }
00201
00202 static const char *className(const Class *cls,
00203 Bool makeC = True,
00204 Bool makeAlias = False)
00205 {
00206 const char *name = (makeAlias ? cls->getAliasName() : cls->getName());
00207
00208 if (!strncmp(name, "set<", 4))
00209 return "eyedb::CollSet";
00210
00211 if (!strncmp(name, "bag<", 4))
00212 return "eyedb::CollBag";
00213
00214 if (!strncmp(name, "array<", 6))
00215 return "eyedb::CollArray";
00216
00217 if (!strncmp(name, "list<", 5))
00218 return "eyedb::CollList";
00219
00220 for (int i = 0; i < idbLAST_Type; i++)
00221 if (!strcmp(name, class_info[i].name))
00222 return Class::classNameToCName(name);
00223
00224 if (makeC) {
00225 if (!strcmp(name, char_class_name))
00226 return "eyedb::Char";
00227
00228 if (!strcmp(name, int32_class_name))
00229 return "eyedb::Int32";
00230
00231 if (!strcmp(name, int64_class_name))
00232 return "eyedb::Int64";
00233
00234 if (!strcmp(name, int16_class_name))
00235 return "eyedb::Int16";
00236
00237 if (!strcmp(name, "float"))
00238 return "eyedb::Float";
00239
00240 if (!strcmp(name, "oid"))
00241 return "eyedb::OidP";
00242
00243 if (!strcmp(name, "byte"))
00244 return "eyedb::Byte";
00245 }
00246 else {
00247 if (!strcmp(name, int32_class_name))
00248 return "eyedblib::int32";
00249
00250 if (!strcmp(name, int64_class_name))
00251 return "eyedblib::int64";
00252
00253 if (!strcmp(name, int16_class_name))
00254 return "eyedblib::int16";
00255
00256 if (!strcmp(name, "oid"))
00257 return "eyedb::Oid";
00258
00259 if (!strcmp(name, "byte"))
00260 return "unsigned char";
00261
00262 if (!strcmp(name, "float"))
00263 return "double";
00264 }
00265
00266 if (cls->asEnumClass() && class_enums) {
00267 if (Class::isBoolClass(cls)) {
00268 return cls->getCName(True);
00269 }
00270 static std::string enum_s;
00271 enum_s = std::string(name) + "::" + enum_type;
00272 return enum_s.c_str();
00273 }
00274
00275 const char *sCName = Class::getSCName(name);
00276 return sCName ? sCName : name;
00277 }
00278
00279 static void dimArgsGen(FILE *fd, int ndims, Bool named = True)
00280 {
00281 for (int i = 0; i < ndims; i++)
00282 {
00283 if (i)
00284 fprintf(fd, ", ");
00285 fprintf(fd, "unsigned int");
00286 if (named)
00287 fprintf(fd, " a%d", i);
00288 }
00289 }
00290
00291 Status Attribute::generateClassDesc_C(GenContext *ctx)
00292 {
00293 FILE *fd = ctx->getFile();
00294 int ndims = typmod.ndims;
00295
00296 fprintf(fd, "\n");
00297 if (ndims)
00298 {
00299 fprintf(fd, "%sdims = new int[%d];\n", ctx->get(), ndims);
00300 for (int i = 0; i < ndims; i++)
00301 fprintf(fd, "%sdims[%d] = %d;\n", ctx->get(), i, typmod.dims[i]);
00302 }
00303 else
00304 fprintf(fd, "%sdims = 0;\n", ctx->get());
00305
00306 fprintf(fd, "%sattr[%d] = new eyedb::Attribute(", ctx->get(), num);
00307
00308 if (cls->asCollectionClass())
00309 fprintf(fd, "(m ? m->getClass(\"%s\") : %s%s), \"%s\", ",
00310 cls->getAliasName(), cls->getCName(), classSuffix, name);
00311 else if (cls->asEnumClass())
00312 fprintf(fd, "(m ? m->getClass(\"%s\") : %s%s), \"%s\", ",
00313 cls->getAliasName(), cls->getCName(False), classSuffix, name);
00314 else
00315 fprintf(fd, "(m ? m->getClass(\"%s\") : %s%s), \"%s\", ",
00316 cls->getAliasName(), className(cls), classSuffix, name);
00317
00318 fprintf(fd, "%s, %d, dims);\n", (isIndirect() ? "eyedb::True" : "eyedb::False"), ndims);
00319
00320
00321
00322
00323
00324
00325 if (ndims)
00326 fprintf(fd, "%sdelete[] dims;\n", ctx->get());
00327
00328 if (inv_spec.clsname)
00329 fprintf(fd, "%sattr[%d]->setInverse(\"%s\", \"%s\");\n", ctx->get(), num,
00330 inv_spec.clsname, inv_spec.fname);
00331 else if (inv_spec.item)
00332 fprintf(fd, "%sattr[%d]->setInverse(\"%s\", \"%s\");\n", ctx->get(), num,
00333 inv_spec.item->getClassOwner()->getName(), inv_spec.item->getName());
00334
00335 return Success;
00336 }
00337
00338 enum OP {
00339 op_GET = 1,
00340 op_SET,
00341 op_OTHER
00342 };
00343
00344 static void
00345 dynamic_attr_gen(FILE *fd, GenContext *ctx,
00346 const Attribute *attr,
00347 OP set,
00348 Bool isoid = False,
00349 Bool is_string = False,
00350 const char *cast = 0)
00351 {
00352 fprintf(fd, "%sconst eyedb::Attribute *%s = getClass()->getAttribute(\"%s\");\n",
00353 ctx->get(), __agrdyn, attr->getName());
00354 fprintf(fd, "%sif (!%s) {\n", ctx->get(), __agrdyn);
00355 ctx->push();
00356 if (set == op_GET && !isoid)
00357 fprintf(fd, "%sif (isnull) *isnull = eyedb::True;\n", ctx->get());
00358 fprintf(fd, "%sif (dyn%s_error_policy) {\n", ctx->get(), (set ? "set" : "get"));
00359 fprintf(fd, "%s eyedb::Status s = eyedb::Exception::make(eyedb::IDB_ATTRIBUTE_ERROR, "
00360 "\"object %%s: attribute %%s::%%s not found\", oid.toString(), getClass()->getName(), \"%s\");\n",
00361 ctx->get(), attr->getName());
00362 if (set == op_SET) {
00363 fprintf(fd, "%s return s;\n", ctx->get());
00364 fprintf(fd, "%s}\n", ctx->get());
00365 fprintf(fd, "%sreturn eyedb::Success;\n", ctx->get());
00366 }
00367 else {
00368 fprintf(fd, "%s if (rs) *rs = s;\n", ctx->get());
00369 fprintf(fd, "%s}\n", ctx->get());
00370 if (isoid)
00371 fprintf(fd, "%sreturn nulloid;\n", ctx->get());
00372 else if (is_string)
00373 fprintf(fd, "%sreturn \"\";\n", ctx->get());
00374 else if (cast)
00375 fprintf(fd, "%sreturn (%s)0;\n", ctx->get(), cast);
00376 else
00377 fprintf(fd, "%sreturn 0;\n", ctx->get());
00378 }
00379 ctx->pop();
00380 fprintf(fd, "%s}\n\n", ctx->get());
00381 }
00382
00383 Status
00384 Attribute::generateCollRealizeClassMethod_C(Class *own,
00385 GenContext *ctx,
00386 const GenCodeHints &hints,
00387 Bool isoid,
00388 int xacctype)
00389 {
00390 FILE *fd = ctx->getFile();
00391 int ndims = typmod.ndims, i;
00392 const char *comma = (ndims ? ", " : "");
00393 Bool _isref;
00394 eyedblib::int16 _dim;
00395 Class *cl =
00396 ((CollectionClass *)cls)->getCollClass(&_isref, &_dim);
00397 GenCodeHints::OpType acctype = (GenCodeHints::OpType)xacctype;
00398 const char *etc = (acctype == GenCodeHints::tAddItemToColl ?
00399 ", const eyedb::CollImpl *collimpl" : "");
00400 const char *accmth = (acctype == GenCodeHints::tAddItemToColl ? "insert" : "suppress");
00401 const char *oclassname = _isref ?
00402 className(cl, True) : className(cl, False);
00403
00404 if (isoid && cl->asBasicClass())
00405 return Success;
00406
00407 const char *cast = (cl->asBasicClass() ? "(eyedb::Value)" : "");
00408
00409 const char *classname;
00410 Bool ordered;
00411 CollectionClass *mcoll = (CollectionClass *)cls;
00412 if (mcoll->asCollSetClass())
00413 {
00414 classname = "eyedb::CollSet";
00415 ordered = False;
00416 }
00417 else if (mcoll->asCollBagClass())
00418 {
00419 classname = "eyedb::CollBag";
00420 ordered = False;
00421 }
00422 else if (mcoll->asCollArrayClass())
00423 {
00424 classname = "eyedb::CollArray";
00425 ordered = True;
00426 }
00427 else if (mcoll->asCollListClass())
00428 {
00429 classname = "eyedb::CollList";
00430 ordered = True;
00431 }
00432
00433 const char *At = ((acctype == GenCodeHints::tAddItemToColl ||
00434 acctype == GenCodeHints::tRmvItemFromColl)
00435 && ordered ? "At" : "");
00436
00437 const char *etc1 = "";
00438 const char *etc2 = "";
00439 Bool rmv_from_array = (acctype == GenCodeHints::tRmvItemFromColl)
00440 && ordered ? True : False;
00441
00442 if (rmv_from_array && isoid)
00443 return Success;
00444
00445 GenCodeHints::OpType nacctype;
00446 if (ordered)
00447 nacctype = (acctype == GenCodeHints::tRmvItemFromColl ?
00448 GenCodeHints::tUnsetItemInColl :
00449 GenCodeHints::tSetItemInColl);
00450 else
00451 nacctype = acctype;
00452
00453 if (!*At)
00454 {
00455 if (acctype == GenCodeHints::tAddItemToColl)
00456 {
00457 etc1 = ", eyedb::Bool noDup";
00458 etc2 = ", noDup";
00459 }
00460 else if (acctype == GenCodeHints::tRmvItemFromColl)
00461 {
00462 etc1 = ", eyedb::Bool checkFirst";
00463 etc2 = ", checkFirst";
00464 }
00465 }
00466
00467 if (_dim == 1)
00468 {
00469 fprintf(fd, "eyedb::Status %s::%s(%s%s", className(own),
00470 ATTRNAME_1(name, nacctype, hints),
00471 (*At ? "int where" : ""),
00472 (*At && (!rmv_from_array || ndims >= 1) ? ", " : ""));
00473 dimArgsGen(fd, ndims);
00474 if (rmv_from_array)
00475 fprintf(fd, ")\n{\n");
00476 else if (isoid)
00477 fprintf(fd, "%sconst eyedb::Oid &_oid%s)\n{\n", comma, etc);
00478 else
00479 fprintf(fd, "%s%s%s_%s%s%s)\n{\n", comma, oclassname,
00480 (_isref || !cl->asBasicClass() ? getPtrRet() : " "), name,
00481 etc1, etc);
00482 }
00483 else if (!strcmp(cl->getName(), char_class_name) && _dim > 1)
00484 {
00485 fprintf(fd, "eyedb::Status %s::%s(%s", className(own),
00486 ATTRNAME_1(name, nacctype, hints),
00487 (*At ? "int where, " : ""));
00488 dimArgsGen(fd, ndims);
00489 fprintf(fd, "%sconst char *_%s%s%s)\n{\n", comma, name, etc1, etc);
00490 }
00491 else
00492 return Success;
00493
00494 gbx_suspend(ctx);
00495
00496 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
00497
00498 fprintf(fd, "%s%s *_coll;\n", ctx->get(), classname);
00499 fprintf(fd, "%seyedb::Bool _not_set = eyedb::False;\n", ctx->get());
00500 if (ndims > 1)
00501 {
00502 fprintf(fd, "%seyedb::Size from = a%d;\n", ctx->get(), ndims-1);
00503 for (int i = ndims - 2 ; i >= 0; i--)
00504 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00505 }
00506 else
00507 fprintf(fd, "%seyedb::Size from = 0;\n", ctx->get());
00508
00509 if (odl_dynamic_attr) {
00510 dynamic_attr_gen(fd, ctx, this, op_SET, isoid);
00511 fprintf(fd, "\n%sstatus = %s->getValue(this, (eyedb::Data *)&_coll, 1, from);\n",
00512 ctx->get(), __agrdyn, name);
00513 }
00514 else
00515 fprintf(fd, "\n%sstatus = %s[%d]->getValue(this, (eyedb::Data *)&_coll, 1, from);\n",
00516 ctx->get(), __agritems, num, name);
00517 fprintf(fd, "%sif (status)\n%s return status;\n\n", ctx->get(), ctx->get());
00518 fprintf(fd, "%sif (!_coll)\n", ctx->get());
00519 fprintf(fd, "%s {\n", ctx->get());
00520 ctx->push();
00521 fprintf(fd, "%s _not_set = eyedb::True;\n", ctx->get());
00522 fprintf(fd, "%s eyedb::Oid _coll_oid;\n", ctx->get());
00523 if (odl_dynamic_attr)
00524 fprintf(fd, "%s status = %s->getOid(this, &_coll_oid, 1, from);\n",
00525 ctx->get(), __agrdyn, name);
00526 else
00527 fprintf(fd, "%s status = %s[%d]->getOid(this, &_coll_oid, 1, from);\n",
00528 ctx->get(), __agritems, num, name);
00529 fprintf(fd, "%s if (status)\n%s return status;\n\n", ctx->get(), ctx->get());
00530 fprintf(fd, "%s if (_coll_oid.isValid())\n", ctx->get());
00531 fprintf(fd, "%s {\n", ctx->get());
00532 ctx->push();
00533 fprintf(fd, "%s status = db->loadObject(&_coll_oid, (eyedb::Object **)&_coll);\n",
00534 ctx->get());
00535 fprintf(fd, "%s if (status)\n%s return status;\n", ctx->get(), ctx->get());
00536 ctx->pop();
00537 fprintf(fd, "%s }\n", ctx->get());
00538 fprintf(fd, "%s else\n", ctx->get());
00539 if (acctype == GenCodeHints::tAddItemToColl)
00540 {
00541 fprintf(fd, "%s {\n", ctx->get());
00542
00543 fprintf(fd, "%s _coll = new %s(db, \"\", "
00544 "db->getSchema()->getClass(\"%s\"), %s, collimpl);\n",
00545 ctx->get(), classname,
00546 cl->getAliasName(), (_isref ? "eyedb::True" : make_int(_dim)));
00547
00548 fprintf(fd, "%s }\n", ctx->get());
00549 }
00550 else
00551 fprintf(fd, "%s return eyedb::Exception::make(eyedb::IDB_ERROR, \"no valid collection in attribute %s::%s\");\n\n", ctx->get(), class_owner->getName(), name);
00552
00553 ctx->pop();
00554 fprintf(fd, "%s }\n", ctx->get());
00555 if (rmv_from_array)
00556 fprintf(fd, "\n%sstatus = _coll->suppressAt(where);\n", ctx->get());
00557 else if (isoid)
00558 fprintf(fd, "\n%sstatus = _coll->%s%s(%s_oid);\n", ctx->get(),
00559 accmth, At, (*At ? "where, " : ""));
00560 else
00561 fprintf(fd, "\n%sstatus = _coll->%s%s(%s%s_%s%s);\n", ctx->get(),
00562 accmth, At, (*At ? "where, " : ""), cast, name,
00563 etc2);
00564 fprintf(fd, "%sif (status || !_not_set)\n%s return status;\n\n", ctx->get(), ctx->get());
00565 if (odl_dynamic_attr)
00566 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&_coll, 1, from);\n",
00567 ctx->get(), __agrdyn);
00568 else
00569 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&_coll, 1, from);\n",
00570 ctx->get(), __agritems, num);
00571
00572 fprintf(fd, "%s _coll->release();\n", ctx->get());
00573 fprintf(fd, "\n%sreturn status;\n", ctx->get());
00574 fprintf(fd, "}\n\n");
00575 return Success;
00576 }
00577
00578 Status
00579 Attribute::generateCollInsertClassMethod_C(Class *own,
00580 GenContext *ctx,
00581 const GenCodeHints &hints,
00582 Bool isoid)
00583 {
00584 return generateCollRealizeClassMethod_C(own, ctx, hints,
00585 isoid,
00586 GenCodeHints::tAddItemToColl);
00587 }
00588
00589 Status
00590 Attribute::generateCollSuppressClassMethod_C(Class *own,
00591 GenContext *ctx,
00592 const GenCodeHints &hints,
00593 Bool isoid)
00594 {
00595 return generateCollRealizeClassMethod_C(own, ctx, hints,
00596 isoid,
00597 GenCodeHints::tRmvItemFromColl);
00598 }
00599
00600 Status
00601 Attribute::generateSetMethod_C(Class *own, GenContext *ctx,
00602 const GenCodeHints &hints)
00603 {
00604 if (cls->asCollectionClass())
00605 {
00606 (void)generateCollInsertClassMethod_C(own, ctx, hints, False);
00607 (void)generateCollInsertClassMethod_C(own, ctx, hints, True);
00608
00609 (void)generateCollSuppressClassMethod_C(own, ctx, hints, False);
00610 (void)generateCollSuppressClassMethod_C(own, ctx, hints, True);
00611 }
00612 return Success;
00613 }
00614
00615 #define NOT_BASIC() \
00616 (isIndirect() || (!cls->asBasicClass() && !cls->asEnumClass()))
00617
00618 Status
00619 Attribute::generateSetMethod_C(Class *own, GenContext *ctx,
00620 Bool isoid,
00621 const GenCodeHints &hints)
00622 {
00623 FILE *fd = ctx->getFile();
00624 int ndims = typmod.ndims, i;
00625 int not_basic = NOT_BASIC();
00626 const char *ref = (not_basic ? getPtrRet() : " ");
00627 const char *ref_set = (not_basic ? getPtrSet() : " ");
00628 const char *comma = (ndims ? ", " : "");
00629 const char *classname = isIndirect() ?
00630 className(cls, True) : className(cls, False);
00631
00632 if (isoid)
00633 fprintf(fd, "eyedb::Status %s::%s(", className(own),
00634 ATTRNAME(name, tSetOid, hints));
00635 else
00636 fprintf(fd, "eyedb::Status %s::%s(", className(own),
00637 ATTRNAME_1(name, ATTRSET(cls), hints));
00638
00639 dimArgsGen(fd, ndims, True);
00640
00641 if (isoid)
00642 fprintf(fd, "%sconst eyedb::Oid &_oid)\n{\n", comma);
00643 else if (cls->asEnumClass())
00644 fprintf(fd, "%s%s%s_%s, eyedb::Bool _check_value)\n{\n",
00645 comma, classname, ref, name);
00646 else
00647 fprintf(fd, "%s%s%s_%s)\n{\n", comma, classname, ref_set, name);
00648
00649 GenCodeHints::OpType optype = (isoid ? GenCodeHints::tSetOid:
00650 GenCodeHints::tSet);
00651
00652 if (attr_cache)
00653 genAttrCacheSetPrologue(ctx, optype);
00654
00655 if (odl_dynamic_attr)
00656 dynamic_attr_gen(fd, ctx, this, op_SET, isoid);
00657
00658 gbx_suspend(ctx);
00659
00660 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
00661
00662 if (ndims) {
00663 fprintf(fd, "%seyedb::Size from = a%d;\n", ctx->get(), ndims-1);
00664 for (int i = ndims - 2 ; i >= 0; i--)
00665 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00666
00667 if (isVarDim()) {
00668 fprintf(fd, "\n%seyedb::Size size;\n", ctx->get());
00669 if (odl_dynamic_attr)
00670 fprintf(fd, "%sstatus = %s->getSize(this, size);\n",
00671 ctx->get(), __agrdyn);
00672 else
00673 fprintf(fd, "%sstatus = %s[%d]->getSize(this, size);\n",
00674 ctx->get(), __agritems, num);
00675 fprintf(fd, "%sif (status)\n%s return status;\n\n", ctx->get(),
00676 ctx->get());
00677 fprintf(fd, "%sif (size <= from)\n", ctx->get());
00678 ctx->push();
00679 if (odl_dynamic_attr)
00680 fprintf(fd, "%sstatus = %s->setSize(this, from+1);\n",
00681 ctx->get(), __agrdyn);
00682 else
00683 fprintf(fd, "%sstatus = %s[%d]->setSize(this, from+1);\n",
00684 ctx->get(), __agritems, num);
00685 ctx->pop();
00686 fprintf(fd, "%sif (status)\n%s return status;\n", ctx->get(),
00687 ctx->get());
00688 }
00689
00690 if (isoid) {
00691 if (odl_dynamic_attr)
00692 fprintf(fd, "\n%sstatus = %s->setOid(this, &_oid, 1, from, oid_check);\n",
00693 ctx->get(), __agrdyn);
00694 else
00695 fprintf(fd, "\n%sstatus = %s[%d]->setOid(this, &_oid, 1, from, oid_check);\n",
00696 ctx->get(), __agritems, num);
00697 if (attr_cache)
00698 genAttrCacheSetEpilogue(ctx, optype);
00699 fprintf(fd, "%sreturn status;\n", ctx->get());
00700 }
00701
00702 else if (cls->asEnumClass()) {
00703 fprintf(fd, "%seyedblib::int32 __tmp = _%s;\n", ctx->get(), name);
00704 if (odl_dynamic_attr)
00705 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&__tmp, 1, from, _check_value);\n",
00706 ctx->get(), __agrdyn, name);
00707 else
00708 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&__tmp, 1, from, _check_value);\n",
00709 ctx->get(), __agritems, num, name);
00710 if (attr_cache)
00711 genAttrCacheSetEpilogue(ctx, optype);
00712 fprintf(fd, "%sreturn status;\n", ctx->get());
00713 }
00714 else if (not_basic) {
00715 if (odl_smartptr)
00716 fprintf(fd, "\n%seyedb::Object *_o%s = _%s.getObject();\n", ctx->get(),
00717 name, name);
00718 else
00719 fprintf(fd, "\n%seyedb::Object *_o%s = _%s;\n", ctx->get(), name,
00720 name);
00721
00722 if (odl_dynamic_attr)
00723 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&_o%s, 1, from);\n",
00724 ctx->get(), __agrdyn, name);
00725 else
00726 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&_o%s, 1, from);\n",
00727 ctx->get(), __agritems, num, name);
00728 if (attr_cache)
00729 genAttrCacheSetEpilogue(ctx, optype);
00730 fprintf(fd, "%sreturn status;\n", ctx->get());
00731 }
00732 else {
00733 if (odl_dynamic_attr)
00734 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&_%s, 1, from);\n",
00735 ctx->get(), __agrdyn, name);
00736 else
00737 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&_%s, 1, from);\n",
00738 ctx->get(), __agritems, num, name);
00739 if (attr_cache)
00740 genAttrCacheSetEpilogue(ctx, optype);
00741 fprintf(fd, "%sreturn status;\n", ctx->get());
00742 }
00743 }
00744 else if (isoid) {
00745 if (odl_dynamic_attr)
00746 fprintf(fd, "\n%sstatus = %s->setOid(this, &_oid, 1, 0, oid_check);\n",
00747 ctx->get(), __agrdyn);
00748 else
00749 fprintf(fd, "\n%sstatus = %s[%d]->setOid(this, &_oid, 1, 0, oid_check);\n",
00750 ctx->get(), __agritems, num);
00751 if (attr_cache)
00752 genAttrCacheSetEpilogue(ctx, optype);
00753 fprintf(fd, "%sreturn status;\n", ctx->get());
00754 }
00755 else if (cls->asEnumClass()) {
00756 fprintf(fd, "%seyedblib::int32 __tmp = _%s;\n", ctx->get(), name);
00757 if (odl_dynamic_attr)
00758 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&__tmp, 1, 0, _check_value);\n",
00759 ctx->get(), __agrdyn, name);
00760 else
00761 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&__tmp, 1, 0, _check_value);\n",
00762 ctx->get(), __agritems, num, name);
00763 if (attr_cache)
00764 genAttrCacheSetEpilogue(ctx, optype);
00765 fprintf(fd, "%sreturn status;\n", ctx->get());
00766 }
00767 else if (not_basic) {
00768 if (odl_smartptr)
00769 fprintf(fd, "\n%seyedb::Object *_o%s = _%s.getObject();\n", ctx->get(),
00770 name, name);
00771 else
00772 fprintf(fd, "\n%seyedb::Object *_o%s = _%s;\n", ctx->get(), name, name);
00773
00774 if (odl_dynamic_attr)
00775 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&_o%s, 1, 0);\n",
00776 ctx->get(), __agrdyn, name);
00777 else
00778 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&_o%s, 1, 0);\n",
00779 ctx->get(), __agritems, num, name);
00780 if (attr_cache)
00781 genAttrCacheSetEpilogue(ctx, optype);
00782 fprintf(fd, "%sreturn status;\n", ctx->get());
00783 }
00784 else {
00785 if (odl_dynamic_attr)
00786 fprintf(fd, "\n%sstatus = %s->setValue(this, (eyedb::Data)&_%s, 1, 0);\n",
00787 ctx->get(), __agrdyn, name);
00788 else
00789 fprintf(fd, "\n%sstatus = %s[%d]->setValue(this, (eyedb::Data)&_%s, 1, 0);\n",
00790 ctx->get(), __agritems, num, name);
00791 if (attr_cache)
00792 genAttrCacheSetEpilogue(ctx, optype);
00793 fprintf(fd, "%sreturn status;\n", ctx->get());
00794 }
00795
00796 fprintf(fd, "}\n\n");
00797
00798 return Success;
00799 }
00800
00801
00802 #define STATUS_ARG(HINTS, COMMA) \
00803 (((HINTS).error_policy == GenCodeHints::StatusErrorPolicy) ? \
00804 ((COMMA) ? ", eyedb::Status *rs" : "eyedb::Status *rs") : "")
00805
00806 #define STATUS_PROTO(HINTS, COMMA) \
00807 (((HINTS).error_policy == GenCodeHints::StatusErrorPolicy) ? \
00808 ((COMMA) ? ", eyedb::Status * = 0" : "eyedb::Status * = 0") : "")
00809
00810 Status
00811 Attribute::generateCollGetMethod_C(Class *own, GenContext *ctx,
00812 Bool isoid,
00813 const GenCodeHints &hints,
00814 const char *_const)
00815 {
00816 FILE *fd = ctx->getFile();
00817 int ndims = typmod.ndims, i;
00818 Bool _isref;
00819 eyedblib::int16 _dim;
00820 Class *cl = const_cast<Class *>(cls->asCollectionClass()->getCollClass(&_isref, &_dim));
00821 int not_basic = _isref || (!cl->asBasicClass() && !cl->asEnumClass());
00822 const char *ref = (not_basic ? getPtrRet() : " ");
00823 const char *starg = STATUS_ARG(hints, False);
00824 const char *stargcom = STATUS_ARG(hints, True);
00825 const char *classname = isIndirect() ?
00826 className(cls, True) : className(cls, False);
00827 const char *oclassname = _isref ?
00828 className(cl, True) : className(cl, False);
00829 const char *comma = (ndims ? ", " : "");
00830
00831 Bool ordered = (cls->asCollArrayClass() || cls->asCollListClass()) ? True : False;
00832 if (isoid) {
00833 if (!_isref)
00834 return Success;
00835
00836 if (ordered) {
00837 fprintf(fd, "eyedb::Oid %s::%s(unsigned int ind, ",
00838 own->getName(),
00839 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveOidItemAt : GenCodeHints::tGetOidItemAt), hints));
00840 dimArgsGen(fd, ndims, True);
00841 fprintf(fd, "%seyedb::Status *rs) const\n", comma);
00842 fprintf(fd, "{\n");
00843
00844 fprintf(fd, "%seyedb::Oid tmp;;\n", ctx->get());
00845
00846
00847
00848
00849 fprintf(fd, "%seyedb::Status s;\n", ctx->get());
00850
00851 fprintf(fd, "%sconst eyedb::Collection%s coll = %s(", ctx->get(),
00852 getPtrRet(),
00853 ATTRNAME(name, tGetColl, hints));
00854
00855 for (i = 0; i < ndims; i++)
00856 fprintf(fd, "a%d, ", i);
00857
00858 fprintf(fd, "(eyedb::Bool *)0, rs);\n\n", ctx->get());
00859 fprintf(fd, "%sif (!coll || (rs && *rs))\n", ctx->get());
00860 fprintf(fd, "%s return tmp;\n\n", ctx->get());
00861
00862 if (cls->asCollArrayClass() || cls->asCollListClass())
00863 fprintf(fd, "%ss = coll->asCollArray()->retrieveAt(ind, tmp);\n", ctx->get());
00864 else
00865 fprintf(fd, "%ss = coll->getOidAt(ind, tmp);\n", ctx->get());
00866 fprintf(fd, "%sif (s && rs) *rs = s;\n", ctx->get());
00867 fprintf(fd, "%sreturn tmp;\n", ctx->get());
00868 fprintf(fd, "}\n\n");
00869 return Success;
00870 }
00871 }
00872
00873 if (!*_const && cl->asBasicClass())
00874 return Success;
00875
00876
00877 if (!ordered)
00878 return Success;
00879
00880 if (!strcmp(cl->getName(), char_class_name) && _dim > 1) {
00881 fprintf(fd, "const char *%s::%s(unsigned int ind, ",
00882 own->getName(),
00883 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints));
00884 }
00885 else if (_dim == 1)
00886 fprintf(fd, "%s%s%s%s::%s(unsigned int ind, ",
00887 _const, oclassname, ref, own->getName(),
00888 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints));
00889 else {
00890
00891 return Success;
00892 }
00893
00894 dimArgsGen(fd, ndims, True);
00895 fprintf(fd, "%seyedb::Bool *isnull, eyedb::Status *rs) %s\n", comma, _const);
00896 fprintf(fd, "{\n");
00897
00898
00899
00900
00901
00902 fprintf(fd, "%seyedb::Status s;\n", ctx->get());
00903
00904 fprintf(fd, "%sconst eyedb::Collection%s coll = %s(", ctx->get(),
00905 getPtrRet(),
00906 ATTRNAME(name, tGetColl, hints));
00907
00908 for (i = 0; i < ndims; i++)
00909 fprintf(fd, "a%d, ", i);
00910
00911 fprintf(fd, "isnull, rs);\n\n", ctx->get());
00912 fprintf(fd, "%sif (!coll || (rs && *rs))\n", ctx->get());
00913 if (not_basic)
00914 {
00915 fprintf(fd, "%s return (%s *)0;\n\n", ctx->get(), oclassname);
00916 fprintf(fd, "%s%s *tmp = 0;\n", ctx->get(), oclassname);
00917 if (cls->asCollArrayClass() || cls->asCollListClass())
00918 fprintf(fd, "%ss = coll->asCollArray()->retrieveAt(ind, (eyedb::Object*&)tmp);\n", ctx->get());
00919 else
00920 fprintf(fd, "%ss = coll->getObjectAt(ind, (eyedb::Object*&)tmp);\n", ctx->get());
00921 }
00922 else
00923 {
00924 fprintf(fd, "%s return 0;\n\n", ctx->get(), oclassname);
00925 fprintf(fd, "%seyedb::Value tmp;\n", ctx->get());
00926 if (cls->asCollArrayClass() || cls->asCollListClass())
00927 fprintf(fd, "%ss = coll->asCollArray()->retrieveAt(ind, tmp);\n", ctx->get());
00928 else
00929 fprintf(fd, "%ss = coll->getValueAt(ind, tmp);\n", ctx->get());
00930 }
00931
00932 if (not_basic)
00933 {
00934 fprintf(fd, "%sif (s) {if (rs) *rs = s; return (%s *)0;}\n", ctx->get(), oclassname);
00935 fprintf(fd, "%sreturn tmp;\n", ctx->get());
00936 }
00937 else
00938 {
00939 fprintf(fd, "%sif (s) {if (rs) *rs = s; return 0;}\n", ctx->get());
00940 fprintf(fd, "%sreturn tmp.%s;\n", ctx->get(),
00941 Value::getAttributeName(cl, (_isref || (_dim > 1)) ?
00942 True : False));
00943 }
00944
00945 fprintf(fd, "}\n\n");
00946 return Success;
00947 }
00948
00949 Status
00950 Attribute::generateGetMethod_C(Class *own, GenContext *ctx,
00951 Bool isoid,
00952 const GenCodeHints &hints,
00953 const char *_const)
00954 {
00955 FILE *fd = ctx->getFile();
00956 int ndims = typmod.ndims, i;
00957 int not_basic = NOT_BASIC();
00958 const char *ref = (not_basic ? getPtrRet() : " ");
00959 const char *pure_ref = (not_basic ? "*" : " ");
00960 const char *starg = STATUS_ARG(hints, False);
00961 const char *stargcom = STATUS_ARG(hints, True);
00962 const char *classname = isIndirect() ?
00963 className(cls, True) : className(cls, False);
00964
00965 if (isoid)
00966 fprintf(fd, "eyedb::Oid %s::%s(", className(own),
00967 ATTRNAME(name, tGetOid, hints));
00968 else
00969 fprintf(fd, "%s%s%s%s::%s(", _const, classname, ref,
00970 className(own), ATTRNAME_1(name, ATTRGET(cls), hints));
00971
00972 dimArgsGen(fd, ndims, True);
00973
00974 if (isoid)
00975
00976 fprintf(fd, "%s) %s\n{\n", (ndims ? stargcom : starg), "const");
00977 else
00978 fprintf(fd, "%seyedb::Bool *isnull%s) %s\n{\n", (ndims ? ", " : ""),
00979 stargcom, (!not_basic ? "const" : _const));
00980
00981 int const_obj = (!isoid && not_basic);
00982
00983 GenCodeHints::OpType optype = (isoid ? GenCodeHints::tGetOid:
00984 GenCodeHints::tGet);
00985 if (attr_cache)
00986 genAttrCacheGetPrologue(ctx, optype);
00987
00988 if (odl_dynamic_attr)
00989 dynamic_attr_gen(fd, ctx, this, op_GET, isoid, False,
00990 cls->asEnumClass() ?
00991 className(cls, True) : 0);
00992
00993 gbx_suspend(ctx);
00994
00995 if (isoid)
00996 fprintf(fd, "%seyedb::Oid __tmp;\n", ctx->get());
00997 else
00998 {
00999 if (const_obj)
01000 fprintf(fd, "%seyedb::Object *__o = 0, *__go;\n", ctx->get());
01001 else if (cls->asEnumClass())
01002 fprintf(fd, "%seyedblib::int32 %s__tmp%s;\n", ctx->get(),
01003 ref,
01004 (!strcmp(cls->getName(), "oid") ? "" : " = 0"));
01005 else
01006 fprintf(fd, "%s%s%s__tmp%s;\n", ctx->get(),
01007 classname, ref,
01008 (!strcmp(cls->getName(), "oid") ? "" : " = 0"));
01009 }
01010
01011 const char *psret = "";
01012 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01013 {
01014
01015
01016
01017
01018
01019 fprintf(fd, "%seyedb::Status s;\n", ctx->get());
01020 psret = "s = ";
01021 }
01022
01023 if (ndims)
01024 {
01025 fprintf(fd, "%seyedb::Size from = a%d;\n", ctx->get(), ndims-1);
01026 for (int i = ndims - 2 ; i >= 0; i--)
01027 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
01028
01029 if (odl_dynamic_attr) {
01030 if (isoid)
01031 fprintf(fd, "\n%s%s%s->getOid(this, &__tmp, 1, from);\n",
01032 ctx->get(), psret, __agrdyn);
01033 else
01034 fprintf(fd, "\n%s%s%s->getValue(this, (eyedb::Data *)&%s, 1, from, isnull);\n",
01035 ctx->get(), psret, __agrdyn, (const_obj ? "__o" : "__tmp"));
01036 }
01037 else {
01038 if (isoid)
01039 fprintf(fd, "\n%s%s%s[%d]->getOid(this, &__tmp, 1, from);\n",
01040 ctx->get(), psret, __agritems, num);
01041 else
01042 fprintf(fd, "\n%s%s%s[%d]->getValue(this, (eyedb::Data *)&%s, 1, from, isnull);\n",
01043 ctx->get(), psret, __agritems, num, (const_obj ? "__o" : "__tmp"));
01044 }
01045 }
01046 else if (isoid) {
01047 if (odl_dynamic_attr)
01048 fprintf(fd, "\n%s%s%s->getOid(this, &__tmp, 1, 0);\n",
01049 ctx->get(), psret, __agrdyn);
01050 else
01051 fprintf(fd, "\n%s%s%s[%d]->getOid(this, &__tmp, 1, 0);\n",
01052 ctx->get(), psret, __agritems, num);
01053 }
01054 else {
01055 if (odl_dynamic_attr)
01056 fprintf(fd, "\n%s%s%s->getValue(this, (eyedb::Data *)&%s, 1, 0, isnull);\n",
01057 ctx->get(), psret, __agrdyn, (const_obj ? "__o" : "__tmp"));
01058 else
01059 fprintf(fd, "\n%s%s%s[%d]->getValue(this, (eyedb::Data *)&%s, 1, 0, isnull);\n",
01060 ctx->get(), psret, __agritems, num, (const_obj ? "__o" : "__tmp"));
01061 }
01062
01063 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01064 {
01065 if (isoid || !strcmp(cls->getName(), "oid"))
01066 fprintf(fd, "%sif (s) {if (rs) *rs = s; return nulloid;}\n\n",
01067 ctx->get());
01068 else
01069 RETURN_ERROR(fd, ctx, cls, "");
01070 }
01071
01072 if (const_obj)
01073 {
01074 if (isIndirect())
01075 {
01076 fprintf(fd, "\n%sif (__o)\n", ctx->get());
01077 fprintf(fd, "%s {\n", ctx->get());
01078 if (!cls->asCollectionClass())
01079 {
01080 fprintf(fd, " %sif (eyedb::ObjectPeer::isGRTObject(__o)) {\n", ctx->get());
01081 if (attr_cache)
01082 {
01083 ctx->push();
01084 ctx->push();
01085 genAttrCacheGetEpilogue(ctx, optype);
01086 ctx->pop();
01087 ctx->pop();
01088 }
01089
01090 fprintf(fd, " %sreturn (%s *)__o;\n", ctx->get(),
01091 classname);
01092 fprintf(fd, " %s}\n", ctx->get());
01093 fprintf(fd, " %s__go = (%s *)make_object(__o, eyedb::False);\n", ctx->get(), classname);
01094 fprintf(fd, " %sif (__go)\n", ctx->get());
01095 fprintf(fd, " %s {\n", ctx->get());
01096 ctx->push();
01097 fprintf(fd, " %s__o = __go;\n", ctx->get());
01098 if (odl_dynamic_attr)
01099 fprintf(fd, " %s%s%s->setValue((Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01100 ctx->get(), psret, __agrdyn, (ndims ? "from" : "0"));
01101 else
01102 fprintf(fd, " %s%s%s[%d]->setValue((Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01103 ctx->get(), psret, __agritems, num, (ndims ? "from" : "0"));
01104
01105 fprintf(fd, " %seyedb::ObjectPeer::decrRefCount(__o);\n", ctx->get());
01106
01107 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01108 RETURN_ERROR(fd, ctx, cls, " ");
01109
01110 ctx->pop();
01111 fprintf(fd, " %s }\n", ctx->get());
01112
01113 if (attr_cache)
01114 {
01115 ctx->push();
01116 genAttrCacheGetEpilogue(ctx, optype);
01117 ctx->pop();
01118 }
01119 }
01120
01121 fprintf(fd, " %sreturn (%s%s)__o;\n", ctx->get(),
01122 classname, pure_ref);
01123 fprintf(fd, "%s }\n\n", ctx->get());
01124
01125 fprintf(fd, "%seyedb::Bool wasnull = (!__o ? eyedb::True : eyedb::False);\n", ctx->get());
01126 fprintf(fd, "%sif (!__o && db)\n", ctx->get());
01127 fprintf(fd, "%s {\n", ctx->get());
01128 fprintf(fd, "%s eyedb::Oid toid;\n", ctx->get());
01129 if (odl_dynamic_attr)
01130 fprintf(fd, "%s %s%s->getOid(this, &toid, 1, %s);\n",
01131 ctx->get(), psret, __agrdyn, (ndims ? "from" : "0"));
01132 else
01133 fprintf(fd, "%s %s%s[%d]->getOid(this, &toid, 1, %s);\n",
01134 ctx->get(), psret, __agritems, num, (ndims ? "from" : "0"));
01135 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01136 RETURN_ERROR(fd, ctx, cls, " ");
01137
01138 fprintf(fd, "%s if (toid.isValid())\n", ctx->get());
01139 fprintf(fd, "%s {\n", ctx->get());
01140 fprintf(fd, "%s %sdb->loadObject(&toid, &__o);\n",
01141 ctx->get(), psret);
01142 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01143 RETURN_ERROR(fd, ctx, cls, " ");
01144
01145
01146 if (!cls->asCollectionClass())
01147 {
01148 fprintf(fd, "%s if (!eyedb::ObjectPeer::isGRTObject(__o))\n",
01149 ctx->get());
01150 fprintf(fd, "%s {\n", ctx->get());
01151 fprintf(fd, "%s __go = (%s *)make_object"
01152 "(__o, eyedb::False);\n", ctx->get(), classname);
01153 fprintf(fd, "%s if (__go) __o = __go;\n", ctx->get());
01154 fprintf(fd, "%s }\n", ctx->get());
01155 }
01156
01157 fprintf(fd, "%s }\n", ctx->get());
01158 fprintf(fd, "%s }\n", ctx->get());
01159
01160 fprintf(fd, "\n%sif (__o && wasnull)\n", ctx->get());
01161 fprintf(fd, "%s {\n", ctx->get());
01162 if (odl_dynamic_attr)
01163 fprintf(fd, " %s%s%s->setValue((eyedb::Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01164 ctx->get(), psret, __agrdyn, (ndims ? "from" : "0"));
01165 else
01166 fprintf(fd, " %s%s%s[%d]->setValue((eyedb::Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01167 ctx->get(), psret, __agritems, num, (ndims ? "from" : "0"));
01168 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01169 RETURN_ERROR(fd, ctx, cls, " ");
01170
01171
01172 fprintf(fd, " %s__o->release();\n", ctx->get());
01173 fprintf(fd, "%s }\n", ctx->get());
01174 }
01175 else if (!cls->asCollectionClass())
01176 {
01177 fprintf(fd, "\n%sif (__o)\n", ctx->get());
01178 fprintf(fd, "%s {\n", ctx->get());
01179 fprintf(fd, " %sif (eyedb::ObjectPeer::isGRTObject(__o)) {\n", ctx->get());
01180 if (attr_cache)
01181 {
01182 ctx->push();
01183 ctx->push();
01184 genAttrCacheGetEpilogue(ctx, optype);
01185 ctx->pop();
01186 ctx->pop();
01187 }
01188
01189 fprintf(fd, " %sreturn (%s *)__o;\n", ctx->get(),
01190 classname);
01191 fprintf(fd, " %s}\n", ctx->get());
01192 fprintf(fd, " %s__go = (%s *)make_object(__o, eyedb::False);\n", ctx->get(), classname);
01193 fprintf(fd, " %sif (__go)\n", ctx->get());
01194 fprintf(fd, " %s {\n", ctx->get());
01195 ctx->push();
01196 fprintf(fd, " %s__o = __go;;\n", ctx->get());
01197 if (odl_dynamic_attr)
01198 fprintf(fd, " %s%s%s->setValue((eyedb::Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01199 ctx->get(), psret, __agrdyn, (ndims ? "from" : "0"));
01200 else
01201 fprintf(fd, " %s%s%s[%d]->setValue((Agregat *)this, (eyedb::Data)&__o, 1, %s);\n",
01202 ctx->get(), psret, __agritems, num, (ndims ? "from" : "0"));
01203 fprintf(fd, " %seyedb::ObjectPeer::decrRefCount(__o);\n", ctx->get());
01204
01205 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01206 RETURN_ERROR(fd, ctx, cls, " ");
01207
01208 ctx->pop();
01209 fprintf(fd, " %s }\n", ctx->get());
01210 fprintf(fd, "%s }\n", ctx->get());
01211 }
01212 }
01213
01214 if (attr_cache)
01215 genAttrCacheGetEpilogue(ctx, optype);
01216
01217 if (const_obj)
01218 fprintf(fd, "%sreturn (%s%s)__o;\n", ctx->get(),
01219 classname, pure_ref);
01220 else if (cls->asEnumClass())
01221 fprintf(fd, "%sreturn (%s)__tmp;\n", ctx->get(), className(cls, True));
01222 else
01223 fprintf(fd, "%sreturn __tmp;\n", ctx->get());
01224
01225 fprintf(fd, "}\n\n");
01226
01227
01228
01229 if (isVarDim() && !isoid && !*_const && !IS_STRING())
01230 {
01231 fprintf(fd, "unsigned int %s::%s(%s) const\n{\n", className(own),
01232 ATTRNAME(name, tGetCount, hints), starg);
01233
01234 if (attr_cache)
01235 genAttrCacheGetPrologue(ctx, GenCodeHints::tGetCount);
01236
01237 if (odl_dynamic_attr)
01238 dynamic_attr_gen(fd, ctx, this, op_OTHER, isoid);
01239
01240 gbx_suspend(ctx);
01241
01242 fprintf(fd, "%seyedb::Size size;\n", ctx->get());
01243 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01244 {
01245
01246
01247
01248
01249 fprintf(fd, "%seyedb::Status s;\n", ctx->get());
01250 }
01251 if (odl_dynamic_attr)
01252 fprintf(fd, "%s%s%s->getSize(this, size);\n", ctx->get(), psret,
01253 __agrdyn);
01254 else
01255 fprintf(fd, "%s%s%s[%d]->getSize(this, size);\n", ctx->get(), psret,
01256 __agritems, num);
01257 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01258 fprintf(fd, "%sif (s) {if (rs) *rs = s; return 0;}\n", ctx->get());
01259
01260 if (attr_cache)
01261 genAttrCacheGetEpilogue(ctx, GenCodeHints::tGetCount);
01262
01263 fprintf(fd, "%sreturn (int)size;\n", ctx->get());
01264 fprintf(fd, "}\n\n");
01265 }
01266
01267 if (cls->asCollectionClass())
01268 return generateCollGetMethod_C(own, ctx, isoid,
01269 hints, _const);
01270 return Success;
01271 }
01272
01273 Status Attribute::generateBody_C(Class *own,
01274 GenContext *ctx,
01275 const GenCodeHints &hints)
01276 {
01277 FILE *fd = ctx->getFile();
01278 int ndims = typmod.ndims, i;
01279 int maxdims = typmod.maxdims;
01280 int not_basic = NOT_BASIC();
01281 const char *ref = (not_basic ? getPtrRet() : " ");
01282 int is_string = IS_STRING();
01283 int is_raw = IS_RAW();
01284 const char *starg = STATUS_ARG(hints, False);
01285 const char *stargcom = STATUS_ARG(hints, True);
01286 const char *psret = "";
01287
01288
01289 if (is_string || is_raw)
01290 {
01291 const char *sclass = SCLASS();
01292 const char *sarg = SARGIN();
01293 #ifdef ODL_STD_STRING
01294 if (is_string)
01295 fprintf(fd, "eyedb::Status %s::%s(const std::string &_%s%s)\n{\n",
01296 className(own), ATTRNAME(name, tSet, hints), name,
01297 sarg);
01298 else
01299 fprintf(fd, "eyedb::Status %s::%s(const %s *_%s%s)\n{\n",
01300 className(own), ATTRNAME(name, tSet, hints), sclass, name,
01301 sarg);
01302 #else
01303 fprintf(fd, "eyedb::Status %s::%s(const %s *_%s%s)\n{\n",
01304 className(own), ATTRNAME(name, tSet, hints), sclass, name,
01305 sarg);
01306 #endif
01307
01308 if (attr_cache)
01309 genAttrCacheSetPrologue(ctx, GenCodeHints::tSet, True);
01310
01311 if (odl_dynamic_attr)
01312 dynamic_attr_gen(fd, ctx, this, op_SET);
01313
01314 gbx_suspend(ctx);
01315 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
01316
01317 if (isVarDim())
01318 {
01319 fprintf(fd, "%seyedb::Size size;\n", ctx->get());
01320
01321 #ifdef ODL_STD_STRING
01322 if (is_string)
01323 fprintf(fd, "%seyedb::Size len = _%s.size() + 1;\n\n", ctx->get(), name);
01324 #else
01325 if (is_string)
01326 fprintf(fd, "%seyedb::Size len = ::strlen(_%s) + 1;\n\n", ctx->get(), name);
01327 #endif
01328 if (odl_dynamic_attr)
01329 fprintf(fd, "%sstatus = %s->getSize(this, size);\n", ctx->get(),
01330 __agrdyn);
01331 else
01332 fprintf(fd, "%sstatus = %s[%d]->getSize(this, size);\n", ctx->get(),
01333 __agritems, num);
01334 fprintf(fd, "%sif (status)\n%s return status;\n\n", ctx->get(),
01335 ctx->get());
01336 fprintf(fd, "%sif (size != len)\n", ctx->get());
01337 ctx->push();
01338 if (odl_dynamic_attr)
01339 fprintf(fd, "%sstatus = %s->setSize(this, len);\n", ctx->get(),
01340 __agrdyn);
01341 else
01342 fprintf(fd, "%sstatus = %s[%d]->setSize(this, len);\n", ctx->get(),
01343 __agritems, num);
01344 ctx->pop();
01345 fprintf(fd, "%sif (status)\n%s return status;\n\n", ctx->get(),
01346 ctx->get());
01347
01348 #ifdef ODL_STD_STRING
01349 if (odl_dynamic_attr) {
01350 if (is_string)
01351 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s.c_str(), len, 0);\n",
01352 ctx->get(), __agrdyn, name);
01353 else
01354 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s., len, 0);\n",
01355 ctx->get(), __agrdyn, name);
01356 }
01357 else {
01358 if (is_string)
01359 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s.c_str(), len, 0);\n",
01360 ctx->get(), __agritems, num, name);
01361 else
01362 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01363 ctx->get(), __agritems, num, name);
01364 }
01365 #else
01366 if (odl_dynamic_attr)
01367 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01368 ctx->get(), __agrdyn, name);
01369 else
01370 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01371 ctx->get(), __agritems, num, name);
01372 #endif
01373
01374 if (attr_cache)
01375 genAttrCacheSetEpilogue(ctx, GenCodeHints::tSet, True);
01376 fprintf(fd, "%sreturn status;\n\n", ctx->get());
01377 }
01378 else
01379 {
01380 if (is_string) {
01381 fprintf(fd, "%sunsigned char data[%d];\n", ctx->get(), maxdims);
01382 #ifdef ODL_STD_STRING
01383 fprintf(fd, "%seyedb::Size len = _%s.size();\n", ctx->get(), name);
01384 #else
01385 fprintf(fd, "%seyedb::Size len = ::strlen(_%s);\n", ctx->get(), name);
01386 #endif
01387 }
01388 fprintf(fd, "%sif (len >= %d)\n", ctx->get(), maxdims);
01389 #ifdef ODL_STD_STRING
01390 if (is_string)
01391 fprintf(fd, "%s return eyedb::Exception::make(eyedb::IDB_ERROR, "
01392 "\"string `%%s' [%%d] too long for attribute %s::%s, maximum "
01393 "is %d\\n\", _%s.c_str(), len);\n", ctx->get(),
01394 class_owner->getName(), name, maxdims, name);
01395 else
01396 fprintf(fd, "%s return eyedb::Exception::make(eyedb::IDB_ERROR, "
01397 "\"string `%%s' [%%d] too long for attribute %s::%s, maximum "
01398 "is %d\\n\", _%s, len);\n", ctx->get(),
01399 class_owner->getName(), name, maxdims, name);
01400 #else
01401 fprintf(fd, "%s return eyedb::Exception::make(eyedb::IDB_ERROR, "
01402 "\"string `%%s' [%%d] too long for attribute %s::%s, maximum "
01403 "is %d\\n\", _%s, len);\n", ctx->get(),
01404 class_owner->getName(), name, maxdims, name);
01405 #endif
01406 if (is_string) {
01407 fprintf(fd, "%smemset(data, 0, %d);\n", ctx->get(), maxdims);
01408 #ifdef ODL_STD_STRING
01409 fprintf(fd, "%sstrncpy((char *)data, _%s.c_str(), min(%d, len));\n",
01410 ctx->get(), name, maxdims-1);
01411 #else
01412 fprintf(fd, "%sstrncpy((char *)data, _%s, min(%d, len));\n",
01413 ctx->get(), name, maxdims-1);
01414 #endif
01415 if (odl_dynamic_attr)
01416 fprintf(fd, "%sstatus = %s->setValue(this, data, %d, 0);\n",
01417 ctx->get(), __agrdyn, maxdims);
01418 else
01419 fprintf(fd, "%sstatus = %s[%d]->setValue(this, data, %d, 0);\n",
01420 ctx->get(), __agritems, num, maxdims);
01421 }
01422 else {
01423 #ifdef ODL_STD_STRING
01424 if (odl_dynamic_attr) {
01425 if (is_string)
01426 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s.c_str(), len, 0);\n",
01427 ctx->get(), __agrdyn, name);
01428 else
01429 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01430 ctx->get(), __agrdyn, name);
01431 }
01432 else {
01433 if (is_string)
01434 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s.c_str(), len, 0);\n",
01435 ctx->get(), __agritems, num, name);
01436 else
01437 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01438 ctx->get(), __agritems, num, name);
01439 }
01440 #else
01441 if (odl_dynamic_attr)
01442 fprintf(fd, "%sstatus = %s->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01443 ctx->get(), __agrdyn, name);
01444 else
01445 fprintf(fd, "%sstatus = %s[%d]->setValue(this, (eyedb::Data)_%s, len, 0);\n",
01446 ctx->get(), __agritems, num, name);
01447 #endif
01448 }
01449
01450 if (attr_cache)
01451 genAttrCacheSetEpilogue(ctx, GenCodeHints::tSet, True);
01452 fprintf(fd, "%sreturn status;\n\n", ctx->get());
01453 }
01454 fprintf(fd, "}\n\n");
01455 }
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467 #ifdef NO_DIRECT_SET
01468 if (isIndirect() || !not_basic)
01469 #endif
01470 generateSetMethod_C(own, ctx, False, hints);
01471 #ifdef NO_DIRECT_SET
01472 else
01473 #endif
01474 #if defined(SET_COUNT_DIRECT) || defined(NO_DIRECT_SET)
01475
01476
01477 if (isVarDim() && !is_string)
01478 {
01479 fprintf(fd, "eyedb::Status %s::%s(", className(own),
01480 ATTRNAME(name, tSetCount, hints));
01481
01482 dimArgsGen(fd, ndims, True);
01483
01484 fprintf(fd, ")\n{\n");
01485
01486 if (attr_cache)
01487 genAttrCacheSetPrologue(ctx, GenCodeHints::tSetCount);
01488
01489 if (odl_dynamic_attr)
01490 dynamic_attr_gen(fd, ctx, this, op_SET);
01491
01492 gbx_suspend(ctx);
01493
01494 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
01495
01496 fprintf(fd, "%seyedb::Size from = a%d;\n", ctx->get(), ndims-1);
01497 for (int i = ndims - 2 ; i >= 0; i--)
01498 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
01499
01500
01501
01502 #if 0
01503 fprintf(fd, "\n%seyedb::Size size;\n", ctx->get());
01504 if (odl_dynamic_attr)
01505 fprintf(fd, "%sstatus = %s->getSize(this, size);\n",
01506 ctx->get(), __agrdyn);
01507 else
01508 fprintf(fd, "%sstatus = %s[%d]->getSize(this, size);\n",
01509 ctx->get(), __agritems, num);
01510 fprintf(fd, "%sif (status)\n%s return status;\n\n", ctx->get(),
01511 ctx->get());
01512
01513 fprintf(fd, "%sif (size < from)\n", ctx->get());
01514 ctx->push();
01515 #endif
01516 if (odl_dynamic_attr)
01517 fprintf(fd, "%sstatus = %s->setSize(this, from);\n",
01518 ctx->get(), __agrdyn);
01519 else
01520 fprintf(fd, "%sstatus = %s[%d]->setSize(this, from);\n",
01521 ctx->get(), __agritems, num);
01522
01523 #if 0
01524 ctx->pop();
01525 #endif
01526
01527 if (attr_cache)
01528 genAttrCacheSetEpilogue(ctx, GenCodeHints::tSetCount);
01529
01530 fprintf(fd, "%sreturn status;\n", ctx->get(),
01531 ctx->get());
01532
01533 fprintf(fd, "}\n\n");
01534 }
01535 #endif
01536
01537
01538 if (is_string || is_raw)
01539 {
01540 const char *sclass = SCLASS();
01541 const char *sarg = SARGOUT();
01542
01543 #ifdef ODL_STD_STRING
01544 if (is_string)
01545 fprintf(fd, "std::string %s::%s(%seyedb::Bool *isnull%s) const\n{\n",
01546 className(own), ATTRNAME(name, tGet, hints), sarg,
01547 stargcom);
01548 else
01549 fprintf(fd, "const %s *%s::%s(%seyedb::Bool *isnull%s) const\n{\n",
01550 sclass, className(own), ATTRNAME(name, tGet, hints), sarg,
01551 stargcom);
01552 #else
01553 fprintf(fd, "const %s *%s::%s(%seyedb::Bool *isnull%s) const\n{\n",
01554 sclass, className(own), ATTRNAME(name, tGet, hints), sarg,
01555 stargcom);
01556 #endif
01557
01558 if (attr_cache)
01559 genAttrCacheGetPrologue(ctx, GenCodeHints::tGet, True);
01560
01561 if (odl_dynamic_attr)
01562 dynamic_attr_gen(fd, ctx, this, op_GET, False, IDBBOOL(is_string));
01563
01564 gbx_suspend(ctx);
01565
01566 fprintf(fd, "%seyedb::Data data;\n", ctx->get());
01567 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01568 {
01569
01570
01571
01572
01573
01574 fprintf(fd, "%seyedb::Status s;\n", ctx->get());
01575 psret = "s = ";
01576 }
01577 if (odl_dynamic_attr)
01578 fprintf(fd, "\n%s%s%s->getValue(this, (eyedb::Data *)&data, eyedb::Attribute::directAccess, 0, isnull);\n",
01579 ctx->get(), psret, __agrdyn);
01580 else
01581 fprintf(fd, "\n%s%s%s[%d]->getValue(this, (eyedb::Data *)&data, eyedb::Attribute::directAccess, 0, isnull);\n",
01582 ctx->get(), psret, __agritems, num);
01583
01584 if (hints.error_policy == GenCodeHints::StatusErrorPolicy)
01585 RETURN_ERROR(fd, ctx, cls, "");
01586
01587 if (isVarDim())
01588 fprintf(fd, "%sif (!data) data = nulldata;\n", ctx->get());
01589
01590 if (attr_cache)
01591 genAttrCacheGetEpilogue(ctx, GenCodeHints::tGet, True);
01592
01593 if (is_raw && isVarDim())
01594 fprintf(fd, "%sif (len) *len = %s();\n", ctx->get(),
01595 ATTRNAME(name, tGetCount, hints));
01596
01597 if (attr_cache) {
01598 #ifdef ODL_STD_STRING
01599 fprintf(fd, "%sreturn %s;\n", ctx->get(),
01600 atc_name(name));
01601 #else
01602 fprintf(fd, "%sreturn (const %s *)%s;\n", ctx->get(), sclass,
01603 atc_name(name));
01604 #endif
01605 }
01606 else
01607 fprintf(fd, "%sreturn (const %s *)data;\n", ctx->get(), sclass);
01608 fprintf(fd, "}\n\n");
01609 }
01610 else if (not_basic)
01611 generateGetMethod_C(own, ctx, False, hints, "const ");
01612
01613 generateGetMethod_C(own, ctx, False, hints, "");
01614
01615 if (isIndirect())
01616 {
01617 generateSetMethod_C(own, ctx, True, hints);
01618 generateGetMethod_C(own, ctx, True, hints, "");
01619 }
01620 else if (cls->asCollectionClass())
01621 generateCollGetMethod_C(own, ctx, True, hints, "");
01622
01623 generateSetMethod_C(own, ctx, hints);
01624
01625 return Success;
01626 }
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643 #define ATC_NOVD // acronym for ATtribute Cache NO VarDim
01644
01645 void
01646 Attribute::genAttrCacheDecl(GenContext *ctx)
01647 {
01648 if (isNative()) return;
01649
01650 #ifdef ATC_NOVD
01651
01652 #endif
01653 FILE *fd = ctx->getFile();
01654
01655 int is_string = IS_STRING();
01656 int is_raw = IS_RAW();
01657 int i;
01658
01659 if (isVarDim())
01660 fprintf(fd, "%sunsigned int %s;\n", ctx->get(), atc_cnt(name));
01661 #ifdef ATC_NOVD
01662 if (isVarDim() && !(is_string || is_raw))
01663 return;
01664 #endif
01665
01666 fprintf(fd, "%sunsigned char ", ctx->get());
01667
01668 #ifndef ATC_NOVD
01669 if (isVarDim())
01670 fprintf(fd, getPtrRet());
01671 #endif
01672
01673 fprintf(fd, atc_set(name));
01674 if (!is_string && !is_raw)
01675 {
01676 for (i = 0; i < typmod.ndims; i++)
01677 if (typmod.dims[i] > 0)
01678 fprintf(fd, "[%d]", typmod.dims[i]);
01679 }
01680 fprintf(fd, ";\n");
01681
01682 if (is_string || is_raw)
01683 {
01684 #ifdef ODL_STD_STRING
01685 #ifdef ATTR_CACHE_DIRECT
01686 if (is_string)
01687 fprintf(fd, "%sstd::string %s;\n", ctx->get(), atc_name(name));
01688 else
01689 fprintf(fd, "%sconst %s *%s;\n", ctx->get(), SCLASS(), atc_name(name));
01690 #else
01691 if (is_string)
01692 fprintf(fd, "%sstd::string %s;\n", ctx->get(), atc_name(name));
01693 else
01694 fprintf(fd, "%s%s *%s;\n", ctx->get(), SCLASS(), atc_name(name));
01695 #endif
01696 #else
01697 #ifdef ATTR_CACHE_DIRECT
01698 fprintf(fd, "%sconst %s *%s;\n", ctx->get(), SCLASS(), atc_name(name));
01699 #else
01700 fprintf(fd, "%s%s *%s;\n", ctx->get(), SCLASS(), atc_name(name));
01701 #endif
01702 #endif
01703 return;
01704 }
01705 else
01706 fprintf(fd, "%s%s%s%s%s",
01707 ctx->get(), className(cls, (isIndirect() ? True : False)),
01708 (isVarDim() ? getPtrRet() : " "), (NOT_BASIC() ? getPtrRet() : " "), atc_name(name));
01709
01710 for (i = 0; i < typmod.ndims; i++)
01711 if (typmod.dims[i] > 0)
01712 fprintf(fd, "[%d]", typmod.dims[i]);
01713
01714 fprintf(fd, ";\n");
01715 }
01716
01717 void
01718 Attribute::genAttrCacheEmpty(GenContext *ctx)
01719 {
01720 if (isNative())
01721 return;
01722
01723 #ifdef ATC_NOVD
01724
01725 #endif
01726
01727 int is_string = IS_STRING();
01728 int is_raw = IS_RAW();
01729
01730 FILE *fd = ctx->getFile();
01731 if (isVarDim())
01732 fprintf(fd, "%s%s = ~0;\n", ctx->get(), atc_cnt(name));
01733
01734 #ifdef ATC_NOVD
01735 if (isVarDim() && !(is_string || is_raw)) return;
01736 #endif
01737
01738 if (!typmod.ndims || is_string || is_raw) {
01739 #ifdef ODL_STD_STRING
01740
01741
01742
01743
01744
01745 fprintf(fd, "%s%s = 0;\n", ctx->get(), atc_set(name));
01746 #else
01747 fprintf(fd, "%s%s = 0;\n", ctx->get(), atc_set(name));
01748 #endif
01749 }
01750 else
01751 fprintf(fd, "%smemset(%s, 0, %d);\n", ctx->get(), atc_set(name),
01752 typmod.pdims);
01753 }
01754
01755 void
01756 Attribute::genAttrCacheGarbage(GenContext *ctx)
01757 {
01758 if (isNative()) return;
01759 #ifdef ATC_NOVD
01760 if (isVarDim() && !(IS_STRING() || IS_RAW())) return;
01761 #endif
01762
01763
01764 FILE *fd = ctx->getFile();
01765
01766 if (IS_STRING() || IS_RAW())
01767 {
01768 #ifndef ATTR_CACHE_DIRECT
01769 fprintf(fd, "%sif (%s) free(%s);\n", ctx->get(), atc_set(name),
01770 atc_name(name));
01771 #endif
01772 return;
01773 }
01774
01775 if (!isVarDim()) return;
01776
01777
01778
01779
01780
01781
01782 fprintf(fd, "%sif (%s) {free(%s); free(%s);}\n", ctx->get(), atc_cnt(name),
01783 atc_set(name), atc_name(name));
01784 }
01785
01786 void
01787 Attribute::genAttrCacheGetPrologue(GenContext *ctx, int optype,
01788 Bool is_raw_string)
01789 {
01790 #ifdef ATC_NOVD
01791 if (optype != GenCodeHints::tGetCount)
01792 {
01793 if (isVarDim() && !is_raw_string)
01794 return;
01795 if ((IS_STRING() || IS_RAW()) && !is_raw_string)
01796 return;
01797 }
01798 #endif
01799
01800 if (optype == GenCodeHints::tGetOid && !isIndirect()) return;
01801
01802 if (optype == GenCodeHints::tGetOid) return;
01803
01804 FILE *fd = ctx->getFile();
01805
01806 if (optype == GenCodeHints::tGetCount)
01807 {
01808 fprintf(fd, "%sif (%s != (unsigned int)~0) return %s;\n", ctx->get(), atc_cnt(name),
01809 atc_cnt(name));
01810 return;
01811 }
01812
01813
01814
01815 if (is_raw_string)
01816 {
01817 if (IS_RAW() && isVarDim())
01818 {
01819 fprintf(fd, "%sif (%s) {if (len) *len = %s; return %s;}\n",
01820 ctx->get(), atc_set(name), atc_cnt(name), atc_name(name));
01821 }
01822 else
01823 fprintf(fd, "%sif (%s) return %s;\n", ctx->get(), atc_set(name),
01824 atc_name(name));
01825 return;
01826 }
01827
01828 if (isVarDim())
01829 fprintf(fd, "%sif (%s > a%d && %s",
01830 ctx->get(), atc_cnt(name), typmod.ndims-1, atc_set(name));
01831 else
01832 fprintf(fd, "%sif (%s", ctx->get(), atc_set(name));
01833
01834 int i;
01835 for (i = 0; i < typmod.ndims; i++)
01836 fprintf(fd, "[a%d]", i);
01837 fprintf(fd, ") return %s", atc_name(name));
01838
01839 for (i = 0; i < typmod.ndims; i++)
01840 fprintf(fd, "[a%d]", i);
01841 fprintf(fd, ";\n\n");
01842 }
01843
01844 void
01845 Attribute::genAttrCacheGetEpilogue(GenContext *ctx, int optype,
01846 Bool is_raw_string)
01847 {
01848 #ifdef ATC_NOVD
01849 if (optype != GenCodeHints::tGetCount)
01850 {
01851 if (isVarDim() && !is_raw_string)
01852 return;
01853 if ((IS_STRING() || IS_RAW()) && !is_raw_string)
01854 return;
01855 }
01856 #endif
01857
01858 if (optype == GenCodeHints::tGetOid && !isIndirect()) return;
01859
01860 if (optype == GenCodeHints::tGetOid) return;
01861
01862 FILE *fd = ctx->getFile();
01863
01864 const char *classname = className(class_owner);
01865
01866 if (optype == GenCodeHints::tGetCount)
01867 {
01868 fprintf(fd, "%s%s->%s = size;\n", ctx->get(), atc_this(classname),
01869 atc_cnt(name));
01870 return;
01871 }
01872
01873 if (is_raw_string)
01874 {
01875 fprintf(fd, "%s%s->%s = 1;\n", ctx->get(), atc_this(classname),
01876 atc_set(name));
01877
01878 if (IS_RAW())
01879 {
01880 #ifdef ATTR_CACHE_DIRECT
01881 if (isVarDim())
01882 {
01883 const char *scnt = ATTRNAME(name, tGetCount, *phints);
01884 fprintf(fd, "%s%s->%s = %s();\n", ctx->get(),
01885 atc_this(classname), atc_cnt(name), scnt);
01886 }
01887
01888 fprintf(fd, "%s%s->%s = data;\n", ctx->get(),
01889 atc_this(classname), atc_name(name));
01890 #else
01891 if (isVarDim())
01892 {
01893 const char *scnt = ATTRNAME(name, tGetCount, *phints);
01894 fprintf(fd, "%s%s->%s = rawdup(data, %s());\n", ctx->get(),
01895 atc_this(classname), atc_name(name), scnt);
01896 fprintf(fd, "%s%s->%s = %s();\n", ctx->get(),
01897 atc_this(classname), atc_cnt(name), scnt);
01898
01899 }
01900 else
01901 fprintf(fd, "%s%s->%s = rawdup(data, %d);\n", ctx->get(),
01902 atc_this(classname), atc_name(name), typmod.pdims);
01903 #endif
01904 }
01905 #ifdef ATTR_CACHE_DIRECT
01906 else
01907 fprintf(fd, "%s%s->%s = (const char *)data;\n", ctx->get(),
01908 atc_this(classname), atc_name(name));
01909 #else
01910 else
01911 fprintf(fd, "%s%s->%s = strdup((const char *)data);\n", ctx->get(),
01912 atc_this(classname), atc_name(name));
01913 #endif
01914 return;
01915 }
01916
01917 if (isVarDim())
01918 {
01919
01920
01921 fprintf(fd, "%sif (%s) {free(%s->%s); free(%s->%s);}\n",
01922 ctx->get(), atc_cnt(name), atc_this(classname), atc_set(name),
01923 atc_this(classname), atc_name(name));
01924 fprintf(fd, "%s%s->%s = a%d+1;\n", ctx->get(), atc_this(classname), atc_cnt(name),
01925 typmod.ndims-1);
01926 fprintf(fd, "%s%s->%s",
01927 ctx->get(), atc_this(classname), atc_set(name));
01928 int i;
01929 for (i = 0; i < typmod.ndims; i++)
01930 if (typmod.dims[i] > 0) fprintf(fd, "[a%d]", i);
01931
01932 fprintf(fd, " = (unsigned char *)malloc(a%d+1);\n", typmod.ndims-1);
01933
01934 fprintf(fd, "%s%s->%s",
01935 ctx->get(), atc_this(classname), atc_name(name));
01936 for (i = 0; i < typmod.ndims; i++)
01937 if (typmod.dims[i] > 0) fprintf(fd, "[a%d]", i);
01938 fprintf(fd, " = (%s *%s)malloc((a%d+1)*sizeof(%s *));\n",
01939 className(cls, (isIndirect() ? True : False)),
01940 (NOT_BASIC() ? getPtrRet() : " "),
01941 typmod.ndims-1, className(cls, True));
01942 }
01943
01944 fprintf(fd, "%s%s->%s", ctx->get(), atc_this(classname), atc_set(name));
01945 int i;
01946 for (i = 0; i < typmod.ndims; i++)
01947 fprintf(fd, "[a%d]", i);
01948
01949 fprintf(fd, " = 1;\n");
01950 fprintf(fd, "%s%s->%s", ctx->get(), atc_this(classname), atc_name(name));
01951 for (i = 0; i < typmod.ndims; i++)
01952 fprintf(fd, "[a%d]", i);
01953
01954 fprintf(fd, " = ");
01955
01956 if (NOT_BASIC())
01957 fprintf(fd, "(%s *)__o", className(cls, True));
01958 else
01959 fprintf(fd, "(%s)__tmp", className(cls, False));
01960 fprintf(fd, ";\n");
01961 }
01962
01963 void
01964 Attribute::genAttrCacheSetPrologue(GenContext *ctx, int optype,
01965 Bool is_raw_string)
01966 {
01967
01968 }
01969
01970 void
01971 Attribute::genAttrCacheSetEpilogue(GenContext *ctx, int optype,
01972 Bool is_raw_string)
01973 {
01974 #ifdef ATC_NOVD
01975 if (optype != GenCodeHints::tSetCount)
01976 {
01977 if (isVarDim() && !is_raw_string)
01978 return;
01979 if ((IS_STRING() || IS_RAW()) && !is_raw_string)
01980 return;
01981 }
01982 #endif
01983 if (optype == GenCodeHints::tSetOid && !isIndirect()) return;
01984
01985 if (optype == GenCodeHints::tSetOid) return;
01986
01987 FILE *fd = ctx->getFile();
01988
01989 if (optype == GenCodeHints::tSetCount)
01990 {
01991
01992
01993 return;
01994 }
01995
01996 const char *classname = className(class_owner);
01997
01998 fprintf(fd, "%sif (!status) {\n", ctx->get());
01999 ctx->push();
02000
02001 if (is_raw_string)
02002 {
02003 if (IS_RAW() && !isVarDim())
02004 {
02005 fprintf(fd, "%sif (len == %d) {\n", ctx->get(), typmod.pdims);
02006 ctx->push();
02007 }
02008
02009 #ifndef ATTR_CACHE_DIRECT
02010 fprintf(fd, "%sif (%s) free(%s->%s);\n", ctx->get(), atc_set(name),
02011 atc_this(classname), atc_name(name));
02012 #endif
02013 fprintf(fd, "%s%s->%s = 1;\n", ctx->get(), atc_this(classname),
02014 atc_set(name));
02015
02016 if (IS_RAW())
02017 {
02018 #ifdef ATTR_CACHE_DIRECT
02019 fprintf(fd, "%s%s->%s = %s(%s);\n", ctx->get(),
02020 atc_this(classname), atc_name(name),
02021 ATTRNAME(name, tGet, *phints),
02022 (isVarDim() ? "(unsigned int *)0" : ""));
02023 #else
02024 fprintf(fd, "%s%s->%s = rawdup(_%s, len);\n", ctx->get(),
02025 atc_this(classname), atc_name(name), name);
02026 #endif
02027 if (isVarDim())
02028 fprintf(fd, "%s%s->%s = len;\n", ctx->get(),
02029 atc_this(classname), atc_cnt(name));
02030 else
02031 {
02032 ctx->pop();
02033 fprintf(fd, "%s}\n", ctx->get());
02034 }
02035 }
02036 else
02037 {
02038 #ifdef ATTR_CACHE_DIRECT
02039 fprintf(fd, "%s%s->%s = %s();\n", ctx->get(),
02040 atc_this(classname), atc_name(name),
02041 ATTRNAME(name, tGet, *phints));
02042 #else
02043 if (isVarDim())
02044 fprintf(fd, "%s%s->%s = strdup((const char *)_%s);\n", ctx->get(),
02045 atc_this(classname), atc_name(name), name);
02046 else
02047 fprintf(fd, "%s%s->%s = strdup((const char *)data);\n", ctx->get(),
02048 atc_this(classname), atc_name(name));
02049 #endif
02050 }
02051 ctx->pop();
02052 fprintf(fd, "%s}\n", ctx->get());
02053 return;
02054 }
02055
02056 fprintf(fd, "%s%s->%s", ctx->get(), atc_this(classname), atc_set(name));
02057 int i;
02058 for (i = 0; i < typmod.ndims; i++)
02059 fprintf(fd, "[a%d]", i);
02060
02061 fprintf(fd, " = 1;\n");
02062 fprintf(fd, "%s%s->%s", ctx->get(), atc_this(classname), atc_name(name));
02063 for (i = 0; i < typmod.ndims; i++)
02064 fprintf(fd, "[a%d]", i);
02065
02066 fprintf(fd, " = ");
02067
02068
02069
02070
02071
02072
02073
02074
02075 if (NOT_BASIC())
02076 fprintf(fd, "(%s *)_%s", className(cls, True), name);
02077 else
02078 fprintf(fd, "(%s)_%s", className(cls, False), name);
02079
02080 fprintf(fd, ";\n");
02081 ctx->pop();
02082 fprintf(fd, "%s}\n", ctx->get());
02083 }
02084
02085 Status Attribute::generateCode_C(Class *own,
02086 const GenCodeHints &hints,
02087 GenContext *ctxH,
02088 GenContext *ctxC)
02089 {
02090 FILE *fdh = ctxH->getFile();
02091 int ndims = typmod.ndims, i;
02092 int not_basic = NOT_BASIC();
02093 const char *ref1 = (not_basic ? getPtrSet() : " ");
02094
02095 const char *ref2 = (not_basic ? getPtrRet() : " ");
02096 const char *comma = (ndims ? ", " : "");
02097 int is_string = IS_STRING();
02098 int is_raw = IS_RAW();
02099 const char *starg = STATUS_PROTO(hints, False);
02100 const char *stargcom = STATUS_PROTO(hints, True);
02101 const char *classname = isIndirect() ?
02102 className(cls, True) : className(cls, False);
02103
02104
02105 fprintf(fdh, "\n");
02106 if (is_string || is_raw) {
02107 #ifdef ODL_STD_STRING
02108 if (is_string)
02109 fprintf(fdh, "%seyedb::Status %s(const std::string &%s);\n", ctxH->get(),
02110 ATTRNAME(name, tSet, hints), SARGIN());
02111 else
02112 fprintf(fdh, "%seyedb::Status %s(const %s *%s);\n", ctxH->get(),
02113 ATTRNAME(name, tSet, hints), SCLASS(), SARGIN());
02114 #else
02115 fprintf(fdh, "%seyedb::Status %s(const %s *%s);\n", ctxH->get(),
02116 ATTRNAME(name, tSet, hints), SCLASS(), SARGIN());
02117 #endif
02118 }
02119
02120 #ifdef NO_DIRECT_SET
02121 if (isIndirect() || !not_basic)
02122 #endif
02123 {
02124 fprintf(fdh, "%seyedb::Status %s(", ctxH->get(),
02125 ATTRNAME_1(name, ATTRSET(cls), hints));
02126 dimArgsGen(fdh, ndims);
02127 if (cls->asEnumClass())
02128 fprintf(fdh, "%s%s%s, eyedb::Bool _check_value = eyedb::True);\n",
02129 comma, classname, ref1);
02130 else
02131 fprintf(fdh, "%s%s%s);\n", comma, classname, ref1);
02132 }
02133 #ifdef NO_DIRECT_SET
02134 else
02135 #endif
02136 #if defined(SET_COUNT_DIRECT) || defined(NO_DIRECT_SET)
02137
02138
02139
02140 if (isVarDim() && !is_string)
02141 {
02142 fprintf(fdh, "%seyedb::Status %s(",
02143 ctxH->get(), ATTRNAME(name, tSetCount, hints));
02144
02145 dimArgsGen(fdh, ndims);
02146 fprintf(fdh, ");\n");
02147 }
02148 #endif
02149
02150
02151 if (is_string || is_raw) {
02152 #ifdef ODL_STD_STRING
02153 if (is_string)
02154 fprintf(fdh, "%sstd::string %s(%seyedb::Bool *isnull = 0%s) const;\n",
02155 ctxH->get(), ATTRNAME(name, tGet, hints), SARGOUT(),
02156 stargcom);
02157 else
02158 fprintf(fdh, "%sconst %s *%s(%seyedb::Bool *isnull = 0%s) const;\n",
02159 ctxH->get(), SCLASS(), ATTRNAME(name, tGet, hints), SARGOUT(),
02160 stargcom);
02161 #else
02162 fprintf(fdh, "%sconst %s *%s(%seyedb::Bool *isnull = 0%s) const;\n",
02163 ctxH->get(), SCLASS(), ATTRNAME(name, tGet, hints), SARGOUT(),
02164 stargcom);
02165 #endif
02166 }
02167
02168 fprintf(fdh, "%s%s%s%s(", ctxH->get(), classname, ref2,
02169 ATTRNAME_1(name, ATTRGET(cls), hints));
02170 dimArgsGen(fdh, ndims);
02171 fprintf(fdh, "%seyedb::Bool *isnull = 0%s) %s;\n", comma,
02172 stargcom, (!not_basic ? " const" : ""));
02173
02174 if (cls->asCollectionClass()) {
02175 fprintf(fdh, "%sunsigned int %s(", ctxH->get(),
02176 ATTRNAME(name, tGetCount, hints));
02177 dimArgsGen(fdh, ndims);
02178 fprintf(fdh, "%seyedb::Bool *isnull = 0, eyedb::Status *rs = 0) const "
02179 "{const eyedb::Collection%s _coll = %s(", comma, getPtrRet(),ATTRNAME(name, tGetColl, hints));
02180 for (i = 0; i < ndims; i++)
02181 fprintf(fdh, "a%d, ", i);
02182 fprintf(fdh, "isnull, rs); ");
02183 fprintf(fdh, "return (!!_coll ? _coll->getCount() : 0);}\n");
02184 }
02185
02186 if (not_basic) {
02187 fprintf(fdh, "%sconst %s%s%s(", ctxH->get(), classname, ref2,
02188 ATTRNAME_1(name, ATTRGET(cls), hints));
02189
02190 dimArgsGen(fdh, ndims);
02191 fprintf(fdh, "%seyedb::Bool *isnull = 0%s) const;\n", comma,
02192 stargcom);
02193 }
02194
02195 if (isIndirect()) {
02196 fprintf(fdh, "%seyedb::Oid %s(",
02197 ctxH->get(), ATTRNAME(name, tGetOid, hints));
02198 dimArgsGen(fdh, ndims);
02199 fprintf(fdh, "%s) const;\n", (ndims ? stargcom : starg));
02200 fprintf(fdh, "%seyedb::Status %s(",
02201 ctxH->get(), ATTRNAME(name, tSetOid, hints));
02202 dimArgsGen(fdh, ndims);
02203 fprintf(fdh, "%sconst eyedb::Oid &);\n", comma);
02204 }
02205
02206 if (cls->asCollectionClass()) {
02207 Bool _isref;
02208 eyedblib::int16 _dim;
02209 Class *cl = const_cast<Class *>
02210 (cls->asCollectionClass()->getCollClass(&_isref, &_dim));
02211 const char *oclassname = _isref ?
02212 className(cl, True) : className(cl, False);
02213 Bool ordered;
02214
02215 if (cls->asCollSetClass() || cls->asCollBagClass())
02216 ordered = False;
02217 else
02218 ordered = True;
02219
02220 const char *where = (ordered ? "int where, " : "");
02221
02222 if (_dim == 1) {
02223 fprintf(fdh, "%seyedb::Status %s(%s", ctxH->get(),
02224 ATTRNAME_1(name, (ordered ? GenCodeHints::tSetItemInColl : GenCodeHints::tAddItemToColl), hints), where);
02225 dimArgsGen(fdh, ndims);
02226 fprintf(fdh, "%s%s%s%s, const eyedb::CollImpl * = 0);\n", comma,
02227 oclassname, (_isref || !cl->asBasicClass() ? getPtrRet() : " "),
02228 (!*where ? ", eyedb::Bool noDup = eyedb::False" : ""));
02229
02230 if (ordered) {
02231 fprintf(fdh, "%seyedb::Status %s(int where%s", ctxH->get(),
02232 ATTRNAME(name, tUnsetItemInColl, hints),
02233 (ndims >= 1 ? ", " : ""));
02234 dimArgsGen(fdh, ndims);
02235 fprintf(fdh, ");\n");
02236 }
02237 else
02238 {
02239 fprintf(fdh, "%seyedb::Status %s(%s", ctxH->get(),
02240 ATTRNAME(name, tRmvItemFromColl, hints), where);
02241 dimArgsGen(fdh, ndims);
02242 fprintf(fdh, "%s%s%s%s);\n", comma, oclassname,
02243 (_isref || !cl->asBasicClass() ? getPtrRet() : " "),
02244 (!*where ? ", eyedb::Bool checkFirst = eyedb::False" : ""));
02245 }
02246 }
02247 else if (!strcmp(cl->getName(), char_class_name) && _dim > 1) {
02248 fprintf(fdh, "%seyedb::Status %s(%s", ctxH->get(),
02249 ATTRNAME_1(name, (ordered ? GenCodeHints::tSetItemInColl : GenCodeHints::tAddItemToColl), hints), where);
02250
02251 dimArgsGen(fdh, ndims);
02252 fprintf(fdh, "%sconst char *%s, const eyedb::CollImpl * = 0);\n",
02253 comma,
02254 (!*where ? ", eyedb::Bool noDup = eyedb::False" : ""));
02255
02256
02257
02258
02259
02260 if (ordered)
02261 fprintf(fdh, "%seyedb::Status %s(", ctxH->get(),
02262 ATTRNAME(name, tUnsetItemInColl, hints));
02263 else
02264 fprintf(fdh, "%seyedb::Status %s(", ctxH->get(),
02265 ATTRNAME(name, tRmvItemFromColl, hints));
02266
02267 dimArgsGen(fdh, ndims);
02268 fprintf(fdh, "%sconst char *%s);\n", comma,
02269 (!*where ? ", eyedb::Bool checkFirst = eyedb::False" : ""));
02270 }
02271
02272 if (!cl->asBasicClass()) {
02273 fprintf(fdh, "%seyedb::Status %s(%s", ctxH->get(),
02274 ATTRNAME_1(name, (ordered ? GenCodeHints::tSetItemInColl : GenCodeHints::tAddItemToColl), hints), where);
02275 dimArgsGen(fdh, ndims);
02276 fprintf(fdh, "%sconst eyedb::Oid &, const eyedb::CollImpl * = 0);\n",
02277 comma);
02278 fprintf(fdh, "%seyedb::Status %s(", ctxH->get(),
02279 ATTRNAME_1(name, (ordered ? GenCodeHints::tUnsetItemInColl : GenCodeHints::tRmvItemFromColl), hints));
02280 dimArgsGen(fdh, ndims);
02281 fprintf(fdh, "%sconst eyedb::Oid &);\n", comma);
02282 }
02283
02284 if (ordered) {
02285 if (!strcmp(cl->getName(), char_class_name) && _dim > 1) {
02286 fprintf(fdh, "%sconst char *%s(unsigned int ind, ",
02287 ctxH->get(),
02288 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints));
02289 dimArgsGen(fdh, ndims);
02290 fprintf(fdh, "%seyedb::Bool *isnull = 0, eyedb::Status *rs = 0) const;\n", comma);
02291 }
02292 else if (_dim == 1) {
02293 fprintf(fdh, "%sconst %s%s%s(unsigned int ind, ",
02294 ctxH->get(),
02295 oclassname, (_isref || !cl->asBasicClass() ? getPtrRet() : " "),
02296 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints));
02297 dimArgsGen(fdh, ndims);
02298 fprintf(fdh, "%seyedb::Bool *isnull = 0, eyedb::Status *rs = 0) const;\n", comma);
02299
02300 if (!cl->asBasicClass()) {
02301 fprintf(fdh, "%s%s%s%s(unsigned int ind, ",
02302 ctxH->get(),
02303 oclassname, (_isref || !cl->asBasicClass() ? getPtrRet() : " "),
02304 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints));
02305 dimArgsGen(fdh, ndims);
02306 fprintf(fdh, "%seyedb::Bool *isnull = 0, eyedb::Status *rs = 0);\n", comma);
02307 }
02308 }
02309
02310 if (_isref) {
02311 fprintf(fdh, "%seyedb::Oid %s(unsigned int ind, ",
02312 ctxH->get(),
02313 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveOidItemAt : GenCodeHints::tGetOidItemAt) , hints));
02314 dimArgsGen(fdh, ndims);
02315 fprintf(fdh, "%seyedb::Status *rs = 0) const;\n", comma);
02316 }
02317 }
02318 }
02319
02320 if (isVarDim() && !is_string)
02321 fprintf(fdh, "%sunsigned int %s(%s) const;\n", ctxH->get(),
02322 ATTRNAME(name, tGetCount, hints), starg);
02323
02324 generateBody_C(own, ctxC, hints);
02325
02326 return Success;
02327 }
02328
02329 static void const_f0(FILE *fd, Class *parent, const char *var,
02330 Bool fill = False)
02331 {
02332 if (!strcmp(parent->getName(), "struct"))
02333 fprintf(fd, "eyedb::Struct(%s)", var);
02334 else if (!strcmp(parent->getName(), "union"))
02335 fprintf(fd, "eyedb::Union(%s)", var);
02336 else
02337 fprintf(fd, "%s(%s, 1)", className(parent), var);
02338
02339 if (fill)
02340 fprintf(fd, "\n{\n");
02341 }
02342
02343 static void const_f01(FILE *fd, Class *parent, const char *var,
02344 Bool fill = False)
02345 {
02346 if (!strcmp(parent->getName(), "struct"))
02347 fprintf(fd, "eyedb::Struct(%s, share)", var);
02348 else if (!strcmp(parent->getName(), "union"))
02349 fprintf(fd, "eyedb::Union(%s, share)", var);
02350 else
02351 fprintf(fd, "%s(%s, share, 1)", className(parent), var);
02352
02353 if (fill)
02354 fprintf(fd, "\n{\n");
02355 }
02356
02357 static void const_f1(FILE *fd, GenContext *ctx, const char *name, Bool share)
02358 {
02359 if (share)
02360 fprintf(fd, "%sif (!share)\n%s {\n", ctx->get(), ctx->get());
02361
02362 fprintf(fd, "%s%sheaderCode(eyedb::_Struct_Type, idr_psize, IDB_XINFO_LOCAL_OBJ);\n",
02363 ctx->get(), (share ? " " : ""), name);
02364
02365 fprintf(fd, "%s%seyedb::ClassPeer::newObjRealize(getClass(), this);\n", ctx->get(), (share ? " " : ""));
02366 if (share)
02367 fprintf(fd, "%s }\n\n", ctx->get());
02368
02369 fprintf(fd, "%seyedb::ObjectPeer::setGRTObject(this, eyedb::True);\n", ctx->get());
02370 }
02371
02372 Status AgregatClass::generateConstructors_C(GenContext *ctx)
02373 {
02374 FILE *fd = ctx->getFile();
02375
02376 fprintf(fd, "%s::%s(eyedb::Database *_db, const eyedb::Dataspace *_dataspace) : ", name, name);
02377
02378 const_f0(fd, parent, "_db, _dataspace", eyedb::True);
02379
02380 if (attr_cache && !isRootClass())
02381 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02382 fprintf(fd, "%sinitialize(_db);\n", ctx->get());
02383 fprintf(fd, "}\n\n");
02384
02385 if (attr_cache && !isRootClass())
02386 {
02387 fprintf(fd, "void %s::attrCacheEmpty()\n{\n", name);
02388 if (strcmp(getParent()->getName(), "struct") &&
02389 !getParent()->isRootClass())
02390 fprintf(fd, "%s%s::attrCacheEmpty();\n", ctx->get(),
02391 getParent()->getCName());
02392
02393 int i;
02394 for (i = 0; i < items_cnt; i++)
02395 if (items[i]->getClassOwner()->compare(this))
02396 items[i]->genAttrCacheEmpty(ctx);
02397 fprintf(fd, "}\n\n");
02398
02399 fprintf(fd, "void %s::garbage()\n{\n", name);
02400 for (i = 0; i < items_cnt; i++)
02401 if (items[i]->getClassOwner()->compare(this))
02402 items[i]->genAttrCacheGarbage(ctx);
02403 fprintf(fd, "%s%s::garbage();\n", ctx->get(), getParent()->getCName());
02404 fprintf(fd, "}\n\n");
02405 }
02406
02407
02408
02409
02410
02411
02412 fprintf(fd, "%s::%s(const eyedb::Class *_cls, eyedb::Data _idr)", name, name);
02413 if (strcmp(parent->getName(), "struct"))
02414 fprintf(fd, ": %s((eyedb::Database *)0, (const eyedb::Dataspace *)0, 1)", className(parent));
02415 fprintf(fd, "\n{\n");
02416 fprintf(fd, "%ssetClass((eyedb::Class *)_cls);\n\n", ctx->get());
02417
02418 fprintf(fd, "%seyedb::Size idr_psize;\n", ctx->get());
02419 fprintf(fd, "%seyedb::Size idr_tsize = getClass()->getIDRObjectSize(&idr_psize);\n", ctx->get(), name);
02420 fprintf(fd, "%sif (_idr)\n", ctx->get());
02421 fprintf(fd, "%s idr->setIDR(idr_tsize, _idr);\n", ctx->get());
02422 fprintf(fd, "%selse\n", ctx->get());
02423 fprintf(fd, "%s {\n", ctx->get());
02424
02425
02426 fprintf(fd, "%s idr->setIDR(idr_tsize);\n", ctx->get());
02427 fprintf(fd, "%s memset(idr->getIDR() + IDB_OBJ_HEAD_SIZE, 0, idr->getSize() - IDB_OBJ_HEAD_SIZE);\n", ctx->get());
02428 fprintf(fd, "%s }\n", ctx->get());
02429
02430 fprintf(fd, "%sheaderCode(eyedb::_Struct_Type, idr_psize, IDB_XINFO_LOCAL_OBJ);\n", ctx->get(), name);
02431 fprintf(fd, "%seyedb::ClassPeer::newObjRealize(getClass(), this);\n", ctx->get());
02432 fprintf(fd, "%seyedb::ObjectPeer::setGRTObject(this, eyedb::True);\n", ctx->get());
02433 fprintf(fd, "%suserInitialize();\n", ctx->get());
02434 fprintf(fd, "}\n\n");
02435
02436 fprintf(fd, "void %s::initialize(eyedb::Database *_db)\n{\n",
02437 name);
02438 fprintf(fd, "%ssetClass((_db ? _db->getSchema()->getClass(\"%s\") : %s%s));\n\n", ctx->get(), getAliasName(), name, classSuffix);
02439 fprintf(fd, "%seyedb::Size idr_psize;\n", ctx->get());
02440
02441 fprintf(fd, "%sidr->setIDR(getClass()->getIDRObjectSize(&idr_psize));\n",
02442 ctx->get(), name);
02443
02444
02445 fprintf(fd, "%smemset(idr->getIDR() + IDB_OBJ_HEAD_SIZE, 0, idr->getSize() - IDB_OBJ_HEAD_SIZE);\n",
02446 ctx->get());
02447
02448 const_f1(fd, ctx, name, False);
02449 if (attr_cache && !isRootClass())
02450 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02451 fprintf(fd, "%suserInitialize();\n", ctx->get());
02452 fprintf(fd, "}\n\n");
02453
02454 fprintf(fd, "%s::%s(const %s& x) : %s(x)\n{\n",
02455 name, name, name, parent->getCName(), ctx->get());
02456 if (attr_cache && !isRootClass())
02457 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02458 fprintf(fd, "%suserCopy(x);\n", ctx->get());
02459 fprintf(fd, "}\n\n");
02460 fprintf(fd, "%s& %s::operator=(const %s& x)\n{\n", name, name, name);
02461 fprintf(fd, "%s*(%s *)this = %s::operator=((const %s &)x);\n",
02462 ctx->get(), parent->getCName(), parent->getCName(), parent->getCName());
02463 if (attr_cache && !isRootClass())
02464 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02465 fprintf(fd, "%suserCopy(x);\n", ctx->get());
02466 fprintf(fd, "%sreturn *this;\n", ctx->get());
02467 fprintf(fd, "}\n\n", ctx->get());
02468
02469 fprintf(fd, "%s::%s(const eyedb::Struct *x, eyedb::Bool share) : ",
02470 name, name, className(parent));
02471
02472 const_f01(fd, parent, "x", True);
02473
02474 fprintf(fd, "%ssetClass((db ? db->getSchema()->getClass(\"%s\") : %s%s));\n\n", ctx->get(), getAliasName(), name, classSuffix);
02475 fprintf(fd, "%seyedb::Size idr_psize;\n", ctx->get());
02476 fprintf(fd, "%sgetClass()->getIDRObjectSize(&idr_psize);\n", ctx->get(), name);
02477
02478 const_f1(fd, ctx, name, True);
02479 if (attr_cache && !isRootClass())
02480 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02481 fprintf(fd, "%suserCopy(*x);\n", ctx->get());
02482 fprintf(fd, "}\n\n");
02483
02484 fprintf(fd, "%s::%s(const %s *x, eyedb::Bool share) : ", name, name,
02485 name, className(parent));
02486
02487 const_f01(fd, parent, "x", True);
02488
02489 fprintf(fd, "%ssetClass((db ? db->getSchema()->getClass(\"%s\") : %s%s));\n\n", ctx->get(), getAliasName(), name, classSuffix);
02490
02491 fprintf(fd, "%seyedb::Size idr_psize;\n", ctx->get());
02492 fprintf(fd, "%sgetClass()->getIDRObjectSize(&idr_psize);\n", ctx->get(), name);
02493 const_f1(fd, ctx, name, True);
02494 if (attr_cache && !isRootClass())
02495 fprintf(fd, "%sattrCacheEmpty();\n", ctx->get());
02496 fprintf(fd, "%suserCopy(*x);\n", ctx->get());
02497
02498 fprintf(fd, "}\n\n");
02499 return Success;
02500 }
02501
02502 Status AgregatClass::generateDownCasting_C(GenContext *ctx,
02503 Schema *m)
02504 {
02505 const LinkedList *list = m->getClassList();
02506 LinkedListCursor *curs = list->startScan();
02507 FILE *fd = ctx->getFile();
02508
02509 Class *cl;
02510
02511 while (list->getNextObject(curs, (void *&)cl))
02512 {
02513 Bool is;
02514 if (isSuperClassOf(cl, &is) == Success && is)
02515 {
02516 const char *s = className(cl);
02517 char body[128], body_const[128];
02518
02519 if (cl == this)
02520 {
02521 sprintf(body, " {return this;}\n");
02522 strcpy(body_const, body);
02523 }
02524 else
02525 {
02526 sprintf(body, " {return (%s *)0;}\n", s);
02527 sprintf(body_const, " {return (const %s *)0;}\n", s);
02528 }
02529
02530 fprintf(fd, "%svirtual %s *%s%s()%s", ctx->get(),
02531 s, downCastPrefix, cl->getCanonicalName(), body);
02532
02533 fprintf(fd, "%svirtual const %s *%s%s() const%s", ctx->get(),
02534 s, downCastPrefix, cl->getCanonicalName(), body_const);
02535 }
02536 }
02537
02538 return Success;
02539 }
02540
02541 static int
02542 true_items_count(const Class *cls, Attribute **items, int items_cnt)
02543 {
02544 for (int i = 0; i < items_cnt; i++)
02545 if (items[i]->getClassOwner() == cls && !items[i]->isNative())
02546 return items_cnt - i;
02547
02548 return 0;
02549 }
02550
02551 Status
02552 AgregatClass::generateClassDesc_C(GenContext *ctx,
02553 const char *)
02554 {
02555 FILE *fd = ctx->getFile();
02556 Status status;
02557 const char *_type = (asStructClass() ? "Struct" : "Union");
02558
02559 fprintf(fd, "static const eyedb::Attribute **%s_agritems;\n", name);
02560 fprintf(fd, "static eyedb::Size %s_idr_objsz, %s_idr_psize;\n\n", name, name);
02561
02562 fprintf(fd, "static eyedb::%sClass *%s_make(eyedb::%sClass *%s_class = 0, eyedb::Schema *m = 0)\n{\n", _type, name, _type, name);
02563 ctx->push();
02564
02565 fprintf(fd, "%sif (!%s_class)\n", ctx->get(), name);
02566 Class *parent_cl = parent->isRootClass() ? parent->getParent() : parent;
02567 fprintf(fd,"%s return new eyedb::%sClass(\"%s\", (m ? m->getClass(\"%s\") : %s%s));\n", ctx->get(), _type, getAliasName(),
02568 (parent_cl->getAliasName() ? parent_cl->getAliasName() : parent_cl->getName()),
02569 className(parent_cl), classSuffix);
02570
02571
02572
02573 if (items_cnt)
02574 {
02575 fprintf(fd, "%seyedb::Attribute *attr[%d];\n", ctx->get(), items_cnt);
02576 int dims_declare = 0;
02577
02578 int i;
02579 for (i = 0; i < items_cnt; i++)
02580 if (items[i]->class_owner == (void *)this && !items[i]->isNative())
02581 {
02582 if (!dims_declare)
02583 {
02584 dims_declare = 1;
02585 fprintf(fd, "%sint *dims;\n", ctx->get());
02586 }
02587 status = items[i]->generateClassDesc_C(ctx);
02588 if (status)
02589 return status;
02590 }
02591
02592 int count = true_items_count(this, items, items_cnt);
02593 fprintf(fd, "\n%s%s_class->setAttributes(&attr[%d], %d);\n", ctx->get(),
02594 name, items_cnt - count, count);
02595
02596 fprintf(fd, "\n");
02597
02598 for (i = items_cnt - count; i < items_cnt; i++)
02599 fprintf(fd, "%sdelete attr[%d];\n", ctx->get(), i);
02600
02601 fprintf(fd, "\n");
02602 }
02603 else
02604 fprintf(fd, "\n%s%s_class->setAttributes(0, 0);\n", ctx->get(), name);
02605
02606
02607
02608
02609
02610
02611
02612
02613 if (isSystem() || odl_system_class)
02614 fprintf(fd, "%seyedb::ClassPeer::setMType(%s_class, eyedb::Class::System);\n",
02615 ctx->get(), name);
02616
02617 fprintf(fd, "\n%sreturn %s_class;\n}\n\n", ctx->get(),
02618 name);
02619
02620 fprintf(fd, "eyedb::Object *%s_construct_x(const eyedb::Class *cls, eyedb::Data idr)\n{\n", name);
02621 fprintf(fd, "%sreturn new %s(cls, idr);\n", ctx->get(), name);
02622 fprintf(fd, "}\n\n");
02623
02624 fprintf(fd, "eyedb::Object *%s_construct(const eyedb::Object *o, eyedb::Bool share)\n{\n", name);
02625 fprintf(fd, "%sreturn new %s((const eyedb::Struct *)o, share);\n", ctx->get(), name);
02626 fprintf(fd, "}\n\n");
02627
02628 fprintf(fd, "static void %s_init_p()\n{\n", name);
02629 fprintf(fd, "%s%s%s = %s_make();\n", ctx->get(), name, classSuffix, name);
02630 fprintf(fd, "%sconstructors_x[class_ind] = %s_construct_x;\n", ctx->get(),
02631 name);
02632 fprintf(fd, "%sconstructors[class_ind] = %s_construct;\n", ctx->get(),
02633 name);
02634 fprintf(fd, "%shash->insert(\"%s\", class_ind++);\n", ctx->get(),
02635 getAliasName());
02636 fprintf(fd, "}\n\n");
02637
02638 fprintf(fd, "static void %s_init()\n{\n", name);
02639 fprintf(fd, "%s%s_make(%s%s);\n\n", ctx->get(), name, name, classSuffix);
02640 fprintf(fd, "%s%s_agritems = %s%s->getAttributes();\n", ctx->get(),
02641 name, name, classSuffix);
02642 fprintf(fd, "%s%s_idr_objsz = %s%s->getIDRObjectSize(&%s_idr_psize, 0);\n\n",
02643 ctx->get(), name, name, classSuffix, name);
02644
02645 fprintf(fd, "%seyedb::ObjectPeer::setUnrealizable(%s%s, eyedb::True);\n",
02646 ctx->get(), name, classSuffix);
02647 fprintf(fd, "}\n\n");
02648 ctx->pop();
02649 return Success;
02650 }
02651
02652 #define NEW_ARGTYPE
02653
02654 static inline void
02655 argTypeDump(GenContext *ctx, ArgType *argtype, const char *str)
02656 {
02657 FILE *fd = ctx->getFile();
02658
02659 #ifdef NEW_ARGTYPE
02660 fprintf(fd, "%sargtype = %s;\n", ctx->get(), str);
02661 #else
02662 fprintf(fd, "%sargtype = new eyedb::ArgType();\n", ctx->get());
02663 #endif
02664
02665 fprintf(fd, "%sargtype->setType((eyedb::ArgType_Type)%d, eyedb::False);\n",
02666 ctx->get(), argtype->getType());
02667
02668
02669
02670
02671 fprintf(fd, "%sargtype->setClname(\"%s\");\n", ctx->get(),
02672 argtype->getClname().c_str());
02673 }
02674
02675 static void
02676 sign_declare_realize(FILE *fd, GenContext *ctx)
02677 {
02678 fprintf(fd, "%seyedb::Signature *sign;\n", ctx->get());
02679 fprintf(fd, "%seyedb::ArgType *argtype;\n\n", ctx->get());
02680 }
02681
02682 #define dataspace_prologue(ctx, fd, x) \
02683 do { \
02684 Bool isnull; \
02685 short dspid = x->getDspid(&isnull); \
02686 if (!isnull) { \
02687 fprintf(fd, "%sstatus = db->getDataspace(%d, dataspace);\n", \
02688 ctx->get(), dspid); \
02689 fprintf(fd, "%sif (status) return status;\n", ctx->get()); \
02690 } \
02691 else \
02692 fprintf(fd, "%sdataspace = 0;;\n", ctx->get()); \
02693 } while(0)
02694
02695 #define hints_prologue(ctx, fd, x) \
02696 do { \
02697 int cnt = x->getImplHintsCount(); \
02698 if (cnt) { \
02699 fprintf(fd, "%simpl_hints = new int[%d];\n", \
02700 ctx->get(), cnt); \
02701 for (int i = 0; i < cnt; i++) \
02702 fprintf(fd, "%simpl_hints[%d] = %d;\n", ctx->get(), i, \
02703 x->getImplHints(i)); \
02704 } \
02705 } while(0)
02706
02707
02708 #define hints_epilogue(ctx, fd, x) \
02709 do { \
02710 int cnt = x->getImplHintsCount(); \
02711 if (cnt) { \
02712 fprintf(fd, ", impl_hints, %d);\n", cnt); \
02713 fprintf(fd, "%sdelete [] impl_hints;\n", ctx->get());\
02714 } \
02715 else \
02716 fprintf(fd, "0, 0);\n"); \
02717 } while(0)
02718
02719 void
02720 Class::compAddGenerate(GenContext *ctx, FILE *fd)
02721 {
02722 if (asAgregatClass()) {
02723
02724
02725
02726
02727
02728 fprintf(fd, "%scls->add(comp->getInd(), comp);\n\n", ctx->get());
02729 }
02730 else
02731 fprintf(fd, "%sif (status = comp->realize()) return status;\n\n", ctx->get());
02732 }
02733
02734 Status Class::generateAttrComponent_C(GenContext *ctx)
02735 {
02736 if (!getUserData(odlGENCODE) && !getUserData(odlGENCOMP)) {
02737 printf("generateAttrComponent_C -> is system %s %p\n", name, this);
02738 return Success;
02739 }
02740
02741 const LinkedList *list;
02742 Status s = getAttrCompList(list);
02743 if (s) return s;
02744
02745 FILE *fd = ctx->getFile();
02746
02747 fprintf(fd, "static eyedb::Status %s_attrcomp_realize(eyedb::Database *db, eyedb::Class *cls)\n{\n", name);
02748
02749 ctx->push();
02750 if (list->getCount()) {
02751 fprintf(fd, "%seyedb::AttributeComponent *comp;\n", ctx->get());
02752 fprintf(fd, "%sconst eyedb::Dataspace *dataspace;\n", ctx->get());
02753 fprintf(fd, "%seyedb::ClassComponent *clcomp;\n", ctx->get());
02754 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
02755 fprintf(fd, "%sint *impl_hints;\n", ctx->get());
02756 }
02757
02758 LinkedListCursor c(list);
02759
02760 AttributeComponent *comp;
02761 Bool setup_done = False;
02762 while (c.getNext((void *&)comp)){
02763 if (comp->asNotNullConstraint()) {
02764 NotNullConstraint *notnull = comp->asNotNullConstraint();
02765 fprintf(fd, "%scomp = new eyedb::NotNullConstraint(db, cls, \"%s\", %s);\n",
02766 ctx->get(), notnull->getAttrpath().c_str(),
02767 IDBBOOL_STR(notnull->getPropagate()));
02768 }
02769 else if (comp->asUniqueConstraint()) {
02770 UniqueConstraint *unique = comp->asUniqueConstraint();
02771 fprintf(fd, "%scomp = new eyedb::UniqueConstraint(db, cls, \"%s\", %s);\n",
02772 ctx->get(), unique->getAttrpath().c_str(),
02773 IDBBOOL_STR(unique->getPropagate()));
02774 }
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785 else if (comp->asBTreeIndex()) {
02786 BTreeIndex *idx = comp->asBTreeIndex();
02787 hints_prologue(ctx, fd, idx);
02788 dataspace_prologue(ctx, fd, idx);
02789 fprintf(fd, "%scomp = new eyedb::BTreeIndex(db, cls, \"%s\", %s, %s, dataspace, %d",
02790 ctx->get(), idx->getAttrpath().c_str(),
02791 IDBBOOL_STR(idx->getPropagate()),
02792 IDBBOOL_STR(idx->getIsString()),
02793 idx->getDegree());
02794 hints_epilogue(ctx, fd, idx);
02795 }
02796 else if (comp->asHashIndex()) {
02797 HashIndex *idx = comp->asHashIndex();
02798 if (idx->getHashMethod()) {
02799
02800 if (!setup_done) {
02801 fprintf(fd, "%sgetClass()->setSetupComplete(eyedb::True);\n", ctx->get());
02802 setup_done = True;
02803 }
02804 fprintf(fd, "%sstatus = getClass()->getComp(\"%s\", clcomp);\n",
02805 ctx->get(), idx->getHashMethod()->getName().c_str());
02806 fprintf(fd, "%sif (status) return status;\n", ctx->get());
02807 }
02808 hints_prologue(ctx, fd, idx);
02809 dataspace_prologue(ctx, fd, idx);
02810 fprintf(fd, "%scomp = new eyedb::HashIndex(db, cls, \"%s\", %s, %s, dataspace, %d",
02811 ctx->get(), idx->getAttrpath().c_str(),
02812 IDBBOOL_STR(idx->getPropagate()),
02813 IDBBOOL_STR(idx->getIsString()),
02814 idx->getKeyCount());
02815
02816 if (idx->getHashMethod())
02817 fprintf(fd, ", clcomp->asBEMethod_C()");
02818 else
02819 fprintf(fd, ", 0");
02820 hints_epilogue(ctx, fd, idx);
02821 }
02822 else if (comp->asCollAttrImpl()) {
02823 CollAttrImpl *collimpl = comp->asCollAttrImpl();
02824 if (collimpl->getHashMethod()) {
02825
02826 if (!setup_done) {
02827 fprintf(fd, "%sgetClass()->setSetupComplete(eyedb::True);\n", ctx->get());
02828 setup_done = True;
02829 }
02830 fprintf(fd, "%sstatus = getClass()->getComp(\"%s\", clcomp);\n",
02831 ctx->get(), collimpl->getHashMethod()->getName().c_str());
02832 fprintf(fd, "%sif (status) return status;\n", ctx->get());
02833 }
02834 hints_prologue(ctx, fd, collimpl);
02835 dataspace_prologue(ctx, fd, collimpl);
02836 fprintf(fd, "%scomp = new eyedb::CollAttrImpl(db, cls, \"%s\", %s, dataspace, %s, %d",
02837 ctx->get(), collimpl->getAttrpath().c_str(),
02838 IDBBOOL_STR(collimpl->getPropagate()),
02839 (collimpl->getImplType() == IndexImpl::Hash ?
02840 "eyedb::CollImpl::HashIndex" :
02841 (collimpl->getImplType() == CollImpl::NoIndex ?
02842 "eyedb::CollImpl::NoIndex" :
02843 "eyedb::CollImpl::BTreeIndex")),
02844 collimpl->getKeyCountOrDegree());
02845
02846 if (collimpl->getHashMethod())
02847 fprintf(fd, ", clcomp->asBEMethod_C()");
02848 else
02849 fprintf(fd, ", 0");
02850 hints_epilogue(ctx, fd, collimpl);
02851 }
02852 else
02853 abort();
02854
02855 compAddGenerate(ctx, fd);
02856 }
02857
02858 fprintf(fd, "%sreturn eyedb::Success;\n", ctx->get());
02859
02860 ctx->pop();
02861 fprintf(fd, "}\n\n");
02862 return Success;
02863 }
02864
02865 Status Class::generateClassComponent_C(GenContext *ctx)
02866 {
02867 if (!getCompList() || !getCompList()->getCount())
02868 return Success;
02869
02870 if (!getUserData(odlGENCODE) && !getUserData(odlGENCOMP)) {
02871 printf("generateClassComponent_C -> is system %s %p\n", name, this);
02872 return Success;
02873 }
02874
02875 FILE *fd = ctx->getFile();
02876
02877 Status status;
02878
02879
02880 fprintf(fd, "static eyedb::Status %s_comp_realize(eyedb::Database *db, eyedb::Class *cls)\n{\n", name);
02881
02882 ctx->push();
02883 if (complist->getCount())
02884 {
02885 fprintf(fd, "%seyedb::ClassComponent *comp;\n", ctx->get());
02886 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
02887 }
02888
02889 int sign_declare = 0;
02890
02891 LinkedListCursor c(complist);
02892
02893 ClassComponent *comp;
02894 while (complist->getNextObject(&c, (void *&)comp))
02895 {
02896 if (comp->asCardinalityConstraint())
02897 {
02898 CardinalityConstraint *card = comp->asCardinalityConstraint();
02899 CardinalityDescription *card_desc = card->getCardDesc();
02900 fprintf(fd, "%scomp = new eyedb::CardinalityConstraint(db, cls, \"%s\", %d, %d, %d, %d);\n",
02901 ctx->get(), card->getAttrname().c_str(), card_desc->getBottom(),
02902 card_desc->getBottomExcl(),
02903 card_desc->getTop(), card_desc->getTopExcl());
02904 }
02905 else if (comp->asTrigger())
02906 {
02907 Trigger *trig = comp->asTrigger();
02908 char *x = purge(trig->getEx()->getExtrefBody().c_str());
02909 fprintf(fd, "%scomp = new eyedb::Trigger(db, cls, (eyedb::TriggerType)%d, (eyedb::ExecutableLang)%d, %s, \"%s\", %s, \"%s\");\n",
02910 ctx->get(), trig->getType(),
02911 (trig->getEx()->getLang() & ~SYSTEM_EXEC),
02912 STRBOOL(trig->getEx()->getLang() & SYSTEM_EXEC),
02913 trig->getSuffix().c_str(),
02914 trig->getLight() ? "eyedb::True" : "eyedb::False",
02915 x);
02916 free(x);
02917 }
02918 else if (comp->asMethod())
02919 {
02920 Method *mth = comp->asMethod();
02921 Executable *ex = mth->getEx();
02922
02923 if ((ex->getLang() & (C_LANG|SYSTEM_EXEC)) ==
02924 (C_LANG|SYSTEM_EXEC) && !odl_system_class)
02925 continue;
02926
02927 if (!sign_declare)
02928 {
02929 sign_declare = 1;
02930 sign_declare_realize(fd, ctx);
02931 }
02932
02933 fprintf(fd, "%ssign = new eyedb::Signature();\n",
02934 ctx->get());
02935 Signature *sign = ex->getSign();
02936 const char *prefix = ((ex->getLoc()&~STATIC_EXEC) == FRONTEND ? "FE" : "BE");
02937 const char *lang = ((ex->getLang() & C_LANG) ? "C" : "OQL");
02938 char *extref = purge(ex->getExtrefBody().c_str());
02939
02940 #ifdef NEW_ARGTYPE
02941 argTypeDump(ctx, sign->getRettype(), "sign->getRettype()");
02942 #else
02943 argTypeDump(ctx, sign->getRettype());
02944 fprintf(fd, "%ssign->setRettype(argtype);\n", ctx->get());
02945 fprintf(fd, "%sargtype->release();\n\n", ctx->get());
02946 #endif
02947
02948 int nargs = sign->getNargs();
02949 fprintf(fd, "%ssign->setNargs(%d);\n", ctx->get(), nargs);
02950 fprintf(fd, "%ssign->setTypesCount(%d);\n", ctx->get(), nargs);
02951 int i;
02952 for (i = 0; i < nargs; i++)
02953 {
02954 #ifdef NEW_ARGTYPE
02955 char tok[128];
02956 sprintf(tok, "sign->getTypes(%d)", i);
02957 argTypeDump(ctx, sign->getTypes(i), tok);
02958 #else
02959 argTypeDump(ctx, sign->getTypes(i));
02960 fprintf(fd, "%ssign->setTypes(%d, argtype);\n", ctx->get(),
02961 i);
02962 fprintf(fd, "%sargtype->release();\n\n", ctx->get());
02963 #endif
02964 }
02965
02966 fprintf(fd,
02967 "%scomp = new eyedb::%sMethod_%s(db, cls, \"%s\", sign, %s, %s, \"%s\");\n",
02968 ctx->get(), prefix, lang, ex->getExname().c_str(),
02969 STRBOOL(ex->isStaticExec()),
02970 STRBOOL(ex->getLang() & SYSTEM_EXEC),
02971 extref);
02972 free(extref);
02973 }
02974 else
02975 abort();
02976
02977 compAddGenerate(ctx, fd);
02978
02979 if (comp->asMethod())
02980 fprintf(fd, "%ssign->release();\n\n", ctx->get());
02981 }
02982
02983 fprintf(fd, "%sreturn eyedb::Success;\n", ctx->get());
02984
02985 ctx->pop();
02986 fprintf(fd, "}\n\n");
02987 return Success;
02988 }
02989
02990 Status AgregatClass::generateConstructors_C(GenContext *ctxH,
02991 GenContext *ctxC)
02992 {
02993 FILE *fdh = ctxH->getFile();
02994
02995 fprintf(fdh, "%s%s(eyedb::Database * = 0, const eyedb::Dataspace * = 0);\n", ctxH->get(), name);
02996
02997 fprintf(fdh, "%s%s(const %s& x);\n\n", ctxH->get(), name, name);
02998
02999 if (isRootClass()) {
03000 fprintf(fdh, "%svirtual eyedb::Object *clone() const "
03001 "{return _clone();};\n", ctxH->get(), name);
03002 fprintf(fdh, "%svirtual eyedb::Object *_clone() const "
03003 "{return new %s(*this);};\n\n", ctxH->get(), name);
03004 }
03005 else if (odl_rootclass) {
03006 fprintf(fdh, "%svirtual eyedb::Object *_clone() const "
03007 "{return new %s(*this);};\n\n", ctxH->get(), name);
03008 }
03009 else {
03010 fprintf(fdh, "%svirtual eyedb::Object *clone() const "
03011 "{return new %s(*this);};\n\n", ctxH->get(), name);
03012 }
03013
03014 fprintf(fdh, "%s%s& operator=(const %s& x);\n\n", ctxH->get(), name, name);
03015
03016 generateConstructors_C(ctxC);
03017
03018 return Success;
03019 }
03020
03021 Status
03022 AgregatClass::generateMethodDecl_C(Schema *m, GenContext *ctx)
03023 {
03024 FILE *fd = ctx->getFile();
03025 LinkedListCursor c(complist);
03026
03027 ClassComponent *comp;
03028
03029 while (c.getNext((void *&)comp))
03030 if (comp->asMethod())
03031 {
03032 Method *mth = comp->asMethod();
03033 Executable *ex = mth->getEx();
03034
03035 if (!(ex->getLang() & C_LANG))
03036 continue;
03037
03038 if (!mth->getUserData())
03039 continue;
03040
03041 Signature *sign = ex->getSign();
03042
03043 if (sign->getUserData()) {
03044 odlMethodHints *mth_hints = ((odlSignUserData *)sign->getUserData())->mth_hints;
03045 if (mth_hints->calledFrom != odlMethodHints::ANY_HINTS &&
03046 mth_hints->calledFrom != odlMethodHints::C_HINTS)
03047 continue;
03048 }
03049
03050 if (ex->isStaticExec()) {
03051 fprintf(fd, "%sstatic eyedb::Status %s(eyedb::Database *db", ctx->get(),
03052 ex->getExname().c_str());
03053 if (sign->getNargs() || !Signature::isVoid(sign->getRettype()))
03054 fprintf(fd, ", ");
03055 }
03056 else
03057 fprintf(fd, "%svirtual eyedb::Status %s(", ctx->get(), ex->getExname().c_str());
03058
03059 sign->declArgs(fd, m);
03060 fprintf(fd, ");\n\n");
03061 }
03062
03063 return Success;
03064 }
03065
03066 Status
03067 AgregatClass::generateMethodFetch_C(GenContext *ctx, Method *mth)
03068 {
03069 FILE *fd = ctx->getFile();
03070 fprintf(fd, "%sif (!mth)\n", ctx->get());
03071 fprintf(fd, "%s{\n", ctx->get());
03072 ctx->push();
03073 fprintf(fd, "%sstatus = eyedb::Method::get(db, "
03074 "db->getSchema()->getClass(\"%s\"), \"%s\", %s, mth);\n",
03075 ctx->get(), (getAliasName() ? getAliasName() : getName()),
03076 mth->getPrototype(False),
03077 STRBOOL(mth->getEx()->isStaticExec()));
03078
03079 fprintf(fd, "%sif (status) return status;\n", ctx->get());
03080
03081 fprintf(fd, "%sif (!mth)\n", ctx->get());
03082 fprintf(fd, "%s return eyedb::Exception::make(eyedb::IDB_ERROR, "
03083 "\"method '%s' not found\");\n", ctx->get(), mth->getPrototype());
03084 ctx->pop();
03085 fprintf(fd, "%s}\n\n", ctx->get());
03086
03087 return Success;
03088 }
03089
03090 Status
03091 AgregatClass::generateMethodBodyFE_C(Schema *m,
03092 GenContext *ctx, Method *mth)
03093 {
03094 FILE *fd = ctx->getFile();
03095 Executable *ex = mth->getEx();
03096 Signature *sign = ex->getSign();
03097
03098 fprintf(fd, "eyedb::Status %s::%s(", name, ex->getExname().c_str());
03099 if (ex->isStaticExec()) {
03100 fprintf(fd, "eyedb::Database *db");
03101 if (sign->getNargs() || !Signature::isVoid(sign->getRettype()))
03102 fprintf(fd, ", ");
03103 }
03104 sign->declArgs(fd, m);
03105 fprintf(fd, ")\n{\n");
03106 ctx->push();
03107
03108 fprintf(fd, "%sstatic eyedb::Method *mth;\n", ctx->get());
03109 fprintf(fd, "%seyedb::Status status;\n", ctx->get());
03110
03111 generateMethodFetch_C(ctx, mth);
03112
03113 #ifdef NEW_ARGARR
03114 fprintf(fd, "%sstatic eyedb::ArgArray *argarr = new eyedb::ArgArray(%d, eyedb::Argument::AutoFullGarbage);\n\n",
03115 ctx->get(), sign->getNargs());
03116 sign->setArgs(fd, m, IN_ARG_TYPE, "(*argarr)[%d]->", "retarg.", ctx->get());
03117 fprintf(fd, "\n%seyedb::Argument __retarg;\n", ctx->get());
03118 fprintf(fd, "%sstatus = mth->applyTo(db, %s, *argarr, __retarg, eyedb::False);\n\n",
03119 ctx->get(), (mth->getEx()->isStaticExec() ? "0" : "this"));
03120 fprintf(fd, "%sif (status) return status;\n\n", ctx->get());
03121 sign->retArgs(fd, m, "(*argarr)[%d]->", "__retarg.", ctx->get());
03122 #else
03123 fprintf(fd, "%seyedb::ArgArray argarr(%d, eyedb::Argument::AutoFullGarbage);\n\n",
03124 ctx->get(), sign->getNargs());
03125 sign->setArgs(fd, m, IN_ARG_TYPE, "argarr[%d]->", "retarg.", ctx->get());
03126 fprintf(fd, "\n%seyedb::Argument __retarg;\n", ctx->get());
03127 fprintf(fd, "%sstatus = mth->applyTo(db, %s, argarr, __retarg, eyedb::False);\n\n",
03128 ctx->get(), (mth->getEx()->isStaticExec() ? "0" : "this"));
03129 fprintf(fd, "%sif (status) return status;\n\n", ctx->get());
03130 sign->retArgs(fd, m, "argarr[%d]->", "__retarg.", ctx->get());
03131 #endif
03132
03133 fprintf(fd, "%sreturn eyedb::Success;\n}\n\n", ctx->get());
03134 ctx->pop();
03135
03136 return Success;
03137 }
03138
03139 static void
03140 userImpl(FILE *fd)
03141 {
03142 fprintf(fd, " _packageInit(_db);\n");
03143 fprintf(fd, "\n //\n // User Implementation\n //\n\n");
03144 fprintf(fd, " return eyedb::Success;\n");
03145 }
03146
03147 Status
03148 Class::generateMethodBodyFE_C(Schema *m,
03149 GenContext *ctx, Method *mth)
03150 {
03151 return Success;
03152 }
03153
03154 Status
03155 Class::generateMethodBodyBE_C(Schema *m,
03156 GenContext *ctxStubs,
03157 GenContext *ctxMth,
03158 Method *mth)
03159 {
03160 FILE *fdstubs = ctxStubs->getFile();
03161 FILE *fdmth = ctxMth->getFile();
03162 Executable *ex = mth->getEx();
03163
03164 Signature *sign = ex->getSign();
03165 const char *intname =
03166 Executable::makeInternalName(ex->getExname().c_str(),
03167 sign,
03168 (mth->getEx()->isStaticExec() ? True:
03169 False),
03170 (getAliasName() ?
03171 getAliasName() : getName()));
03172
03173
03174 const char *prefix = ((ex->getLoc()&~STATIC_EXEC) == FRONTEND ? "FE" : "BE");
03175 const char *lang = ((ex->getLang() & C_LANG) ? "C" : "OQL");
03176
03177 fprintf(fdmth, "//\n// %s [%s.cc]\n//\n\n", mth->getPrototype(),
03178 mth->getEx()->getExtrefBody().c_str());
03179 fprintf(fdmth, "Status\n");
03180 fprintf(fdmth, "__%s(eyedb::Database *_db, eyedb::%sMethod_%s *_m%s",
03181 intname,
03182 prefix, lang,
03183 (ex->isStaticExec() ? "" : ", eyedb::Object *_o"));
03184
03185 if (sign->getNargs() || !Signature::isVoid(sign->getRettype()))
03186 fprintf(fdmth, ", ");
03187
03188 sign->declArgs(fdmth, m);
03189
03190 fprintf(fdmth, ")\n{\n");
03191 userImpl(fdmth);
03192 fprintf(fdmth, "}\n\n");
03193
03194 fprintf(fdstubs, "extern eyedb::Status __%s(eyedb::Database *_db, "
03195 "eyedb::%sMethod_%s *_m%s",
03196 intname,
03197 prefix, lang,
03198 (ex->isStaticExec() ? "" : ", eyedb::Object *_o"));
03199
03200 if (sign->getNargs() || !Signature::isVoid(sign->getRettype()))
03201 fprintf(fdstubs, ", ");
03202
03203 sign->declArgs(fdstubs, m);
03204 fprintf(fdstubs, ");\n\n");
03205
03206 fprintf(fdstubs, "extern \"C\" eyedb::Status\n");
03207 fprintf(fdstubs, "%s(eyedb::Database *_db, eyedb::%sMethod_%s *_m, "
03208 "eyedb::Object *_o, eyedb::ArgArray &_array, eyedb::Argument &__retarg)\n{\n",
03209 intname,
03210 prefix, lang);
03211
03212 ctxStubs->push();
03213 fprintf(fdstubs, "%seyedb::Status status;\n\n", ctxStubs->get());
03214
03215 sign->initArgs(fdstubs, m, "_array[%d]->", "_retarg", ctxStubs->get());
03216
03217 fprintf(fdstubs, "\n%sstatus = __%s(_db, _m%s", ctxStubs->get(), intname,
03218 (ex->isStaticExec() ? "" : ", _o"));
03219
03220 if (sign->getNargs() || !Signature::isVoid(sign->getRettype()))
03221 fprintf(fdstubs, ", ");
03222
03223 sign->listArgs(fdstubs, m);
03224
03225 fprintf(fdstubs, ");\n");
03226
03227 fprintf(fdstubs, "%sif (status) return status;\n\n", ctxStubs->get());
03228
03229 sign->setArgs(fdstubs, m, OUT_ARG_TYPE, "_array[%d]->", "__retarg.",
03230 ctxStubs->get());
03231
03232 fprintf(fdstubs, "%sreturn eyedb::Success;\n}\n\n", ctxStubs->get());
03233 ctxStubs->pop();
03234
03235 return Success;
03236 }
03237
03238 Status
03239 Class::generateTriggerBody_C(Schema *m,
03240 GenContext *ctxMth,
03241 Trigger *trig)
03242 {
03243 FILE *fdmth = ctxMth->getFile();
03244
03245 fprintf(fdmth, "//\n// %s\n//\n\n", trig->getPrototype());
03246 fprintf(fdmth, "extern \"C\"\n");
03247 fprintf(fdmth, "eyedb::Status %s(eyedb::TriggerType type, eyedb::Database *_db, "
03248 "const eyedb::Oid &oid, eyedb::Object *o)\n{\n",
03249 trig->getCSym());
03250 userImpl(fdmth);
03251 fprintf(fdmth, "}\n\n");
03252 return Success;
03253 }
03254
03255 Status
03256 Class::generateMethodBody_C(Schema *m,
03257 GenContext *ctx,
03258 GenContext *ctxStubsFe,
03259 GenContext *ctxStubsBe,
03260 GenContext *ctxMthFe,
03261 GenContext *ctxMthBe)
03262 {
03263 if (!getUserData(odlGENCODE) && !getUserData(odlGENCOMP))
03264 return Success;
03265
03266 LinkedListCursor c(complist);
03267
03268 ClassComponent *comp;
03269
03270 while (c.getNext((void *&)comp))
03271 if (comp->asMethod()) {
03272 Method *mth = comp->asMethod();
03273 if (!(mth->getEx()->getLang() & C_LANG))
03274 continue;
03275
03276 Signature *sign = mth->getEx()->getSign();
03277
03278 if (mth->asBEMethod())
03279 generateMethodBodyBE_C(m, ctxStubsBe, ctxMthBe, mth);
03280 else
03281 generateMethodBodyBE_C(m, ctxStubsFe, ctxMthFe, mth);
03282
03283 if (!mth->getUserData())
03284 continue;
03285
03286 if (sign->getUserData()) {
03287 odlMethodHints *mth_hints = ((odlSignUserData *)sign->getUserData())->mth_hints;
03288 if (mth_hints->calledFrom != odlMethodHints::ANY_HINTS &&
03289 mth_hints->calledFrom != odlMethodHints::C_HINTS)
03290 continue;
03291 }
03292 generateMethodBodyFE_C(m, ctx, mth);
03293 }
03294 else if (comp->asTrigger())
03295 generateTriggerBody_C(m, ctxMthBe, comp->asTrigger());
03296
03297 return Success;
03298 }
03299
03300 Status
03301 Class::generateCode_C(Schema *m,
03302 const char *prefix,
03303 const GenCodeHints &hints,
03304 const char *stubs,
03305 FILE *fdh,
03306 FILE *fdc, FILE *fdstubsfe,
03307 FILE *fdstubsbe,
03308 FILE *fdmthfe,
03309 FILE *fdmthbe)
03310 {
03311 GenContext ctxH(fdh), ctxC(fdc), ctxStubsFe(fdstubsfe),
03312 ctxStubsBe(fdstubsbe), ctxMthFe(fdmthfe), ctxMthBe(fdmthbe);
03313
03314 ctxC.push();
03315 generateMethodBody_C(m, &ctxC, &ctxStubsFe, &ctxStubsBe,
03316 &ctxMthFe, &ctxMthBe);
03317 ctxC.pop();
03318
03319 generateClassComponent_C(&ctxC);
03320 generateAttrComponent_C(&ctxC);
03321
03322 return Success;
03323 }
03324
03325 Status
03326 AgregatClass::generateCode_C(Schema *m,
03327 const char *prefix,
03328 const GenCodeHints &hints,
03329 const char *stubs,
03330 FILE *fdh,
03331 FILE *fdc, FILE *fdstubsfe,
03332 FILE *fdstubsbe,
03333 FILE *fdmthfe,
03334 FILE *fdmthbe)
03335 {
03336 GenContext ctxH(fdh), ctxC(fdc), ctxStubsFe(fdstubsfe),
03337 ctxStubsBe(fdstubsbe), ctxMthFe(fdmthfe), ctxMthBe(fdmthbe);
03338
03339 int i;
03340 Status status;
03341
03342 phints = &hints;
03343 class_enums = hints.class_enums;
03344 attr_cache = hints.attr_cache;
03345
03346 if (getUserData(odlGENCODE))
03347 generateClassDesc_C(&ctxC, "");
03348
03349 generateClassComponent_C(&ctxC);
03350 generateAttrComponent_C(&ctxC);
03351
03352 if (!getUserData(odlGENCODE))
03353 return Success;
03354
03355 fprintf(fdh, "class %s : public %s {\n", name, className(parent));
03356
03357 ctxH.push();
03358
03359 if (stubs)
03360 fprintf(fdh, "#include \"%s\"\n", stubs);
03361
03362 #ifndef NO_COMMENTS
03363 fprintf(fdh, "\n%s// ----------------------------------------------------------------------\n", ctxH.get());
03364 fprintf(fdh, "%s// %s Interface\n", ctxH.get(), name);
03365 fprintf(fdh, "%s// ----------------------------------------------------------------------\n", ctxH.get());
03366 #else
03367 fprintf(fdh, "\n");
03368 #endif
03369 fprintf(fdh, " public:\n");
03370
03371 ctxC.push();
03372
03373 generateConstructors_C(&ctxH, &ctxC);
03374
03375 if (hints.gen_down_casting)
03376 generateDownCasting_C(&ctxH, m);
03377
03378 for (i = 0; i < items_cnt; i++)
03379 {
03380 if (items[i]->class_owner == (void *)this)
03381 {
03382 status = items[i]->generateCode_C(this, hints, &ctxH, &ctxC);
03383 if (status)
03384 return status;
03385 }
03386 }
03387
03388 ctxC.pop();
03389 generateMethodBody_C(m, &ctxC, &ctxStubsFe, &ctxStubsBe,
03390 &ctxMthFe, &ctxMthBe);
03391 ctxC.push();
03392
03393
03394
03395 generateMethodDecl_C(m, &ctxH);
03396
03397 fprintf(fdh, "%svirtual ~%s() {garbageRealize();}\n", ctxH.get(),
03398 name);
03399
03400 if (attr_cache)
03401 fprintf(fdh, "\n%svoid attrCacheEmpty();\n", ctxH.get());
03402
03403 if (getTiedCode())
03404 {
03405 #ifndef NO_COMMENTS
03406 fprintf(fdh, "\n%s// ----------------------------------------------------------------------\n", ctxH.get());
03407 #endif
03408 fprintf(fdh, "%s// %s User Part\n", ctxH.get(), name);
03409 #ifndef NO_COMMENTS
03410 fprintf(fdh, "%s// ----------------------------------------------------------------------\n", ctxH.get());
03411 #endif
03412 fprintf(fdh, "%s\n", getTiedCode());
03413 }
03414
03415 #ifndef NO_COMMENTS
03416 fprintf(fdh, "\n%s// ----------------------------------------------------------------------\n", ctxH.get());
03417 fprintf(fdh, "%s// %s Protected Part\n", ctxH.get(), name);
03418 fprintf(fdh, "%s// ----------------------------------------------------------------------\n", ctxH.get());
03419 #else
03420 fprintf(fdh, "\n");
03421 #endif
03422 fprintf(fdh, " protected:\n");
03423
03424 if (attr_cache && !isRootClass())
03425 fprintf(fdh, "%svirtual void garbage();\n", ctxH.get());
03426
03427
03428 fprintf(fdh, "%s%s(eyedb::Database *_db, const eyedb::Dataspace *_dataspace, int) : ", ctxH.get(), name);
03429
03430 const_f0(fdh, parent, "_db, _dataspace");
03431
03432 fprintf(fdh, " {}\n");
03433 fprintf(fdh, "%s%s(const eyedb::Struct *x, eyedb::Bool share, int) : ",
03434 ctxH.get(), name);
03435 const_f01(fdh, parent, "x");
03436 fprintf(fdh, " {}\n");
03437
03438 fprintf(fdh, "%s%s(const %s *x, eyedb::Bool share, int) : ", ctxH.get(), name, name);
03439 const_f01(fdh, parent, "x");
03440
03441 fprintf(fdh, " {}\n");
03442
03443 #ifndef NO_COMMENTS
03444 fprintf(fdh, "\n%s// ----------------------------------------------------------------------\n", ctxH.get());
03445 fprintf(fdh, "%s// %s Private Part\n", ctxH.get(), name);
03446 fprintf(fdh, "%s// ----------------------------------------------------------------------\n", ctxH.get());
03447 #else
03448 fprintf(fdh, "\n");
03449 #endif
03450
03451 fprintf(fdh, " private:\n", ctxH.get());
03452
03453 fprintf(fdh, "%svoid initialize(eyedb::Database *_db);\n", ctxH.get());
03454
03455 if (attr_cache)
03456 {
03457 fprintf(fdh, "\n");
03458 int i;
03459 for (i = 0; i < items_cnt; i++)
03460 if (items[i]->getClassOwner()->compare(this))
03461 items[i]->genAttrCacheDecl(&ctxH);
03462 }
03463
03464 fprintf(fdh, "\n public: /* restricted */\n", ctxH.get());
03465 fprintf(fdh, "%s%s(const eyedb::Struct *, eyedb::Bool = eyedb::False);\n",
03466 ctxH.get(), name);
03467 fprintf(fdh, "%s%s(const %s *, eyedb::Bool = eyedb::False);\n",
03468 ctxH.get(), name, name);
03469 fprintf(fdh, "%s%s(const eyedb::Class *, eyedb::Data);\n", ctxH.get(), name);
03470
03471 fprintf(fdh, "};\n\n");
03472
03473 ctxH.pop();
03474 ctxC.pop();
03475
03476 return Success;
03477 }
03478
03479 Status EnumClass::generateClassDesc_C(GenContext *ctx)
03480 {
03481 FILE *fd = ctx->getFile();
03482 Status status;
03483
03484 fprintf(fd, "static eyedb::Size %s_idr_objsz, %s_idr_psize;\n\n", name, name);
03485
03486 fprintf(fd, "static eyedb::EnumClass *%s_make(eyedb::EnumClass *%s_class = 0, eyedb::Schema *m = 0)\n{\n", name, name);
03487
03488 ctx->push();
03489 fprintf(fd, "%sif (!%s_class)\n", ctx->get(), name);
03490 fprintf(fd, "%s return new eyedb::EnumClass(\"%s\");\n", ctx->get(), getAliasName());
03491
03492 fprintf(fd, "%seyedb::EnumItem *en[%d];\n", ctx->get(), items_cnt);
03493
03494 int i;
03495 for (i = 0; i < items_cnt; i++)
03496 fprintf(fd, "%sen[%d] = new eyedb::EnumItem(\"%s\", \"%s\", (unsigned int)%d);\n",
03497 ctx->get(),
03498 i, items[i]->getName(), items[i]->getAliasName(),
03499 items[i]->getValue());
03500
03501 fprintf(fd, "\n%s%s_class->setEnumItems(en, %d);\n", ctx->get(),
03502 name, items_cnt);
03503
03504 fprintf(fd, "\n");
03505 for (i = 0; i < items_cnt; i++)
03506 fprintf(fd, "%sdelete en[%d];\n", ctx->get(), i);
03507 fprintf(fd, "\n");
03508
03509 if (isSystem() || odl_system_class)
03510 fprintf(fd, "%seyedb::ClassPeer::setMType(%s_class, eyedb::Class::System);\n",
03511 ctx->get(), name);
03512
03513 fprintf(fd, "\n%sreturn %s_class;\n}\n\n", ctx->get(), name);
03514
03515 fprintf(fd, "static void %s_init_p()\n{\n", name);
03516 fprintf(fd, "%s%s%s = %s_make();\n", ctx->get(), name, classSuffix, name);
03517 fprintf(fd, "}\n\n");
03518
03519 fprintf(fd, "static void %s_init()\n{\n", name);
03520 fprintf(fd, "%s%s_make(%s%s);\n\n", ctx->get(), name, name, classSuffix);
03521
03522 fprintf(fd, "%s%s_idr_objsz = %s%s->getIDRObjectSize(&%s_idr_psize, 0);\n\n",
03523 ctx->get(), name, name, classSuffix, name);
03524
03525 fprintf(fd, "%seyedb::ObjectPeer::setUnrealizable(%s%s, eyedb::True);\n",
03526 ctx->get(), name, classSuffix);
03527 fprintf(fd, "}\n\n");
03528 ctx->pop();
03529
03530 return Success;
03531 }
03532
03533 Status
03534 EnumClass::generateCode_C(Schema *,
03535 const char *prefix,
03536 const GenCodeHints &hints,
03537 const char *stubs,
03538 FILE *fdh, FILE *fdc, FILE *,
03539 FILE *, FILE *, FILE *)
03540 {
03541 GenContext ctxH(fdh), ctxC(fdc);
03542 int i;
03543 Status status;
03544
03545 phints = &hints;
03546 class_enums = hints.class_enums;
03547 attr_cache = hints.attr_cache;
03548
03549 generateClassDesc_C(&ctxC);
03550
03551 ctxH.push();
03552 ctxC.push();
03553
03554
03555
03556 const char *indent_str;
03557
03558 if (class_enums) {
03559 fprintf(fdh, "class %s {\n", name);
03560 fprintf(fdh, "\npublic:\n");
03561 fprintf(fdh, " enum %s {\n", enum_type);
03562 indent_str = " ";
03563 }
03564 else {
03565 fprintf(fdh, "enum %s {\n", name);
03566 indent_str = " ";
03567 }
03568
03569 EnumItem **it;
03570 for (i = 0, it = items; i < items_cnt; i++, it++)
03571 {
03572 if (i) fprintf(fdh, ",\n");
03573 fprintf(fdh, "%s%s = %d", indent_str,
03574 (*it)->getAliasName(), (*it)->getValue());
03575 }
03576
03577 if (class_enums)
03578 fprintf(fdh, "\n };");
03579
03580 fprintf(fdh, "\n};\n\n");
03581
03582 ctxH.pop();
03583 ctxC.pop();
03584
03585 return Success;
03586 }
03587
03588 Status CollectionClass::generateCode_C(Schema *,
03589 const char *prefix,
03590 const GenCodeHints &hints,
03591 const char *stubs,
03592 FILE *fdh,
03593 FILE *fdc, FILE *, FILE *,
03594 FILE *, FILE *)
03595 {
03596 GenContext ctxH(fdh), ctxC(fdc);
03597 int i;
03598 Status status;
03599 const char *c_name = getCName();
03600 const char *_type = getCSuffix();
03601
03602 phints = &hints;
03603 class_enums = hints.class_enums;
03604 attr_cache = hints.attr_cache;
03605
03606 fprintf(fdc, "static eyedb::%sClass *%s_make(eyedb::%sClass *cls = 0, eyedb::Schema *m = 0)\n{\n", _type, c_name, _type);
03607 ctxC.push();
03608
03609 fprintf(fdc, "%sif (!cls)\n%s {\n", ctxC.get(), ctxC.get());
03610
03611 fprintf(fdc, "%s cls = new eyedb::%sClass((m ? m->getClass(\"%s\") : %s%s), ",
03612 ctxC.get(), _type, coll_class->getAliasName(),
03613 (coll_class->asCollectionClass() ? coll_class->getCName() :
03614 className(coll_class)), classSuffix);
03615
03616 if (dim > 1)
03617 fprintf(fdc, "%d);\n", dim);
03618 else
03619 fprintf(fdc, "%s);\n", (isref ? "eyedb::True" : "eyedb::False"));
03620
03621 fprintf(fdc, "%s eyedb::ClassPeer::setMType(cls, eyedb::Class::System);\n",
03622 ctxC.get());
03623 fprintf(fdc, "%s }\n", ctxC.get());
03624
03625 fprintf(fdc, "%sreturn cls;\n", ctxC.get());
03626 fprintf(fdc, "}\n\n");
03627
03628 fprintf(fdc, "static void %s_init_p()\n{\n", c_name);
03629 fprintf(fdc, "%s%s%s = %s_make();\n", ctxC.get(), c_name, classSuffix, c_name);
03630 fprintf(fdc, "}\n\n");
03631
03632 return Success;
03633 }
03634 }
03635