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

Side by Side Diff: frog/leg/ssa/codegen.dart

Issue 9271037: Inserted string validation as separate task in compiler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed offline comments. 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 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 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 String generate(WorkItem work, HGraph graph) { 9 String generate(WorkItem work, HGraph graph) {
10 return measure(() { 10 return measure(() {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 buffer.add('new $jsClassReference('); 482 buffer.add('new $jsClassReference(');
483 // We can't use 'visitArguments', since our arguments start at input[0]. 483 // We can't use 'visitArguments', since our arguments start at input[0].
484 List<HInstruction> inputs = node.inputs; 484 List<HInstruction> inputs = node.inputs;
485 for (int i = 0; i < inputs.length; i++) { 485 for (int i = 0; i < inputs.length; i++) {
486 if (i != 0) buffer.add(', '); 486 if (i != 0) buffer.add(', ');
487 use(inputs[i]); 487 use(inputs[i]);
488 } 488 }
489 buffer.add(')'); 489 buffer.add(')');
490 } 490 }
491 491
492 /**
493 * Write the contents of the quoted string to a [StringBuffer] in
494 * a form that is valid as JavaScript string literal content.
495 * The string is assumed quoted by [quote] characters.
496 */
497 static void writeEscapedString(QuotedString string,
498 StringBuffer buffer,
499 int quote,
500 void cancel(String reason)) {
501 bool raw = string.quoting.raw;
502 Iterator<int> iter = string.iterator();
ahe 2012/01/26 19:24:28 Do you think performance would suffer if this was
Lasse Reichstein Nielsen 2012/01/27 11:39:04 Absoleffinglutely. But I'll rename it anyway, just
503 while (iter.hasNext()) {
504 int code = iter.next();
505 if (code === quote) {
506 // We need to add a backslash before quotes, both in normal
507 // and in raw strings.
508 buffer.add(@'\');
509 buffer.add(code === $SQ ? "'" : '"');
510 } else if (code === $LF) {
511 // Newlines in strings only occour in multiline strings.
ahe 2012/01/26 19:24:28 occour -> occur
Lasse Reichstein Nielsen 2012/01/27 11:39:04 Done.
512 // They need to be written using escapes in JS..
ahe 2012/01/26 19:24:28 Extra .
Lasse Reichstein Nielsen 2012/01/27 11:39:04 Done.
513 assert(string.quoting.multiline);
514 buffer.add(@'\n');
515 } else if (code === $CR) {
516 assert(string.quoting.multiline);
517 buffer.add(@'\r');
518 } else if (code === $LS) {
519 // This Unicode line terminator and $PS are invalid in JS string
520 // literals.
521 buffer.add(@'\u2028');
522 } else if (code === $PS) {
523 buffer.add(@'\u2029');
524 } else if (code !== $BACKSLASH) {
525 buffer.add(new String.fromCharCodes([code]));
526 } else if (raw) {
527 buffer.add(@'\\');
528 } else {
ahe 2012/01/26 19:24:28 For documentation, how about adding: assert(code
Lasse Reichstein Nielsen 2012/01/27 11:39:04 Done.
529 code = iter.next();
530 switch (code) {
531 case $u:
532 buffer.add(@'\u');
533 code = iter.next();
534 if (code == $OPEN_CURLY_BRACKET) {
535 int value = 0;
536 code = iter.next();
537 do {
538 value = value * 16 + hexDigitValue(code);
539 code = iter.next();
540 } while (code !== $CLOSE_CURLY_BRACKET);
541 if (code > 0xffff) {
542 cancel("Unhandled non-BMP character: " +
543 "U+${code.toRadixString(16)}");
544 }
545 for (int i = 12; i >= 0; i -= 4) {
546 buffer.add(((value >> i) & 0xf).toRadixString(16));
547 }
548 } else {
549 buffer.add(new String.fromCharCodes([code]));
550 // Remaining three hex digits will be copied verbatim.
551 }
552 break;
553 case $x:
554 buffer.add(@'\x');
555 // The two hex digits will be copied verbatim.
556 break;
557 // Character escapes that identical in meaning in JS.
karlklose 2012/01/27 09:11:59 that *are* identical
Lasse Reichstein Nielsen 2012/01/27 11:39:04 Good catch.
ahe 2012/01/27 12:12:37 You forgot to change it :-)
558 case $b: buffer.add(@'\b'); break;
559 case $f: buffer.add(@'\f'); break;
560 case $n: buffer.add(@'\n'); break;
561 case $r: buffer.add(@'\r'); break;
562 case $t: buffer.add(@'\t'); break;
563 case $v: buffer.add(@'\v'); break;
564 // Identity escapes that must be escaped in JS strings.
565 case $BACKSLASH: buffer.add(@'\\'); break;
566 case $LF: buffer.add(@'\n'); break;
567 case $CR: buffer.add(@'\r'); break;
568 case $LS: buffer.add(@'\u2028'); break;
569 case $PS: buffer.add(@'\u2029'); break;
570 // Quotes may or may not need the escape.
571 case $SQ:
572 case $DQ:
573 // Only escape quotes if they match the generated string quotes.
574 if (code == quote) buffer.add(@'\');
575 buffer.add(code === $SQ ? "'" : '"');
576 break;
577 default:
578 // All other escaped characters are identity escapes,
579 // and don't need a backslash in JS.
580 buffer.add(new String.fromCharCodes([code]));
581 break;
582 }
583 }
584 }
585 }
586
587
492 visitLiteral(HLiteral node) { 588 visitLiteral(HLiteral node) {
493 if (node.isLiteralNull()) { 589 if (node.isLiteralNull()) {
494 buffer.add("(void 0)"); 590 buffer.add("(void 0)");
495 } else if (node.value is num && node.value < 0) { 591 } else if (node.value is num && node.value < 0) {
496 buffer.add('(${node.value})'); 592 buffer.add('(${node.value})');
497 } else if (node.isLiteralString()) { 593 } else if (node.isLiteralString()) {
498 QuotedString string = node.value; 594 QuotedString string = node.value;
499 String quote = string.quoteChar; 595 StringQuoting quoting = string.quoting;
596 String quote = quoting.quoteChar;
500 buffer.add(quote); 597 buffer.add(quote);
501 string.writeEscaped(buffer, string.quoteCharCode, 598 writeEscapedString(string, buffer, quoting.quote,
502 (String reason) { 599 (String reason) {
503 compiler.cancel(reason, instruction: node); 600 compiler.cancel(reason, instruction:node);
504 }); 601 });
505 buffer.add(quote); 602 buffer.add(quote);
506 } else { 603 } else {
507 buffer.add(node.value); 604 buffer.add(node.value);
508 } 605 }
509 } 606 }
510 607
511 visitLoopBranch(HLoopBranch node) { 608 visitLoopBranch(HLoopBranch node) {
512 HBasicBlock branchBlock = currentBlock; 609 HBasicBlock branchBlock = currentBlock;
513 handleLoopCondition(node); 610 handleLoopCondition(node);
514 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; 611 List<HBasicBlock> dominated = currentBlock.dominatedBlocks;
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 startBailoutSwitch(); 1127 startBailoutSwitch();
1031 } 1128 }
1032 } 1129 }
1033 1130
1034 void endElse(HIf node) { 1131 void endElse(HIf node) {
1035 if (node.elseBlock.hasBailouts()) { 1132 if (node.elseBlock.hasBailouts()) {
1036 endBailoutSwitch(); 1133 endBailoutSwitch();
1037 } 1134 }
1038 } 1135 }
1039 } 1136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698