| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 if (parsed_function->has_finally_return_temp_var()) { | 1099 if (parsed_function->has_finally_return_temp_var()) { |
| 1100 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); | 1100 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); |
| 1101 } | 1101 } |
| 1102 // The instantiator is not required in a static expression. | 1102 // The instantiator is not required in a static expression. |
| 1103 ASSERT(!parser.IsInstantiatorRequired()); | 1103 ASSERT(!parser.IsInstantiatorRequired()); |
| 1104 | 1104 |
| 1105 return parsed_function; | 1105 return parsed_function; |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 | 1108 |
| 1109 RawObject* Parser::ParseFunctionFromSource(const Class& owning_class, |
| 1110 const String& source) { |
| 1111 Isolate* isolate = Isolate::Current(); |
| 1112 StackZone zone(isolate); |
| 1113 LongJumpScope jump; |
| 1114 if (setjmp(*jump.Set()) == 0) { |
| 1115 const String& uri = String::Handle(Symbols::New("dynamically-added")); |
| 1116 const Script& script = Script::Handle( |
| 1117 Script::New(uri, source, RawScript::kSourceTag)); |
| 1118 const Library& owning_library = Library::Handle(owning_class.library()); |
| 1119 const String& private_key = String::Handle(owning_library.private_key()); |
| 1120 script.Tokenize(private_key); |
| 1121 const intptr_t token_pos = 0; |
| 1122 Parser parser(script, owning_library, token_pos); |
| 1123 parser.is_top_level_ = true; |
| 1124 parser.set_current_class(owning_class); |
| 1125 const String& class_name = String::Handle(owning_class.Name()); |
| 1126 ClassDesc members(owning_class, class_name, false, token_pos); |
| 1127 const intptr_t metadata_pos = parser.SkipMetadata(); |
| 1128 parser.ParseClassMemberDefinition(&members, metadata_pos); |
| 1129 ASSERT(members.functions().Length() == 1); |
| 1130 const Function& func = |
| 1131 Function::ZoneHandle(Function::RawCast(members.functions().At(0))); |
| 1132 func.set_eval_script(script); |
| 1133 ParsedFunction* parsed_function = new ParsedFunction(isolate, func); |
| 1134 Parser::ParseFunction(parsed_function); |
| 1135 return func.raw(); |
| 1136 } else { |
| 1137 const Error& error = Error::Handle(isolate->object_store()->sticky_error()); |
| 1138 isolate->object_store()->clear_sticky_error(); |
| 1139 return error.raw(); |
| 1140 } |
| 1141 UNREACHABLE(); |
| 1142 } |
| 1143 |
| 1144 |
| 1109 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) { | 1145 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) { |
| 1110 TRACE_PARSER("ParseStaticFinalGetter"); | 1146 TRACE_PARSER("ParseStaticFinalGetter"); |
| 1111 ParamList params; | 1147 ParamList params; |
| 1112 ASSERT(func.num_fixed_parameters() == 0); // static. | 1148 ASSERT(func.num_fixed_parameters() == 0); // static. |
| 1113 ASSERT(!func.HasOptionalParameters()); | 1149 ASSERT(!func.HasOptionalParameters()); |
| 1114 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); | 1150 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); |
| 1115 | 1151 |
| 1116 // Build local scope for function and populate with the formal parameters. | 1152 // Build local scope for function and populate with the formal parameters. |
| 1117 OpenFunctionBlock(func); | 1153 OpenFunctionBlock(func); |
| 1118 AddFormalParamsToScope(¶ms, current_block_->scope); | 1154 AddFormalParamsToScope(¶ms, current_block_->scope); |
| (...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3294 ASSERT(CurrentToken() == Token::kPERIOD); // We checked above. | 3330 ASSERT(CurrentToken() == Token::kPERIOD); // We checked above. |
| 3295 ConsumeToken(); | 3331 ConsumeToken(); |
| 3296 return prefix.raw(); | 3332 return prefix.raw(); |
| 3297 } | 3333 } |
| 3298 | 3334 |
| 3299 | 3335 |
| 3300 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { | 3336 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { |
| 3301 TRACE_PARSER("ParseMethodOrConstructor"); | 3337 TRACE_PARSER("ParseMethodOrConstructor"); |
| 3302 ASSERT(CurrentToken() == Token::kLPAREN || method->IsGetter()); | 3338 ASSERT(CurrentToken() == Token::kLPAREN || method->IsGetter()); |
| 3303 ASSERT(method->type != NULL); | 3339 ASSERT(method->type != NULL); |
| 3304 ASSERT(method->name_pos > 0); | 3340 ASSERT(is_top_level_ || method->name_pos > 0); |
| 3305 ASSERT(current_member_ == method); | 3341 ASSERT(current_member_ == method); |
| 3306 | 3342 |
| 3307 if (method->has_var) { | 3343 if (method->has_var) { |
| 3308 ReportError(method->name_pos, "keyword var not allowed for methods"); | 3344 ReportError(method->name_pos, "keyword var not allowed for methods"); |
| 3309 } | 3345 } |
| 3310 if (method->has_final) { | 3346 if (method->has_final) { |
| 3311 ReportError(method->name_pos, "'final' not allowed for methods"); | 3347 ReportError(method->name_pos, "'final' not allowed for methods"); |
| 3312 } | 3348 } |
| 3313 if (method->has_abstract && method->has_static) { | 3349 if (method->has_abstract && method->has_static) { |
| 3314 ReportError(method->name_pos, | 3350 ReportError(method->name_pos, |
| (...skipping 8851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12166 void Parser::SkipQualIdent() { | 12202 void Parser::SkipQualIdent() { |
| 12167 ASSERT(IsIdentifier()); | 12203 ASSERT(IsIdentifier()); |
| 12168 ConsumeToken(); | 12204 ConsumeToken(); |
| 12169 if (CurrentToken() == Token::kPERIOD) { | 12205 if (CurrentToken() == Token::kPERIOD) { |
| 12170 ConsumeToken(); // Consume the kPERIOD token. | 12206 ConsumeToken(); // Consume the kPERIOD token. |
| 12171 ExpectIdentifier("identifier expected after '.'"); | 12207 ExpectIdentifier("identifier expected after '.'"); |
| 12172 } | 12208 } |
| 12173 } | 12209 } |
| 12174 | 12210 |
| 12175 } // namespace dart | 12211 } // namespace dart |
| OLD | NEW |