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 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 Parser parser(script, lib, cls.token_pos()); | 788 Parser parser(script, lib, cls.token_pos()); |
789 parser.ParseEnumDefinition(cls); | 789 parser.ParseEnumDefinition(cls); |
790 } | 790 } |
791 } | 791 } |
792 | 792 |
793 | 793 |
794 RawObject* Parser::ParseFunctionParameters(const Function& func) { | 794 RawObject* Parser::ParseFunctionParameters(const Function& func) { |
795 ASSERT(!func.IsNull()); | 795 ASSERT(!func.IsNull()); |
796 Thread* thread = Thread::Current(); | 796 Thread* thread = Thread::Current(); |
797 Isolate* isolate = thread->isolate(); | 797 Isolate* isolate = thread->isolate(); |
798 StackZone stack_zone(isolate); | 798 StackZone stack_zone(thread); |
799 Zone* zone = stack_zone.GetZone(); | 799 Zone* zone = stack_zone.GetZone(); |
800 LongJumpScope jump; | 800 LongJumpScope jump; |
801 if (setjmp(*jump.Set()) == 0) { | 801 if (setjmp(*jump.Set()) == 0) { |
802 const Script& script = Script::Handle(zone, func.script()); | 802 const Script& script = Script::Handle(zone, func.script()); |
803 const Class& owner = Class::Handle(zone, func.Owner()); | 803 const Class& owner = Class::Handle(zone, func.Owner()); |
804 ASSERT(!owner.IsNull()); | 804 ASSERT(!owner.IsNull()); |
805 ParsedFunction* parsed_function = new ParsedFunction( | 805 ParsedFunction* parsed_function = new ParsedFunction( |
806 thread, Function::ZoneHandle(zone, func.raw())); | 806 thread, Function::ZoneHandle(zone, func.raw())); |
807 Parser parser(script, parsed_function, func.token_pos()); | 807 Parser parser(script, parsed_function, func.token_pos()); |
808 parser.SkipFunctionPreamble(); | 808 parser.SkipFunctionPreamble(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 971 } |
972 } | 972 } |
973 | 973 |
974 parsed_function->set_default_parameter_values(default_parameter_values); | 974 parsed_function->set_default_parameter_values(default_parameter_values); |
975 } | 975 } |
976 | 976 |
977 | 977 |
978 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { | 978 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { |
979 Thread* thread = Thread::Current(); | 979 Thread* thread = Thread::Current(); |
980 Isolate* isolate = thread->isolate(); | 980 Isolate* isolate = thread->isolate(); |
981 StackZone stack_zone(isolate); | 981 StackZone stack_zone(thread); |
982 Zone* zone = stack_zone.GetZone(); | 982 Zone* zone = stack_zone.GetZone(); |
983 LongJumpScope jump; | 983 LongJumpScope jump; |
984 if (setjmp(*jump.Set()) == 0) { | 984 if (setjmp(*jump.Set()) == 0) { |
985 const Script& script = Script::Handle(zone, cls.script()); | 985 const Script& script = Script::Handle(zone, cls.script()); |
986 // Parsing metadata can involve following paths in the parser that are | 986 // Parsing metadata can involve following paths in the parser that are |
987 // normally used for expressions and assume current_function is non-null, | 987 // normally used for expressions and assume current_function is non-null, |
988 // so we create a fake function to use as the current_function rather than | 988 // so we create a fake function to use as the current_function rather than |
989 // scattering special cases throughout the parser. | 989 // scattering special cases throughout the parser. |
990 const Function& fake_function = Function::ZoneHandle(zone, Function::New( | 990 const Function& fake_function = Function::ZoneHandle(zone, Function::New( |
991 Symbols::At(), | 991 Symbols::At(), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 ASSERT(!parser.IsInstantiatorRequired()); | 1159 ASSERT(!parser.IsInstantiatorRequired()); |
1160 | 1160 |
1161 return parsed_function; | 1161 return parsed_function; |
1162 } | 1162 } |
1163 | 1163 |
1164 | 1164 |
1165 RawObject* Parser::ParseFunctionFromSource(const Class& owning_class, | 1165 RawObject* Parser::ParseFunctionFromSource(const Class& owning_class, |
1166 const String& source) { | 1166 const String& source) { |
1167 Thread* thread = Thread::Current(); | 1167 Thread* thread = Thread::Current(); |
1168 Isolate* isolate = thread->isolate(); | 1168 Isolate* isolate = thread->isolate(); |
1169 StackZone stack_zone(isolate); | 1169 StackZone stack_zone(thread); |
1170 LongJumpScope jump; | 1170 LongJumpScope jump; |
1171 if (setjmp(*jump.Set()) == 0) { | 1171 if (setjmp(*jump.Set()) == 0) { |
1172 const String& uri = String::Handle(Symbols::New("dynamically-added")); | 1172 const String& uri = String::Handle(Symbols::New("dynamically-added")); |
1173 const Script& script = Script::Handle( | 1173 const Script& script = Script::Handle( |
1174 Script::New(uri, source, RawScript::kSourceTag)); | 1174 Script::New(uri, source, RawScript::kSourceTag)); |
1175 const Library& owning_library = Library::Handle(owning_class.library()); | 1175 const Library& owning_library = Library::Handle(owning_class.library()); |
1176 const String& private_key = String::Handle(owning_library.private_key()); | 1176 const String& private_key = String::Handle(owning_library.private_key()); |
1177 script.Tokenize(private_key); | 1177 script.Tokenize(private_key); |
1178 const intptr_t token_pos = 0; | 1178 const intptr_t token_pos = 0; |
1179 Parser parser(script, owning_library, token_pos); | 1179 Parser parser(script, owning_library, token_pos); |
(...skipping 10848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12028 return false; | 12028 return false; |
12029 } | 12029 } |
12030 | 12030 |
12031 | 12031 |
12032 // Resolve an identifier by checking the global scope of the current | 12032 // Resolve an identifier by checking the global scope of the current |
12033 // library. If not found in the current library, then look in the scopes | 12033 // library. If not found in the current library, then look in the scopes |
12034 // of all libraries that are imported without a library prefix. | 12034 // of all libraries that are imported without a library prefix. |
12035 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, | 12035 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, |
12036 const String& ident) { | 12036 const String& ident) { |
12037 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); | 12037 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); |
12038 HANDLESCOPE(I); | 12038 HANDLESCOPE(thread()); |
12039 const Object& obj = Object::Handle(Z, library_.ResolveName(ident)); | 12039 const Object& obj = Object::Handle(Z, library_.ResolveName(ident)); |
12040 if (obj.IsClass()) { | 12040 if (obj.IsClass()) { |
12041 const Class& cls = Class::Cast(obj); | 12041 const Class& cls = Class::Cast(obj); |
12042 return new(Z) PrimaryNode(ident_pos, Class::ZoneHandle(Z, cls.raw())); | 12042 return new(Z) PrimaryNode(ident_pos, Class::ZoneHandle(Z, cls.raw())); |
12043 } else if (obj.IsField()) { | 12043 } else if (obj.IsField()) { |
12044 const Field& field = Field::Cast(obj); | 12044 const Field& field = Field::Cast(obj); |
12045 ASSERT(field.is_static()); | 12045 ASSERT(field.is_static()); |
12046 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos); | 12046 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos); |
12047 if (get_field->IsStaticGetterNode()) { | 12047 if (get_field->IsStaticGetterNode()) { |
12048 get_field->AsStaticGetterNode()->set_owner(library_); | 12048 get_field->AsStaticGetterNode()->set_owner(library_); |
(...skipping 26 matching lines...) Expand all Loading... |
12075 } | 12075 } |
12076 | 12076 |
12077 | 12077 |
12078 // Do a lookup for the identifier in the scope of the specified | 12078 // Do a lookup for the identifier in the scope of the specified |
12079 // library prefix. This means trying to resolve it locally in all of the | 12079 // library prefix. This means trying to resolve it locally in all of the |
12080 // libraries present in the library prefix. | 12080 // libraries present in the library prefix. |
12081 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, | 12081 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, |
12082 const LibraryPrefix& prefix, | 12082 const LibraryPrefix& prefix, |
12083 const String& ident) { | 12083 const String& ident) { |
12084 TRACE_PARSER("ResolveIdentInPrefixScope"); | 12084 TRACE_PARSER("ResolveIdentInPrefixScope"); |
12085 HANDLESCOPE(I); | 12085 HANDLESCOPE(thread()); |
12086 if (ident.CharAt(0) == Library::kPrivateIdentifierStart) { | 12086 if (ident.CharAt(0) == Library::kPrivateIdentifierStart) { |
12087 // Private names are not exported by libraries. The name mangling | 12087 // Private names are not exported by libraries. The name mangling |
12088 // of private names with a library-specific suffix usually ensures | 12088 // of private names with a library-specific suffix usually ensures |
12089 // that _x in library A is not found when looked up from library B. | 12089 // that _x in library A is not found when looked up from library B. |
12090 // In the pathological case where a library imports itself with | 12090 // In the pathological case where a library imports itself with |
12091 // a prefix, the name mangling would not help in hiding the private | 12091 // a prefix, the name mangling would not help in hiding the private |
12092 // name, so we need to explicitly reject private names here. | 12092 // name, so we need to explicitly reject private names here. |
12093 return NULL; | 12093 return NULL; |
12094 } | 12094 } |
12095 Object& obj = Object::Handle(Z); | 12095 Object& obj = Object::Handle(Z); |
(...skipping 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14068 void Parser::SkipQualIdent() { | 14068 void Parser::SkipQualIdent() { |
14069 ASSERT(IsIdentifier()); | 14069 ASSERT(IsIdentifier()); |
14070 ConsumeToken(); | 14070 ConsumeToken(); |
14071 if (CurrentToken() == Token::kPERIOD) { | 14071 if (CurrentToken() == Token::kPERIOD) { |
14072 ConsumeToken(); // Consume the kPERIOD token. | 14072 ConsumeToken(); // Consume the kPERIOD token. |
14073 ExpectIdentifier("identifier expected after '.'"); | 14073 ExpectIdentifier("identifier expected after '.'"); |
14074 } | 14074 } |
14075 } | 14075 } |
14076 | 14076 |
14077 } // namespace dart | 14077 } // namespace dart |
OLD | NEW |