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

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

Issue 2643523002: Implement generic function type syntax in the VM (fixes #27966). (Closed)
Patch Set: refactor parsing of formal parameter per review request Created 3 years, 11 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
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('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 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 "Enable conditional directives"); 56 "Enable conditional directives");
57 DEFINE_FLAG(bool, generic_method_syntax, true, "Enable generic functions."); 57 DEFINE_FLAG(bool, generic_method_syntax, true, "Enable generic functions.");
58 DEFINE_FLAG(bool, 58 DEFINE_FLAG(bool,
59 initializing_formal_access, 59 initializing_formal_access,
60 true, 60 true,
61 "Make initializing formal parameters visible in initializer list."); 61 "Make initializing formal parameters visible in initializer list.");
62 DEFINE_FLAG(bool, 62 DEFINE_FLAG(bool,
63 warn_super, 63 warn_super,
64 false, 64 false,
65 "Warning if super initializer not last in initializer list."); 65 "Warning if super initializer not last in initializer list.");
66 DEFINE_FLAG(bool, warn_patch, false, "Warn on old-style patch syntax.");
67 DEFINE_FLAG( 66 DEFINE_FLAG(
68 bool, 67 bool,
69 await_is_keyword, 68 await_is_keyword,
70 false, 69 false,
71 "await and yield are treated as proper keywords in synchronous code."); 70 "await and yield are treated as proper keywords in synchronous code.");
72 DEFINE_FLAG(bool, 71 DEFINE_FLAG(bool,
73 assert_initializer, 72 assert_initializer,
74 false, 73 false,
75 "Allow asserts in initializer lists."); 74 "Allow asserts in initializer lists.");
76 75
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 Thread* thread = Thread::Current(); 987 Thread* thread = Thread::Current();
989 StackZone stack_zone(thread); 988 StackZone stack_zone(thread);
990 Zone* zone = stack_zone.GetZone(); 989 Zone* zone = stack_zone.GetZone();
991 const Script& script = Script::Handle(zone, func.script()); 990 const Script& script = Script::Handle(zone, func.script());
992 const Class& owner = Class::Handle(zone, func.Owner()); 991 const Class& owner = Class::Handle(zone, func.Owner());
993 ASSERT(!owner.IsNull()); 992 ASSERT(!owner.IsNull());
994 ParsedFunction* parsed_function = 993 ParsedFunction* parsed_function =
995 new ParsedFunction(thread, Function::ZoneHandle(zone, func.raw())); 994 new ParsedFunction(thread, Function::ZoneHandle(zone, func.raw()));
996 Parser parser(script, parsed_function, func.token_pos()); 995 Parser parser(script, parsed_function, func.token_pos());
997 parser.SkipFunctionPreamble(); 996 parser.SkipFunctionPreamble();
997 const bool use_function_type_syntax = false;
998 const bool allow_explicit_default_values = true;
999 const bool evaluate_metadata = true;
998 ParamList params; 1000 ParamList params;
999 parser.ParseFormalParameterList(true, true, &params); 1001 parser.ParseFormalParameterList(use_function_type_syntax,
1002 allow_explicit_default_values,
1003 evaluate_metadata, &params);
1000 ParamDesc* param = params.parameters->data(); 1004 ParamDesc* param = params.parameters->data();
1001 const int param_cnt = 1005 const int param_cnt =
1002 params.num_fixed_parameters + params.num_optional_parameters; 1006 params.num_fixed_parameters + params.num_optional_parameters;
1003 const Array& param_descriptor = 1007 const Array& param_descriptor =
1004 Array::Handle(Array::New(param_cnt * kParameterEntrySize, Heap::kOld)); 1008 Array::Handle(Array::New(param_cnt * kParameterEntrySize, Heap::kOld));
1005 for (int i = 0, j = 0; i < param_cnt; i++, j += kParameterEntrySize) { 1009 for (int i = 0, j = 0; i < param_cnt; i++, j += kParameterEntrySize) {
1006 param_descriptor.SetAt(j + kParameterIsFinalOffset, 1010 param_descriptor.SetAt(j + kParameterIsFinalOffset,
1007 param[i].is_final ? Bool::True() : Bool::False()); 1011 param[i].is_final ? Bool::True() : Bool::False());
1008 param_descriptor.SetAt(j + kParameterDefaultValueOffset, 1012 param_descriptor.SetAt(j + kParameterDefaultValueOffset,
1009 (param[i].default_value == NULL) 1013 (param[i].default_value == NULL)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 } 1048 }
1045 LongJumpScope jump; 1049 LongJumpScope jump;
1046 if (setjmp(*jump.Set()) == 0) { 1050 if (setjmp(*jump.Set()) == 0) {
1047 const Script& script = Script::Handle(func.script()); 1051 const Script& script = Script::Handle(func.script());
1048 const Class& owner = Class::Handle(func.Owner()); 1052 const Class& owner = Class::Handle(func.Owner());
1049 ASSERT(!owner.IsNull()); 1053 ASSERT(!owner.IsNull());
1050 ParsedFunction* parsed_function = 1054 ParsedFunction* parsed_function =
1051 new ParsedFunction(Thread::Current(), Function::ZoneHandle(func.raw())); 1055 new ParsedFunction(Thread::Current(), Function::ZoneHandle(func.raw()));
1052 Parser parser(script, parsed_function, func.token_pos()); 1056 Parser parser(script, parsed_function, func.token_pos());
1053 parser.SkipFunctionPreamble(); 1057 parser.SkipFunctionPreamble();
1054 parser.ParseFormalParameterList(true, true, params); 1058 const bool use_function_type_syntax = false;
1059 const bool allow_explicit_default_values = true;
1060 const bool evaluate_metadata = true;
1061 parser.ParseFormalParameterList(use_function_type_syntax,
1062 allow_explicit_default_values,
1063 evaluate_metadata, params);
1055 return true; 1064 return true;
1056 } else { 1065 } else {
1057 Thread::Current()->clear_sticky_error(); 1066 Thread::Current()->clear_sticky_error();
1058 params->Clear(); 1067 params->Clear();
1059 return false; 1068 return false;
1060 } 1069 }
1061 UNREACHABLE(); 1070 UNREACHABLE();
1062 return false; 1071 return false;
1063 } 1072 }
1064 1073
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 } 1360 }
1352 // The instantiator is not required in a static expression. 1361 // The instantiator is not required in a static expression.
1353 ASSERT(!parser.IsInstantiatorRequired()); 1362 ASSERT(!parser.IsInstantiatorRequired());
1354 1363
1355 return parsed_function; 1364 return parsed_function;
1356 } 1365 }
1357 1366
1358 1367
1359 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) { 1368 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) {
1360 TRACE_PARSER("ParseStaticFinalGetter"); 1369 TRACE_PARSER("ParseStaticFinalGetter");
1361 ParamList params;
1362 ASSERT(func.num_fixed_parameters() == 0); // static. 1370 ASSERT(func.num_fixed_parameters() == 0); // static.
1363 ASSERT(!func.HasOptionalParameters()); 1371 ASSERT(!func.HasOptionalParameters());
1364 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 1372 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
1365
1366 // Build local scope for function and populate with the formal parameters.
1367 OpenFunctionBlock(func); 1373 OpenFunctionBlock(func);
1368 AddFormalParamsToScope(&params, current_block_->scope);
1369
1370 TokenPosition ident_pos = TokenPos(); 1374 TokenPosition ident_pos = TokenPos();
1371 const String& field_name = *ExpectIdentifier("field name expected"); 1375 const String& field_name = *ExpectIdentifier("field name expected");
1372 const Class& field_class = Class::Handle(Z, func.Owner()); 1376 const Class& field_class = Class::Handle(Z, func.Owner());
1373 const Field& field = 1377 const Field& field =
1374 Field::ZoneHandle(Z, field_class.LookupStaticField(field_name)); 1378 Field::ZoneHandle(Z, field_class.LookupStaticField(field_name));
1375 ASSERT(!field.IsNull()); 1379 ASSERT(!field.IsNull());
1376 1380
1377 // Static final fields must have an initializer. 1381 // Static final fields must have an initializer.
1378 ExpectToken(Token::kASSIGN); 1382 ExpectToken(Token::kASSIGN);
1379 1383
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 const Function& parent = Function::Handle(func.parent_function()); 1557 const Function& parent = Function::Handle(func.parent_function());
1554 if (parent.IsImplicitSetterFunction()) { 1558 if (parent.IsImplicitSetterFunction()) {
1555 const TokenPosition ident_pos = func.token_pos(); 1559 const TokenPosition ident_pos = func.token_pos();
1556 ASSERT(IsIdentifier()); 1560 ASSERT(IsIdentifier());
1557 params.AddFinalParameter(ident_pos, &Symbols::Value(), 1561 params.AddFinalParameter(ident_pos, &Symbols::Value(),
1558 &Object::dynamic_type()); 1562 &Object::dynamic_type());
1559 ASSERT(func.num_fixed_parameters() == 2); // closure, value. 1563 ASSERT(func.num_fixed_parameters() == 2); // closure, value.
1560 } else if (!parent.IsGetterFunction() && !parent.IsImplicitGetterFunction()) { 1564 } else if (!parent.IsGetterFunction() && !parent.IsImplicitGetterFunction()) {
1561 // NOTE: For the `kernel -> flowgraph` we don't use the parser. 1565 // NOTE: For the `kernel -> flowgraph` we don't use the parser.
1562 if (parent.kernel_function() == NULL) { 1566 if (parent.kernel_function() == NULL) {
1567 SkipFunctionPreamble();
1568 const bool use_function_type_syntax = false;
1563 const bool allow_explicit_default_values = true; 1569 const bool allow_explicit_default_values = true;
1564 SkipFunctionPreamble(); 1570 const bool evaluate_metadata = false;
1565 ParseFormalParameterList(allow_explicit_default_values, false, &params); 1571 ParseFormalParameterList(use_function_type_syntax,
1572 allow_explicit_default_values, evaluate_metadata,
1573 &params);
1574 FinalizeFormalParameterTypes(&params);
1566 SetupDefaultsForOptionalParams(params); 1575 SetupDefaultsForOptionalParams(params);
1567 } 1576 }
1568 } 1577 }
1569 1578
1570 // Populate function scope with the formal parameters. 1579 // Populate function scope with the formal parameters.
1571 LocalScope* scope = current_block_->scope; 1580 LocalScope* scope = current_block_->scope;
1572 AddFormalParamsToScope(&params, scope); 1581 AddFormalParamsToScope(&params, scope);
1573 1582
1574 ArgumentListNode* func_args = new ArgumentListNode(token_pos); 1583 ArgumentListNode* func_args = new ArgumentListNode(token_pos);
1575 if (!func.is_static()) { 1584 if (!func.is_static()) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 1939
1931 // Skips tokens up to and including matching closing parenthesis. 1940 // Skips tokens up to and including matching closing parenthesis.
1932 void Parser::SkipToMatchingParenthesis() { 1941 void Parser::SkipToMatchingParenthesis() {
1933 ASSERT(CurrentToken() == Token::kLPAREN); 1942 ASSERT(CurrentToken() == Token::kLPAREN);
1934 SkipToMatching(); 1943 SkipToMatching();
1935 ASSERT(CurrentToken() == Token::kRPAREN); 1944 ASSERT(CurrentToken() == Token::kRPAREN);
1936 ConsumeToken(); 1945 ConsumeToken();
1937 } 1946 }
1938 1947
1939 1948
1949 // Parses a parameter type as defined by the 'parameterTypeList' production.
1950 void Parser::ParseParameterType(ParamList* params) {
1951 TRACE_PARSER("ParseParameterType");
1952 ParamDesc parameter;
1953
1954 parameter.has_explicit_type = true; // The type is required by the syntax.
1955 // It is too early to resolve the type here, since it can be a result type
1956 // referring to a not yet declared function type parameter.
1957 parameter.type = &AbstractType::ZoneHandle(
1958 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kDoNotResolve));
1959
1960 // At this point, we must see an identifier for the parameter name, unless
1961 // we are using the function type syntax (in which case the name is optional,
1962 // unless we expect optional named parameters).
1963 if (IsIdentifier()) {
1964 parameter.name_pos = TokenPos();
1965 parameter.name = CurrentLiteral();
1966 ConsumeToken();
1967
1968 if (params->has_optional_named_parameters &&
1969 (parameter.name->CharAt(0) == Library::kPrivateIdentifierStart)) {
1970 ReportError(parameter.name_pos, "named parameter must not be private");
1971 }
1972
1973 // Check for duplicate formal parameters.
1974 const intptr_t num_existing_parameters =
1975 params->num_fixed_parameters + params->num_optional_parameters;
1976 for (intptr_t i = 0; i < num_existing_parameters; i++) {
1977 ParamDesc& existing_parameter = (*params->parameters)[i];
1978 if (existing_parameter.name->Equals(*parameter.name)) {
1979 ReportError(parameter.name_pos, "duplicate formal parameter '%s'",
1980 parameter.name->ToCString());
1981 }
1982 }
1983 } else if (params->has_optional_named_parameters) {
1984 ExpectIdentifier("parameter name expected");
1985 } else {
1986 parameter.name_pos = TokenPos();
1987 parameter.name = &Symbols::NotNamed();
1988 }
1989
1990 // The function type syntax does not allow the signature type syntax.
1991 // No need to check for IsParameterPart().
1992
1993 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) {
1994 ReportError("parameter must not specify a default value");
1995 } else {
1996 if (params->has_optional_positional_parameters ||
1997 params->has_optional_named_parameters) {
1998 // Implicit default value is null.
1999 params->num_optional_parameters++;
2000 parameter.default_value = &Object::null_instance();
2001 } else {
2002 params->num_fixed_parameters++;
2003 ASSERT(params->num_optional_parameters == 0);
2004 }
2005 }
2006 if (parameter.type->IsVoidType()) {
2007 ReportError("parameter '%s' may not be 'void'",
2008 parameter.name->ToCString());
2009 }
2010 if (params->implicitly_final) {
2011 parameter.is_final = true;
2012 }
2013 params->parameters->Add(parameter);
2014 if (parameter.is_covariant) {
2015 params->has_covariant = true;
2016 }
2017 }
2018
2019
2020 // Parses a formal parameter as defined by the 'formalParameterList' production.
1940 void Parser::ParseFormalParameter(bool allow_explicit_default_value, 2021 void Parser::ParseFormalParameter(bool allow_explicit_default_value,
1941 bool evaluate_metadata, 2022 bool evaluate_metadata,
1942 ParamList* params) { 2023 ParamList* params) {
1943 TRACE_PARSER("ParseFormalParameter"); 2024 TRACE_PARSER("ParseFormalParameter");
1944 ParamDesc parameter; 2025 ParamDesc parameter;
1945 bool var_seen = false; 2026 bool var_seen = false;
1946 bool final_seen = false; 2027 bool final_seen = false;
1947 bool this_seen = false; 2028 bool this_seen = false;
1948 2029
1949 if (evaluate_metadata && (CurrentToken() == Token::kAT)) { 2030 if (evaluate_metadata && (CurrentToken() == Token::kAT)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 } 2062 }
1982 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) { 2063 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) {
1983 ConsumeToken(); 2064 ConsumeToken();
1984 // This must later be changed to a closure type if we recognize 2065 // This must later be changed to a closure type if we recognize
1985 // a closure/function type parameter. We check this at the end 2066 // a closure/function type parameter. We check this at the end
1986 // of ParseFormalParameter. 2067 // of ParseFormalParameter.
1987 parameter.type = &Object::void_type(); 2068 parameter.type = &Object::void_type();
1988 } 2069 }
1989 if (parameter.type == NULL) { 2070 if (parameter.type == NULL) {
1990 // At this point, we must see an identifier for the type or the 2071 // At this point, we must see an identifier for the type or the
1991 // function parameter. 2072 // function parameter. The identifier may be 'Function'.
1992 if (!IsIdentifier()) { 2073 if (!IsIdentifier()) {
1993 ReportError("parameter name or type expected"); 2074 ReportError("parameter name or type expected");
1994 } 2075 }
1995 2076
1996 // Lookahead to determine whether the next tokens are a return type 2077 // Lookahead to determine whether the next tokens are a return type
1997 // followed by a parameter name. 2078 // followed by a parameter name.
1998 bool found_type = false; 2079 bool found_type = false;
1999 { 2080 {
2000 TokenPosScope saved_pos(this); 2081 TokenPosScope saved_pos(this);
2001 if (TryParseReturnType()) { 2082 if (TryParseType(true)) {
2002 if (IsIdentifier() || (CurrentToken() == Token::kTHIS)) { 2083 if (IsIdentifier() || (CurrentToken() == Token::kTHIS)) {
2003 found_type = true; 2084 found_type = true;
2004 } 2085 }
2005 } 2086 }
2006 } 2087 }
2007 if (found_type) { 2088 if (found_type) {
2008 // The types of formal parameters are never ignored, even in unchecked 2089 // The types of formal parameters are never ignored, even in unchecked
2009 // mode, because they are part of the function type of closurized 2090 // mode, because they are part of the function type of closurized
2010 // functions appearing in type tests with typedefs. 2091 // functions appearing in type tests with typedefs.
2011 parameter.has_explicit_type = true; 2092 parameter.has_explicit_type = true;
2012 // It is too early to resolve the type here, since it can be a result type 2093 // It is too early to resolve the type here, since it can be a result
2013 // referring to a not yet declared function type parameter. 2094 // type referring to a not yet declared function type parameter.
2014 parameter.type = &AbstractType::ZoneHandle( 2095 parameter.type = &AbstractType::ZoneHandle(
2015 Z, ParseType(ClassFinalizer::kDoNotResolve)); 2096 Z, ParseTypeOrFunctionType(true, ClassFinalizer::kDoNotResolve));
2016 } else { 2097 } else {
2017 // If this is an initializing formal, its type will be set to the type of 2098 // If this is an initializing formal, its type will be set to the type
2018 // the respective field when the constructor is fully parsed. 2099 // of the respective field when the constructor is fully parsed.
2019 parameter.type = &Object::dynamic_type(); 2100 parameter.type = &Object::dynamic_type();
2020 } 2101 }
2021 } 2102 }
2022 if (!this_seen && (CurrentToken() == Token::kTHIS)) { 2103 if (!this_seen && (CurrentToken() == Token::kTHIS)) {
2023 ConsumeToken(); 2104 ConsumeToken();
2024 ExpectToken(Token::kPERIOD); 2105 ExpectToken(Token::kPERIOD);
2025 this_seen = true; 2106 this_seen = true;
2026 parameter.is_field_initializer = true; 2107 parameter.is_field_initializer = true;
2027 if (FLAG_initializing_formal_access) { 2108 if (FLAG_initializing_formal_access) {
2028 parameter.is_final = true; 2109 parameter.is_final = true;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 innermost_function_ = signature_function.raw(); 2158 innermost_function_ = signature_function.raw();
2078 2159
2079 // Finish parsing the function type parameter. 2160 // Finish parsing the function type parameter.
2080 if (CurrentToken() == Token::kLT) { 2161 if (CurrentToken() == Token::kLT) {
2081 if (!FLAG_generic_method_syntax) { 2162 if (!FLAG_generic_method_syntax) {
2082 ReportError("generic function types not supported"); 2163 ReportError("generic function types not supported");
2083 } 2164 }
2084 ParseTypeParameters(false); // Not parameterizing class, but function. 2165 ParseTypeParameters(false); // Not parameterizing class, but function.
2085 } 2166 }
2086 2167
2087 // Now that type parameters are declared, the result type can be resolved.
2088 ResolveType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters
2089 : ClassFinalizer::kCanonicalize,
2090 &result_type);
2091
2092 ASSERT(CurrentToken() == Token::kLPAREN); 2168 ASSERT(CurrentToken() == Token::kLPAREN);
2093 ParamList func_params; 2169 ParamList func_params;
2094 2170
2095 // Add implicit closure object parameter. 2171 // Add implicit closure object parameter.
2096 func_params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), 2172 func_params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
2097 &Object::dynamic_type()); 2173 &Object::dynamic_type());
2098 2174
2099 const bool no_explicit_default_values = false; 2175 const bool use_function_type_syntax = false;
2100 ParseFormalParameterList(no_explicit_default_values, false, &func_params); 2176 const bool allow_explicit_default_values = false;
2177 const bool evaluate_metadata = false;
2178 ParseFormalParameterList(use_function_type_syntax,
2179 allow_explicit_default_values, evaluate_metadata,
2180 &func_params);
2101 2181
2102 signature_function.set_result_type(result_type); 2182 signature_function.set_result_type(result_type);
2103 AddFormalParamsToFunction(&func_params, signature_function); 2183 AddFormalParamsToFunction(&func_params, signature_function);
2104 2184
2105 ASSERT(innermost_function().raw() == signature_function.raw()); 2185 ASSERT(innermost_function().raw() == signature_function.raw());
2106 innermost_function_ = signature_function.parent_function(); 2186 innermost_function_ = signature_function.parent_function();
2107 2187
2108 Type& signature_type = 2188 Type& signature_type =
2109 Type::ZoneHandle(Z, signature_function.SignatureType()); 2189 Type::ZoneHandle(Z, signature_function.SignatureType());
2110 if (!is_top_level_) { 2190
2111 signature_type ^= ClassFinalizer::FinalizeType(
2112 current_class(), signature_type, ClassFinalizer::kCanonicalize);
2113 // Do not refer to signature_function anymore, since it may have been
2114 // replaced during canonicalization.
2115 signature_function = Function::null();
2116 }
2117 ASSERT(is_top_level_ || signature_type.IsFinalized());
2118 // A signature type itself cannot be malformed or malbounded, only its 2191 // A signature type itself cannot be malformed or malbounded, only its
2119 // signature function's result type or parameter types may be. 2192 // signature function's result type or parameter types may be.
2120 ASSERT(!signature_type.IsMalformed()); 2193 ASSERT(!signature_type.IsMalformed());
2121 ASSERT(!signature_type.IsMalbounded()); 2194 ASSERT(!signature_type.IsMalbounded());
2122 // The type of the parameter is now the signature type. 2195 // The type of the parameter is now the signature type.
2123 parameter.type = &signature_type; 2196 parameter.type = &signature_type;
2124 } 2197 }
2125 } else {
2126 if (!parameter.type->IsFinalized()) {
2127 AbstractType& type = AbstractType::ZoneHandle(Z, parameter.type->raw());
2128 if (is_top_level_) {
2129 ResolveType(ClassFinalizer::kResolveTypeParameters, &type);
2130 } else {
2131 ResolveType(ClassFinalizer::kCanonicalize, &type);
2132 type = ClassFinalizer::FinalizeType(current_class(), type,
2133 ClassFinalizer::kCanonicalize);
2134 }
2135 parameter.type = &type;
2136 }
2137 } 2198 }
2138 2199
2139 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { 2200 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) {
2140 if ((!params->has_optional_positional_parameters && 2201 if ((!params->has_optional_positional_parameters &&
2141 !params->has_optional_named_parameters) || 2202 !params->has_optional_named_parameters) ||
2142 !allow_explicit_default_value) { 2203 !allow_explicit_default_value) {
2143 ReportError("parameter must not specify a default value"); 2204 ReportError("parameter must not specify a default value");
2144 } 2205 }
2145 if (params->has_optional_positional_parameters) { 2206 if (params->has_optional_positional_parameters) {
2146 ExpectToken(Token::kASSIGN); 2207 ExpectToken(Token::kASSIGN);
(...skipping 28 matching lines...) Expand all
2175 parameter.is_final = true; 2236 parameter.is_final = true;
2176 } 2237 }
2177 params->parameters->Add(parameter); 2238 params->parameters->Add(parameter);
2178 if (parameter.is_covariant) { 2239 if (parameter.is_covariant) {
2179 params->has_covariant = true; 2240 params->has_covariant = true;
2180 } 2241 }
2181 } 2242 }
2182 2243
2183 2244
2184 // Parses a sequence of normal or optional formal parameters. 2245 // Parses a sequence of normal or optional formal parameters.
2185 void Parser::ParseFormalParameters(bool allow_explicit_default_values, 2246 void Parser::ParseFormalParameters(bool use_function_type_syntax,
2247 bool allow_explicit_default_values,
2186 bool evaluate_metadata, 2248 bool evaluate_metadata,
2187 ParamList* params) { 2249 ParamList* params) {
2188 TRACE_PARSER("ParseFormalParameters"); 2250 TRACE_PARSER("ParseFormalParameters");
2189 // Optional parameter lists cannot be empty. 2251 // Optional parameter lists cannot be empty.
2190 // The completely empty parameter list is handled before getting here. 2252 // The completely empty parameter list is handled before getting here.
2191 bool has_seen_parameter = false; 2253 bool has_seen_parameter = false;
2192 do { 2254 do {
2193 ConsumeToken(); 2255 ConsumeToken();
2194 if (!params->has_optional_positional_parameters && 2256 if (!params->has_optional_positional_parameters &&
2195 !params->has_optional_named_parameters && 2257 !params->has_optional_named_parameters &&
(...skipping 11 matching lines...) Expand all
2207 } 2269 }
2208 Token::Kind terminator = params->has_optional_positional_parameters 2270 Token::Kind terminator = params->has_optional_positional_parameters
2209 ? Token::kRBRACK 2271 ? Token::kRBRACK
2210 : params->has_optional_named_parameters 2272 : params->has_optional_named_parameters
2211 ? Token::kRBRACE 2273 ? Token::kRBRACE
2212 : Token::kRPAREN; 2274 : Token::kRPAREN;
2213 if (has_seen_parameter && CurrentToken() == terminator) { 2275 if (has_seen_parameter && CurrentToken() == terminator) {
2214 // Allow a trailing comma. 2276 // Allow a trailing comma.
2215 break; 2277 break;
2216 } 2278 }
2217 ParseFormalParameter(allow_explicit_default_values, evaluate_metadata, 2279 if (use_function_type_syntax) {
2218 params); 2280 ASSERT(!allow_explicit_default_values && !evaluate_metadata);
2281 ParseParameterType(params);
2282 } else {
2283 ParseFormalParameter(allow_explicit_default_values, evaluate_metadata,
2284 params);
2285 }
2219 has_seen_parameter = true; 2286 has_seen_parameter = true;
2220 } while (CurrentToken() == Token::kCOMMA); 2287 } while (CurrentToken() == Token::kCOMMA);
2221 } 2288 }
2222 2289
2223 2290
2224 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, 2291 void Parser::ParseFormalParameterList(bool use_function_type_syntax,
2292 bool allow_explicit_default_values,
2225 bool evaluate_metadata, 2293 bool evaluate_metadata,
2226 ParamList* params) { 2294 ParamList* params) {
2227 TRACE_PARSER("ParseFormalParameterList"); 2295 TRACE_PARSER("ParseFormalParameterList");
2228 ASSERT(CurrentToken() == Token::kLPAREN); 2296 ASSERT(CurrentToken() == Token::kLPAREN);
2229 2297
2230 if (LookaheadToken(1) != Token::kRPAREN) { 2298 if (LookaheadToken(1) != Token::kRPAREN) {
2231 // Parse fixed parameters. 2299 // Parse fixed parameters.
2232 ParseFormalParameters(allow_explicit_default_values, evaluate_metadata, 2300 ParseFormalParameters(use_function_type_syntax,
2301 allow_explicit_default_values, evaluate_metadata,
2233 params); 2302 params);
2234 if (params->has_optional_positional_parameters || 2303 if (params->has_optional_positional_parameters ||
2235 params->has_optional_named_parameters) { 2304 params->has_optional_named_parameters) {
2236 // Parse optional parameters. 2305 // Parse optional parameters.
2237 ParseFormalParameters(allow_explicit_default_values, evaluate_metadata, 2306 ParseFormalParameters(use_function_type_syntax,
2307 allow_explicit_default_values, evaluate_metadata,
2238 params); 2308 params);
2239 if (params->has_optional_positional_parameters) { 2309 if (params->has_optional_positional_parameters) {
2240 CheckToken(Token::kRBRACK, "',' or ']' expected"); 2310 CheckToken(Token::kRBRACK, "',' or ']' expected");
2241 } else { 2311 } else {
2242 CheckToken(Token::kRBRACE, "',' or '}' expected"); 2312 CheckToken(Token::kRBRACE, "',' or '}' expected");
2243 } 2313 }
2244 ConsumeToken(); // ']' or '}'. 2314 ConsumeToken(); // ']' or '}'.
2245 } 2315 }
2246 if ((CurrentToken() != Token::kRPAREN) && 2316 if ((CurrentToken() != Token::kRPAREN) &&
2247 !params->has_optional_positional_parameters && 2317 !params->has_optional_positional_parameters &&
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 // The parser adds an implicit default constructor when a class 3253 // The parser adds an implicit default constructor when a class
3184 // does not have any explicit constructor or factory (see 3254 // does not have any explicit constructor or factory (see
3185 // Parser::AddImplicitConstructor). 3255 // Parser::AddImplicitConstructor).
3186 // There is no source text to parse. We just build the 3256 // There is no source text to parse. We just build the
3187 // sequence node by hand. 3257 // sequence node by hand.
3188 return MakeImplicitConstructor(func); 3258 return MakeImplicitConstructor(func);
3189 } 3259 }
3190 3260
3191 OpenFunctionBlock(func); 3261 OpenFunctionBlock(func);
3192 ParamList params; 3262 ParamList params;
3193 const bool allow_explicit_default_values = true;
3194 ASSERT(CurrentToken() == Token::kLPAREN); 3263 ASSERT(CurrentToken() == Token::kLPAREN);
3195 3264
3196 // Add implicit receiver parameter which is passed the allocated 3265 // Add implicit receiver parameter which is passed the allocated
3197 // but uninitialized instance to construct. 3266 // but uninitialized instance to construct.
3198 ASSERT(current_class().raw() == func.Owner()); 3267 ASSERT(current_class().raw() == func.Owner());
3199 params.AddReceiver(ReceiverType(current_class()), func.token_pos()); 3268 params.AddReceiver(ReceiverType(current_class()), func.token_pos());
3200 3269
3201 if (func.is_const()) { 3270 if (func.is_const()) {
3202 params.SetImplicitlyFinal(); 3271 params.SetImplicitlyFinal();
3203 } 3272 }
3204 ParseFormalParameterList(allow_explicit_default_values, false, &params); 3273 const bool use_function_type_syntax = false;
3274 const bool allow_explicit_default_values = true;
3275 const bool evaluate_metadata = false;
3276 ParseFormalParameterList(use_function_type_syntax,
3277 allow_explicit_default_values, evaluate_metadata,
3278 &params);
3279 FinalizeFormalParameterTypes(&params);
3205 3280
3206 SetupDefaultsForOptionalParams(params); 3281 SetupDefaultsForOptionalParams(params);
3207 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 3282 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
3208 ASSERT(func.NumParameters() == params.parameters->length());
3209 3283
3210 // Now populate function scope with the formal parameters. 3284 // Now populate function scope with the formal parameters.
3211 AddFormalParamsToScope(&params, current_block_->scope); 3285 AddFormalParamsToScope(&params, current_block_->scope);
3212 3286
3213 const bool is_redirecting_constructor = 3287 const bool is_redirecting_constructor =
3214 (CurrentToken() == Token::kCOLON) && 3288 (CurrentToken() == Token::kCOLON) &&
3215 ((LookaheadToken(1) == Token::kTHIS) && 3289 ((LookaheadToken(1) == Token::kTHIS) &&
3216 ((LookaheadToken(2) == Token::kLPAREN) || 3290 ((LookaheadToken(2) == Token::kLPAREN) ||
3217 ((LookaheadToken(2) == Token::kPERIOD) && 3291 ((LookaheadToken(2) == Token::kPERIOD) &&
3218 (LookaheadToken(4) == Token::kLPAREN)))); 3292 (LookaheadToken(4) == Token::kLPAREN))));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3376 // The first parameter of a factory is the TypeArguments vector of 3450 // The first parameter of a factory is the TypeArguments vector of
3377 // the type of the instance to be allocated. 3451 // the type of the instance to be allocated.
3378 params.AddFinalParameter(TokenPos(), &Symbols::TypeArgumentsParameter(), 3452 params.AddFinalParameter(TokenPos(), &Symbols::TypeArgumentsParameter(),
3379 &Object::dynamic_type()); 3453 &Object::dynamic_type());
3380 } 3454 }
3381 // Expect the parameter list unless this is a getter function, or the 3455 // Expect the parameter list unless this is a getter function, or the
3382 // body closure of an async or generator getter function. 3456 // body closure of an async or generator getter function.
3383 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction() || 3457 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction() ||
3384 (func.is_generated_body() && 3458 (func.is_generated_body() &&
3385 Function::Handle(func.parent_function()).IsGetterFunction())); 3459 Function::Handle(func.parent_function()).IsGetterFunction()));
3386 const bool allow_explicit_default_values = true;
3387 if (func.IsGetterFunction()) { 3460 if (func.IsGetterFunction()) {
3388 // Populate function scope with the formal parameters. Since in this case 3461 // Populate function scope with the formal parameters. Since in this case
3389 // we are compiling a getter this will at most populate the receiver. 3462 // we are compiling a getter this will at most populate the receiver.
3390 AddFormalParamsToScope(&params, current_block_->scope); 3463 AddFormalParamsToScope(&params, current_block_->scope);
3391 } else if (func.IsAsyncClosure()) { 3464 } else if (func.IsAsyncClosure()) {
3392 AddAsyncClosureParameters(&params); 3465 AddAsyncClosureParameters(&params);
3393 SetupDefaultsForOptionalParams(params); 3466 SetupDefaultsForOptionalParams(params);
3394 AddFormalParamsToScope(&params, current_block_->scope); 3467 AddFormalParamsToScope(&params, current_block_->scope);
3395 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 3468 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
3396 ASSERT(func.NumParameters() == params.parameters->length()); 3469 ASSERT(func.NumParameters() == params.parameters->length());
(...skipping 20 matching lines...) Expand all
3417 AddFormalParamsToScope(&params, current_block_->scope); 3490 AddFormalParamsToScope(&params, current_block_->scope);
3418 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 3491 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
3419 ASSERT(func.NumParameters() == params.parameters->length()); 3492 ASSERT(func.NumParameters() == params.parameters->length());
3420 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { 3493 if (!Function::Handle(func.parent_function()).IsGetterFunction()) {
3421 // Skip formal parameters. They are accessed as context variables. 3494 // Skip formal parameters. They are accessed as context variables.
3422 // Parsing them again (and discarding them) does not work in case of 3495 // Parsing them again (and discarding them) does not work in case of
3423 // default values with same name as already parsed formal parameter. 3496 // default values with same name as already parsed formal parameter.
3424 SkipToMatchingParenthesis(); 3497 SkipToMatchingParenthesis();
3425 } 3498 }
3426 } else { 3499 } else {
3427 ParseFormalParameterList(allow_explicit_default_values, false, &params); 3500 const bool use_function_type_syntax = false;
3501 const bool allow_explicit_default_values = true;
3502 const bool evaluate_metadata = false;
3503 ParseFormalParameterList(use_function_type_syntax,
3504 allow_explicit_default_values, evaluate_metadata,
3505 &params);
3506 if (!is_top_level_) {
3507 FinalizeFormalParameterTypes(&params);
3508 }
3428 3509
3429 // The number of parameters and their type are not yet set in local 3510 // The number of parameters and their type are not yet set in local
3430 // functions, since they are not 'top-level' parsed. 3511 // functions, since they are not 'top-level' parsed.
3431 // However, they are already set when the local function is compiled, since 3512 // However, they are already set when the local function is compiled, since
3432 // the local function was parsed when its parent was compiled. 3513 // the local function was parsed when its parent was compiled.
3433 if (func.parameter_types() == Object::empty_array().raw()) { 3514 if (func.parameter_types() == Object::empty_array().raw()) {
3434 AddFormalParamsToFunction(&params, func); 3515 AddFormalParamsToFunction(&params, func);
3435 } 3516 }
3517 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func);
3518 if (!is_top_level_) {
3519 ClassFinalizer::FinalizeSignature(current_class(), func);
3520 }
3436 SetupDefaultsForOptionalParams(params); 3521 SetupDefaultsForOptionalParams(params);
3437 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 3522 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
3438 ASSERT(func.NumParameters() == params.parameters->length());
3439 3523
3440 // Populate function scope with the formal parameters. 3524 // Populate function scope with the formal parameters.
3441 AddFormalParamsToScope(&params, current_block_->scope); 3525 AddFormalParamsToScope(&params, current_block_->scope);
3442 3526
3443 if (I->type_checks() && (FunctionLevel() > 0)) { 3527 if (I->type_checks() && (FunctionLevel() > 0)) {
3444 // We are parsing, but not compiling, a local function. 3528 // We are parsing, but not compiling, a local function.
3445 // The instantiator may be required at run time for generic type checks. 3529 // The instantiator may be required at run time for generic type checks.
3446 if (IsInstantiatorRequired()) { 3530 if (IsInstantiatorRequired()) {
3447 // Make sure that the receiver of the enclosing instance function 3531 // Make sure that the receiver of the enclosing instance function
3448 // (or implicit first parameter of an enclosing factory) is marked as 3532 // (or implicit first parameter of an enclosing factory) is marked as
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 if (method->IsFactoryOrConstructor()) { 3817 if (method->IsFactoryOrConstructor()) {
3734 ReportError(method->name_pos, "constructor cannot be generic"); 3818 ReportError(method->name_pos, "constructor cannot be generic");
3735 } 3819 }
3736 if (method->IsGetter() || method->IsSetter()) { 3820 if (method->IsGetter() || method->IsSetter()) {
3737 ReportError(type_param_pos, "%s cannot be generic", 3821 ReportError(type_param_pos, "%s cannot be generic",
3738 method->IsGetter() ? "getter" : "setter"); 3822 method->IsGetter() ? "getter" : "setter");
3739 } 3823 }
3740 ParseTypeParameters(false); // Not parameterizing class, but function. 3824 ParseTypeParameters(false); // Not parameterizing class, but function.
3741 } 3825 }
3742 3826
3743 // Now that type parameters are declared, the result type can be resolved.
3744 if (!method->type->IsResolved()) {
3745 AbstractType& type = AbstractType::ZoneHandle(Z, method->type->raw());
3746 ResolveType(ClassFinalizer::kResolveTypeParameters, &type);
3747 method->type = &type;
3748 }
3749
3750 // Parse the formal parameters. 3827 // Parse the formal parameters.
3751 const bool are_implicitly_final = method->has_const;
3752 const bool allow_explicit_default_values = true;
3753 const TokenPosition formal_param_pos = TokenPos(); 3828 const TokenPosition formal_param_pos = TokenPos();
3754 method->params.Clear(); 3829 method->params.Clear();
3755 // Static functions do not have a receiver. 3830 // Static functions do not have a receiver.
3756 // The first parameter of a factory is the TypeArguments vector of 3831 // The first parameter of a factory is the TypeArguments vector of
3757 // the type of the instance to be allocated. 3832 // the type of the instance to be allocated.
3758 if (!method->has_static || method->IsConstructor()) { 3833 if (!method->has_static || method->IsConstructor()) {
3759 method->params.AddReceiver(ReceiverType(current_class()), formal_param_pos); 3834 method->params.AddReceiver(ReceiverType(current_class()), formal_param_pos);
3760 } else if (method->IsFactory()) { 3835 } else if (method->IsFactory()) {
3761 method->params.AddFinalParameter(formal_param_pos, 3836 method->params.AddFinalParameter(formal_param_pos,
3762 &Symbols::TypeArgumentsParameter(), 3837 &Symbols::TypeArgumentsParameter(),
3763 &Object::dynamic_type()); 3838 &Object::dynamic_type());
3764 } 3839 }
3765 if (are_implicitly_final) { 3840 if (method->has_const) {
3766 method->params.SetImplicitlyFinal(); 3841 method->params.SetImplicitlyFinal();
3767 } 3842 }
3768 if (!method->IsGetter()) { 3843 if (!method->IsGetter()) {
3769 ParseFormalParameterList(allow_explicit_default_values, false, 3844 const bool use_function_type_syntax = false;
3845 const bool allow_explicit_default_values = true;
3846 const bool evaluate_metadata = false;
3847 ParseFormalParameterList(use_function_type_syntax,
3848 allow_explicit_default_values, evaluate_metadata,
3770 &method->params); 3849 &method->params);
3771 } 3850 }
3772 3851
3773 // Now that we know the parameter list, we can distinguish between the 3852 // Now that we know the parameter list, we can distinguish between the
3774 // unary and binary operator -. 3853 // unary and binary operator -.
3775 if (method->has_operator) { 3854 if (method->has_operator) {
3776 if ((method->operator_token == Token::kSUB) && 3855 if ((method->operator_token == Token::kSUB) &&
3777 (method->params.num_fixed_parameters == 1)) { 3856 (method->params.num_fixed_parameters == 1)) {
3778 // Patch up name for unary operator - so it does not clash with the 3857 // Patch up name for unary operator - so it does not clash with the
3779 // name for binary operator -. 3858 // name for binary operator -.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) { 4082 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) {
4004 ReportError(modifier_pos, 4083 ReportError(modifier_pos,
4005 "abstract function '%s' may not be async, async* or sync*", 4084 "abstract function '%s' may not be async, async* or sync*",
4006 method->name->ToCString()); 4085 method->name->ToCString());
4007 } 4086 }
4008 4087
4009 // Update function object. 4088 // Update function object.
4010 func.set_name(*method->name); 4089 func.set_name(*method->name);
4011 func.set_is_abstract(method->has_abstract); 4090 func.set_is_abstract(method->has_abstract);
4012 func.set_is_native(method->has_native); 4091 func.set_is_native(method->has_native);
4013 func.set_result_type(*method->type); 4092 func.set_result_type(*method->type); // May set parent_function in type.
4014 func.set_end_token_pos(method_end_pos); 4093 func.set_end_token_pos(method_end_pos);
4015 func.set_is_redirecting(is_redirecting); 4094 func.set_is_redirecting(is_redirecting);
4016 func.set_modifier(async_modifier); 4095 func.set_modifier(async_modifier);
4017 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { 4096 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) {
4018 func.set_is_reflectable(false); 4097 func.set_is_reflectable(false);
4019 } 4098 }
4020 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) { 4099 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) {
4021 // Currently, we just ignore the patch annotation. If the function 4100 // Currently, we just ignore the patch annotation. If the function
4022 // name already exists in the patched class, this function will replace 4101 // name already exists in the patched class, this function will replace
4023 // the one in the patched class. 4102 // the one in the patched class.
4024 method->metadata_pos = TokenPosition::kNoSource; 4103 method->metadata_pos = TokenPosition::kNoSource;
4025 } 4104 }
4026 if (FLAG_enable_mirrors && (method->metadata_pos.IsReal())) { 4105 if (FLAG_enable_mirrors && (method->metadata_pos.IsReal())) {
4027 library_.AddFunctionMetadata(func, method->metadata_pos); 4106 library_.AddFunctionMetadata(func, method->metadata_pos);
4028 } 4107 }
4029 if (method->has_native) { 4108 if (method->has_native) {
4030 func.set_native_name(*native_name); 4109 func.set_native_name(*native_name);
4031 } 4110 }
4032 4111
4033 // If this method is a redirecting factory, set the redirection information. 4112 // If this method is a redirecting factory, set the redirection information.
4034 if (!redirection_type.IsNull()) { 4113 if (!redirection_type.IsNull()) {
4035 ASSERT(func.IsFactory()); 4114 ASSERT(func.IsFactory());
4036 func.SetRedirectionType(redirection_type); 4115 func.SetRedirectionType(redirection_type);
4037 if (!redirection_identifier.IsNull()) { 4116 if (!redirection_identifier.IsNull()) {
4038 func.SetRedirectionIdentifier(redirection_identifier); 4117 func.SetRedirectionIdentifier(redirection_identifier);
4039 } 4118 }
4040 } 4119 }
4041 4120
4042 // No need to resolve parameter types yet, or add parameters to local scope.
4043 ASSERT(is_top_level_); 4121 ASSERT(is_top_level_);
4044 AddFormalParamsToFunction(&method->params, func); 4122 AddFormalParamsToFunction(&method->params, func);
4045 ASSERT(innermost_function().raw() == func.raw()); 4123 ASSERT(innermost_function().raw() == func.raw());
4046 innermost_function_ = Function::null(); 4124 innermost_function_ = Function::null();
4125 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func);
4047 members->AddFunction(func); 4126 members->AddFunction(func);
4048 } 4127 }
4049 4128
4050 4129
4051 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { 4130 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) {
4052 TRACE_PARSER("ParseFieldDefinition"); 4131 TRACE_PARSER("ParseFieldDefinition");
4053 // The parser has read the first field name and is now at the token 4132 // The parser has read the first field name and is now at the token
4054 // after the field name. 4133 // after the field name.
4055 ASSERT(CurrentToken() == Token::kSEMICOLON || 4134 ASSERT(CurrentToken() == Token::kSEMICOLON ||
4056 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); 4135 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
4176 /* is_abstract = */ false, 4255 /* is_abstract = */ false,
4177 /* is_external = */ false, 4256 /* is_external = */ false,
4178 /* is_native = */ false, current_class(), 4257 /* is_native = */ false, current_class(),
4179 field->name_pos); 4258 field->name_pos);
4180 ParamList params; 4259 ParamList params;
4181 ASSERT(current_class().raw() == getter.Owner()); 4260 ASSERT(current_class().raw() == getter.Owner());
4182 params.AddReceiver(ReceiverType(current_class()), field->name_pos); 4261 params.AddReceiver(ReceiverType(current_class()), field->name_pos);
4183 getter.set_result_type(*field->type); 4262 getter.set_result_type(*field->type);
4184 getter.set_is_debuggable(false); 4263 getter.set_is_debuggable(false);
4185 AddFormalParamsToFunction(&params, getter); 4264 AddFormalParamsToFunction(&params, getter);
4265 ResolveSignature(ClassFinalizer::kResolveTypeParameters, getter);
4186 members->AddFunction(getter); 4266 members->AddFunction(getter);
4187 if (!field->has_final) { 4267 if (!field->has_final) {
4188 // Build a setter accessor for non-const fields. 4268 // Build a setter accessor for non-const fields.
4189 String& setter_name = 4269 String& setter_name =
4190 String::Handle(Z, Field::SetterSymbol(*field->name)); 4270 String::Handle(Z, Field::SetterSymbol(*field->name));
4191 setter = Function::New(setter_name, RawFunction::kImplicitSetter, 4271 setter = Function::New(setter_name, RawFunction::kImplicitSetter,
4192 field->has_static, field->has_final, 4272 field->has_static, field->has_final,
4193 /* is_abstract = */ false, 4273 /* is_abstract = */ false,
4194 /* is_external = */ false, 4274 /* is_external = */ false,
4195 /* is_native = */ false, current_class(), 4275 /* is_native = */ false, current_class(),
4196 field->name_pos); 4276 field->name_pos);
4197 ParamList params; 4277 ParamList params;
4198 ASSERT(current_class().raw() == setter.Owner()); 4278 ASSERT(current_class().raw() == setter.Owner());
4199 params.AddReceiver(ReceiverType(current_class()), field->name_pos); 4279 params.AddReceiver(ReceiverType(current_class()), field->name_pos);
4200 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); 4280 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type);
4201 setter.set_result_type(Object::void_type()); 4281 setter.set_result_type(Object::void_type());
4202 setter.set_is_debuggable(false); 4282 setter.set_is_debuggable(false);
4203 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { 4283 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) {
4204 setter.set_is_reflectable(false); 4284 setter.set_is_reflectable(false);
4205 } 4285 }
4206 AddFormalParamsToFunction(&params, setter); 4286 AddFormalParamsToFunction(&params, setter);
4287 ResolveSignature(ClassFinalizer::kResolveTypeParameters, setter);
4207 members->AddFunction(setter); 4288 members->AddFunction(setter);
4208 } 4289 }
4209 } 4290 }
4210 4291
4211 if (CurrentToken() != Token::kCOMMA) { 4292 if (CurrentToken() != Token::kCOMMA) {
4212 break; 4293 break;
4213 } 4294 }
4214 ConsumeToken(); 4295 ConsumeToken();
4215 field->name_pos = this->TokenPos(); 4296 field->name_pos = this->TokenPos();
4216 field->name = ExpectIdentifier("field name expected"); 4297 field->name = ExpectIdentifier("field name expected");
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
4317 ReportError("void not expected"); 4398 ReportError("void not expected");
4318 } 4399 }
4319 ConsumeToken(); 4400 ConsumeToken();
4320 ASSERT(member.type == NULL); 4401 ASSERT(member.type == NULL);
4321 member.type = &Object::void_type(); 4402 member.type = &Object::void_type();
4322 } else { 4403 } else {
4323 bool found_type = false; 4404 bool found_type = false;
4324 { 4405 {
4325 // Lookahead to determine whether the next tokens are a return type. 4406 // Lookahead to determine whether the next tokens are a return type.
4326 TokenPosScope saved_pos(this); 4407 TokenPosScope saved_pos(this);
4327 if (TryParseReturnType()) { 4408 if (TryParseType(true)) {
4328 if (IsIdentifier() || (CurrentToken() == Token::kGET) || 4409 if (IsIdentifier() || (CurrentToken() == Token::kGET) ||
4329 (CurrentToken() == Token::kSET) || 4410 (CurrentToken() == Token::kSET) ||
4330 (CurrentToken() == Token::kOPERATOR)) { 4411 (CurrentToken() == Token::kOPERATOR)) {
4331 found_type = true; 4412 found_type = true;
4332 } 4413 }
4333 } 4414 }
4334 } 4415 }
4335 if (found_type) { 4416 if (found_type) {
4336 // It is too early to resolve the type here, since it can be a result type 4417 // It is too early to resolve the type here, since it can be a result type
4337 // referring to a not yet declared function type parameter. 4418 // referring to a not yet declared function type parameter.
4338 member.type = &AbstractType::ZoneHandle( 4419 member.type = &AbstractType::ZoneHandle(
4339 Z, ParseType(ClassFinalizer::kDoNotResolve)); 4420 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kDoNotResolve));
4340 } 4421 }
4341 } 4422 }
4342 4423
4343 // Optionally parse a (possibly named) constructor name or factory. 4424 // Optionally parse a (possibly named) constructor name or factory.
4344 if (IsIdentifier() && 4425 if (IsIdentifier() &&
4345 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { 4426 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
4346 member.name_pos = TokenPos(); 4427 member.name_pos = TokenPos();
4347 member.name = CurrentLiteral(); // Unqualified identifier. 4428 member.name = CurrentLiteral(); // Unqualified identifier.
4348 ConsumeToken(); 4429 ConsumeToken();
4349 if (member.has_factory) { 4430 if (member.has_factory) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 ReportError("identifier expected"); 4523 ReportError("identifier expected");
4443 } 4524 }
4444 4525
4445 ASSERT(member.name != NULL); 4526 ASSERT(member.name != NULL);
4446 if (IsParameterPart() || member.IsGetter()) { 4527 if (IsParameterPart() || member.IsGetter()) {
4447 // Constructor or method. 4528 // Constructor or method.
4448 if (member.type == NULL) { 4529 if (member.type == NULL) {
4449 member.type = &Object::dynamic_type(); 4530 member.type = &Object::dynamic_type();
4450 } 4531 }
4451 ASSERT(member.IsFactory() == member.has_factory); 4532 ASSERT(member.IsFactory() == member.has_factory);
4452 // Note that member.type may still be unresolved. 4533 // Note that member.type may still be unresolved and may refer to not yet
4534 // parsed function type parameters.
4453 ParseMethodOrConstructor(members, &member); 4535 ParseMethodOrConstructor(members, &member);
4454 } else if (CurrentToken() == Token::kSEMICOLON || 4536 } else if (CurrentToken() == Token::kSEMICOLON ||
4455 CurrentToken() == Token::kCOMMA || 4537 CurrentToken() == Token::kCOMMA ||
4456 CurrentToken() == Token::kASSIGN) { 4538 CurrentToken() == Token::kASSIGN) {
4457 // Field definition. 4539 // Field definition.
4458 if (member.has_const) { 4540 if (member.has_const) {
4459 // const fields are implicitly final. 4541 // const fields are implicitly final.
4460 member.has_final = true; 4542 member.has_final = true;
4461 } 4543 }
4462 if (member.type == NULL) { 4544 if (member.type == NULL) {
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 /* is_static = */ false, 4903 /* is_static = */ false,
4822 /* is_const = */ true, 4904 /* is_const = */ true,
4823 /* is_abstract = */ false, 4905 /* is_abstract = */ false,
4824 /* is_external = */ false, 4906 /* is_external = */ false,
4825 /* is_native = */ false, cls, cls.token_pos()); 4907 /* is_native = */ false, cls, cls.token_pos());
4826 getter.set_result_type(int_type); 4908 getter.set_result_type(int_type);
4827 getter.set_is_debuggable(false); 4909 getter.set_is_debuggable(false);
4828 ParamList params; 4910 ParamList params;
4829 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); 4911 params.AddReceiver(&Object::dynamic_type(), cls.token_pos());
4830 AddFormalParamsToFunction(&params, getter); 4912 AddFormalParamsToFunction(&params, getter);
4913 ResolveSignature(ClassFinalizer::kResolveTypeParameters, getter);
4831 enum_members.AddFunction(getter); 4914 enum_members.AddFunction(getter);
4832 4915
4833 ASSERT(IsIdentifier()); 4916 ASSERT(IsIdentifier());
4834 ASSERT(CurrentLiteral()->raw() == cls.Name()); 4917 ASSERT(CurrentLiteral()->raw() == cls.Name());
4835 4918
4836 ConsumeToken(); // Enum type name. 4919 ConsumeToken(); // Enum type name.
4837 ExpectToken(Token::kLBRACE); 4920 ExpectToken(Token::kLBRACE);
4838 Field& enum_value = Field::Handle(Z); 4921 Field& enum_value = Field::Handle(Z);
4839 intptr_t i = 0; 4922 intptr_t i = 0;
4840 GrowableArray<String*> declared_names(8); 4923 GrowableArray<String*> declared_names(8);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4935 /* is_static = */ false, 5018 /* is_static = */ false,
4936 /* is_const = */ true, 5019 /* is_const = */ true,
4937 /* is_abstract = */ false, 5020 /* is_abstract = */ false,
4938 /* is_external = */ false, 5021 /* is_external = */ false,
4939 /* is_native = */ false, cls, cls.token_pos()); 5022 /* is_native = */ false, cls, cls.token_pos());
4940 name_getter.set_result_type(string_type); 5023 name_getter.set_result_type(string_type);
4941 name_getter.set_is_debuggable(false); 5024 name_getter.set_is_debuggable(false);
4942 ParamList name_params; 5025 ParamList name_params;
4943 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); 5026 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos());
4944 AddFormalParamsToFunction(&name_params, name_getter); 5027 AddFormalParamsToFunction(&name_params, name_getter);
5028 ResolveSignature(ClassFinalizer::kResolveTypeParameters, name_getter);
4945 enum_members.AddFunction(name_getter); 5029 enum_members.AddFunction(name_getter);
4946 5030
4947 // Clone the toString() function from the helper class. 5031 // Clone the toString() function from the helper class.
4948 Function& to_string_func = Function::Handle( 5032 Function& to_string_func = Function::Handle(
4949 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); 5033 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString()));
4950 ASSERT(!to_string_func.IsNull()); 5034 ASSERT(!to_string_func.IsNull());
4951 to_string_func = to_string_func.Clone(cls); 5035 to_string_func = to_string_func.Clone(cls);
4952 enum_members.AddFunction(to_string_func); 5036 enum_members.AddFunction(to_string_func);
4953 5037
4954 // Clone the hashCode getter function from the helper class. 5038 // Clone the hashCode getter function from the helper class.
(...skipping 29 matching lines...) Expand all
4984 if (library_.is_dart_scheme() && library_.IsPrivate(ctor_name)) { 5068 if (library_.is_dart_scheme() && library_.IsPrivate(ctor_name)) {
4985 ctor.set_is_reflectable(false); 5069 ctor.set_is_reflectable(false);
4986 } 5070 }
4987 5071
4988 ParamList params; 5072 ParamList params;
4989 // Add implicit 'this' parameter. 5073 // Add implicit 'this' parameter.
4990 const AbstractType* receiver_type = ReceiverType(cls); 5074 const AbstractType* receiver_type = ReceiverType(cls);
4991 params.AddReceiver(receiver_type, cls.token_pos()); 5075 params.AddReceiver(receiver_type, cls.token_pos());
4992 5076
4993 AddFormalParamsToFunction(&params, ctor); 5077 AddFormalParamsToFunction(&params, ctor);
5078 ctor.set_result_type(Object::dynamic_type());
5079 ResolveSignature(ClassFinalizer::kResolveTypeParameters, ctor);
4994 // The body of the constructor cannot modify the type of the constructed 5080 // The body of the constructor cannot modify the type of the constructed
4995 // instance, which is passed in as the receiver. 5081 // instance, which is passed in as the receiver.
4996 ctor.set_result_type(*receiver_type); 5082 ctor.set_result_type(*receiver_type);
4997 cls.AddFunction(ctor); 5083 cls.AddFunction(ctor);
4998 } 5084 }
4999 5085
5000 5086
5001 // Check for cycles in constructor redirection. 5087 // Check for cycles in constructor redirection.
5002 void Parser::CheckConstructors(ClassDesc* class_desc) { 5088 void Parser::CheckConstructors(ClassDesc* class_desc) {
5003 // Check for cycles in constructor redirection. 5089 // Check for cycles in constructor redirection.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5080 ParseInterfaceList(mixin_application); 5166 ParseInterfaceList(mixin_application);
5081 } 5167 }
5082 ExpectSemicolon(); 5168 ExpectSemicolon();
5083 pending_classes.Add(mixin_application, Heap::kOld); 5169 pending_classes.Add(mixin_application, Heap::kOld);
5084 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { 5170 if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
5085 library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos); 5171 library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos);
5086 } 5172 }
5087 } 5173 }
5088 5174
5089 5175
5090 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(". 5176 // Look ahead to detect if we are seeing ident [ TypeParameters ] ("(" | "=").
5091 // We need this lookahead to distinguish between the optional return type 5177 // We need this lookahead to distinguish between the optional return type
5092 // and the alias name of a function type alias. 5178 // and the alias name of a function type alias.
5093 // Token position remains unchanged. 5179 // Token position remains unchanged.
5094 bool Parser::IsFunctionTypeAliasName() { 5180 bool Parser::IsFunctionTypeAliasName(bool* use_function_type_syntax) {
5095 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { 5181 if (IsIdentifier()) {
5096 return true; 5182 const Token::Kind ahead = LookaheadToken(1);
5183 if ((ahead == Token::kLPAREN) || (ahead == Token::kASSIGN)) {
5184 *use_function_type_syntax = (ahead == Token::kASSIGN);
5185 return true;
5186 }
5097 } 5187 }
5098 const TokenPosScope saved_pos(this); 5188 const TokenPosScope saved_pos(this);
5099 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) { 5189 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) {
5100 ConsumeToken(); 5190 ConsumeToken();
5101 if (TryParseTypeParameters() && (CurrentToken() == Token::kLPAREN)) { 5191 if (TryParseTypeParameters()) {
5102 return true; 5192 const Token::Kind current = CurrentToken();
5193 if ((current == Token::kLPAREN) || (current == Token::kASSIGN)) {
5194 *use_function_type_syntax = (current == Token::kASSIGN);
5195 return true;
5196 }
5103 } 5197 }
5104 } 5198 }
5199 *use_function_type_syntax = false;
5105 return false; 5200 return false;
5106 } 5201 }
5107 5202
5108 5203
5109 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, 5204 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes,
5110 const Object& tl_owner, 5205 const Object& tl_owner,
5111 TokenPosition metadata_pos) { 5206 TokenPosition metadata_pos) {
5112 TRACE_PARSER("ParseTypedef"); 5207 TRACE_PARSER("ParseTypedef");
5113 TokenPosition declaration_pos = 5208 TokenPosition declaration_pos =
5114 metadata_pos.IsReal() ? metadata_pos : TokenPos(); 5209 metadata_pos.IsReal() ? metadata_pos : TokenPos();
5115 ExpectToken(Token::kTYPEDEF); 5210 ExpectToken(Token::kTYPEDEF);
5116 5211
5117 // Parse the result type of the function type. 5212 // Distinguish between two possible typedef forms:
5118 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); 5213 // 1) returnType? identifier typeParameters? formalParameterList ’;’
5214 // 2) identifier typeParameters? '=' functionType ’;’
5215
5216 bool use_function_type_syntax; // Set to false for form 1, true for form 2.
5217
5218 // If present, parse the result type of the function type.
5219 AbstractType& result_type = Type::Handle(Z);
5119 if (CurrentToken() == Token::kVOID) { 5220 if (CurrentToken() == Token::kVOID) {
5120 ConsumeToken(); 5221 ConsumeToken();
5121 result_type = Type::VoidType(); 5222 result_type = Type::VoidType();
5122 } else if (!IsFunctionTypeAliasName()) { 5223 use_function_type_syntax = false;
5224 } else if (!IsFunctionTypeAliasName(&use_function_type_syntax)) {
5123 // Type annotations in typedef are never ignored, even in production mode. 5225 // Type annotations in typedef are never ignored, even in production mode.
5124 // Wait until we have an owner class before resolving the result type. 5226 // Wait until we have an owner class before resolving the result type.
5125 result_type = ParseType(ClassFinalizer::kDoNotResolve); 5227 result_type = ParseType(ClassFinalizer::kDoNotResolve);
5228 ASSERT(!use_function_type_syntax);
5126 } 5229 }
5127 5230
5128 const TokenPosition alias_name_pos = TokenPos(); 5231 const TokenPosition alias_name_pos = TokenPos();
5129 const String* alias_name = 5232 const String* alias_name =
5130 ExpectUserDefinedTypeIdentifier("function alias name expected"); 5233 ExpectUserDefinedTypeIdentifier("function alias name expected");
5131 5234
5132 // Lookup alias name and report an error if it is already defined in 5235 // Lookup alias name and report an error if it is already defined in
5133 // the library scope. 5236 // the library scope.
5134 const Object& obj = 5237 const Object& obj =
5135 Object::Handle(Z, library_.LookupLocalObject(*alias_name)); 5238 Object::Handle(Z, library_.LookupLocalObject(*alias_name));
5136 if (!obj.IsNull()) { 5239 if (!obj.IsNull()) {
5137 ReportError(alias_name_pos, "'%s' is already defined", 5240 ReportError(alias_name_pos, "'%s' is already defined",
5138 alias_name->ToCString()); 5241 alias_name->ToCString());
5139 } 5242 }
5140 5243
5141 // Create the function type alias scope class. It will be linked to its 5244 // Create the function type alias scope class. It will be linked to its
5142 // signature function after it has been parsed. The type parameters, in order 5245 // signature function after it has been parsed. The type parameters, in order
5143 // to be properly finalized, need to be associated to this scope class as 5246 // to be properly finalized, need to be associated to this scope class as
5144 // they are parsed. 5247 // they are parsed.
5145 const Class& function_type_alias = Class::Handle( 5248 const Class& function_type_alias = Class::Handle(
5146 Z, Class::New(library_, *alias_name, script_, declaration_pos)); 5249 Z, Class::New(library_, *alias_name, script_, declaration_pos));
5147 function_type_alias.set_is_synthesized_class(); 5250 function_type_alias.set_is_synthesized_class();
5148 function_type_alias.set_is_abstract(); 5251 function_type_alias.set_is_abstract();
5149 function_type_alias.set_is_prefinalized(); 5252 function_type_alias.set_is_prefinalized();
5150 library_.AddClass(function_type_alias); 5253 library_.AddClass(function_type_alias);
5254 ASSERT(current_class().IsTopLevel());
5151 set_current_class(function_type_alias); 5255 set_current_class(function_type_alias);
5152 // Parse the type parameters of the typedef class. 5256 // Parse the type parameters of the typedef class.
5153 ParseTypeParameters(true); // Parameterizing current class. 5257 ParseTypeParameters(true); // Parameterizing current class.
5154 // At this point, the type parameters have been parsed, so we can resolve the 5258 Function& signature_function = Function::Handle(Z);
5155 // result type. 5259 ASSERT(innermost_function().IsNull());
5156 if (!result_type.IsNull()) { 5260 if (use_function_type_syntax) {
5157 ResolveType(ClassFinalizer::kResolveTypeParameters, &result_type); 5261 ExpectToken(Token::kASSIGN);
5262 ASSERT(result_type.IsNull()); // Not parsed yet.
5263 // Do not resolve types before the function type alias can be recognized as
5264 // a typedef class, so that correct promotion of function types can occur.
5265 const Type& function_type = Type::Handle(
5266 Z, ParseFunctionType(result_type, ClassFinalizer::kDoNotResolve));
5267 signature_function = function_type.signature();
5268 } else {
5269 signature_function =
5270 Function::NewSignatureFunction(function_type_alias, alias_name_pos);
5271 innermost_function_ = signature_function.raw();
5272 ParamList params;
5273 // Parse the formal parameters of the function type.
5274 CheckToken(Token::kLPAREN, "formal parameter list expected");
5275 // Add implicit closure object parameter.
5276 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
5277 &Object::dynamic_type());
5278 const bool allow_explicit_default_values = false;
5279 const bool evaluate_metadata = false;
5280 ParseFormalParameterList(use_function_type_syntax,
5281 allow_explicit_default_values, evaluate_metadata,
5282 &params);
5283 if (result_type.IsNull()) {
5284 result_type = Type::DynamicType();
5285 }
5286 signature_function.set_result_type(result_type);
5287 AddFormalParamsToFunction(&params, signature_function);
5288 ASSERT(innermost_function().raw() == signature_function.raw());
5289 innermost_function_ = Function::null();
5158 } 5290 }
5159 // Parse the formal parameters of the function type. 5291 ExpectSemicolon();
5160 CheckToken(Token::kLPAREN, "formal parameter list expected"); 5292 ASSERT(innermost_function().IsNull());
5161 ParamList func_params;
5162 5293
5163 // Add implicit closure object parameter.
5164 func_params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
5165 &Object::dynamic_type());
5166
5167 // Mark the current class as a typedef class (by setting its signature
5168 // function field to a non-null function) before parsing its formal parameters
5169 // so that parsed function types are aware that their owner class is a
5170 // typedef class.
5171 Function& signature_function = Function::Handle(
5172 Z, Function::NewSignatureFunction(function_type_alias, alias_name_pos));
5173 ASSERT(innermost_function().IsNull());
5174 innermost_function_ = signature_function.raw();
5175 // Set the signature function in the function type alias class. 5294 // Set the signature function in the function type alias class.
5176 function_type_alias.set_signature_function(signature_function); 5295 function_type_alias.set_signature_function(signature_function);
5177 5296
5178 const bool no_explicit_default_values = false; 5297 // At this point, all function type parameters have been parsed and the class
5179 ParseFormalParameterList(no_explicit_default_values, false, &func_params); 5298 // function_type_alias is recognized as a typedef, so we can resolve all type
5180 ExpectSemicolon(); 5299 // parameters in the signature type defined by the typedef.
5181 signature_function.set_result_type(result_type); 5300 AbstractType& function_type =
5182 AddFormalParamsToFunction(&func_params, signature_function); 5301 Type::Handle(Z, signature_function.SignatureType());
5183 5302 ASSERT(current_class().raw() == function_type_alias.raw());
5184 ASSERT(innermost_function().raw() == signature_function.raw()); 5303 ResolveType(ClassFinalizer::kResolveTypeParameters, &function_type);
5185 innermost_function_ = Function::null(); 5304 // Resolving does not replace type or signature.
5305 ASSERT(function_type_alias.signature_function() ==
5306 Type::Cast(function_type).signature());
5186 5307
5187 if (FLAG_trace_parser) { 5308 if (FLAG_trace_parser) {
5188 OS::Print("TopLevel parsing function type alias '%s'\n", 5309 OS::Print("TopLevel parsing function type alias '%s'\n",
5189 String::Handle(Z, signature_function.Signature()).ToCString()); 5310 String::Handle(Z, signature_function.Signature()).ToCString());
5190 } 5311 }
5191 // The alias should not be marked as finalized yet, since it needs to be 5312 // The alias should not be marked as finalized yet, since it needs to be
5192 // checked in the class finalizer for illegal self references. 5313 // checked in the class finalizer for illegal self references.
5193 ASSERT(!function_type_alias.is_finalized()); 5314 ASSERT(!function_type_alias.is_finalized());
5194 pending_classes.Add(function_type_alias, Heap::kOld); 5315 pending_classes.Add(function_type_alias, Heap::kOld);
5195 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { 5316 if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5245 } 5366 }
5246 } 5367 }
5247 return metadata_pos; 5368 return metadata_pos;
5248 } 5369 }
5249 5370
5250 5371
5251 void Parser::SkipTypeArguments() { 5372 void Parser::SkipTypeArguments() {
5252 if (CurrentToken() == Token::kLT) { 5373 if (CurrentToken() == Token::kLT) {
5253 do { 5374 do {
5254 ConsumeToken(); 5375 ConsumeToken();
5255 SkipType(false); 5376 SkipTypeOrFunctionType(false);
5256 } while (CurrentToken() == Token::kCOMMA); 5377 } while (CurrentToken() == Token::kCOMMA);
5257 Token::Kind token = CurrentToken(); 5378 Token::Kind token = CurrentToken();
5258 if ((token == Token::kGT) || (token == Token::kSHR)) { 5379 if ((token == Token::kGT) || (token == Token::kSHR)) {
5259 ConsumeRightAngleBracket(); 5380 ConsumeRightAngleBracket();
5260 } else { 5381 } else {
5261 ReportError("right angle bracket expected"); 5382 ReportError("right angle bracket expected");
5262 } 5383 }
5263 } 5384 }
5264 } 5385 }
5265 5386
5266 5387
5267 void Parser::SkipType(bool allow_void) { 5388 void Parser::SkipType(bool allow_void) {
5268 if (CurrentToken() == Token::kVOID) { 5389 if (CurrentToken() == Token::kVOID) {
5269 if (!allow_void) { 5390 if (!allow_void) {
5270 ReportError("'void' not allowed here"); 5391 ReportError("'void' not allowed here");
5271 } 5392 }
5272 ConsumeToken(); 5393 ConsumeToken();
5273 } else { 5394 } else {
5274 ExpectIdentifier("type name expected"); 5395 ExpectIdentifier("type name expected");
5275 if (CurrentToken() == Token::kPERIOD) { 5396 if (CurrentToken() == Token::kPERIOD) {
5276 ConsumeToken(); 5397 ConsumeToken();
5277 ExpectIdentifier("name expected"); 5398 ExpectIdentifier("name expected");
5278 } 5399 }
5279 SkipTypeArguments(); 5400 SkipTypeArguments();
5280 } 5401 }
5281 } 5402 }
5282 5403
5283 5404
5405 void Parser::SkipTypeOrFunctionType(bool allow_void) {
5406 if (CurrentToken() == Token::kVOID) {
5407 TokenPosition void_pos = TokenPos();
5408 ConsumeToken();
5409 // 'void' is always allowed as result type of a function type.
5410 if (!allow_void && !IsFunctionTypeSymbol()) {
5411 ReportError(void_pos, "'void' not allowed here");
5412 }
5413 } else if (!IsFunctionTypeSymbol()) {
5414 // Including 'Function' not followed by '(' or '<'.
5415 SkipType(false);
5416 }
5417 while (IsSymbol(Symbols::Function())) {
5418 ConsumeToken();
5419 SkipTypeArguments();
5420 if (CurrentToken() == Token::kLPAREN) {
5421 SkipToMatchingParenthesis();
5422 } else {
5423 ReportError("'(' expected");
5424 }
5425 }
5426 }
5427
5428
5284 void Parser::ParseTypeParameters(bool parameterizing_class) { 5429 void Parser::ParseTypeParameters(bool parameterizing_class) {
5285 TRACE_PARSER("ParseTypeParameters"); 5430 TRACE_PARSER("ParseTypeParameters");
5286 if (CurrentToken() == Token::kLT) { 5431 if (CurrentToken() == Token::kLT) {
5287 GrowableArray<AbstractType*> type_parameters_array(Z, 2); 5432 GrowableArray<AbstractType*> type_parameters_array(Z, 2);
5288 intptr_t index = 0; 5433 intptr_t index = 0;
5289 TypeParameter& type_parameter = TypeParameter::Handle(Z); 5434 TypeParameter& type_parameter = TypeParameter::Handle(Z);
5290 TypeParameter& existing_type_parameter = TypeParameter::Handle(Z); 5435 TypeParameter& existing_type_parameter = TypeParameter::Handle(Z);
5291 String& existing_type_parameter_name = String::Handle(Z); 5436 String& existing_type_parameter_name = String::Handle(Z);
5292 AbstractType& type_parameter_bound = Type::Handle(Z); 5437 AbstractType& type_parameter_bound = Type::Handle(Z);
5293 do { 5438 do {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
5369 5514
5370 5515
5371 RawTypeArguments* Parser::ParseTypeArguments( 5516 RawTypeArguments* Parser::ParseTypeArguments(
5372 ClassFinalizer::FinalizationKind finalization) { 5517 ClassFinalizer::FinalizationKind finalization) {
5373 TRACE_PARSER("ParseTypeArguments"); 5518 TRACE_PARSER("ParseTypeArguments");
5374 if (CurrentToken() == Token::kLT) { 5519 if (CurrentToken() == Token::kLT) {
5375 GrowableArray<AbstractType*> types; 5520 GrowableArray<AbstractType*> types;
5376 AbstractType& type = AbstractType::Handle(Z); 5521 AbstractType& type = AbstractType::Handle(Z);
5377 do { 5522 do {
5378 ConsumeToken(); 5523 ConsumeToken();
5379 type = ParseType(finalization); 5524 type = ParseTypeOrFunctionType(false, finalization);
5380 // Map a malformed type argument to dynamic. 5525 // Map a malformed type argument to dynamic.
5381 if (type.IsMalformed()) { 5526 if (type.IsMalformed()) {
5382 type = Type::DynamicType(); 5527 type = Type::DynamicType();
5383 } 5528 }
5384 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); 5529 types.Add(&AbstractType::ZoneHandle(Z, type.raw()));
5385 } while (CurrentToken() == Token::kCOMMA); 5530 } while (CurrentToken() == Token::kCOMMA);
5386 Token::Kind token = CurrentToken(); 5531 Token::Kind token = CurrentToken();
5387 if ((token == Token::kGT) || (token == Token::kSHR)) { 5532 if ((token == Token::kGT) || (token == Token::kSHR)) {
5388 ConsumeRightAngleBracket(); 5533 ConsumeRightAngleBracket();
5389 } else { 5534 } else {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
5575 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); 5720 AbstractType& result_type = Type::Handle(Z, Type::DynamicType());
5576 bool is_external = false; 5721 bool is_external = false;
5577 bool is_patch = false; 5722 bool is_patch = false;
5578 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { 5723 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) {
5579 is_patch = true; 5724 is_patch = true;
5580 metadata_pos = TokenPosition::kNoSource; 5725 metadata_pos = TokenPosition::kNoSource;
5581 } else if (CurrentToken() == Token::kEXTERNAL) { 5726 } else if (CurrentToken() == Token::kEXTERNAL) {
5582 ConsumeToken(); 5727 ConsumeToken();
5583 is_external = true; 5728 is_external = true;
5584 } 5729 }
5585 if (CurrentToken() == Token::kVOID) { 5730 // Parse optional result type.
5586 ConsumeToken(); 5731 if (IsFunctionReturnType()) {
5587 result_type = Type::VoidType(); 5732 // It is too early to resolve the type here, since it can be a result type
5588 } else { 5733 // referring to a not yet declared function type parameter.
5589 // Parse optional type. 5734 result_type = ParseTypeOrFunctionType(true, ClassFinalizer::kDoNotResolve);
5590 if (IsFunctionReturnType()) {
5591 // It is too early to resolve the type here, since it can be a result type
5592 // referring to a not yet declared function type parameter.
5593 result_type = ParseType(ClassFinalizer::kDoNotResolve);
5594 }
5595 } 5735 }
5596 const TokenPosition name_pos = TokenPos(); 5736 const TokenPosition name_pos = TokenPos();
5597 const String& func_name = *ExpectIdentifier("function name expected"); 5737 const String& func_name = *ExpectIdentifier("function name expected");
5598 5738
5599 bool found = library_.LookupLocalObject(func_name) != Object::null(); 5739 bool found = library_.LookupLocalObject(func_name) != Object::null();
5600 if (found && !is_patch) { 5740 if (found && !is_patch) {
5601 ReportError(name_pos, "'%s' is already defined", func_name.ToCString()); 5741 ReportError(name_pos, "'%s' is already defined", func_name.ToCString());
5602 } else if (!found && is_patch) { 5742 } else if (!found && is_patch) {
5603 ReportError(name_pos, "missing '%s' cannot be patched", 5743 ReportError(name_pos, "missing '%s' cannot be patched",
5604 func_name.ToCString()); 5744 func_name.ToCString());
(...skipping 16 matching lines...) Expand all
5621 5761
5622 ASSERT(innermost_function().IsNull()); 5762 ASSERT(innermost_function().IsNull());
5623 innermost_function_ = func.raw(); 5763 innermost_function_ = func.raw();
5624 5764
5625 if (CurrentToken() == Token::kLT) { 5765 if (CurrentToken() == Token::kLT) {
5626 if (!FLAG_generic_method_syntax) { 5766 if (!FLAG_generic_method_syntax) {
5627 ReportError("generic functions not supported"); 5767 ReportError("generic functions not supported");
5628 } 5768 }
5629 ParseTypeParameters(false); // Not parameterizing class, but function. 5769 ParseTypeParameters(false); // Not parameterizing class, but function.
5630 } 5770 }
5631 // At this point, the type parameters have been parsed, so we can resolve the
5632 // result type.
5633 if (!result_type.IsNull()) {
5634 ResolveType(ClassFinalizer::kResolveTypeParameters, &result_type);
5635 }
5636 5771
5637 CheckToken(Token::kLPAREN); 5772 CheckToken(Token::kLPAREN);
5638 const TokenPosition function_pos = TokenPos(); 5773 const TokenPosition function_pos = TokenPos();
5639 ParamList params; 5774 ParamList params;
5775 const bool use_function_type_syntax = false;
5640 const bool allow_explicit_default_values = true; 5776 const bool allow_explicit_default_values = true;
5641 ParseFormalParameterList(allow_explicit_default_values, false, &params); 5777 const bool evaluate_metadata = false;
5778 ParseFormalParameterList(use_function_type_syntax,
5779 allow_explicit_default_values, evaluate_metadata,
5780 &params);
5642 5781
5643 const TokenPosition modifier_pos = TokenPos(); 5782 const TokenPosition modifier_pos = TokenPos();
5644 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); 5783 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier();
5645 5784
5646 TokenPosition function_end_pos = function_pos; 5785 TokenPosition function_end_pos = function_pos;
5647 bool is_native = false; 5786 bool is_native = false;
5648 String* native_name = NULL; 5787 String* native_name = NULL;
5649 if (is_external) { 5788 if (is_external) {
5650 function_end_pos = TokenPos(); 5789 function_end_pos = TokenPos();
5651 ExpectSemicolon(); 5790 ExpectSemicolon();
(...skipping 26 matching lines...) Expand all
5678 func.set_modifier(func_modifier); 5817 func.set_modifier(func_modifier);
5679 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { 5818 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) {
5680 func.set_is_reflectable(false); 5819 func.set_is_reflectable(false);
5681 } 5820 }
5682 if (is_native) { 5821 if (is_native) {
5683 func.set_native_name(*native_name); 5822 func.set_native_name(*native_name);
5684 } 5823 }
5685 AddFormalParamsToFunction(&params, func); 5824 AddFormalParamsToFunction(&params, func);
5686 ASSERT(innermost_function().raw() == func.raw()); 5825 ASSERT(innermost_function().raw() == func.raw());
5687 innermost_function_ = Function::null(); 5826 innermost_function_ = Function::null();
5827 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func);
5688 top_level->AddFunction(func); 5828 top_level->AddFunction(func);
5689 if (!is_patch) { 5829 if (!is_patch) {
5690 library_.AddObject(func, func_name); 5830 library_.AddObject(func, func_name);
5691 } else { 5831 } else {
5692 // Need to remove the previously added function that is being patched. 5832 // Need to remove the previously added function that is being patched.
5693 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); 5833 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class());
5694 const Function& replaced_func = 5834 const Function& replaced_func =
5695 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); 5835 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name));
5696 ASSERT(!replaced_func.IsNull()); 5836 ASSERT(!replaced_func.IsNull());
5697 toplevel_cls.RemoveFunction(replaced_func); 5837 toplevel_cls.RemoveFunction(replaced_func);
(...skipping 19 matching lines...) Expand all
5717 metadata_pos = TokenPosition::kNoSource; 5857 metadata_pos = TokenPosition::kNoSource;
5718 } else if (CurrentToken() == Token::kEXTERNAL) { 5858 } else if (CurrentToken() == Token::kEXTERNAL) {
5719 ConsumeToken(); 5859 ConsumeToken();
5720 is_external = true; 5860 is_external = true;
5721 } 5861 }
5722 bool is_getter = (CurrentToken() == Token::kGET); 5862 bool is_getter = (CurrentToken() == Token::kGET);
5723 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { 5863 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) {
5724 ConsumeToken(); 5864 ConsumeToken();
5725 result_type = Type::DynamicType(); 5865 result_type = Type::DynamicType();
5726 } else { 5866 } else {
5727 if (CurrentToken() == Token::kVOID) { 5867 result_type =
5728 ConsumeToken(); 5868 ParseTypeOrFunctionType(true, ClassFinalizer::kResolveTypeParameters);
5729 result_type = Type::VoidType();
5730 } else {
5731 result_type = ParseType(ClassFinalizer::kResolveTypeParameters);
5732 }
5733 is_getter = (CurrentToken() == Token::kGET); 5869 is_getter = (CurrentToken() == Token::kGET);
5734 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { 5870 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) {
5735 ConsumeToken(); 5871 ConsumeToken();
5736 } else { 5872 } else {
5737 UnexpectedToken(); 5873 UnexpectedToken();
5738 } 5874 }
5739 } 5875 }
5740 const TokenPosition name_pos = TokenPos(); 5876 const TokenPosition name_pos = TokenPos();
5741 const String* field_name = ExpectIdentifier("accessor name expected"); 5877 const String* field_name = ExpectIdentifier("accessor name expected");
5742 5878
5743 const TokenPosition accessor_pos = TokenPos(); 5879 const TokenPosition accessor_pos = TokenPos();
5744 ParamList params; 5880 ParamList params;
5745 5881
5746 if (!is_getter) { 5882 if (!is_getter) {
5883 const bool use_function_type_syntax = false;
5747 const bool allow_explicit_default_values = true; 5884 const bool allow_explicit_default_values = true;
5748 ParseFormalParameterList(allow_explicit_default_values, false, &params); 5885 const bool evaluate_metadata = false;
5886 ParseFormalParameterList(use_function_type_syntax,
5887 allow_explicit_default_values, evaluate_metadata,
5888 &params);
5749 } 5889 }
5750 String& accessor_name = String::ZoneHandle(Z); 5890 String& accessor_name = String::ZoneHandle(Z);
5751 int expected_num_parameters = -1; 5891 int expected_num_parameters = -1;
5752 if (is_getter) { 5892 if (is_getter) {
5753 expected_num_parameters = 0; 5893 expected_num_parameters = 0;
5754 accessor_name = Field::GetterSymbol(*field_name); 5894 accessor_name = Field::GetterSymbol(*field_name);
5755 } else { 5895 } else {
5756 expected_num_parameters = 1; 5896 expected_num_parameters = 1;
5757 accessor_name = Field::SetterSymbol(*field_name); 5897 accessor_name = Field::SetterSymbol(*field_name);
5758 } 5898 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
5832 func.set_end_token_pos(accessor_end_pos); 5972 func.set_end_token_pos(accessor_end_pos);
5833 func.set_modifier(func_modifier); 5973 func.set_modifier(func_modifier);
5834 if (is_native) { 5974 if (is_native) {
5835 func.set_is_debuggable(false); 5975 func.set_is_debuggable(false);
5836 func.set_native_name(*native_name); 5976 func.set_native_name(*native_name);
5837 } 5977 }
5838 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { 5978 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) {
5839 func.set_is_reflectable(false); 5979 func.set_is_reflectable(false);
5840 } 5980 }
5841 AddFormalParamsToFunction(&params, func); 5981 AddFormalParamsToFunction(&params, func);
5982 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func);
5842 top_level->AddFunction(func); 5983 top_level->AddFunction(func);
5843 if (!is_patch) { 5984 if (!is_patch) {
5844 library_.AddObject(func, accessor_name); 5985 library_.AddObject(func, accessor_name);
5845 } else { 5986 } else {
5846 // Need to remove the previously added accessor that is being patched. 5987 // Need to remove the previously added accessor that is being patched.
5847 const Class& toplevel_cls = Class::Handle( 5988 const Class& toplevel_cls = Class::Handle(
5848 Z, owner.IsClass() ? Class::Cast(owner).raw() 5989 Z, owner.IsClass() ? Class::Cast(owner).raw()
5849 : PatchClass::Cast(owner).patched_class()); 5990 : PatchClass::Cast(owner).patched_class());
5850 const Function& replaced_func = 5991 const Function& replaced_func =
5851 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); 5992 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name));
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
6682 body.set_result_type(Object::dynamic_type()); 6823 body.set_result_type(Object::dynamic_type());
6683 is_new_closure = true; 6824 is_new_closure = true;
6684 } 6825 }
6685 6826
6686 ParamList closure_params; 6827 ParamList closure_params;
6687 AddSyncGenClosureParameters(&closure_params); 6828 AddSyncGenClosureParameters(&closure_params);
6688 6829
6689 if (is_new_closure) { 6830 if (is_new_closure) {
6690 // Add the parameters to the newly created closure. 6831 // Add the parameters to the newly created closure.
6691 AddFormalParamsToFunction(&closure_params, body); 6832 AddFormalParamsToFunction(&closure_params, body);
6692 6833 ResolveSignature(ClassFinalizer::kResolveTypeParameters, body);
6693 // Finalize function type. 6834 // Finalize function type.
6694 Type& signature_type = Type::Handle(Z, body.SignatureType()); 6835 Type& signature_type = Type::Handle(Z, body.SignatureType());
6695 signature_type ^= ClassFinalizer::FinalizeType( 6836 signature_type ^= ClassFinalizer::FinalizeType(
6696 current_class(), signature_type, ClassFinalizer::kCanonicalize); 6837 current_class(), signature_type, ClassFinalizer::kCanonicalize);
6697 body.SetSignatureType(signature_type); 6838 body.SetSignatureType(signature_type);
6698 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); 6839 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved());
6699 ASSERT(body.NumParameters() == closure_params.parameters->length()); 6840 ASSERT(body.NumParameters() == closure_params.parameters->length());
6700 } 6841 }
6701 6842
6702 OpenFunctionBlock(body); 6843 OpenFunctionBlock(body);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
6810 closure.set_is_generated_body(true); 6951 closure.set_is_generated_body(true);
6811 closure.set_result_type(Object::dynamic_type()); 6952 closure.set_result_type(Object::dynamic_type());
6812 is_new_closure = true; 6953 is_new_closure = true;
6813 } 6954 }
6814 // Create the parameter list for the async body closure. 6955 // Create the parameter list for the async body closure.
6815 ParamList closure_params; 6956 ParamList closure_params;
6816 AddAsyncClosureParameters(&closure_params); 6957 AddAsyncClosureParameters(&closure_params);
6817 if (is_new_closure) { 6958 if (is_new_closure) {
6818 // Add the parameters to the newly created closure. 6959 // Add the parameters to the newly created closure.
6819 AddFormalParamsToFunction(&closure_params, closure); 6960 AddFormalParamsToFunction(&closure_params, closure);
6961 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure);
6820 6962
6821 // Finalize function type. 6963 // Finalize function type.
6822 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 6964 Type& signature_type = Type::Handle(Z, closure.SignatureType());
6823 signature_type ^= ClassFinalizer::FinalizeType( 6965 signature_type ^= ClassFinalizer::FinalizeType(
6824 current_class(), signature_type, ClassFinalizer::kCanonicalize); 6966 current_class(), signature_type, ClassFinalizer::kCanonicalize);
6825 closure.SetSignatureType(signature_type); 6967 closure.SetSignatureType(signature_type);
6826 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 6968 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
6827 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 6969 ASSERT(closure.NumParameters() == closure_params.parameters->length());
6828 } 6970 }
6829 OpenFunctionBlock(closure); 6971 OpenFunctionBlock(closure);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
6939 closure.set_result_type(Object::dynamic_type()); 7081 closure.set_result_type(Object::dynamic_type());
6940 is_new_closure = true; 7082 is_new_closure = true;
6941 } 7083 }
6942 7084
6943 ParamList closure_params; 7085 ParamList closure_params;
6944 AddAsyncGenClosureParameters(&closure_params); 7086 AddAsyncGenClosureParameters(&closure_params);
6945 7087
6946 if (is_new_closure) { 7088 if (is_new_closure) {
6947 // Add the parameters to the newly created closure. 7089 // Add the parameters to the newly created closure.
6948 AddFormalParamsToFunction(&closure_params, closure); 7090 AddFormalParamsToFunction(&closure_params, closure);
7091 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure);
6949 7092
6950 // Finalize function type. 7093 // Finalize function type.
6951 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 7094 Type& signature_type = Type::Handle(Z, closure.SignatureType());
6952 signature_type ^= ClassFinalizer::FinalizeType( 7095 signature_type ^= ClassFinalizer::FinalizeType(
6953 current_class(), signature_type, ClassFinalizer::kCanonicalize); 7096 current_class(), signature_type, ClassFinalizer::kCanonicalize);
6954 closure.SetSignatureType(signature_type); 7097 closure.SetSignatureType(signature_type);
6955 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 7098 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
6956 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 7099 ASSERT(closure.NumParameters() == closure_params.parameters->length());
6957 } 7100 }
6958 7101
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
7301 for (int i = 0; i < params.num_optional_parameters; i++) { 7444 for (int i = 0; i < params.num_optional_parameters; i++) {
7302 const Instance* default_value = 7445 const Instance* default_value =
7303 parameters[i + first_opt_param_offset].default_value; 7446 parameters[i + first_opt_param_offset].default_value;
7304 default_values->Add(default_value); 7447 default_values->Add(default_value);
7305 } 7448 }
7306 parsed_function()->set_default_parameter_values(default_values); 7449 parsed_function()->set_default_parameter_values(default_values);
7307 } 7450 }
7308 } 7451 }
7309 7452
7310 7453
7454 void Parser::FinalizeFormalParameterTypes(const ParamList* params) {
7455 ASSERT((params != NULL) && (params->parameters != NULL));
7456 const int num_parameters = params->parameters->length();
7457 AbstractType& type = AbstractType::Handle(Z);
7458 for (int i = 0; i < num_parameters; i++) {
7459 ParamDesc& param_desc = (*params->parameters)[i];
7460 type = param_desc.type->raw();
7461 ResolveType(ClassFinalizer::kCanonicalize, &type);
7462 type = ClassFinalizer::FinalizeType(current_class(), type,
7463 ClassFinalizer::kCanonicalize);
7464 if (type.raw() != param_desc.type->raw()) {
7465 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw());
7466 }
7467 }
7468 }
7469
7470
7311 // Populate the parameter type array and parameter name array of the function 7471 // Populate the parameter type array and parameter name array of the function
7312 // with the formal parameter types and names. 7472 // with the formal parameter types and names.
7313 void Parser::AddFormalParamsToFunction(const ParamList* params, 7473 void Parser::AddFormalParamsToFunction(const ParamList* params,
7314 const Function& func) { 7474 const Function& func) {
7315 ASSERT((params != NULL) && (params->parameters != NULL)); 7475 ASSERT((params != NULL) && (params->parameters != NULL));
7316 ASSERT((params->num_optional_parameters > 0) == 7476 ASSERT((params->num_optional_parameters > 0) ==
7317 (params->has_optional_positional_parameters || 7477 (params->has_optional_positional_parameters ||
7318 params->has_optional_named_parameters)); 7478 params->has_optional_named_parameters));
7319 if (!Utils::IsInt(16, params->num_fixed_parameters) || 7479 if (!Utils::IsInt(16, params->num_fixed_parameters) ||
7320 !Utils::IsInt(16, params->num_optional_parameters)) { 7480 !Utils::IsInt(16, params->num_optional_parameters)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
7355 7515
7356 7516
7357 // Populate local scope with the formal parameters. 7517 // Populate local scope with the formal parameters.
7358 void Parser::AddFormalParamsToScope(const ParamList* params, 7518 void Parser::AddFormalParamsToScope(const ParamList* params,
7359 LocalScope* scope) { 7519 LocalScope* scope) {
7360 ASSERT((params != NULL) && (params->parameters != NULL)); 7520 ASSERT((params != NULL) && (params->parameters != NULL));
7361 ASSERT(scope != NULL); 7521 ASSERT(scope != NULL);
7362 const int num_parameters = params->parameters->length(); 7522 const int num_parameters = params->parameters->length();
7363 for (int i = 0; i < num_parameters; i++) { 7523 for (int i = 0; i < num_parameters; i++) {
7364 ParamDesc& param_desc = (*params->parameters)[i]; 7524 ParamDesc& param_desc = (*params->parameters)[i];
7365 ASSERT(!is_top_level_ || param_desc.type->IsResolved());
7366 const String* name = param_desc.name; 7525 const String* name = param_desc.name;
7367 LocalVariable* parameter = new (Z) LocalVariable( 7526 LocalVariable* parameter = new (Z) LocalVariable(
7368 param_desc.name_pos, param_desc.name_pos, *name, *param_desc.type); 7527 param_desc.name_pos, param_desc.name_pos, *name, *param_desc.type);
7369 if (!scope->InsertParameterAt(i, parameter)) { 7528 if (!scope->InsertParameterAt(i, parameter)) {
7370 ReportError(param_desc.name_pos, "name '%s' already exists in scope", 7529 ReportError(param_desc.name_pos, "name '%s' already exists in scope",
7371 param_desc.name->ToCString()); 7530 param_desc.name->ToCString());
7372 } 7531 }
7373 param_desc.var = parameter; 7532 param_desc.var = parameter;
7374 if (param_desc.is_final) { 7533 if (param_desc.is_final) {
7375 parameter->set_is_final(); 7534 parameter->set_is_final();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
7534 TRACE_PARSER("ParseConstFinalVarOrType"); 7693 TRACE_PARSER("ParseConstFinalVarOrType");
7535 if (CurrentToken() == Token::kVAR) { 7694 if (CurrentToken() == Token::kVAR) {
7536 ConsumeToken(); 7695 ConsumeToken();
7537 return Type::DynamicType(); 7696 return Type::DynamicType();
7538 } 7697 }
7539 bool type_is_optional = false; 7698 bool type_is_optional = false;
7540 if ((CurrentToken() == Token::kFINAL) || (CurrentToken() == Token::kCONST)) { 7699 if ((CurrentToken() == Token::kFINAL) || (CurrentToken() == Token::kCONST)) {
7541 ConsumeToken(); 7700 ConsumeToken();
7542 type_is_optional = true; 7701 type_is_optional = true;
7543 } 7702 }
7703 if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
7704 return ParseFunctionType(AbstractType::Handle(Z), finalization);
7705 }
7544 if (CurrentToken() != Token::kIDENT) { 7706 if (CurrentToken() != Token::kIDENT) {
7545 if (type_is_optional) { 7707 if (type_is_optional) {
7546 return Type::DynamicType(); 7708 return Type::DynamicType();
7547 } else { 7709 } else {
7548 ReportError("type name expected"); 7710 ReportError("type name expected");
7549 } 7711 }
7550 } 7712 }
7551 if (type_is_optional) { 7713 if (type_is_optional) {
7552 Token::Kind follower = LookaheadToken(1); 7714 Token::Kind follower = LookaheadToken(1);
7553 // We have an identifier followed by a 'follower' token. 7715 // We have an identifier followed by a 'follower' token.
7554 // We either parse a type or return now. 7716 // We either parse a type or return now.
7555 if ((follower != Token::kLT) && // Parameterized type. 7717 if ((follower != Token::kLT) && // Parameterized type.
7556 (follower != Token::kPERIOD) && // Qualified class name of type. 7718 (follower != Token::kPERIOD) && // Qualified class name of type.
7557 !Token::IsIdentifier(follower) && // Variable name following a type. 7719 !Token::IsIdentifier(follower) && // Variable name following a type.
7558 (follower != Token::kTHIS)) { // Field parameter following a type. 7720 (follower != Token::kTHIS)) { // Field parameter following a type.
7559 return Type::DynamicType(); 7721 return Type::DynamicType();
7560 } 7722 }
7561 } 7723 }
7562 return ParseType(finalization); 7724 return ParseTypeOrFunctionType(false, finalization);
7563 } 7725 }
7564 7726
7565 7727
7566 // Returns ast nodes of the variable initialization. Variables without an 7728 // Returns ast nodes of the variable initialization. Variables without an
7567 // explicit initializer are initialized to null. If several variables are 7729 // explicit initializer are initialized to null. If several variables are
7568 // declared, the individual initializers are collected in a sequence node. 7730 // declared, the individual initializers are collected in a sequence node.
7569 AstNode* Parser::ParseVariableDeclarationList() { 7731 AstNode* Parser::ParseVariableDeclarationList() {
7570 TRACE_PARSER("ParseVariableDeclarationList"); 7732 TRACE_PARSER("ParseVariableDeclarationList");
7571 SkipMetadata(); 7733 SkipMetadata();
7572 bool is_final = (CurrentToken() == Token::kFINAL); 7734 bool is_final = (CurrentToken() == Token::kFINAL);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
7604 } 7766 }
7605 sequence->Add(declaration); 7767 sequence->Add(declaration);
7606 initializers = sequence; 7768 initializers = sequence;
7607 } 7769 }
7608 return initializers; 7770 return initializers;
7609 } 7771 }
7610 7772
7611 7773
7612 AstNode* Parser::ParseFunctionStatement(bool is_literal) { 7774 AstNode* Parser::ParseFunctionStatement(bool is_literal) {
7613 TRACE_PARSER("ParseFunctionStatement"); 7775 TRACE_PARSER("ParseFunctionStatement");
7614 AbstractType& result_type = AbstractType::Handle(Z); 7776 AbstractType& result_type = AbstractType::Handle(Z, Type::DynamicType());
7615 const String* function_name = NULL; 7777 const String* function_name = NULL;
7616
7617 result_type = Type::DynamicType();
7618
7619 const TokenPosition function_pos = TokenPos(); 7778 const TokenPosition function_pos = TokenPos();
7620 TokenPosition function_name_pos = TokenPosition::kNoSource; 7779 TokenPosition function_name_pos = TokenPosition::kNoSource;
7621 TokenPosition metadata_pos = TokenPosition::kNoSource; 7780 TokenPosition metadata_pos = TokenPosition::kNoSource;
7622 if (is_literal) { 7781 if (is_literal) {
7623 ASSERT(CurrentToken() == Token::kLPAREN || CurrentToken() == Token::kLT); 7782 ASSERT(CurrentToken() == Token::kLPAREN || CurrentToken() == Token::kLT);
7624 function_name = &Symbols::AnonymousClosure(); 7783 function_name = &Symbols::AnonymousClosure();
7625 } else { 7784 } else {
7626 metadata_pos = SkipMetadata(); 7785 metadata_pos = SkipMetadata();
7627 if (CurrentToken() == Token::kVOID) { 7786 // Parse optional result type.
7628 ConsumeToken(); 7787 if (IsFunctionReturnType()) {
7629 result_type = Type::VoidType();
7630 } else if (IsFunctionReturnType()) {
7631 // It is too early to resolve the type here, since it can be a result type 7788 // It is too early to resolve the type here, since it can be a result type
7632 // referring to a not yet declared function type parameter. 7789 // referring to a not yet declared function type parameter.
7633 result_type = ParseType(ClassFinalizer::kDoNotResolve); 7790 result_type =
7791 ParseTypeOrFunctionType(true, ClassFinalizer::kDoNotResolve);
7634 } 7792 }
7635 function_name_pos = TokenPos(); 7793 function_name_pos = TokenPos();
7636 function_name = ExpectIdentifier("function name expected"); 7794 function_name = ExpectIdentifier("function name expected");
7637 7795
7638 // Check that the function name has not been referenced 7796 // Check that the function name has not been referenced
7639 // before this declaration. 7797 // before this declaration.
7640 ASSERT(current_block_ != NULL); 7798 ASSERT(current_block_ != NULL);
7641 const TokenPosition previous_pos = 7799 const TokenPosition previous_pos =
7642 current_block_->scope->PreviousReferencePos(*function_name); 7800 current_block_->scope->PreviousReferencePos(*function_name);
7643 if (previous_pos.IsReal()) { 7801 if (previous_pos.IsReal()) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
7993 (CurrentLiteral()->raw() == Symbols::YieldKw().raw()))); 8151 (CurrentLiteral()->raw() == Symbols::YieldKw().raw())));
7994 } 8152 }
7995 8153
7996 8154
7997 bool Parser::IsSymbol(const String& symbol) { 8155 bool Parser::IsSymbol(const String& symbol) {
7998 return (CurrentLiteral()->raw() == symbol.raw()) && 8156 return (CurrentLiteral()->raw() == symbol.raw()) &&
7999 (CurrentToken() == Token::kIDENT); 8157 (CurrentToken() == Token::kIDENT);
8000 } 8158 }
8001 8159
8002 8160
8161 // Returns true if the current token is 'Function' followed by '<' or '('.
8162 // 'Function' not followed by '<' or '(' denotes the Function class.
8163 bool Parser::IsFunctionTypeSymbol() {
8164 return IsSymbol(Symbols::Function()) &&
8165 ((LookaheadToken(1) == Token::kLPAREN) ||
8166 (LookaheadToken(1) == Token::kLT));
8167 }
8168
8169
8003 // Returns true if the next tokens can be parsed as a an optionally 8170 // Returns true if the next tokens can be parsed as a an optionally
8004 // qualified identifier: [ident '.'] ident. 8171 // qualified identifier: [ident '.'] ident.
8005 // Current token position is not restored. 8172 // Current token position is not restored.
8006 bool Parser::TryParseQualIdent() { 8173 bool Parser::TryParseQualIdent() {
8007 if (CurrentToken() != Token::kIDENT) { 8174 if (CurrentToken() != Token::kIDENT) {
8008 return false; 8175 return false;
8009 } 8176 }
8010 ConsumeToken(); 8177 ConsumeToken();
8011 if (CurrentToken() == Token::kPERIOD) { 8178 if (CurrentToken() == Token::kPERIOD) {
8012 ConsumeToken(); 8179 ConsumeToken();
8013 if (CurrentToken() != Token::kIDENT) { 8180 if (CurrentToken() != Token::kIDENT) {
8014 return false; 8181 return false;
8015 } 8182 }
8016 ConsumeToken(); 8183 ConsumeToken();
8017 } 8184 }
8018 return true; 8185 return true;
8019 } 8186 }
8020 8187
8021 8188
8022 // Returns true if the next tokens can be parsed as a type with optional 8189 // Returns true if the next tokens can be parsed as a type with optional
8023 // type parameters. Current token position is not restored. 8190 // type parameters. Current token position is not restored.
8024 bool Parser::TryParseOptionalType() { 8191 // Allow 'void' as type if 'allow_void' is true.
8025 if (CurrentToken() == Token::kIDENT) { 8192 // Note that 'void Function()' is always allowed, since it is a function type
8193 // and not the void type.
8194 bool Parser::TryParseType(bool allow_void) {
8195 bool found = false;
8196 if (CurrentToken() == Token::kVOID) {
8197 ConsumeToken();
8198 if (allow_void) {
8199 found = true;
8200 } else if (!IsFunctionTypeSymbol()) {
8201 return false;
8202 }
8203 } else if ((CurrentToken() == Token::kIDENT) && !IsFunctionTypeSymbol()) {
8204 // 'Function' not followed by '(' or '<' means the Function class.
8026 if (!TryParseQualIdent()) { 8205 if (!TryParseQualIdent()) {
8027 return false; 8206 return false;
8028 } 8207 }
8029 if ((CurrentToken() == Token::kLT) && !TryParseTypeParameters()) { 8208 if ((CurrentToken() == Token::kLT) && !TryParseTypeParameters()) {
8030 return false; 8209 return false;
8031 } 8210 }
8211 found = true;
8032 } 8212 }
8033 return true; 8213 while (IsSymbol(Symbols::Function())) {
8214 ConsumeToken();
8215 if ((CurrentToken() == Token::kLT) && !TryParseTypeParameters()) {
8216 return false;
8217 }
8218 if (CurrentToken() == Token::kLPAREN) {
8219 SkipToMatchingParenthesis();
8220 } else {
8221 return false;
8222 }
8223 found = true;
8224 }
8225 return found;
8034 } 8226 }
8035 8227
8036 8228
8037 // Returns true if the next tokens can be parsed as a type with optional
8038 // type parameters, or keyword "void".
8039 // Current token position is not restored.
8040 bool Parser::TryParseReturnType() {
8041 if (CurrentToken() == Token::kVOID) {
8042 ConsumeToken();
8043 return true;
8044 } else if (CurrentToken() == Token::kIDENT) {
8045 return TryParseOptionalType();
8046 }
8047 return false;
8048 }
8049
8050
8051 // Look ahead to detect whether the next tokens should be parsed as 8229 // Look ahead to detect whether the next tokens should be parsed as
8052 // a variable declaration. Ignores optional metadata. 8230 // a variable declaration. Ignores optional metadata.
8053 // Returns true if we detect the token pattern: 8231 // Returns true if we detect the token pattern:
8054 // 'var' 8232 // 'var'
8055 // | 'final' 8233 // | 'final'
8056 // | const [type] ident (';' | '=' | ',') 8234 // | const [type] ident (';' | '=' | ',')
8057 // | type ident (';' | '=' | ',') 8235 // | type ident (';' | '=' | ',')
8058 // Token position remains unchanged. 8236 // Token position remains unchanged.
8059 bool Parser::IsVariableDeclaration() { 8237 bool Parser::IsVariableDeclaration() {
8060 if ((CurrentToken() == Token::kVAR) || (CurrentToken() == Token::kFINAL)) { 8238 if ((CurrentToken() == Token::kVAR) || (CurrentToken() == Token::kFINAL)) {
8061 return true; 8239 return true;
8062 } 8240 }
8063 // Skip optional metadata. 8241 // Skip optional metadata.
8064 if (CurrentToken() == Token::kAT) { 8242 if (CurrentToken() == Token::kAT) {
8065 const TokenPosition saved_pos = TokenPos(); 8243 const TokenPosition saved_pos = TokenPos();
8066 SkipMetadata(); 8244 SkipMetadata();
8067 const bool is_var_decl = IsVariableDeclaration(); 8245 const bool is_var_decl = IsVariableDeclaration();
8068 SetPosition(saved_pos); 8246 SetPosition(saved_pos);
8069 return is_var_decl; 8247 return is_var_decl;
8070 } 8248 }
8071 if ((CurrentToken() != Token::kIDENT) && (CurrentToken() != Token::kCONST)) { 8249 if ((CurrentToken() != Token::kIDENT) && (CurrentToken() != Token::kVOID) &&
8072 // Not a legal type identifier or const keyword or metadata. 8250 (CurrentToken() != Token::kCONST)) {
8251 // Not a legal type identifier or void (result type of function type)
8252 // or const keyword or metadata.
8073 return false; 8253 return false;
8074 } 8254 }
8075 const TokenPosition saved_pos = TokenPos(); 8255 const TokenPosition saved_pos = TokenPos();
8076 bool is_var_decl = false; 8256 bool is_var_decl = false;
8077 bool have_type = false; 8257 bool have_type = false;
8078 if (CurrentToken() == Token::kCONST) { 8258 if (CurrentToken() == Token::kCONST) {
8079 ConsumeToken(); 8259 ConsumeToken();
8080 have_type = true; // Type is dynamic. 8260 have_type = true; // Type is dynamic if 'const' is not followed by a type.
8081 } 8261 }
8082 if (IsIdentifier()) { // Type or variable name. 8262 if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
8263 if (TryParseType(false)) {
8264 have_type = true;
8265 }
8266 } else if (IsIdentifier()) { // Type or variable name.
8083 Token::Kind follower = LookaheadToken(1); 8267 Token::Kind follower = LookaheadToken(1);
8084 if ((follower == Token::kLT) || // Parameterized type. 8268 if ((follower == Token::kLT) || // Parameterized type.
8085 (follower == Token::kPERIOD) || // Qualified class name of type. 8269 (follower == Token::kPERIOD) || // Qualified class name of type.
8086 Token::IsIdentifier(follower)) { // Variable name following a type. 8270 Token::IsIdentifier(follower)) { // Variable name following a type.
8087 // We see the beginning of something that could be a type. 8271 // We see the beginning of something that could be a type.
8088 const TokenPosition type_pos = TokenPos(); 8272 const TokenPosition type_pos = TokenPos();
8089 if (TryParseOptionalType()) { 8273 if (TryParseType(false)) {
8090 have_type = true; 8274 have_type = true;
8091 } else { 8275 } else {
8092 SetPosition(type_pos); 8276 SetPosition(type_pos);
8093 } 8277 }
8094 } 8278 }
8095 if (have_type && IsIdentifier()) { 8279 }
8096 ConsumeToken(); 8280 if (have_type && IsIdentifier()) {
8097 if ((CurrentToken() == Token::kSEMICOLON) || 8281 ConsumeToken();
8098 (CurrentToken() == Token::kCOMMA) || 8282 if ((CurrentToken() == Token::kSEMICOLON) ||
8099 (CurrentToken() == Token::kASSIGN)) { 8283 (CurrentToken() == Token::kCOMMA) ||
8100 is_var_decl = true; 8284 (CurrentToken() == Token::kASSIGN)) {
8101 } 8285 is_var_decl = true;
8102 } 8286 }
8103 } 8287 }
8104 SetPosition(saved_pos); 8288 SetPosition(saved_pos);
8105 return is_var_decl; 8289 return is_var_decl;
8106 } 8290 }
8107 8291
8108 8292
8109 // Look ahead to see if the following tokens are a return type followed 8293 // Look ahead to see if the following tokens are a return type followed
8110 // by an identifier. 8294 // by an identifier.
8111 bool Parser::IsFunctionReturnType() { 8295 bool Parser::IsFunctionReturnType() {
8112 TokenPosScope decl_pos(this); 8296 TokenPosScope decl_pos(this);
8113 if (TryParseReturnType()) { 8297 if (TryParseType(true)) {
8114 if (IsIdentifier()) { 8298 if (IsIdentifier()) {
8115 // Return type followed by function name. 8299 // Return type followed by function name.
8116 return true; 8300 return true;
8117 } 8301 }
8118 } 8302 }
8119 return false; 8303 return false;
8120 } 8304 }
8121 8305
8122 8306
8123 // Look ahead to detect whether the next tokens should be parsed as 8307 // Look ahead to detect whether the next tokens should be parsed as
8124 // a function declaration. Token position remains unchanged. 8308 // a function declaration. Token position remains unchanged.
8125 bool Parser::IsFunctionDeclaration() { 8309 bool Parser::IsFunctionDeclaration() {
8126 bool is_external = false; 8310 bool is_external = false;
8127 TokenPosScope decl_pos(this); 8311 TokenPosScope decl_pos(this);
8128 SkipMetadata(); 8312 SkipMetadata();
8129 if ((is_top_level_) && (CurrentToken() == Token::kEXTERNAL)) { 8313 if ((is_top_level_) && (CurrentToken() == Token::kEXTERNAL)) {
8130 // Skip over 'external' for top-level function declarations. 8314 // Skip over 'external' for top-level function declarations.
8131 is_external = true; 8315 is_external = true;
8132 ConsumeToken(); 8316 ConsumeToken();
8133 } 8317 }
8134 const TokenPosition type_or_name_pos = TokenPos(); 8318 const TokenPosition type_or_name_pos = TokenPos();
8135 if (TryParseReturnType()) { 8319 if (TryParseType(true)) {
8136 if (!IsIdentifier()) { 8320 if (!IsIdentifier()) {
8137 SetPosition(type_or_name_pos); 8321 SetPosition(type_or_name_pos);
8138 } 8322 }
8139 } else { 8323 } else {
8140 SetPosition(type_or_name_pos); 8324 SetPosition(type_or_name_pos);
8141 } 8325 }
8142 // Check for function name followed by optional type parameters. 8326 // Check for function name followed by optional type parameters.
8143 if (!IsIdentifier()) { 8327 if (!IsIdentifier()) {
8144 return false; 8328 return false;
8145 } 8329 }
(...skipping 19 matching lines...) Expand all
8165 8349
8166 8350
8167 bool Parser::IsTopLevelAccessor() { 8351 bool Parser::IsTopLevelAccessor() {
8168 const TokenPosScope saved_pos(this); 8352 const TokenPosScope saved_pos(this);
8169 if (CurrentToken() == Token::kEXTERNAL) { 8353 if (CurrentToken() == Token::kEXTERNAL) {
8170 ConsumeToken(); 8354 ConsumeToken();
8171 } 8355 }
8172 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 8356 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
8173 return true; 8357 return true;
8174 } 8358 }
8175 if (TryParseReturnType()) { 8359 if (TryParseType(true)) {
8176 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 8360 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
8177 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. 8361 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name.
8178 return true; 8362 return true;
8179 } 8363 }
8180 } 8364 }
8181 } 8365 }
8182 return false; 8366 return false;
8183 } 8367 }
8184 8368
8185 8369
(...skipping 28 matching lines...) Expand all
8214 // Allow const modifier as well when recognizing a for-in statement 8398 // Allow const modifier as well when recognizing a for-in statement
8215 // pattern. We will get an error later if the loop variable is 8399 // pattern. We will get an error later if the loop variable is
8216 // declared with const. 8400 // declared with const.
8217 if (CurrentToken() == Token::kVAR || CurrentToken() == Token::kFINAL || 8401 if (CurrentToken() == Token::kVAR || CurrentToken() == Token::kFINAL ||
8218 CurrentToken() == Token::kCONST) { 8402 CurrentToken() == Token::kCONST) {
8219 ConsumeToken(); 8403 ConsumeToken();
8220 } 8404 }
8221 if (IsIdentifier()) { 8405 if (IsIdentifier()) {
8222 if (LookaheadToken(1) == Token::kIN) { 8406 if (LookaheadToken(1) == Token::kIN) {
8223 return true; 8407 return true;
8224 } else if (TryParseOptionalType()) { 8408 } else if (TryParseType(false)) {
8225 if (IsIdentifier()) { 8409 if (IsIdentifier()) {
8226 ConsumeToken(); 8410 ConsumeToken();
8227 } 8411 }
8228 return CurrentToken() == Token::kIN; 8412 return CurrentToken() == Token::kIN;
8229 } 8413 }
8230 } 8414 }
8231 return false; 8415 return false;
8232 } 8416 }
8233 8417
8234 8418
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
9513 while ((CurrentToken() == Token::kCATCH) || IsSymbol(Symbols::On())) { 9697 while ((CurrentToken() == Token::kCATCH) || IsSymbol(Symbols::On())) {
9514 // Open a block that contains the if or an unconditional body. It's 9698 // Open a block that contains the if or an unconditional body. It's
9515 // closed in the loop that builds the if-then-else nest. 9699 // closed in the loop that builds the if-then-else nest.
9516 OpenBlock(); 9700 OpenBlock();
9517 const TokenPosition catch_pos = TokenPos(); 9701 const TokenPosition catch_pos = TokenPos();
9518 CatchParamDesc exception_param; 9702 CatchParamDesc exception_param;
9519 CatchParamDesc stack_trace_param; 9703 CatchParamDesc stack_trace_param;
9520 if (IsSymbol(Symbols::On())) { 9704 if (IsSymbol(Symbols::On())) {
9521 ConsumeToken(); 9705 ConsumeToken();
9522 exception_param.type = &AbstractType::ZoneHandle( 9706 exception_param.type = &AbstractType::ZoneHandle(
9523 Z, ParseType(ClassFinalizer::kCanonicalize)); 9707 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kCanonicalize));
9524 } else { 9708 } else {
9525 exception_param.type = &Object::dynamic_type(); 9709 exception_param.type = &Object::dynamic_type();
9526 } 9710 }
9527 if (CurrentToken() == Token::kCATCH) { 9711 if (CurrentToken() == Token::kCATCH) {
9528 ConsumeToken(); // Consume the 'catch'. 9712 ConsumeToken(); // Consume the 'catch'.
9529 ExpectToken(Token::kLPAREN); 9713 ExpectToken(Token::kLPAREN);
9530 exception_param.token_pos = TokenPos(); 9714 exception_param.token_pos = TokenPos();
9531 exception_param.name = ExpectIdentifier("identifier expected"); 9715 exception_param.name = ExpectIdentifier("identifier expected");
9532 if (CurrentToken() == Token::kCOMMA) { 9716 if (CurrentToken() == Token::kCOMMA) {
9533 ConsumeToken(); 9717 ConsumeToken();
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
10619 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { 10803 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) {
10620 right_operand = ParseBinaryExpr(current_preced + 1); 10804 right_operand = ParseBinaryExpr(current_preced + 1);
10621 } else { 10805 } else {
10622 // For 'is' and 'as' we expect the right operand to be a type. 10806 // For 'is' and 'as' we expect the right operand to be a type.
10623 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { 10807 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) {
10624 ConsumeToken(); 10808 ConsumeToken();
10625 op_kind = Token::kISNOT; 10809 op_kind = Token::kISNOT;
10626 } 10810 }
10627 const TokenPosition type_pos = TokenPos(); 10811 const TokenPosition type_pos = TokenPos();
10628 const AbstractType& type = AbstractType::ZoneHandle( 10812 const AbstractType& type = AbstractType::ZoneHandle(
10629 Z, ParseType(ClassFinalizer::kCanonicalize)); 10813 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kCanonicalize));
10630 if (!type.IsInstantiated() && (FunctionLevel() > 0)) { 10814 if (!type.IsInstantiated() && (FunctionLevel() > 0)) {
10631 // Make sure that the instantiator is captured. 10815 // Make sure that the instantiator is captured.
10632 CaptureInstantiator(); 10816 CaptureInstantiator();
10633 } 10817 }
10634 right_operand = new (Z) TypeNode(type_pos, type); 10818 right_operand = new (Z) TypeNode(type_pos, type);
10635 // In production mode, the type may be malformed. 10819 // In production mode, the type may be malformed.
10636 // In checked mode, the type may be malformed or malbounded. 10820 // In checked mode, the type may be malformed or malbounded.
10637 if (type.IsMalformedOrMalbounded()) { 10821 if (type.IsMalformedOrMalbounded()) {
10638 // Note that a type error is thrown in a type test or in 10822 // Note that a type error is thrown in a type test or in
10639 // a type cast even if the tested value is null. 10823 // a type cast even if the tested value is null.
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
11948 // The result is a pair of the (side effects of the) store followed by 12132 // The result is a pair of the (side effects of the) store followed by
11949 // the (value of the) initial value temp variable load. 12133 // the (value of the) initial value temp variable load.
11950 let_expr->AddNode(store); 12134 let_expr->AddNode(store);
11951 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); 12135 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp));
11952 return let_expr; 12136 return let_expr;
11953 } 12137 }
11954 return expr; 12138 return expr;
11955 } 12139 }
11956 12140
11957 12141
12142 // Resolve the types of the given signature from the current class according to
12143 // the given type finalization mode.
12144 // Not all involved type classes may get resolved yet, but at least type
12145 // parameters will get resolved, thereby relieving the class
12146 // finalizer from resolving type parameters out of context.
12147 // TODO(regis): Refactor this code which is partially duplicated in the class
12148 // finalizer, paying attention to type parameter resolution and mixin library.
12149 void Parser::ResolveSignature(ClassFinalizer::FinalizationKind finalization,
12150 const Function& signature) {
12151 const Function& saved_innermost_function =
12152 Function::Handle(Z, innermost_function().raw());
12153 innermost_function_ = signature.raw();
12154 // TODO(regis): Resolve upper bounds of function type parameters.
12155 AbstractType& type = AbstractType::Handle(signature.result_type());
12156 ResolveType(finalization, &type);
12157 signature.set_result_type(type);
12158 const intptr_t num_parameters = signature.NumParameters();
12159 for (intptr_t i = 0; i < num_parameters; i++) {
12160 type = signature.ParameterTypeAt(i);
12161 ResolveType(finalization, &type);
12162 signature.SetParameterTypeAt(i, type);
12163 }
12164 innermost_function_ = saved_innermost_function.raw();
12165 }
12166
12167
11958 // Resolve the given type and its type arguments from the current function and 12168 // Resolve the given type and its type arguments from the current function and
11959 // current class according to the given type finalization mode. 12169 // current class according to the given type finalization mode.
11960 // Not all involved type classes may get resolved yet, but at least type 12170 // Not all involved type classes may get resolved yet, but at least type
11961 // parameters will get resolved, thereby relieving the class 12171 // parameters will get resolved, thereby relieving the class
11962 // finalizer from resolving type parameters out of context. 12172 // finalizer from resolving type parameters out of context.
11963 // TODO(regis): Refactor this code which is partially duplicated in the class 12173 // TODO(regis): Refactor this code which is partially duplicated in the class
11964 // finalizer, paying attention to type parameter resolution and mixin library. 12174 // finalizer, paying attention to type parameter resolution and mixin library.
11965 void Parser::ResolveType(ClassFinalizer::FinalizationKind finalization, 12175 void Parser::ResolveType(ClassFinalizer::FinalizationKind finalization,
11966 AbstractType* type) { 12176 AbstractType* type) {
11967 ASSERT(finalization >= ClassFinalizer::kResolveTypeParameters); 12177 ASSERT(finalization >= ClassFinalizer::kResolveTypeParameters);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
12075 arguments.SetTypeAt(i, type_argument); 12285 arguments.SetTypeAt(i, type_argument);
12076 } 12286 }
12077 } 12287 }
12078 if (type->IsFunctionType()) { 12288 if (type->IsFunctionType()) {
12079 const Function& signature = 12289 const Function& signature =
12080 Function::Handle(Z, Type::Cast(*type).signature()); 12290 Function::Handle(Z, Type::Cast(*type).signature());
12081 Type& signature_type = Type::Handle(Z, signature.SignatureType()); 12291 Type& signature_type = Type::Handle(Z, signature.SignatureType());
12082 if (signature_type.raw() != type->raw()) { 12292 if (signature_type.raw() != type->raw()) {
12083 ResolveType(finalization, &signature_type); 12293 ResolveType(finalization, &signature_type);
12084 } else { 12294 } else {
12085 AbstractType& type = AbstractType::Handle(signature.result_type()); 12295 ResolveSignature(finalization, signature);
12086 ResolveType(finalization, &type);
12087 signature.set_result_type(type);
12088 const intptr_t num_parameters = signature.NumParameters();
12089 for (intptr_t i = 0; i < num_parameters; i++) {
12090 type = signature.ParameterTypeAt(i);
12091 ResolveType(finalization, &type);
12092 signature.SetParameterTypeAt(i, type);
12093 }
12094 if (signature.IsSignatureFunction()) { 12296 if (signature.IsSignatureFunction()) {
12095 // Drop fields that are not necessary anymore after resolution. 12297 // Drop fields that are not necessary anymore after resolution.
12096 // The parent function, owner, and token position of a shared 12298 // The parent function, owner, and token position of a shared
12097 // canonical function type are meaningless, since the canonical 12299 // canonical function type are meaningless, since the canonical
12098 // representent is picked arbitrarily. 12300 // representent is picked arbitrarily.
12099 signature.set_parent_function(Function::Handle(Z)); 12301 signature.set_parent_function(Function::Handle(Z));
12100 // TODO(regis): As long as we support metadata in typedef signatures, 12302 // TODO(regis): As long as we support metadata in typedef signatures,
12101 // we cannot reset these fields used to reparse a typedef. 12303 // we cannot reset these fields used to reparse a typedef.
12102 // Note that the scope class of a typedef function type is always 12304 // Note that the scope class of a typedef function type is always
12103 // preserved as the typedef class (not reset to _Closure class), thereby 12305 // preserved as the typedef class (not reset to _Closure class), thereby
12104 // preventing sharing of canonical function types between typedefs. 12306 // preventing sharing of canonical function types between typedefs.
12105 // Not being shared, these fields are therefore always meaningful for 12307 // Not being shared, these fields are therefore always meaningful for
12106 // typedefs. 12308 // typedefs.
12107 if (type.HasResolvedTypeClass()) { 12309 }
12108 const Class& scope_class = Class::Handle(Z, type.type_class()); 12310 if (type->HasResolvedTypeClass()) {
12109 if (!scope_class.IsTypedefClass()) { 12311 const Class& scope_class = Class::Handle(Z, type->type_class());
12312 if (!scope_class.IsTypedefClass()) {
12313 if (signature.IsSignatureFunction()) {
12110 signature.set_owner(Object::Handle(Z)); 12314 signature.set_owner(Object::Handle(Z));
12111 signature.set_token_pos(TokenPosition::kNoSource); 12315 signature.set_token_pos(TokenPosition::kNoSource);
12112 } 12316 }
12317 if ((type->arguments() != TypeArguments::null()) &&
12318 signature.HasInstantiatedSignature()) {
12319 ASSERT(scope_class.IsGeneric());
12320 // Although the scope class of this function type is generic,
12321 // the signature of this function type does not refer to any
12322 // of its type parameters. Reset its scope class to _Closure.
12323 Type::Cast(*type).set_type_class(Class::Handle(
12324 Z, Isolate::Current()->object_store()->closure_class()));
12325 type->set_arguments(Object::null_type_arguments());
12326 }
12113 } 12327 }
12114 } 12328 }
12115 } 12329 }
12116 } 12330 }
12117 } 12331 }
12118 12332
12119 12333
12120 LocalVariable* Parser::LookupLocalScope(const String& ident) { 12334 LocalVariable* Parser::LookupLocalScope(const String& ident) {
12121 if (current_block_ == NULL) { 12335 if (current_block_ == NULL) {
12122 return NULL; 12336 return NULL;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
12714 12928
12715 RawAbstractType* Parser::ParseType( 12929 RawAbstractType* Parser::ParseType(
12716 ClassFinalizer::FinalizationKind finalization, 12930 ClassFinalizer::FinalizationKind finalization,
12717 bool allow_deferred_type, 12931 bool allow_deferred_type,
12718 bool consume_unresolved_prefix) { 12932 bool consume_unresolved_prefix) {
12719 LibraryPrefix& prefix = LibraryPrefix::Handle(Z); 12933 LibraryPrefix& prefix = LibraryPrefix::Handle(Z);
12720 return ParseType(finalization, allow_deferred_type, consume_unresolved_prefix, 12934 return ParseType(finalization, allow_deferred_type, consume_unresolved_prefix,
12721 &prefix); 12935 &prefix);
12722 } 12936 }
12723 12937
12938
12939 // Parses and returns a type or a function type.
12940 RawAbstractType* Parser::ParseTypeOrFunctionType(
12941 bool allow_void,
12942 ClassFinalizer::FinalizationKind finalization) {
12943 TRACE_PARSER("ParseTypeOrFunctionType");
12944 AbstractType& type = AbstractType::Handle(Z);
12945 if (CurrentToken() == Token::kVOID) {
12946 TokenPosition void_pos = TokenPos();
12947 type = Type::VoidType();
12948 ConsumeToken();
12949 // 'void' is always allowed as result type of a function type.
12950 if (!allow_void && !IsFunctionTypeSymbol()) {
12951 ReportError(void_pos, "'void' not allowed here");
12952 }
12953 } else if (!IsFunctionTypeSymbol()) {
12954 // Including 'Function' not followed by '(' or '<'.
12955 // It is too early to resolve the type here, since it can
12956 // refer to a not yet declared function type parameter.
12957 type = ParseType(ClassFinalizer::kDoNotResolve);
12958 }
12959 while (IsSymbol(Symbols::Function())) {
12960 if (type.IsNull()) {
12961 type = Type::DynamicType();
12962 }
12963 // 'type' is the result type of the function type.
12964 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve);
12965 }
12966 // At this point, all type parameters have been parsed, resolve the type.
12967 if (finalization == ClassFinalizer::kIgnore) {
12968 return Type::DynamicType();
12969 }
12970 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
12971 ResolveType(finalization, &type);
12972 if (finalization >= ClassFinalizer::kCanonicalize) {
12973 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization);
12974 }
12975 }
12976 return type.raw();
12977 }
12978
12979
12980 // Parses and returns a function type.
12981 // If 'result_type' is not null, parsing of the result type is skipped.
12982 RawType* Parser::ParseFunctionType(
12983 const AbstractType& result_type,
12984 ClassFinalizer::FinalizationKind finalization) {
12985 TRACE_PARSER("ParseFunctionType");
12986 AbstractType& type = AbstractType::Handle(Z, result_type.raw());
12987 if (type.IsNull()) {
12988 if (CurrentToken() == Token::kVOID) {
12989 ConsumeToken();
12990 type = Type::VoidType();
12991 } else if (IsFunctionTypeSymbol()) {
12992 type = Type::DynamicType();
12993 } else {
12994 // Including 'Function' not followed by '(' or '<'.
12995 // It is too early to resolve the type here, since it can
12996 // refer to a not yet declared function type parameter.
12997 type = ParseType(ClassFinalizer::kDoNotResolve);
12998 }
12999 }
13000 if (!IsSymbol(Symbols::Function())) {
13001 ReportError("'Function' expected");
13002 }
13003 do {
13004 ConsumeToken();
13005 const Function& signature_function =
13006 Function::Handle(Z, Function::NewSignatureFunction(
13007 current_class(), TokenPosition::kNoSource));
13008 signature_function.set_parent_function(innermost_function());
13009 innermost_function_ = signature_function.raw();
13010 signature_function.set_result_type(type);
13011 // Parse optional type parameters.
13012 if (CurrentToken() == Token::kLT) {
13013 if (!FLAG_generic_method_syntax) {
13014 ReportError("generic type arguments not supported.");
13015 }
13016 ParseTypeParameters(false); // Not parameterizing class, but function.
13017 }
13018 ParamList params;
13019 // We do not yet allow Function of any arity, so expect parameter list.
13020 CheckToken(Token::kLPAREN, "formal parameter list expected");
13021
13022 // Add implicit closure object parameter. Do not specify a token position,
13023 // since it would make no sense after function type canonicalization.
13024 params.AddFinalParameter(TokenPosition::kNoSource,
13025 &Symbols::ClosureParameter(),
13026 &Object::dynamic_type());
13027
13028 const bool use_function_type_syntax = true;
13029 const bool allow_explicit_default_values = false;
13030 const bool evaluate_metadata = false;
13031 ParseFormalParameterList(use_function_type_syntax,
13032 allow_explicit_default_values, evaluate_metadata,
13033 &params);
13034 AddFormalParamsToFunction(&params, signature_function);
13035 innermost_function_ = innermost_function_.parent_function();
13036 type = signature_function.SignatureType();
13037 } while (IsSymbol(Symbols::Function()));
13038 // At this point, all type parameters have been parsed, resolve the type.
13039 if (finalization == ClassFinalizer::kIgnore) {
13040 return Type::DynamicType();
13041 }
13042 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13043 ResolveType(finalization, &type);
13044 if (finalization >= ClassFinalizer::kCanonicalize) {
13045 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization);
13046 }
13047 }
13048 return Type::RawCast(type.raw());
13049 }
13050
13051
12724 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and 13052 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and
12725 // finalize it according to the given type finalization mode. Returns prefix. 13053 // finalize it according to the given type finalization mode.
13054 // Returns type and sets prefix.
12726 RawAbstractType* Parser::ParseType( 13055 RawAbstractType* Parser::ParseType(
12727 ClassFinalizer::FinalizationKind finalization, 13056 ClassFinalizer::FinalizationKind finalization,
12728 bool allow_deferred_type, 13057 bool allow_deferred_type,
12729 bool consume_unresolved_prefix, 13058 bool consume_unresolved_prefix,
12730 LibraryPrefix* prefix) { 13059 LibraryPrefix* prefix) {
12731 TRACE_PARSER("ParseType"); 13060 TRACE_PARSER("ParseType");
12732 CheckToken(Token::kIDENT, "type name expected"); 13061 CheckToken(Token::kIDENT, "type name expected");
12733 TokenPosition ident_pos = TokenPos(); 13062 TokenPosition ident_pos = TokenPos();
12734 String& type_name = String::Handle(Z); 13063 String& type_name = String::Handle(Z);
12735 13064
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
13365 // Replace the types parsed from the constructor. 13694 // Replace the types parsed from the constructor.
13366 params.EraseParameterTypes(); 13695 params.EraseParameterTypes();
13367 13696
13368 closure = Function::NewClosureFunction(closure_name, innermost_function(), 13697 closure = Function::NewClosureFunction(closure_name, innermost_function(),
13369 token_pos); 13698 token_pos);
13370 closure.set_is_generated_body(true); 13699 closure.set_is_generated_body(true);
13371 closure.set_is_debuggable(false); 13700 closure.set_is_debuggable(false);
13372 closure.set_is_visible(false); 13701 closure.set_is_visible(false);
13373 closure.set_result_type(Object::dynamic_type()); 13702 closure.set_result_type(Object::dynamic_type());
13374 AddFormalParamsToFunction(&params, closure); 13703 AddFormalParamsToFunction(&params, closure);
13704 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure);
13375 13705
13376 // Finalize function type. 13706 // Finalize function type.
13377 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 13707 Type& signature_type = Type::Handle(Z, closure.SignatureType());
13378 signature_type ^= ClassFinalizer::FinalizeType( 13708 signature_type ^= ClassFinalizer::FinalizeType(
13379 current_class(), signature_type, ClassFinalizer::kCanonicalize); 13709 current_class(), signature_type, ClassFinalizer::kCanonicalize);
13380 closure.SetSignatureType(signature_type); 13710 closure.SetSignatureType(signature_type);
13381 // Finalization would be premature when top-level parsing. 13711 // Finalization would be premature when top-level parsing.
13382 ASSERT(!is_top_level_); 13712 ASSERT(!is_top_level_);
13383 return closure.raw(); 13713 return closure.raw();
13384 } 13714 }
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
14209 value = TryCanonicalize(value, expr_pos); 14539 value = TryCanonicalize(value, expr_pos);
14210 CacheConstantValue(expr_pos, value); 14540 CacheConstantValue(expr_pos, value);
14211 return value; 14541 return value;
14212 } 14542 }
14213 } 14543 }
14214 14544
14215 14545
14216 void Parser::SkipFunctionLiteral() { 14546 void Parser::SkipFunctionLiteral() {
14217 if (IsIdentifier()) { 14547 if (IsIdentifier()) {
14218 if (LookaheadToken(1) != Token::kLPAREN) { 14548 if (LookaheadToken(1) != Token::kLPAREN) {
14219 SkipType(true); 14549 SkipTypeOrFunctionType(true);
14220 } 14550 }
14221 ExpectIdentifier("function name expected"); 14551 ExpectIdentifier("function name expected");
14222 } 14552 }
14223 if (CurrentToken() == Token::kLPAREN) { 14553 if (CurrentToken() == Token::kLPAREN) {
14224 SkipToMatchingParenthesis(); 14554 SkipToMatchingParenthesis();
14225 } 14555 }
14226 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier(); 14556 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier();
14227 BoolScope allow_await(&this->await_is_keyword_, 14557 BoolScope allow_await(&this->await_is_keyword_,
14228 async_modifier != RawFunction::kNoModifier); 14558 async_modifier != RawFunction::kNoModifier);
14229 if (CurrentToken() == Token::kLBRACE) { 14559 if (CurrentToken() == Token::kLBRACE) {
14230 SkipBlock(); 14560 SkipBlock();
14231 ExpectToken(Token::kRBRACE); 14561 ExpectToken(Token::kRBRACE);
14232 } else if (CurrentToken() == Token::kARROW) { 14562 } else if (CurrentToken() == Token::kARROW) {
14233 ConsumeToken(); 14563 ConsumeToken();
14234 SkipExpr(); 14564 SkipExpr();
14235 } 14565 }
14236 } 14566 }
14237 14567
14238 14568
14239 // Skips function/method/constructor/getter/setter preambles until the formal 14569 // Skips function/method/constructor/getter/setter preambles until the formal
14240 // parameter list. It is enough to skip the tokens, since we have already 14570 // parameter list. It is enough to skip the tokens, since we have already
14241 // previously parsed the function. 14571 // previously parsed the function.
14242 void Parser::SkipFunctionPreamble() { 14572 void Parser::SkipFunctionPreamble() {
14243 while (true) { 14573 while (true) {
14244 const Token::Kind token = CurrentToken(); 14574 const Token::Kind token = CurrentToken();
14575 if (IsFunctionTypeSymbol()) {
14576 ConsumeToken();
14577 SkipTypeArguments();
14578 SkipToMatchingParenthesis();
14579 continue;
14580 }
14245 if (token == Token::kLPAREN) { 14581 if (token == Token::kLPAREN) {
14246 return; 14582 return;
14247 } 14583 }
14248 if (token == Token::kGET) { 14584 if (token == Token::kGET) {
14249 if (LookaheadToken(1) == Token::kLPAREN) { 14585 if (LookaheadToken(1) == Token::kLPAREN) {
14250 // Case: Function/method named get. 14586 // Case: Function/method named get.
14251 ConsumeToken(); // Parse away 'get' (the function's name). 14587 ConsumeToken(); // Parse away 'get' (the function's name).
14252 return; 14588 return;
14253 } 14589 }
14254 // Case: Getter. 14590 // Case: Getter.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
14509 SkipUnaryExpr(); 14845 SkipUnaryExpr();
14510 const int min_prec = Token::Precedence(Token::kIFNULL); 14846 const int min_prec = Token::Precedence(Token::kIFNULL);
14511 const int max_prec = Token::Precedence(Token::kMUL); 14847 const int max_prec = Token::Precedence(Token::kMUL);
14512 while (((min_prec <= Token::Precedence(CurrentToken())) && 14848 while (((min_prec <= Token::Precedence(CurrentToken())) &&
14513 (Token::Precedence(CurrentToken()) <= max_prec))) { 14849 (Token::Precedence(CurrentToken()) <= max_prec))) {
14514 if (CurrentToken() == Token::kIS) { 14850 if (CurrentToken() == Token::kIS) {
14515 ConsumeToken(); 14851 ConsumeToken();
14516 if (CurrentToken() == Token::kNOT) { 14852 if (CurrentToken() == Token::kNOT) {
14517 ConsumeToken(); 14853 ConsumeToken();
14518 } 14854 }
14519 SkipType(false); 14855 SkipTypeOrFunctionType(false);
14520 } else if (CurrentToken() == Token::kAS) { 14856 } else if (CurrentToken() == Token::kAS) {
14521 ConsumeToken(); 14857 ConsumeToken();
14522 SkipType(false); 14858 SkipTypeOrFunctionType(false);
14523 } else { 14859 } else {
14524 ConsumeToken(); 14860 ConsumeToken();
14525 SkipUnaryExpr(); 14861 SkipUnaryExpr();
14526 } 14862 }
14527 } 14863 }
14528 } 14864 }
14529 14865
14530 14866
14531 void Parser::SkipConditionalExpr() { 14867 void Parser::SkipConditionalExpr() {
14532 SkipBinaryExpr(); 14868 SkipBinaryExpr();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
14668 const ArgumentListNode& function_args, 15004 const ArgumentListNode& function_args,
14669 const LocalVariable* temp_for_last_arg, 15005 const LocalVariable* temp_for_last_arg,
14670 bool is_super_invocation) { 15006 bool is_super_invocation) {
14671 UNREACHABLE(); 15007 UNREACHABLE();
14672 return NULL; 15008 return NULL;
14673 } 15009 }
14674 15010
14675 } // namespace dart 15011 } // namespace dart
14676 15012
14677 #endif // DART_PRECOMPILED_RUNTIME 15013 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698