OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 | 8 |
9 | 9 |
10 #include "SkScript.h" | 10 #include "SkScript.h" |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 fOpStack.pop(); | 1150 fOpStack.pop(); |
1151 else { | 1151 else { |
1152 SkOpType indexType; | 1152 SkOpType indexType; |
1153 fTypeStack.pop(&indexType); | 1153 fTypeStack.pop(&indexType); |
1154 if (indexType != kInt && indexType != kScalar) { | 1154 if (indexType != kInt && indexType != kScalar) { |
1155 fError = kExpectedNumberForArrayIndex; // (although, could p
ermit strings eventually) | 1155 fError = kExpectedNumberForArrayIndex; // (although, could p
ermit strings eventually) |
1156 return -1; | 1156 return -1; |
1157 } | 1157 } |
1158 SkOperand indexOperand; | 1158 SkOperand indexOperand; |
1159 fOperandStack.pop(&indexOperand); | 1159 fOperandStack.pop(&indexOperand); |
1160 int index = indexType == kScalar ? SkScalarFloor(indexOperand.fS
calar) : | 1160 int index = indexType == kScalar ? SkScalarFloorToInt(indexOpera
nd.fScalar) : |
1161 indexOperand.fS32; | 1161 indexOperand.fS32; |
1162 SkOpType arrayType; | 1162 SkOpType arrayType; |
1163 fTypeStack.pop(&arrayType); | 1163 fTypeStack.pop(&arrayType); |
1164 if ((unsigned)arrayType != (unsigned)kArray) { | 1164 if ((unsigned)arrayType != (unsigned)kArray) { |
1165 fError = kExpectedArray; | 1165 fError = kExpectedArray; |
1166 return -1; | 1166 return -1; |
1167 } | 1167 } |
1168 SkOperand arrayOperand; | 1168 SkOperand arrayOperand; |
1169 fOperandStack.pop(&arrayOperand); | 1169 fOperandStack.pop(&arrayOperand); |
1170 SkTypedArray* array = arrayOperand.fArray; | 1170 SkTypedArray* array = arrayOperand.fArray; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 if ((type1 & attributes->fLeftType) == 0 || type1 != type2) { | 1317 if ((type1 & attributes->fLeftType) == 0 || type1 != type2) { |
1318 if (type1 == kString) { | 1318 if (type1 == kString) { |
1319 const char* result = SkParse::FindScalar(operand1.fString->c_str
(), &operand1.fScalar); | 1319 const char* result = SkParse::FindScalar(operand1.fString->c_str
(), &operand1.fScalar); |
1320 if (result == NULL) { | 1320 if (result == NULL) { |
1321 fError = kExpectedNumber; | 1321 fError = kExpectedNumber; |
1322 return false; | 1322 return false; |
1323 } | 1323 } |
1324 type1 = kScalar; | 1324 type1 = kScalar; |
1325 } | 1325 } |
1326 if (type1 == kScalar && (attributes->fLeftType == kInt || type2 == k
Int)) { | 1326 if (type1 == kScalar && (attributes->fLeftType == kInt || type2 == k
Int)) { |
1327 operand1.fS32 = SkScalarFloor(operand1.fScalar); | 1327 operand1.fS32 = SkScalarFloorToInt(operand1.fScalar); |
1328 type1 = kInt; | 1328 type1 = kInt; |
1329 } | 1329 } |
1330 } | 1330 } |
1331 } | 1331 } |
1332 if ((type2 & attributes->fRightType) == 0 || type1 != type2) { | 1332 if ((type2 & attributes->fRightType) == 0 || type1 != type2) { |
1333 if (type2 == kString) { | 1333 if (type2 == kString) { |
1334 const char* result = SkParse::FindScalar(operand2.fString->c_str(),
&operand2.fScalar); | 1334 const char* result = SkParse::FindScalar(operand2.fString->c_str(),
&operand2.fScalar); |
1335 if (result == NULL) { | 1335 if (result == NULL) { |
1336 fError = kExpectedNumber; | 1336 fError = kExpectedNumber; |
1337 return false; | 1337 return false; |
1338 } | 1338 } |
1339 type2 = kScalar; | 1339 type2 = kScalar; |
1340 } | 1340 } |
1341 if (type2 == kScalar && (attributes->fRightType == kInt || type1 == kInt
)) { | 1341 if (type2 == kScalar && (attributes->fRightType == kInt || type1 == kInt
)) { |
1342 operand2.fS32 = SkScalarFloor(operand2.fScalar); | 1342 operand2.fS32 = SkScalarFloorToInt(operand2.fScalar); |
1343 type2 = kInt; | 1343 type2 = kInt; |
1344 } | 1344 } |
1345 } | 1345 } |
1346 if (type2 == kScalar) | 1346 if (type2 == kScalar) |
1347 op = (SkOp) (op + 1); | 1347 op = (SkOp) (op + 1); |
1348 else if (type2 == kString) | 1348 else if (type2 == kString) |
1349 op = (SkOp) (op + 2); | 1349 op = (SkOp) (op + 2); |
1350 switch(op) { | 1350 switch(op) { |
1351 case kAddInt: | 1351 case kAddInt: |
1352 operand2.fS32 += operand1.fS32; | 1352 operand2.fS32 += operand1.fS32; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 SkDisplayTypes type = value->fType; | 1496 SkDisplayTypes type = value->fType; |
1497 if (type == toType) | 1497 if (type == toType) |
1498 return true; | 1498 return true; |
1499 SkOperand& operand = value->fOperand; | 1499 SkOperand& operand = value->fOperand; |
1500 bool success = true; | 1500 bool success = true; |
1501 switch (toType) { | 1501 switch (toType) { |
1502 case SkType_Int: | 1502 case SkType_Int: |
1503 if (type == SkType_Boolean) | 1503 if (type == SkType_Boolean) |
1504 break; | 1504 break; |
1505 if (type == SkType_Float) | 1505 if (type == SkType_Float) |
1506 operand.fS32 = SkScalarFloor(operand.fScalar); | 1506 operand.fS32 = SkScalarFloorToInt(operand.fScalar); |
1507 else { | 1507 else { |
1508 if (type != SkType_String) { | 1508 if (type != SkType_String) { |
1509 success = false; | 1509 success = false; |
1510 break; // error | 1510 break; // error |
1511 } | 1511 } |
1512 success = SkParse::FindS32(operand.fString->c_str(), &operand.fS
32) != NULL; | 1512 success = SkParse::FindS32(operand.fString->c_str(), &operand.fS
32) != NULL; |
1513 } | 1513 } |
1514 break; | 1514 break; |
1515 case SkType_Float: | 1515 case SkType_Float: |
1516 if (type == SkType_Int) { | 1516 if (type == SkType_Int) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 break; | 1881 break; |
1882 case SkType_String: | 1882 case SkType_String: |
1883 SkASSERT(strcmp(value.fOperand.fString->c_str(), scriptTests[ind
ex].fStringAnswer) == 0); | 1883 SkASSERT(strcmp(value.fOperand.fString->c_str(), scriptTests[ind
ex].fStringAnswer) == 0); |
1884 break; | 1884 break; |
1885 default: | 1885 default: |
1886 SkASSERT(0); | 1886 SkASSERT(0); |
1887 } | 1887 } |
1888 } | 1888 } |
1889 } | 1889 } |
1890 #endif | 1890 #endif |
OLD | NEW |