OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #if defined(DEBUG) | 51 #if defined(DEBUG) |
52 class TraceParser : public ValueObject { | 52 class TraceParser : public ValueObject { |
53 public: | 53 public: |
54 TraceParser(intptr_t token_pos, const Script& script, const char* msg) { | 54 TraceParser(intptr_t token_pos, const Script& script, const char* msg) { |
55 if (FLAG_trace_parser) { | 55 if (FLAG_trace_parser) { |
56 // Skips tracing of bootstrap libraries. | 56 // Skips tracing of bootstrap libraries. |
57 if (script.HasSource()) { | 57 if (script.HasSource()) { |
58 intptr_t line, column; | 58 intptr_t line, column; |
59 script.GetTokenLocation(token_pos, &line, &column); | 59 script.GetTokenLocation(token_pos, &line, &column); |
60 PrintIndent(); | 60 PrintIndent(); |
61 OS::Print("%s (line %"Pd", col %"Pd", token %"Pd")\n", | 61 OS::Print("%s (line %" Pd ", col %" Pd ", token %" Pd ")\n", |
62 msg, line, column, token_pos); | 62 msg, line, column, token_pos); |
63 } | 63 } |
64 indent_++; | 64 indent_++; |
65 } | 65 } |
66 } | 66 } |
67 ~TraceParser() { indent_--; } | 67 ~TraceParser() { indent_--; } |
68 private: | 68 private: |
69 void PrintIndent() { | 69 void PrintIndent() { |
70 for (int i = 0; i < indent_; i++) { OS::Print(". "); } | 70 for (int i = 0; i < indent_; i++) { OS::Print(". "); } |
71 } | 71 } |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 Array& default_values) { | 1126 Array& default_values) { |
1127 ParamList params; | 1127 ParamList params; |
1128 // Receiver first. | 1128 // Receiver first. |
1129 intptr_t token_pos = func.token_pos(); | 1129 intptr_t token_pos = func.token_pos(); |
1130 params.AddReceiver(ReceiverType(current_class()), token_pos); | 1130 params.AddReceiver(ReceiverType(current_class()), token_pos); |
1131 // Remaining positional parameters. | 1131 // Remaining positional parameters. |
1132 intptr_t i = 1; | 1132 intptr_t i = 1; |
1133 for (; i < desc.PositionalCount(); ++i) { | 1133 for (; i < desc.PositionalCount(); ++i) { |
1134 ParamDesc p; | 1134 ParamDesc p; |
1135 char name[64]; | 1135 char name[64]; |
1136 OS::SNPrint(name, 64, ":p%"Pd, i); | 1136 OS::SNPrint(name, 64, ":p%" Pd, i); |
1137 p.name = &String::ZoneHandle(Symbols::New(name)); | 1137 p.name = &String::ZoneHandle(Symbols::New(name)); |
1138 p.type = &Type::ZoneHandle(Type::DynamicType()); | 1138 p.type = &Type::ZoneHandle(Type::DynamicType()); |
1139 params.parameters->Add(p); | 1139 params.parameters->Add(p); |
1140 params.num_fixed_parameters++; | 1140 params.num_fixed_parameters++; |
1141 } | 1141 } |
1142 ASSERT(desc.PositionalCount() == params.num_fixed_parameters); | 1142 ASSERT(desc.PositionalCount() == params.num_fixed_parameters); |
1143 | 1143 |
1144 // Named parameters. | 1144 // Named parameters. |
1145 for (; i < desc.Count(); ++i) { | 1145 for (; i < desc.Count(); ++i) { |
1146 ParamDesc p; | 1146 ParamDesc p; |
(...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3253 } else if ((op == Token::kBIT_NOT) || (op == Token::kNEGATE)) { | 3253 } else if ((op == Token::kBIT_NOT) || (op == Token::kNEGATE)) { |
3254 expected_num_parameters = 1; | 3254 expected_num_parameters = 1; |
3255 } else { | 3255 } else { |
3256 expected_num_parameters = 2; | 3256 expected_num_parameters = 2; |
3257 } | 3257 } |
3258 if ((member.params.num_optional_parameters > 0) || | 3258 if ((member.params.num_optional_parameters > 0) || |
3259 member.params.has_optional_positional_parameters || | 3259 member.params.has_optional_positional_parameters || |
3260 member.params.has_optional_named_parameters || | 3260 member.params.has_optional_named_parameters || |
3261 (member.params.num_fixed_parameters != expected_num_parameters)) { | 3261 (member.params.num_fixed_parameters != expected_num_parameters)) { |
3262 // Subtract receiver when reporting number of expected arguments. | 3262 // Subtract receiver when reporting number of expected arguments. |
3263 ErrorMsg(member.name_pos, "operator %s expects %"Pd" argument(s)", | 3263 ErrorMsg(member.name_pos, "operator %s expects %" Pd " argument(s)", |
3264 member.name->ToCString(), (expected_num_parameters - 1)); | 3264 member.name->ToCString(), (expected_num_parameters - 1)); |
3265 } | 3265 } |
3266 } | 3266 } |
3267 | 3267 |
3268 | 3268 |
3269 void Parser::ParseClassMemberDefinition(ClassDesc* members, | 3269 void Parser::ParseClassMemberDefinition(ClassDesc* members, |
3270 intptr_t metadata_pos) { | 3270 intptr_t metadata_pos) { |
3271 TRACE_PARSER("ParseClassMemberDefinition"); | 3271 TRACE_PARSER("ParseClassMemberDefinition"); |
3272 MemberDesc member; | 3272 MemberDesc member; |
3273 current_member_ = &member; | 3273 current_member_ = &member; |
(...skipping 3571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6845 intptr_t token_pos, | 6845 intptr_t token_pos, |
6846 const char* message_header, | 6846 const char* message_header, |
6847 const char* format, va_list args) { | 6847 const char* format, va_list args) { |
6848 String& result = String::Handle(); | 6848 String& result = String::Handle(); |
6849 const String& msg = String::Handle(String::NewFormattedV(format, args)); | 6849 const String& msg = String::Handle(String::NewFormattedV(format, args)); |
6850 if (!script.IsNull()) { | 6850 if (!script.IsNull()) { |
6851 const String& script_url = String::Handle(script.url()); | 6851 const String& script_url = String::Handle(script.url()); |
6852 if (token_pos >= 0) { | 6852 if (token_pos >= 0) { |
6853 intptr_t line, column; | 6853 intptr_t line, column; |
6854 script.GetTokenLocation(token_pos, &line, &column); | 6854 script.GetTokenLocation(token_pos, &line, &column); |
6855 result = String::NewFormatted("'%s': %s: line %"Pd" pos %"Pd": ", | 6855 result = String::NewFormatted("'%s': %s: line %" Pd " pos %" Pd ": ", |
6856 script_url.ToCString(), | 6856 script_url.ToCString(), |
6857 message_header, | 6857 message_header, |
6858 line, | 6858 line, |
6859 column); | 6859 column); |
6860 // Append the formatted error or warning message. | 6860 // Append the formatted error or warning message. |
6861 result = String::Concat(result, msg); | 6861 result = String::Concat(result, msg); |
6862 const String& new_line = String::Handle(String::New("\n")); | 6862 const String& new_line = String::Handle(String::New("\n")); |
6863 // Append the source line. | 6863 // Append the source line. |
6864 const String& script_line = String::Handle(script.GetLine(line)); | 6864 const String& script_line = String::Handle(script.GetLine(line)); |
6865 ASSERT(!script_line.IsNull()); | 6865 ASSERT(!script_line.IsNull()); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7234 Type::ZoneHandle(Type::DynamicType())); | 7234 Type::ZoneHandle(Type::DynamicType())); |
7235 ASSERT(temp != NULL); | 7235 ASSERT(temp != NULL); |
7236 parsed_function()->set_saved_current_context_var(temp); | 7236 parsed_function()->set_saved_current_context_var(temp); |
7237 } | 7237 } |
7238 } | 7238 } |
7239 | 7239 |
7240 | 7240 |
7241 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, | 7241 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, |
7242 const char* s) { | 7242 const char* s) { |
7243 char name[64]; | 7243 char name[64]; |
7244 OS::SNPrint(name, 64, ":%s%"Pd, s, token_pos); | 7244 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); |
7245 LocalVariable* temp = | 7245 LocalVariable* temp = |
7246 new LocalVariable(token_pos, | 7246 new LocalVariable(token_pos, |
7247 String::ZoneHandle(Symbols::New(name)), | 7247 String::ZoneHandle(Symbols::New(name)), |
7248 Type::ZoneHandle(Type::DynamicType())); | 7248 Type::ZoneHandle(Type::DynamicType())); |
7249 temp->set_is_final(); | 7249 temp->set_is_final(); |
7250 current_block_->scope->AddVariable(temp); | 7250 current_block_->scope->AddVariable(temp); |
7251 return temp; | 7251 return temp; |
7252 } | 7252 } |
7253 | 7253 |
7254 | 7254 |
(...skipping 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10327 void Parser::SkipQualIdent() { | 10327 void Parser::SkipQualIdent() { |
10328 ASSERT(IsIdentifier()); | 10328 ASSERT(IsIdentifier()); |
10329 ConsumeToken(); | 10329 ConsumeToken(); |
10330 if (CurrentToken() == Token::kPERIOD) { | 10330 if (CurrentToken() == Token::kPERIOD) { |
10331 ConsumeToken(); // Consume the kPERIOD token. | 10331 ConsumeToken(); // Consume the kPERIOD token. |
10332 ExpectIdentifier("identifier expected after '.'"); | 10332 ExpectIdentifier("identifier expected after '.'"); |
10333 } | 10333 } |
10334 } | 10334 } |
10335 | 10335 |
10336 } // namespace dart | 10336 } // namespace dart |
OLD | NEW |