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

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 9959134: Implement StringConcatNode in flow graph builder (it is ised on for "+" on strings, will be soon re… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/dart_entry.h"
8 #include "vm/flags.h" 9 #include "vm/flags.h"
9 #include "vm/intermediate_language.h" 10 #include "vm/intermediate_language.h"
10 #include "vm/longjump.h" 11 #include "vm/longjump.h"
12 #include "vm/object_store.h"
11 #include "vm/os.h" 13 #include "vm/os.h"
12 #include "vm/parser.h" 14 #include "vm/parser.h"
15 #include "vm/resolver.h"
13 #include "vm/stub_code.h" 16 #include "vm/stub_code.h"
14 17
15 namespace dart { 18 namespace dart {
16 19
17 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); 20 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph.");
18 DECLARE_FLAG(bool, enable_type_checks); 21 DECLARE_FLAG(bool, enable_type_checks);
19 DECLARE_FLAG(bool, print_ast); 22 DECLARE_FLAG(bool, print_ast);
20 23
21 void EffectGraphVisitor::Append(const EffectGraphVisitor& other_fragment) { 24 void EffectGraphVisitor::Append(const EffectGraphVisitor& other_fragment) {
22 ASSERT(is_open()); 25 ASSERT(is_open());
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 new BindInstr(temp_index(), new ConstantVal(bool_true))); 301 new BindInstr(temp_index(), new ConstantVal(bool_true)));
299 Join(for_test, for_true, for_right); 302 Join(for_test, for_true, for_right);
300 } 303 }
301 ReturnValue(new TempVal(AllocateTempIndex())); 304 ReturnValue(new TempVal(AllocateTempIndex()));
302 return; 305 return;
303 } 306 }
304 EffectGraphVisitor::VisitBinaryOpNode(node); 307 EffectGraphVisitor::VisitBinaryOpNode(node);
305 } 308 }
306 309
307 310
308 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) { 311 void EffectGraphVisitor::CompiletimeStringInterpolation(
309 Bailout("EffectGraphVisitor::VisitStringConcatNode"); 312 const Function& interpol_func, const Array& literals) {
313 // Do nothing.
310 } 314 }
311 315
312 316
317 void ValueGraphVisitor::CompiletimeStringInterpolation(
318 const Function& interpol_func, const Array& literals) {
319 // Build argument array to pass to the interpolation function.
320 GrowableArray<const Object*> interpolate_arg;
321 interpolate_arg.Add(&literals);
322 const Array& kNoArgumentNames = Array::Handle();
323 // Call the interpolation function.
324 String& concatenated = String::ZoneHandle();
325 concatenated ^= DartEntry::InvokeStatic(interpol_func,
326 interpolate_arg,
327 kNoArgumentNames);
328 if (concatenated.IsUnhandledException()) {
329 // TODO(srdjan): Remove this node and this UNREACHABLE.
330 UNREACHABLE();
331 }
332 ASSERT(!concatenated.IsNull());
333 concatenated = String::NewSymbol(concatenated);
334 ReturnValue(new ConstantVal(concatenated));
335 }
336
337
338
339 // TODO(srdjan): Remove this node once the "+" string operator has been
340 // eliminated.
341 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) {
342 const String& cls_name = String::Handle(String::NewSymbol("StringBase"));
343 const Library& core_lib = Library::Handle(
344 Isolate::Current()->object_store()->core_library());
345 const Class& cls = Class::Handle(core_lib.LookupClass(cls_name));
346 ASSERT(!cls.IsNull());
347 const String& func_name = String::Handle(String::NewSymbol("_interpolate"));
348 const int number_of_parameters = 1;
349 const Function& interpol_func = Function::ZoneHandle(
350 Resolver::ResolveStatic(cls, func_name,
351 number_of_parameters,
352 Array::Handle(),
353 Resolver::kIsQualified));
354 ASSERT(!interpol_func.IsNull());
355
356 // First try to concatenate and canonicalize the values at compile time.
357 bool compile_time_interpolation = true;
358 Array& literals = Array::Handle(Array::New(node->values()->length()));
359 for (int i = 0; i < node->values()->length(); i++) {
360 if (node->values()->ElementAt(i)->IsLiteralNode()) {
361 LiteralNode* lit = node->values()->ElementAt(i)->AsLiteralNode();
362 literals.SetAt(i, lit->literal());
363 } else {
364 compile_time_interpolation = false;
365 break;
366 }
367 }
368 if (compile_time_interpolation) {
369 // Not needed for effect, only for value
370 CompiletimeStringInterpolation(interpol_func, literals);
371 return;
372 }
373 // Runtime string interpolation.
374 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>();
375 ArgumentListNode* interpol_arg = new ArgumentListNode(node->token_index());
376 interpol_arg->Add(node->values());
377 TranslateArgumentList(*interpol_arg, temp_index(), values);
378 StaticCallComp* call =
379 new StaticCallComp(node->token_index(),
380 interpol_func,
381 interpol_arg->names(),
382 values);
383 ReturnComputation(call);
384 }
385
386
313 // <Expression> :: Comparison { kind: Token::Kind 387 // <Expression> :: Comparison { kind: Token::Kind
314 // left: <Expression> 388 // left: <Expression>
315 // right: <Expression> } 389 // right: <Expression> }
316 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { 390 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) {
317 if (Token::IsInstanceofOperator(node->kind())) { 391 if (Token::IsInstanceofOperator(node->kind())) {
318 ArgumentGraphVisitor for_left_value(owner(), temp_index()); 392 ArgumentGraphVisitor for_left_value(owner(), temp_index());
319 node->left()->Visit(&for_left_value); 393 node->left()->Visit(&for_left_value);
320 Append(for_left_value); 394 Append(for_left_value);
321 InstanceOfComp* instance_of = new InstanceOfComp( 395 InstanceOfComp* instance_of = new InstanceOfComp(
322 node->id(), 396 node->id(),
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 char* chars = reinterpret_cast<char*>( 2187 char* chars = reinterpret_cast<char*>(
2114 Isolate::Current()->current_zone()->Allocate(len)); 2188 Isolate::Current()->current_zone()->Allocate(len));
2115 OS::SNPrint(chars, len, kFormat, function_name, reason); 2189 OS::SNPrint(chars, len, kFormat, function_name, reason);
2116 const Error& error = Error::Handle( 2190 const Error& error = Error::Handle(
2117 LanguageError::New(String::Handle(String::New(chars)))); 2191 LanguageError::New(String::Handle(String::New(chars))));
2118 Isolate::Current()->long_jump_base()->Jump(1, error); 2192 Isolate::Current()->long_jump_base()->Jump(1, error);
2119 } 2193 }
2120 2194
2121 2195
2122 } // namespace dart 2196 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698