Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: runtime/vm/parser.cc

Issue 8724015: Properly detect name collisions at library level (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 const Type& type = Type::ZoneHandle( 2933 const Type& type = Type::ZoneHandle(
2934 ParseFinalVarOrType(kIsMandatory, kCanResolve)); 2934 ParseFinalVarOrType(kIsMandatory, kCanResolve));
2935 2935
2936 while (true) { 2936 while (true) {
2937 const intptr_t name_pos = token_index_; 2937 const intptr_t name_pos = token_index_;
2938 String& var_name = *ExpectIdentifier("variable name expected"); 2938 String& var_name = *ExpectIdentifier("variable name expected");
2939 2939
2940 if (library_.LookupObject(var_name) != Object::null()) { 2940 if (library_.LookupObject(var_name) != Object::null()) {
2941 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); 2941 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString());
2942 } 2942 }
2943 String& accessor_name = String::Handle(Field::GetterName(var_name));
2944 if (library_.LookupObject(accessor_name) != Object::null()) {
2945 ErrorMsg(name_pos, "getter for '%s' is already defined",
2946 var_name.ToCString());
2947 }
2948 accessor_name = Field::SetterName(var_name);
2949 if (library_.LookupObject(accessor_name) != Object::null()) {
2950 ErrorMsg(name_pos, "setter for '%s' is already defined",
2951 var_name.ToCString());
2952 }
2953
2943 Field& field = Field::ZoneHandle( 2954 Field& field = Field::ZoneHandle(
2944 Field::New(var_name, is_static, is_final, name_pos)); 2955 Field::New(var_name, is_static, is_final, name_pos));
2945 field.set_type(type); 2956 field.set_type(type);
2946 field.set_value(Instance::Handle(Instance::null())); 2957 field.set_value(Instance::Handle(Instance::null()));
2947 top_level->fields.Add(&field); 2958 top_level->fields.Add(&field);
2948 library_.AddObject(field, var_name); 2959 library_.AddObject(field, var_name);
2949 if (CurrentToken() == Token::kASSIGN) { 2960 if (CurrentToken() == Token::kASSIGN) {
2950 ConsumeToken(); 2961 ConsumeToken();
2951 SkipExpr(); 2962 SkipExpr();
2952 field.set_value(Instance::Handle(Object::sentinel())); 2963 field.set_value(Instance::Handle(Object::sentinel()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 (LookaheadToken(1) != Token::kLPAREN)) { 2996 (LookaheadToken(1) != Token::kLPAREN)) {
2986 result_type = ParseType(kCanResolve); 2997 result_type = ParseType(kCanResolve);
2987 } 2998 }
2988 } 2999 }
2989 const intptr_t name_pos = token_index_; 3000 const intptr_t name_pos = token_index_;
2990 const String& func_name = *ExpectIdentifier("function name expected"); 3001 const String& func_name = *ExpectIdentifier("function name expected");
2991 3002
2992 if (library_.LookupObject(func_name) != Object::null()) { 3003 if (library_.LookupObject(func_name) != Object::null()) {
2993 ErrorMsg(name_pos, "'%s' is already defined", func_name.ToCString()); 3004 ErrorMsg(name_pos, "'%s' is already defined", func_name.ToCString());
2994 } 3005 }
3006 String& accessor_name = String::Handle(Field::GetterName(func_name));
3007 if (library_.LookupObject(accessor_name) != Object::null()) {
3008 ErrorMsg(name_pos, "'%s' is already defined as getter",
3009 func_name.ToCString());
3010 }
3011 accessor_name = Field::SetterName(func_name);
3012 if (library_.LookupObject(accessor_name) != Object::null()) {
3013 ErrorMsg(name_pos, "'%s' is already defined as setter",
3014 func_name.ToCString());
3015 }
2995 3016
2996 if (CurrentToken() != Token::kLPAREN) { 3017 if (CurrentToken() != Token::kLPAREN) {
2997 ErrorMsg("'(' expected"); 3018 ErrorMsg("'(' expected");
2998 } 3019 }
2999 const intptr_t function_pos = token_index_; 3020 const intptr_t function_pos = token_index_;
3000 ParamList params; 3021 ParamList params;
3001 const bool allow_explicit_default_values = true; 3022 const bool allow_explicit_default_values = true;
3002 ParseFormalParameterList(allow_explicit_default_values, &params); 3023 ParseFormalParameterList(allow_explicit_default_values, &params);
3003 3024
3004 if (CurrentToken() == Token::kLBRACE) { 3025 if (CurrentToken() == Token::kLBRACE) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 } else { 3083 } else {
3063 expected_num_parameters = 1; 3084 expected_num_parameters = 1;
3064 accessor_name = Field::SetterName(*field_name); 3085 accessor_name = Field::SetterName(*field_name);
3065 } 3086 }
3066 if ((params.num_fixed_parameters != expected_num_parameters) || 3087 if ((params.num_fixed_parameters != expected_num_parameters) ||
3067 (params.num_optional_parameters != 0)) { 3088 (params.num_optional_parameters != 0)) {
3068 ErrorMsg(name_pos, "illegal %s parameters", 3089 ErrorMsg(name_pos, "illegal %s parameters",
3069 is_getter ? "getter" : "setter"); 3090 is_getter ? "getter" : "setter");
3070 } 3091 }
3071 3092
3093 if (library_.LookupObject(*field_name) != Object::null()) {
3094 ErrorMsg(name_pos, "'%s' is already defined in this library",
3095 field_name->ToCString());
3096 }
3097 if (library_.LookupObject(accessor_name) != Object::null()) {
3098 ErrorMsg(name_pos, "%s for '%s' is already defined",
3099 is_getter ? "getter" : "setter",
3100 field_name->ToCString());
3101 }
3102
3072 if (CurrentToken() == Token::kLBRACE) { 3103 if (CurrentToken() == Token::kLBRACE) {
3073 SkipBlock(); 3104 SkipBlock();
3074 } else if (CurrentToken() == Token::kARROW) { 3105 } else if (CurrentToken() == Token::kARROW) {
3075 ConsumeToken(); 3106 ConsumeToken();
3076 SkipExpr(); 3107 SkipExpr();
3077 ExpectSemicolon(); 3108 ExpectSemicolon();
3078 } else if (IsLiteral("native")) { 3109 } else if (IsLiteral("native")) {
3079 ParseNativeDeclaration(); 3110 ParseNativeDeclaration();
3080 } else { 3111 } else {
3081 ErrorMsg("function block expected"); 3112 ErrorMsg("function block expected");
(...skipping 4469 matching lines...) Expand 10 before | Expand all | Expand 10 after
7551 } 7582 }
7552 7583
7553 7584
7554 void Parser::SkipNestedExpr() { 7585 void Parser::SkipNestedExpr() {
7555 const bool saved_mode = SetAllowFunctionLiterals(true); 7586 const bool saved_mode = SetAllowFunctionLiterals(true);
7556 SkipExpr(); 7587 SkipExpr();
7557 SetAllowFunctionLiterals(saved_mode); 7588 SetAllowFunctionLiterals(saved_mode);
7558 } 7589 }
7559 7590
7560 } // namespace dart 7591 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/src/ToplevelCollision1Test.dart » ('j') | tests/language/src/ToplevelCollision2Test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698