| 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 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 parameter.is_field_initializer = true; | 1027 parameter.is_field_initializer = true; |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 // At this point, we must see an identifier for the parameter name. | 1030 // At this point, we must see an identifier for the parameter name. |
| 1031 parameter.name_pos = token_index_; | 1031 parameter.name_pos = token_index_; |
| 1032 parameter.name = ExpectIdentifier("parameter name expected"); | 1032 parameter.name = ExpectIdentifier("parameter name expected"); |
| 1033 if (parameter.is_field_initializer) { | 1033 if (parameter.is_field_initializer) { |
| 1034 params->has_field_initializer = true; | 1034 params->has_field_initializer = true; |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 // Check that the formal parameter is not repeated. | 1037 // Check for duplicate formal parameters. |
| 1038 const intptr_t num_existing_parameters = | 1038 const intptr_t num_existing_parameters = |
| 1039 params->num_fixed_parameters + params->num_optional_parameters; | 1039 params->num_fixed_parameters + params->num_optional_parameters; |
| 1040 for (intptr_t i = 0; i < num_existing_parameters; i++) { | 1040 for (intptr_t i = 0; i < num_existing_parameters; i++) { |
| 1041 ParamDesc& existing_parameter = (*params->parameters)[i]; | 1041 ParamDesc& existing_parameter = (*params->parameters)[i]; |
| 1042 if (existing_parameter.name->Equals(*parameter.name)) { | 1042 if (existing_parameter.name->Equals(*parameter.name)) { |
| 1043 ErrorMsg(parameter.name_pos, "repeated formal parameter"); | 1043 ErrorMsg(parameter.name_pos, "duplicate formal parameter '%s'", |
| 1044 parameter.name->ToCString()); |
| 1044 } | 1045 } |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 if (CurrentToken() == Token::kLPAREN) { | 1048 if (CurrentToken() == Token::kLPAREN) { |
| 1048 // This parameter is probably a closure. If we saw the keyword 'var' | 1049 // This parameter is probably a closure. If we saw the keyword 'var' |
| 1049 // or 'final', a closure is not legal here and we ignore the | 1050 // or 'final', a closure is not legal here and we ignore the |
| 1050 // opening parens. | 1051 // opening parens. |
| 1051 if (!var_seen && !parameter.is_final) { | 1052 if (!var_seen && !parameter.is_final) { |
| 1052 // The parsed parameter type is actually the function result type. | 1053 // The parsed parameter type is actually the function result type. |
| 1053 const AbstractType& result_type = | 1054 const AbstractType& result_type = |
| (...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3159 do { | 3160 do { |
| 3160 ConsumeToken(); | 3161 ConsumeToken(); |
| 3161 if (CurrentToken() != Token::kIDENT) { | 3162 if (CurrentToken() != Token::kIDENT) { |
| 3162 ErrorMsg("type parameter name expected"); | 3163 ErrorMsg("type parameter name expected"); |
| 3163 } | 3164 } |
| 3164 String& type_parameter_name = *CurrentLiteral(); | 3165 String& type_parameter_name = *CurrentLiteral(); |
| 3165 type_parameter = TypeParameter::New(cls, | 3166 type_parameter = TypeParameter::New(cls, |
| 3166 index, | 3167 index, |
| 3167 type_parameter_name, | 3168 type_parameter_name, |
| 3168 token_index_); | 3169 token_index_); |
| 3169 // Check that the type parameter is not repeated. | 3170 // Check for duplicate type parameters. |
| 3170 for (intptr_t i = 0; i < index; i++) { | 3171 for (intptr_t i = 0; i < index; i++) { |
| 3171 existing_type_parameter ^= type_parameters_array.At(i); | 3172 existing_type_parameter ^= type_parameters_array.At(i); |
| 3172 existing_type_parameter_name = existing_type_parameter.Name(); | 3173 existing_type_parameter_name = existing_type_parameter.Name(); |
| 3173 if (existing_type_parameter_name.Equals(type_parameter_name)) { | 3174 if (existing_type_parameter_name.Equals(type_parameter_name)) { |
| 3174 ErrorMsg("repeated type parameter"); | 3175 ErrorMsg("duplicate type parameter '%s'", |
| 3176 type_parameter_name.ToCString()); |
| 3175 } | 3177 } |
| 3176 } | 3178 } |
| 3177 ConsumeToken(); | 3179 ConsumeToken(); |
| 3178 bound = Type::DynamicType(); | 3180 bound = Type::DynamicType(); |
| 3179 if (CurrentToken() == Token::kEXTENDS) { | 3181 if (CurrentToken() == Token::kEXTENDS) { |
| 3180 ConsumeToken(); | 3182 ConsumeToken(); |
| 3181 // A bound may refer to the owner of the type parameter it applies to, | 3183 // A bound may refer to the owner of the type parameter it applies to, |
| 3182 // i.e. to the class or interface currently being parsed. | 3184 // i.e. to the class or interface currently being parsed. |
| 3183 // Postpone resolution in order to avoid resolving the class and its | 3185 // Postpone resolution in order to avoid resolving the class and its |
| 3184 // type parameters, as they are not fully parsed yet. | 3186 // type parameters, as they are not fully parsed yet. |
| (...skipping 5319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8504 void Parser::SkipQualIdent() { | 8506 void Parser::SkipQualIdent() { |
| 8505 ASSERT(IsIdentifier()); | 8507 ASSERT(IsIdentifier()); |
| 8506 ConsumeToken(); | 8508 ConsumeToken(); |
| 8507 if (CurrentToken() == Token::kPERIOD) { | 8509 if (CurrentToken() == Token::kPERIOD) { |
| 8508 ConsumeToken(); // Consume the kPERIOD token. | 8510 ConsumeToken(); // Consume the kPERIOD token. |
| 8509 ExpectIdentifier("identifier expected after '.'"); | 8511 ExpectIdentifier("identifier expected after '.'"); |
| 8510 } | 8512 } |
| 8511 } | 8513 } |
| 8512 | 8514 |
| 8513 } // namespace dart | 8515 } // namespace dart |
| OLD | NEW |