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

Unified Diff: runtime/lib/error.cc

Issue 9515011: Add support for malformed types and postpone some related errors from compile (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/error.h ('k') | runtime/lib/error.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/error.cc
===================================================================
--- runtime/lib/error.cc (revision 4731)
+++ runtime/lib/error.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -106,7 +106,8 @@
static void ThrowTypeError(intptr_t location,
const String& src_type_name,
const String& dst_type_name,
- const String& dst_name) {
+ const String& dst_name,
+ const String& malformed_error) {
// Allocate a new instance of TypeError.
const Instance& type_error = Instance::Handle(NewInstance("TypeError"));
@@ -139,18 +140,25 @@
// Initialize field 'dstName'.
SetField(type_error, cls, "dstName", dst_name);
+ // Initialize field 'malformedError'.
+ SetField(type_error, cls, "malformedError", malformed_error);
+
// Type errors in the core library may be difficult to diagnose.
// Print type error information before throwing the error when debugging.
if (FLAG_print_stack_trace_at_throw) {
- intptr_t line, column;
- script.GetTokenLocation(location, &line, &column);
- OS::Print("'%s': Failed type check: line %d pos %d: "
- "type '%s' is not assignable to type '%s' of '%s'.\n",
- String::Handle(script.url()).ToCString(),
- line, column,
- src_type_name.ToCString(),
- dst_type_name.ToCString(),
- dst_name.ToCString());
+ if (!malformed_error.IsNull()) {
+ OS::Print("%s", malformed_error.ToCString());
+ } else {
+ intptr_t line, column;
+ script.GetTokenLocation(location, &line, &column);
+ OS::Print("'%s': Failed type check: line %d pos %d: "
+ "type '%s' is not assignable to type '%s' of '%s'.\n",
+ String::Handle(script.url()).ToCString(),
+ line, column,
+ src_type_name.ToCString(),
+ dst_type_name.ToCString(),
+ dst_name.ToCString());
+ }
}
// Throw TypeError instance.
Exceptions::Throw(type_error);
@@ -163,15 +171,18 @@
// Arg1: src value.
// Arg2: dst type name.
// Arg3: dst name.
+// Arg4: malformed type error message.
// Return value: none, throws an exception.
-DEFINE_NATIVE_ENTRY(TypeError_throwNew, 4) {
+DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) {
intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value();
const Instance& src_value = Instance::CheckedHandle(arguments->At(1));
const String& dst_type_name = String::CheckedHandle(arguments->At(2));
const String& dst_name = String::CheckedHandle(arguments->At(3));
+ const String& malformed_error = String::CheckedHandle(arguments->At(4));
const String& src_type_name =
String::Handle(Type::Handle(src_value.GetType()).Name());
- ThrowTypeError(location, src_type_name, dst_type_name, dst_name);
+ ThrowTypeError(location, src_type_name,
+ dst_type_name, dst_name, malformed_error);
}
@@ -291,7 +302,9 @@
} else {
dst_type_name = dst_type.Name();
}
- ThrowTypeError(location, src_type_name, dst_type_name, dst_name);
+ const String& no_malformed_type_error = String::Handle();
+ ThrowTypeError(location, src_type_name, dst_type_name, dst_name,
+ no_malformed_type_error);
UNREACHABLE();
}
arguments.SetReturn(src_instance);
@@ -308,17 +321,40 @@
intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value();
const Instance& src_instance = Instance::CheckedHandle(arguments.At(1));
ASSERT(src_instance.IsNull() || !src_instance.IsBool());
- const char* msg = "boolean expression";
const Type& bool_interface = Type::Handle(Type::BoolInterface());
const Type& src_type = Type::Handle(src_instance.GetType());
const String& src_type_name = String::Handle(src_type.Name());
const String& bool_type_name = String::Handle(bool_interface.Name());
- ThrowTypeError(location, src_type_name, bool_type_name,
- String::Handle(String::NewSymbol(msg)));
+ const String& expr = String::Handle(String::NewSymbol("boolean expression"));
+ const String& no_malformed_type_error = String::Handle();
+ ThrowTypeError(location, src_type_name, bool_type_name, expr,
+ no_malformed_type_error);
UNREACHABLE();
}
+// Report that the type of the type check is malformed.
+// Arg0: index of the token of the failed type check.
+// Arg1: src value.
+// Arg2: malformed type error message.
+// Return value: none, throws an exception.
+DEFINE_RUNTIME_ENTRY(MalformedTypeError, 3) {
+ ASSERT(arguments.Count() ==
+ kMalformedTypeErrorRuntimeEntry.argument_count());
+ intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value();
+ const Instance& src_value = Instance::CheckedHandle(arguments.At(1));
+ const String& malformed_error = String::CheckedHandle(arguments.At(2));
+ const String& dst_type_name =
+ String::Handle(String::NewSymbol("malformed type"));
+ const String& dst_name = String::Handle(String::NewSymbol(""));
+ const String& src_type_name =
+ String::Handle(Type::Handle(src_value.GetType()).Name());
+ ThrowTypeError(location, src_type_name,
+ dst_type_name, dst_name, malformed_error);
+ UNREACHABLE();
+}
+
+
// Check that the type of each element of the given array is assignable to the
// given type.
// Arg0: index of the token of the rest argument declaration (source location).
@@ -361,7 +397,9 @@
dst_type_name = element_type.Name();
}
const String& dst_name = String::Handle(String::New(buf));
- ThrowTypeError(location, src_type_name, dst_type_name, dst_name);
+ const String& no_malformed_type_error = String::Handle();
+ ThrowTypeError(location, src_type_name, dst_type_name, dst_name,
+ no_malformed_type_error);
UNREACHABLE();
}
}
« no previous file with comments | « runtime/lib/error.h ('k') | runtime/lib/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698