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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 6883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6894 Isolate* isolate = Isolate::Current(); | 6894 Isolate* isolate = Isolate::Current(); |
6895 // First try to find the identifier in the nested local scopes. | 6895 // First try to find the identifier in the nested local scopes. |
6896 LocalVariable* local = LookupLocalScope(ident); | 6896 LocalVariable* local = LookupLocalScope(ident); |
6897 if (local != NULL) { | 6897 if (local != NULL) { |
6898 if (node != NULL) { | 6898 if (node != NULL) { |
6899 *node = new LoadLocalNode(ident_pos, *local); | 6899 *node = new LoadLocalNode(ident_pos, *local); |
6900 } | 6900 } |
6901 return true; | 6901 return true; |
6902 } | 6902 } |
6903 | 6903 |
6904 // Try to find the identifier in the class scope. | 6904 // Try to find the identifier in the class scope of the current class. |
6905 Class& cls = Class::Handle(isolate, current_class().raw()); | 6905 Class& cls = Class::Handle(isolate, current_class().raw()); |
6906 Function& func = Function::Handle(isolate, Function::null()); | 6906 Function& func = Function::Handle(isolate, Function::null()); |
6907 Field& field = Field::Handle(isolate, Field::null()); | 6907 Field& field = Field::Handle(isolate, Field::null()); |
6908 while (!cls.IsNull()) { | 6908 |
6909 // First check if a field exists. | 6909 // First check if a field exists. |
6910 field = cls.LookupField(ident); | 6910 field = cls.LookupField(ident); |
6911 if (!field.IsNull()) { | 6911 if (!field.IsNull()) { |
6912 if (node != NULL) { | |
6913 if (!field.is_static()) { | |
6914 CheckInstanceFieldAccess(ident_pos, ident); | |
6915 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | |
6916 } else { | |
6917 *node = GenerateStaticFieldLookup(field, ident_pos); | |
6918 } | |
6919 } | |
6920 return true; | |
6921 } | |
6922 | |
6923 // Check if an instance/static function exists. | |
6924 func = cls.LookupFunction(ident); | |
6925 if (!func.IsNull() && | |
6926 (func.IsDynamicFunction() || func.IsStaticFunction())) { | |
6927 if (node != NULL) { | |
6928 *node = new PrimaryNode(ident_pos, | |
6929 Function::ZoneHandle(isolate, func.raw())); | |
6930 } | |
6931 return true; | |
6932 } | |
6933 | |
6934 // Now check if a getter/setter method exists for it in which case | |
6935 // it is still a field. | |
6936 func = cls.LookupGetterFunction(ident); | |
6937 if (!func.IsNull()) { | |
6938 if (func.IsDynamicFunction()) { | |
6912 if (node != NULL) { | 6939 if (node != NULL) { |
6913 if (!field.is_static()) { | 6940 CheckInstanceFieldAccess(ident_pos, ident); |
6914 CheckInstanceFieldAccess(ident_pos, ident); | 6941 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
6915 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6942 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
6916 } else { | 6943 } |
6917 *node = GenerateStaticFieldLookup(field, ident_pos); | 6944 return true; |
6918 } | 6945 } else if (func.IsStaticFunction()) { |
6946 if (node != NULL) { | |
6947 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
6948 *node = new StaticGetterNode(ident_pos, | |
6949 Class::ZoneHandle(isolate, cls.raw()), | |
6950 ident); | |
6919 } | 6951 } |
6920 return true; | 6952 return true; |
6921 } | 6953 } |
6922 | 6954 } |
6923 // Check if an instance/static function exists. | 6955 func = cls.LookupSetterFunction(ident); |
6924 func = cls.LookupFunction(ident); | 6956 if (!func.IsNull()) { |
6925 if (!func.IsNull() && | 6957 if (func.IsDynamicFunction()) { |
6926 (func.IsDynamicFunction() || func.IsStaticFunction())) { | |
6927 if (node != NULL) { | 6958 if (node != NULL) { |
6928 *node = new PrimaryNode(ident_pos, | 6959 // We create a getter node even though a getter doesn't exist as |
6929 Function::ZoneHandle(isolate, func.raw())); | 6960 // it could be followed by an assignment which will convert it to |
6961 // a setter node. If there is no assignment we will get an error | |
6962 // when we try to invoke the getter. | |
6963 CheckInstanceFieldAccess(ident_pos, ident); | |
6964 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
6965 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | |
6966 } | |
6967 return true; | |
6968 } else if (func.IsStaticFunction()) { | |
6969 if (node != NULL) { | |
6970 // We create a getter node even though a getter doesn't exist as | |
6971 // it could be followed by an assignment which will convert it to | |
6972 // a setter node. If there is no assignment we will get an error | |
6973 // when we try to invoke the getter. | |
6974 *node = new StaticGetterNode(ident_pos, | |
6975 Class::ZoneHandle(isolate, cls.raw()), | |
6976 ident); | |
6930 } | 6977 } |
6931 return true; | 6978 return true; |
6932 } | 6979 } |
6980 } | |
6933 | 6981 |
6934 // Now check if a getter/setter method exists for it in which case | 6982 // Nothing found in scope of current class. |
siva
2012/04/18 00:56:23
As discussed offline we need to figure if this wil
hausner
2012/04/18 16:49:26
Yes. If necessary, I will do that as a separate ch
| |
6935 // it is still a field. | |
6936 func = cls.LookupGetterFunction(ident); | |
6937 if (!func.IsNull()) { | |
6938 if (func.IsDynamicFunction()) { | |
6939 if (node != NULL) { | |
6940 CheckInstanceFieldAccess(ident_pos, ident); | |
6941 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
6942 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | |
6943 } | |
6944 return true; | |
6945 } else if (func.IsStaticFunction()) { | |
6946 if (node != NULL) { | |
6947 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
6948 *node = new StaticGetterNode(ident_pos, | |
6949 Class::ZoneHandle(isolate, cls.raw()), | |
6950 ident); | |
6951 } | |
6952 return true; | |
6953 } | |
6954 } | |
6955 func = cls.LookupSetterFunction(ident); | |
6956 if (!func.IsNull()) { | |
6957 if (func.IsDynamicFunction()) { | |
6958 if (node != NULL) { | |
6959 // We create a getter node even though a getter doesn't exist as | |
6960 // it could be followed by an assignment which will convert it to | |
6961 // a setter node. If there is no assignment we will get an error | |
6962 // when we try to invoke the getter. | |
6963 CheckInstanceFieldAccess(ident_pos, ident); | |
6964 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
6965 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | |
6966 } | |
6967 return true; | |
6968 } else if (func.IsStaticFunction()) { | |
6969 if (node != NULL) { | |
6970 // We create a getter node even though a getter doesn't exist as | |
6971 // it could be followed by an assignment which will convert it to | |
6972 // a setter node. If there is no assignment we will get an error | |
6973 // when we try to invoke the getter. | |
6974 *node = new StaticGetterNode(ident_pos, | |
6975 Class::ZoneHandle(isolate, cls.raw()), | |
6976 ident); | |
6977 } | |
6978 return true; | |
6979 } | |
6980 } | |
6981 | |
6982 cls = cls.SuperClass(); | |
6983 } | |
6984 if (node != NULL) { | 6983 if (node != NULL) { |
6985 *node = NULL; | 6984 *node = NULL; |
6986 } | 6985 } |
6987 return false; // Not an unqualified identifier. | 6986 return false; // Not an unqualified identifier. |
6988 } | 6987 } |
6989 | 6988 |
6990 | 6989 |
6991 // Do a lookup for the identifier in the library scope of the specified | 6990 // Do a lookup for the identifier in the library scope of the specified |
6992 // library. If resolve_locally is true the lookup does not consider | 6991 // library. If resolve_locally is true the lookup does not consider |
6993 // the libraries imported by it for the lookup. | 6992 // the libraries imported by it for the lookup. |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8388 void Parser::SkipQualIdent() { | 8387 void Parser::SkipQualIdent() { |
8389 ASSERT(IsIdentifier()); | 8388 ASSERT(IsIdentifier()); |
8390 ConsumeToken(); | 8389 ConsumeToken(); |
8391 if (CurrentToken() == Token::kPERIOD) { | 8390 if (CurrentToken() == Token::kPERIOD) { |
8392 ConsumeToken(); // Consume the kPERIOD token. | 8391 ConsumeToken(); // Consume the kPERIOD token. |
8393 ExpectIdentifier("identifier expected after '.'"); | 8392 ExpectIdentifier("identifier expected after '.'"); |
8394 } | 8393 } |
8395 } | 8394 } |
8396 | 8395 |
8397 } // namespace dart | 8396 } // namespace dart |
OLD | NEW |