Fennel: /home/pub/open/dev/fennel/calculator/BoolPointerInstruction.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 #ifndef Fennel_BoolPointerInstruction_Included 00023 #define Fennel_BoolPointerInstruction_Included 00024 00025 #include "fennel/calculator/PointerInstruction.h" 00026 00027 FENNEL_BEGIN_NAMESPACE 00028 00034 template 00035 class BoolPointerInstruction : public PointerInstruction 00036 { 00037 public: 00038 explicit 00039 BoolPointerInstruction( 00040 RegisterRef* result, 00041 RegisterRef* op1, 00042 StandardTypeDescriptorOrdinal pointerType) 00043 : mResult(result), 00044 mOp1(op1), 00045 mOp2(),
00046 mPointerType(pointerType) 00047 {} 00048 explicit 00049 BoolPointerInstruction( 00050 RegisterRef* result, 00051 RegisterRef* op1, 00052 RegisterRef* op2, 00053 StandardTypeDescriptorOrdinal pointerType) 00054 : mResult(result), 00055 mOp1(op1), 00056 mOp2(op2), 00057 mPointerType(pointerType) 00058 {} 00059 ~BoolPointerInstruction() { 00060 #ifndef MSVC 00061
00062 if (0) { 00063 PointerInstruction_NotAPointerType(); 00064 } 00065 #endif 00066 } 00067 00068 protected: 00069 RegisterRef* mResult; 00070 RegisterRef* mOp1; 00071 RegisterRef* mOp2; 00072 StandardTypeDescriptorOrdinal mPointerType; 00073 00074 }; 00075 00076 template 00077 class BoolPointerEqual : public BoolPointerInstruction 00078 { 00079 public: 00080 explicit 00081 BoolPointerEqual( 00082 RegisterRef* result, 00083 RegisterRef* op1, 00084 RegisterRef* op2, 00085 StandardTypeDescriptorOrdinal pointerType) 00086 : BoolPointerInstruction(result, op1, op2, pointerType) 00087 {} 00088 virtual 00089 ~BoolPointerEqual() {} 00090 00091 virtual void exec(TProgramCounter& pc) const { 00092 pc++; 00093 00094 if (BoolPointerInstruction::mOp1->isNull() || 00095 BoolPointerInstruction::mOp2->isNull()) { 00096 BoolPointerInstruction::mResult->toNull(); 00097 } else if (BoolPointerInstruction::mOp1->pointer() == 00098 BoolPointerInstruction::mOp2->pointer()) { 00099 BoolPointerInstruction::mResult->value(true); 00100 } else { 00101 BoolPointerInstruction::mResult->value(false); 00102 } 00103 } 00104 00105 static const char * longName() 00106 { 00107 return "BoolPointerEqual"; 00108 } 00109 00110 static const char * shortName() 00111 { 00112 return "EQ"; 00113 } 00114 00115 static int numArgs() 00116 { 00117 return 3; 00118 } 00119 00120 void describe(string& out, bool values) const { 00121 describeHelper( 00122 out, values, longName(), shortName(), 00123 BoolPointerInstruction::mResult, 00124 BoolPointerInstruction::mOp1, 00125 BoolPointerInstruction::mOp2); 00126 } 00127 00128 static InstructionSignature 00129 signature(StandardTypeDescriptorOrdinal type) { 00130 vector v(numArgs(), type); 00131 v[0] = STANDARD_TYPE_BOOL; 00132 return InstructionSignature(shortName(), v); 00133 } 00134 00135 static Instruction* 00136 create(InstructionSignature const & sig) 00137 { 00138 assert(sig.size() == numArgs()); 00139 return new 00140 BoolPointerEqual( 00141 static_cast<RegisterRef> (sig[0]), 00142 static_cast<RegisterRef> (sig[1]), 00143 static_cast<RegisterRef> (sig[2]), 00144 (sig[1])->type()); 00145 } 00146 }; 00147 00148 template 00149 class BoolPointerNotEqual : public BoolPointerInstruction 00150 { 00151 public: 00152 explicit 00153 BoolPointerNotEqual( 00154 RegisterRef result, 00155 RegisterRef* op1, 00156 RegisterRef* op2, 00157 StandardTypeDescriptorOrdinal pointerType) 00158 : BoolPointerInstruction(result, op1, op2, pointerType) 00159 {} 00160 virtual 00161 ~BoolPointerNotEqual() {} 00162 00163 virtual void exec(TProgramCounter& pc) const { 00164 pc++; 00165 if (BoolPointerInstruction::mOp1->isNull() || 00166 BoolPointerInstruction::mOp2->isNull()) { 00167 BoolPointerInstruction::mResult->toNull(); 00168 } else if (BoolPointerInstruction::mOp1->pointer() == 00169 BoolPointerInstruction::mOp2->pointer()) { 00170 BoolPointerInstruction::mResult->value(false); 00171 } else { 00172 BoolPointerInstruction::mResult->value(true); 00173 } 00174 } 00175 00176 static const char * longName() 00177 { 00178 return "BoolPointerNotEqual"; 00179 } 00180 00181 static const char * shortName() 00182 { 00183 return "NE"; 00184 } 00185 00186 static int numArgs() 00187 { 00188 return 3; 00189 } 00190 00191 void describe(string& out, bool values) const { 00192 describeHelper( 00193 out, values, longName(), shortName(), 00194 BoolPointerInstruction::mResult, 00195 BoolPointerInstruction::mOp1, 00196 BoolPointerInstruction::mOp2); 00197 } 00198 00199 static InstructionSignature 00200 signature(StandardTypeDescriptorOrdinal type) { 00201 vector v(numArgs(), type); 00202 v[0] = STANDARD_TYPE_BOOL; 00203 return InstructionSignature(shortName(), v); 00204 } 00205 00206 static Instruction* 00207 create(InstructionSignature const & sig) 00208 { 00209 assert(sig.size() == numArgs()); 00210 return new 00211 BoolPointerNotEqual( 00212 static_cast<RegisterRef> (sig[0]), 00213 static_cast<RegisterRef> (sig[1]), 00214 static_cast<RegisterRef> (sig[2]), 00215 (sig[1])->type()); 00216 } 00217 }; 00218 00219 template 00220 class BoolPointerGreater : public BoolPointerInstruction 00221 { 00222 public: 00223 explicit 00224 BoolPointerGreater( 00225 RegisterRef result, 00226 RegisterRef* op1, 00227 RegisterRef* op2, 00228 StandardTypeDescriptorOrdinal pointerType) 00229 : BoolPointerInstruction(result, op1, op2, pointerType) 00230 {} 00231 virtual 00232 ~BoolPointerGreater() {} 00233 00234 virtual void exec(TProgramCounter& pc) const { 00235 pc++; 00236 if (BoolPointerInstruction::mOp1->isNull() || 00237 BoolPointerInstruction::mOp2->isNull()) { 00238 BoolPointerInstruction::mResult->toNull(); 00239 } else if (BoolPointerInstruction::mOp1->pointer() > 00240 BoolPointerInstruction::mOp2->pointer()) { 00241 BoolPointerInstruction::mResult->value(true); 00242 } else { 00243 BoolPointerInstruction::mResult->value(false); 00244 } 00245 } 00246 00247 static const char * longName() 00248 { 00249 return "BoolPointerGreater"; 00250 } 00251 00252 static const char * shortName() 00253 { 00254 return "GT"; 00255 } 00256 00257 static int numArgs() 00258 { 00259 return 3; 00260 } 00261 00262 void describe(string& out, bool values) const { 00263 describeHelper( 00264 out, values, longName(), shortName(), 00265 BoolPointerInstruction::mResult, 00266 BoolPointerInstruction::mOp1, 00267 BoolPointerInstruction::mOp2); 00268 } 00269 00270 static InstructionSignature 00271 signature(StandardTypeDescriptorOrdinal type) { 00272 vector v(numArgs(), type); 00273 v[0] = STANDARD_TYPE_BOOL; 00274 return InstructionSignature(shortName(), v); 00275 } 00276 00277 static Instruction* 00278 create(InstructionSignature const & sig) 00279 { 00280 assert(sig.size() == numArgs()); 00281 return new 00282 BoolPointerGreater( 00283 static_cast<RegisterRef> (sig[0]), 00284 static_cast<RegisterRef> (sig[1]), 00285 static_cast<RegisterRef> (sig[2]), 00286 (sig[1])->type()); 00287 } 00288 }; 00289 00290 template 00291 class BoolPointerGreaterEqual : public BoolPointerInstruction 00292 { 00293 public: 00294 explicit 00295 BoolPointerGreaterEqual( 00296 RegisterRef result, 00297 RegisterRef* op1, 00298 RegisterRef* op2, 00299 StandardTypeDescriptorOrdinal pointerType) 00300 : BoolPointerInstruction(result, op1, op2, pointerType) 00301 {} 00302 virtual 00303 ~BoolPointerGreaterEqual() {} 00304 00305 virtual void exec(TProgramCounter& pc) const { 00306 pc++; 00307 if (BoolPointerInstruction::mOp1->isNull() || 00308 BoolPointerInstruction::mOp2->isNull()) { 00309 BoolPointerInstruction::mResult->toNull(); 00310 } else if (BoolPointerInstruction::mOp1->pointer() >= 00311 BoolPointerInstruction::mOp2->pointer()) { 00312 BoolPointerInstruction::mResult->value(true); 00313 } else { 00314 BoolPointerInstruction::mResult->value(false); 00315 } 00316 } 00317 00318 static const char * longName() 00319 { 00320 return "BoolPointerGreaterEqual"; 00321 } 00322 00323 static const char * shortName() 00324 { 00325 return "GE"; 00326 } 00327 00328 static int numArgs() 00329 { 00330 return 3; 00331 } 00332 00333 void describe(string& out, bool values) const { 00334 describeHelper( 00335 out, values, longName(), shortName(), 00336 BoolPointerInstruction::mResult, 00337 BoolPointerInstruction::mOp1, 00338 BoolPointerInstruction::mOp2); 00339 } 00340 00341 static InstructionSignature 00342 signature(StandardTypeDescriptorOrdinal type) { 00343 vector v(numArgs(), type); 00344 v[0] = STANDARD_TYPE_BOOL; 00345 return InstructionSignature(shortName(), v); 00346 } 00347 00348 static Instruction* 00349 create(InstructionSignature const & sig) 00350 { 00351 assert(sig.size() == numArgs()); 00352 return new 00353 BoolPointerGreaterEqual( 00354 static_cast<RegisterRef> (sig[0]), 00355 static_cast<RegisterRef> (sig[1]), 00356 static_cast<RegisterRef> (sig[2]), 00357 (sig[1])->type()); 00358 } 00359 }; 00360 00361 template 00362 class BoolPointerLess : public BoolPointerInstruction 00363 { 00364 public: 00365 explicit 00366 BoolPointerLess( 00367 RegisterRef result, 00368 RegisterRef* op1, 00369 RegisterRef* op2, 00370 StandardTypeDescriptorOrdinal pointerType) 00371 : BoolPointerInstruction(result, op1, op2, pointerType) 00372 {} 00373 virtual 00374 ~BoolPointerLess() {} 00375 00376 virtual void exec(TProgramCounter& pc) const { 00377 pc++; 00378 if (BoolPointerInstruction::mOp1->isNull() || 00379 BoolPointerInstruction::mOp2->isNull()) { 00380 BoolPointerInstruction::mResult->toNull(); 00381 } else if (BoolPointerInstruction::mOp1->pointer() < 00382 BoolPointerInstruction::mOp2->pointer()) { 00383 BoolPointerInstruction::mResult->value(true); 00384 } else { 00385 BoolPointerInstruction::mResult->value(false); 00386 } 00387 } 00388 00389 static const char * longName() 00390 { 00391 return "BoolPointerLess"; 00392 } 00393 00394 static const char * shortName() 00395 { 00396 return "LT"; 00397 } 00398 00399 static int numArgs() 00400 { 00401 return 3; 00402 } 00403 00404 void describe(string& out, bool values) const { 00405 describeHelper( 00406 out, values, longName(), shortName(), 00407 BoolPointerInstruction::mResult, 00408 BoolPointerInstruction::mOp1, 00409 BoolPointerInstruction::mOp2); 00410 } 00411 00412 static InstructionSignature 00413 signature(StandardTypeDescriptorOrdinal type) { 00414 vector v(numArgs(), type); 00415 v[0] = STANDARD_TYPE_BOOL; 00416 return InstructionSignature(shortName(), v); 00417 } 00418 00419 static Instruction* 00420 create(InstructionSignature const & sig) 00421 { 00422 assert(sig.size() == numArgs()); 00423 return new 00424 BoolPointerLess( 00425 static_cast<RegisterRef> (sig[0]), 00426 static_cast<RegisterRef> (sig[1]), 00427 static_cast<RegisterRef> (sig[2]), 00428 (sig[1])->type()); 00429 } 00430 }; 00431 00432 template 00433 class BoolPointerLessEqual : public BoolPointerInstruction 00434 { 00435 public: 00436 explicit 00437 BoolPointerLessEqual( 00438 RegisterRef result, 00439 RegisterRef* op1, 00440 RegisterRef* op2, 00441 StandardTypeDescriptorOrdinal pointerType) 00442 : BoolPointerInstruction(result, op1, op2, pointerType) 00443 {} 00444 virtual 00445 ~BoolPointerLessEqual() {} 00446 00447 virtual void exec(TProgramCounter& pc) const { 00448 pc++; 00449 if (BoolPointerInstruction::mOp1->isNull() || 00450 BoolPointerInstruction::mOp2->isNull()) { 00451 BoolPointerInstruction::mResult->toNull(); 00452 } else if (BoolPointerInstruction::mOp1->pointer() <= 00453 BoolPointerInstruction::mOp2->pointer()) { 00454 BoolPointerInstruction::mResult->value(true); 00455 } else { 00456 BoolPointerInstruction::mResult->value(false); 00457 } 00458 } 00459 00460 static const char * longName() 00461 { 00462 return "BoolPointerLessEqual"; 00463 } 00464 00465 static const char * shortName() 00466 { 00467 return "LE"; 00468 } 00469 00470 static int numArgs() 00471 { 00472 return 3; 00473 } 00474 00475 void describe(string& out, bool values) const { 00476 describeHelper( 00477 out, values, longName(), shortName(), 00478 BoolPointerInstruction::mResult, 00479 BoolPointerInstruction::mOp1, 00480 BoolPointerInstruction::mOp2); 00481 } 00482 00483 static InstructionSignature 00484 signature(StandardTypeDescriptorOrdinal type) { 00485 vector v(numArgs(), type); 00486 v[0] = STANDARD_TYPE_BOOL; 00487 return InstructionSignature(shortName(), v); 00488 } 00489 00490 static Instruction* 00491 create(InstructionSignature const & sig) 00492 { 00493 assert(sig.size() == numArgs()); 00494 return new 00495 BoolPointerLessEqual( 00496 static_cast<RegisterRef> (sig[0]), 00497 static_cast<RegisterRef> (sig[1]), 00498 static_cast<RegisterRef> (sig[2]), 00499 (sig[1])->type()); 00500 } 00501 }; 00502 00503 template 00504 class BoolPointerIsNull : public BoolPointerInstruction 00505 { 00506 public: 00507 explicit 00508 BoolPointerIsNull( 00509 RegisterRef result, 00510 RegisterRef* op1, 00511 StandardTypeDescriptorOrdinal pointerType) 00512 : BoolPointerInstruction(result, op1, pointerType) 00513 {} 00514 virtual 00515 ~BoolPointerIsNull() {} 00516 00517 virtual void exec(TProgramCounter& pc) const { 00518 pc++; 00519 if (BoolPointerInstruction::mOp1->isNull()) { 00520 BoolPointerInstruction::mResult->value(true); 00521 } else { 00522 BoolPointerInstruction::mResult->value(false); 00523 } 00524 } 00525 00526 static const char * longName() 00527 { 00528 return "BoolPointerIsNull"; 00529 } 00530 00531 static const char * shortName() 00532 { 00533 return "ISNULL"; 00534 } 00535 00536 static int numArgs() 00537 { 00538 return 2; 00539 } 00540 00541 void describe(string& out, bool values) const { 00542 describeHelper( 00543 out, values, longName(), shortName(), 00544 BoolPointerInstruction::mResult, 00545 BoolPointerInstruction::mOp1, 00546 BoolPointerInstruction::mOp2); 00547 } 00548 00549 static InstructionSignature 00550 signature(StandardTypeDescriptorOrdinal type) { 00551 vector v(numArgs(), type); 00552 v[0] = STANDARD_TYPE_BOOL; 00553 return InstructionSignature(shortName(), v); 00554 } 00555 00556 static Instruction* 00557 create(InstructionSignature const & sig) 00558 { 00559 assert(sig.size() == numArgs()); 00560 return new 00561 BoolPointerIsNull( 00562 static_cast<RegisterRef> (sig[0]), 00563 static_cast<RegisterRef> (sig[1]), 00564 (sig[1])->type()); 00565 } 00566 }; 00567 00568 template 00569 class BoolPointerIsNotNull : public BoolPointerInstruction 00570 { 00571 public: 00572 explicit 00573 BoolPointerIsNotNull( 00574 RegisterRef* result, 00575 RegisterRef* op1, 00576 StandardTypeDescriptorOrdinal pointerType) 00577 : BoolPointerInstruction(result, op1, pointerType) 00578 {} 00579 virtual 00580 ~BoolPointerIsNotNull() {} 00581 00582 virtual void exec(TProgramCounter& pc) const { 00583 pc++; 00584 if (BoolPointerInstruction::mOp1->isNull()) { 00585 BoolPointerInstruction::mResult->value(false); 00586 } else { 00587 BoolPointerInstruction::mResult->value(true); 00588 } 00589 } 00590 00591 static const char * longName() 00592 { 00593 return "BoolPointerIsNotNull"; 00594 } 00595 00596 static const char * shortName() 00597 { 00598 return "ISNOTNULL"; 00599 } 00600 00601 static int numArgs() 00602 { 00603 return 2; 00604 } 00605 00606 void describe(string& out, bool values) const { 00607 describeHelper( 00608 out, values, longName(), shortName(), 00609 BoolPointerInstruction::mResult, 00610 BoolPointerInstruction::mOp1, 00611 BoolPointerInstruction::mOp2); 00612 } 00613 00614 static InstructionSignature 00615 signature(StandardTypeDescriptorOrdinal type) { 00616 vector v(numArgs(), type); 00617 v[0] = STANDARD_TYPE_BOOL; 00618 return InstructionSignature(shortName(), v); 00619 } 00620 00621 static Instruction* 00622 create(InstructionSignature const & sig) 00623 { 00624 assert(sig.size() == numArgs()); 00625 return new 00626 BoolPointerIsNotNull( 00627 static_cast<RegisterRef> (sig[0]), 00628 static_cast<RegisterRef> (sig[1]), 00629 (sig[1])->type()); 00630 } 00631 }; 00632 00633 class FENNEL_CALCULATOR_EXPORT BoolPointerInstructionRegister 00634 : InstructionRegister 00635 { 00636
00637 template < template class INSTCLASS2 > 00638 static void 00639 registerTypes(vector const &t) { 00640 00641 for (uint i = 0; i < t.size(); i++) { 00642 StandardTypeDescriptorOrdinal type = t[i]; 00643
00644 InstructionSignature sig = INSTCLASS2::signature(type); 00645 switch (type) { 00646
00647
00648
00649
00650 #define Fennel_InstructionRegisterSwitch_Array 1 00651 #include "fennel/calculator/InstructionRegisterSwitch.h" 00652 default: 00653 throw std::logic_error("Default InstructionRegister"); 00654 } 00655 } 00656 } 00657 00658 public: 00659 static void 00660 registerInstructions() { 00661 vector t; 00662
00663
00664
00665 t = InstructionSignature::typeVector(StandardTypeDescriptor::isArray); 00666 00667
00668
00669
00670
00671
00672 registerTypesfennel::BoolPointerEqual(t); 00673 registerTypesfennel::BoolPointerNotEqual(t); 00674 registerTypesfennel::BoolPointerGreater(t); 00675 registerTypesfennel::BoolPointerGreaterEqual(t); 00676 registerTypesfennel::BoolPointerLess(t); 00677 registerTypesfennel::BoolPointerLessEqual(t); 00678 registerTypesfennel::BoolPointerIsNull(t); 00679 registerTypesfennel::BoolPointerIsNotNull(t); 00680 } 00681 }; 00682 00683 FENNEL_END_NAMESPACE 00684 00685 #endif 00686 00687 00688