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

Unified Diff: runtime/vm/kernel_to_il.cc

Issue 2621343002: VM: [Kernel] Add kernel::ConstantEvaluator support for string.length (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel_to_il.cc
diff --git a/runtime/vm/kernel_to_il.cc b/runtime/vm/kernel_to_il.cc
index 73760227dabbe7928674ab39c94203236b2e7315..2133a130028d3bd2245938b02c716f500df376c5 100644
--- a/runtime/vm/kernel_to_il.cc
+++ b/runtime/vm/kernel_to_il.cc
@@ -1770,6 +1770,28 @@ void ConstantEvaluator::VisitNot(Not* node) {
}
+void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) {
+ const size_t kLengthLen = strlen("length");
+
+ String* string = node->name()->string();
+ if (string->size() == kLengthLen &&
+ memcmp(string->buffer(), "length", kLengthLen) == 0) {
+ node->receiver()->AcceptExpressionVisitor(this);
+ if (result_.IsString()) {
+ const dart::String& str =
+ dart::String::Handle(Z, dart::String::RawCast(result_.raw()));
+ result_ = Integer::New(str.Length());
+ } else {
+ H.ReportError(
+ "Constant expressions can only call "
+ "'length' on string constants.");
+ }
+ } else {
+ VisitDefaultExpression(node);
+ }
+}
+
+
const TypeArguments* ConstantEvaluator::TranslateTypeArguments(
const Function& target,
dart::Class* target_klass,
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698