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

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

Issue 489993004: Private names are not exported, not even if the library imports itself (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months 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
« no previous file with comments | « no previous file | tests/language/import_self_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 } 1515 }
1516 1516
1517 // At this point, we must see an identifier for the parameter name. 1517 // At this point, we must see an identifier for the parameter name.
1518 parameter.name_pos = TokenPos(); 1518 parameter.name_pos = TokenPos();
1519 parameter.name = ExpectIdentifier("parameter name expected"); 1519 parameter.name = ExpectIdentifier("parameter name expected");
1520 if (parameter.is_field_initializer) { 1520 if (parameter.is_field_initializer) {
1521 params->has_field_initializer = true; 1521 params->has_field_initializer = true;
1522 } 1522 }
1523 1523
1524 if (params->has_optional_named_parameters && 1524 if (params->has_optional_named_parameters &&
1525 (parameter.name->CharAt(0) == '_')) { 1525 (parameter.name->CharAt(0) == Library::kPrivateIdentifierStart)) {
1526 ReportError(parameter.name_pos, "named parameter must not be private"); 1526 ReportError(parameter.name_pos, "named parameter must not be private");
1527 } 1527 }
1528 1528
1529 // Check for duplicate formal parameters. 1529 // Check for duplicate formal parameters.
1530 const intptr_t num_existing_parameters = 1530 const intptr_t num_existing_parameters =
1531 params->num_fixed_parameters + params->num_optional_parameters; 1531 params->num_fixed_parameters + params->num_optional_parameters;
1532 for (intptr_t i = 0; i < num_existing_parameters; i++) { 1532 for (intptr_t i = 0; i < num_existing_parameters; i++) {
1533 ParamDesc& existing_parameter = (*params->parameters)[i]; 1533 ParamDesc& existing_parameter = (*params->parameters)[i];
1534 if (existing_parameter.name->Equals(*parameter.name)) { 1534 if (existing_parameter.name->Equals(*parameter.name)) {
1535 ReportError(parameter.name_pos, "duplicate formal parameter '%s'", 1535 ReportError(parameter.name_pos, "duplicate formal parameter '%s'",
(...skipping 8010 matching lines...) Expand 10 before | Expand all | Expand 10 after
9546 9546
9547 9547
9548 // Do a lookup for the identifier in the scope of the specified 9548 // Do a lookup for the identifier in the scope of the specified
9549 // library prefix. This means trying to resolve it locally in all of the 9549 // library prefix. This means trying to resolve it locally in all of the
9550 // libraries present in the library prefix. 9550 // libraries present in the library prefix.
9551 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, 9551 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos,
9552 const LibraryPrefix& prefix, 9552 const LibraryPrefix& prefix,
9553 const String& ident) { 9553 const String& ident) {
9554 TRACE_PARSER("ResolveIdentInPrefixScope"); 9554 TRACE_PARSER("ResolveIdentInPrefixScope");
9555 HANDLESCOPE(I); 9555 HANDLESCOPE(I);
9556 if (ident.CharAt(0) == Library::kPrivateIdentifierStart) {
9557 // Private names are not exported by libraries. The name mangling
9558 // of private names with a library-specific suffix usually ensures
9559 // that _x in library A is not found when looked up from library B.
9560 // In the pathological case where a library includes itself with
9561 // a prefix, the name mangling would not help in hiding the private
9562 // name, so we need to explicitly reject private names here.
9563 return NULL;
9564 }
9556 Object& obj = Object::Handle(I); 9565 Object& obj = Object::Handle(I);
9557 if (prefix.is_loaded()) { 9566 if (prefix.is_loaded()) {
9558 obj = prefix.LookupObject(ident); 9567 obj = prefix.LookupObject(ident);
9559 } else { 9568 } else {
9560 // Remember that this function depends on an import prefix of an 9569 // Remember that this function depends on an import prefix of an
9561 // unloaded deferred library. Note that parsed_function() can be 9570 // unloaded deferred library. Note that parsed_function() can be
9562 // NULL when parsing expressions outside the scope of a function. 9571 // NULL when parsing expressions outside the scope of a function.
9563 if (parsed_function() != NULL) { 9572 if (parsed_function() != NULL) {
9564 parsed_function()->AddDeferredPrefix(prefix); 9573 parsed_function()->AddDeferredPrefix(prefix);
9565 } 9574 }
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
11257 void Parser::SkipQualIdent() { 11266 void Parser::SkipQualIdent() {
11258 ASSERT(IsIdentifier()); 11267 ASSERT(IsIdentifier());
11259 ConsumeToken(); 11268 ConsumeToken();
11260 if (CurrentToken() == Token::kPERIOD) { 11269 if (CurrentToken() == Token::kPERIOD) {
11261 ConsumeToken(); // Consume the kPERIOD token. 11270 ConsumeToken(); // Consume the kPERIOD token.
11262 ExpectIdentifier("identifier expected after '.'"); 11271 ExpectIdentifier("identifier expected after '.'");
11263 } 11272 }
11264 } 11273 }
11265 11274
11266 } // namespace dart 11275 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/import_self_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698