From 35d242b74b4f31fd4be8853d2bd945df975d4d7b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 21 May 2006 21:18:23 +0000 Subject: make printExpr, skipExpr accept both gob1 and gob2 expressions svn-id: r22568 --- engines/gob/parse.cpp | 105 ++++++++++++++++++++++++++++++-------------------- engines/gob/parse.h | 2 + 2 files changed, 65 insertions(+), 42 deletions(-) (limited to 'engines/gob') diff --git a/engines/gob/parse.cpp b/engines/gob/parse.cpp index be007bc7c8..14fec542fb 100644 --- a/engines/gob/parse.cpp +++ b/engines/gob/parse.cpp @@ -85,10 +85,13 @@ void Parse::skipExpr(char stopToken) { while (1) { operation = *_vm->_global->_inter_execPtr++; - if (operation >= 19 && operation <= 29) { + if (operation >= 16 && operation <= 29) { switch (operation) { + case 17: + case 18: case 20: case 23: + case 24: _vm->_global->_inter_execPtr += 2; break; @@ -96,6 +99,10 @@ void Parse::skipExpr(char stopToken) { _vm->_global->_inter_execPtr += 4; break; + case 21: + _vm->_global->_inter_execPtr += 1; + break; + case 22: _vm->_global->_inter_execPtr += strlen(_vm->_global->_inter_execPtr) + 1; break; @@ -108,10 +115,14 @@ void Parse::skipExpr(char stopToken) { } break; + case 16: case 26: + case 27: case 28: dimCount = _vm->_global->_inter_execPtr[2]; - _vm->_global->_inter_execPtr += 3 + dimCount; // ??? + // skip header and dimensions + _vm->_global->_inter_execPtr += 3 + dimCount; + // skip indices for (dim = 0; dim < dimCount; dim++) skipExpr(12); @@ -126,7 +137,7 @@ void Parse::skipExpr(char stopToken) { skipExpr(10); } continue; - } // if (operation >= 19 && operation <= 29) + } // if (operation >= 16 && operation <= 29) if (operation == 9) { num++; @@ -151,61 +162,77 @@ void Parse::skipExpr(char stopToken) { } void Parse::printExpr(char stopToken) { + // Expression printing disabled by default + return; + + char* savedPos = _vm->_global->_inter_execPtr; + printExpr_internal(stopToken); + + // restore IP to start of expression + _vm->_global->_inter_execPtr = savedPos; +} + +void Parse::printExpr_internal(char stopToken) { int16 dimCount; char operation; int16 num; int16 dim; char *arrDesc; char func; - char saved = 0; - static char *savedPos = 0; - - // TODO: There seems to be a problem here, GOB2 runs into an endless loop - return; - - if (savedPos == 0) { - savedPos = _vm->_global->_inter_execPtr; - saved = 1; - } num = 0; while (1) { operation = *_vm->_global->_inter_execPtr++; - if (operation >= 19 && operation <= 29) { + if (operation >= 16 && operation <= 29) { + // operands + switch (operation) { - case 19: + case 17: // uint16 variable load + debugN(5, "var16_%d", _vm->_inter->load16()); + break; + + case 18: // uint8 variable load: + debugN(5, "var8_%d", _vm->_inter->load16()); + break; + + case 19: // uint32 immediate debugN(5, "%d", READ_LE_UINT32(_vm->_global->_inter_execPtr)); _vm->_global->_inter_execPtr += 4; break; - case 20: + case 20: // uint16 immediate debugN(5, "%d", _vm->_inter->load16()); break; - case 22: + case 21: // uint8 immediate + debugN(5, "%d", *_vm->_global->_inter_execPtr++); + break; + + case 22: // string immediate debugN(5, "\42%s\42", _vm->_global->_inter_execPtr); _vm->_global->_inter_execPtr += strlen(_vm->_global->_inter_execPtr) + 1; break; - case 23: - { - int16 varnum = _vm->_inter->load16(); - debugN(5, "var_%d (val=%d)", varnum, READ_LE_UINT32(_vm->_global->_inter_variables + varnum * 4) ); + case 23: // uint32 variable load + case 24: // uint32 variable load as uint16 + debugN(5, "var_%d", _vm->_inter->load16()); break; - } - case 25: + + case 25: // string variable load debugN(5, "(&var_%d)", _vm->_inter->load16()); if (*_vm->_global->_inter_execPtr == 13) { _vm->_global->_inter_execPtr++; debugN(5, "{"); - printExpr(12); - debugN(5, "}"); + printExpr_internal(12); // this also prints the closing } } break; - case 26: - case 28: + case 16: // uint8 array access + case 26: // uint32 array access + case 27: // uint16 array access + case 28: // string array access + debugN(5, "\n"); if (operation == 28) debugN(5, "(&"); @@ -214,7 +241,7 @@ void Parse::printExpr(char stopToken) { arrDesc = _vm->_global->_inter_execPtr; _vm->_global->_inter_execPtr += dimCount; for (dim = 0; dim < dimCount; dim++) { - printExpr(12); + printExpr_internal(12); debugN(5, " of %d", (int16)arrDesc[dim]); if (dim != dimCount - 1) debugN(5, ","); @@ -226,12 +253,11 @@ void Parse::printExpr(char stopToken) { if (operation == 28 && *_vm->_global->_inter_execPtr == 13) { _vm->_global->_inter_execPtr++; debugN(5, "{"); - printExpr(12); -// debugN(5, "}"); + printExpr_internal(12); // this also prints the closing } } break; - case 29: + case 29: // function func = *_vm->_global->_inter_execPtr++; if (func == 5) debugN(5, "sqr("); @@ -243,15 +269,13 @@ void Parse::printExpr(char stopToken) { debugN(5, "sqrt("); else debugN(5, "id("); - printExpr(10); - break; - - default: - debugN(5, "<%d>", (int16)operation); + printExpr_internal(10); break; } continue; - } // if (operation >= 19 && operation <= 29) + } // if (operation >= 16 && operation <= 29) + + // operators switch (operation) { case 9: debugN(5, "("); @@ -342,6 +366,7 @@ void Parse::printExpr(char stopToken) { default: debugN(5, "<%d>", (int16)operation); + error("printExpr: invalid operator in expression"); break; } @@ -361,17 +386,13 @@ void Parse::printExpr(char stopToken) { if (operation == stopToken) { if (stopToken != 10 || num < 0) { - - if (saved != 0) { - _vm->_global->_inter_execPtr = savedPos; - savedPos = 0; - } return; } } } } + void Parse::printVarIndex() { char *arrDesc; int16 dim; diff --git a/engines/gob/parse.h b/engines/gob/parse.h index e85fbebcfa..2ebcdfb2ec 100644 --- a/engines/gob/parse.h +++ b/engines/gob/parse.h @@ -48,6 +48,8 @@ protected: int32 encodePtr(char *ptr, int type); char *decodePtr(int32 n); + + void printExpr_internal(char stopToken); }; class Parse_v1 : public Parse { -- cgit v1.2.3