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

Side by Side Diff: vm/parser.cc

Issue 11613009: Changed the API in DartEntry for invoking dart code from C++ to make it more compatible with the re… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 7826 matching lines...) Expand 10 before | Expand all | Expand 10 after
7837 } else if (value.raw() == Object::sentinel()) { 7837 } else if (value.raw() == Object::sentinel()) {
7838 // This field has not been referenced yet and thus the value has 7838 // This field has not been referenced yet and thus the value has
7839 // not been evaluated. If the field is const, call the static getter method 7839 // not been evaluated. If the field is const, call the static getter method
7840 // to evaluate the expression and canonicalize the value. 7840 // to evaluate the expression and canonicalize the value.
7841 if (field.is_const()) { 7841 if (field.is_const()) {
7842 field.set_value(Instance::Handle(Object::transition_sentinel())); 7842 field.set_value(Instance::Handle(Object::transition_sentinel()));
7843 const String& field_name = String::Handle(field.name()); 7843 const String& field_name = String::Handle(field.name());
7844 const String& getter_name = 7844 const String& getter_name =
7845 String::Handle(Field::GetterName(field_name)); 7845 String::Handle(Field::GetterName(field_name));
7846 const Class& cls = Class::Handle(field.owner()); 7846 const Class& cls = Class::Handle(field.owner());
7847 GrowableArray<const Object*> arguments; // no arguments.
7848 const int kNumArguments = 0; // no arguments. 7847 const int kNumArguments = 0; // no arguments.
7849 const Array& kNoArgumentNames = Array::Handle(); 7848 const Array& kNoArgumentNames = Array::Handle();
7850 const Function& func = 7849 const Function& func =
7851 Function::Handle(Resolver::ResolveStatic(cls, 7850 Function::Handle(Resolver::ResolveStatic(cls,
7852 getter_name, 7851 getter_name,
7853 kNumArguments, 7852 kNumArguments,
7854 kNoArgumentNames, 7853 kNoArgumentNames,
7855 Resolver::kIsQualified)); 7854 Resolver::kIsQualified));
7856 ASSERT(!func.IsNull()); 7855 ASSERT(!func.IsNull());
7857 ASSERT(func.kind() == RawFunction::kConstImplicitGetter); 7856 ASSERT(func.kind() == RawFunction::kConstImplicitGetter);
7858 Object& const_value = Object::Handle( 7857 const Array& args = Array::Handle(Object::empty_array());
7859 DartEntry::InvokeStatic(func, arguments, kNoArgumentNames)); 7858 Object& const_value = Object::Handle(DartEntry::InvokeStatic(func, args));
7860 if (const_value.IsError()) { 7859 if (const_value.IsError()) {
7861 const Error& error = Error::Cast(const_value); 7860 const Error& error = Error::Cast(const_value);
7862 if (error.IsUnhandledException()) { 7861 if (error.IsUnhandledException()) {
7863 field.set_value(Instance::Handle()); 7862 field.set_value(Instance::Handle());
7864 // It is a compile-time error if evaluation of a compile-time constant 7863 // It is a compile-time error if evaluation of a compile-time constant
7865 // would raise an exception. 7864 // would raise an exception.
7866 AppendErrorMsg(error, TokenPos(), 7865 AppendErrorMsg(error, TokenPos(),
7867 "error initializing const field '%s'", 7866 "error initializing const field '%s'",
7868 String::Handle(field.name()).ToCString()); 7867 String::Handle(field.name()).ToCString());
7869 } else { 7868 } else {
(...skipping 17 matching lines...) Expand all
7887 } 7886 }
7888 return NULL; 7887 return NULL;
7889 } 7888 }
7890 7889
7891 7890
7892 RawObject* Parser::EvaluateConstConstructorCall( 7891 RawObject* Parser::EvaluateConstConstructorCall(
7893 const Class& type_class, 7892 const Class& type_class,
7894 const AbstractTypeArguments& type_arguments, 7893 const AbstractTypeArguments& type_arguments,
7895 const Function& constructor, 7894 const Function& constructor,
7896 ArgumentListNode* arguments) { 7895 ArgumentListNode* arguments) {
7897 // +2 for implicit receiver and construction phase arguments. 7896 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args.
7898 GrowableArray<const Object*> arg_values(arguments->length() + 2); 7897 const int num_arguments = arguments->length() + kNumExtraArgs;
7898 const Array& arg_values = Array::Handle(Array::New(num_arguments));
7899 Instance& instance = Instance::Handle(); 7899 Instance& instance = Instance::Handle();
7900 ASSERT(!constructor.IsFactory()); 7900 ASSERT(!constructor.IsFactory());
7901 instance = Instance::New(type_class, Heap::kOld); 7901 instance = Instance::New(type_class, Heap::kOld);
7902 if (!type_arguments.IsNull()) { 7902 if (!type_arguments.IsNull()) {
7903 if (!type_arguments.IsInstantiated()) { 7903 if (!type_arguments.IsInstantiated()) {
7904 ErrorMsg("type must be constant in const constructor"); 7904 ErrorMsg("type must be constant in const constructor");
7905 } 7905 }
7906 instance.SetTypeArguments( 7906 instance.SetTypeArguments(
7907 AbstractTypeArguments::Handle(type_arguments.Canonicalize())); 7907 AbstractTypeArguments::Handle(type_arguments.Canonicalize()));
7908 } 7908 }
7909 arg_values.Add(&instance); 7909 arg_values.SetAt(0, instance);
7910 arg_values.Add(&Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 7910 arg_values.SetAt(1, Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
7911 for (int i = 0; i < arguments->length(); i++) { 7911 for (int i = 0; i < arguments->length(); i++) {
7912 AstNode* arg = arguments->NodeAt(i); 7912 AstNode* arg = arguments->NodeAt(i);
7913 // Arguments have been evaluated to a literal value already. 7913 // Arguments have been evaluated to a literal value already.
7914 ASSERT(arg->IsLiteralNode()); 7914 ASSERT(arg->IsLiteralNode());
7915 arg_values.Add(&arg->AsLiteralNode()->literal()); 7915 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal());
7916 } 7916 }
7917 const Array& opt_arg_names = arguments->names(); 7917 const Array& arg_descriptor =
7918 const Object& result = Object::Handle( 7918 Array::Handle(ArgumentsDescriptor::New(num_arguments,
7919 DartEntry::InvokeStatic(constructor, arg_values, opt_arg_names)); 7919 arguments->names()));
7920 const Object& result =
7921 Object::Handle(DartEntry::InvokeStatic(constructor,
7922 arg_values,
7923 arg_descriptor));
7920 if (result.IsError()) { 7924 if (result.IsError()) {
7921 if (result.IsUnhandledException()) { 7925 if (result.IsUnhandledException()) {
7922 return result.raw(); 7926 return result.raw();
7923 } else { 7927 } else {
7924 Isolate::Current()->long_jump_base()->Jump(1, Error::Cast(result)); 7928 Isolate::Current()->long_jump_base()->Jump(1, Error::Cast(result));
7925 UNREACHABLE(); 7929 UNREACHABLE();
7926 return Object::null(); 7930 return Object::null();
7927 } 7931 }
7928 } else { 7932 } else {
7929 if (!instance.IsNull()) { 7933 if (!instance.IsNull()) {
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
9109 ASSERT(!func.IsNull()); 9113 ASSERT(!func.IsNull());
9110 9114
9111 // Build the array of literal values to interpolate. 9115 // Build the array of literal values to interpolate.
9112 const Array& value_arr = Array::Handle(Array::New(values->length())); 9116 const Array& value_arr = Array::Handle(Array::New(values->length()));
9113 for (int i = 0; i < values->length(); i++) { 9117 for (int i = 0; i < values->length(); i++) {
9114 ASSERT(values->ElementAt(i)->IsLiteralNode()); 9118 ASSERT(values->ElementAt(i)->IsLiteralNode());
9115 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); 9119 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal());
9116 } 9120 }
9117 9121
9118 // Build argument array to pass to the interpolation function. 9122 // Build argument array to pass to the interpolation function.
9119 GrowableArray<const Object*> interpolate_arg; 9123 const Array& interpolate_arg = Array::Handle(Array::New(1));
9120 interpolate_arg.Add(&value_arr); 9124 interpolate_arg.SetAt(0, value_arr);
9121 const Array& kNoArgumentNames = Array::Handle();
9122 9125
9123 // Call interpolation function. 9126 // Call interpolation function.
9124 String& concatenated = String::ZoneHandle(); 9127 String& concatenated = String::ZoneHandle();
9125 concatenated ^= DartEntry::InvokeStatic(func, 9128 concatenated ^= DartEntry::InvokeStatic(func, interpolate_arg);
9126 interpolate_arg,
9127 kNoArgumentNames);
9128 if (concatenated.IsUnhandledException()) { 9129 if (concatenated.IsUnhandledException()) {
9129 ErrorMsg("Exception thrown in Parser::Interpolate"); 9130 ErrorMsg("Exception thrown in Parser::Interpolate");
9130 } 9131 }
9131 concatenated = Symbols::New(concatenated); 9132 concatenated = Symbols::New(concatenated);
9132 return concatenated; 9133 return concatenated;
9133 } 9134 }
9134 9135
9135 9136
9136 // A string literal consists of the concatenation of the next n tokens 9137 // A string literal consists of the concatenation of the next n tokens
9137 // that satisfy the EBNF grammar: 9138 // that satisfy the EBNF grammar:
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
9696 void Parser::SkipQualIdent() { 9697 void Parser::SkipQualIdent() {
9697 ASSERT(IsIdentifier()); 9698 ASSERT(IsIdentifier());
9698 ConsumeToken(); 9699 ConsumeToken();
9699 if (CurrentToken() == Token::kPERIOD) { 9700 if (CurrentToken() == Token::kPERIOD) {
9700 ConsumeToken(); // Consume the kPERIOD token. 9701 ConsumeToken(); // Consume the kPERIOD token.
9701 ExpectIdentifier("identifier expected after '.'"); 9702 ExpectIdentifier("identifier expected after '.'");
9702 } 9703 }
9703 } 9704 }
9704 9705
9705 } // namespace dart 9706 } // namespace dart
OLDNEW
« vm/dart_entry.h ('K') | « vm/isolate.cc ('k') | vm/resolver_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698