Index: runtime/vm/parser.cc |
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
index aafb65592dd7ebf433f229c005c10c4fa15fc158..4963568b905109b763d646ee8e33bc90db967186 100644 |
--- a/runtime/vm/parser.cc |
+++ b/runtime/vm/parser.cc |
@@ -432,12 +432,14 @@ struct ParamDesc { |
name_pos(0), |
name(NULL), |
default_value(NULL), |
+ metadata(NULL), |
is_final(false), |
is_field_initializer(false) { } |
const AbstractType* type; |
intptr_t name_pos; |
const String* name; |
const Object* default_value; // NULL if not an optional parameter. |
+ const Object* metadata; // NULL if no metadata or metadata not evaluated. |
bool is_final; |
bool is_field_initializer; |
}; |
@@ -791,17 +793,24 @@ RawObject* Parser::ParseFunctionParameters(const Function& func) { |
parser.set_current_class(owner); |
parser.SkipFunctionPreamble(); |
ParamList params; |
- parser.ParseFormalParameterList(true, ¶ms); |
+ parser.ParseFormalParameterList(true, true, ¶ms); |
ParamDesc* param = params.parameters->data(); |
const int param_cnt = params.num_fixed_parameters + |
params.num_optional_parameters; |
- Array& param_descriptor = Array::Handle(isolate, Array::New(param_cnt * 2)); |
- for (int i = 0, j = 0; i < param_cnt; i++, j += 2) { |
+ Array& param_descriptor = Array::Handle(Array::New(param_cnt * 3)); |
+ for (int i = 0, j = 0; i < param_cnt; i++, j += 3) { |
param_descriptor.SetAt(j, param[i].is_final ? Bool::True() : |
siva
2013/08/28 23:26:48
Ditto comment about '3' here.
|
Bool::False()); |
param_descriptor.SetAt(j + 1, |
(param[i].default_value == NULL) ? Object::null_instance() : |
*(param[i].default_value)); |
+ const Object* metadata = param[i].metadata; |
+ if ((metadata != NULL) && (*metadata).IsError()) { |
+ return (*metadata).raw(); // Error evaluating the metadata. |
+ } |
+ param_descriptor.SetAt(j + 2, |
+ (param[i].metadata == NULL) ? Object::null_instance() : |
+ *(param[i].metadata)); |
} |
isolate->set_long_jump_base(base); |
return param_descriptor.raw(); |
@@ -1381,13 +1390,19 @@ void Parser::SkipBlock() { |
void Parser::ParseFormalParameter(bool allow_explicit_default_value, |
+ bool evaluate_metadata, |
ParamList* params) { |
TRACE_PARSER("ParseFormalParameter"); |
ParamDesc parameter; |
bool var_seen = false; |
bool this_seen = false; |
- SkipMetadata(); |
+ if (evaluate_metadata && (CurrentToken() == Token::kAT)) { |
+ parameter.metadata = &Array::ZoneHandle(EvaluateMetadata()); |
+ } else { |
+ SkipMetadata(); |
+ } |
+ |
if (CurrentToken() == Token::kFINAL) { |
ConsumeToken(); |
parameter.is_final = true; |
@@ -1487,7 +1502,7 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value, |
&Type::ZoneHandle(Type::DynamicType())); |
const bool no_explicit_default_values = false; |
- ParseFormalParameterList(no_explicit_default_values, &func_params); |
+ ParseFormalParameterList(no_explicit_default_values, false, &func_params); |
// The field 'is_static' has no meaning for signature functions. |
const Function& signature_function = Function::Handle( |
@@ -1571,6 +1586,7 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value, |
// Parses a sequence of normal or optional formal parameters. |
void Parser::ParseFormalParameters(bool allow_explicit_default_values, |
+ bool evaluate_metadata, |
ParamList* params) { |
TRACE_PARSER("ParseFormalParameters"); |
do { |
@@ -1589,23 +1605,30 @@ void Parser::ParseFormalParameters(bool allow_explicit_default_values, |
params->has_optional_named_parameters = true; |
return; |
} |
- ParseFormalParameter(allow_explicit_default_values, params); |
+ ParseFormalParameter(allow_explicit_default_values, |
+ evaluate_metadata, |
+ params); |
} while (CurrentToken() == Token::kCOMMA); |
} |
void Parser::ParseFormalParameterList(bool allow_explicit_default_values, |
+ bool evaluate_metadata, |
ParamList* params) { |
TRACE_PARSER("ParseFormalParameterList"); |
ASSERT(CurrentToken() == Token::kLPAREN); |
if (LookaheadToken(1) != Token::kRPAREN) { |
// Parse fixed parameters. |
- ParseFormalParameters(allow_explicit_default_values, params); |
+ ParseFormalParameters(allow_explicit_default_values, |
+ evaluate_metadata, |
+ params); |
if (params->has_optional_positional_parameters || |
params->has_optional_named_parameters) { |
// Parse optional parameters. |
- ParseFormalParameters(allow_explicit_default_values, params); |
+ ParseFormalParameters(allow_explicit_default_values, |
+ evaluate_metadata, |
+ params); |
if (params->has_optional_positional_parameters) { |
if (CurrentToken() != Token::kRBRACK) { |
ErrorMsg("',' or ']' expected"); |
@@ -2496,7 +2519,7 @@ SequenceNode* Parser::ParseConstructor(const Function& func, |
if (func.is_const()) { |
params.SetImplicitlyFinal(); |
} |
- ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
+ ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
@@ -2748,7 +2771,7 @@ SequenceNode* Parser::ParseFunc(const Function& func, |
ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); |
const bool allow_explicit_default_values = true; |
if (!func.IsGetterFunction()) { |
- ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
+ ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
} else { |
// TODO(hausner): Remove this once we no longer support the old |
// getter syntax with explicit empty parameter list. |
@@ -2985,7 +3008,9 @@ void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { |
method->params.SetImplicitlyFinal(); |
} |
if (!method->IsGetter()) { |
- ParseFormalParameterList(allow_explicit_default_values, &method->params); |
+ ParseFormalParameterList(allow_explicit_default_values, |
+ false, |
+ &method->params); |
} |
// Now that we know the parameter list, we can distinguish between the |
@@ -4037,7 +4062,7 @@ void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, |
&Type::ZoneHandle(Type::DynamicType())); |
const bool no_explicit_default_values = false; |
- ParseFormalParameterList(no_explicit_default_values, &func_params); |
+ ParseFormalParameterList(no_explicit_default_values, false, &func_params); |
ExpectSemicolon(); |
// The field 'is_static' has no meaning for signature functions. |
Function& signature_function = Function::Handle( |
@@ -4486,7 +4511,7 @@ void Parser::ParseTopLevelFunction(TopLevel* top_level, |
const intptr_t function_pos = TokenPos(); |
ParamList params; |
const bool allow_explicit_default_values = true; |
- ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
+ ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
intptr_t function_end_pos = function_pos; |
if (is_external) { |
@@ -4575,7 +4600,7 @@ void Parser::ParseTopLevelAccessor(TopLevel* top_level, |
if (!is_getter) { |
const bool allow_explicit_default_values = true; |
- ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
+ ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
} |
String& accessor_name = String::ZoneHandle(); |
int expected_num_parameters = -1; |
@@ -10183,7 +10208,7 @@ void Parser::SkipFunctionLiteral() { |
const bool allow_explicit_default_values = true; |
ParamList params; |
params.skipped = true; |
- ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
+ ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
} |
if (CurrentToken() == Token::kLBRACE) { |
SkipBlock(); |