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 4225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4236 } | 4236 } |
4237 } | 4237 } |
4238 | 4238 |
4239 | 4239 |
4240 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4240 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
4241 // CallRuntime :: | 4241 // CallRuntime :: |
4242 // '%' Identifier Arguments | 4242 // '%' Identifier Arguments |
4243 | 4243 |
4244 Expect(Token::MOD, CHECK_OK); | 4244 Expect(Token::MOD, CHECK_OK); |
4245 Handle<String> name = ParseIdentifier(CHECK_OK); | 4245 Handle<String> name = ParseIdentifier(CHECK_OK); |
4246 Runtime::Function* function = | |
4247 Runtime::FunctionForName(scanner_.literal()); | |
4248 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 4246 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
4249 if (function == NULL && extension_ != NULL) { | 4247 if (is_pre_parsing_) return NULL; |
| 4248 |
| 4249 if (extension_ != NULL) { |
4250 // The extension structures are only accessible while parsing the | 4250 // The extension structures are only accessible while parsing the |
4251 // very first time not when reparsing because of lazy compilation. | 4251 // very first time not when reparsing because of lazy compilation. |
4252 top_scope_->ForceEagerCompilation(); | 4252 top_scope_->ForceEagerCompilation(); |
4253 } | 4253 } |
4254 | 4254 |
4255 // Check for built-in macros. | 4255 Runtime::Function* function = Runtime::FunctionForSymbol(name); |
4256 if (!is_pre_parsing_) { | 4256 |
4257 if (function == Runtime::FunctionForId(Runtime::kIS_VAR)) { | 4257 // Check for built-in IS_VAR macro. |
4258 // %IS_VAR(x) | 4258 if (function != NULL && |
4259 // evaluates to x if x is a variable, | 4259 function->intrinsic_type == Runtime::RUNTIME && |
4260 // leads to a parse error otherwise | 4260 function->function_id == Runtime::kIS_VAR) { |
4261 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { | 4261 // %IS_VAR(x) evaluates to x if x is a variable, |
4262 return args->at(0); | 4262 // leads to a parse error otherwise. Could be implemented as an |
4263 } | 4263 // inline function %_IS_VAR(x) to eliminate this special case. |
| 4264 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { |
| 4265 return args->at(0); |
| 4266 } else { |
| 4267 ReportMessage("unable_to_parse", Vector<const char*>::empty()); |
4264 *ok = false; | 4268 *ok = false; |
4265 // Check here for other macros. | |
4266 // } else if (function == Runtime::FunctionForId(Runtime::kIS_VAR)) { | |
4267 // ... | |
4268 } | |
4269 | |
4270 if (!*ok) { | |
4271 // We found a macro but it failed. | |
4272 ReportMessage("unable_to_parse", Vector<const char*>::empty()); | |
4273 return NULL; | 4269 return NULL; |
4274 } | 4270 } |
4275 } | 4271 } |
4276 | 4272 |
4277 // Check that the expected number arguments are passed to runtime functions. | 4273 // Check that the expected number of arguments are being passed. |
4278 if (!is_pre_parsing_) { | 4274 if (function != NULL && |
4279 if (function != NULL | 4275 function->nargs != -1 && |
4280 && function->nargs != -1 | 4276 function->nargs != args->length()) { |
4281 && function->nargs != args->length()) { | 4277 ReportMessage("illegal_access", Vector<const char*>::empty()); |
4282 ReportMessage("illegal_access", Vector<const char*>::empty()); | 4278 *ok = false; |
4283 *ok = false; | 4279 return NULL; |
4284 return NULL; | |
4285 } else if (function == NULL && !name.is_null()) { | |
4286 // If this is not a runtime function implemented in C++ it might be an | |
4287 // inlined runtime function. | |
4288 int argc = CodeGenerator::InlineRuntimeCallArgumentsCount(name); | |
4289 if (argc != -1 && argc != args->length()) { | |
4290 ReportMessage("illegal_access", Vector<const char*>::empty()); | |
4291 *ok = false; | |
4292 return NULL; | |
4293 } | |
4294 } | |
4295 } | 4280 } |
4296 | 4281 |
4297 // Otherwise we have a valid runtime call. | 4282 // We have a valid intrinsics call or a call to a builtin. |
4298 return NEW(CallRuntime(name, function, args)); | 4283 return NEW(CallRuntime(name, function, args)); |
4299 } | 4284 } |
4300 | 4285 |
4301 | 4286 |
4302 void Parser::Consume(Token::Value token) { | 4287 void Parser::Consume(Token::Value token) { |
4303 Token::Value next = Next(); | 4288 Token::Value next = Next(); |
4304 USE(next); | 4289 USE(next); |
4305 USE(token); | 4290 USE(token); |
4306 ASSERT(next == token); | 4291 ASSERT(next == token); |
4307 } | 4292 } |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5585 parser.ParseLazy(script_source, name, | 5570 parser.ParseLazy(script_source, name, |
5586 start_position, end_position, is_expression); | 5571 start_position, end_position, is_expression); |
5587 return result; | 5572 return result; |
5588 } | 5573 } |
5589 | 5574 |
5590 | 5575 |
5591 #undef NEW | 5576 #undef NEW |
5592 | 5577 |
5593 | 5578 |
5594 } } // namespace v8::internal | 5579 } } // namespace v8::internal |
OLD | NEW |