OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkScript2.h" | 8 #include "SkScript2.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 ++script; | 596 ++script; |
597 track(operand.fOperand.fString); | 597 track(operand.fOperand.fString); |
598 operand.fType = SkOperand2::kString; | 598 operand.fType = SkOperand2::kString; |
599 operand.fIsConstant = SkScriptValue2::kConstant; | 599 operand.fIsConstant = SkScriptValue2::kConstant; |
600 fValueStack.push(operand); | 600 fValueStack.push(operand); |
601 lastPush = true; | 601 lastPush = true; |
602 continue; | 602 continue; |
603 } | 603 } |
604 if (ch == '.') { | 604 if (ch == '.') { |
605 if (fTokenLength == 0) { | 605 if (fTokenLength == 0) { |
606 SkDEBUGCODE(SkScriptValue2 scriptValue;) | |
607 SkDEBUGCODE(scriptValue.fOperand.fObject = NULL); | |
608 int tokenLength = token_length(++script); | 606 int tokenLength = token_length(++script); |
609 const char* token = script; | 607 const char* token = script; |
610 script += tokenLength; | 608 script += tokenLength; |
611 SkASSERT(fValueStack.count() > 0); // !!! add error handling | 609 SkASSERT(fValueStack.count() > 0); // !!! add error handling |
612 SkScriptValue2 top; | 610 SkScriptValue2 top; |
613 fValueStack.pop(&top); | 611 fValueStack.pop(&top); |
614 | 612 |
615 addTokenInt(top.fType); | 613 addTokenInt(top.fType); |
616 addToken(kBoxToken); | 614 addToken(kBoxToken); |
617 top.fType = SkOperand2::kObject; | 615 top.fType = SkOperand2::kObject; |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 string->set(*value.fOperand.fString); | 1264 string->set(*value.fOperand.fString); |
1267 break; | 1265 break; |
1268 default: | 1266 default: |
1269 SkASSERT(0); | 1267 SkASSERT(0); |
1270 return false; | 1268 return false; |
1271 } | 1269 } |
1272 return true; // no error | 1270 return true; // no error |
1273 } | 1271 } |
1274 | 1272 |
1275 #ifdef SK_DEBUG | 1273 #ifdef SK_DEBUG |
| 1274 #if defined(SK_SUPPORT_UNITTEST) |
1276 | 1275 |
1277 #define testInt(expression) { #expression, SkOperand2::kS32, expression, 0, NULL
} | 1276 #define testInt(expression) { #expression, SkOperand2::kS32, expression, 0, NULL
} |
1278 #ifdef SK_SCALAR_IS_FLOAT | 1277 #ifdef SK_SCALAR_IS_FLOAT |
1279 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (float) (e
xpression), NULL } | 1278 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (float) (e
xpression), NULL } |
1280 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, fmo
df((float) exp1, (float) exp2), NULL } | 1279 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, fmo
df((float) exp1, (float) exp2), NULL } |
1281 #else | 1280 #else |
1282 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (int) ((ex
pression) * 65536.0f), NULL } | 1281 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (int) ((ex
pression) * 65536.0f), NULL } |
1283 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, (in
t) (fmod(exp1, exp2) * 65536.0f), NULL } | 1282 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, (in
t) (fmod(exp1, exp2) * 65536.0f), NULL } |
1284 #endif | 1283 #endif |
1285 #define testTrue(expression) { #expression, SkOperand2::kS32, 1, 0, NULL } | 1284 #define testTrue(expression) { #expression, SkOperand2::kS32, 1, 0, NULL } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 testInt((1&&0)||3), | 1467 testInt((1&&0)||3), |
1469 testInt((1&&0)||0), | 1468 testInt((1&&0)||0), |
1470 testInt(1||(0&&3)), | 1469 testInt(1||(0&&3)), |
1471 testInt(0||(0&&3)), | 1470 testInt(0||(0&&3)), |
1472 testInt(0||(1&&3)), | 1471 testInt(0||(1&&3)), |
1473 testInt(0&&1?2:3) | 1472 testInt(0&&1?2:3) |
1474 , { "123.5", SkOperand2::kScalar, 0, SkIntToScalar(123) + SK_Scalar1/2, N
ULL } | 1473 , { "123.5", SkOperand2::kScalar, 0, SkIntToScalar(123) + SK_Scalar1/2, N
ULL } |
1475 }; | 1474 }; |
1476 | 1475 |
1477 #define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests) | 1476 #define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests) |
| 1477 #endif // SK_SUPPORT_UNITTEST |
1478 | 1478 |
1479 void SkScriptEngine2::UnitTest() { | 1479 void SkScriptEngine2::UnitTest() { |
1480 #if defined(SK_SUPPORT_UNITTEST) | 1480 #if defined(SK_SUPPORT_UNITTEST) |
1481 ValidateDecompileTable(); | 1481 ValidateDecompileTable(); |
1482 for (int index = 0; index < SkScriptNAnswer_testCount; index++) { | 1482 for (int index = 0; index < SkScriptNAnswer_testCount; index++) { |
1483 SkScriptEngine2 engine(scriptTests[index].fType); | 1483 SkScriptEngine2 engine(scriptTests[index].fType); |
1484 SkScriptValue2 value; | 1484 SkScriptValue2 value; |
1485 const char* script = scriptTests[index].fScript; | 1485 const char* script = scriptTests[index].fScript; |
1486 const char* scriptPtr = script; | 1486 const char* scriptPtr = script; |
1487 SkASSERT(engine.evaluateScript(&scriptPtr, &value) == true); | 1487 SkASSERT(engine.evaluateScript(&scriptPtr, &value) == true); |
(...skipping 11 matching lines...) Expand all Loading... |
1499 SkDEBUGF(("script '%s' == value %g != expected answer %g\n",
script, value.fOperand.fScalar / (1.0f * SK_Scalar1), scriptTests[index].fScala
rAnswer / (1.0f * SK_Scalar1))); | 1499 SkDEBUGF(("script '%s' == value %g != expected answer %g\n",
script, value.fOperand.fScalar / (1.0f * SK_Scalar1), scriptTests[index].fScala
rAnswer / (1.0f * SK_Scalar1))); |
1500 SkASSERT(error < SK_Scalar1 / 10000); | 1500 SkASSERT(error < SK_Scalar1 / 10000); |
1501 break; | 1501 break; |
1502 case SkOperand2::kString: | 1502 case SkOperand2::kString: |
1503 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri
ngAnswer)); | 1503 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri
ngAnswer)); |
1504 break; | 1504 break; |
1505 default: | 1505 default: |
1506 SkASSERT(0); | 1506 SkASSERT(0); |
1507 } | 1507 } |
1508 } | 1508 } |
1509 #endif | 1509 #endif // SK_SUPPORT_UNITTEST |
1510 } | 1510 } |
1511 #endif | 1511 #endif // SK_DEBUG |
| 1512 |
OLD | NEW |