OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void TargetCollector::AddTarget(BreakTarget* target) { | 165 void TargetCollector::AddTarget(BreakTarget* target) { |
166 // Add the label to the collector, but discard duplicates. | 166 // Add the label to the collector, but discard duplicates. |
167 int length = targets_->length(); | 167 int length = targets_->length(); |
168 for (int i = 0; i < length; i++) { | 168 for (int i = 0; i < length; i++) { |
169 if (targets_->at(i) == target) return; | 169 if (targets_->at(i) == target) return; |
170 } | 170 } |
171 targets_->Add(target); | 171 targets_->Add(target); |
172 } | 172 } |
173 | 173 |
174 | 174 |
| 175 bool Expression::GuaranteedSmiResult() { |
| 176 BinaryOperation* node = AsBinaryOperation(); |
| 177 if (node == NULL) return false; |
| 178 Token::Value op = node->op(); |
| 179 switch (op) { |
| 180 case Token::COMMA: |
| 181 case Token::OR: |
| 182 case Token::AND: |
| 183 case Token::ADD: |
| 184 case Token::SUB: |
| 185 case Token::MUL: |
| 186 case Token::DIV: |
| 187 case Token::MOD: |
| 188 case Token::BIT_XOR: |
| 189 case Token::SHL: |
| 190 return false; |
| 191 break; |
| 192 case Token::BIT_OR: |
| 193 case Token::BIT_AND: { |
| 194 Literal* left = node->left()->AsLiteral(); |
| 195 Literal* right = node->right()->AsLiteral(); |
| 196 if (left != NULL && left->handle()->IsSmi()) { |
| 197 int value = Smi::cast(*left->handle())->value(); |
| 198 if (op == Token::BIT_OR && ((value & 0xc0000000) == 0xc0000000)) { |
| 199 // Result of bitwise or is always a negative Smi. |
| 200 return true; |
| 201 } |
| 202 if (op == Token::BIT_AND && ((value & 0xc0000000) == 0)) { |
| 203 // Result of bitwise and is always a positive Smi. |
| 204 return true; |
| 205 } |
| 206 } |
| 207 if (right != NULL && right->handle()->IsSmi()) { |
| 208 int value = Smi::cast(*right->handle())->value(); |
| 209 if (op == Token::BIT_OR && ((value & 0xc0000000) == 0xc0000000)) { |
| 210 // Result of bitwise or is always a negative Smi. |
| 211 return true; |
| 212 } |
| 213 if (op == Token::BIT_AND && ((value & 0xc0000000) == 0)) { |
| 214 // Result of bitwise and is always a positive Smi. |
| 215 return true; |
| 216 } |
| 217 } |
| 218 return false; |
| 219 break; |
| 220 } |
| 221 case Token::SAR: |
| 222 case Token::SHR: { |
| 223 Literal* right = node->right()->AsLiteral(); |
| 224 if (right != NULL && right->handle()->IsSmi()) { |
| 225 int value = Smi::cast(*right->handle())->value(); |
| 226 if ((value & 0x1F) > 1 || |
| 227 (op == Token::SAR && (value & 0x1F) == 1)) { |
| 228 return true; |
| 229 } |
| 230 } |
| 231 return false; |
| 232 break; |
| 233 } |
| 234 default: |
| 235 UNREACHABLE(); |
| 236 break; |
| 237 } |
| 238 return false; |
| 239 } |
| 240 |
175 // ---------------------------------------------------------------------------- | 241 // ---------------------------------------------------------------------------- |
176 // Implementation of AstVisitor | 242 // Implementation of AstVisitor |
177 | 243 |
178 | 244 |
179 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 245 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
180 for (int i = 0; i < declarations->length(); i++) { | 246 for (int i = 0; i < declarations->length(); i++) { |
181 Visit(declarations->at(i)); | 247 Visit(declarations->at(i)); |
182 } | 248 } |
183 } | 249 } |
184 | 250 |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 SetStackOverflow(); | 1237 SetStackOverflow(); |
1172 } | 1238 } |
1173 | 1239 |
1174 | 1240 |
1175 void CopyAstVisitor::VisitDeclaration(Declaration* decl) { | 1241 void CopyAstVisitor::VisitDeclaration(Declaration* decl) { |
1176 UNREACHABLE(); | 1242 UNREACHABLE(); |
1177 } | 1243 } |
1178 | 1244 |
1179 | 1245 |
1180 } } // namespace v8::internal | 1246 } } // namespace v8::internal |
OLD | NEW |