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

Side by Side Diff: pkg/analyzer/lib/src/generated/scanner.dart

Issue 103233003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.scanner; 4 library engine.scanner;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'source.dart'; 9 import 'source.dart';
10 import 'error.dart'; 10 import 'error.dart';
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 519 }
520 return _sequence.charAt(_charOffset + 1); 520 return _sequence.charAt(_charOffset + 1);
521 } 521 }
522 522
523 void set offset(int offset) { 523 void set offset(int offset) {
524 _charOffset = offset; 524 _charOffset = offset;
525 } 525 }
526 } 526 }
527 527
528 /** 528 /**
529 * Synthetic `StringToken` represent a token whose value is independent of it's type.
530 *
531 * @coverage dart.engine.parser
532 */
533 class SyntheticStringToken extends StringToken {
534 /**
535 * Initialize a newly created token to represent a token of the given type wit h the given value.
536 *
537 * @param type the type of the token
538 * @param value the lexeme represented by this token
539 * @param offset the offset from the beginning of the file to the first charac ter in the token
540 */
541 SyntheticStringToken(TokenType type, String value, int offset) : super(type, v alue, offset);
542
543 bool get isSynthetic => true;
544 }
545
546 /**
529 * Instances of the class `IncrementalScanner` implement a scanner that scans a subset of a 547 * Instances of the class `IncrementalScanner` implement a scanner that scans a subset of a
530 * string and inserts the resulting tokens into the middle of an existing token stream. 548 * string and inserts the resulting tokens into the middle of an existing token stream.
531 * 549 *
532 * @coverage dart.engine.parser 550 * @coverage dart.engine.parser
533 */ 551 */
534 class IncrementalScanner extends Scanner { 552 class IncrementalScanner extends Scanner {
535 /** 553 /**
536 * The reader used to access the characters in the source. 554 * The reader used to access the characters in the source.
537 */ 555 */
538 CharacterReader _reader; 556 CharacterReader _reader;
539 557
540 /** 558 /**
541 * A map from tokens that were copied to the copies of the tokens. 559 * A map from tokens that were copied to the copies of the tokens.
542 */ 560 */
543 final TokenMap tokenMap = new TokenMap(); 561 final TokenMap tokenMap = new TokenMap();
544 562
545 /** 563 /**
546 * The first token in the range of tokens that are different from the tokens i n the original token 564 * The token in the new token stream immediately to the left of the range of t okens that were
547 * stream. 565 * inserted, or the token immediately to the left of the modified region if th ere were no new
566 * tokens.
548 */ 567 */
549 Token _firstToken; 568 Token leftToken;
550 569
551 /** 570 /**
552 * The last token in the range of tokens that are different from the tokens in the original token 571 * The token in the new token stream immediately to the right of the range of tokens that were
553 * stream. 572 * inserted, or the token immediately to the right of the modified region if t here were no new
573 * tokens.
554 */ 574 */
555 Token lastToken; 575 Token rightToken;
576
577 /**
578 * A flag indicating whether there were any tokens changed as a result of the modification.
579 */
580 bool _hasNonWhitespaceChange2 = false;
556 581
557 /** 582 /**
558 * Initialize a newly created scanner. 583 * Initialize a newly created scanner.
559 * 584 *
560 * @param source the source being scanned 585 * @param source the source being scanned
561 * @param reader the character reader used to read the characters in the sourc e 586 * @param reader the character reader used to read the characters in the sourc e
562 * @param errorListener the error listener that will be informed of any errors that are found 587 * @param errorListener the error listener that will be informed of any errors that are found
563 */ 588 */
564 IncrementalScanner(Source source, CharacterReader reader, AnalysisErrorListene r errorListener) : super(source, reader, errorListener) { 589 IncrementalScanner(Source source, CharacterReader reader, AnalysisErrorListene r errorListener) : super(source, reader, errorListener) {
565 this._reader = reader; 590 this._reader = reader;
566 } 591 }
567 592
568 /** 593 /**
569 * Return the first token in the range of tokens that are different from the t okens in the 594 * Return `true` if there were any tokens either added or removed (or both) as a result of
570 * original token stream or `null` if the new tokens are the same as the origi nal tokens 595 * the modification.
571 * except for offset.
572 * 596 *
573 * @return the first token in the range of new tokens 597 * @return `true` if there were any tokens changed as a result of the modifica tion
574 */ 598 */
575 Token get firstToken => _firstToken; 599 bool hasNonWhitespaceChange() => _hasNonWhitespaceChange2;
576 600
577 /** 601 /**
578 * Given the stream of tokens scanned from the original source, the modified s ource (the result of 602 * Given the stream of tokens scanned from the original source, the modified s ource (the result of
579 * replacing one contiguous range of characters with another string of charact ers), and a 603 * replacing one contiguous range of characters with another string of charact ers), and a
580 * specification of the modification that was made, return a stream of tokens scanned from the 604 * specification of the modification that was made, return a stream of tokens scanned from the
581 * modified source. The original stream of tokens will not be modified. 605 * modified source. The original stream of tokens will not be modified.
582 * 606 *
583 * @param originalStream the stream of tokens scanned from the original source 607 * @param originalStream the stream of tokens scanned from the original source
584 * @param index the index of the first character in both the original and modi fied source that was 608 * @param index the index of the first character in both the original and modi fied source that was
585 * affected by the modification 609 * affected by the modification
586 * @param removedLength the number of characters removed from the original sou rce 610 * @param removedLength the number of characters removed from the original sou rce
587 * @param insertedLength the number of characters added to the modified source 611 * @param insertedLength the number of characters added to the modified source
588 */ 612 */
589 Token rescan(Token originalStream, int index, int removedLength, int insertedL ength) { 613 Token rescan(Token originalStream, int index, int removedLength, int insertedL ength) {
590 while (originalStream.type != TokenType.EOF && originalStream.end < index) { 614 while (originalStream.type != TokenType.EOF && originalStream.end < index) {
591 originalStream = copyAndAdvance(originalStream, 0); 615 originalStream = copyAndAdvance(originalStream, 0);
592 } 616 }
593 Token lastCopied = tail; 617 Token oldFirst = originalStream;
594 int modifiedEnd = index + insertedLength - 1; 618 Token oldLeftToken = originalStream.previous;
595 if (originalStream.offset < index) { 619 leftToken = tail;
596 modifiedEnd += originalStream.end - index - removedLength; 620 int removedEnd = index + (removedLength == 0 ? 0 : removedLength - 1);
621 while (originalStream.type != TokenType.EOF && originalStream.offset <= remo vedEnd) {
622 originalStream = originalStream.next;
597 } 623 }
598 _reader.offset = Math.min(originalStream.offset, index) - 1; 624 Token oldLast;
625 Token oldRightToken;
626 if (originalStream.type != TokenType.EOF && removedEnd + 1 == originalStream .offset) {
627 oldLast = originalStream;
628 originalStream = originalStream.next;
629 oldRightToken = originalStream;
630 } else {
631 oldLast = originalStream.previous;
632 oldRightToken = originalStream;
633 }
634 int delta = insertedLength - removedLength;
635 int scanStart = Math.min(oldFirst.offset, index);
636 int oldEnd = oldLast.end + delta - 1;
637 int newEnd = index + insertedLength - 1;
638 int scanEnd = Math.max(newEnd, oldEnd);
639 _reader.offset = scanStart - 1;
599 int next = _reader.advance(); 640 int next = _reader.advance();
600 while (next != -1 && _reader.offset <= modifiedEnd) { 641 while (next != -1 && _reader.offset <= scanEnd) {
601 next = bigSwitch(next); 642 next = bigSwitch(next);
602 } 643 }
603 _firstToken = lastCopied.next; 644 if (identical(originalStream.type, TokenType.EOF)) {
604 lastToken = tail; 645 copyAndAdvance(originalStream, delta);
605 if (_firstToken == null || identical(_firstToken.type, TokenType.EOF)) { 646 rightToken = tail;
606 _firstToken = null; 647 rightToken.setNextWithoutSettingPrevious(rightToken);
607 lastToken = null; 648 } else {
608 } else if (originalStream.end == index && _firstToken.end == index) { 649 originalStream = copyAndAdvance(originalStream, delta);
609 tokenMap.put(originalStream, _firstToken); 650 rightToken = tail;
610 if (identical(lastToken, _firstToken)) { 651 while (originalStream.type != TokenType.EOF) {
611 lastToken = lastToken.next; 652 originalStream = copyAndAdvance(originalStream, delta);
612 } 653 }
613 _firstToken = _firstToken.next; 654 Token eof = copyAndAdvance(originalStream, delta);
655 eof.setNextWithoutSettingPrevious(eof);
614 } 656 }
615 int removedEnd = index + removedLength - 1 + Math.max(0, tail.end - index - insertedLength); 657 Token newFirst = leftToken.next;
616 while (originalStream.offset <= removedEnd) { 658 while (newFirst != rightToken && oldFirst != oldRightToken && newFirst.type != TokenType.EOF && equals3(oldFirst, newFirst)) {
617 originalStream = originalStream.next; 659 tokenMap.put(oldFirst, newFirst);
660 oldLeftToken = oldFirst;
661 oldFirst = oldFirst.next;
662 leftToken = newFirst;
663 newFirst = newFirst.next;
618 } 664 }
619 int delta = insertedLength - removedLength; 665 Token newLast = rightToken.previous;
620 while (originalStream.type != TokenType.EOF) { 666 while (newLast != leftToken && oldLast != oldLeftToken && newLast.type != To kenType.EOF && equals3(oldLast, newLast)) {
621 originalStream = copyAndAdvance(originalStream, delta); 667 tokenMap.put(oldLast, newLast);
668 oldRightToken = oldLast;
669 oldLast = oldLast.previous;
670 rightToken = newLast;
671 newLast = newLast.previous;
622 } 672 }
623 Token eof = copyAndAdvance(originalStream, delta); 673 _hasNonWhitespaceChange2 = leftToken.next != rightToken || oldLeftToken.next != oldRightToken;
624 eof.setNextWithoutSettingPrevious(eof); 674 return firstToken;
625 return super.firstToken;
626 } 675 }
627 676
628 Token copyAndAdvance(Token originalToken, int delta) { 677 Token copyAndAdvance(Token originalToken, int delta) {
629 Token copiedToken = originalToken.copy(); 678 Token copiedToken = originalToken.copy();
630 tokenMap.put(originalToken, copiedToken); 679 tokenMap.put(originalToken, copiedToken);
631 copiedToken.applyDelta(delta); 680 copiedToken.applyDelta(delta);
632 appendToken(copiedToken); 681 appendToken(copiedToken);
633 Token originalComment = originalToken.precedingComments; 682 Token originalComment = originalToken.precedingComments;
634 Token copiedComment = originalToken.precedingComments; 683 Token copiedComment = originalToken.precedingComments;
635 while (originalComment != null) { 684 while (originalComment != null) {
636 tokenMap.put(originalComment, copiedComment); 685 tokenMap.put(originalComment, copiedComment);
637 originalComment = originalComment.next; 686 originalComment = originalComment.next;
638 copiedComment = copiedComment.next; 687 copiedComment = copiedComment.next;
639 } 688 }
640 return originalToken.next; 689 return originalToken.next;
641 } 690 }
691
692 /**
693 * Return `true` if the two tokens are equal to each other. For the purposes o f the
694 * incremental scanner, two tokens are equal if they have the same type and le xeme.
695 *
696 * @param oldToken the token from the old stream that is being compared
697 * @param newToken the token from the new stream that is being compared
698 * @return `true` if the two tokens are equal to each other
699 */
700 bool equals3(Token oldToken, Token newToken) => identical(oldToken.type, newTo ken.type) && oldToken.length == newToken.length && oldToken.lexeme == newToken.l exeme;
642 } 701 }
643 702
644 /** 703 /**
645 * The class `Scanner` implements a scanner for Dart code. 704 * The class `Scanner` implements a scanner for Dart code.
646 * 705 *
647 * The lexical structure of Dart is ambiguous without knowledge of the context i n which a token is 706 * The lexical structure of Dart is ambiguous without knowledge of the context i n which a token is
648 * being scanned. For example, without context we cannot determine whether sourc e of the form "<<" 707 * being scanned. For example, without context we cannot determine whether sourc e of the form "<<"
649 * should be scanned as a single left-shift operator or as two left angle bracke ts. This scanner 708 * should be scanned as a single left-shift operator or as two left angle bracke ts. This scanner
650 * does not have any context, so it always resolves such conflicts by scanning t he longest possible 709 * does not have any context, so it always resolves such conflicts by scanning t he longest possible
651 * token. 710 * token.
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 1875
1817 /** 1876 /**
1818 * Return `true` if this token represents an operator. 1877 * Return `true` if this token represents an operator.
1819 * 1878 *
1820 * @return `true` if this token represents an operator 1879 * @return `true` if this token represents an operator
1821 */ 1880 */
1822 bool get isOperator => type.isOperator; 1881 bool get isOperator => type.isOperator;
1823 1882
1824 /** 1883 /**
1825 * Return `true` if this token is a synthetic token. A synthetic token is a to ken that was 1884 * Return `true` if this token is a synthetic token. A synthetic token is a to ken that was
1826 * introduced by the parser in order to recover from an error in the code. Syn thetic tokens always 1885 * introduced by the parser in order to recover from an error in the code.
1827 * have a length of zero (`0`).
1828 * 1886 *
1829 * @return `true` if this token is a synthetic token 1887 * @return `true` if this token is a synthetic token
1830 */ 1888 */
1831 bool get isSynthetic => length == 0; 1889 bool get isSynthetic => length == 0;
1832 1890
1833 /** 1891 /**
1834 * Return `true` if this token represents an operator that can be defined by u sers. 1892 * Return `true` if this token represents an operator that can be defined by u sers.
1835 * 1893 *
1836 * @return `true` if this token represents an operator that can be defined by users 1894 * @return `true` if this token represents an operator that can be defined by users
1837 */ 1895 */
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 static final TokenClass ADDITIVE_OPERATOR = new TokenClass.con2('ADDITIVE_OPER ATOR', 1, 12); 2116 static final TokenClass ADDITIVE_OPERATOR = new TokenClass.con2('ADDITIVE_OPER ATOR', 1, 12);
2059 2117
2060 /** 2118 /**
2061 * A value used to indicate that the token type is an assignment operator. 2119 * A value used to indicate that the token type is an assignment operator.
2062 */ 2120 */
2063 static final TokenClass ASSIGNMENT_OPERATOR = new TokenClass.con2('ASSIGNMENT_ OPERATOR', 2, 1); 2121 static final TokenClass ASSIGNMENT_OPERATOR = new TokenClass.con2('ASSIGNMENT_ OPERATOR', 2, 1);
2064 2122
2065 /** 2123 /**
2066 * A value used to indicate that the token type is a bitwise-and operator. 2124 * A value used to indicate that the token type is a bitwise-and operator.
2067 */ 2125 */
2068 static final TokenClass BITWISE_AND_OPERATOR = new TokenClass.con2('BITWISE_AN D_OPERATOR', 3, 8); 2126 static final TokenClass BITWISE_AND_OPERATOR = new TokenClass.con2('BITWISE_AN D_OPERATOR', 3, 10);
2069 2127
2070 /** 2128 /**
2071 * A value used to indicate that the token type is a bitwise-or operator. 2129 * A value used to indicate that the token type is a bitwise-or operator.
2072 */ 2130 */
2073 static final TokenClass BITWISE_OR_OPERATOR = new TokenClass.con2('BITWISE_OR_ OPERATOR', 4, 6); 2131 static final TokenClass BITWISE_OR_OPERATOR = new TokenClass.con2('BITWISE_OR_ OPERATOR', 4, 8);
2074 2132
2075 /** 2133 /**
2076 * A value used to indicate that the token type is a bitwise-xor operator. 2134 * A value used to indicate that the token type is a bitwise-xor operator.
2077 */ 2135 */
2078 static final TokenClass BITWISE_XOR_OPERATOR = new TokenClass.con2('BITWISE_XO R_OPERATOR', 5, 7); 2136 static final TokenClass BITWISE_XOR_OPERATOR = new TokenClass.con2('BITWISE_XO R_OPERATOR', 5, 9);
2079 2137
2080 /** 2138 /**
2081 * A value used to indicate that the token type is a cascade operator. 2139 * A value used to indicate that the token type is a cascade operator.
2082 */ 2140 */
2083 static final TokenClass CASCADE_OPERATOR = new TokenClass.con2('CASCADE_OPERAT OR', 6, 2); 2141 static final TokenClass CASCADE_OPERATOR = new TokenClass.con2('CASCADE_OPERAT OR', 6, 2);
2084 2142
2085 /** 2143 /**
2086 * A value used to indicate that the token type is a conditional operator. 2144 * A value used to indicate that the token type is a conditional operator.
2087 */ 2145 */
2088 static final TokenClass CONDITIONAL_OPERATOR = new TokenClass.con2('CONDITIONA L_OPERATOR', 7, 3); 2146 static final TokenClass CONDITIONAL_OPERATOR = new TokenClass.con2('CONDITIONA L_OPERATOR', 7, 3);
2089 2147
2090 /** 2148 /**
2091 * A value used to indicate that the token type is an equality operator. 2149 * A value used to indicate that the token type is an equality operator.
2092 */ 2150 */
2093 static final TokenClass EQUALITY_OPERATOR = new TokenClass.con2('EQUALITY_OPER ATOR', 8, 9); 2151 static final TokenClass EQUALITY_OPERATOR = new TokenClass.con2('EQUALITY_OPER ATOR', 8, 6);
2094 2152
2095 /** 2153 /**
2096 * A value used to indicate that the token type is a logical-and operator. 2154 * A value used to indicate that the token type is a logical-and operator.
2097 */ 2155 */
2098 static final TokenClass LOGICAL_AND_OPERATOR = new TokenClass.con2('LOGICAL_AN D_OPERATOR', 9, 5); 2156 static final TokenClass LOGICAL_AND_OPERATOR = new TokenClass.con2('LOGICAL_AN D_OPERATOR', 9, 5);
2099 2157
2100 /** 2158 /**
2101 * A value used to indicate that the token type is a logical-or operator. 2159 * A value used to indicate that the token type is a logical-or operator.
2102 */ 2160 */
2103 static final TokenClass LOGICAL_OR_OPERATOR = new TokenClass.con2('LOGICAL_OR_ OPERATOR', 10, 4); 2161 static final TokenClass LOGICAL_OR_OPERATOR = new TokenClass.con2('LOGICAL_OR_ OPERATOR', 10, 4);
2104 2162
2105 /** 2163 /**
2106 * A value used to indicate that the token type is a multiplicative operator. 2164 * A value used to indicate that the token type is a multiplicative operator.
2107 */ 2165 */
2108 static final TokenClass MULTIPLICATIVE_OPERATOR = new TokenClass.con2('MULTIPL ICATIVE_OPERATOR', 11, 13); 2166 static final TokenClass MULTIPLICATIVE_OPERATOR = new TokenClass.con2('MULTIPL ICATIVE_OPERATOR', 11, 13);
2109 2167
2110 /** 2168 /**
2111 * A value used to indicate that the token type is a relational operator. 2169 * A value used to indicate that the token type is a relational operator.
2112 */ 2170 */
2113 static final TokenClass RELATIONAL_OPERATOR = new TokenClass.con2('RELATIONAL_ OPERATOR', 12, 10); 2171 static final TokenClass RELATIONAL_OPERATOR = new TokenClass.con2('RELATIONAL_ OPERATOR', 12, 7);
2114 2172
2115 /** 2173 /**
2116 * A value used to indicate that the token type is a shift operator. 2174 * A value used to indicate that the token type is a shift operator.
2117 */ 2175 */
2118 static final TokenClass SHIFT_OPERATOR = new TokenClass.con2('SHIFT_OPERATOR', 13, 11); 2176 static final TokenClass SHIFT_OPERATOR = new TokenClass.con2('SHIFT_OPERATOR', 13, 11);
2119 2177
2120 /** 2178 /**
2121 * A value used to indicate that the token type is a unary operator. 2179 * A value used to indicate that the token type is a unary operator.
2122 */ 2180 */
2123 static final TokenClass UNARY_POSTFIX_OPERATOR = new TokenClass.con2('UNARY_PO STFIX_OPERATOR', 14, 15); 2181 static final TokenClass UNARY_POSTFIX_OPERATOR = new TokenClass.con2('UNARY_PO STFIX_OPERATOR', 14, 15);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 * @return `true` if this token type represents an operator that can be define d by users 2585 * @return `true` if this token type represents an operator that can be define d by users
2528 */ 2586 */
2529 bool get isUserDefinableOperator => identical(lexeme, "==") || identical(lexem e, "~") || identical(lexeme, "[]") || identical(lexeme, "[]=") || identical(lexe me, "*") || identical(lexeme, "/") || identical(lexeme, "%") || identical(lexeme , "~/") || identical(lexeme, "+") || identical(lexeme, "-") || identical(lexeme, "<<") || identical(lexeme, ">>") || identical(lexeme, ">=") || identical(lexeme , ">") || identical(lexeme, "<=") || identical(lexeme, "<") || identical(lexeme, "&") || identical(lexeme, "^") || identical(lexeme, "|"); 2587 bool get isUserDefinableOperator => identical(lexeme, "==") || identical(lexem e, "~") || identical(lexeme, "[]") || identical(lexeme, "[]=") || identical(lexe me, "*") || identical(lexeme, "/") || identical(lexeme, "%") || identical(lexeme , "~/") || identical(lexeme, "+") || identical(lexeme, "-") || identical(lexeme, "<<") || identical(lexeme, ">>") || identical(lexeme, ">=") || identical(lexeme , ">") || identical(lexeme, "<=") || identical(lexeme, "<") || identical(lexeme, "&") || identical(lexeme, "^") || identical(lexeme, "|");
2530 } 2588 }
2531 2589
2532 class TokenType_EOF extends TokenType { 2590 class TokenType_EOF extends TokenType {
2533 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super. con2(name, ordinal, arg0, arg1); 2591 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super. con2(name, ordinal, arg0, arg1);
2534 2592
2535 String toString() => "-eof-"; 2593 String toString() => "-eof-";
2536 } 2594 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/lib/src/generated/sdk_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698