| 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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 bool success = functionParams(scriptPtr, ¶ms); | 808 bool success = functionParams(scriptPtr, ¶ms); |
| 809 if (success == false) | 809 if (success == false) |
| 810 goto done; | 810 goto done; |
| 811 { | 811 { |
| 812 for (SkScriptCallBack** callBack = fCallBackArray.begin(); callBack < fC
allBackArray.end(); callBack++) { | 812 for (SkScriptCallBack** callBack = fCallBackArray.begin(); callBack < fC
allBackArray.end(); callBack++) { |
| 813 if ((*callBack)->getType() != SkScriptCallBack::kFunction) | 813 if ((*callBack)->getType() != SkScriptCallBack::kFunction) |
| 814 continue; | 814 continue; |
| 815 SkScriptValue2 callbackResult; | 815 SkScriptValue2 callbackResult; |
| 816 success = (*callBack)->getReference(functionName, functionNameLen, &
callbackResult); | 816 success = (*callBack)->getReference(functionName, functionNameLen, &
callbackResult); |
| 817 if (success) { | 817 if (success) { |
| 818 callbackResult.fType = (*callBack)->getReturnType(callbackResult
.fOperand.fReference, NULL); | 818 callbackResult.fType = (*callBack)->getReturnType(callbackResult
.fOperand.fReference, nullptr); |
| 819 callbackResult.fIsConstant = SkScriptValue2::kVariable; | 819 callbackResult.fIsConstant = SkScriptValue2::kVariable; |
| 820 fValueStack.push(callbackResult); | 820 fValueStack.push(callbackResult); |
| 821 goto done; | 821 goto done; |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 return false; | 825 return false; |
| 826 done: | 826 done: |
| 827 fOpStack.pop(); | 827 fOpStack.pop(); |
| 828 return success; | 828 return success; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 } | 870 } |
| 871 | 871 |
| 872 bool SkScriptEngine2::handleProperty() { | 872 bool SkScriptEngine2::handleProperty() { |
| 873 bool success = true; | 873 bool success = true; |
| 874 for (SkScriptCallBack** callBack = fCallBackArray.begin(); callBack < fCallB
ackArray.end(); callBack++) { | 874 for (SkScriptCallBack** callBack = fCallBackArray.begin(); callBack < fCallB
ackArray.end(); callBack++) { |
| 875 if ((*callBack)->getType() != SkScriptCallBack::kProperty) | 875 if ((*callBack)->getType() != SkScriptCallBack::kProperty) |
| 876 continue; | 876 continue; |
| 877 SkScriptValue2 callbackResult; | 877 SkScriptValue2 callbackResult; |
| 878 success = (*callBack)->getReference(fToken, fTokenLength, &callbackResul
t); | 878 success = (*callBack)->getReference(fToken, fTokenLength, &callbackResul
t); |
| 879 if (success) { | 879 if (success) { |
| 880 if (callbackResult.fType == SkOperand2::kString && callbackResult.fO
perand.fString == NULL) { | 880 if (callbackResult.fType == SkOperand2::kString && callbackResult.fO
perand.fString == nullptr) { |
| 881 callbackResult.fOperand.fString = new SkString(fToken, fTokenLen
gth); | 881 callbackResult.fOperand.fString = new SkString(fToken, fTokenLen
gth); |
| 882 track(callbackResult.fOperand.fString); | 882 track(callbackResult.fOperand.fString); |
| 883 } | 883 } |
| 884 callbackResult.fIsConstant = SkScriptValue2::kVariable; | 884 callbackResult.fIsConstant = SkScriptValue2::kVariable; |
| 885 fValueStack.push(callbackResult); | 885 fValueStack.push(callbackResult); |
| 886 goto done; | 886 goto done; |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 done: | 889 done: |
| 890 fTokenLength = 0; | 890 fTokenLength = 0; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 if (type == toType) | 1196 if (type == toType) |
| 1197 return true; | 1197 return true; |
| 1198 SkOperand2& operand = value->fOperand; | 1198 SkOperand2& operand = value->fOperand; |
| 1199 bool success = true; | 1199 bool success = true; |
| 1200 switch (toType) { | 1200 switch (toType) { |
| 1201 case SkOperand2::kS32: | 1201 case SkOperand2::kS32: |
| 1202 if (type == SkOperand2::kScalar) | 1202 if (type == SkOperand2::kScalar) |
| 1203 operand.fS32 = SkScalarFloorToInt(operand.fScalar); | 1203 operand.fS32 = SkScalarFloorToInt(operand.fScalar); |
| 1204 else { | 1204 else { |
| 1205 SkASSERT(type == SkOperand2::kString); | 1205 SkASSERT(type == SkOperand2::kString); |
| 1206 success = SkParse::FindS32(operand.fString->c_str(), &operand.fS
32) != NULL; | 1206 success = SkParse::FindS32(operand.fString->c_str(), &operand.fS
32) != nullptr; |
| 1207 } | 1207 } |
| 1208 break; | 1208 break; |
| 1209 case SkOperand2::kScalar: | 1209 case SkOperand2::kScalar: |
| 1210 if (type == SkOperand2::kS32) | 1210 if (type == SkOperand2::kS32) |
| 1211 operand.fScalar = IntToScalar(operand.fS32); | 1211 operand.fScalar = IntToScalar(operand.fS32); |
| 1212 else { | 1212 else { |
| 1213 SkASSERT(type == SkOperand2::kString); | 1213 SkASSERT(type == SkOperand2::kString); |
| 1214 success = SkParse::FindScalar(operand.fString->c_str(), &operand
.fScalar) != NULL; | 1214 success = SkParse::FindScalar(operand.fString->c_str(), &operand
.fScalar) != nullptr; |
| 1215 } | 1215 } |
| 1216 break; | 1216 break; |
| 1217 case SkOperand2::kString: { | 1217 case SkOperand2::kString: { |
| 1218 SkString* strPtr = new SkString(); | 1218 SkString* strPtr = new SkString(); |
| 1219 SkASSERT(engine); | 1219 SkASSERT(engine); |
| 1220 engine->track(strPtr); | 1220 engine->track(strPtr); |
| 1221 if (type == SkOperand2::kS32) | 1221 if (type == SkOperand2::kS32) |
| 1222 strPtr->appendS32(operand.fS32); | 1222 strPtr->appendS32(operand.fS32); |
| 1223 else { | 1223 else { |
| 1224 SkASSERT(type == SkOperand2::kScalar); | 1224 SkASSERT(type == SkOperand2::kScalar); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 default: | 1266 default: |
| 1267 SkASSERT(0); | 1267 SkASSERT(0); |
| 1268 return false; | 1268 return false; |
| 1269 } | 1269 } |
| 1270 return true; // no error | 1270 return true; // no error |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 #ifdef SK_DEBUG | 1273 #ifdef SK_DEBUG |
| 1274 #if defined(SK_SUPPORT_UNITTEST) | 1274 #if defined(SK_SUPPORT_UNITTEST) |
| 1275 | 1275 |
| 1276 #define testInt(expression) { #expression, SkOperand2::kS32, expression, 0, NULL
} | 1276 #define testInt(expression) { #expression, SkOperand2::kS32, expression, 0, null
ptr } |
| 1277 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (float) (e
xpression), NULL } | 1277 #define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (float) (e
xpression), nullptr } |
| 1278 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, fmo
df((float) exp1, (float) exp2), NULL } | 1278 #define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, fmo
df((float) exp1, (float) exp2), nullptr } |
| 1279 #define testTrue(expression) { #expression, SkOperand2::kS32, 1, 0, NULL } | 1279 #define testTrue(expression) { #expression, SkOperand2::kS32, 1, 0, nullptr } |
| 1280 #define testFalse(expression) { #expression, SkOperand2::kS32, 0, 0, NULL } | 1280 #define testFalse(expression) { #expression, SkOperand2::kS32, 0, 0, nullptr } |
| 1281 | 1281 |
| 1282 static const SkScriptNAnswer2 scriptTests[] = { | 1282 static const SkScriptNAnswer2 scriptTests[] = { |
| 1283 testInt(1||(0&&3)), | 1283 testInt(1||(0&&3)), |
| 1284 testScalar(- -5.5- -1.5), | 1284 testScalar(- -5.5- -1.5), |
| 1285 testScalar(1.0+5), | 1285 testScalar(1.0+5), |
| 1286 testInt((6+7)*8), | 1286 testInt((6+7)*8), |
| 1287 testInt(3*(4+5)), | 1287 testInt(3*(4+5)), |
| 1288 testScalar(1.0+2.0), | 1288 testScalar(1.0+2.0), |
| 1289 testScalar(3.0-1.0), | 1289 testScalar(3.0-1.0), |
| 1290 testScalar(6-1.0), | 1290 testScalar(6-1.0), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1301 testTrue(-9.*1==-4-5), | 1301 testTrue(-9.*1==-4-5), |
| 1302 testFalse(-9!=-9.0), | 1302 testFalse(-9!=-9.0), |
| 1303 testFalse(-9.!=-4.0-5), | 1303 testFalse(-9.!=-4.0-5), |
| 1304 testFalse(-9.*1!=-4-5), | 1304 testFalse(-9.*1!=-4-5), |
| 1305 testInt(0x123), | 1305 testInt(0x123), |
| 1306 testInt(0XABC), | 1306 testInt(0XABC), |
| 1307 testInt(0xdeadBEEF), | 1307 testInt(0xdeadBEEF), |
| 1308 { "'123'+\"456\"", SkOperand2::kString, 0, 0, "123456" }, | 1308 { "'123'+\"456\"", SkOperand2::kString, 0, 0, "123456" }, |
| 1309 { "123+\"456\"", SkOperand2::kString, 0, 0, "123456" }, | 1309 { "123+\"456\"", SkOperand2::kString, 0, 0, "123456" }, |
| 1310 { "'123'+456", SkOperand2::kString, 0, 0, "123456" }, | 1310 { "'123'+456", SkOperand2::kString, 0, 0, "123456" }, |
| 1311 { "'123'|\"456\"", SkOperand2::kS32, 123|456, 0, NULL }, | 1311 { "'123'|\"456\"", SkOperand2::kS32, 123|456, 0, nullptr }, |
| 1312 { "123|\"456\"", SkOperand2::kS32, 123|456, 0, NULL }, | 1312 { "123|\"456\"", SkOperand2::kS32, 123|456, 0, nullptr }, |
| 1313 { "'123'|456", SkOperand2::kS32, 123|456, 0, NULL }, | 1313 { "'123'|456", SkOperand2::kS32, 123|456, 0, nullptr }, |
| 1314 { "'2'<11", SkOperand2::kS32, 1, 0, NULL }, | 1314 { "'2'<11", SkOperand2::kS32, 1, 0, nullptr }, |
| 1315 { "2<'11'", SkOperand2::kS32, 1, 0, NULL }, | 1315 { "2<'11'", SkOperand2::kS32, 1, 0, nullptr }, |
| 1316 { "'2'<'11'", SkOperand2::kS32, 0, 0, NULL }, | 1316 { "'2'<'11'", SkOperand2::kS32, 0, 0, nullptr }, |
| 1317 testInt(123), | 1317 testInt(123), |
| 1318 testInt(-345), | 1318 testInt(-345), |
| 1319 testInt(+678), | 1319 testInt(+678), |
| 1320 testInt(1+2+3), | 1320 testInt(1+2+3), |
| 1321 testInt(3*4+5), | 1321 testInt(3*4+5), |
| 1322 testInt(6+7*8), | 1322 testInt(6+7*8), |
| 1323 testInt(-1-2-8/4), | 1323 testInt(-1-2-8/4), |
| 1324 testInt(-9%4), | 1324 testInt(-9%4), |
| 1325 testInt(9%-4), | 1325 testInt(9%-4), |
| 1326 testInt(-9%-4), | 1326 testInt(-9%-4), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 // logic | 1458 // logic |
| 1459 testInt(1?2:3), | 1459 testInt(1?2:3), |
| 1460 testInt(0?2:3), | 1460 testInt(0?2:3), |
| 1461 testInt((1&&2)||3), | 1461 testInt((1&&2)||3), |
| 1462 testInt((1&&0)||3), | 1462 testInt((1&&0)||3), |
| 1463 testInt((1&&0)||0), | 1463 testInt((1&&0)||0), |
| 1464 testInt(1||(0&&3)), | 1464 testInt(1||(0&&3)), |
| 1465 testInt(0||(0&&3)), | 1465 testInt(0||(0&&3)), |
| 1466 testInt(0||(1&&3)), | 1466 testInt(0||(1&&3)), |
| 1467 testInt(0&&1?2:3) | 1467 testInt(0&&1?2:3) |
| 1468 , { "123.5", SkOperand2::kScalar, 0, SkIntToScalar(123) + SK_Scalar1/2, N
ULL } | 1468 , { "123.5", SkOperand2::kScalar, 0, SkIntToScalar(123) + SK_Scalar1/2, n
ullptr } |
| 1469 }; | 1469 }; |
| 1470 | 1470 |
| 1471 #define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests) | 1471 #define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests) |
| 1472 #endif // SK_SUPPORT_UNITTEST | 1472 #endif // SK_SUPPORT_UNITTEST |
| 1473 | 1473 |
| 1474 void SkScriptEngine2::UnitTest() { | 1474 void SkScriptEngine2::UnitTest() { |
| 1475 #if defined(SK_SUPPORT_UNITTEST) | 1475 #if defined(SK_SUPPORT_UNITTEST) |
| 1476 ValidateDecompileTable(); | 1476 ValidateDecompileTable(); |
| 1477 for (size_t index = 0; index < SkScriptNAnswer_testCount; index++) { | 1477 for (size_t index = 0; index < SkScriptNAnswer_testCount; index++) { |
| 1478 SkScriptEngine2 engine(scriptTests[index].fType); | 1478 SkScriptEngine2 engine(scriptTests[index].fType); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1497 case SkOperand2::kString: | 1497 case SkOperand2::kString: |
| 1498 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri
ngAnswer)); | 1498 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri
ngAnswer)); |
| 1499 break; | 1499 break; |
| 1500 default: | 1500 default: |
| 1501 SkASSERT(0); | 1501 SkASSERT(0); |
| 1502 } | 1502 } |
| 1503 } | 1503 } |
| 1504 #endif // SK_SUPPORT_UNITTEST | 1504 #endif // SK_SUPPORT_UNITTEST |
| 1505 } | 1505 } |
| 1506 #endif // SK_DEBUG | 1506 #endif // SK_DEBUG |
| OLD | NEW |