| OLD | NEW |
| 1 #!/usr/bin/env node | 1 #!/usr/bin/env node |
| 2 // ********** Library dart:core ************** | 2 // ********** Library dart:core ************** |
| 3 // ********** Natives core.js ************** | 3 // ********** Natives core.js ************** |
| 4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 5 // for details. All rights reserved. Use of this source code is governed by a | 5 // for details. All rights reserved. Use of this source code is governed by a |
| 6 // BSD-style license that can be found in the LICENSE file. | 6 // BSD-style license that can be found in the LICENSE file. |
| 7 | 7 |
| 8 // TODO(jimhug): Completeness - see tests/corelib | 8 // TODO(jimhug): Completeness - see tests/corelib |
| 9 | 9 |
| 10 /** Implements extends for dart classes on javascript prototypes. */ | 10 /** Implements extends for dart classes on javascript prototypes. */ |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 405 } |
| 406 Math.min = function(a, b) { | 406 Math.min = function(a, b) { |
| 407 if (a == b) return a; | 407 if (a == b) return a; |
| 408 if (a < b) { | 408 if (a < b) { |
| 409 if (isNaN(b)) return b; | 409 if (isNaN(b)) return b; |
| 410 else return a; | 410 else return a; |
| 411 } | 411 } |
| 412 if (isNaN(a)) return a; | 412 if (isNaN(a)) return a; |
| 413 else return b; | 413 else return b; |
| 414 } | 414 } |
| 415 // ********** Code for Dispatcher ************** | |
| 416 function Dispatcher() {} | |
| 417 // ********** Code for Strings ************** | 415 // ********** Code for Strings ************** |
| 418 function Strings() {} | 416 function Strings() {} |
| 419 Strings.String$fromCharCodes$factory = function(charCodes) { | 417 Strings.String$fromCharCodes$factory = function(charCodes) { |
| 420 return StringBase.createFromCharCodes(charCodes); | 418 return StringBase.createFromCharCodes(charCodes); |
| 421 } | 419 } |
| 422 Strings.join = function(strings, separator) { | 420 Strings.join = function(strings, separator) { |
| 423 return StringBase.join(strings, separator); | 421 return StringBase.join(strings, separator); |
| 424 } | 422 } |
| 425 // ********** Code for top level ************** | 423 // ********** Code for top level ************** |
| 426 function print(obj) { | 424 function print(obj) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 ListFactory$DoubleLinkedQueueEntry$KeyValuePair$K$V = ListFactory; | 476 ListFactory$DoubleLinkedQueueEntry$KeyValuePair$K$V = ListFactory; |
| 479 ListFactory$DoubleLinkedQueueEntry$KeyValuePair$String$Keyword = ListFactory; | 477 ListFactory$DoubleLinkedQueueEntry$KeyValuePair$String$Keyword = ListFactory; |
| 480 ListFactory$E = ListFactory; | 478 ListFactory$E = ListFactory; |
| 481 ListFactory$Element = ListFactory; | 479 ListFactory$Element = ListFactory; |
| 482 ListFactory$HInstruction = ListFactory; | 480 ListFactory$HInstruction = ListFactory; |
| 483 ListFactory$K = ListFactory; | 481 ListFactory$K = ListFactory; |
| 484 ListFactory$KeywordState = ListFactory; | 482 ListFactory$KeywordState = ListFactory; |
| 485 ListFactory$SplayTreeNode$K$V = ListFactory; | 483 ListFactory$SplayTreeNode$K$V = ListFactory; |
| 486 ListFactory$String = ListFactory; | 484 ListFactory$String = ListFactory; |
| 487 ListFactory$T = ListFactory; | 485 ListFactory$T = ListFactory; |
| 486 ListFactory$Token = ListFactory; |
| 488 ListFactory$V = ListFactory; | 487 ListFactory$V = ListFactory; |
| 489 // ********** Code for ListIterator ************** | 488 // ********** Code for ListIterator ************** |
| 490 function ListIterator(array) { | 489 function ListIterator(array) { |
| 491 this._array = array; | 490 this._array = array; |
| 492 this._pos = 0; | 491 this._pos = 0; |
| 493 // Initializers done | 492 // Initializers done |
| 494 } | 493 } |
| 495 ListIterator.prototype.hasNext = function() { | 494 ListIterator.prototype.hasNext = function() { |
| 496 return this._array.length > this._pos; | 495 return this._array.length > this._pos; |
| 497 } | 496 } |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 this._numberOfEntries = 0; | 998 this._numberOfEntries = 0; |
| 1000 this._numberOfDeleted = 0; | 999 this._numberOfDeleted = 0; |
| 1001 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); | 1000 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 1002 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); | 1001 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1003 this._values = new ListFactory$DoubleLinkedQueueEntry$KeyValuePair$String$Keyw
ord(8/*HashMapImplementation._INITIAL_CAPACITY*/); | 1002 this._values = new ListFactory$DoubleLinkedQueueEntry$KeyValuePair$String$Keyw
ord(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1004 } | 1003 } |
| 1005 $inherits(HashMapImplementation$String$DoubleLinkedQueueEntry$KeyValuePair$Strin
g$Keyword, HashMapImplementation); | 1004 $inherits(HashMapImplementation$String$DoubleLinkedQueueEntry$KeyValuePair$Strin
g$Keyword, HashMapImplementation); |
| 1006 HashMapImplementation$String$DoubleLinkedQueueEntry$KeyValuePair$String$Keyword.
_computeLoadLimit = function(capacity) { | 1005 HashMapImplementation$String$DoubleLinkedQueueEntry$KeyValuePair$String$Keyword.
_computeLoadLimit = function(capacity) { |
| 1007 return $truncdiv((capacity * 3), 4); | 1006 return $truncdiv((capacity * 3), 4); |
| 1008 } | 1007 } |
| 1008 // ********** Code for HashMapImplementation$int$Token ************** |
| 1009 function HashMapImplementation$int$Token() { |
| 1010 // Initializers done |
| 1011 if (HashMapImplementation._deletedKey == null) { |
| 1012 HashMapImplementation._deletedKey = new Object(); |
| 1013 } |
| 1014 this._numberOfEntries = 0; |
| 1015 this._numberOfDeleted = 0; |
| 1016 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 1017 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1018 this._values = new ListFactory$Token(8/*HashMapImplementation._INITIAL_CAPACIT
Y*/); |
| 1019 } |
| 1020 $inherits(HashMapImplementation$int$Token, HashMapImplementation); |
| 1021 HashMapImplementation$int$Token._computeLoadLimit = function(capacity) { |
| 1022 return $truncdiv((capacity * 3), 4); |
| 1023 } |
| 1009 // ********** Code for HashSetImplementation ************** | 1024 // ********** Code for HashSetImplementation ************** |
| 1010 function HashSetImplementation() { | 1025 function HashSetImplementation() { |
| 1011 // Initializers done | 1026 // Initializers done |
| 1012 this._backingMap = new HashMapImplementation$E$E(); | 1027 this._backingMap = new HashMapImplementation$E$E(); |
| 1013 } | 1028 } |
| 1014 HashSetImplementation.HashSetImplementation$from$factory = function(other) { | 1029 HashSetImplementation.HashSetImplementation$from$factory = function(other) { |
| 1015 var set = new HashSetImplementation(); | 1030 var set = new HashSetImplementation(); |
| 1016 for (var $i = other.iterator(); $i.hasNext(); ) { | 1031 for (var $i = other.iterator(); $i.hasNext(); ) { |
| 1017 var e = $i.next(); | 1032 var e = $i.next(); |
| 1018 set.add(e); | 1033 set.add(e); |
| (...skipping 10620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11639 } | 11654 } |
| 11640 TokenKind.kindFromAssign = function(kind) { | 11655 TokenKind.kindFromAssign = function(kind) { |
| 11641 if (kind == 20/*TokenKind.ASSIGN*/) return 0; | 11656 if (kind == 20/*TokenKind.ASSIGN*/) return 0; |
| 11642 if (kind > 20/*TokenKind.ASSIGN*/ && kind <= 32/*TokenKind.ASSIGN_MOD*/) { | 11657 if (kind > 20/*TokenKind.ASSIGN*/ && kind <= 32/*TokenKind.ASSIGN_MOD*/) { |
| 11643 return kind + (15)/*(ADD - ASSIGN_ADD)*/; | 11658 return kind + (15)/*(ADD - ASSIGN_ADD)*/; |
| 11644 } | 11659 } |
| 11645 return -1; | 11660 return -1; |
| 11646 } | 11661 } |
| 11647 // ********** Code for lang_Parser ************** | 11662 // ********** Code for lang_Parser ************** |
| 11648 function lang_Parser(source, diet, startOffset) { | 11663 function lang_Parser(source, diet, startOffset) { |
| 11664 this._highestCachePosition = -1 |
| 11649 this.source = source; | 11665 this.source = source; |
| 11650 this.diet = diet; | 11666 this.diet = diet; |
| 11651 // Initializers done | 11667 // Initializers done |
| 11652 this.tokenizer = new Tokenizer(this.source, true, startOffset); | 11668 this.tokenizer = new Tokenizer(this.source, true, startOffset); |
| 11653 this._peekToken = this.tokenizer.next(); | 11669 this._peekToken = this.tokenizer.next(); |
| 11654 this._previousToken = null; | 11670 this._previousToken = null; |
| 11655 this._inInitializers = false; | 11671 this._inInitializers = false; |
| 11672 this._afterCloseParenCache = new HashMapImplementation$int$Token(); |
| 11656 } | 11673 } |
| 11657 lang_Parser.prototype.isPrematureEndOfFile = function() { | 11674 lang_Parser.prototype.isPrematureEndOfFile = function() { |
| 11658 if (this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { | 11675 if (this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { |
| 11659 this._lang_error('unexpected end of file', this._peekToken.get$span()); | 11676 this._lang_error('unexpected end of file', this._peekToken.get$span()); |
| 11660 return true; | 11677 return true; |
| 11661 } | 11678 } |
| 11662 else { | 11679 else { |
| 11663 return false; | 11680 return false; |
| 11664 } | 11681 } |
| 11665 } | 11682 } |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12419 this._eat(2/*TokenKind.LPAREN*/); | 12436 this._eat(2/*TokenKind.LPAREN*/); |
| 12420 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { | 12437 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 12421 do { | 12438 do { |
| 12422 args.add(this.argument()); | 12439 args.add(this.argument()); |
| 12423 } | 12440 } |
| 12424 while (this._maybeEat(11/*TokenKind.COMMA*/)) | 12441 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 12425 this._eat(3/*TokenKind.RPAREN*/); | 12442 this._eat(3/*TokenKind.RPAREN*/); |
| 12426 } | 12443 } |
| 12427 return args; | 12444 return args; |
| 12428 } | 12445 } |
| 12429 lang_Parser.prototype.get$arguments = function() { | |
| 12430 return lang_Parser.prototype.arguments.bind(this); | |
| 12431 } | |
| 12432 lang_Parser.prototype.finishPostfixExpression = function(expr) { | 12446 lang_Parser.prototype.finishPostfixExpression = function(expr) { |
| 12433 switch (this._peek()) { | 12447 switch (this._peek()) { |
| 12434 case 2/*TokenKind.LPAREN*/: | 12448 case 2/*TokenKind.LPAREN*/: |
| 12435 | 12449 |
| 12436 return this.finishPostfixExpression(new CallExpression(expr, this.argument
s(), this._makeSpan(expr.get$span().start))); | 12450 return this.finishCallOrLambdaExpression(expr); |
| 12437 | 12451 |
| 12438 case 4/*TokenKind.LBRACK*/: | 12452 case 4/*TokenKind.LBRACK*/: |
| 12439 | 12453 |
| 12440 this._eat(4/*TokenKind.LBRACK*/); | 12454 this._eat(4/*TokenKind.LBRACK*/); |
| 12441 var index = this.expression(); | 12455 var index = this.expression(); |
| 12442 this._eat(5/*TokenKind.RBRACK*/); | 12456 this._eat(5/*TokenKind.RBRACK*/); |
| 12443 return this.finishPostfixExpression(new IndexExpression(expr, index, this.
_makeSpan(expr.get$span().start))); | 12457 return this.finishPostfixExpression(new IndexExpression(expr, index, this.
_makeSpan(expr.get$span().start))); |
| 12444 | 12458 |
| 12445 case 14/*TokenKind.DOT*/: | 12459 case 14/*TokenKind.DOT*/: |
| 12446 | 12460 |
| 12447 this._eat(14/*TokenKind.DOT*/); | 12461 this._eat(14/*TokenKind.DOT*/); |
| 12448 var name = this.identifier(); | 12462 var name = this.identifier(); |
| 12449 var ret = new DotExpression(expr, name, this._makeSpan(expr.get$span().sta
rt)); | 12463 var ret = new DotExpression(expr, name, this._makeSpan(expr.get$span().sta
rt)); |
| 12450 return this.finishPostfixExpression(ret); | 12464 return this.finishPostfixExpression(ret); |
| 12451 | 12465 |
| 12452 case 16/*TokenKind.INCR*/: | 12466 case 16/*TokenKind.INCR*/: |
| 12453 case 17/*TokenKind.DECR*/: | 12467 case 17/*TokenKind.DECR*/: |
| 12454 | 12468 |
| 12455 var tok = this._lang_next(); | 12469 var tok = this._lang_next(); |
| 12456 return new PostfixExpression(expr, tok, this._makeSpan(expr.get$span().sta
rt)); | 12470 return new PostfixExpression(expr, tok, this._makeSpan(expr.get$span().sta
rt)); |
| 12457 | 12471 |
| 12458 case 9/*TokenKind.ARROW*/: | 12472 case 9/*TokenKind.ARROW*/: |
| 12459 case 6/*TokenKind.LBRACE*/: | 12473 case 6/*TokenKind.LBRACE*/: |
| 12460 | 12474 |
| 12461 if (this._inInitializers) return expr; | 12475 return expr; |
| 12462 var body = this.functionBody(true); | |
| 12463 return this._makeFunction(expr, body); | |
| 12464 | 12476 |
| 12465 default: | 12477 default: |
| 12466 | 12478 |
| 12467 if (this._peekIdentifier()) { | 12479 if (this._peekIdentifier()) { |
| 12468 return this.finishPostfixExpression(new DeclaredIdentifier(this._makeTyp
e(expr), this.identifier(), this._makeSpan(expr.get$span().start))); | 12480 return this.finishPostfixExpression(new DeclaredIdentifier(this._makeTyp
e(expr), this.identifier(), this._makeSpan(expr.get$span().start))); |
| 12469 } | 12481 } |
| 12470 else { | 12482 else { |
| 12471 return expr; | 12483 return expr; |
| 12472 } | 12484 } |
| 12473 | 12485 |
| 12474 } | 12486 } |
| 12475 } | 12487 } |
| 12488 lang_Parser.prototype.finishCallOrLambdaExpression = function(expr) { |
| 12489 if (!this._inInitializers && this._atClosureParameters()) { |
| 12490 var formals = this.formalParameterList(); |
| 12491 var body = this.functionBody(true); |
| 12492 return this._makeFunction(expr, formals, body); |
| 12493 } |
| 12494 else { |
| 12495 var args = this.arguments(); |
| 12496 return this.finishPostfixExpression(new CallExpression(expr, args, this._mak
eSpan(expr.get$span().start))); |
| 12497 } |
| 12498 } |
| 12476 lang_Parser.prototype._isBin = function(expr, kind) { | 12499 lang_Parser.prototype._isBin = function(expr, kind) { |
| 12477 return (expr instanceof BinaryExpression) && expr.op.kind == kind; | 12500 return (expr instanceof BinaryExpression) && expr.op.kind == kind; |
| 12478 } | 12501 } |
| 12479 lang_Parser.prototype._boolTypeRef = function(span) { | 12502 lang_Parser.prototype._boolTypeRef = function(span) { |
| 12480 return new TypeReference(span, world.boolType); | 12503 return new TypeReference(span, world.boolType); |
| 12481 } | 12504 } |
| 12482 lang_Parser.prototype._numTypeRef = function(span) { | 12505 lang_Parser.prototype._numTypeRef = function(span) { |
| 12483 return new TypeReference(span, world.numType); | 12506 return new TypeReference(span, world.numType); |
| 12484 } | 12507 } |
| 12485 lang_Parser.prototype._stringTypeRef = function(span) { | 12508 lang_Parser.prototype._stringTypeRef = function(span) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12640 this._errorExpected('string literal, but found interpolated string start'); | 12663 this._errorExpected('string literal, but found interpolated string start'); |
| 12641 } | 12664 } |
| 12642 else if ($eq(kind, 65/*TokenKind.INCOMPLETE_STRING*/)) { | 12665 else if ($eq(kind, 65/*TokenKind.INCOMPLETE_STRING*/)) { |
| 12643 this._lang_next(); | 12666 this._lang_next(); |
| 12644 this._errorExpected('string literal, but found incomplete string'); | 12667 this._errorExpected('string literal, but found incomplete string'); |
| 12645 } | 12668 } |
| 12646 return null; | 12669 return null; |
| 12647 } | 12670 } |
| 12648 lang_Parser.prototype._parenOrLambda = function() { | 12671 lang_Parser.prototype._parenOrLambda = function() { |
| 12649 var start = this._peekToken.start; | 12672 var start = this._peekToken.start; |
| 12650 var args = this.arguments(); | 12673 if (!this._inInitializers && this._atClosureParameters()) { |
| 12651 if (!this._inInitializers && (this._peekKind(9/*TokenKind.ARROW*/) || this._pe
ekKind(6/*TokenKind.LBRACE*/))) { | 12674 var formals = this.formalParameterList(); |
| 12652 var body = this.functionBody(true); | 12675 var body = this.functionBody(true); |
| 12653 var formals = this._makeFormals(args); | |
| 12654 var func = new FunctionDefinition(null, null, null, formals, null, body, thi
s._makeSpan(start)); | 12676 var func = new FunctionDefinition(null, null, null, formals, null, body, thi
s._makeSpan(start)); |
| 12655 return new LambdaExpression(func, func.get$span()); | 12677 return new LambdaExpression(func, func.get$span()); |
| 12656 } | 12678 } |
| 12657 else { | 12679 else { |
| 12680 var args = this.arguments(); |
| 12658 if (args.length == 1) { | 12681 if (args.length == 1) { |
| 12659 return new ParenExpression(args.$index(0).get$value(), this._makeSpan(star
t)); | 12682 return new ParenExpression(args.$index(0).get$value(), this._makeSpan(star
t)); |
| 12660 } | 12683 } |
| 12661 else { | 12684 else { |
| 12662 this._lang_error('unexpected comma expression'); | 12685 this._lang_error('unexpected comma expression'); |
| 12663 return args.$index(0).get$value(); | 12686 return args.$index(0).get$value(); |
| 12664 } | 12687 } |
| 12665 } | 12688 } |
| 12666 } | 12689 } |
| 12690 lang_Parser.prototype._atClosureParameters = function() { |
| 12691 var afterCloseParen = this._peekPastCloseParen(); |
| 12692 return afterCloseParen.kind == 9/*TokenKind.ARROW*/ || afterCloseParen.kind ==
6/*TokenKind.LBRACE*/; |
| 12693 } |
| 12694 lang_Parser.prototype._peekPastCloseParen = function() { |
| 12695 var pos = this._peekToken.start; |
| 12696 if (pos > this._highestCachePosition) return this._fillAfterCloseParenCache(); |
| 12697 return this._afterCloseParenCache.$index(pos); |
| 12698 } |
| 12699 lang_Parser.prototype._fillAfterCloseParenCache = function() { |
| 12700 var tokens = []; |
| 12701 var positions = []; |
| 12702 var firstOpenParen = this._peekToken; |
| 12703 while (true) { |
| 12704 var token = this._lang_next(); |
| 12705 tokens.add(token); |
| 12706 var kind = token.kind; |
| 12707 if (kind == 2/*TokenKind.LPAREN*/) { |
| 12708 positions.add(token.start); |
| 12709 } |
| 12710 else if (kind == 3/*TokenKind.RPAREN*/) { |
| 12711 var openPos = positions.removeLast(); |
| 12712 if (positions.length == 0) break; |
| 12713 this._afterCloseParenCache.$setindex(openPos, this._peekToken); |
| 12714 if (openPos > this._highestCachePosition) this._highestCachePosition = ope
nPos; |
| 12715 } |
| 12716 else if (kind == 1/*TokenKind.END_OF_FILE*/) { |
| 12717 this._lang_error('parenthesis never closed', firstOpenParen.get$span()); |
| 12718 this._afterCloseParenCache = new HashMapImplementation$int$Token(); |
| 12719 this._highestCachePosition = -1; |
| 12720 break; |
| 12721 } |
| 12722 } |
| 12723 var after = this._peekToken; |
| 12724 tokens.add(this._peekToken); |
| 12725 this.tokenizer = new DivertedTokenSource(tokens, this, this.tokenizer); |
| 12726 this._lang_next(); |
| 12727 return after; |
| 12728 } |
| 12667 lang_Parser.prototype._typeAsIdentifier = function(type) { | 12729 lang_Parser.prototype._typeAsIdentifier = function(type) { |
| 12668 return type.get$name(); | 12730 return type.get$name(); |
| 12669 } | 12731 } |
| 12670 lang_Parser.prototype._specialIdentifier = function(includeOperators) { | 12732 lang_Parser.prototype._specialIdentifier = function(includeOperators) { |
| 12671 var start = this._peekToken.start; | 12733 var start = this._peekToken.start; |
| 12672 var name; | 12734 var name; |
| 12673 switch (this._peek()) { | 12735 switch (this._peek()) { |
| 12674 case 15/*TokenKind.ELLIPSIS*/: | 12736 case 15/*TokenKind.ELLIPSIS*/: |
| 12675 | 12737 |
| 12676 this._eat(15/*TokenKind.ELLIPSIS*/); | 12738 this._eat(15/*TokenKind.ELLIPSIS*/); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13022 } | 13084 } |
| 13023 return formals; | 13085 return formals; |
| 13024 } | 13086 } |
| 13025 lang_Parser.prototype.identifier = function() { | 13087 lang_Parser.prototype.identifier = function() { |
| 13026 var tok = this._lang_next(); | 13088 var tok = this._lang_next(); |
| 13027 if (!TokenKind.isIdentifier(tok.kind)) { | 13089 if (!TokenKind.isIdentifier(tok.kind)) { |
| 13028 this._lang_error(('expected identifier, but found ' + tok + ''), tok.get$spa
n()); | 13090 this._lang_error(('expected identifier, but found ' + tok + ''), tok.get$spa
n()); |
| 13029 } | 13091 } |
| 13030 return new lang_Identifier(tok.get$text(), this._makeSpan(tok.start)); | 13092 return new lang_Identifier(tok.get$text(), this._makeSpan(tok.start)); |
| 13031 } | 13093 } |
| 13032 lang_Parser.prototype._makeFunction = function(expr, body) { | 13094 lang_Parser.prototype._makeFunction = function(expr, formals, body) { |
| 13033 var name, type; | 13095 var name, type; |
| 13034 if ((expr instanceof CallExpression)) { | 13096 if ((expr instanceof VarExpression)) { |
| 13035 if ((expr.target instanceof VarExpression)) { | 13097 name = expr.get$name(); |
| 13036 name = expr.target.get$name(); | 13098 type = null; |
| 13037 type = null; | 13099 } |
| 13038 } | 13100 else if ((expr instanceof DeclaredIdentifier)) { |
| 13039 else if ((expr.target instanceof DeclaredIdentifier)) { | 13101 name = expr.get$name(); |
| 13040 name = expr.target.get$name(); | 13102 type = expr.type; |
| 13041 type = expr.target.type; | |
| 13042 } | |
| 13043 else { | |
| 13044 this._lang_error('bad function'); | |
| 13045 } | |
| 13046 var formals = this._makeFormals(expr.get$arguments()); | |
| 13047 var span = new SourceSpan(expr.get$span().file, expr.get$span().start, body.
get$span().end); | |
| 13048 var func = new FunctionDefinition(null, type, name, formals, null, body, spa
n); | |
| 13049 return new LambdaExpression(func, func.get$span()); | |
| 13050 } | 13103 } |
| 13051 else { | 13104 else { |
| 13052 this._lang_error('expected function'); | 13105 this._lang_error('bad function'); |
| 13053 } | 13106 } |
| 13054 } | 13107 var span = new SourceSpan(expr.get$span().file, expr.get$span().start, body.ge
t$span().end); |
| 13055 lang_Parser.prototype._makeFormal = function(expr) { | 13108 var func = new FunctionDefinition(null, type, name, formals, null, body, span)
; |
| 13056 if ((expr instanceof VarExpression)) { | 13109 return new LambdaExpression(func, func.get$span()); |
| 13057 return new FormalNode(false, false, null, expr.get$name(), null, expr.get$sp
an()); | |
| 13058 } | |
| 13059 else if ((expr instanceof DeclaredIdentifier)) { | |
| 13060 return new FormalNode(false, false, expr.type, expr.get$name(), null, expr.g
et$span()); | |
| 13061 } | |
| 13062 else if (this._isBin(expr, 20/*TokenKind.ASSIGN*/) && ((expr.x instanceof Decl
aredIdentifier))) { | |
| 13063 var di = expr.x; | |
| 13064 return new FormalNode(false, false, di.type, di.name, expr.y, expr.get$span(
)); | |
| 13065 } | |
| 13066 else if (this._isBin(expr, 52/*TokenKind.LT*/)) { | |
| 13067 return null; | |
| 13068 } | |
| 13069 else if ((expr instanceof ListExpression)) { | |
| 13070 return this._makeFormalsFromList(expr); | |
| 13071 } | |
| 13072 else { | |
| 13073 this._lang_error('expected formal', expr.get$span()); | |
| 13074 } | |
| 13075 } | |
| 13076 lang_Parser.prototype._makeFormalsFromList = function(expr) { | |
| 13077 if (expr.get$isConst()) { | |
| 13078 this._lang_error('expected formal, but found "const"', expr.get$span()); | |
| 13079 } | |
| 13080 else if ($ne(expr.type, null)) { | |
| 13081 this._lang_error('expected formal, but found generic type arguments', expr.t
ype.get$span()); | |
| 13082 } | |
| 13083 return this._makeFormalsFromExpressions(expr.values, false); | |
| 13084 } | |
| 13085 lang_Parser.prototype._makeFormals = function(arguments) { | |
| 13086 var expressions = []; | |
| 13087 for (var i = 0; | |
| 13088 i < arguments.length; i++) { | |
| 13089 var arg = arguments.$index(i); | |
| 13090 if (arg.label != null) { | |
| 13091 this._lang_error('expected formal, but found ":"'); | |
| 13092 } | |
| 13093 expressions.add(arg.get$value()); | |
| 13094 } | |
| 13095 return this._makeFormalsFromExpressions(expressions, true); | |
| 13096 } | |
| 13097 lang_Parser.prototype._makeFormalsFromExpressions = function(expressions, allowO
ptional) { | |
| 13098 var formals = []; | |
| 13099 for (var i = 0; | |
| 13100 i < expressions.length; i++) { | |
| 13101 var formal = this._makeFormal(expressions.$index(i)); | |
| 13102 if (formal == null) { | |
| 13103 var baseType = this._makeType(expressions.$index(i).x); | |
| 13104 var typeParams = [this._makeType(expressions.$index(i).y)]; | |
| 13105 i++; | |
| 13106 while (i < expressions.length) { | |
| 13107 var expr = expressions.$index(i++); | |
| 13108 if (this._isBin(expr, 53/*TokenKind.GT*/)) { | |
| 13109 typeParams.add(this._makeType(expr.x)); | |
| 13110 var type = new GenericTypeReference(baseType, typeParams, 0, this._mak
eSpan(baseType.get$span().start)); | |
| 13111 var name = null; | |
| 13112 if ((expr.y instanceof VarExpression)) { | |
| 13113 var ve = expr.y; | |
| 13114 name = ve.name; | |
| 13115 } | |
| 13116 else { | |
| 13117 this._lang_error('expected formal', expr.get$span()); | |
| 13118 } | |
| 13119 formal = new FormalNode(false, false, type, name, null, this._makeSpan
(expressions.$index(0).get$span().start)); | |
| 13120 break; | |
| 13121 } | |
| 13122 else { | |
| 13123 typeParams.add(this._makeType(expr)); | |
| 13124 } | |
| 13125 } | |
| 13126 formals.add(formal); | |
| 13127 } | |
| 13128 else if (!!(formal && formal.is$List)) { | |
| 13129 formals.addAll(formal); | |
| 13130 if (!allowOptional) { | |
| 13131 this._lang_error('unexpected nested optional formal', expressions.$index
(i).get$span()); | |
| 13132 } | |
| 13133 } | |
| 13134 else { | |
| 13135 formals.add(formal); | |
| 13136 } | |
| 13137 } | |
| 13138 return formals; | |
| 13139 } | 13110 } |
| 13140 lang_Parser.prototype._makeDeclaredIdentifier = function(e) { | 13111 lang_Parser.prototype._makeDeclaredIdentifier = function(e) { |
| 13141 if ((e instanceof VarExpression)) { | 13112 if ((e instanceof VarExpression)) { |
| 13142 return new DeclaredIdentifier(null, e.get$name(), e.get$span()); | 13113 return new DeclaredIdentifier(null, e.get$name(), e.get$span()); |
| 13143 } | 13114 } |
| 13144 else if ((e instanceof DeclaredIdentifier)) { | 13115 else if ((e instanceof DeclaredIdentifier)) { |
| 13145 return e; | 13116 return e; |
| 13146 } | 13117 } |
| 13147 else { | 13118 else { |
| 13148 this._lang_error('expected declared identifier'); | 13119 this._lang_error('expected declared identifier'); |
| 13149 return new DeclaredIdentifier(null, null, e.get$span()); | 13120 return new DeclaredIdentifier(null, null, e.get$span()); |
| 13150 } | 13121 } |
| 13151 } | 13122 } |
| 13152 lang_Parser.prototype._makeLabel = function(expr) { | 13123 lang_Parser.prototype._makeLabel = function(expr) { |
| 13153 if ((expr instanceof VarExpression)) { | 13124 if ((expr instanceof VarExpression)) { |
| 13154 return expr.get$name(); | 13125 return expr.get$name(); |
| 13155 } | 13126 } |
| 13156 else { | 13127 else { |
| 13157 this._errorExpected('label'); | 13128 this._errorExpected('label'); |
| 13158 return null; | 13129 return null; |
| 13159 } | 13130 } |
| 13160 } | 13131 } |
| 13132 // ********** Code for DivertedTokenSource ************** |
| 13133 function DivertedTokenSource(tokens, parser, previousTokenizer) { |
| 13134 this._lang_pos = 0 |
| 13135 this.tokens = tokens; |
| 13136 this.parser = parser; |
| 13137 this.previousTokenizer = previousTokenizer; |
| 13138 // Initializers done |
| 13139 } |
| 13140 DivertedTokenSource.prototype.next = function() { |
| 13141 var token = this.tokens.$index(this._lang_pos); |
| 13142 ++this._lang_pos; |
| 13143 if (this._lang_pos == this.tokens.length) { |
| 13144 this.parser.tokenizer = this.previousTokenizer; |
| 13145 } |
| 13146 return token; |
| 13147 } |
| 13161 // ********** Code for lang_Node ************** | 13148 // ********** Code for lang_Node ************** |
| 13162 function lang_Node(span) { | 13149 function lang_Node(span) { |
| 13163 this.span = span; | 13150 this.span = span; |
| 13164 // Initializers done | 13151 // Initializers done |
| 13165 } | 13152 } |
| 13166 lang_Node.prototype.get$span = function() { return this.span; }; | 13153 lang_Node.prototype.get$span = function() { return this.span; }; |
| 13167 lang_Node.prototype.set$span = function(value) { return this.span = value; }; | 13154 lang_Node.prototype.set$span = function(value) { return this.span = value; }; |
| 13168 // ********** Code for Definition ************** | 13155 // ********** Code for Definition ************** |
| 13169 function Definition(span) { | 13156 function Definition(span) { |
| 13170 lang_Statement.call(this, span); | 13157 lang_Statement.call(this, span); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13263 // ********** Code for DirectiveDefinition ************** | 13250 // ********** Code for DirectiveDefinition ************** |
| 13264 function DirectiveDefinition(name, arguments, span) { | 13251 function DirectiveDefinition(name, arguments, span) { |
| 13265 this.name = name; | 13252 this.name = name; |
| 13266 this.arguments = arguments; | 13253 this.arguments = arguments; |
| 13267 Definition.call(this, span); | 13254 Definition.call(this, span); |
| 13268 // Initializers done | 13255 // Initializers done |
| 13269 } | 13256 } |
| 13270 $inherits(DirectiveDefinition, Definition); | 13257 $inherits(DirectiveDefinition, Definition); |
| 13271 DirectiveDefinition.prototype.get$name = function() { return this.name; }; | 13258 DirectiveDefinition.prototype.get$name = function() { return this.name; }; |
| 13272 DirectiveDefinition.prototype.set$name = function(value) { return this.name = va
lue; }; | 13259 DirectiveDefinition.prototype.set$name = function(value) { return this.name = va
lue; }; |
| 13273 DirectiveDefinition.prototype.get$arguments = function() { return this.arguments
; }; | |
| 13274 DirectiveDefinition.prototype.set$arguments = function(value) { return this.argu
ments = value; }; | |
| 13275 DirectiveDefinition.prototype.visit = function(visitor) { | 13260 DirectiveDefinition.prototype.visit = function(visitor) { |
| 13276 return visitor.visitDirectiveDefinition(this); | 13261 return visitor.visitDirectiveDefinition(this); |
| 13277 } | 13262 } |
| 13278 // ********** Code for TypeDefinition ************** | 13263 // ********** Code for TypeDefinition ************** |
| 13279 function TypeDefinition(isClass, name, typeParameters, extendsTypes, implementsT
ypes, nativeType, factoryType, body, span) { | 13264 function TypeDefinition(isClass, name, typeParameters, extendsTypes, implementsT
ypes, nativeType, factoryType, body, span) { |
| 13280 this.isClass = isClass; | 13265 this.isClass = isClass; |
| 13281 this.name = name; | 13266 this.name = name; |
| 13282 this.typeParameters = typeParameters; | 13267 this.typeParameters = typeParameters; |
| 13283 this.extendsTypes = extendsTypes; | 13268 this.extendsTypes = extendsTypes; |
| 13284 this.implementsTypes = implementsTypes; | 13269 this.implementsTypes = implementsTypes; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13551 return visitor.visitLambdaExpression(this); | 13536 return visitor.visitLambdaExpression(this); |
| 13552 } | 13537 } |
| 13553 // ********** Code for CallExpression ************** | 13538 // ********** Code for CallExpression ************** |
| 13554 function CallExpression(target, arguments, span) { | 13539 function CallExpression(target, arguments, span) { |
| 13555 this.target = target; | 13540 this.target = target; |
| 13556 this.arguments = arguments; | 13541 this.arguments = arguments; |
| 13557 lang_Expression.call(this, span); | 13542 lang_Expression.call(this, span); |
| 13558 // Initializers done | 13543 // Initializers done |
| 13559 } | 13544 } |
| 13560 $inherits(CallExpression, lang_Expression); | 13545 $inherits(CallExpression, lang_Expression); |
| 13561 CallExpression.prototype.get$arguments = function() { return this.arguments; }; | |
| 13562 CallExpression.prototype.set$arguments = function(value) { return this.arguments
= value; }; | |
| 13563 CallExpression.prototype.visit = function(visitor) { | 13546 CallExpression.prototype.visit = function(visitor) { |
| 13564 return visitor.visitCallExpression(this); | 13547 return visitor.visitCallExpression(this); |
| 13565 } | 13548 } |
| 13566 // ********** Code for IndexExpression ************** | 13549 // ********** Code for IndexExpression ************** |
| 13567 function IndexExpression(target, index, span) { | 13550 function IndexExpression(target, index, span) { |
| 13568 this.target = target; | 13551 this.target = target; |
| 13569 this.index = index; | 13552 this.index = index; |
| 13570 lang_Expression.call(this, span); | 13553 lang_Expression.call(this, span); |
| 13571 // Initializers done | 13554 // Initializers done |
| 13572 } | 13555 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13615 this.name = name; | 13598 this.name = name; |
| 13616 this.arguments = arguments; | 13599 this.arguments = arguments; |
| 13617 lang_Expression.call(this, span); | 13600 lang_Expression.call(this, span); |
| 13618 // Initializers done | 13601 // Initializers done |
| 13619 } | 13602 } |
| 13620 $inherits(lang_NewExpression, lang_Expression); | 13603 $inherits(lang_NewExpression, lang_Expression); |
| 13621 lang_NewExpression.prototype.get$isConst = function() { return this.isConst; }; | 13604 lang_NewExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 13622 lang_NewExpression.prototype.set$isConst = function(value) { return this.isConst
= value; }; | 13605 lang_NewExpression.prototype.set$isConst = function(value) { return this.isConst
= value; }; |
| 13623 lang_NewExpression.prototype.get$name = function() { return this.name; }; | 13606 lang_NewExpression.prototype.get$name = function() { return this.name; }; |
| 13624 lang_NewExpression.prototype.set$name = function(value) { return this.name = val
ue; }; | 13607 lang_NewExpression.prototype.set$name = function(value) { return this.name = val
ue; }; |
| 13625 lang_NewExpression.prototype.get$arguments = function() { return this.arguments;
}; | |
| 13626 lang_NewExpression.prototype.set$arguments = function(value) { return this.argum
ents = value; }; | |
| 13627 lang_NewExpression.prototype.visit = function(visitor) { | 13608 lang_NewExpression.prototype.visit = function(visitor) { |
| 13628 return visitor.visitNewExpression(this); | 13609 return visitor.visitNewExpression(this); |
| 13629 } | 13610 } |
| 13630 // ********** Code for ListExpression ************** | 13611 // ********** Code for ListExpression ************** |
| 13631 function ListExpression(isConst, type, values, span) { | 13612 function ListExpression(isConst, type, values, span) { |
| 13632 this.isConst = isConst; | 13613 this.isConst = isConst; |
| 13633 this.type = type; | 13614 this.type = type; |
| 13634 this.values = values; | 13615 this.values = values; |
| 13635 lang_Expression.call(this, span); | 13616 lang_Expression.call(this, span); |
| 13636 // Initializers done | 13617 // Initializers done |
| (...skipping 2391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16028 INTERFACE, | 16009 INTERFACE, |
| 16029 LIBRARY, | 16010 LIBRARY, |
| 16030 NATIVE, | 16011 NATIVE, |
| 16031 NEGATE, | 16012 NEGATE, |
| 16032 OPERATOR, | 16013 OPERATOR, |
| 16033 SET, | 16014 SET, |
| 16034 SOURCE, | 16015 SOURCE, |
| 16035 STATIC, | 16016 STATIC, |
| 16036 TYPEDEF ]*/; | 16017 TYPEDEF ]*/; |
| 16037 main(); | 16018 main(); |
| OLD | NEW |