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

Side by Side Diff: frog/leg/tree/nodes.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: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 interface Visitor<R> { 5 interface Visitor<R> {
6 R visitBlock(Block node); 6 R visitBlock(Block node);
7 R visitBreakStatement(BreakStatement node); 7 R visitBreakStatement(BreakStatement node);
8 R visitCatchBlock(CatchBlock node); 8 R visitCatchBlock(CatchBlock node);
9 R visitClassNode(ClassNode node); 9 R visitClassNode(ClassNode node);
10 R visitConditional(Conditional node); 10 R visitConditional(Conditional node);
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 case Keyword.TRUE: return true; 605 case Keyword.TRUE: return true;
606 case Keyword.FALSE: return false; 606 case Keyword.FALSE: return false;
607 default: 607 default:
608 (this.handler)(token, "not a bool ${token.value}"); 608 (this.handler)(token, "not a bool ${token.value}");
609 } 609 }
610 } 610 }
611 611
612 accept(Visitor visitor) => visitor.visitLiteralBool(this); 612 accept(Visitor visitor) => visitor.visitLiteralBool(this);
613 } 613 }
614 614
615
616 class StringQuoting {
617 static final StringQuoting SINGLELINE_DQ =
618 const StringQuoting($DQ, false, false);
ahe 2012/01/25 08:39:44 Is is possible to use named arguments here?
karlklose 2012/01/25 08:47:26 It would be nice to have named arguments here.
Lasse Reichstein Nielsen 2012/01/26 10:14:20 Done.
619 static final StringQuoting RAW_SINGLELINE_DQ =
620 const StringQuoting($DQ, true, false);
621 static final StringQuoting MULTILINE_DQ =
622 const StringQuoting($DQ, false, true);
623 static final StringQuoting RAW_MULTILINE_DQ =
624 const StringQuoting($DQ, true, true);
625 static final StringQuoting SINGLELINE_SQ =
626 const StringQuoting($SQ, false, false);
627 static final StringQuoting RAW_SINGLELINE_SQ =
628 const StringQuoting($SQ, true, false);
629 static final StringQuoting MULTILINE_SQ =
630 const StringQuoting($SQ, false, true);
631 static final StringQuoting RAW_MULTILINE_SQ =
632 const StringQuoting($SQ, true, true);
633 static final List<StringQuoting> mapping = const <StringQuoting>[
634 SINGLELINE_DQ,
635 RAW_SINGLELINE_DQ,
636 MULTILINE_DQ,
637 RAW_MULTILINE_DQ,
638 SINGLELINE_SQ,
639 RAW_SINGLELINE_SQ,
640 MULTILINE_DQ,
641 RAW_MULTILINE_SQ
642 ];
643 final bool raw;
644 final bool multiline;
645 final int quote;
646 const StringQuoting(this.quote, this.raw, this.multiline);
647 String get quoteChar() => quote === $DQ ? '"' : "'";
648
649 int get leftQuoteLength() => (raw ? 1 : 0) + (multiline ? 3 : 1);
650 int get rightQuoteLength() => multiline ? 3 : 1;
651 static StringQuoting get(int quote, bool raw, bool multiline) =>
652 mapping[(raw ? 1 : 0) + (multiline ? 2 : 0) + (quote === $SQ ? 4 : 0)];
653 }
654
655 /**
656 * A wrapper around a SourceString that stores extra information about
657 * the (potentially implicit) quoting style of the original string.
658 * For most strings, the quotes are included in the [source], but
659 * parts of strings from a string interpolation might be missing one or
660 * both quotes.
661 */
662 class QuotedString {
663 // A source-backed string literal without the quotes.
664 final SourceString source;
665 // The quoting style of the original string literal.
666 // Whether it's raw or multi-line impacts the interpretation of
667 // the string literal content. Whether it's single- or double-quoted
668 // is only used as a hint later.
669 final StringQuoting quoting;
670 /** Actual length of the corresponding, parsed, Dart string */
671 final int length;
672
673 const QuotedString(this.source, this.quoting, this.length);
674 /**
675 * Construct a [QuotedString] containing exactly the given string.
676 * The choice of quoting ensures that all characters of the original
677 * string are valid and has their exact meaning.
678 */
679 QuotedString.literal(String string)
680 : source = new SourceString(string),
681 quoting = StringQuoting.RAW_MULTILINE_DQ,
682 length = string.length;
683
684 bool isEmpty() => source.isEmpty();
685 Iterator<int> iterator() => source.iterator();
686
687 bool definitlyEquals(QuotedString other) {
688 return source === other.source && quoting === other.quoting;
689 }
690 }
691
692
615 class LiteralString extends Literal<SourceString> { 693 class LiteralString extends Literal<SourceString> {
694 /** Set on validated string literals. */
695 QuotedString quotedString = null;
ahe 2012/01/25 08:39:44 I think this should be final.
Lasse Reichstein Nielsen 2012/01/26 10:14:20 It is now that we find the value during parsing.
696
616 LiteralString(Token token) : super(token, null); 697 LiteralString(Token token) : super(token, null);
617 698
618 LiteralString asLiteralString() => this; 699 LiteralString asLiteralString() => this;
619 700
701 bool isValid() => quotedString !== null;
ahe 2012/01/25 08:39:44 This method will answer false for valid strings th
Lasse Reichstein Nielsen 2012/01/26 10:14:20 Yes. Renaming to isValidated().
702
620 SourceString get value() => token.value; 703 SourceString get value() => token.value;
621 704
622 accept(Visitor visitor) => visitor.visitLiteralString(this); 705 accept(Visitor visitor) => visitor.visitLiteralString(this);
623 } 706 }
624 707
625 class LiteralNull extends Literal<SourceString> { 708 class LiteralNull extends Literal<SourceString> {
626 LiteralNull(Token token) : super(token, null); 709 LiteralNull(Token token) : super(token, null);
627 710
628 LiteralNull asLiteralNull() => this; 711 LiteralNull asLiteralNull() => this;
629 712
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 1338
1256 visitChildren(Visitor visitor) { 1339 visitChildren(Visitor visitor) {
1257 formals.accept(visitor); 1340 formals.accept(visitor);
1258 block.accept(visitor); 1341 block.accept(visitor);
1259 } 1342 }
1260 1343
1261 Token getBeginToken() => catchKeyword; 1344 Token getBeginToken() => catchKeyword;
1262 1345
1263 Token getEndToken() => block.getEndToken(); 1346 Token getEndToken() => block.getEndToken();
1264 } 1347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698