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

Side by Side Diff: dart/frog/minfrog

Issue 10164004: Remove frogsh. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased 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 | « dart/frog/lib/node/node.dart ('k') | dart/frog/minfrog.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env node
2 // ********** Library dart:core **************
3 // ********** Natives dart:core **************
4 function $defProp(obj, prop, value) {
5 Object.defineProperty(obj, prop,
6 {value: value, enumerable: false, writable: true, configurable: true});
7 }
8 Function.prototype.bind = Function.prototype.bind ||
9 function(thisObj) {
10 var func = this;
11 var funcLength = func.$length || func.length;
12 var argsLength = arguments.length;
13 if (argsLength > 1) {
14 var boundArgs = Array.prototype.slice.call(arguments, 1);
15 var bound = function() {
16 // Prepend the bound arguments to the current arguments.
17 var newArgs = Array.prototype.slice.call(arguments);
18 Array.prototype.unshift.apply(newArgs, boundArgs);
19 return func.apply(thisObj, newArgs);
20 };
21 bound.$length = Math.max(0, funcLength - (argsLength - 1));
22 return bound;
23 } else {
24 var bound = function() {
25 return func.apply(thisObj, arguments);
26 };
27 bound.$length = funcLength;
28 return bound;
29 }
30 };
31 function $throw(e) {
32 // If e is not a value, we can use V8's captureStackTrace utility method.
33 // TODO(jmesserly): capture the stack trace on other JS engines.
34 if (e && (typeof e == 'object') && Error.captureStackTrace) {
35 // TODO(jmesserly): this will clobber the e.stack property
36 Error.captureStackTrace(e, $throw);
37 }
38 throw e;
39 }
40 $defProp(Object.prototype, '$index', function(i) {
41 $throw(new NoSuchMethodException(this, "operator []", [i]));
42 });
43 $defProp(Array.prototype, '$index', function(index) {
44 var i = index | 0;
45 if (i !== index) {
46 throw new IllegalArgumentException('index is not int');
47 } else if (i < 0 || i >= this.length) {
48 throw new IndexOutOfRangeException(index);
49 }
50 return this[i];
51 });
52 $defProp(String.prototype, '$index', function(i) {
53 return this[i];
54 });
55 $defProp(Object.prototype, '$setindex', function(i, value) {
56 $throw(new NoSuchMethodException(this, "operator []=", [i, value]));
57 });
58 $defProp(Array.prototype, '$setindex', function(index, value) {
59 var i = index | 0;
60 if (i !== index) {
61 throw new IllegalArgumentException('index is not int');
62 } else if (i < 0 || i >= this.length) {
63 throw new IndexOutOfRangeException(index);
64 }
65 return this[i] = value;
66 });
67 function $add$complex$(x, y) {
68 if (typeof(x) == 'number') {
69 $throw(new IllegalArgumentException(y));
70 } else if (typeof(x) == 'string') {
71 var str = (y == null) ? 'null' : y.toString();
72 if (typeof(str) != 'string') {
73 throw new Error("calling toString() on right hand operand of operator " +
74 "+ did not return a String");
75 }
76 return x + str;
77 } else if (typeof(x) == 'object') {
78 return x.$add(y);
79 } else {
80 $throw(new NoSuchMethodException(x, "operator +", [y]));
81 }
82 }
83
84 function $add$(x, y) {
85 if (typeof(x) == 'number' && typeof(y) == 'number') return x + y;
86 return $add$complex$(x, y);
87 }
88 function $bit_xor$complex$(x, y) {
89 if (typeof(x) == 'number') {
90 $throw(new IllegalArgumentException(y));
91 } else if (typeof(x) == 'object') {
92 return x.$bit_xor(y);
93 } else {
94 $throw(new NoSuchMethodException(x, "operator ^", [y]));
95 }
96 }
97 function $bit_xor$(x, y) {
98 if (typeof(x) == 'number' && typeof(y) == 'number') return x ^ y;
99 return $bit_xor$complex$(x, y);
100 }
101 function $eq$(x, y) {
102 if (x == null) return y == null;
103 return (typeof(x) != 'object') ? x === y : x.$eq(y);
104 }
105 // TODO(jimhug): Should this or should it not match equals?
106 $defProp(Object.prototype, '$eq', function(other) {
107 return this === other;
108 });
109 function $gt$complex$(x, y) {
110 if (typeof(x) == 'number') {
111 $throw(new IllegalArgumentException(y));
112 } else if (typeof(x) == 'object') {
113 return x.$gt(y);
114 } else {
115 $throw(new NoSuchMethodException(x, "operator >", [y]));
116 }
117 }
118 function $gt$(x, y) {
119 if (typeof(x) == 'number' && typeof(y) == 'number') return x > y;
120 return $gt$complex$(x, y);
121 }
122 function $gte$complex$(x, y) {
123 if (typeof(x) == 'number') {
124 $throw(new IllegalArgumentException(y));
125 } else if (typeof(x) == 'object') {
126 return x.$gte(y);
127 } else {
128 $throw(new NoSuchMethodException(x, "operator >=", [y]));
129 }
130 }
131 function $gte$(x, y) {
132 if (typeof(x) == 'number' && typeof(y) == 'number') return x >= y;
133 return $gte$complex$(x, y);
134 }
135 function $lt$complex$(x, y) {
136 if (typeof(x) == 'number') {
137 $throw(new IllegalArgumentException(y));
138 } else if (typeof(x) == 'object') {
139 return x.$lt(y);
140 } else {
141 $throw(new NoSuchMethodException(x, "operator <", [y]));
142 }
143 }
144 function $lt$(x, y) {
145 if (typeof(x) == 'number' && typeof(y) == 'number') return x < y;
146 return $lt$complex$(x, y);
147 }
148 function $lte$complex$(x, y) {
149 if (typeof(x) == 'number') {
150 $throw(new IllegalArgumentException(y));
151 } else if (typeof(x) == 'object') {
152 return x.$lte(y);
153 } else {
154 $throw(new NoSuchMethodException(x, "operator <=", [y]));
155 }
156 }
157 function $lte$(x, y) {
158 if (typeof(x) == 'number' && typeof(y) == 'number') return x <= y;
159 return $lte$complex$(x, y);
160 }
161 function $mod$(x, y) {
162 if (typeof(x) == 'number') {
163 if (typeof(y) == 'number') {
164 var result = x % y;
165 if (result == 0) {
166 return 0; // Make sure we don't return -0.0.
167 } else if (result < 0) {
168 if (y < 0) {
169 return result - y;
170 } else {
171 return result + y;
172 }
173 }
174 return result;
175 } else {
176 $throw(new IllegalArgumentException(y));
177 }
178 } else if (typeof(x) == 'object') {
179 return x.$mod(y);
180 } else {
181 $throw(new NoSuchMethodException(x, "operator %", [y]));
182 }
183 }
184 function $mul$complex$(x, y) {
185 if (typeof(x) == 'number') {
186 $throw(new IllegalArgumentException(y));
187 } else if (typeof(x) == 'object') {
188 return x.$mul(y);
189 } else {
190 $throw(new NoSuchMethodException(x, "operator *", [y]));
191 }
192 }
193 function $mul$(x, y) {
194 if (typeof(x) == 'number' && typeof(y) == 'number') return x * y;
195 return $mul$complex$(x, y);
196 }
197 function $ne$(x, y) {
198 if (x == null) return y != null;
199 return (typeof(x) != 'object') ? x !== y : !x.$eq(y);
200 }
201 function $shl$complex$(x, y) {
202 if (typeof(x) == 'number') {
203 $throw(new IllegalArgumentException(y));
204 } else if (typeof(x) == 'object') {
205 return x.$shl(y);
206 } else {
207 $throw(new NoSuchMethodException(x, "operator <<", [y]));
208 }
209 }
210 function $shl$(x, y) {
211 if (typeof(x) == 'number' && typeof(y) == 'number') return x << y;
212 return $shl$complex$(x, y);
213 }
214 function $sub$complex$(x, y) {
215 if (typeof(x) == 'number') {
216 $throw(new IllegalArgumentException(y));
217 } else if (typeof(x) == 'object') {
218 return x.$sub(y);
219 } else {
220 $throw(new NoSuchMethodException(x, "operator -", [y]));
221 }
222 }
223 function $sub$(x, y) {
224 if (typeof(x) == 'number' && typeof(y) == 'number') return x - y;
225 return $sub$complex$(x, y);
226 }
227 function $truncdiv$(x, y) {
228 if (typeof(x) == 'number') {
229 if (typeof(y) == 'number') {
230 if (y == 0) $throw(new IntegerDivisionByZeroException());
231 var tmp = x / y;
232 return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp);
233 } else {
234 $throw(new IllegalArgumentException(y));
235 }
236 } else if (typeof(x) == 'object') {
237 return x.$truncdiv(y);
238 } else {
239 $throw(new NoSuchMethodException(x, "operator ~/", [y]));
240 }
241 }
242 /** Implements extends for Dart classes on JavaScript prototypes. */
243 function $inherits(child, parent) {
244 if (child.prototype.__proto__) {
245 child.prototype.__proto__ = parent.prototype;
246 } else {
247 function tmp() {};
248 tmp.prototype = parent.prototype;
249 child.prototype = new tmp();
250 child.prototype.constructor = child;
251 }
252 }
253 $defProp(Object.prototype, '$typeNameOf', (function() {
254 function constructorNameWithFallback(obj) {
255 var constructor = obj.constructor;
256 if (typeof(constructor) == 'function') {
257 // The constructor isn't null or undefined at this point. Try
258 // to grab hold of its name.
259 var name = constructor.name;
260 // If the name is a non-empty string, we use that as the type
261 // name of this object. On Firefox, we often get 'Object' as
262 // the constructor name even for more specialized objects so
263 // we have to fall through to the toString() based implementation
264 // below in that case.
265 if (typeof(name) == 'string' && name && name != 'Object') return name;
266 }
267 var string = Object.prototype.toString.call(obj);
268 return string.substring(8, string.length - 1);
269 }
270
271 function chrome$typeNameOf() {
272 var name = this.constructor.name;
273 if (name == 'Window') return 'DOMWindow';
274 return name;
275 }
276
277 function firefox$typeNameOf() {
278 var name = constructorNameWithFallback(this);
279 if (name == 'Window') return 'DOMWindow';
280 if (name == 'Document') return 'HTMLDocument';
281 if (name == 'XMLDocument') return 'Document';
282 return name;
283 }
284
285 function ie$typeNameOf() {
286 var name = constructorNameWithFallback(this);
287 if (name == 'Window') return 'DOMWindow';
288 // IE calls both HTML and XML documents 'Document', so we check for the
289 // xmlVersion property, which is the empty string on HTML documents.
290 if (name == 'Document' && this.xmlVersion) return 'Document';
291 if (name == 'Document') return 'HTMLDocument';
292 return name;
293 }
294
295 // If we're not in the browser, we're almost certainly running on v8.
296 if (typeof(navigator) != 'object') return chrome$typeNameOf;
297
298 var userAgent = navigator.userAgent;
299 if (/Chrome|DumpRenderTree/.test(userAgent)) return chrome$typeNameOf;
300 if (/Firefox/.test(userAgent)) return firefox$typeNameOf;
301 if (/MSIE/.test(userAgent)) return ie$typeNameOf;
302 return function() { return constructorNameWithFallback(this); };
303 })());
304 function $dynamic(name) {
305 var f = Object.prototype[name];
306 if (f && f.methods) return f.methods;
307
308 var methods = {};
309 if (f) methods.Object = f;
310 function $dynamicBind() {
311 // Find the target method
312 var obj = this;
313 var tag = obj.$typeNameOf();
314 var method = methods[tag];
315 if (!method) {
316 var table = $dynamicMetadata;
317 for (var i = 0; i < table.length; i++) {
318 var entry = table[i];
319 if (entry.map.hasOwnProperty(tag)) {
320 method = methods[entry.tag];
321 if (method) break;
322 }
323 }
324 }
325 method = method || methods.Object;
326
327 var proto = Object.getPrototypeOf(obj);
328
329 if (method == null) {
330 // Trampoline to throw NoSuchMethodException (TODO: call noSuchMethod).
331 method = function(){
332 // Exact type check to prevent this code shadowing the dispatcher from a
333 // subclass.
334 if (Object.getPrototypeOf(this) === proto) {
335 // TODO(sra): 'name' is the jsname, should be the Dart name.
336 $throw(new NoSuchMethodException(
337 obj, name, Array.prototype.slice.call(arguments)));
338 }
339 return Object.prototype[name].apply(this, arguments);
340 };
341 }
342
343 if (!proto.hasOwnProperty(name)) {
344 $defProp(proto, name, method);
345 }
346
347 return method.apply(this, Array.prototype.slice.call(arguments));
348 };
349 $dynamicBind.methods = methods;
350 $defProp(Object.prototype, name, $dynamicBind);
351 return methods;
352 }
353 if (typeof $dynamicMetadata == 'undefined') $dynamicMetadata = [];
354 // ********** Code for Object **************
355 $defProp(Object.prototype, "get$dynamic", function() {
356 "use strict"; return this;
357 });
358 $defProp(Object.prototype, "noSuchMethod", function(name, args) {
359 $throw(new NoSuchMethodException(this, name, args));
360 });
361 $defProp(Object.prototype, "_pushBlock$1", function($0) {
362 return this.noSuchMethod("_pushBlock", [$0]);
363 });
364 $defProp(Object.prototype, "analyze$1", function($0) {
365 return this.noSuchMethod("analyze", [$0]);
366 });
367 $defProp(Object.prototype, "contains$1", function($0) {
368 return this.noSuchMethod("contains", [$0]);
369 });
370 $defProp(Object.prototype, "create$3$isFinal", function($0, $1, $2, isFinal) {
371 return this.noSuchMethod("create", [$0, $1, $2, isFinal]);
372 });
373 $defProp(Object.prototype, "end$0", function() {
374 return this.noSuchMethod("end", []);
375 });
376 $defProp(Object.prototype, "indexOf$1", function($0) {
377 return this.noSuchMethod("indexOf", [$0]);
378 });
379 $defProp(Object.prototype, "instanceOf$3$isTrue$forceCheck", function($0, $1, $2 , isTrue, forceCheck) {
380 return this.noSuchMethod("instanceOf", [$0, $1, $2, isTrue, forceCheck]);
381 });
382 $defProp(Object.prototype, "instanceOf$4", function($0, $1, $2, $3) {
383 return this.noSuchMethod("instanceOf", [$0, $1, $2, $3]);
384 });
385 $defProp(Object.prototype, "invokeNoSuchMethod$3", function($0, $1, $2) {
386 return this.noSuchMethod("invokeNoSuchMethod", [$0, $1, $2]);
387 });
388 $defProp(Object.prototype, "is$Collection", function() {
389 return false;
390 });
391 $defProp(Object.prototype, "is$List", function() {
392 return false;
393 });
394 $defProp(Object.prototype, "is$Map", function() {
395 return false;
396 });
397 $defProp(Object.prototype, "is$RegExp", function() {
398 return false;
399 });
400 $defProp(Object.prototype, "remove$1", function($0) {
401 return this.noSuchMethod("remove", [$0]);
402 });
403 $defProp(Object.prototype, "run$0", function() {
404 return this.noSuchMethod("run", []);
405 });
406 $defProp(Object.prototype, "setIndex$4$kind", function($0, $1, $2, $3, kind) {
407 return this.noSuchMethod("setIndex", [$0, $1, $2, $3, kind]);
408 });
409 $defProp(Object.prototype, "setIndex$4$kind$returnKind", function($0, $1, $2, $3 , kind, returnKind) {
410 return this.noSuchMethod("setIndex", [$0, $1, $2, $3, kind, returnKind]);
411 });
412 $defProp(Object.prototype, "set_$4$kind", function($0, $1, $2, $3, kind) {
413 return this.noSuchMethod("set_", [$0, $1, $2, $3, kind]);
414 });
415 $defProp(Object.prototype, "set_$4$kind$returnKind", function($0, $1, $2, $3, ki nd, returnKind) {
416 return this.noSuchMethod("set_", [$0, $1, $2, $3, kind, returnKind]);
417 });
418 $defProp(Object.prototype, "substring$1", function($0) {
419 return this.noSuchMethod("substring", [$0]);
420 });
421 $defProp(Object.prototype, "toString$0", function() {
422 return this.toString();
423 });
424 $defProp(Object.prototype, "visitBinaryExpression$1", function($0) {
425 return this.noSuchMethod("visitBinaryExpression", [$0]);
426 });
427 $defProp(Object.prototype, "visitCallExpression$1", function($0) {
428 return this.noSuchMethod("visitCallExpression", [$0]);
429 });
430 $defProp(Object.prototype, "visitPostfixExpression$1", function($0) {
431 return this.noSuchMethod("visitPostfixExpression", [$0]);
432 });
433 $defProp(Object.prototype, "write$1", function($0) {
434 return this.noSuchMethod("write", [$0]);
435 });
436 // ********** Code for Clock **************
437 function Clock() {}
438 Clock.now = function() {
439 return new Date().getTime();
440 }
441 Clock.frequency = function() {
442 return (1000);
443 }
444 // ********** Code for IndexOutOfRangeException **************
445 function IndexOutOfRangeException(_index) {
446 this._index = _index;
447 }
448 IndexOutOfRangeException.prototype.is$IndexOutOfRangeException = function(){retu rn true};
449 IndexOutOfRangeException.prototype.toString = function() {
450 return ("IndexOutOfRangeException: " + this._index);
451 }
452 IndexOutOfRangeException.prototype.toString$0 = IndexOutOfRangeException.prototy pe.toString;
453 // ********** Code for IllegalAccessException **************
454 function IllegalAccessException() {
455
456 }
457 IllegalAccessException.prototype.toString = function() {
458 return "Attempt to modify an immutable object";
459 }
460 IllegalAccessException.prototype.toString$0 = IllegalAccessException.prototype.t oString;
461 // ********** Code for NoSuchMethodException **************
462 function NoSuchMethodException(_receiver, _functionName, _arguments, _existingAr gumentNames) {
463 this._receiver = _receiver;
464 this._functionName = _functionName;
465 this._arguments = _arguments;
466 this._existingArgumentNames = _existingArgumentNames;
467 }
468 NoSuchMethodException.prototype.is$NoSuchMethodException = function(){return tru e};
469 NoSuchMethodException.prototype.toString = function() {
470 var sb = new StringBufferImpl("");
471 for (var i = (0);
472 i < this._arguments.get$length(); i++) {
473 if (i > (0)) {
474 sb.add(", ");
475 }
476 sb.add(this._arguments.$index(i));
477 }
478 if (null == this._existingArgumentNames) {
479 return (("NoSuchMethodException : method not found: '" + this._functionName + "'\n") + ("Receiver: " + this._receiver + "\n") + ("Arguments: [" + sb + "]")) ;
480 }
481 else {
482 var actualParameters = sb.toString();
483 sb = new StringBufferImpl("");
484 for (var i = (0);
485 i < this._existingArgumentNames.get$length(); i++) {
486 if (i > (0)) {
487 sb.add(", ");
488 }
489 sb.add(this._existingArgumentNames.$index(i));
490 }
491 var formalParameters = sb.toString();
492 return ("NoSuchMethodException: incorrect number of arguments passed to " + ("method named '" + this._functionName + "'\nReceiver: " + this._receiver + "\n" ) + ("Tried calling: " + this._functionName + "(" + actualParameters + ")\n") + ("Found: " + this._functionName + "(" + formalParameters + ")"));
493 }
494 }
495 NoSuchMethodException.prototype.toString$0 = NoSuchMethodException.prototype.toS tring;
496 // ********** Code for ClosureArgumentMismatchException **************
497 function ClosureArgumentMismatchException() {
498
499 }
500 ClosureArgumentMismatchException.prototype.toString = function() {
501 return "Closure argument mismatch";
502 }
503 ClosureArgumentMismatchException.prototype.toString$0 = ClosureArgumentMismatchE xception.prototype.toString;
504 // ********** Code for ObjectNotClosureException **************
505 function ObjectNotClosureException() {
506
507 }
508 ObjectNotClosureException.prototype.toString = function() {
509 return "Object is not closure";
510 }
511 ObjectNotClosureException.prototype.toString$0 = ObjectNotClosureException.proto type.toString;
512 // ********** Code for IllegalArgumentException **************
513 function IllegalArgumentException(arg) {
514 this._arg = arg;
515 }
516 IllegalArgumentException.prototype.is$IllegalArgumentException = function(){retu rn true};
517 IllegalArgumentException.prototype.toString = function() {
518 return ("Illegal argument(s): " + this._arg);
519 }
520 IllegalArgumentException.prototype.toString$0 = IllegalArgumentException.prototy pe.toString;
521 // ********** Code for StackOverflowException **************
522 function StackOverflowException() {
523
524 }
525 StackOverflowException.prototype.toString = function() {
526 return "Stack Overflow";
527 }
528 StackOverflowException.prototype.toString$0 = StackOverflowException.prototype.t oString;
529 // ********** Code for BadNumberFormatException **************
530 function BadNumberFormatException(_s) {
531 this._s = _s;
532 }
533 BadNumberFormatException.prototype.toString = function() {
534 return ("BadNumberFormatException: '" + this._s + "'");
535 }
536 BadNumberFormatException.prototype.toString$0 = BadNumberFormatException.prototy pe.toString;
537 // ********** Code for NullPointerException **************
538 function NullPointerException(functionName, arguments) {
539 this.functionName = functionName;
540 this.arguments = arguments;
541 }
542 NullPointerException.prototype.toString = function() {
543 if (this.functionName == null) {
544 return this.get$exceptionName();
545 }
546 else {
547 return (("" + this.get$exceptionName() + " : method: '" + this.functionName + "'\n") + "Receiver: null\n" + ("Arguments: " + this.arguments));
548 }
549 }
550 NullPointerException.prototype.get$exceptionName = function() {
551 return "NullPointerException";
552 }
553 NullPointerException.prototype.toString$0 = NullPointerException.prototype.toStr ing;
554 // ********** Code for NoMoreElementsException **************
555 function NoMoreElementsException() {
556
557 }
558 NoMoreElementsException.prototype.toString = function() {
559 return "NoMoreElementsException";
560 }
561 NoMoreElementsException.prototype.toString$0 = NoMoreElementsException.prototype .toString;
562 // ********** Code for EmptyQueueException **************
563 function EmptyQueueException() {
564
565 }
566 EmptyQueueException.prototype.toString = function() {
567 return "EmptyQueueException";
568 }
569 EmptyQueueException.prototype.toString$0 = EmptyQueueException.prototype.toStrin g;
570 // ********** Code for IntegerDivisionByZeroException **************
571 function IntegerDivisionByZeroException() {
572
573 }
574 IntegerDivisionByZeroException.prototype.is$IntegerDivisionByZeroException = fun ction(){return true};
575 IntegerDivisionByZeroException.prototype.toString = function() {
576 return "IntegerDivisionByZeroException";
577 }
578 IntegerDivisionByZeroException.prototype.toString$0 = IntegerDivisionByZeroExcep tion.prototype.toString;
579 // ********** Code for dart_core_Function **************
580 Function.prototype.to$call$0 = function() {
581 this.call$0 = this._genStub(0);
582 this.to$call$0 = function() { return this.call$0; };
583 return this.call$0;
584 };
585 Function.prototype.call$0 = function() {
586 return this.to$call$0()();
587 };
588 function to$call$0(f) { return f && f.to$call$0(); }
589 Function.prototype.to$call$1 = function() {
590 this.call$1 = this._genStub(1);
591 this.to$call$1 = function() { return this.call$1; };
592 return this.call$1;
593 };
594 Function.prototype.call$1 = function($0) {
595 return this.to$call$1()($0);
596 };
597 function to$call$1(f) { return f && f.to$call$1(); }
598 Function.prototype.to$call$2 = function() {
599 this.call$2 = this._genStub(2);
600 this.to$call$2 = function() { return this.call$2; };
601 return this.call$2;
602 };
603 Function.prototype.call$2 = function($0, $1) {
604 return this.to$call$2()($0, $1);
605 };
606 function to$call$2(f) { return f && f.to$call$2(); }
607 // ********** Code for Math **************
608 Math.parseInt = function(str) {
609 var match = /^\s*[+-]?(?:(0[xX][abcdefABCDEF0-9]+)|\d+)\s*$/.exec(str);
610 if (!match) $throw(new BadNumberFormatException(str));
611 var isHex = !!match[1];
612 var ret = parseInt(str, isHex ? 16 : 10);
613 if (isNaN(ret)) $throw(new BadNumberFormatException(str));
614 return ret;
615 }
616 Math.parseDouble = function(str) {
617 var ret = parseFloat(str);
618 if (isNaN(ret) && str != 'NaN') $throw(new BadNumberFormatException(str));
619 return ret;
620 }
621 Math.min = function(a, b) {
622 if (a == b) return a;
623 if (a < b) {
624 if (isNaN(b)) return b;
625 else return a;
626 }
627 if (isNaN(a)) return a;
628 else return b;
629 }
630 // ********** Code for Strings **************
631 function Strings() {}
632 Strings.String$fromCharCodes$factory = function(charCodes) {
633 return StringBase.createFromCharCodes(charCodes);
634 }
635 Strings.join = function(strings, separator) {
636 return StringBase.join(strings, separator);
637 }
638 // ********** Code for top level **************
639 function print$(obj) {
640 return _print(obj);
641 }
642 function _print(obj) {
643 if (typeof console == 'object') {
644 if (obj) obj = obj.toString();
645 console.log(obj);
646 } else if (typeof write === 'function') {
647 write(obj);
648 write('\n');
649 }
650 }
651 function _toDartException(e) {
652 function attachStack(dartEx) {
653 // TODO(jmesserly): setting the stack property is not a long term solution.
654 var stack = e.stack;
655 // The stack contains the error message, and the stack is all that is
656 // printed (the exception's toString() is never called). Make the Dart
657 // exception's toString() be the dominant message.
658 if (typeof stack == 'string') {
659 var message = dartEx.toString();
660 if (/^(Type|Range)Error:/.test(stack)) {
661 // Indent JS message (it can be helpful) so new message stands out.
662 stack = ' (' + stack.substring(0, stack.indexOf('\n')) + ')\n' +
663 stack.substring(stack.indexOf('\n') + 1);
664 }
665 stack = message + '\n' + stack;
666 }
667 dartEx.stack = stack;
668 return dartEx;
669 }
670
671 if (e instanceof TypeError) {
672 switch(e.type) {
673 case 'property_not_function':
674 case 'called_non_callable':
675 if (e.arguments[0] == null) {
676 return attachStack(new NullPointerException(null, []));
677 } else {
678 return attachStack(new ObjectNotClosureException());
679 }
680 break;
681 case 'non_object_property_call':
682 case 'non_object_property_load':
683 return attachStack(new NullPointerException(null, []));
684 break;
685 case 'undefined_method':
686 var mname = e.arguments[0];
687 if (typeof(mname) == 'string' && (mname.indexOf('call$') == 0
688 || mname == 'call' || mname == 'apply')) {
689 return attachStack(new ObjectNotClosureException());
690 } else {
691 // TODO(jmesserly): fix noSuchMethod on operators so we don't hit this
692 return attachStack(new NoSuchMethodException('', e.arguments[0], []));
693 }
694 break;
695 }
696 } else if (e instanceof RangeError) {
697 if (e.message.indexOf('call stack') >= 0) {
698 return attachStack(new StackOverflowException());
699 }
700 }
701 return e;
702 }
703 // ********** Library dart:coreimpl **************
704 // ********** Code for ListFactory **************
705 ListFactory = Array;
706 $defProp(ListFactory.prototype, "is$List", function(){return true});
707 $defProp(ListFactory.prototype, "is$Collection", function(){return true});
708 ListFactory.ListFactory$from$factory = function(other) {
709 var list = [];
710 for (var $$i = other.iterator(); $$i.hasNext(); ) {
711 var e = $$i.next();
712 list.add(e);
713 }
714 return list;
715 }
716 $defProp(ListFactory.prototype, "get$length", function() { return this.length; } );
717 $defProp(ListFactory.prototype, "set$length", function(value) { return this.leng th = value; });
718 $defProp(ListFactory.prototype, "add", function(value) {
719 this.push(value);
720 });
721 $defProp(ListFactory.prototype, "addLast", function(value) {
722 this.push(value);
723 });
724 $defProp(ListFactory.prototype, "addAll", function(collection) {
725 for (var $$i = collection.iterator(); $$i.hasNext(); ) {
726 var item = $$i.next();
727 this.add(item);
728 }
729 });
730 $defProp(ListFactory.prototype, "clear", function() {
731 this.set$length((0));
732 });
733 $defProp(ListFactory.prototype, "removeLast", function() {
734 return this.pop();
735 });
736 $defProp(ListFactory.prototype, "last", function() {
737 return this.$index(this.get$length() - (1));
738 });
739 $defProp(ListFactory.prototype, "getRange", function(start, rangeLength) {
740 if (rangeLength == 0) return [];
741 if (rangeLength < 0) throw new IllegalArgumentException('length');
742 if (start < 0 || start + rangeLength > this.length)
743 throw new IndexOutOfRangeException(start);
744 return this.slice(start, start + rangeLength);
745
746 });
747 $defProp(ListFactory.prototype, "insertRange", function(start, rangeLength, init ialValue) {
748 if (rangeLength == 0) return;
749 if (rangeLength < 0) throw new IllegalArgumentException('length');
750 if (start < 0 || start > this.length)
751 throw new IndexOutOfRangeException(start);
752
753 // Splice in the values with a minimum of array allocations.
754 var args = new Array(rangeLength + 2);
755 args[0] = start;
756 args[1] = 0;
757 for (var i = 0; i < rangeLength; i++) {
758 args[i + 2] = initialValue;
759 }
760 this.splice.apply(this, args);
761
762 });
763 $defProp(ListFactory.prototype, "isEmpty", function() {
764 return this.get$length() == (0);
765 });
766 $defProp(ListFactory.prototype, "iterator", function() {
767 return new ListIterator(this);
768 });
769 $defProp(ListFactory.prototype, "toString", function() {
770 return Collections.collectionToString(this);
771 });
772 $defProp(ListFactory.prototype, "indexOf$1", ListFactory.prototype.indexOf);
773 $defProp(ListFactory.prototype, "toString$0", ListFactory.prototype.toString);
774 // ********** Code for ListIterator **************
775 function ListIterator(array) {
776 this._array = array;
777 this._pos = (0);
778 }
779 ListIterator.prototype.hasNext = function() {
780 return this._array.get$length() > this._pos;
781 }
782 ListIterator.prototype.next = function() {
783 if (!this.hasNext()) {
784 $throw(const$0001);
785 }
786 return this._array.$index(this._pos++);
787 }
788 // ********** Code for ImmutableList **************
789 $inherits(ImmutableList, ListFactory);
790 function ImmutableList(length) {
791 Array.call(this, length);
792 }
793 ImmutableList.ImmutableList$from$factory = function(other) {
794 return _constList(other);
795 }
796 ImmutableList.prototype.get$length = function() {
797 return this.length;
798 }
799 ImmutableList.prototype.set$length = function(length) {
800 $throw(const$0006);
801 }
802 ImmutableList.prototype.$setindex = function(index, value) {
803 $throw(const$0006);
804 }
805 ImmutableList.prototype.insertRange = function(start, length, initialValue) {
806 $throw(const$0006);
807 }
808 ImmutableList.prototype.sort = function(compare) {
809 $throw(const$0006);
810 }
811 ImmutableList.prototype.add = function(element) {
812 $throw(const$0006);
813 }
814 ImmutableList.prototype.addLast = function(element) {
815 $throw(const$0006);
816 }
817 ImmutableList.prototype.addAll = function(elements) {
818 $throw(const$0006);
819 }
820 ImmutableList.prototype.clear = function() {
821 $throw(const$0006);
822 }
823 ImmutableList.prototype.removeLast = function() {
824 $throw(const$0006);
825 }
826 ImmutableList.prototype.toString = function() {
827 return Collections.collectionToString(this);
828 }
829 ImmutableList.prototype.toString$0 = ImmutableList.prototype.toString;
830 // ********** Code for JSSyntaxRegExp **************
831 function JSSyntaxRegExp(pattern, multiLine, ignoreCase) {
832 JSSyntaxRegExp._create$ctor.call(this, pattern, $add$(($eq$(multiLine, true) ? "m" : ""), ($eq$(ignoreCase, true) ? "i" : "")));
833 }
834 JSSyntaxRegExp._create$ctor = function(pattern, flags) {
835 this.re = new RegExp(pattern, flags);
836 this.pattern = pattern;
837 this.multiLine = this.re.multiline;
838 this.ignoreCase = this.re.ignoreCase;
839 }
840 JSSyntaxRegExp._create$ctor.prototype = JSSyntaxRegExp.prototype;
841 JSSyntaxRegExp.prototype.is$RegExp = function(){return true};
842 JSSyntaxRegExp.prototype.firstMatch = function(str) {
843 var m = this._exec(str);
844 return m == null ? null : new MatchImplementation(this.pattern, str, this._mat chStart(m), this.get$_lastIndex(), m);
845 }
846 JSSyntaxRegExp.prototype._exec = function(str) {
847 return this.re.exec(str);
848 }
849 JSSyntaxRegExp.prototype._matchStart = function(m) {
850 return m.index;
851 }
852 JSSyntaxRegExp.prototype.get$_lastIndex = function() {
853 return this.re.lastIndex;
854 }
855 JSSyntaxRegExp.prototype.hasMatch = function(str) {
856 return this.re.test(str);
857 }
858 JSSyntaxRegExp.prototype.allMatches = function(str) {
859 return new _AllMatchesIterable(this, str);
860 }
861 JSSyntaxRegExp.prototype.get$_global = function() {
862 return new JSSyntaxRegExp._create$ctor(this.pattern, $add$($add$("g", (this.mu ltiLine ? "m" : "")), (this.ignoreCase ? "i" : "")));
863 }
864 // ********** Code for MatchImplementation **************
865 function MatchImplementation(pattern, str, _start, _end, _groups) {
866 this.pattern = pattern;
867 this.str = str;
868 this._start = _start;
869 this._end = _end;
870 this._groups = _groups;
871 }
872 MatchImplementation.prototype.start = function() {
873 return this._start;
874 }
875 MatchImplementation.prototype.get$start = function() {
876 return this.start.bind(this);
877 }
878 MatchImplementation.prototype.end = function() {
879 return this._end;
880 }
881 MatchImplementation.prototype.$index = function(groupIndex) {
882 return this._groups.$index(groupIndex);
883 }
884 MatchImplementation.prototype.end$0 = MatchImplementation.prototype.end;
885 // ********** Code for _AllMatchesIterable **************
886 function _AllMatchesIterable(_re, _str) {
887 this._re = _re;
888 this._str = _str;
889 }
890 _AllMatchesIterable.prototype.iterator = function() {
891 return new _AllMatchesIterator(this._re, this._str);
892 }
893 // ********** Code for _AllMatchesIterator **************
894 function _AllMatchesIterator(re, _str) {
895 this._str = _str;
896 this._done = false;
897 this._re = re.get$_global();
898 }
899 _AllMatchesIterator.prototype.next = function() {
900 if (!this.hasNext()) {
901 $throw(const$0001);
902 }
903 var result = this._next;
904 this._next = null;
905 return result;
906 }
907 _AllMatchesIterator.prototype.hasNext = function() {
908 if (this._done) {
909 return false;
910 }
911 else if (this._next != null) {
912 return true;
913 }
914 this._next = this._re.firstMatch(this._str);
915 if (this._next == null) {
916 this._done = true;
917 return false;
918 }
919 else {
920 return true;
921 }
922 }
923 // ********** Code for NumImplementation **************
924 NumImplementation = Number;
925 NumImplementation.prototype.$negate = function() {
926 'use strict'; return -this;
927 }
928 NumImplementation.prototype.isNaN = function() {
929 'use strict'; return isNaN(this);
930 }
931 NumImplementation.prototype.isNegative = function() {
932 'use strict'; return this == 0 ? (1 / this) < 0 : this < 0;
933 }
934 NumImplementation.prototype.hashCode = function() {
935 'use strict'; return this & 0x1FFFFFFF;
936 }
937 NumImplementation.prototype.toDouble = function() {
938 'use strict'; return this + 0;
939 }
940 NumImplementation.prototype.toRadixString = function(radix) {
941 'use strict'; return this.toString(radix)
942 }
943 NumImplementation.prototype.compareTo = function(other) {
944 var thisValue = this.toDouble();
945 if (thisValue < other) {
946 return (-1);
947 }
948 else if (thisValue > other) {
949 return (1);
950 }
951 else if (thisValue == other) {
952 if (thisValue == (0)) {
953 var thisIsNegative = this.isNegative();
954 var otherIsNegative = other.isNegative();
955 if ($eq$(thisIsNegative, otherIsNegative)) return (0);
956 if (thisIsNegative) return (-1);
957 return (1);
958 }
959 return (0);
960 }
961 else if (this.isNaN()) {
962 if (other.isNaN()) {
963 return (0);
964 }
965 return (1);
966 }
967 else {
968 return (-1);
969 }
970 }
971 // ********** Code for Collections **************
972 function Collections() {}
973 Collections.collectionToString = function(c) {
974 var result = new StringBufferImpl("");
975 Collections._emitCollection(c, result, new Array());
976 return result.toString$0();
977 }
978 Collections._emitCollection = function(c, result, visiting) {
979 visiting.add(c);
980 var isList = !!(c && c.is$List());
981 result.add(isList ? "[" : "{");
982 var first = true;
983 for (var $$i = c.iterator(); $$i.hasNext(); ) {
984 var e = $$i.next();
985 if (!first) {
986 result.add(", ");
987 }
988 first = false;
989 Collections._emitObject(e, result, visiting);
990 }
991 result.add(isList ? "]" : "}");
992 visiting.removeLast();
993 }
994 Collections._emitObject = function(o, result, visiting) {
995 if (!!(o && o.is$Collection())) {
996 if (Collections._containsRef(visiting, o)) {
997 result.add(!!(o && o.is$List()) ? "[...]" : "{...}");
998 }
999 else {
1000 Collections._emitCollection(o, result, visiting);
1001 }
1002 }
1003 else if (!!(o && o.is$Map())) {
1004 if (Collections._containsRef(visiting, o)) {
1005 result.add("{...}");
1006 }
1007 else {
1008 Maps._emitMap(o, result, visiting);
1009 }
1010 }
1011 else {
1012 result.add($eq$(o) ? "null" : o);
1013 }
1014 }
1015 Collections._containsRef = function(c, ref) {
1016 for (var $$i = c.iterator(); $$i.hasNext(); ) {
1017 var e = $$i.next();
1018 if ((null == e ? null == (ref) : e === ref)) return true;
1019 }
1020 return false;
1021 }
1022 // ********** Code for HashMapImplementation **************
1023 function HashMapImplementation() {
1024 this._numberOfEntries = (0);
1025 this._numberOfDeleted = (0);
1026 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1027 this._keys = new Array((8));
1028 this._values = new Array((8));
1029 }
1030 HashMapImplementation.prototype.is$Map = function(){return true};
1031 HashMapImplementation.HashMapImplementation$from$factory = function(other) {
1032 var result = new HashMapImplementation();
1033 other.forEach((function (key, value) {
1034 result.$setindex(key, value);
1035 })
1036 );
1037 return result;
1038 }
1039 HashMapImplementation._computeLoadLimit = function(capacity) {
1040 return $truncdiv$((capacity * (3)), (4));
1041 }
1042 HashMapImplementation._firstProbe = function(hashCode, length) {
1043 return hashCode & (length - (1));
1044 }
1045 HashMapImplementation._nextProbe = function(currentProbe, numberOfProbes, length ) {
1046 return (currentProbe + numberOfProbes) & (length - (1));
1047 }
1048 HashMapImplementation.prototype._probeForAdding = function(key) {
1049 var hash = HashMapImplementation._firstProbe(key.hashCode(), this._keys.get$le ngth());
1050 var numberOfProbes = (1);
1051 var initialHash = hash;
1052 var insertionIndex = (-1);
1053 while (true) {
1054 var existingKey = this._keys.$index(hash);
1055 if (null == existingKey) {
1056 if (insertionIndex < (0)) return hash;
1057 return insertionIndex;
1058 }
1059 else if ($eq$(existingKey, key)) {
1060 return hash;
1061 }
1062 else if ((insertionIndex < (0)) && ((null == const$0000 ? null == (existingK ey) : const$0000 === existingKey))) {
1063 insertionIndex = hash;
1064 }
1065 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.g et$length());
1066 }
1067 }
1068 HashMapImplementation.prototype._probeForLookup = function(key) {
1069 var hash = HashMapImplementation._firstProbe(key.hashCode(), this._keys.get$le ngth());
1070 var numberOfProbes = (1);
1071 var initialHash = hash;
1072 while (true) {
1073 var existingKey = this._keys.$index(hash);
1074 if (null == existingKey) return (-1);
1075 if ($eq$(existingKey, key)) return hash;
1076 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.g et$length());
1077 }
1078 }
1079 HashMapImplementation.prototype._ensureCapacity = function() {
1080 var newNumberOfEntries = this._numberOfEntries + (1);
1081 if (newNumberOfEntries >= this._loadLimit) {
1082 this._grow(this._keys.get$length() * (2));
1083 return;
1084 }
1085 var capacity = this._keys.get$length();
1086 var numberOfFreeOrDeleted = capacity - newNumberOfEntries;
1087 var numberOfFree = numberOfFreeOrDeleted - this._numberOfDeleted;
1088 if (this._numberOfDeleted > numberOfFree) {
1089 this._grow(this._keys.get$length());
1090 }
1091 }
1092 HashMapImplementation._isPowerOfTwo = function(x) {
1093 return ((x & (x - (1))) == (0));
1094 }
1095 HashMapImplementation.prototype._grow = function(newCapacity) {
1096 var capacity = this._keys.get$length();
1097 this._loadLimit = HashMapImplementation._computeLoadLimit(newCapacity);
1098 var oldKeys = this._keys;
1099 var oldValues = this._values;
1100 this._keys = new Array(newCapacity);
1101 this._values = new Array(newCapacity);
1102 for (var i = (0);
1103 i < capacity; i++) {
1104 var key = oldKeys.$index(i);
1105 if (null == key || (null == key ? null == (const$0000) : key === const$0000) ) {
1106 continue;
1107 }
1108 var value = oldValues.$index(i);
1109 var newIndex = this._probeForAdding(key);
1110 this._keys.$setindex(newIndex, key);
1111 this._values.$setindex(newIndex, value);
1112 }
1113 this._numberOfDeleted = (0);
1114 }
1115 HashMapImplementation.prototype.$setindex = function(key, value) {
1116 var $0;
1117 this._ensureCapacity();
1118 var index = this._probeForAdding(key);
1119 if ((null == this._keys.$index(index)) || ((($0 = this._keys.$index(index)) == null ? null == (const$0000) : $0 === const$0000))) {
1120 this._numberOfEntries++;
1121 }
1122 this._keys.$setindex(index, key);
1123 this._values.$setindex(index, value);
1124 }
1125 HashMapImplementation.prototype.$index = function(key) {
1126 var index = this._probeForLookup(key);
1127 if (index < (0)) return null;
1128 return this._values.$index(index);
1129 }
1130 HashMapImplementation.prototype.putIfAbsent = function(key, ifAbsent) {
1131 var index = this._probeForLookup(key);
1132 if (index >= (0)) return this._values.$index(index);
1133 var value = ifAbsent();
1134 this.$setindex(key, value);
1135 return value;
1136 }
1137 HashMapImplementation.prototype.remove = function(key) {
1138 var index = this._probeForLookup(key);
1139 if (index >= (0)) {
1140 this._numberOfEntries--;
1141 var value = this._values.$index(index);
1142 this._values.$setindex(index);
1143 this._keys.$setindex(index, const$0000);
1144 this._numberOfDeleted++;
1145 return value;
1146 }
1147 return null;
1148 }
1149 HashMapImplementation.prototype.isEmpty = function() {
1150 return this._numberOfEntries == (0);
1151 }
1152 HashMapImplementation.prototype.get$length = function() {
1153 return this._numberOfEntries;
1154 }
1155 HashMapImplementation.prototype.forEach = function(f) {
1156 var length = this._keys.get$length();
1157 for (var i = (0);
1158 i < length; i++) {
1159 var key = this._keys.$index(i);
1160 if ((null != key) && ((null == key ? null != (const$0000) : key !== const$00 00))) {
1161 f(key, this._values.$index(i));
1162 }
1163 }
1164 }
1165 HashMapImplementation.prototype.getKeys = function() {
1166 var list = new Array(this.get$length());
1167 var i = (0);
1168 this.forEach(function _(key, value) {
1169 list.$setindex(i++, key);
1170 }
1171 );
1172 return list;
1173 }
1174 HashMapImplementation.prototype.getValues = function() {
1175 var list = new Array(this.get$length());
1176 var i = (0);
1177 this.forEach(function _(key, value) {
1178 list.$setindex(i++, value);
1179 }
1180 );
1181 return list;
1182 }
1183 HashMapImplementation.prototype.containsKey = function(key) {
1184 return (this._probeForLookup(key) != (-1));
1185 }
1186 HashMapImplementation.prototype.toString = function() {
1187 return Maps.mapToString(this);
1188 }
1189 HashMapImplementation.prototype.remove$1 = HashMapImplementation.prototype.remov e;
1190 HashMapImplementation.prototype.toString$0 = HashMapImplementation.prototype.toS tring;
1191 // ********** Code for HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyV aluePair **************
1192 $inherits(HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyValuePair, Has hMapImplementation);
1193 function HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyValuePair() {
1194 this._numberOfEntries = (0);
1195 this._numberOfDeleted = (0);
1196 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1197 this._keys = new Array((8));
1198 this._values = new Array((8));
1199 }
1200 HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyValuePair.prototype.remo ve$1 = HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyValuePair.prototy pe.remove;
1201 // ********** Code for HashMapImplementation_dart_core_String$dart_core_String * *************
1202 $inherits(HashMapImplementation_dart_core_String$dart_core_String, HashMapImplem entation);
1203 function HashMapImplementation_dart_core_String$dart_core_String() {
1204 this._numberOfEntries = (0);
1205 this._numberOfDeleted = (0);
1206 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1207 this._keys = new Array((8));
1208 this._values = new Array((8));
1209 }
1210 HashMapImplementation_dart_core_String$dart_core_String.prototype.remove$1 = Has hMapImplementation_dart_core_String$dart_core_String.prototype.remove;
1211 // ********** Code for HashMapImplementation_dart_core_String$VariableValue **** **********
1212 $inherits(HashMapImplementation_dart_core_String$VariableValue, HashMapImplement ation);
1213 function HashMapImplementation_dart_core_String$VariableValue() {
1214 this._numberOfEntries = (0);
1215 this._numberOfDeleted = (0);
1216 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1217 this._keys = new Array((8));
1218 this._values = new Array((8));
1219 }
1220 HashMapImplementation_dart_core_String$VariableValue.prototype.remove$1 = HashMa pImplementation_dart_core_String$VariableValue.prototype.remove;
1221 // ********** Code for HashMapImplementation_FieldMember$Value **************
1222 $inherits(HashMapImplementation_FieldMember$Value, HashMapImplementation);
1223 function HashMapImplementation_FieldMember$Value() {
1224 this._numberOfEntries = (0);
1225 this._numberOfDeleted = (0);
1226 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1227 this._keys = new Array((8));
1228 this._values = new Array((8));
1229 }
1230 HashMapImplementation_FieldMember$Value.prototype.remove$1 = HashMapImplementati on_FieldMember$Value.prototype.remove;
1231 // ********** Code for HashMapImplementation_Library$Library **************
1232 $inherits(HashMapImplementation_Library$Library, HashMapImplementation);
1233 function HashMapImplementation_Library$Library() {
1234 this._numberOfEntries = (0);
1235 this._numberOfDeleted = (0);
1236 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1237 this._keys = new Array((8));
1238 this._values = new Array((8));
1239 }
1240 // ********** Code for HashMapImplementation_Member$Member **************
1241 $inherits(HashMapImplementation_Member$Member, HashMapImplementation);
1242 function HashMapImplementation_Member$Member() {
1243 this._numberOfEntries = (0);
1244 this._numberOfDeleted = (0);
1245 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1246 this._keys = new Array((8));
1247 this._values = new Array((8));
1248 }
1249 // ********** Code for HashMapImplementation_Type$Map_dart_core_String$bool **** **********
1250 $inherits(HashMapImplementation_Type$Map_dart_core_String$bool, HashMapImplement ation);
1251 function HashMapImplementation_Type$Map_dart_core_String$bool() {
1252 this._numberOfEntries = (0);
1253 this._numberOfDeleted = (0);
1254 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1255 this._keys = new Array((8));
1256 this._values = new Array((8));
1257 }
1258 HashMapImplementation_Type$Map_dart_core_String$bool.prototype.remove$1 = HashMa pImplementation_Type$Map_dart_core_String$bool.prototype.remove;
1259 // ********** Code for HashMapImplementation_Type$Type **************
1260 $inherits(HashMapImplementation_Type$Type, HashMapImplementation);
1261 function HashMapImplementation_Type$Type() {
1262 this._numberOfEntries = (0);
1263 this._numberOfDeleted = (0);
1264 this._loadLimit = HashMapImplementation._computeLoadLimit((8));
1265 this._keys = new Array((8));
1266 this._values = new Array((8));
1267 }
1268 // ********** Code for HashSetImplementation **************
1269 function HashSetImplementation() {
1270 this._backingMap = new HashMapImplementation();
1271 }
1272 HashSetImplementation.prototype.is$Collection = function(){return true};
1273 HashSetImplementation.HashSetImplementation$from$factory = function(other) {
1274 var set = new HashSetImplementation();
1275 for (var $$i = other.iterator(); $$i.hasNext(); ) {
1276 var e = $$i.next();
1277 set.add(e);
1278 }
1279 return set;
1280 }
1281 HashSetImplementation.prototype.add = function(value) {
1282 this._backingMap.$setindex(value, value);
1283 }
1284 HashSetImplementation.prototype.contains = function(value) {
1285 return this._backingMap.containsKey(value);
1286 }
1287 HashSetImplementation.prototype.remove = function(value) {
1288 if (!this._backingMap.containsKey(value)) return false;
1289 this._backingMap.remove(value);
1290 return true;
1291 }
1292 HashSetImplementation.prototype.addAll = function(collection) {
1293 var $this = this; // closure support
1294 collection.forEach(function _(value) {
1295 $this.add(value);
1296 }
1297 );
1298 }
1299 HashSetImplementation.prototype.forEach = function(f) {
1300 this._backingMap.forEach(function _(key, value) {
1301 f(key);
1302 }
1303 );
1304 }
1305 HashSetImplementation.prototype.map = function(f) {
1306 var result = new HashSetImplementation();
1307 this._backingMap.forEach(function _(key, value) {
1308 result.add(f(key));
1309 }
1310 );
1311 return result;
1312 }
1313 HashSetImplementation.prototype.filter = function(f) {
1314 var result = new HashSetImplementation();
1315 this._backingMap.forEach(function _(key, value) {
1316 if (f(key)) result.add(key);
1317 }
1318 );
1319 return result;
1320 }
1321 HashSetImplementation.prototype.every = function(f) {
1322 var keys = this._backingMap.getKeys();
1323 return keys.every(f);
1324 }
1325 HashSetImplementation.prototype.some = function(f) {
1326 var keys = this._backingMap.getKeys();
1327 return keys.some(f);
1328 }
1329 HashSetImplementation.prototype.isEmpty = function() {
1330 return this._backingMap.isEmpty();
1331 }
1332 HashSetImplementation.prototype.get$length = function() {
1333 return this._backingMap.get$length();
1334 }
1335 HashSetImplementation.prototype.iterator = function() {
1336 return new HashSetIterator(this);
1337 }
1338 HashSetImplementation.prototype.toString = function() {
1339 return Collections.collectionToString(this);
1340 }
1341 HashSetImplementation.prototype.contains$1 = HashSetImplementation.prototype.con tains;
1342 HashSetImplementation.prototype.remove$1 = HashSetImplementation.prototype.remov e;
1343 HashSetImplementation.prototype.toString$0 = HashSetImplementation.prototype.toS tring;
1344 // ********** Code for HashSetImplementation_dart_core_String **************
1345 $inherits(HashSetImplementation_dart_core_String, HashSetImplementation);
1346 function HashSetImplementation_dart_core_String() {
1347 this._backingMap = new HashMapImplementation_dart_core_String$dart_core_String ();
1348 }
1349 HashSetImplementation_dart_core_String.prototype.contains$1 = HashSetImplementat ion_dart_core_String.prototype.contains;
1350 // ********** Code for HashSetImplementation_Library **************
1351 $inherits(HashSetImplementation_Library, HashSetImplementation);
1352 function HashSetImplementation_Library() {
1353 this._backingMap = new HashMapImplementation_Library$Library();
1354 }
1355 // ********** Code for HashSetImplementation_Member **************
1356 $inherits(HashSetImplementation_Member, HashSetImplementation);
1357 function HashSetImplementation_Member() {
1358 this._backingMap = new HashMapImplementation_Member$Member();
1359 }
1360 // ********** Code for HashSetImplementation_Type **************
1361 $inherits(HashSetImplementation_Type, HashSetImplementation);
1362 function HashSetImplementation_Type() {
1363 this._backingMap = new HashMapImplementation_Type$Type();
1364 }
1365 HashSetImplementation_Type.prototype.contains$1 = HashSetImplementation_Type.pro totype.contains;
1366 // ********** Code for HashSetIterator **************
1367 function HashSetIterator(set_) {
1368 this._nextValidIndex = (-1);
1369 this._entries = set_._backingMap._keys;
1370 this._advance();
1371 }
1372 HashSetIterator.prototype.hasNext = function() {
1373 var $0;
1374 if (this._nextValidIndex >= this._entries.get$length()) return false;
1375 if ((($0 = this._entries.$index(this._nextValidIndex)) == null ? null == (cons t$0000) : $0 === const$0000)) {
1376 this._advance();
1377 }
1378 return this._nextValidIndex < this._entries.get$length();
1379 }
1380 HashSetIterator.prototype.next = function() {
1381 if (!this.hasNext()) {
1382 $throw(const$0001);
1383 }
1384 var res = this._entries.$index(this._nextValidIndex);
1385 this._advance();
1386 return res;
1387 }
1388 HashSetIterator.prototype._advance = function() {
1389 var length = this._entries.get$length();
1390 var entry;
1391 var deletedKey = const$0000;
1392 do {
1393 if (++this._nextValidIndex >= length) break;
1394 entry = this._entries.$index(this._nextValidIndex);
1395 }
1396 while ((null == entry) || ((null == entry ? null == (deletedKey) : entry === d eletedKey)))
1397 }
1398 // ********** Code for _DeletedKeySentinel **************
1399 function _DeletedKeySentinel() {
1400
1401 }
1402 // ********** Code for KeyValuePair **************
1403 function KeyValuePair(key, value) {
1404 this.key = key;
1405 this.value = value;
1406 }
1407 KeyValuePair.prototype.get$value = function() { return this.value; };
1408 KeyValuePair.prototype.set$value = function(value) { return this.value = value; };
1409 // ********** Code for LinkedHashMapImplementation **************
1410 function LinkedHashMapImplementation() {
1411 this._map = new HashMapImplementation_Dynamic$DoubleLinkedQueueEntry_KeyValueP air();
1412 this._list = new DoubleLinkedQueue_KeyValuePair();
1413 }
1414 LinkedHashMapImplementation.prototype.is$Map = function(){return true};
1415 LinkedHashMapImplementation.prototype.$setindex = function(key, value) {
1416 if (this._map.containsKey(key)) {
1417 this._map.$index(key).get$element().set$value(value);
1418 }
1419 else {
1420 this._list.addLast(new KeyValuePair(key, value));
1421 this._map.$setindex(key, this._list.lastEntry());
1422 }
1423 }
1424 LinkedHashMapImplementation.prototype.$index = function(key) {
1425 var entry = this._map.$index(key);
1426 if (null == entry) return null;
1427 return entry.get$element().get$value();
1428 }
1429 LinkedHashMapImplementation.prototype.remove = function(key) {
1430 var entry = this._map.remove(key);
1431 if (null == entry) return null;
1432 entry.remove();
1433 return entry.get$element().get$value();
1434 }
1435 LinkedHashMapImplementation.prototype.putIfAbsent = function(key, ifAbsent) {
1436 var value = this.$index(key);
1437 if ((null == this.$index(key)) && !(this.containsKey(key))) {
1438 value = ifAbsent();
1439 this.$setindex(key, value);
1440 }
1441 return value;
1442 }
1443 LinkedHashMapImplementation.prototype.getKeys = function() {
1444 var list = new Array(this.get$length());
1445 var index = (0);
1446 this._list.forEach(function _(entry) {
1447 list.$setindex(index++, entry.key);
1448 }
1449 );
1450 return list;
1451 }
1452 LinkedHashMapImplementation.prototype.getValues = function() {
1453 var list = new Array(this.get$length());
1454 var index = (0);
1455 this._list.forEach(function _(entry) {
1456 list.$setindex(index++, entry.value);
1457 }
1458 );
1459 return list;
1460 }
1461 LinkedHashMapImplementation.prototype.forEach = function(f) {
1462 this._list.forEach(function _(entry) {
1463 f(entry.key, entry.value);
1464 }
1465 );
1466 }
1467 LinkedHashMapImplementation.prototype.containsKey = function(key) {
1468 return this._map.containsKey(key);
1469 }
1470 LinkedHashMapImplementation.prototype.get$length = function() {
1471 return this._map.get$length();
1472 }
1473 LinkedHashMapImplementation.prototype.isEmpty = function() {
1474 return this.get$length() == (0);
1475 }
1476 LinkedHashMapImplementation.prototype.toString = function() {
1477 return Maps.mapToString(this);
1478 }
1479 LinkedHashMapImplementation.prototype.remove$1 = LinkedHashMapImplementation.pro totype.remove;
1480 LinkedHashMapImplementation.prototype.toString$0 = LinkedHashMapImplementation.p rototype.toString;
1481 // ********** Code for Maps **************
1482 function Maps() {}
1483 Maps.mapToString = function(m) {
1484 var result = new StringBufferImpl("");
1485 Maps._emitMap(m, result, new Array());
1486 return result.toString$0();
1487 }
1488 Maps._emitMap = function(m, result, visiting) {
1489 visiting.add(m);
1490 result.add("{");
1491 var first = true;
1492 m.forEach((function (k, v) {
1493 if (!first) {
1494 result.add(", ");
1495 }
1496 first = false;
1497 Collections._emitObject(k, result, visiting);
1498 result.add(": ");
1499 Collections._emitObject(v, result, visiting);
1500 })
1501 );
1502 result.add("}");
1503 visiting.removeLast();
1504 }
1505 // ********** Code for DoubleLinkedQueueEntry **************
1506 function DoubleLinkedQueueEntry(e) {
1507 this._element = e;
1508 }
1509 DoubleLinkedQueueEntry.prototype._link = function(p, n) {
1510 this._next = n;
1511 this._previous = p;
1512 p._next = this;
1513 n._previous = this;
1514 }
1515 DoubleLinkedQueueEntry.prototype.prepend = function(e) {
1516 new DoubleLinkedQueueEntry(e)._link(this._previous, this);
1517 }
1518 DoubleLinkedQueueEntry.prototype.remove = function() {
1519 this._previous._next = this._next;
1520 this._next._previous = this._previous;
1521 this._next = null;
1522 this._previous = null;
1523 return this._element;
1524 }
1525 DoubleLinkedQueueEntry.prototype._asNonSentinelEntry = function() {
1526 return this;
1527 }
1528 DoubleLinkedQueueEntry.prototype.previousEntry = function() {
1529 return this._previous._asNonSentinelEntry();
1530 }
1531 DoubleLinkedQueueEntry.prototype.get$element = function() {
1532 return this._element;
1533 }
1534 // ********** Code for DoubleLinkedQueueEntry_KeyValuePair **************
1535 $inherits(DoubleLinkedQueueEntry_KeyValuePair, DoubleLinkedQueueEntry);
1536 function DoubleLinkedQueueEntry_KeyValuePair(e) {
1537 this._element = e;
1538 }
1539 // ********** Code for _DoubleLinkedQueueEntrySentinel **************
1540 $inherits(_DoubleLinkedQueueEntrySentinel, DoubleLinkedQueueEntry);
1541 function _DoubleLinkedQueueEntrySentinel() {
1542 DoubleLinkedQueueEntry.call(this, null);
1543 this._link(this, this);
1544 }
1545 _DoubleLinkedQueueEntrySentinel.prototype.remove = function() {
1546 $throw(const$0002);
1547 }
1548 _DoubleLinkedQueueEntrySentinel.prototype._asNonSentinelEntry = function() {
1549 return null;
1550 }
1551 _DoubleLinkedQueueEntrySentinel.prototype.get$element = function() {
1552 $throw(const$0002);
1553 }
1554 // ********** Code for _DoubleLinkedQueueEntrySentinel_KeyValuePair ************ **
1555 $inherits(_DoubleLinkedQueueEntrySentinel_KeyValuePair, _DoubleLinkedQueueEntryS entinel);
1556 function _DoubleLinkedQueueEntrySentinel_KeyValuePair() {
1557 DoubleLinkedQueueEntry_KeyValuePair.call(this, null);
1558 this._link(this, this);
1559 }
1560 // ********** Code for DoubleLinkedQueue **************
1561 function DoubleLinkedQueue() {
1562 this._sentinel = new _DoubleLinkedQueueEntrySentinel();
1563 }
1564 DoubleLinkedQueue.prototype.is$Collection = function(){return true};
1565 DoubleLinkedQueue.DoubleLinkedQueue$from$factory = function(other) {
1566 var list = new DoubleLinkedQueue();
1567 for (var $$i = other.iterator(); $$i.hasNext(); ) {
1568 var e = $$i.next();
1569 list.addLast(e);
1570 }
1571 return list;
1572 }
1573 DoubleLinkedQueue.prototype.addLast = function(value) {
1574 this._sentinel.prepend(value);
1575 }
1576 DoubleLinkedQueue.prototype.add = function(value) {
1577 this.addLast(value);
1578 }
1579 DoubleLinkedQueue.prototype.addAll = function(collection) {
1580 for (var $$i = collection.iterator(); $$i.hasNext(); ) {
1581 var e = $$i.next();
1582 this.add(e);
1583 }
1584 }
1585 DoubleLinkedQueue.prototype.removeLast = function() {
1586 return this._sentinel._previous.remove();
1587 }
1588 DoubleLinkedQueue.prototype.removeFirst = function() {
1589 return this._sentinel._next.remove();
1590 }
1591 DoubleLinkedQueue.prototype.last = function() {
1592 return this._sentinel._previous.get$element();
1593 }
1594 DoubleLinkedQueue.prototype.lastEntry = function() {
1595 return this._sentinel.previousEntry();
1596 }
1597 DoubleLinkedQueue.prototype.get$length = function() {
1598 var counter = (0);
1599 this.forEach(function _(element) {
1600 counter++;
1601 }
1602 );
1603 return counter;
1604 }
1605 DoubleLinkedQueue.prototype.isEmpty = function() {
1606 var $0;
1607 return ((($0 = this._sentinel._next) == null ? null == (this._sentinel) : $0 = == this._sentinel));
1608 }
1609 DoubleLinkedQueue.prototype.forEach = function(f) {
1610 var entry = this._sentinel._next;
1611 while ((null == entry ? null != (this._sentinel) : entry !== this._sentinel)) {
1612 var nextEntry = entry._next;
1613 f(entry._element);
1614 entry = nextEntry;
1615 }
1616 }
1617 DoubleLinkedQueue.prototype.every = function(f) {
1618 var entry = this._sentinel._next;
1619 while ((null == entry ? null != (this._sentinel) : entry !== this._sentinel)) {
1620 var nextEntry = entry._next;
1621 if (!f(entry._element)) return false;
1622 entry = nextEntry;
1623 }
1624 return true;
1625 }
1626 DoubleLinkedQueue.prototype.some = function(f) {
1627 var entry = this._sentinel._next;
1628 while ((null == entry ? null != (this._sentinel) : entry !== this._sentinel)) {
1629 var nextEntry = entry._next;
1630 if (f(entry._element)) return true;
1631 entry = nextEntry;
1632 }
1633 return false;
1634 }
1635 DoubleLinkedQueue.prototype.map = function(f) {
1636 var other = new DoubleLinkedQueue();
1637 var entry = this._sentinel._next;
1638 while ((null == entry ? null != (this._sentinel) : entry !== this._sentinel)) {
1639 var nextEntry = entry._next;
1640 other.addLast(f(entry._element));
1641 entry = nextEntry;
1642 }
1643 return other;
1644 }
1645 DoubleLinkedQueue.prototype.filter = function(f) {
1646 var other = new DoubleLinkedQueue();
1647 var entry = this._sentinel._next;
1648 while ((null == entry ? null != (this._sentinel) : entry !== this._sentinel)) {
1649 var nextEntry = entry._next;
1650 if (f(entry._element)) other.addLast(entry._element);
1651 entry = nextEntry;
1652 }
1653 return other;
1654 }
1655 DoubleLinkedQueue.prototype.iterator = function() {
1656 return new _DoubleLinkedQueueIterator(this._sentinel);
1657 }
1658 DoubleLinkedQueue.prototype.toString = function() {
1659 return Collections.collectionToString(this);
1660 }
1661 DoubleLinkedQueue.prototype.toString$0 = DoubleLinkedQueue.prototype.toString;
1662 // ********** Code for DoubleLinkedQueue_KeyValuePair **************
1663 $inherits(DoubleLinkedQueue_KeyValuePair, DoubleLinkedQueue);
1664 function DoubleLinkedQueue_KeyValuePair() {
1665 this._sentinel = new _DoubleLinkedQueueEntrySentinel_KeyValuePair();
1666 }
1667 // ********** Code for _DoubleLinkedQueueIterator **************
1668 function _DoubleLinkedQueueIterator(_sentinel) {
1669 this._sentinel = _sentinel;
1670 this._currentEntry = this._sentinel;
1671 }
1672 _DoubleLinkedQueueIterator.prototype.hasNext = function() {
1673 var $0;
1674 return (($0 = this._currentEntry._next) == null ? null != (this._sentinel) : $ 0 !== this._sentinel);
1675 }
1676 _DoubleLinkedQueueIterator.prototype.next = function() {
1677 if (!this.hasNext()) {
1678 $throw(const$0001);
1679 }
1680 this._currentEntry = this._currentEntry._next;
1681 return this._currentEntry.get$element();
1682 }
1683 // ********** Code for StopwatchImplementation **************
1684 function StopwatchImplementation() {
1685 this._start = null;
1686 this._stop = null;
1687 }
1688 StopwatchImplementation.prototype.start = function() {
1689 if (null == this._start) {
1690 this._start = Clock.now();
1691 }
1692 else {
1693 if (null == this._stop) {
1694 return;
1695 }
1696 this._start = Clock.now() - (this._stop - this._start);
1697 this._stop = null;
1698 }
1699 }
1700 StopwatchImplementation.prototype.get$start = function() {
1701 return this.start.bind(this);
1702 }
1703 StopwatchImplementation.prototype.stop = function() {
1704 if (null == this._start || null != this._stop) {
1705 return;
1706 }
1707 this._stop = Clock.now();
1708 }
1709 StopwatchImplementation.prototype.elapsed = function() {
1710 if (null == this._start) {
1711 return (0);
1712 }
1713 return (null == this._stop) ? (Clock.now() - this._start) : (this._stop - this ._start);
1714 }
1715 StopwatchImplementation.prototype.elapsedInMs = function() {
1716 return $truncdiv$((this.elapsed() * (1000)), this.frequency());
1717 }
1718 StopwatchImplementation.prototype.frequency = function() {
1719 return Clock.frequency();
1720 }
1721 // ********** Code for StringBufferImpl **************
1722 function StringBufferImpl(content) {
1723 this.clear();
1724 this.add(content);
1725 }
1726 StringBufferImpl.prototype.get$length = function() {
1727 return this._length;
1728 }
1729 StringBufferImpl.prototype.isEmpty = function() {
1730 return this._length == (0);
1731 }
1732 StringBufferImpl.prototype.add = function(obj) {
1733 var str = obj.toString$0();
1734 if (null == str || str.isEmpty()) return this;
1735 this._buffer.add(str);
1736 this._length = this._length + str.length;
1737 return this;
1738 }
1739 StringBufferImpl.prototype.addAll = function(objects) {
1740 for (var $$i = objects.iterator(); $$i.hasNext(); ) {
1741 var obj = $$i.next();
1742 this.add(obj);
1743 }
1744 return this;
1745 }
1746 StringBufferImpl.prototype.clear = function() {
1747 this._buffer = new Array();
1748 this._length = (0);
1749 return this;
1750 }
1751 StringBufferImpl.prototype.toString = function() {
1752 if (this._buffer.get$length() == (0)) return "";
1753 if (this._buffer.get$length() == (1)) return this._buffer.$index((0));
1754 var result = StringBase.concatAll(this._buffer);
1755 this._buffer.clear();
1756 this._buffer.add(result);
1757 return result;
1758 }
1759 StringBufferImpl.prototype.toString$0 = StringBufferImpl.prototype.toString;
1760 // ********** Code for StringBase **************
1761 function StringBase() {}
1762 StringBase.createFromCharCodes = function(charCodes) {
1763 if (Object.getPrototypeOf(charCodes) !== Array.prototype) {
1764 charCodes = new ListFactory.ListFactory$from$factory(charCodes);
1765 }
1766 return String.fromCharCode.apply(null, charCodes);
1767 }
1768 StringBase.join = function(strings, separator) {
1769 if (strings.get$length() == (0)) return "";
1770 var s = strings.$index((0));
1771 for (var i = (1);
1772 i < strings.get$length(); i++) {
1773 s = $add$($add$(s, separator), strings.$index(i));
1774 }
1775 return s;
1776 }
1777 StringBase.concatAll = function(strings) {
1778 return StringBase.join(strings, "");
1779 }
1780 // ********** Code for StringImplementation **************
1781 StringImplementation = String;
1782 StringImplementation.prototype.get$length = function() { return this.length; };
1783 StringImplementation.prototype.endsWith = function(other) {
1784 'use strict';
1785 if (other.length > this.length) return false;
1786 return other == this.substring(this.length - other.length);
1787 }
1788 StringImplementation.prototype.startsWith = function(other) {
1789 'use strict';
1790 if (other.length > this.length) return false;
1791 return other == this.substring(0, other.length);
1792 }
1793 StringImplementation.prototype.isEmpty = function() {
1794 return this.length == (0);
1795 }
1796 StringImplementation.prototype.contains = function(pattern, startIndex) {
1797 'use strict'; return this.indexOf(pattern, startIndex) >= 0;
1798 }
1799 StringImplementation.prototype._replaceRegExp = function(from, to) {
1800 'use strict';return this.replace(from.re, to);
1801 }
1802 StringImplementation.prototype._replaceAll = function(from, to) {
1803 'use strict';
1804 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g');
1805 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun!
1806 return this.replace(from, to);
1807 }
1808 StringImplementation.prototype.replaceAll = function(from, to) {
1809 if ((typeof(from) == 'string')) return this._replaceAll(from, to);
1810 if (!!(from && from.is$RegExp())) return this._replaceRegExp(from.get$dynamic( ).get$_global(), to);
1811 var buffer = new StringBufferImpl("");
1812 var lastMatchEnd = (0);
1813 var $$list = from.allMatches(this);
1814 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
1815 var match = $$i.next();
1816 buffer.add(this.substring(lastMatchEnd, match.start()));
1817 buffer.add(to);
1818 lastMatchEnd = match.end$0();
1819 }
1820 buffer.add(this.substring(lastMatchEnd));
1821 }
1822 StringImplementation.prototype.split$_ = function(pattern) {
1823 if ((typeof(pattern) == 'string')) return this._split(pattern);
1824 if (!!(pattern && pattern.is$RegExp())) return this._splitRegExp(pattern);
1825 $throw("String.split(Pattern) unimplemented.");
1826 }
1827 StringImplementation.prototype._split = function(pattern) {
1828 'use strict'; return this.split(pattern);
1829 }
1830 StringImplementation.prototype._splitRegExp = function(pattern) {
1831 'use strict'; return this.split(pattern.re);
1832 }
1833 StringImplementation.prototype.allMatches = function(str) {
1834 $throw("String.allMatches(String str) unimplemented.");
1835 }
1836 StringImplementation.prototype.hashCode = function() {
1837 'use strict';
1838 var hash = 0;
1839 for (var i = 0; i < this.length; i++) {
1840 hash = 0x1fffffff & (hash + this.charCodeAt(i));
1841 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
1842 hash ^= hash >> 6;
1843 }
1844
1845 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
1846 hash ^= hash >> 11;
1847 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
1848 }
1849 StringImplementation.prototype.compareTo = function(other) {
1850 'use strict'; return this == other ? 0 : this < other ? -1 : 1;
1851 }
1852 StringImplementation.prototype.contains$1 = StringImplementation.prototype.conta ins;
1853 StringImplementation.prototype.indexOf$1 = StringImplementation.prototype.indexO f;
1854 StringImplementation.prototype.substring$1 = StringImplementation.prototype.subs tring;
1855 // ********** Code for _ArgumentMismatchException **************
1856 $inherits(_ArgumentMismatchException, ClosureArgumentMismatchException);
1857 function _ArgumentMismatchException(_message) {
1858 this._dart_coreimpl_message = _message;
1859 ClosureArgumentMismatchException.call(this);
1860 }
1861 _ArgumentMismatchException.prototype.toString = function() {
1862 return ("Closure argument mismatch: " + this._dart_coreimpl_message);
1863 }
1864 _ArgumentMismatchException.prototype.toString$0 = _ArgumentMismatchException.pro totype.toString;
1865 // ********** Code for _FunctionImplementation **************
1866 _FunctionImplementation = Function;
1867 _FunctionImplementation.prototype._genStub = function(argsLength, names) {
1868 // Fast path #1: if no named arguments and arg count matches.
1869 var thisLength = this.$length || this.length;
1870 if (thisLength == argsLength && !names) {
1871 return this;
1872 }
1873
1874 var paramsNamed = this.$optional ? (this.$optional.length / 2) : 0;
1875 var paramsBare = thisLength - paramsNamed;
1876 var argsNamed = names ? names.length : 0;
1877 var argsBare = argsLength - argsNamed;
1878
1879 // Check we got the right number of arguments
1880 if (argsBare < paramsBare || argsLength > thisLength ||
1881 argsNamed > paramsNamed) {
1882 return function() {
1883 $throw(new _ArgumentMismatchException(
1884 'Wrong number of arguments to function. Expected ' + paramsBare +
1885 ' positional arguments and at most ' + paramsNamed +
1886 ' named arguments, but got ' + argsBare +
1887 ' positional arguments and ' + argsNamed + ' named arguments.'));
1888 };
1889 }
1890
1891 // First, fill in all of the default values
1892 var p = new Array(paramsBare);
1893 if (paramsNamed) {
1894 p = p.concat(this.$optional.slice(paramsNamed));
1895 }
1896 // Fill in positional args
1897 var a = new Array(argsLength);
1898 for (var i = 0; i < argsBare; i++) {
1899 p[i] = a[i] = '$' + i;
1900 }
1901 // Then overwrite with supplied values for optional args
1902 var lastParameterIndex;
1903 var namesInOrder = true;
1904 for (var i = 0; i < argsNamed; i++) {
1905 var name = names[i];
1906 a[i + argsBare] = name;
1907 var j = this.$optional.indexOf(name);
1908 if (j < 0 || j >= paramsNamed) {
1909 return function() {
1910 $throw(new _ArgumentMismatchException(
1911 'Named argument "' + name + '" was not expected by function.' +
1912 ' Did you forget to mark the function parameter [optional]?'));
1913 };
1914 } else if (lastParameterIndex && lastParameterIndex > j) {
1915 namesInOrder = false;
1916 }
1917 p[j + paramsBare] = name;
1918 lastParameterIndex = j;
1919 }
1920
1921 if (thisLength == argsLength && namesInOrder) {
1922 // Fast path #2: named arguments, but they're in order and all supplied.
1923 return this;
1924 }
1925
1926 // Note: using Function instead of 'eval' to get a clean scope.
1927 // TODO(jmesserly): evaluate the performance of these stubs.
1928 var f = 'function(' + a.join(',') + '){return $f(' + p.join(',') + ');}';
1929 return new Function('$f', 'return ' + f + '').call(null, this);
1930
1931 }
1932 // ********** Code for top level **************
1933 function _constList(other) {
1934 other.__proto__ = ImmutableList.prototype;
1935 return other;
1936 }
1937 function _map(itemsAndKeys) {
1938 var ret = new LinkedHashMapImplementation();
1939 for (var i = (0);
1940 i < itemsAndKeys.get$length(); ) {
1941 ret.$setindex(itemsAndKeys.$index(i++), itemsAndKeys.$index(i++));
1942 }
1943 return ret;
1944 }
1945 // ********** Library node **************
1946 // ********** Code for Process **************
1947 function Process(_process) {
1948 this.SIGHUP = "SIGHUP";
1949 this.SIGINT = "SIGINT";
1950 this.SIGQUIT = "SIGQUIT";
1951 this.SIGILL = "SIGILL";
1952 this.SIGTRAP = "SIGTRAP";
1953 this.SIGABRT = "SIGABRT";
1954 this.SIGEMT = "SIGEMT";
1955 this.SIGFPE = "SIGFPE";
1956 this.SIGKILL = "SIGKILL";
1957 this.SIGBUS = "SIGBUS";
1958 this.SIGSEGV = "SIGSEGV";
1959 this.SIGSYS = "SIGSYS";
1960 this.SIGPIPE = "SIGPIPE";
1961 this.SIGALRM = "SIGALRM";
1962 this.SIGTERM = "SIGTERM";
1963 this.SIGURG = "SIGURG";
1964 this.SIGSTOP = "SIGSTOP";
1965 this.SIGTSTP = "SIGTSTP";
1966 this.SIGCONT = "SIGCONT";
1967 this.SIGCHLD = "SIGCHLD";
1968 this.SIGTTIN = "SIGTTIN";
1969 this.SIGTTOU = "SIGTTOU";
1970 this.SIGIO = "SIGIO";
1971 this.SIGXCPU = "SIGXCPU";
1972 this.SIGXFSZ = "SIGXFSZ";
1973 this.SIGVTALRM = "SIGVTALRM";
1974 this.SIGPROF = "SIGPROF";
1975 this.SIGWINCH = "SIGWINCH";
1976 this.SIGINFO = "SIGINFO";
1977 this.SIGUSR1 = "SIGUSR1";
1978 this.SIGUSR2 = "SIGUSR2";
1979 this._process = _process;
1980 }
1981 Process.prototype.get$argv = function() {
1982 return this._process.argv;
1983 }
1984 Process.prototype.set$argv = function(value) {
1985 this._process.argv = value;
1986 }
1987 Process.prototype.get$env = function() {
1988 return new EnvMap(this._process);
1989 }
1990 Process.prototype.exit = function(code) {
1991 this._process.exit(code);
1992 }
1993 // ********** Code for EnvMap **************
1994 function EnvMap(_process) {
1995 this._process = _process;
1996 }
1997 EnvMap.prototype.$index = function(key) {
1998 return this._process.env[key];
1999 }
2000 // ********** Code for ReadableStream **************
2001 // ********** Code for WritableStream **************
2002 $dynamic("end$0").WriteStream = function() {
2003 return this.end(null, "utf8");
2004 };
2005 $dynamic("write$1").WriteStream = function($0) {
2006 return this.write($0, "utf8");
2007 };
2008 // ********** Code for vm **************
2009 vm = require('vm');
2010 // ********** Code for fs **************
2011 fs = require('fs');
2012 // ********** Code for path **************
2013 path = require('path');
2014 // ********** Code for top level **************
2015 function createSandbox() {
2016 return {'require': require, 'process': process, 'console': console,
2017 'Buffer' : Buffer,
2018 'setTimeout$': this.setTimeout, 'clearTimeout': clearTimeout};
2019 }
2020 function get$$_process() {
2021 return process;
2022 }
2023 function get$$process() {
2024 return new Process(get$$_process());
2025 }
2026 // ********** Library file_system **************
2027 // ********** Code for top level **************
2028 function canonicalizePath(path) {
2029 return path.replaceAll("\\", "/");
2030 }
2031 function joinPaths(path1, path2) {
2032 path1 = canonicalizePath(path1);
2033 path2 = canonicalizePath(path2);
2034 var pieces = path1.split$_("/");
2035 var $$list = path2.split$_("/");
2036 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2037 var piece = $$i.next();
2038 if ($eq$(piece, "..") && pieces.get$length() > (0) && $ne$(pieces.last(), ". ") && $ne$(pieces.last(), "..")) {
2039 pieces.removeLast();
2040 }
2041 else if ($ne$(piece, "")) {
2042 if (pieces.get$length() > (0) && $eq$(pieces.last(), ".")) {
2043 pieces.removeLast();
2044 }
2045 pieces.add(piece);
2046 }
2047 }
2048 return Strings.join(pieces, "/");
2049 }
2050 function dirname(path) {
2051 path = canonicalizePath(path);
2052 var lastSlash = path.lastIndexOf("/", path.length);
2053 if (lastSlash == (-1)) {
2054 return ".";
2055 }
2056 else {
2057 return path.substring((0), lastSlash);
2058 }
2059 }
2060 function basename(path) {
2061 path = canonicalizePath(path);
2062 var lastSlash = path.lastIndexOf("/", path.length);
2063 if (lastSlash == (-1)) {
2064 return path;
2065 }
2066 else {
2067 return path.substring(lastSlash + (1));
2068 }
2069 }
2070 // ********** Library file_system_node **************
2071 // ********** Code for NodeFileSystem **************
2072 function NodeFileSystem() {
2073
2074 }
2075 NodeFileSystem.prototype.writeString = function(outfile, text) {
2076 fs.writeFileSync(outfile, text);
2077 }
2078 NodeFileSystem.prototype.readAll = function(filename) {
2079 return fs.readFileSync(filename, "utf8");
2080 }
2081 NodeFileSystem.prototype.fileExists = function(filename) {
2082 return path.existsSync(filename);
2083 }
2084 // ********** Code for top level **************
2085 // ********** Library lang **************
2086 // ********** Code for MethodAnalyzer **************
2087 function MethodAnalyzer(method, body) {
2088 this.hasTypeParams = false;
2089 this.method = method;
2090 this.body = body;
2091 }
2092 MethodAnalyzer.prototype.get$method = function() { return this.method; };
2093 MethodAnalyzer.prototype.get$body = function() { return this.body; };
2094 MethodAnalyzer.prototype.get$hasTypeParams = function() { return this.hasTypePar ams; };
2095 MethodAnalyzer.prototype.analyze = function(context) {
2096 var thisValue;
2097 if (context != null) {
2098 thisValue = context.thisValue;
2099 }
2100 else {
2101 thisValue = new PureStaticValue(this.method.declaringType, null, false, fals e);
2102 }
2103 var values = [];
2104 var $$list = this.method.parameters;
2105 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2106 var p = $$i.next();
2107 values.add(new PureStaticValue(p.get$type(), null, false, false));
2108 }
2109 var args = new Arguments(null, values);
2110 this._frame = new CallFrame(this, this.method, thisValue, args, context);
2111 this._bindArguments(this._frame.args);
2112 var declaredInitializers = this.method.definition.get$dynamic().get$initialize rs();
2113 if ($ne$(declaredInitializers)) {
2114 for (var $$i = declaredInitializers.iterator(); $$i.hasNext(); ) {
2115 var init = $$i.next();
2116 if ((init instanceof CallExpression)) {
2117 this.visitCallExpression(init, true);
2118 }
2119 }
2120 }
2121 if (this.body != null) this.body.visit(this);
2122 }
2123 MethodAnalyzer.prototype._hasTypeParams = function(node) {
2124 if ((node instanceof NameTypeReference)) {
2125 var name = node.get$name().get$name();
2126 return (this.method.declaringType.lookupTypeParam(name) != null);
2127 }
2128 else if ((node instanceof GenericTypeReference)) {
2129 var $$list = node.get$typeArguments();
2130 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2131 var typeArg = $$i.next();
2132 if (this._hasTypeParams(typeArg)) return true;
2133 }
2134 return false;
2135 }
2136 else {
2137 return false;
2138 }
2139 }
2140 MethodAnalyzer.prototype.resolveType = function(node, typeErrors, allowTypeParam s) {
2141 if (!this.hasTypeParams && this._hasTypeParams(node)) {
2142 this.hasTypeParams = true;
2143 }
2144 return this.method.resolveType(node, typeErrors, allowTypeParams);
2145 }
2146 MethodAnalyzer.prototype.makeNeutral = function(inValue, span) {
2147 return new PureStaticValue(inValue.get$type(), span, false, false);
2148 }
2149 MethodAnalyzer.prototype._bindArguments = function(args) {
2150 for (var i = (0);
2151 i < this.method.parameters.get$length(); i++) {
2152 var p = this.method.parameters.$index(i);
2153 var currentArg = null;
2154 if (i < args.get$bareCount()) {
2155 currentArg = args.values.$index(i);
2156 }
2157 else {
2158 currentArg = args.getValue(p.get$name());
2159 if (null == currentArg) {
2160 p.genValue(this.method, this._frame);
2161 if (null == p.get$value()) {
2162 $globals.world.warning("missing argument at call - does not match");
2163 }
2164 currentArg = p.get$value();
2165 }
2166 }
2167 currentArg = this.makeNeutral(currentArg, p.get$definition().get$span());
2168 this._frame.declareParameter(p, currentArg);
2169 }
2170 }
2171 MethodAnalyzer.prototype.visitBool = function(node) {
2172 return this.visitTypedValue(node, $globals.world.boolType);
2173 }
2174 MethodAnalyzer.prototype.visitValue = function(node) {
2175 if (node == null) return null;
2176 var value = node.visit(this);
2177 value.checkFirstClass(node.span);
2178 return value;
2179 }
2180 MethodAnalyzer.prototype.visitTypedValue = function(node, expectedType) {
2181 var val = this.visitValue(node);
2182 return null == val ? null : val.convertTo(this._frame, expectedType);
2183 }
2184 MethodAnalyzer.prototype.visitVoid = function(node) {
2185 return this.visitValue(node);
2186 }
2187 MethodAnalyzer.prototype._visitArgs = function(arguments) {
2188 var args = [];
2189 var seenLabel = false;
2190 for (var $$i = arguments.iterator(); $$i.hasNext(); ) {
2191 var arg = $$i.next();
2192 if (arg.get$label() != null) {
2193 seenLabel = true;
2194 }
2195 else if (seenLabel) {
2196 $globals.world.error("bare argument cannot follow named arguments", arg.ge t$span());
2197 }
2198 args.add(this.visitValue(arg.get$value()));
2199 }
2200 return new Arguments(arguments, args);
2201 }
2202 MethodAnalyzer.prototype._makeLambdaMethod = function(name, func) {
2203 var meth = new MethodMember.lambda$ctor(name, this.method.declaringType, func) ;
2204 meth.set$enclosingElement(this.method);
2205 meth.set$_methodData(new MethodData(meth, this._frame));
2206 meth.resolve();
2207 return meth;
2208 }
2209 MethodAnalyzer.prototype._pushBlock = function(node) {
2210 this._frame.pushBlock(node);
2211 }
2212 MethodAnalyzer.prototype._popBlock = function(node) {
2213 this._frame.popBlock(node);
2214 }
2215 MethodAnalyzer.prototype._resolveBare = function(name, node) {
2216 var type = this._frame.method.declaringType;
2217 var member = type.getMember(name);
2218 if ($eq$(member) || $ne$(member.get$declaringType(), type)) {
2219 var libMember = this._frame.get$library().lookup(name, node.span);
2220 if (null != libMember) return libMember;
2221 }
2222 if (null != member && !member.get$isStatic() && this._frame.get$isStatic()) {
2223 $globals.world.error("cannot refer to instance member from static method", n ode.span);
2224 }
2225 return member;
2226 }
2227 MethodAnalyzer.prototype.visitDietStatement = function(node) {
2228 var parser = new Parser(node.span.file, false, false, false, node.span.start);
2229 parser.block().visit(this);
2230 }
2231 MethodAnalyzer.prototype.visitVariableDefinition = function(node) {
2232 var isFinal = false;
2233 if (node.modifiers != null && node.modifiers.$index((0)).kind == (99)) {
2234 isFinal = true;
2235 }
2236 var type = this.resolveType(node.type, false, true);
2237 for (var i = (0);
2238 i < node.names.get$length(); i++) {
2239 var name = node.names.$index(i).name;
2240 var value = this.visitValue(node.values.$index(i));
2241 this._frame.create(name, type, node.names.$index(i), isFinal, value);
2242 }
2243 }
2244 MethodAnalyzer.prototype.visitFunctionDefinition = function(node) {
2245 var meth = this._makeLambdaMethod(node.name.name, node);
2246 var funcValue = this._frame.create(meth.get$name(), meth.get$functionType(), t his.method.definition, true, null);
2247 meth.get$methodData().analyze();
2248 }
2249 MethodAnalyzer.prototype.visitReturnStatement = function(node) {
2250 if (node.value == null) {
2251 this._frame.returns(Value.fromNull(node.span));
2252 }
2253 else {
2254 this._frame.returns(this.visitValue(node.value));
2255 }
2256 }
2257 MethodAnalyzer.prototype.visitThrowStatement = function(node) {
2258 if (node.value != null) {
2259 var value = this.visitValue(node.value);
2260 }
2261 else {
2262 }
2263 }
2264 MethodAnalyzer.prototype.visitAssertStatement = function(node) {
2265 var test = this.visitValue(node.test);
2266 }
2267 MethodAnalyzer.prototype.visitBreakStatement = function(node) {
2268
2269 }
2270 MethodAnalyzer.prototype.visitContinueStatement = function(node) {
2271
2272 }
2273 MethodAnalyzer.prototype.visitIfStatement = function(node) {
2274 var test = this.visitBool(node.test);
2275 node.trueBranch.visit(this);
2276 if (node.falseBranch != null) {
2277 node.falseBranch.visit(this);
2278 }
2279 }
2280 MethodAnalyzer.prototype.visitWhileStatement = function(node) {
2281 var test = this.visitBool(node.test);
2282 node.body.visit(this);
2283 }
2284 MethodAnalyzer.prototype.visitDoStatement = function(node) {
2285 node.body.visit(this);
2286 var test = this.visitBool(node.test);
2287 }
2288 MethodAnalyzer.prototype.visitForStatement = function(node) {
2289 this._pushBlock(node);
2290 if (node.init != null) node.init.visit(this);
2291 if (node.test != null) {
2292 var test = this.visitBool(node.test);
2293 }
2294 var $$list = node.step;
2295 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2296 var s = $$i.next();
2297 var sv = this.visitVoid(s);
2298 }
2299 this._pushBlock(node.body);
2300 node.body.visit(this);
2301 this._popBlock(node.body);
2302 this._popBlock(node);
2303 }
2304 MethodAnalyzer.prototype.visitForInStatement = function(node) {
2305 var itemType = this.resolveType(node.item.type, false, true);
2306 var list = node.list.visit(this);
2307 this._visitForInBody(node, itemType, list);
2308 }
2309 MethodAnalyzer.prototype._isFinal = function(typeRef) {
2310 if ((typeRef instanceof GenericTypeReference)) {
2311 typeRef = typeRef.get$baseType();
2312 }
2313 else if ((typeRef instanceof SimpleTypeReference)) {
2314 return false;
2315 }
2316 return $ne$(typeRef) && typeRef.get$isFinal();
2317 }
2318 MethodAnalyzer.prototype._visitForInBody = function(node, itemType, list) {
2319 this._pushBlock(node);
2320 var isFinal = this._isFinal(node.item.type);
2321 var itemName = node.item.name.name;
2322 var item = this._frame.create(itemName, itemType, node.item.name, isFinal, nul l);
2323 var iterator = list.invoke(this._frame, "iterator", node.list, Arguments.get$E MPTY());
2324 node.body.visit(this);
2325 this._popBlock(node);
2326 }
2327 MethodAnalyzer.prototype._createDI = function(di) {
2328 this._frame.create(di.name.name, this.resolveType(di.type, false, true), di.na me, true, null);
2329 }
2330 MethodAnalyzer.prototype.visitTryStatement = function(node) {
2331 this._pushBlock(node.body);
2332 node.body.visit(this);
2333 this._popBlock(node.body);
2334 if (node.catches.get$length() > (0)) {
2335 for (var i = (0);
2336 i < node.catches.get$length(); i++) {
2337 var catch_ = node.catches.$index(i);
2338 this._pushBlock(catch_);
2339 this._createDI(catch_.get$exception());
2340 if (null != catch_.get$trace()) {
2341 this._createDI(catch_.get$trace());
2342 }
2343 catch_.get$body().visit(this);
2344 this._popBlock(catch_);
2345 }
2346 }
2347 if (node.finallyBlock != null) {
2348 node.finallyBlock.visit(this);
2349 }
2350 }
2351 MethodAnalyzer.prototype.visitSwitchStatement = function(node) {
2352 var test = this.visitValue(node.test);
2353 var $$list = node.cases;
2354 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2355 var case_ = $$i.next();
2356 this._pushBlock(case_);
2357 for (var i = (0);
2358 i < case_.get$cases().get$length(); i++) {
2359 var expr = case_.get$cases().$index(i);
2360 if ($eq$(expr)) {
2361 }
2362 else {
2363 var value = this.visitValue(expr);
2364 }
2365 }
2366 this._visitAllStatements(case_.get$statements());
2367 this._popBlock(case_);
2368 }
2369 }
2370 MethodAnalyzer.prototype._visitAllStatements = function(statementList) {
2371 for (var i = (0);
2372 i < statementList.get$length(); i++) {
2373 var stmt = statementList.$index(i);
2374 stmt.visit(this);
2375 }
2376 }
2377 MethodAnalyzer.prototype.visitBlockStatement = function(node) {
2378 this._pushBlock(node);
2379 this._visitAllStatements(node.body);
2380 this._popBlock(node);
2381 }
2382 MethodAnalyzer.prototype.visitLabeledStatement = function(node) {
2383 node.body.visit(this);
2384 }
2385 MethodAnalyzer.prototype.visitExpressionStatement = function(node) {
2386 var value = this.visitVoid(node.body);
2387 }
2388 MethodAnalyzer.prototype.visitEmptyStatement = function(node) {
2389
2390 }
2391 MethodAnalyzer.prototype.visitLambdaExpression = function(node) {
2392 var name = (node.func.name != null) ? node.func.name.name : "";
2393 var meth = this._makeLambdaMethod(name, node.func);
2394 meth.get$methodData().analyze();
2395 return this._frame._makeValue($globals.world.functionType, node);
2396 }
2397 MethodAnalyzer.prototype.analyzeInitializerConstructorCall = function(node, rece iver, name) {
2398 var type = this._frame.method.declaringType;
2399 if ((receiver instanceof SuperExpression)) {
2400 type = type.get$parent();
2401 }
2402 var member = type.getConstructor(name == null ? "" : name);
2403 if (null != member) {
2404 return member.invoke(this._frame, node, this._frame.makeThisValue(node), thi s._visitArgs(node.arguments));
2405 }
2406 else {
2407 var constructorName = name == null ? "" : ("." + name);
2408 $globals.world.warning(("cannot find constructor \"" + type.get$name() + con structorName + "\""), node.span);
2409 return this._frame._makeValue($globals.world.varType, node);
2410 }
2411 }
2412 MethodAnalyzer.prototype.isThisOrSuper = function(node) {
2413 return (node instanceof ThisExpression) || (node instanceof SuperExpression);
2414 }
2415 MethodAnalyzer.prototype.visitCallExpression = function(node, visitingInitialize rs) {
2416 var target;
2417 var position = node.target;
2418 var name = ":call";
2419 if ((node.target instanceof DotExpression)) {
2420 var dot = node.target;
2421 target = dot.self.visit(this);
2422 name = dot.name.name;
2423 if (this.isThisOrSuper(dot.self) && visitingInitializers) {
2424 return this.analyzeInitializerConstructorCall(node, dot.self, name);
2425 }
2426 else {
2427 position = dot.name;
2428 }
2429 }
2430 else if (this.isThisOrSuper(node.target) && visitingInitializers) {
2431 return this.analyzeInitializerConstructorCall(node, node.target, null);
2432 }
2433 else if ((node.target instanceof VarExpression)) {
2434 var varExpr = node.target;
2435 name = varExpr.name.name;
2436 target = this._frame.lookup(name);
2437 if ($ne$(target)) {
2438 return target.get(position).invoke(this._frame, ":call", node, this._visit Args(node.arguments));
2439 }
2440 var member = this._resolveBare(name, varExpr.name);
2441 if (null != member) {
2442 return member.invoke(this._frame, node, this._frame.makeThisValue(node), t his._visitArgs(node.arguments));
2443 }
2444 else {
2445 $globals.world.warning(("cannot find \"" + name + "\""), node.span);
2446 return this._frame._makeValue($globals.world.varType, node);
2447 }
2448 }
2449 else {
2450 target = node.target.visit(this);
2451 }
2452 return target.invoke(this._frame, name, position, this._visitArgs(node.argumen ts));
2453 }
2454 MethodAnalyzer.prototype.visitIndexExpression = function(node) {
2455 var target = this.visitValue(node.target);
2456 var index = this.visitValue(node.index);
2457 return target.invoke(this._frame, ":index", node, new Arguments(null, [index]) );
2458 }
2459 MethodAnalyzer.prototype.visitBinaryExpression = function(node, isVoid) {
2460 var kind = node.op.kind;
2461 if ($eq$(kind, (35)) || $eq$(kind, (34))) {
2462 var xb = this.visitBool(node.x);
2463 var yb = this.visitBool(node.y);
2464 return xb.binop(kind, yb, this._frame, node);
2465 }
2466 var assignKind = TokenKind.kindFromAssign(node.op.kind);
2467 if ($eq$(assignKind, (-1))) {
2468 var x = this.visitValue(node.x);
2469 var y = this.visitValue(node.y);
2470 return x.binop(kind, y, this._frame, node);
2471 }
2472 else {
2473 return this._visitAssign(assignKind, node.x, node.y, node);
2474 }
2475 }
2476 MethodAnalyzer.prototype._visitAssign = function(kind, xn, yn, position) {
2477 if ((xn instanceof VarExpression)) {
2478 return this._visitVarAssign(kind, xn, yn, position);
2479 }
2480 else if ((xn instanceof IndexExpression)) {
2481 return this._visitIndexAssign(kind, xn, yn, position);
2482 }
2483 else if ((xn instanceof DotExpression)) {
2484 return this._visitDotAssign(kind, xn, yn, position);
2485 }
2486 else {
2487 $globals.world.error("illegal lhs", xn.span);
2488 }
2489 }
2490 MethodAnalyzer.prototype._visitVarAssign = function(kind, xn, yn, node) {
2491 var value = this.visitValue(yn);
2492 var name = xn.name.name;
2493 var slot = this._frame.lookup(name);
2494 if ($ne$(slot)) {
2495 slot.set(value);
2496 }
2497 else {
2498 var member = this._resolveBare(name, xn.name);
2499 if (null != member) {
2500 member._set(this._frame, node, this._frame.makeThisValue(node), value);
2501 }
2502 else {
2503 $globals.world.warning(("cannot find \"" + name + "\""), node.span);
2504 }
2505 }
2506 return this._frame._makeValue(value.get$type(), node);
2507 }
2508 MethodAnalyzer.prototype._visitIndexAssign = function(kind, xn, yn, position) {
2509 var target = this.visitValue(xn.target);
2510 var index = this.visitValue(xn.index);
2511 var y = this.visitValue(yn);
2512 return target.setIndex$4$kind(this._frame, index, position, y, kind);
2513 }
2514 MethodAnalyzer.prototype._visitDotAssign = function(kind, xn, yn, position) {
2515 var target = xn.self.visit(this);
2516 var y = this.visitValue(yn);
2517 return target.set_$4$kind(this._frame, xn.name.name, xn.name, y, kind);
2518 }
2519 MethodAnalyzer.prototype.visitUnaryExpression = function(node) {
2520 var value = this.visitValue(node.self);
2521 switch (node.op.kind) {
2522 case (16):
2523 case (17):
2524
2525 return value.binop((42), this._frame._makeValue($globals.world.intType, no de), this._frame, node);
2526
2527 }
2528 return value.unop(node.op.kind, this._frame, node);
2529 }
2530 MethodAnalyzer.prototype.visitDeclaredIdentifier = function(node) {
2531 $globals.world.error("Expected expression", node.span);
2532 }
2533 MethodAnalyzer.prototype.visitAwaitExpression = function(node) {
2534 $globals.world.internalError("Await expressions should have been eliminated be fore code generation", node.span);
2535 }
2536 MethodAnalyzer.prototype.visitPostfixExpression = function(node, isVoid) {
2537 var value = this.visitValue(node.body);
2538 return this._frame._makeValue(value.get$type(), node);
2539 }
2540 MethodAnalyzer.prototype.visitNewExpression = function(node) {
2541 var typeRef = node.type;
2542 var constructorName = "";
2543 if (node.name != null) {
2544 constructorName = node.name.name;
2545 }
2546 if ($eq$(constructorName, "") && (typeRef instanceof NameTypeReference) && typ eRef.get$names() != null) {
2547 var names = ListFactory.ListFactory$from$factory(typeRef.get$names());
2548 constructorName = names.removeLast().get$name();
2549 if (names.get$length() == (0)) names = null;
2550 typeRef = new NameTypeReference(typeRef.get$isFinal(), typeRef.get$name(), n ames, typeRef.get$span());
2551 }
2552 var type = this.resolveType(typeRef, true, true);
2553 if (type.get$isTop()) {
2554 type = type.get$library().findTypeByName(constructorName);
2555 if ($eq$(type)) {
2556 $globals.world.error(("cannot resolve type " + constructorName), node.span );
2557 }
2558 constructorName = "";
2559 }
2560 if ((type instanceof ParameterType)) {
2561 $globals.world.error("cannot instantiate a type parameter", node.span);
2562 return this._frame._makeValue($globals.world.varType, node);
2563 }
2564 var m = type.getConstructor(constructorName);
2565 if ($eq$(m)) {
2566 var name = type.get$jsname();
2567 if (type.get$isVar()) {
2568 name = typeRef.get$name().get$name();
2569 }
2570 $globals.world.warning(("no matching constructor for " + name), node.span);
2571 return this._frame._makeValue(type, node);
2572 }
2573 if (node.isConst) {
2574 if (!m.get$isConst()) {
2575 $globals.world.error("can't use const on a non-const constructor", node.sp an);
2576 }
2577 var $$list = node.arguments;
2578 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2579 var arg = $$i.next();
2580 if (!this.visitValue(arg.get$value()).get$isConst()) {
2581 $globals.world.error("const constructor expects const arguments", arg.ge t$span());
2582 }
2583 }
2584 }
2585 var args = this._visitArgs(node.arguments);
2586 var target = new TypeValue(type, typeRef.get$span());
2587 return new PureStaticValue(type, node.span, node.isConst, false);
2588 }
2589 MethodAnalyzer.prototype.visitListExpression = function(node) {
2590 var argValues = [];
2591 var listType = $globals.world.listType;
2592 var type = $globals.world.varType;
2593 if (node.itemType != null) {
2594 type = this.resolveType(node.itemType, true, !node.isConst);
2595 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara ms())) {
2596 $globals.world.error("type parameter cannot be used in const list literals ");
2597 }
2598 listType = listType.getOrMakeConcreteType([type]);
2599 }
2600 var $$list = node.values;
2601 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
2602 var item = $$i.next();
2603 var arg = this.visitTypedValue(item, type);
2604 argValues.add(arg);
2605 }
2606 $globals.world.listFactoryType.markUsed();
2607 return new PureStaticValue(listType, node.span, node.isConst, false);
2608 }
2609 MethodAnalyzer.prototype.visitMapExpression = function(node) {
2610 var values = [];
2611 var valueType = $globals.world.varType, keyType = $globals.world.stringType;
2612 var mapType = $globals.world.mapType;
2613 if (null != node.valueType) {
2614 if (null != node.keyType) {
2615 keyType = this.method.resolveType(node.keyType, true, !node.isConst);
2616 if (!keyType.get$isString()) {
2617 $globals.world.error("the key type of a map literal must be \"String\"", keyType.get$span());
2618 }
2619 if (node.isConst && ((keyType instanceof ParameterType) || keyType.get$has TypeParams())) {
2620 $globals.world.error("type parameter cannot be used in const map literal s");
2621 }
2622 }
2623 valueType = this.resolveType(node.valueType, true, !node.isConst);
2624 if (node.isConst && ((valueType instanceof ParameterType) || valueType.get$h asTypeParams())) {
2625 $globals.world.error("type parameter cannot be used in const map literals" );
2626 }
2627 mapType = mapType.getOrMakeConcreteType([keyType, valueType]);
2628 }
2629 for (var i = (0);
2630 i < node.items.get$length(); i += (2)) {
2631 var key = this.visitTypedValue(node.items.$index(i), keyType);
2632 values.add(key);
2633 var value = this.visitTypedValue(node.items.$index(i + (1)), valueType);
2634 if (node.isConst && !value.get$isConst()) {
2635 $globals.world.error("const map can only contain const values", value.get$ span());
2636 }
2637 values.add(value);
2638 }
2639 return new PureStaticValue(mapType, node.span, node.isConst, false);
2640 }
2641 MethodAnalyzer.prototype.visitConditionalExpression = function(node) {
2642 var test = this.visitBool(node.test);
2643 var trueBranch = this.visitValue(node.trueBranch);
2644 var falseBranch = this.visitValue(node.falseBranch);
2645 return this._frame._makeValue(Type.union(trueBranch.get$type(), falseBranch.ge t$type()), node);
2646 }
2647 MethodAnalyzer.prototype.visitIsExpression = function(node) {
2648 var value = this.visitValue(node.x);
2649 var type = this.resolveType(node.type, false, true);
2650 return this._frame._makeValue($globals.world.boolType, node);
2651 }
2652 MethodAnalyzer.prototype.visitParenExpression = function(node) {
2653 return this.visitValue(node.body);
2654 }
2655 MethodAnalyzer.prototype.visitDotExpression = function(node) {
2656 var target = node.self.visit(this);
2657 return target.get_(this._frame, node.name.name, node);
2658 }
2659 MethodAnalyzer.prototype.visitVarExpression = function(node) {
2660 var name = node.name.name;
2661 var slot = this._frame.lookup(name);
2662 if ($ne$(slot)) {
2663 return slot.get(node);
2664 }
2665 var member = this._resolveBare(name, node.name);
2666 if (null != member) {
2667 if ((member instanceof TypeMember)) {
2668 return new PureStaticValue(member.get$dynamic().get$type(), node.span, tru e, true);
2669 }
2670 else {
2671 return member._get(this._frame, node, this._frame.makeThisValue(node));
2672 }
2673 }
2674 else {
2675 $globals.world.warning(("cannot find \"" + name + "\""), node.span);
2676 return this._frame._makeValue($globals.world.varType, node);
2677 }
2678 }
2679 MethodAnalyzer.prototype.visitThisExpression = function(node) {
2680 return this._frame.makeThisValue(node);
2681 }
2682 MethodAnalyzer.prototype.visitSuperExpression = function(node) {
2683 return this._frame.makeSuperValue(node);
2684 }
2685 MethodAnalyzer.prototype.visitLiteralExpression = function(node) {
2686 return new PureStaticValue(node.value.get$type(), node.span, true, false);
2687 }
2688 MethodAnalyzer.prototype.visitStringConcatExpression = function(node) {
2689 var $this = this; // closure support
2690 var isConst = true;
2691 node.strings.forEach((function (each) {
2692 if (!$this.visitValue(each).get$isConst()) isConst = false;
2693 })
2694 );
2695 return new PureStaticValue($globals.world.stringType, node.span, isConst, fals e);
2696 }
2697 MethodAnalyzer.prototype.visitStringInterpExpression = function(node) {
2698 var $this = this; // closure support
2699 var isConst = true;
2700 node.pieces.forEach((function (each) {
2701 if (!$this.visitValue(each).get$isConst()) isConst = false;
2702 })
2703 );
2704 return new PureStaticValue($globals.world.stringType, node.span, isConst, fals e);
2705 }
2706 MethodAnalyzer.prototype._pushBlock$1 = MethodAnalyzer.prototype._pushBlock;
2707 MethodAnalyzer.prototype.analyze$1 = MethodAnalyzer.prototype.analyze;
2708 MethodAnalyzer.prototype.visitBinaryExpression$1 = function($0) {
2709 return this.visitBinaryExpression($0, false);
2710 };
2711 MethodAnalyzer.prototype.visitCallExpression$1 = function($0) {
2712 return this.visitCallExpression($0, false);
2713 };
2714 MethodAnalyzer.prototype.visitPostfixExpression$1 = function($0) {
2715 return this.visitPostfixExpression($0, false);
2716 };
2717 // ********** Code for CallFrame **************
2718 function CallFrame(analyzer, method, thisValue, args, enclosingFrame) {
2719 this.analyzer = analyzer;
2720 this.method = method;
2721 this.thisValue = thisValue;
2722 this.args = args;
2723 this.enclosingFrame = enclosingFrame;
2724 this._slots = [];
2725 this._scope = new AnalyzeScope(null, this, this.analyzer.body);
2726 this._returnSlot = new VariableSlot(this._scope, "return", this.method.returnT ype, this.analyzer.body, false);
2727 }
2728 CallFrame.prototype.findMembers = function(name) {
2729 return this.get$library()._findMembers(name);
2730 }
2731 CallFrame.prototype.get$counters = function() {
2732 return $globals.world.counters;
2733 }
2734 CallFrame.prototype.get$library = function() {
2735 return this.method.get$library();
2736 }
2737 CallFrame.prototype.get$method = function() { return this.method; };
2738 CallFrame.prototype.get$needsCode = function() {
2739 return false;
2740 }
2741 CallFrame.prototype.get$showWarnings = function() {
2742 return true;
2743 }
2744 CallFrame.prototype._makeThisCode = function() {
2745 return null;
2746 }
2747 CallFrame.prototype.getTemp = function(value) {
2748 return null;
2749 }
2750 CallFrame.prototype.forceTemp = function(value) {
2751 return null;
2752 }
2753 CallFrame.prototype.assignTemp = function(tmp, v) {
2754 return null;
2755 }
2756 CallFrame.prototype.freeTemp = function(value) {
2757 return null;
2758 }
2759 CallFrame.prototype.get$isStatic = function() {
2760 return this.enclosingFrame != null ? this.enclosingFrame.get$isStatic() : this .method.isStatic;
2761 }
2762 CallFrame.prototype.get$_slots = function() { return this._slots; };
2763 CallFrame.prototype.get$_scope = function() { return this._scope; };
2764 CallFrame.prototype.pushBlock = function(node) {
2765 this._scope = new AnalyzeScope(this._scope, this, node);
2766 }
2767 CallFrame.prototype.popBlock = function(node) {
2768 if ($ne$(this._scope.node, node)) {
2769 $globals.world.internalError("incorrect pop", node.span, this._scope.node.sp an);
2770 }
2771 this._scope = this._scope.parent;
2772 }
2773 CallFrame.prototype.returns = function(value) {
2774 this._returnSlot.set(value);
2775 }
2776 CallFrame.prototype.lookup = function(name) {
2777 var slot = this._scope._lookup(name);
2778 if ($eq$(slot) && this.enclosingFrame != null) {
2779 return this.enclosingFrame.lookup(name);
2780 }
2781 return slot;
2782 }
2783 CallFrame.prototype.create = function(name, staticType, node, isFinal, value) {
2784 var slot = new VariableSlot(this._scope, name, staticType, node, isFinal, valu e);
2785 var existingSlot = this._scope._lookup(name);
2786 if (null != existingSlot) {
2787 if ($eq$(existingSlot.get$scope(), this)) {
2788 $globals.world.error(("duplicate name \"" + name + "\""), node.span);
2789 }
2790 else {
2791 }
2792 }
2793 this._slots.add(slot);
2794 this._scope._slots.add(slot);
2795 }
2796 CallFrame.prototype.declareParameter = function(p, value) {
2797 return this.create(p.name, p.type, p.definition, false, value);
2798 }
2799 CallFrame.prototype._makeValue = function(type, node) {
2800 return new PureStaticValue(type, node == null ? null : node.span, false, false );
2801 }
2802 CallFrame.prototype.makeSuperValue = function(node) {
2803 return this._makeValue(this.thisValue.get$type().get$parent(), node);
2804 }
2805 CallFrame.prototype.makeThisValue = function(node) {
2806 return this._makeValue(this.thisValue.get$type(), node);
2807 }
2808 // ********** Code for VariableSlot **************
2809 function VariableSlot(scope, name, staticType, node, isFinal, value) {
2810 this.scope = scope;
2811 this.name = name;
2812 this.staticType = staticType;
2813 this.node = node;
2814 this.isFinal = isFinal;
2815 this.value = value;
2816 if (null != this.value) {
2817 this.value = this.value.convertTo(this.scope.frame, this.staticType);
2818 }
2819 }
2820 VariableSlot.prototype.get$scope = function() { return this.scope; };
2821 VariableSlot.prototype.get$name = function() { return this.name; };
2822 VariableSlot.prototype.get$staticType = function() { return this.staticType; };
2823 VariableSlot.prototype.get$isFinal = function() { return this.isFinal; };
2824 VariableSlot.prototype.get$value = function() { return this.value; };
2825 VariableSlot.prototype.set$value = function(value) { return this.value = value; };
2826 VariableSlot.prototype.get = function(position) {
2827 return this.scope.frame._makeValue(this.staticType, position);
2828 }
2829 VariableSlot.prototype.set = function(newValue) {
2830 if (null != newValue) {
2831 newValue = newValue.convertTo(this.scope.frame, this.staticType);
2832 }
2833 this.value = Value.union(this.value, newValue);
2834 }
2835 VariableSlot.prototype.toString = function() {
2836 var valueString = null != this.value ? (" = " + this.value.get$type().name) : "";
2837 return ("" + this.staticType.name + " " + this.name + valueString);
2838 }
2839 VariableSlot.prototype.toString$0 = VariableSlot.prototype.toString;
2840 // ********** Code for AnalyzeScope **************
2841 function AnalyzeScope(parent, frame, node) {
2842 this.parent = parent;
2843 this.frame = frame;
2844 this.node = node;
2845 this._slots = [];
2846 }
2847 AnalyzeScope.prototype.get$parent = function() { return this.parent; };
2848 AnalyzeScope.prototype.get$_slots = function() { return this._slots; };
2849 AnalyzeScope.prototype._lookup = function(name) {
2850 for (var s = this;
2851 $ne$(s); s = s.get$parent()) {
2852 for (var i = (0);
2853 i < s.get$_slots().get$length(); i++) {
2854 var ret = s.get$_slots().$index(i);
2855 if ($eq$(ret.get$name(), name)) return ret;
2856 }
2857 }
2858 return null;
2859 }
2860 // ********** Code for BlockScope **************
2861 function BlockScope(enclosingMethod, parent, node, reentrant) {
2862 this.enclosingMethod = enclosingMethod;
2863 this.parent = parent;
2864 this.node = node;
2865 this.reentrant = reentrant;
2866 this._vars = new CopyOnWriteMap_dart_core_String$VariableValue();
2867 this._jsNames = new HashSetImplementation_dart_core_String();
2868 if (this.get$isMethodScope()) {
2869 this._closedOver = new HashSetImplementation_dart_core_String();
2870 }
2871 else {
2872 this.reentrant = reentrant || this.parent.reentrant;
2873 }
2874 this.inferTypes = $globals.options.inferTypes && (this.parent == null || this. parent.inferTypes);
2875 }
2876 BlockScope._snapshot$ctor = function(original) {
2877 this.enclosingMethod = original.enclosingMethod;
2878 this.parent = original.parent == null ? null : original.parent.snapshot();
2879 this._vars = original._vars.clone();
2880 this.node = original.node;
2881 this.inferTypes = original.inferTypes;
2882 this.rethrow = original.rethrow;
2883 this._jsNames = original._jsNames;
2884 this._closedOver = original._closedOver;
2885 }
2886 BlockScope._snapshot$ctor.prototype = BlockScope.prototype;
2887 BlockScope.prototype.get$enclosingMethod = function() { return this.enclosingMet hod; };
2888 BlockScope.prototype.get$parent = function() { return this.parent; };
2889 BlockScope.prototype.get$_vars = function() { return this._vars; };
2890 BlockScope.prototype.get$_jsNames = function() { return this._jsNames; };
2891 BlockScope.prototype.get$_closedOver = function() { return this._closedOver; };
2892 BlockScope.prototype.get$rethrow = function() { return this.rethrow; };
2893 BlockScope.prototype.get$isMethodScope = function() {
2894 return this.parent == null || $ne$(this.parent.enclosingMethod, this.enclosing Method);
2895 }
2896 BlockScope.prototype.get$methodScope = function() {
2897 var s = this;
2898 while (!s.get$isMethodScope()) s = s.get$parent();
2899 return s;
2900 }
2901 BlockScope.prototype.lookup = function(name) {
2902 for (var s = this;
2903 $ne$(s); s = s.get$parent()) {
2904 var ret = s.get$_vars().$index(name);
2905 if (ret != null) return this._capture(s, ret);
2906 }
2907 return null;
2908 }
2909 BlockScope.prototype.inferAssign = function(name, value) {
2910 if (this.inferTypes) this.assign(name, value);
2911 }
2912 BlockScope.prototype.assign = function(name, value) {
2913 for (var s = this;
2914 $ne$(s); s = s.get$parent()) {
2915 var existing = s.get$_vars().$index(name);
2916 if ($ne$(existing)) {
2917 s.get$_vars().$setindex(name, existing.replaceValue(value));
2918 return;
2919 }
2920 }
2921 $globals.world.internalError(("assigning variable '" + name + "' that doesn't exist."));
2922 }
2923 BlockScope.prototype._capture = function(other, value) {
2924 if ($ne$(other.enclosingMethod, this.enclosingMethod)) {
2925 other.get$methodScope()._closedOver.add(value.get$code());
2926 if (this.enclosingMethod.captures != null && other.reentrant) {
2927 this.enclosingMethod.captures.add(value.get$code());
2928 }
2929 }
2930 return value;
2931 }
2932 BlockScope.prototype._isDefinedInParent = function(name) {
2933 if (this.get$isMethodScope() && this._closedOver.contains(name)) return true;
2934 for (var s = this.parent;
2935 $ne$(s); s = s.get$parent()) {
2936 if (s.get$_vars().containsKey(name)) return true;
2937 if (s.get$_jsNames().contains(name)) return true;
2938 if (s.get$isMethodScope() && s.get$_closedOver().contains(name)) return true ;
2939 }
2940 var type = this.enclosingMethod.method.declaringType;
2941 if (type.get$library().lookup(name, null) != null) return true;
2942 return false;
2943 }
2944 BlockScope.prototype.create = function(name, type, span, isFinal, isParameter) {
2945 var jsName = $globals.world.toJsIdentifier(name);
2946 if (this._vars.containsKey(name)) {
2947 $globals.world.error(("duplicate name \"" + name + "\""), span);
2948 }
2949 if (!isParameter) {
2950 var index = (0);
2951 while (this._isDefinedInParent(jsName)) {
2952 jsName = ("" + name + (index++));
2953 }
2954 }
2955 var ret = new VariableValue(type, jsName, span, isFinal);
2956 this._vars.$setindex(name, ret);
2957 if (name != jsName) this._jsNames.add(jsName);
2958 return ret;
2959 }
2960 BlockScope.prototype.declareParameter = function(p) {
2961 return this.create(p.name, p.type, p.definition.span, false, true);
2962 }
2963 BlockScope.prototype.declare = function(id) {
2964 var type = this.enclosingMethod.method.resolveType(id.type, false, true);
2965 return this.create(id.name.name, type, id.span, false, false);
2966 }
2967 BlockScope.prototype.getRethrow = function() {
2968 var scope = this;
2969 while (scope.get$rethrow() == null && $ne$(scope.get$parent())) {
2970 scope = scope.get$parent();
2971 }
2972 return scope.get$rethrow();
2973 }
2974 BlockScope.prototype.snapshot = function() {
2975 return new BlockScope._snapshot$ctor(this);
2976 }
2977 BlockScope.prototype.unionWith = function(other) {
2978 var $this = this; // closure support
2979 var $0;
2980 var changed = false;
2981 if (this.parent != null) {
2982 changed = this.parent.unionWith(other.parent);
2983 }
2984 if ((($0 = this._vars._lang_map) == null ? null != (other._vars._lang_map) : $ 0 !== other._vars._lang_map)) {
2985 other._vars.forEach((function (key, otherVar) {
2986 var $0;
2987 var myVar = $this._vars.$index(key);
2988 var v = Value.union(myVar.value, otherVar.value);
2989 if ((($0 = myVar.value) == null ? null != (v) : $0 !== v)) {
2990 $this._vars.$setindex(key, myVar.replaceValue(v));
2991 changed = true;
2992 }
2993 })
2994 );
2995 }
2996 return changed;
2997 }
2998 BlockScope.prototype.create$3$isFinal = function($0, $1, $2, isFinal) {
2999 return this.create($0, $1, $2, isFinal, false);
3000 };
3001 // ********** Code for CodeWriter **************
3002 function CodeWriter() {
3003 this.writeComments = true;
3004 this._buf = [];
3005 }
3006 CodeWriter.prototype.get$text = function() {
3007 var $this = this; // closure support
3008 var sb = new StringBufferImpl("");
3009 var indentation = (0);
3010 var pendingIndent = false;
3011 function _walk(list) {
3012 for (var $$i = list.iterator(); $$i.hasNext(); ) {
3013 var thing = $$i.next();
3014 if ((typeof(thing) == 'string')) {
3015 if (pendingIndent) {
3016 for (var i = (0);
3017 i < indentation; i++) {
3018 sb.add(" ");
3019 }
3020 pendingIndent = false;
3021 }
3022 sb.add(thing);
3023 }
3024 else if (null == thing) {
3025 sb.add("\n");
3026 pendingIndent = true;
3027 }
3028 else if ((typeof(thing) == 'number')) {
3029 indentation = $add$(indentation, thing);
3030 }
3031 else if (!!(thing && thing.is$List())) {
3032 _walk(thing);
3033 }
3034 }
3035 }
3036 _walk(this._buf);
3037 return sb.toString();
3038 }
3039 CodeWriter.prototype.subWriter = function() {
3040 var sub = new CodeWriter();
3041 sub.writeComments = this.writeComments;
3042 this._buf.add(sub._buf);
3043 return sub;
3044 }
3045 CodeWriter.prototype.comment = function(text) {
3046 if (this.writeComments) {
3047 this.writeln(text);
3048 }
3049 }
3050 CodeWriter.prototype._writeFragment = function(text) {
3051 if (text.length == (0)) return;
3052 this._buf.add(text);
3053 }
3054 CodeWriter.prototype.write = function(text) {
3055 if (text.length == (0)) return;
3056 if (text.indexOf("\n") != (-1)) {
3057 var lines = text.split$_("\n");
3058 this._writeFragment(lines.$index((0)));
3059 for (var i = (1);
3060 i < lines.get$length(); i++) {
3061 this._buf.add();
3062 this._writeFragment(lines.$index(i));
3063 }
3064 }
3065 else {
3066 this._buf.add(text);
3067 }
3068 }
3069 CodeWriter.prototype.writeln = function(text) {
3070 if (text == null) {
3071 this._buf.add();
3072 }
3073 else {
3074 this.write(text);
3075 if (!text.endsWith("\n")) this._buf.add();
3076 }
3077 }
3078 CodeWriter.prototype.writeln.$optional = ['text', 'null']
3079 CodeWriter.prototype.get$writeln = function() {
3080 return this.writeln.bind(this);
3081 }
3082 CodeWriter.prototype.enterBlock = function(text) {
3083 this.writeln(text);
3084 this._buf.add((1));
3085 }
3086 CodeWriter.prototype.get$enterBlock = function() {
3087 return this.enterBlock.bind(this);
3088 }
3089 CodeWriter.prototype.exitBlock = function(text) {
3090 this._buf.add((-1));
3091 this.writeln(text);
3092 }
3093 CodeWriter.prototype.nextBlock = function(text) {
3094 this._buf.add((-1));
3095 this.writeln(text);
3096 this._buf.add((1));
3097 }
3098 CodeWriter.prototype.write$1 = CodeWriter.prototype.write;
3099 // ********** Code for CoreJs **************
3100 function CoreJs() {
3101 this.useThrow = false;
3102 this.useNotNullBool = false;
3103 this.useIndex = false;
3104 this.useSetIndex = false;
3105 this.useWrap0 = false;
3106 this.useWrap1 = false;
3107 this.useIsolates = false;
3108 this._generatedTypeNameOf = false;
3109 this._generatedDynamicProto = false;
3110 this._generatedDynamicSetMetadata = false;
3111 this._generatedInherits = false;
3112 this._generatedDefProp = false;
3113 this._generatedBind = false;
3114 this._usedOperators = new HashMapImplementation();
3115 this.writer = new CodeWriter();
3116 }
3117 CoreJs.prototype.get$writer = function() { return this.writer; };
3118 CoreJs.prototype.set$writer = function(value) { return this.writer = value; };
3119 CoreJs.prototype.markCorelibTypeUsed = function(typeName) {
3120 $globals.world.gen.markTypeUsed($globals.world.corelib.types.$index(typeName)) ;
3121 }
3122 CoreJs.prototype.useOperator = function(name) {
3123 if ($ne$(this._usedOperators.$index(name))) return;
3124 if (name != ":ne" && name != ":eq") {
3125 this.markCorelibTypeUsed("NoSuchMethodException");
3126 }
3127 if (name != ":bit_not" && name != ":negate") {
3128 this.markCorelibTypeUsed("IllegalArgumentException");
3129 }
3130 var code;
3131 switch (name) {
3132 case ":ne":
3133
3134 code = "function $ne$(x, y) {\n if (x == null) return y != null;\n retur n (typeof(x) != 'object') ? x !== y : !x.$eq(y);\n}";
3135 break;
3136
3137 case ":eq":
3138
3139 this.ensureDefProp();
3140 code = "function $eq$(x, y) {\n if (x == null) return y == null;\n retur n (typeof(x) != 'object') ? x === y : x.$eq(y);\n}\n// TODO(jimhug): Should this or should it not match equals?\n$defProp(Object.prototype, '$eq', function(othe r) {\n return this === other;\n});";
3141 break;
3142
3143 case ":bit_not":
3144
3145 code = "function $bit_not$(x) {\n if (typeof(x) == 'number') return ~x;\n if (typeof(x) == 'object') return x.$bit_not();\n $throw(new NoSuchMethodExc eption(x, \"operator ~\", []));\n}";
3146 break;
3147
3148 case ":negate":
3149
3150 code = "function $negate$(x) {\n if (typeof(x) == 'number') return -x;\n if (typeof(x) == 'object') return x.$negate();\n $throw(new NoSuchMethodExcept ion(x, \"operator negate\", []));\n}";
3151 break;
3152
3153 case ":add":
3154
3155 code = "function $add$complex$(x, y) {\n if (typeof(x) == 'number') {\n $throw(new IllegalArgumentException(y));\n } else if (typeof(x) == 'string') {\n var str = (y == null) ? 'null' : y.toString();\n if (typeof(str) != 's tring') {\n throw new Error(\"calling toString() on right hand operand of o perator \" +\n \"+ did not return a String\");\n }\n return x + str;\ n } else if (typeof(x) == 'object') {\n return x.$add(y);\n } else {\n $ throw(new NoSuchMethodException(x, \"operator +\", [y]));\n }\n}\n\nfunction $a dd$(x, y) {\n if (typeof(x) == 'number' && typeof(y) == 'number') return x + y; \n return $add$complex$(x, y);\n}";
3156 break;
3157
3158 case ":truncdiv":
3159
3160 this.useThrow = true;
3161 this.markCorelibTypeUsed("IntegerDivisionByZeroException");
3162 code = "function $truncdiv$(x, y) {\n if (typeof(x) == 'number') {\n i f (typeof(y) == 'number') {\n if (y == 0) $throw(new IntegerDivisionByZeroE xception());\n var tmp = x / y;\n return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp);\n } else {\n $throw(new IllegalArgumentException(y));\n }\n } else if (typeof(x) == 'object') {\n return x.$truncdiv(y);\n } el se {\n $throw(new NoSuchMethodException(x, \"operator ~/\", [y]));\n }\n}";
3163 break;
3164
3165 case ":mod":
3166
3167 code = "function $mod$(x, y) {\n if (typeof(x) == 'number') {\n if (ty peof(y) == 'number') {\n var result = x % y;\n if (result == 0) {\n return 0; // Make sure we don't return -0.0.\n } else if (result < 0) {\n if (y < 0) {\n return result - y;\n } else {\n return result + y;\n }\n }\n return result;\n } else {\n $throw(new IllegalArgumentException(y));\n }\n } else if (typeof(x) == 'object') {\n return x.$mod(y);\n } else {\n $throw(new NoSuchMethodExce ption(x, \"operator %\", [y]));\n }\n}";
3168 break;
3169
3170 default:
3171
3172 var op = TokenKind.rawOperatorFromMethod(name);
3173 var jsname = $globals.world.toJsIdentifier(name);
3174 code = _otherOperator(jsname, op);
3175 break;
3176
3177 }
3178 this._usedOperators.$setindex(name, code);
3179 }
3180 CoreJs.prototype.ensureDynamicProto = function() {
3181 if (this._generatedDynamicProto) return;
3182 this._generatedDynamicProto = true;
3183 this.ensureTypeNameOf();
3184 this.ensureDefProp();
3185 this.writer.writeln("function $dynamic(name) {\n var f = Object.prototype[nam e];\n if (f && f.methods) return f.methods;\n\n var methods = {};\n if (f) me thods.Object = f;\n function $dynamicBind() {\n // Find the target method\n var obj = this;\n var tag = obj.$typeNameOf();\n var method = methods[t ag];\n if (!method) {\n var table = $dynamicMetadata;\n for (var i = 0; i < table.length; i++) {\n var entry = table[i];\n if (entry. map.hasOwnProperty(tag)) {\n method = methods[entry.tag];\n if (method) break;\n }\n }\n }\n method = method || methods.Obje ct;\n\n var proto = Object.getPrototypeOf(obj);\n\n if (method == null) {\ n // Trampoline to throw NoSuchMethodException (TODO: call noSuchMethod).\n method = function(){\n // Exact type check to prevent this code sha dowing the dispatcher from a\n // subclass.\n if (Object.getProtot ypeOf(this) === proto) {\n // TODO(sra): 'name' is the jsname, should b e the Dart name.\n $throw(new NoSuchMethodException(\n obj , name, Array.prototype.slice.call(arguments)));\n }\n return Obje ct.prototype[name].apply(this, arguments);\n };\n }\n\n if (!proto.ha sOwnProperty(name)) {\n $defProp(proto, name, method);\n }\n\n return method.apply(this, Array.prototype.slice.call(arguments));\n };\n $dynamicBin d.methods = methods;\n $defProp(Object.prototype, name, $dynamicBind);\n retur n methods;\n}\nif (typeof $dynamicMetadata == 'undefined') $dynamicMetadata = [] ;\n");
3186 }
3187 CoreJs.prototype.ensureDynamicSetMetadata = function() {
3188 if (this._generatedDynamicSetMetadata) return;
3189 this._generatedDynamicSetMetadata = true;
3190 this.writer.writeln("function $dynamicSetMetadata(inputTable) {\n // TODO: De al with light isolates.\n var table = [];\n for (var i = 0; i < inputTable.len gth; i++) {\n var tag = inputTable[i][0];\n var tags = inputTable[i][1];\n var map = {};\n var tagNames = tags.split('|');\n for (var j = 0; j < tagNames.length; j++) {\n map[tagNames[j]] = true;\n }\n table.push({ tag: tag, tags: tags, map: map});\n }\n $dynamicMetadata = table;\n}\n");
3191 }
3192 CoreJs.prototype.ensureTypeNameOf = function() {
3193 if (this._generatedTypeNameOf) return;
3194 this._generatedTypeNameOf = true;
3195 this.ensureDefProp();
3196 this.writer.writeln("$defProp(Object.prototype, '$typeNameOf', (function() {\n function constructorNameWithFallback(obj) {\n var constructor = obj.constru ctor;\n if (typeof(constructor) == 'function') {\n // The constructor is n't null or undefined at this point. Try\n // to grab hold of its name.\n var name = constructor.name;\n // If the name is a non-empty string, we use that as the type\n // name of this object. On Firefox, we often get 'O bject' as\n // the constructor name even for more specialized objects so\n // we have to fall through to the toString() based implementation\n // below in that case.\n if (typeof(name) == 'string' && name && name != 'Obj ect') return name;\n }\n var string = Object.prototype.toString.call(obj); \n return string.substring(8, string.length - 1);\n }\n\n function chrome$t ypeNameOf() {\n var name = this.constructor.name;\n if (name == 'Window') return 'DOMWindow';\n return name;\n }\n\n function firefox$typeNameOf() {\ n var name = constructorNameWithFallback(this);\n if (name == 'Window') re turn 'DOMWindow';\n if (name == 'Document') return 'HTMLDocument';\n if (n ame == 'XMLDocument') return 'Document';\n return name;\n }\n\n function ie $typeNameOf() {\n var name = constructorNameWithFallback(this);\n if (name == 'Window') return 'DOMWindow';\n // IE calls both HTML and XML documents ' Document', so we check for the\n // xmlVersion property, which is the empty s tring on HTML documents.\n if (name == 'Document' && this.xmlVersion) return 'Document';\n if (name == 'Document') return 'HTMLDocument';\n return name ;\n }\n\n // If we're not in the browser, we're almost certainly running on v8 .\n if (typeof(navigator) != 'object') return chrome$typeNameOf;\n\n var userA gent = navigator.userAgent;\n if (/Chrome|DumpRenderTree/.test(userAgent)) retu rn chrome$typeNameOf;\n if (/Firefox/.test(userAgent)) return firefox$typeNameO f;\n if (/MSIE/.test(userAgent)) return ie$typeNameOf;\n return function() { r eturn constructorNameWithFallback(this); };\n})());");
3197 }
3198 CoreJs.prototype.ensureInheritsHelper = function() {
3199 if (this._generatedInherits) return;
3200 this._generatedInherits = true;
3201 this.writer.writeln("/** Implements extends for Dart classes on JavaScript pro totypes. */\nfunction $inherits(child, parent) {\n if (child.prototype.__proto_ _) {\n child.prototype.__proto__ = parent.prototype;\n } else {\n functio n tmp() {};\n tmp.prototype = parent.prototype;\n child.prototype = new tm p();\n child.prototype.constructor = child;\n }\n}");
3202 }
3203 CoreJs.prototype.ensureDefProp = function() {
3204 if (this._generatedDefProp) return;
3205 this._generatedDefProp = true;
3206 this.writer.writeln("function $defProp(obj, prop, value) {\n Object.definePro perty(obj, prop,\n {value: value, enumerable: false, writable: true, config urable: true});\n}");
3207 }
3208 CoreJs.prototype.ensureBind = function() {
3209 if (this._generatedBind) return;
3210 this._generatedBind = true;
3211 this.writer.writeln("Function.prototype.bind = Function.prototype.bind ||\n f unction(thisObj) {\n var func = this;\n var funcLength = func.$length || f unc.length;\n var argsLength = arguments.length;\n if (argsLength > 1) {\n var boundArgs = Array.prototype.slice.call(arguments, 1);\n var bound = function() {\n // Prepend the bound arguments to the current arguments .\n var newArgs = Array.prototype.slice.call(arguments);\n Array.p rototype.unshift.apply(newArgs, boundArgs);\n return func.apply(thisObj, newArgs);\n };\n bound.$length = Math.max(0, funcLength - (argsLength - 1));\n return bound;\n } else {\n var bound = function() {\n return func.apply(thisObj, arguments);\n };\n bound.$length = funcL ength;\n return bound;\n }\n };");
3212 }
3213 CoreJs.prototype.generate = function(w) {
3214 w.write(this.writer.get$text());
3215 this.writer = w.subWriter();
3216 if (this.useNotNullBool) {
3217 this.useThrow = true;
3218 this.writer.writeln("function $notnull_bool(test) {\n if (test === true || test === false) return test;\n $throw(new TypeError(test, 'bool'));\n}");
3219 }
3220 if (this.useThrow) {
3221 this.writer.writeln("function $throw(e) {\n // If e is not a value, we can use V8's captureStackTrace utility method.\n // TODO(jmesserly): capture the st ack trace on other JS engines.\n if (e && (typeof e == 'object') && Error.captu reStackTrace) {\n // TODO(jmesserly): this will clobber the e.stack property\ n Error.captureStackTrace(e, $throw);\n }\n throw e;\n}");
3222 }
3223 if (this.useIndex) {
3224 this.markCorelibTypeUsed("NoSuchMethodException");
3225 this.ensureDefProp();
3226 this.writer.writeln($globals.options.disableBoundsChecks ? "$defProp(Object. prototype, '$index', function(i) {\n $throw(new NoSuchMethodException(this, \"o perator []\", [i]));\n});\n$defProp(Array.prototype, '$index', function(i) {\n return this[i];\n});\n$defProp(String.prototype, '$index', function(i) {\n retu rn this[i];\n});" : "$defProp(Object.prototype, '$index', function(i) {\n $thro w(new NoSuchMethodException(this, \"operator []\", [i]));\n});\n$defProp(Array.p rototype, '$index', function(index) {\n var i = index | 0;\n if (i !== index) {\n throw new IllegalArgumentException('index is not int');\n } else if (i < 0 || i >= this.length) {\n throw new IndexOutOfRangeException(index);\n }\n return this[i];\n});\n$defProp(String.prototype, '$index', function(i) {\n re turn this[i];\n});");
3227 }
3228 if (this.useSetIndex) {
3229 this.markCorelibTypeUsed("NoSuchMethodException");
3230 this.ensureDefProp();
3231 this.writer.writeln($globals.options.disableBoundsChecks ? "$defProp(Object. prototype, '$setindex', function(i, value) {\n $throw(new NoSuchMethodException (this, \"operator []=\", [i, value]));\n});\n$defProp(Array.prototype, '$setinde x',\n function(i, value) { return this[i] = value; });" : "$defProp(Object.pr ototype, '$setindex', function(i, value) {\n $throw(new NoSuchMethodException(t his, \"operator []=\", [i, value]));\n});\n$defProp(Array.prototype, '$setindex' , function(index, value) {\n var i = index | 0;\n if (i !== index) {\n thro w new IllegalArgumentException('index is not int');\n } else if (i < 0 || i >= this.length) {\n throw new IndexOutOfRangeException(index);\n }\n return th is[i] = value;\n});");
3232 }
3233 if (!this.useIsolates) {
3234 if (this.useWrap0) {
3235 this.writer.writeln("function $wrap_call$0(fn) { return fn; }");
3236 }
3237 if (this.useWrap1) {
3238 this.writer.writeln("function $wrap_call$1(fn) { return fn; }");
3239 }
3240 }
3241 var $$list = orderValuesByKeys(this._usedOperators);
3242 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3243 var opImpl = $$i.next();
3244 this.writer.writeln(opImpl);
3245 }
3246 if ($globals.world.dom != null) {
3247 this.ensureTypeNameOf();
3248 this.ensureDefProp();
3249 this.writer.writeln("$defProp(Object.prototype, \"get$typeName\", Object.pro totype.$typeNameOf);");
3250 }
3251 }
3252 // ********** Code for Element **************
3253 function Element(name, _enclosingElement) {
3254 this.name = name;
3255 this._enclosingElement = _enclosingElement;
3256 if (null != this.name) {
3257 var mangled = this.mangleJsName();
3258 this._jsname = mangled;
3259 }
3260 }
3261 Element.prototype.get$name = function() { return this.name; };
3262 Element.prototype.set$name = function(value) { return this.name = value; };
3263 Element.prototype.get$_jsname = function() { return this._jsname; };
3264 Element.prototype.set$_jsname = function(value) { return this._jsname = value; } ;
3265 Element.prototype.get$library = function() {
3266 return null;
3267 }
3268 Element.prototype.get$span = function() {
3269 return null;
3270 }
3271 Element.prototype.get$isNative = function() {
3272 return false;
3273 }
3274 Element.prototype.hashCode = function() {
3275 return this.name.hashCode();
3276 }
3277 Element.prototype.get$jsname = function() {
3278 return this._jsname;
3279 }
3280 Element.prototype.get$nativeName = function() {
3281 return this._jsname;
3282 }
3283 Element.prototype.get$avoidNativeName = function() {
3284 return false;
3285 }
3286 Element.prototype.get$jsnamePriority = function() {
3287 return this.get$isNative() ? (2) : (this.get$library().get$isCore() ? (1) : (0 ));
3288 }
3289 Element.prototype.resolve = function() {
3290
3291 }
3292 Element.prototype.mangleJsName = function() {
3293 return $globals.world.toJsIdentifier(this.name);
3294 }
3295 Element.prototype.get$typeParameters = function() {
3296 return null;
3297 }
3298 Element.prototype.get$typeArgsInOrder = function() {
3299 return const$0007;
3300 }
3301 Element.prototype.get$enclosingElement = function() {
3302 return this._enclosingElement == null ? this.get$library() : this._enclosingEl ement;
3303 }
3304 Element.prototype.set$enclosingElement = function(e) {
3305 var $0;
3306 return (this._enclosingElement = ($0 = e), $0);
3307 }
3308 Element.prototype.lookupTypeParam = function(name) {
3309 if (this.get$typeParameters() == null) return null;
3310 for (var i = (0);
3311 i < this.get$typeParameters().get$length(); i++) {
3312 if (this.get$typeParameters().$index(i).name == name) {
3313 return this.get$typeArgsInOrder().$index(i);
3314 }
3315 }
3316 return null;
3317 }
3318 Element.prototype.resolveType = function(node, typeErrors, allowTypeParams) {
3319 if (node == null) return $globals.world.varType;
3320 if ((node instanceof SimpleTypeReference)) {
3321 var ret = node.get$dynamic().get$type();
3322 if ($eq$(ret, $globals.world.voidType)) {
3323 $globals.world.error("\"void\" only allowed as return type", node.span);
3324 return $globals.world.varType;
3325 }
3326 return ret;
3327 }
3328 else if ((node instanceof NameTypeReference)) {
3329 var typeRef = node;
3330 var name;
3331 if (typeRef.names != null) {
3332 name = typeRef.names.last().name;
3333 }
3334 else {
3335 name = typeRef.name.name;
3336 }
3337 var typeParamType = this.lookupTypeParam(name);
3338 if ($ne$(typeParamType)) {
3339 if (!allowTypeParams) {
3340 $globals.world.error("using type parameter in illegal context.", node.sp an);
3341 }
3342 return typeParamType;
3343 }
3344 return this.get$enclosingElement().resolveType(node, typeErrors, allowTypePa rams);
3345 }
3346 else if ((node instanceof GenericTypeReference)) {
3347 var typeRef = node;
3348 var baseType = this.resolveType(typeRef.baseType, typeErrors, allowTypeParam s);
3349 if (!baseType.get$isGeneric()) {
3350 $globals.world.error(("" + baseType.get$name() + " is not generic"), typeR ef.span);
3351 return $globals.world.varType;
3352 }
3353 if (typeRef.typeArguments.get$length() != baseType.get$typeParameters().get$ length()) {
3354 $globals.world.error("wrong number of type arguments", typeRef.span);
3355 return $globals.world.varType;
3356 }
3357 var typeArgs = [];
3358 for (var i = (0);
3359 i < typeRef.typeArguments.get$length(); i++) {
3360 typeArgs.add(this.resolveType(typeRef.typeArguments.$index(i), typeErrors, allowTypeParams));
3361 }
3362 return baseType.getOrMakeConcreteType(typeArgs);
3363 }
3364 else if ((node instanceof FunctionTypeReference)) {
3365 var typeRef = node;
3366 var name = "";
3367 if (typeRef.func.name != null) {
3368 name = typeRef.func.name.name;
3369 }
3370 return this.get$library().getOrAddFunctionType(this, name, typeRef.func, nul l);
3371 }
3372 $globals.world.internalError("unexpected TypeReference", node.span);
3373 }
3374 // ********** Code for ExistingJsGlobal **************
3375 $inherits(ExistingJsGlobal, Element);
3376 function ExistingJsGlobal(name, declaringElement) {
3377 this.declaringElement = declaringElement;
3378 Element.call(this, name, null);
3379 }
3380 ExistingJsGlobal.prototype.get$isNative = function() {
3381 return true;
3382 }
3383 ExistingJsGlobal.prototype.get$jsnamePriority = function() {
3384 return (10);
3385 }
3386 ExistingJsGlobal.prototype.get$span = function() {
3387 return this.declaringElement.get$span();
3388 }
3389 ExistingJsGlobal.prototype.get$library = function() {
3390 return this.declaringElement.get$library();
3391 }
3392 // ********** Code for WorldGenerator **************
3393 function WorldGenerator(main, writer) {
3394 this.hasStatics = false;
3395 this.writer = writer;
3396 this.main = main;
3397 this.mainContext = new MethodGenerator(main, null);
3398 this.globals = new HashMapImplementation();
3399 this.corejs = new CoreJs();
3400 }
3401 WorldGenerator.prototype.get$writer = function() { return this.writer; };
3402 WorldGenerator.prototype.set$writer = function(value) { return this.writer = val ue; };
3403 WorldGenerator.prototype.analyze = function() {
3404 var nlibs = (0), ntypes = (0), nmems = (0), nnews = (0);
3405 var $$list = $globals.world.libraries.getValues();
3406 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3407 var lib = $$i.next();
3408 nlibs += (1);
3409 var $list0 = lib.get$types().getValues();
3410 for (var $i0 = $list0.iterator(); $i0.hasNext(); ) {
3411 var type = $i0.next();
3412 if (type.get$library().get$isDom() || type.get$isHiddenNativeType()) {
3413 if (type.get$isClass()) type.markUsed();
3414 }
3415 ntypes += (1);
3416 var allMembers = [];
3417 allMembers.addAll(type.get$constructors().getValues());
3418 allMembers.addAll(type.get$members().getValues());
3419 type.get$factories().forEach((function (allMembers, f) {
3420 return allMembers.add(f);
3421 }).bind(null, allMembers)
3422 );
3423 for (var $i1 = allMembers.iterator(); $i1.hasNext(); ) {
3424 var m = $i1.next();
3425 if (m.get$isAbstract() || !(m.get$isMethod() || m.get$isConstructor())) continue;
3426 m.get$methodData().analyze();
3427 }
3428 }
3429 }
3430 }
3431 WorldGenerator.prototype.run = function() {
3432 var mainTarget = new TypeValue(this.main.declaringType, this.main.get$span());
3433 var mainCall = this.main.invoke(this.mainContext, null, mainTarget, Arguments. get$EMPTY());
3434 this.main.declaringType.markUsed();
3435 if ($globals.options.compileAll) {
3436 this.markLibrariesUsed([$globals.world.coreimpl, $globals.world.corelib, thi s.main.declaringType.get$library()]);
3437 }
3438 $globals.world.numImplType.markUsed();
3439 $globals.world.stringImplType.markUsed();
3440 if (this.corejs.useIndex || this.corejs.useSetIndex) {
3441 if (!$globals.options.disableBoundsChecks) {
3442 this.markTypeUsed($globals.world.corelib.types.$index("IndexOutOfRangeExce ption"));
3443 this.markTypeUsed($globals.world.corelib.types.$index("IllegalArgumentExce ption"));
3444 }
3445 }
3446 if ($globals.world.isolatelib != null) {
3447 this.corejs.useIsolates = true;
3448 var isolateMain = $globals.world.isolatelib.lookup("startRootIsolate", this. main.get$span());
3449 mainCall = isolateMain.invoke(this.mainContext, null, new TypeValue($globals .world.isolatelib.topType, this.main.get$span()), new Arguments(null, [this.main ._get(this.mainContext, this.main.definition, null)]));
3450 }
3451 this.typeEmittedTests = new HashMapImplementation_Type$Map_dart_core_String$bo ol();
3452 this.writeTypes($globals.world.coreimpl);
3453 this.writeTypes($globals.world.corelib);
3454 this.writeTypes(this.main.declaringType.get$library());
3455 if (this._mixins != null) this.writer.write(this._mixins.get$text());
3456 this.writeDynamicDispatchMetadata();
3457 this.writeGlobals();
3458 this.writer.writeln("if (typeof window != 'undefined' && typeof document != 'u ndefined' &&");
3459 this.writer.writeln(" window.addEventListener && document.readyState == 'lo ading') {");
3460 this.writer.writeln(" window.addEventListener('DOMContentLoaded', function(e) {");
3461 this.writer.writeln((" " + mainCall.get$code() + ";"));
3462 this.writer.writeln(" });");
3463 this.writer.writeln("} else {");
3464 this.writer.writeln((" " + mainCall.get$code() + ";"));
3465 this.writer.writeln("}");
3466 }
3467 WorldGenerator.prototype.markLibrariesUsed = function(libs) {
3468 return this.getAllTypes(libs).forEach(this.get$markTypeUsed());
3469 }
3470 WorldGenerator.prototype.markTypeUsed = function(type) {
3471 if (!type.get$isClass()) return;
3472 type.markUsed();
3473 type.isTested = true;
3474 type.isTested = !type.get$isTop() && !(type.get$isNative() && type.get$members ().getValues().every((function (m) {
3475 return m.get$isStatic() && !m.get$isFactory();
3476 })
3477 ));
3478 var members = ListFactory.ListFactory$from$factory(type.get$members().getValue s());
3479 members.addAll(type.get$constructors().getValues());
3480 type.get$factories().forEach((function (f) {
3481 return members.add(f);
3482 })
3483 );
3484 for (var $$i = members.iterator(); $$i.hasNext(); ) {
3485 var member = $$i.next();
3486 if ((member instanceof PropertyMember)) {
3487 if (member.get$getter() != null) this.genMethod(member.get$getter());
3488 if (member.get$setter() != null) this.genMethod(member.get$setter());
3489 }
3490 if ((member instanceof MethodMember)) this.genMethod(member);
3491 }
3492 }
3493 WorldGenerator.prototype.get$markTypeUsed = function() {
3494 return this.markTypeUsed.bind(this);
3495 }
3496 WorldGenerator.prototype.getAllTypes = function(libs) {
3497 var types = [];
3498 var seen = new HashSetImplementation_Library();
3499 for (var $$i = libs.iterator(); $$i.hasNext(); ) {
3500 var mainLib = $$i.next();
3501 var toCheck = DoubleLinkedQueue.DoubleLinkedQueue$from$factory([mainLib]);
3502 while (!toCheck.isEmpty()) {
3503 var lib = toCheck.removeFirst();
3504 if (seen.contains(lib)) continue;
3505 seen.add(lib);
3506 lib.get$imports().forEach((function (lib, toCheck, i) {
3507 return toCheck.addLast(lib);
3508 }).bind(null, lib, toCheck)
3509 );
3510 lib.get$types().getValues().forEach((function (t) {
3511 return types.add(t);
3512 })
3513 );
3514 }
3515 }
3516 return types;
3517 }
3518 WorldGenerator.prototype.globalForStaticField = function(field, exp, dependencie s) {
3519 this.hasStatics = true;
3520 var key = ("" + field.declaringType.get$jsname() + "." + field.get$jsname());
3521 var ret = this.globals.$index(key);
3522 if (null == ret) {
3523 ret = new GlobalValue(exp.get$type(), exp.get$code(), field.isFinal, field, null, exp, exp.span, dependencies);
3524 this.globals.$setindex(key, ret);
3525 }
3526 return ret;
3527 }
3528 WorldGenerator.prototype.globalForConst = function(exp, dependencies) {
3529 var key = ("" + exp.get$type().get$jsname() + ":" + exp.get$code());
3530 var ret = this.globals.$index(key);
3531 if (null == ret) {
3532 var ns = this.globals.get$length().toString$0();
3533 while (ns.get$length() < (4)) ns = ("0" + ns);
3534 var name = ("const$" + ns);
3535 ret = new GlobalValue(exp.get$type(), name, true, null, name, exp, exp.span, dependencies);
3536 this.globals.$setindex(key, ret);
3537 }
3538 return ret;
3539 }
3540 WorldGenerator.prototype.writeTypes = function(lib) {
3541 if (lib.isWritten) return;
3542 lib.isWritten = true;
3543 var $$list = lib.imports;
3544 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3545 var import_ = $$i.next();
3546 this.writeTypes(import_.get$library());
3547 }
3548 for (var i = (0);
3549 i < lib.sources.get$length(); i++) {
3550 lib.sources.$index(i).orderInLibrary = i;
3551 }
3552 this.writer.comment(("// ********** Library " + lib.name + " **************") );
3553 if (lib.get$isCore()) {
3554 this.writer.comment("// ********** Natives dart:core **************");
3555 this.corejs.generate(this.writer);
3556 }
3557 var $$list = lib.natives;
3558 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3559 var file = $$i.next();
3560 var filename = basename(file.get$filename());
3561 this.writer.comment(("// ********** Natives " + filename + " ************** "));
3562 this.writer.writeln(file.get$text());
3563 }
3564 lib.topType.markUsed();
3565 var orderedTypes = this._orderValues(lib.types);
3566 for (var $$i = orderedTypes.iterator(); $$i.hasNext(); ) {
3567 var type = $$i.next();
3568 if (type.get$isUsed() && type.get$isClass()) {
3569 this.writeType(type);
3570 if (type.get$isGeneric() && (null == type ? null != ($globals.world.listFa ctoryType) : type !== $globals.world.listFactoryType)) {
3571 var $$list = this._orderValues(type.get$_concreteTypes());
3572 for (var $i0 = $$list.iterator(); $i0.hasNext(); ) {
3573 var ct = $i0.next();
3574 if (ct.get$isUsed()) this.writeType(ct);
3575 }
3576 }
3577 }
3578 else if (type.get$isFunction() && type.get$varStubs().get$length() > (0)) {
3579 this.writer.comment(("// ********** Code for " + type.get$jsname() + " *** ***********"));
3580 this._writeDynamicStubs(type);
3581 }
3582 if (type.get$typeCheckCode() != null) {
3583 this.writer.writeln(type.get$typeCheckCode());
3584 }
3585 }
3586 }
3587 WorldGenerator.prototype.genMethod = function(meth) {
3588 meth.get$methodData().run(meth);
3589 }
3590 WorldGenerator.prototype._prototypeOf = function(type, name) {
3591 if (type.get$isSingletonNative()) {
3592 return ("" + type.get$jsname() + "." + name);
3593 }
3594 else if (type.get$isHiddenNativeType()) {
3595 this.corejs.ensureDynamicProto();
3596 this._usedDynamicDispatchOnType(type);
3597 return ("$dynamic(\"" + name + "\")." + type.get$definition().get$nativeType ().name);
3598 }
3599 else {
3600 return ("" + type.get$jsname() + ".prototype." + name);
3601 }
3602 }
3603 WorldGenerator.prototype._writePrototypePatch = function(type, name, functionBod y, writer, isOneLiner) {
3604 var $0;
3605 var writeFunction = writer.get$writeln();
3606 var ending = ";";
3607 if (!isOneLiner) {
3608 writeFunction = writer.get$enterBlock();
3609 ending = "";
3610 }
3611 if (type.get$isObject()) {
3612 ($0 = $globals.world.counters).objectProtoMembers = $0.objectProtoMembers + (1);
3613 }
3614 if (type.get$isObject() || $eq$(type.get$genericType(), $globals.world.listFac toryType)) {
3615 if (isOneLiner) {
3616 ending = (")" + ending);
3617 }
3618 this.corejs.ensureDefProp();
3619 writeFunction.call$1(("$defProp(" + type.get$jsname() + ".prototype, \"" + n ame + "\", " + functionBody + ending));
3620 if (isOneLiner) return "}";
3621 return "});";
3622 }
3623 else {
3624 writeFunction.call$1(("" + this._prototypeOf(type, name) + " = " + functionB ody + ending));
3625 return isOneLiner ? "" : "}";
3626 }
3627 }
3628 WorldGenerator.prototype._maybeIsTest = function(onType, checkType) {
3629 var $this = this; // closure support
3630 var isSubtype = onType.isSubtypeOf(checkType);
3631 var onTypeMap = this.typeEmittedTests.$index(onType);
3632 if ($eq$(onTypeMap)) this.typeEmittedTests.$setindex(onType, onTypeMap = new H ashMapImplementation());
3633 var protoParent = $eq$(onType.get$genericType(), onType) ? onType.get$parent() : onType.get$genericType();
3634 function needToOverride(checkName) {
3635 if (protoParent != null) {
3636 var map0 = $this.typeEmittedTests.$index(protoParent);
3637 if ($ne$(map0)) {
3638 var protoParentIsSubtype = map0.$index(checkName);
3639 if (protoParentIsSubtype != null && $eq$(protoParentIsSubtype, isSubtype )) {
3640 return false;
3641 }
3642 }
3643 }
3644 return true;
3645 }
3646 if (checkType.isTested) {
3647 var checkName = ("is$" + checkType.get$jsname());
3648 onTypeMap.$setindex(checkName, isSubtype);
3649 if (needToOverride(checkName)) {
3650 this._writePrototypePatch(onType, checkName, ("function(){return " + isSub type + "}"), this.writer, true);
3651 }
3652 }
3653 if (checkType.isChecked) {
3654 var checkName = ("assert$" + checkType.get$jsname());
3655 onTypeMap.$setindex(checkName, isSubtype);
3656 if (needToOverride(checkName)) {
3657 var body = "return this";
3658 if (!isSubtype) {
3659 body = $globals.world.objectType.varStubs.$index(checkName).get$body();
3660 }
3661 else if ($eq$(onType, $globals.world.stringImplType) || $eq$(onType, $glob als.world.numImplType)) {
3662 body = ("return " + onType.get$nativeType().name + "(this)");
3663 }
3664 this._writePrototypePatch(onType, checkName, ("function(){" + body + "}"), this.writer, true);
3665 }
3666 }
3667 }
3668 WorldGenerator.prototype.writeType = function(type) {
3669 var $0, $1;
3670 if (type.isWritten) return;
3671 type.isWritten = true;
3672 this.writeType(type.get$genericType());
3673 if (type.get$parent() != null) {
3674 this.writeType(type.get$parent());
3675 }
3676 var typeName = type.get$jsname() != null ? type.get$jsname() : "top level";
3677 this.writer.comment(("// ********** Code for " + typeName + " **************") );
3678 if (type.get$isNative() && !type.get$isTop() && !type.get$isConcreteGeneric()) {
3679 var nativeName = type.get$definition().get$nativeType().name;
3680 if ($eq$(nativeName, "")) {
3681 this.writer.writeln(("function " + type.get$jsname() + "() {}"));
3682 }
3683 else if (type.get$jsname() != nativeName) {
3684 if (type.get$isHiddenNativeType()) {
3685 if (this._hasStaticOrFactoryMethods(type)) {
3686 this.writer.writeln(("var " + type.get$jsname() + " = {};"));
3687 }
3688 }
3689 else {
3690 this.writer.writeln(("" + type.get$jsname() + " = " + nativeName + ";")) ;
3691 }
3692 }
3693 }
3694 if (!type.get$isTop()) {
3695 if ((($0 = type.get$genericType()) == null ? null != (type) : $0 !== type)) {
3696 this.corejs.ensureInheritsHelper();
3697 this.writer.writeln(("$inherits(" + type.get$jsname() + ", " + type.get$ge nericType().get$jsname() + ");"));
3698 }
3699 else if (!type.get$isNative()) {
3700 if (type.get$parent() != null && !type.get$parent().get$isObject()) {
3701 this.corejs.ensureInheritsHelper();
3702 this.writer.writeln(("$inherits(" + type.get$jsname() + ", " + type.get$ parent().get$jsname() + ");"));
3703 }
3704 }
3705 }
3706 if (type.get$isTop()) {
3707 }
3708 else if (type.get$constructors().get$length() == (0)) {
3709 if (!type.get$isNative() || type.get$isConcreteGeneric()) {
3710 this.writer.writeln(("function " + type.get$jsname() + "() {}"));
3711 }
3712 }
3713 else {
3714 var wroteStandard = false;
3715 var $$list = type.get$constructors().getValues();
3716 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3717 var c = $$i.next();
3718 if (c.get$methodData().writeDefinition(c, this.writer)) {
3719 if (c.get$isConstructor() && c.get$constructorName() == "") wroteStandar d = true;
3720 }
3721 }
3722 if (!wroteStandard && (!type.get$isNative() || (($1 = type.get$genericType() ) == null ? null != (type) : $1 !== type))) {
3723 this.writer.writeln(("function " + type.get$jsname() + "() {}"));
3724 }
3725 }
3726 if (!type.get$isConcreteGeneric()) {
3727 this._maybeIsTest(type, type);
3728 }
3729 if (type.get$genericType()._concreteTypes != null) {
3730 var $$list = this._orderValues(type.get$genericType()._concreteTypes);
3731 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3732 var ct = $$i.next();
3733 this._maybeIsTest(type, ct);
3734 }
3735 }
3736 if (type.get$interfaces() != null) {
3737 var seen = new HashSetImplementation();
3738 var worklist = [];
3739 worklist.addAll(type.get$interfaces());
3740 seen.addAll(type.get$interfaces());
3741 while (!worklist.isEmpty()) {
3742 var interface_ = worklist.removeLast();
3743 this._maybeIsTest(type, interface_.get$genericType());
3744 if (interface_.get$genericType()._concreteTypes != null) {
3745 var $$list = this._orderValues(interface_.get$genericType()._concreteTyp es);
3746 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3747 var ct = $$i.next();
3748 this._maybeIsTest(type, ct);
3749 }
3750 }
3751 var $$list = interface_.get$interfaces();
3752 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3753 var other = $$i.next();
3754 if (!seen.contains$1(other)) {
3755 worklist.addLast(other);
3756 seen.add(other);
3757 }
3758 }
3759 }
3760 }
3761 type.get$factories().forEach(this.get$_writeMethod());
3762 var $$list = this._orderValues(type.get$members());
3763 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3764 var member = $$i.next();
3765 if ((member instanceof FieldMember)) {
3766 this._writeField(member);
3767 }
3768 if ((member instanceof PropertyMember)) {
3769 this._writeProperty(member);
3770 }
3771 if (member.get$isMethod()) {
3772 this._writeMethod(member);
3773 }
3774 }
3775 this._writeDynamicStubs(type);
3776 }
3777 WorldGenerator.prototype._hasStaticOrFactoryMethods = function(type) {
3778 return type.get$members().getValues().some((function (m) {
3779 return m.get$isMethod() && m.get$isStatic();
3780 })
3781 ) || !type.get$factories().isEmpty();
3782 }
3783 WorldGenerator.prototype._writeDynamicStubs = function(type) {
3784 var $$list = orderValuesByKeys(type.varStubs);
3785 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3786 var stub = $$i.next();
3787 if (!stub.get$isGenerated()) stub.generate(this.writer);
3788 }
3789 }
3790 WorldGenerator.prototype._writeStaticField = function(field) {
3791 if (field.isFinal) return;
3792 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname ());
3793 if (this.globals.containsKey(fullname)) {
3794 var value = this.globals.$index(fullname);
3795 if (field.declaringType.get$isTop() && !field.isNative) {
3796 this.writer.writeln(("$globals." + field.get$jsname() + " = " + value.get$ exp().get$code() + ";"));
3797 }
3798 else {
3799 this.writer.writeln($add$(("$globals." + field.declaringType.get$jsname() + "_" + field.get$jsname()), (" = " + value.get$exp().get$code() + ";")));
3800 }
3801 }
3802 }
3803 WorldGenerator.prototype._writeField = function(field) {
3804 if (field.declaringType.get$isTop() && !field.isNative && field.value == null) {
3805 this.writer.writeln(("var " + field.get$jsname() + ";"));
3806 }
3807 if (field._provideGetter && !field.declaringType.get$isConcreteGeneric()) {
3808 this._writePrototypePatch(field.declaringType, ("get$" + field.get$jsname()) , ("function() { return this." + field.get$jsname() + "; }"), this.writer, true) ;
3809 }
3810 if (field._provideSetter && !field.declaringType.get$isConcreteGeneric()) {
3811 this._writePrototypePatch(field.declaringType, ("set$" + field.get$jsname()) , ("function(value) { return this." + field.get$jsname() + " = value; }"), this. writer, true);
3812 }
3813 }
3814 WorldGenerator.prototype._writeProperty = function(property) {
3815 if (property.getter != null) this._writeMethod(property.getter);
3816 if (property.setter != null) this._writeMethod(property.setter);
3817 if (property.get$needsFieldSyntax()) {
3818 this.writer.enterBlock(("Object.defineProperty(" + ("" + property.declaringT ype.get$jsname() + ".prototype, \"" + property.get$jsname() + "\", {")));
3819 if (property.getter != null) {
3820 this.writer.write(("get: " + property.declaringType.get$jsname() + ".proto type." + property.getter.get$jsname()));
3821 this.writer.writeln(property.setter == null ? "" : ",");
3822 }
3823 if (property.setter != null) {
3824 this.writer.writeln(("set: " + property.declaringType.get$jsname() + ".pro totype." + property.setter.get$jsname()));
3825 }
3826 this.writer.exitBlock("});");
3827 }
3828 }
3829 WorldGenerator.prototype._writeMethod = function(m) {
3830 m.get$methodData().writeDefinition(m, this.writer);
3831 if (m.get$isNative() && m._provideGetter) {
3832 if (MethodGenerator._maybeGenerateBoundGetter(m, this.writer)) {
3833 $globals.world.gen.corejs.ensureBind();
3834 }
3835 }
3836 }
3837 WorldGenerator.prototype.get$_writeMethod = function() {
3838 return this._writeMethod.bind(this);
3839 }
3840 WorldGenerator.prototype.writeGlobals = function() {
3841 if (this.globals.get$length() > (0)) {
3842 this.writer.comment("// ********** Globals **************");
3843 var list = this.globals.getValues();
3844 list.sort((function (a, b) {
3845 return a.compareTo(b);
3846 })
3847 );
3848 this.writer.enterBlock("function $static_init(){");
3849 for (var $$i = list.iterator(); $$i.hasNext(); ) {
3850 var global = $$i.next();
3851 if (global.get$field() != null) {
3852 this._writeStaticField(global.get$field());
3853 }
3854 }
3855 this.writer.exitBlock("}");
3856 for (var $$i = list.iterator(); $$i.hasNext(); ) {
3857 var global = $$i.next();
3858 if (global.get$field() == null) {
3859 this.writer.writeln(("var " + global.get$name() + " = " + global.get$exp ().get$code() + ";"));
3860 }
3861 }
3862 }
3863 if (!this.corejs.useIsolates) {
3864 if (this.hasStatics) {
3865 this.writer.writeln("var $globals = {};");
3866 }
3867 if (this.globals.get$length() > (0)) {
3868 this.writer.writeln("$static_init();");
3869 }
3870 }
3871 }
3872 WorldGenerator.prototype._usedDynamicDispatchOnType = function(type) {
3873 if (this.typesWithDynamicDispatch == null) this.typesWithDynamicDispatch = new HashSetImplementation();
3874 this.typesWithDynamicDispatch.add(type);
3875 }
3876 WorldGenerator.prototype.writeDynamicDispatchMetadata = function() {
3877 var $this = this; // closure support
3878 if (this.typesWithDynamicDispatch == null) return;
3879 this.writer.comment(("// " + this.typesWithDynamicDispatch.get$length() + " dy namic types."));
3880 var seen = new HashSetImplementation();
3881 var types = [];
3882 function visit(type) {
3883 if (seen.contains$1(type)) return;
3884 seen.add(type);
3885 var $$list = $this._orderCollectionValues(type.get$directSubtypes());
3886 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3887 var subtype = $$i.next();
3888 visit(subtype);
3889 }
3890 types.add(type);
3891 }
3892 var $$list = this._orderCollectionValues(this.typesWithDynamicDispatch);
3893 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3894 var type = $$i.next();
3895 visit(type);
3896 }
3897 var dispatchTypes = types.filter((function (type) {
3898 return !type.get$directSubtypes().isEmpty() && $this.typesWithDynamicDispatc h.contains(type);
3899 })
3900 );
3901 this.writer.comment(("// " + types.get$length() + " types"));
3902 this.writer.comment(("// " + types.filter((function (t) {
3903 return !t.get$directSubtypes().isEmpty();
3904 })
3905 ).get$length() + " !leaf"));
3906 var varNames = [];
3907 var varDefns = new HashMapImplementation();
3908 var tagDefns = new HashMapImplementation();
3909 function makeExpression(type) {
3910 var expressions = [];
3911 var subtags = [type.get$nativeName()];
3912 function walk(type) {
3913 var $$list = $this._orderCollectionValues(type.get$directSubtypes());
3914 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
3915 var subtype = $$i.next();
3916 var tag = subtype.get$nativeName();
3917 var existing = tagDefns.$index(tag);
3918 if ($eq$(existing)) {
3919 subtags.add(tag);
3920 walk(subtype);
3921 }
3922 else {
3923 if (varDefns.containsKey(existing)) {
3924 expressions.add(existing);
3925 }
3926 else {
3927 var varName = ("v" + varNames.get$length() + "/*" + tag + "*/");
3928 varNames.add(varName);
3929 varDefns.$setindex(varName, existing);
3930 tagDefns.$setindex(tag, varName);
3931 expressions.add(varName);
3932 }
3933 }
3934 }
3935 }
3936 walk(type);
3937 var constantPart = ("'" + Strings.join(subtags, "|") + "'");
3938 if ($ne$(constantPart, "''")) expressions.add(constantPart);
3939 var expression;
3940 if (expressions.get$length() == (1)) {
3941 expression = expressions.$index((0));
3942 }
3943 else {
3944 expression = ("[" + Strings.join(expressions, ",") + "].join('|')");
3945 }
3946 return expression;
3947 }
3948 for (var $$i = dispatchTypes.iterator(); $$i.hasNext(); ) {
3949 var type = $$i.next();
3950 tagDefns.$setindex(type.get$nativeName(), makeExpression(type));
3951 }
3952 if (!tagDefns.isEmpty()) {
3953 this.corejs.ensureDynamicSetMetadata();
3954 this.writer.enterBlock("(function(){");
3955 for (var $$i = varNames.iterator(); $$i.hasNext(); ) {
3956 var varName = $$i.next();
3957 this.writer.writeln(("var " + varName + " = " + varDefns.$index(varName) + ";"));
3958 }
3959 this.writer.enterBlock("var table = [");
3960 this.writer.comment("// [dynamic-dispatch-tag, tags of classes implementing dynamic-dispatch-tag]");
3961 var needsComma = false;
3962 for (var $$i = dispatchTypes.iterator(); $$i.hasNext(); ) {
3963 var type = $$i.next();
3964 if (needsComma) {
3965 this.writer.write(", ");
3966 }
3967 this.writer.writeln(("['" + type.get$nativeName() + "', " + tagDefns.$inde x(type.get$nativeName()) + "]"));
3968 needsComma = true;
3969 }
3970 this.writer.exitBlock("];");
3971 this.writer.writeln("$dynamicSetMetadata(table);");
3972 this.writer.exitBlock("})();");
3973 }
3974 }
3975 WorldGenerator.prototype._orderValues = function(map) {
3976 var values = map.getValues();
3977 values.sort(this.get$_compareMembers());
3978 return values;
3979 }
3980 WorldGenerator.prototype._orderCollectionValues = function(collection) {
3981 var values = ListFactory.ListFactory$from$factory(collection);
3982 values.sort(this.get$_compareMembers());
3983 return values;
3984 }
3985 WorldGenerator.prototype._compareMembers = function(x, y) {
3986 if (x.get$span() != null && y.get$span() != null) {
3987 var spans = x.get$span().compareTo(y.get$span());
3988 if (spans != (0)) return spans;
3989 }
3990 else {
3991 if (x.get$span() != null) return (-1);
3992 if (y.get$span() != null) return (1);
3993 }
3994 if ($eq$(x.get$name(), y.get$name())) return (0);
3995 if ($eq$(x.get$name())) return (-1);
3996 if ($eq$(y.get$name())) return (1);
3997 return x.get$name().compareTo(y.get$name());
3998 }
3999 WorldGenerator.prototype.get$_compareMembers = function() {
4000 return this._compareMembers.bind(this);
4001 }
4002 WorldGenerator.prototype.run$0 = WorldGenerator.prototype.run;
4003 // ********** Code for MethodGenerator **************
4004 function MethodGenerator(method, enclosingMethod) {
4005 this.method = method;
4006 this.enclosingMethod = enclosingMethod;
4007 this.writer = new CodeWriter();
4008 this.needsThis = false;
4009 if (this.enclosingMethod != null) {
4010 this._scope = new BlockScope(this, this.enclosingMethod._scope, this.method. get$definition(), false);
4011 this.captures = new HashSetImplementation();
4012 }
4013 else {
4014 this._scope = new BlockScope(this, null, this.method.get$definition(), false );
4015 }
4016 this._usedTemps = new HashSetImplementation();
4017 this._freeTemps = [];
4018 this.counters = $globals.world.counters;
4019 }
4020 MethodGenerator.prototype.get$method = function() { return this.method; };
4021 MethodGenerator.prototype.get$writer = function() { return this.writer; };
4022 MethodGenerator.prototype.set$writer = function(value) { return this.writer = va lue; };
4023 MethodGenerator.prototype.get$_scope = function() { return this._scope; };
4024 MethodGenerator.prototype.get$enclosingMethod = function() { return this.enclosi ngMethod; };
4025 MethodGenerator.prototype.set$needsThis = function(value) { return this.needsThi s = value; };
4026 MethodGenerator.prototype.set$_paramCode = function(value) { return this._paramC ode = value; };
4027 MethodGenerator.prototype.get$counters = function() { return this.counters; };
4028 MethodGenerator.prototype.get$library = function() {
4029 return this.method.get$library();
4030 }
4031 MethodGenerator.prototype.findMembers = function(name) {
4032 return this.get$library()._findMembers(name);
4033 }
4034 MethodGenerator.prototype.get$needsCode = function() {
4035 return true;
4036 }
4037 MethodGenerator.prototype.get$showWarnings = function() {
4038 return false;
4039 }
4040 MethodGenerator.prototype.get$isClosure = function() {
4041 return (this.enclosingMethod != null);
4042 }
4043 MethodGenerator.prototype.get$isStatic = function() {
4044 return this.method.get$isStatic();
4045 }
4046 MethodGenerator.prototype.getTemp = function(value) {
4047 return value.get$needsTemp() ? this.forceTemp(value) : value;
4048 }
4049 MethodGenerator.prototype.forceTemp = function(value) {
4050 var name;
4051 if (this._freeTemps.get$length() > (0)) {
4052 name = this._freeTemps.removeLast();
4053 }
4054 else {
4055 name = ("$" + this._usedTemps.get$length());
4056 }
4057 this._usedTemps.add(name);
4058 return new VariableValue(value.get$staticType(), name, value.span, false, valu e);
4059 }
4060 MethodGenerator.prototype.assignTemp = function(tmp, v) {
4061 if ($eq$(tmp, v)) {
4062 return v;
4063 }
4064 else {
4065 return new Value(v.get$type(), ("(" + tmp.get$code() + " = " + v.get$code() + ")"), v.span);
4066 }
4067 }
4068 MethodGenerator.prototype.freeTemp = function(value) {
4069
4070 }
4071 MethodGenerator.prototype.run = function() {
4072 var thisObject;
4073 if (this.method.get$isConstructor()) {
4074 thisObject = new ObjectValue(false, this.method.declaringType, this.method.g et$span());
4075 thisObject.initFields();
4076 }
4077 else {
4078 thisObject = new Value(this.method.declaringType, "this", null);
4079 }
4080 var values = [];
4081 var $$list = this.method.get$parameters();
4082 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4083 var p = $$i.next();
4084 values.add(new Value(p.get$type(), p.get$name(), null));
4085 }
4086 var args = new Arguments(null, values);
4087 this.evalBody(thisObject, args);
4088 }
4089 MethodGenerator.prototype.writeDefinition = function(defWriter, lambda) {
4090 var paramCode = this._paramCode;
4091 var names = null;
4092 if (this.captures != null && this.captures.get$length() > (0)) {
4093 names = ListFactory.ListFactory$from$factory(this.captures);
4094 names.sort((function (x, y) {
4095 return x.compareTo(y);
4096 })
4097 );
4098 paramCode = ListFactory.ListFactory$from$factory(names);
4099 paramCode.addAll(this._paramCode);
4100 }
4101 var _params = ("(" + Strings.join(this._paramCode, ", ") + ")");
4102 var params = ("(" + Strings.join(paramCode, ", ") + ")");
4103 var suffix = "}";
4104 if (this.method.declaringType.get$isTop() && !this.get$isClosure()) {
4105 defWriter.enterBlock(("function " + this.method.get$jsname() + params + " {" ));
4106 }
4107 else if (this.get$isClosure()) {
4108 if (this.method.name == "") {
4109 defWriter.enterBlock(("(function " + params + " {"));
4110 }
4111 else if ($ne$(names)) {
4112 if (lambda == null) {
4113 defWriter.enterBlock(("var " + this.method.get$jsname() + " = (function" + params + " {"));
4114 }
4115 else {
4116 defWriter.enterBlock(("(function " + this.method.get$jsname() + params + " {"));
4117 }
4118 }
4119 else {
4120 defWriter.enterBlock(("function " + this.method.get$jsname() + params + " {"));
4121 }
4122 }
4123 else if (this.method.get$isConstructor()) {
4124 if (this.method.get$constructorName() == "") {
4125 defWriter.enterBlock(("function " + this.method.declaringType.get$jsname() + params + " {"));
4126 }
4127 else {
4128 defWriter.enterBlock(("" + this.method.declaringType.get$jsname() + "." + this.method.get$constructorName() + "$ctor = function" + params + " {"));
4129 }
4130 }
4131 else if (this.method.get$isFactory()) {
4132 defWriter.enterBlock(("" + this.method.get$generatedFactoryName() + " = func tion" + _params + " {"));
4133 }
4134 else if (this.method.get$isStatic()) {
4135 defWriter.enterBlock(("" + this.method.declaringType.get$jsname() + "." + th is.method.get$jsname() + " = function" + _params + " {"));
4136 }
4137 else {
4138 suffix = $globals.world.gen._writePrototypePatch(this.method.declaringType, this.method.get$jsname(), ("function" + _params + " {"), defWriter, false);
4139 }
4140 if (this.needsThis) {
4141 defWriter.writeln("var $this = this; // closure support");
4142 }
4143 if (this._usedTemps.get$length() > (0) || this._freeTemps.get$length() > (0)) {
4144 this._freeTemps.addAll(this._usedTemps);
4145 this._freeTemps.sort((function (x, y) {
4146 return x.compareTo(y);
4147 })
4148 );
4149 defWriter.writeln(("var " + Strings.join(this._freeTemps, ", ") + ";"));
4150 }
4151 defWriter.writeln(this.writer.get$text());
4152 var usesBind = false;
4153 if ($ne$(names)) {
4154 usesBind = true;
4155 defWriter.exitBlock(("}).bind(null, " + Strings.join(names, ", ") + ")"));
4156 }
4157 else if (this.get$isClosure() && this.method.name == "") {
4158 defWriter.exitBlock("})");
4159 }
4160 else {
4161 defWriter.exitBlock(suffix);
4162 }
4163 if (this.method.get$isConstructor() && this.method.get$constructorName() != "" ) {
4164 defWriter.writeln((("" + this.method.declaringType.get$jsname() + "." + this .method.get$constructorName() + "$ctor.prototype = ") + ("" + this.method.declar ingType.get$jsname() + ".prototype;")));
4165 }
4166 this._provideOptionalParamInfo(defWriter);
4167 if ((this.method instanceof MethodMember)) {
4168 if (MethodGenerator._maybeGenerateBoundGetter(this.method, defWriter)) {
4169 usesBind = true;
4170 }
4171 }
4172 if (usesBind) $globals.world.gen.corejs.ensureBind();
4173 }
4174 MethodGenerator._maybeGenerateBoundGetter = function(m, defWriter) {
4175 if (m._provideGetter) {
4176 var suffix = $globals.world.gen._writePrototypePatch(m.declaringType, ("get$ " + m.get$jsname()), "function() {", defWriter, false);
4177 defWriter.writeln(("return this." + m.get$jsname() + ".bind(this);"));
4178 defWriter.exitBlock(suffix);
4179 return true;
4180 }
4181 return false;
4182 }
4183 MethodGenerator.prototype._provideOptionalParamInfo = function(defWriter) {
4184 if ((this.method instanceof MethodMember)) {
4185 var meth = this.method;
4186 if (meth._provideOptionalParamInfo) {
4187 var optNames = [];
4188 var optValues = [];
4189 meth.genParameterValues(this);
4190 var $$list = meth.parameters;
4191 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4192 var param = $$i.next();
4193 if (param.get$isOptional()) {
4194 optNames.add(param.get$name());
4195 optValues.add(MethodGenerator._escapeString(param.get$value().get$code ()));
4196 }
4197 }
4198 if (optNames.get$length() > (0)) {
4199 var start = "";
4200 if (meth.isStatic) {
4201 if (!meth.declaringType.get$isTop()) {
4202 start = $add$(meth.declaringType.get$jsname(), ".");
4203 }
4204 }
4205 else {
4206 start = $add$(meth.declaringType.get$jsname(), ".prototype.");
4207 }
4208 optNames.addAll(optValues);
4209 var optional = ("['" + Strings.join(optNames, "', '") + "']");
4210 defWriter.writeln(("" + start + meth.get$jsname() + ".$optional = " + op tional));
4211 }
4212 }
4213 }
4214 }
4215 MethodGenerator.prototype._initField = function(newObject, name, value, span) {
4216 var field = this.method.declaringType.getMember(name);
4217 if ($eq$(field)) {
4218 $globals.world.error("bad initializer - no matching field", span);
4219 }
4220 if (!field.get$isField()) {
4221 $globals.world.error(("\"this." + name + "\" does not refer to a field"), sp an);
4222 }
4223 return newObject.setField(field, value, true);
4224 }
4225 MethodGenerator.prototype.evalBody = function(newObject, args) {
4226 var fieldsSet = false;
4227 if (this.method.get$isNative() && this.method.get$isConstructor() && (newObjec t instanceof ObjectValue)) {
4228 newObject.get$dynamic().set$seenNativeInitializer(true);
4229 }
4230 this._paramCode = [];
4231 for (var i = (0);
4232 i < this.method.get$parameters().get$length(); i++) {
4233 var p = this.method.get$parameters().$index(i);
4234 var currentArg = null;
4235 if (i < args.get$bareCount()) {
4236 currentArg = args.values.$index(i);
4237 }
4238 else {
4239 currentArg = args.getValue(p.get$name());
4240 if (null == currentArg) {
4241 p.genValue(this.method, this);
4242 currentArg = p.get$value();
4243 if (currentArg == null) {
4244 return;
4245 }
4246 }
4247 }
4248 if (p.get$isInitializer()) {
4249 this._paramCode.add(p.get$name());
4250 fieldsSet = true;
4251 this._initField(newObject, p.get$name(), currentArg, p.get$definition().ge t$span());
4252 }
4253 else {
4254 var paramValue = this._scope.declareParameter(p);
4255 this._paramCode.add(paramValue.get$code());
4256 if (newObject != null && newObject.get$isConst()) {
4257 this._scope.assign(p.get$name(), currentArg.convertTo(this, p.get$type() ));
4258 }
4259 }
4260 }
4261 var initializerCall = null;
4262 var declaredInitializers = this.method.get$definition().get$dynamic().get$init ializers();
4263 if ($ne$(declaredInitializers)) {
4264 for (var $$i = declaredInitializers.iterator(); $$i.hasNext(); ) {
4265 var init = $$i.next();
4266 if ((init instanceof CallExpression)) {
4267 if ($ne$(initializerCall)) {
4268 $globals.world.error("only one initializer redirecting call is allowed ", init.get$span());
4269 }
4270 initializerCall = init;
4271 }
4272 else if ((init instanceof BinaryExpression) && TokenKind.kindFromAssign(in it.get$op().kind) == (0)) {
4273 var left = init.get$x();
4274 if (!((left instanceof DotExpression) && (left.get$self() instanceof Thi sExpression) || (left instanceof VarExpression))) {
4275 $globals.world.error("invalid left side of initializer", left.get$span ());
4276 continue;
4277 }
4278 var initValue = this.visitValue(init.get$y());
4279 fieldsSet = true;
4280 this._initField(newObject, left.get$name().get$name(), initValue, left.g et$span());
4281 }
4282 else {
4283 $globals.world.error("invalid initializer", init.get$span());
4284 }
4285 }
4286 }
4287 if (this.method.get$isConstructor() && $eq$(initializerCall) && !this.method.g et$isNative()) {
4288 var parentType = this.method.declaringType.get$parent();
4289 if ($ne$(parentType) && !parentType.get$isObject()) {
4290 initializerCall = new CallExpression(new SuperExpression(this.method.get$s pan()), [], this.method.get$span());
4291 }
4292 }
4293 if (this.method.get$isConstructor() && (newObject instanceof ObjectValue)) {
4294 var fields = newObject.get$dynamic().get$fields();
4295 var $$list = newObject.get$dynamic().get$fieldsInInitOrder();
4296 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4297 var field = $$i.next();
4298 if (null != field) {
4299 var value = fields.$index(field);
4300 if (null != value) {
4301 this.writer.writeln(("this." + field.get$jsname() + " = " + value.get$ code() + ";"));
4302 }
4303 }
4304 }
4305 }
4306 if ($ne$(initializerCall)) {
4307 this.evalInitializerCall(newObject, initializerCall, fieldsSet);
4308 }
4309 if (this.method.get$isConstructor() && null != newObject && newObject.get$isCo nst()) {
4310 newObject.validateInitialized(this.method.get$span());
4311 }
4312 else if (this.method.get$isConstructor()) {
4313 var fields = newObject.get$dynamic().get$fields();
4314 var $$list = fields.getKeys();
4315 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4316 var field = $$i.next();
4317 var value = fields.$index(field);
4318 if (null == value && field.get$isFinal() && $eq$(field.get$declaringType() , this.method.declaringType) && !newObject.get$dynamic().get$seenNativeInitializ er()) {
4319 $globals.world.error(("uninitialized final field \"" + field.get$name() + "\""), field.get$span(), this.method.get$span());
4320 }
4321 }
4322 }
4323 var body = this.method.get$definition().get$dynamic().get$body();
4324 if (null == body) {
4325 if (!this.method.get$isConstructor() && !this.method.get$isNative()) {
4326 $globals.world.error(("unexpected empty body for " + this.method.name), th is.method.get$definition().get$span());
4327 }
4328 }
4329 else {
4330 this.visitStatementsInBlock(body);
4331 }
4332 }
4333 MethodGenerator.prototype.evalInitializerCall = function(newObject, node, fields Set) {
4334 var contructorName = "";
4335 var targetExp = node.target;
4336 if ((targetExp instanceof DotExpression)) {
4337 var dot = targetExp;
4338 targetExp = dot.self;
4339 contructorName = dot.name.name;
4340 }
4341 var targetType = null;
4342 var target = null;
4343 if ((targetExp instanceof SuperExpression)) {
4344 targetType = this.method.declaringType.get$parent();
4345 target = this._makeSuperValue(targetExp);
4346 }
4347 else if ((targetExp instanceof ThisExpression)) {
4348 targetType = this.method.declaringType;
4349 target = this._makeThisValue(targetExp);
4350 if (fieldsSet) {
4351 $globals.world.error("no initialization allowed with redirecting construct or", node.span);
4352 }
4353 }
4354 else {
4355 $globals.world.error("bad call in initializers", node.span);
4356 }
4357 var m = targetType.getConstructor(contructorName);
4358 if ($eq$(m)) {
4359 $globals.world.error(("no matching constructor for " + targetType.name), nod e.span);
4360 }
4361 this.method.set$initDelegate(m);
4362 var other = m;
4363 while ($ne$(other)) {
4364 if ($eq$(other, this.method)) {
4365 $globals.world.error("initialization cycle", node.span);
4366 break;
4367 }
4368 other = other.get$initDelegate();
4369 }
4370 var newArgs = this._makeArgs(node.arguments);
4371 $globals.world.gen.genMethod(m);
4372 m._evalConstConstructor(newObject, newArgs);
4373 if (!newObject.isConst) {
4374 var value = m.invoke(this, node, target, newArgs);
4375 if ($ne$(target.get$type(), $globals.world.objectType)) {
4376 this.writer.writeln(("" + value.get$code() + ";"));
4377 }
4378 }
4379 }
4380 MethodGenerator.prototype._makeArgs = function(arguments) {
4381 var args = [];
4382 var seenLabel = false;
4383 for (var $$i = arguments.iterator(); $$i.hasNext(); ) {
4384 var arg = $$i.next();
4385 if (arg.get$label() != null) {
4386 seenLabel = true;
4387 }
4388 else if (seenLabel) {
4389 $globals.world.error("bare argument cannot follow named arguments", arg.ge t$span());
4390 }
4391 args.add(this.visitValue(arg.get$value()));
4392 }
4393 return new Arguments(arguments, args);
4394 }
4395 MethodGenerator.prototype._invokeNative = function(name, arguments) {
4396 var args = Arguments.get$EMPTY();
4397 if (arguments.get$length() > (0)) {
4398 args = new Arguments(null, arguments);
4399 }
4400 var method = $globals.world.corelib.topType.members.$index(name);
4401 return method.invoke(this, method.get$definition(), new Value($globals.world.c orelib.topType, null, null), args);
4402 }
4403 MethodGenerator._escapeString = function(text) {
4404 return text.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"").replaceAll("\n", "\\n").replaceAll("\r", "\\r");
4405 }
4406 MethodGenerator.prototype.visitStatementsInBlock = function(body) {
4407 if ((body instanceof BlockStatement)) {
4408 var block = body;
4409 var $$list = block.body;
4410 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4411 var stmt = $$i.next();
4412 stmt.visit(this);
4413 }
4414 }
4415 else {
4416 if (body != null) body.visit(this);
4417 }
4418 return false;
4419 }
4420 MethodGenerator.prototype._pushBlock = function(node, reentrant) {
4421 this._scope = new BlockScope(this, this._scope, node, reentrant);
4422 }
4423 MethodGenerator.prototype._popBlock = function(node) {
4424 var $0;
4425 if ((($0 = this._scope.node) == null ? null != (node) : $0 !== node)) {
4426 function spanOf(n) {
4427 return $ne$(n) ? n.get$span() : null;
4428 }
4429 $globals.world.internalError($add$(("scope mismatch. Trying to pop \"" + nod e + "\" but found "), (" \"" + this._scope.node + "\"")), spanOf(node), spanOf(t his._scope.node));
4430 }
4431 this._scope = this._scope.parent;
4432 }
4433 MethodGenerator.prototype._visitLoop = function(node, visitBody) {
4434 if (this._scope.inferTypes) {
4435 this._loopFixedPoint(node, visitBody);
4436 }
4437 else {
4438 this._pushBlock(node, true);
4439 visitBody();
4440 this._popBlock(node);
4441 }
4442 }
4443 MethodGenerator.prototype._loopFixedPoint = function(node, visitBody) {
4444 var savedCounters = this.counters;
4445 var savedWriter = this.writer;
4446 var tries = (0);
4447 var startScope = this._scope.snapshot();
4448 var s = startScope;
4449 while (true) {
4450 this.writer = new CodeWriter();
4451 this.counters = new CounterLog();
4452 this._pushBlock(node, true);
4453 if (tries++ >= $globals.options.maxInferenceIterations) {
4454 this._scope.inferTypes = false;
4455 }
4456 visitBody();
4457 this._popBlock(node);
4458 if (!this._scope.inferTypes || !this._scope.unionWith(s)) {
4459 break;
4460 }
4461 s = this._scope.snapshot();
4462 }
4463 savedWriter.write$1(this.writer.get$text());
4464 this.writer = savedWriter;
4465 savedCounters.add(this.counters);
4466 this.counters = savedCounters;
4467 }
4468 MethodGenerator.prototype._makeLambdaMethod = function(name, func) {
4469 var meth = new MethodMember.lambda$ctor(name, this.method.declaringType, func) ;
4470 meth.set$enclosingElement(this.method);
4471 meth.set$_methodData(new MethodData(meth, this));
4472 meth.resolve();
4473 return meth;
4474 }
4475 MethodGenerator.prototype.visitBool = function(node) {
4476 return this.visitValue(node).convertTo(this, $globals.world.nonNullBool);
4477 }
4478 MethodGenerator.prototype.visitValue = function(node) {
4479 if (node == null) return null;
4480 var value = node.visit(this);
4481 value.checkFirstClass(node.span);
4482 return value;
4483 }
4484 MethodGenerator.prototype.visitTypedValue = function(node, expectedType) {
4485 var val = this.visitValue(node);
4486 return expectedType == null ? val : val.convertTo(this, expectedType);
4487 }
4488 MethodGenerator.prototype.visitVoid = function(node) {
4489 if ((node instanceof PostfixExpression)) {
4490 var value = this.visitPostfixExpression(node, true);
4491 value.checkFirstClass(node.span);
4492 return value;
4493 }
4494 else if ((node instanceof BinaryExpression)) {
4495 var value = this.visitBinaryExpression(node, true);
4496 value.checkFirstClass(node.span);
4497 return value;
4498 }
4499 return this.visitValue(node);
4500 }
4501 MethodGenerator.prototype.visitDietStatement = function(node) {
4502 var parser = new Parser(node.span.file, false, false, false, node.span.start);
4503 this.visitStatementsInBlock(parser.block());
4504 return false;
4505 }
4506 MethodGenerator.prototype.visitVariableDefinition = function(node) {
4507 var isFinal = false;
4508 if (node.modifiers != null && node.modifiers.$index((0)).kind == (99)) {
4509 isFinal = true;
4510 }
4511 this.writer.write("var ");
4512 var type = this.method.resolveType(node.type, false, true);
4513 for (var i = (0);
4514 i < node.names.get$length(); i++) {
4515 if (i > (0)) {
4516 this.writer.write(", ");
4517 }
4518 var name = node.names.$index(i).name;
4519 var value = this.visitValue(node.values.$index(i));
4520 if (isFinal && $eq$(value)) {
4521 $globals.world.error("no value specified for final variable", node.span);
4522 }
4523 var val = this._scope.create(name, type, node.names.$index(i).span, isFinal, false);
4524 if ($eq$(value)) {
4525 if (this._scope.reentrant) {
4526 this.writer.write(("" + val.get$code() + " = null"));
4527 }
4528 else {
4529 this.writer.write(("" + val.get$code()));
4530 }
4531 }
4532 else {
4533 value = value.convertTo(this, type);
4534 this._scope.inferAssign(name, value);
4535 this.writer.write(("" + val.get$code() + " = " + value.get$code()));
4536 }
4537 }
4538 this.writer.writeln(";");
4539 return false;
4540 }
4541 MethodGenerator.prototype.visitFunctionDefinition = function(node) {
4542 var meth = this._makeLambdaMethod(node.name.name, node);
4543 var funcValue = this._scope.create(meth.get$name(), meth.get$functionType(), t his.method.get$definition().get$span(), true, false);
4544 meth.get$methodData().createFunction(this.writer);
4545 return false;
4546 }
4547 MethodGenerator.prototype.visitReturnStatement = function(node) {
4548 if (node.value == null) {
4549 this.writer.writeln("return;");
4550 }
4551 else {
4552 if (this.method.get$isConstructor()) {
4553 $globals.world.error("return of value not allowed from constructor", node. span);
4554 }
4555 var value = this.visitTypedValue(node.value, this.method.get$returnType());
4556 this.writer.writeln(("return " + value.get$code() + ";"));
4557 }
4558 return true;
4559 }
4560 MethodGenerator.prototype.visitThrowStatement = function(node) {
4561 if (node.value != null) {
4562 var value = this.visitValue(node.value);
4563 value.invoke(this, "toString", node, Arguments.get$EMPTY());
4564 this.writer.writeln(("$throw(" + value.get$code() + ");"));
4565 $globals.world.gen.corejs.useThrow = true;
4566 }
4567 else {
4568 var rethrow = this._scope.getRethrow();
4569 if ($eq$(rethrow)) {
4570 $globals.world.error("rethrow outside of catch", node.span);
4571 }
4572 else {
4573 this.writer.writeln(("throw " + rethrow + ";"));
4574 }
4575 }
4576 return true;
4577 }
4578 MethodGenerator.prototype.visitAssertStatement = function(node) {
4579 var test = this.visitValue(node.test);
4580 if ($globals.options.enableAsserts) {
4581 var span = node.test.span;
4582 var line = span.get$file().getLine(span.get$start()) + (1);
4583 var column = span.get$file().getColumn($sub$(line, (1)), span.get$start()) + (1);
4584 var args = [test, Value.fromString(span.get$text(), node.span), Value.fromSt ring(span.get$file().filename, node.span), Value.fromInt(line, node.span), Value .fromInt(column, node.span)];
4585 var tp = $globals.world.corelib.topType;
4586 var f = tp.getMember("_assert");
4587 var value = f.invoke(this, node, new TypeValue(tp, null), new Arguments(null , args));
4588 this.writer.writeln(("" + value.get$code() + ";"));
4589 }
4590 return false;
4591 }
4592 MethodGenerator.prototype.visitBreakStatement = function(node) {
4593 if (node.label == null) {
4594 this.writer.writeln("break;");
4595 }
4596 else {
4597 this.writer.writeln(("break " + node.label.name + ";"));
4598 }
4599 return true;
4600 }
4601 MethodGenerator.prototype.visitContinueStatement = function(node) {
4602 if (node.label == null) {
4603 this.writer.writeln("continue;");
4604 }
4605 else {
4606 this.writer.writeln(("continue " + node.label.name + ";"));
4607 }
4608 return true;
4609 }
4610 MethodGenerator.prototype.visitIfStatement = function(node) {
4611 var test = this.visitBool(node.test);
4612 this.writer.write(("if (" + test.get$code() + ") "));
4613 var exit1 = node.trueBranch.visit(this);
4614 if (node.falseBranch != null) {
4615 this.writer.write("else ");
4616 if (node.falseBranch.visit(this) && exit1) {
4617 return true;
4618 }
4619 }
4620 return false;
4621 }
4622 MethodGenerator.prototype.visitWhileStatement = function(node) {
4623 var $this = this; // closure support
4624 var test = this.visitBool(node.test);
4625 this.writer.write(("while (" + test.get$code() + ") "));
4626 this._visitLoop(node, (function () {
4627 node.body.visit($this);
4628 })
4629 );
4630 return false;
4631 }
4632 MethodGenerator.prototype.visitDoStatement = function(node) {
4633 var $this = this; // closure support
4634 this.writer.write("do ");
4635 this._visitLoop(node, (function () {
4636 node.body.visit($this);
4637 })
4638 );
4639 var test = this.visitBool(node.test);
4640 this.writer.writeln(("while (" + test.get$code() + ")"));
4641 return false;
4642 }
4643 MethodGenerator.prototype.visitForStatement = function(node) {
4644 var $this = this; // closure support
4645 this._pushBlock(node, false);
4646 this.writer.write("for (");
4647 if (node.init != null) {
4648 node.init.visit(this);
4649 }
4650 else {
4651 this.writer.write(";");
4652 }
4653 this._visitLoop(node, (function () {
4654 if (node.test != null) {
4655 var test = $this.visitBool(node.test);
4656 $this.writer.write((" " + test.get$code() + "; "));
4657 }
4658 else {
4659 $this.writer.write("; ");
4660 }
4661 var needsComma = false;
4662 var $$list = node.step;
4663 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4664 var s = $$i.next();
4665 if (needsComma) $this.writer.write(", ");
4666 var sv = $this.visitVoid(s);
4667 $this.writer.write(sv.get$code());
4668 needsComma = true;
4669 }
4670 $this.writer.write(") ");
4671 $this._pushBlock(node.body, false);
4672 node.body.visit($this);
4673 $this._popBlock(node.body);
4674 })
4675 );
4676 this._popBlock(node);
4677 return false;
4678 }
4679 MethodGenerator.prototype.visitForInStatement = function(node) {
4680 var $this = this; // closure support
4681 var itemType = this.method.resolveType(node.item.type, false, true);
4682 var list = node.list.visit(this);
4683 this._visitLoop(node, (function () {
4684 $this._visitForInBody(node, itemType, list);
4685 })
4686 );
4687 return false;
4688 }
4689 MethodGenerator.prototype._visitForInBody = function(node, itemType, list) {
4690 var isFinal = node.item.isFinal;
4691 var itemName = node.item.name.name;
4692 var item = this._scope.create(itemName, itemType, node.item.name.span, isFinal , false);
4693 if (list.get$needsTemp()) {
4694 var listVar = this._scope.create("$list", list.get$type(), null, false, fals e);
4695 this.writer.writeln(("var " + listVar.get$code() + " = " + list.get$code() + ";"));
4696 list = listVar;
4697 }
4698 if ($eq$(list.get$type().get$genericType(), $globals.world.listFactoryType)) {
4699 var tmpi = this._scope.create("$i", $globals.world.numType, null, false, fal se);
4700 var listLength = list.get_(this, "length", node.list);
4701 this.writer.enterBlock((("for (var " + tmpi.get$code() + " = 0;") + ("" + tm pi.get$code() + " < " + listLength.get$code() + "; " + tmpi.get$code() + "++) {" )));
4702 var value = list.invoke(this, ":index", node.list, new Arguments(null, [tmpi ]));
4703 this.writer.writeln(("var " + item.get$code() + " = " + value.get$code() + " ;"));
4704 }
4705 else {
4706 var iterator = list.invoke(this, "iterator", node.list, Arguments.get$EMPTY( ));
4707 var tmpi = this._scope.create("$i", iterator.get$type(), null, false, false) ;
4708 var hasNext = tmpi.invoke(this, "hasNext", node.list, Arguments.get$EMPTY()) ;
4709 var next = tmpi.invoke(this, "next", node.list, Arguments.get$EMPTY());
4710 this.writer.enterBlock(("for (var " + tmpi.get$code() + " = " + iterator.get $code() + "; " + hasNext.get$code() + "; ) {"));
4711 this.writer.writeln(("var " + item.get$code() + " = " + next.get$code() + "; "));
4712 }
4713 this.visitStatementsInBlock(node.body);
4714 this.writer.exitBlock("}");
4715 }
4716 MethodGenerator.prototype._genToDartException = function(ex) {
4717 var result = this._invokeNative("_toDartException", [ex]);
4718 this.writer.writeln(("" + ex.get$code() + " = " + result.get$code() + ";"));
4719 }
4720 MethodGenerator.prototype._genStackTraceOf = function(trace, ex) {
4721 var result = this._invokeNative("_stackTraceOf", [ex]);
4722 this.writer.writeln(("var " + trace.get$code() + " = " + result.get$code() + " ;"));
4723 }
4724 MethodGenerator.prototype.visitTryStatement = function(node) {
4725 this.writer.enterBlock("try {");
4726 this._pushBlock(node.body, false);
4727 this.visitStatementsInBlock(node.body);
4728 this._popBlock(node.body);
4729 if (node.catches.get$length() == (1)) {
4730 var catch_ = node.catches.$index((0));
4731 this._pushBlock(catch_, false);
4732 var exType = this.method.resolveType(catch_.get$exception().get$type(), fals e, true);
4733 var ex = this._scope.declare(catch_.get$exception());
4734 this._scope.rethrow = ex.get$code();
4735 this.writer.nextBlock(("} catch (" + ex.get$code() + ") {"));
4736 if ($ne$(catch_.get$trace())) {
4737 var trace = this._scope.declare(catch_.get$trace());
4738 this._genStackTraceOf(trace, ex);
4739 }
4740 this._genToDartException(ex);
4741 if (!exType.get$isVarOrObject()) {
4742 var test = ex.instanceOf$3$isTrue$forceCheck(this, exType, catch_.get$exce ption().get$span(), false, true);
4743 this.writer.writeln(("if (" + test.get$code() + ") throw " + ex.get$code() + ";"));
4744 }
4745 this.visitStatementsInBlock(node.catches.$index((0)).body);
4746 this._popBlock(catch_);
4747 }
4748 else if (node.catches.get$length() > (0)) {
4749 this._pushBlock(node, false);
4750 var ex = this._scope.create("$ex", $globals.world.varType, null, false, fals e);
4751 this._scope.rethrow = ex.get$code();
4752 this.writer.nextBlock(("} catch (" + ex.get$code() + ") {"));
4753 var trace = null;
4754 if (node.catches.some((function (c) {
4755 return $ne$(c.get$trace());
4756 })
4757 )) {
4758 trace = this._scope.create("$trace", $globals.world.varType, null, false, false);
4759 this._genStackTraceOf(trace, ex);
4760 }
4761 this._genToDartException(ex);
4762 var needsRethrow = true;
4763 for (var i = (0);
4764 i < node.catches.get$length(); i++) {
4765 var catch_ = node.catches.$index(i);
4766 this._pushBlock(catch_, false);
4767 var tmpType = this.method.resolveType(catch_.get$exception().get$type(), f alse, true);
4768 var tmp = this._scope.declare(catch_.get$exception());
4769 if (!tmpType.get$isVarOrObject()) {
4770 var test = ex.instanceOf$3$isTrue$forceCheck(this, tmpType, catch_.get$e xception().get$span(), true, true);
4771 if (i == (0)) {
4772 this.writer.enterBlock(("if (" + test.get$code() + ") {"));
4773 }
4774 else {
4775 this.writer.nextBlock(("} else if (" + test.get$code() + ") {"));
4776 }
4777 }
4778 else if (i > (0)) {
4779 this.writer.nextBlock("} else {");
4780 }
4781 this.writer.writeln(("var " + tmp.get$code() + " = " + ex.get$code() + ";" ));
4782 if ($ne$(catch_.get$trace())) {
4783 var tmptrace = this._scope.declare(catch_.get$trace());
4784 this.writer.writeln(("var " + tmptrace.get$code() + " = " + trace.get$co de() + ";"));
4785 }
4786 this.visitStatementsInBlock(catch_.get$body());
4787 this._popBlock(catch_);
4788 if (tmpType.get$isVarOrObject()) {
4789 if (i + (1) < node.catches.get$length()) {
4790 $globals.world.error("Unreachable catch clause", node.catches.$index(i + (1)).span);
4791 }
4792 if (i > (0)) {
4793 this.writer.exitBlock("}");
4794 }
4795 needsRethrow = false;
4796 break;
4797 }
4798 }
4799 if (needsRethrow) {
4800 this.writer.nextBlock("} else {");
4801 this.writer.writeln(("throw " + ex.get$code() + ";"));
4802 this.writer.exitBlock("}");
4803 }
4804 this._popBlock(node);
4805 }
4806 if (node.finallyBlock != null) {
4807 this.writer.nextBlock("} finally {");
4808 this._pushBlock(node.finallyBlock, false);
4809 this.visitStatementsInBlock(node.finallyBlock);
4810 this._popBlock(node.finallyBlock);
4811 }
4812 this.writer.exitBlock("}");
4813 return false;
4814 }
4815 MethodGenerator.prototype.visitSwitchStatement = function(node) {
4816 var test = this.visitValue(node.test);
4817 this.writer.enterBlock(("switch (" + test.get$code() + ") {"));
4818 var $$list = node.cases;
4819 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
4820 var case_ = $$i.next();
4821 if (case_.get$label() != null) {
4822 $globals.world.error("unimplemented: labeled case statement", case_.get$sp an());
4823 }
4824 this._pushBlock(case_, false);
4825 for (var i = (0);
4826 i < case_.get$cases().get$length(); i++) {
4827 var expr = case_.get$cases().$index(i);
4828 if ($eq$(expr)) {
4829 if (i < case_.get$cases().get$length() - (1)) {
4830 $globals.world.error("default clause must be the last case", case_.get $span());
4831 }
4832 this.writer.writeln("default:");
4833 }
4834 else {
4835 var value = this.visitValue(expr);
4836 this.writer.writeln(("case " + value.get$code() + ":"));
4837 }
4838 }
4839 this.writer.enterBlock("");
4840 var caseExits = this._visitAllStatements(case_.get$statements(), false);
4841 if ($ne$(case_, node.cases.$index(node.cases.get$length() - (1))) && !caseEx its) {
4842 var span = case_.get$statements().$index(case_.get$statements().get$length () - (1)).get$span();
4843 this.writer.writeln("$throw(new FallThroughError());");
4844 $globals.world.gen.corejs.useThrow = true;
4845 }
4846 this.writer.exitBlock("");
4847 this._popBlock(case_);
4848 }
4849 this.writer.exitBlock("}");
4850 return false;
4851 }
4852 MethodGenerator.prototype._visitAllStatements = function(statementList, exits) {
4853 for (var i = (0);
4854 i < statementList.get$length(); i++) {
4855 var stmt = statementList.$index(i);
4856 exits = stmt.visit(this);
4857 if ($ne$(stmt, statementList.$index(statementList.get$length() - (1))) && ex its) {
4858 $globals.world.warning("unreachable code", statementList.$index(i + (1)).g et$span());
4859 }
4860 }
4861 return exits;
4862 }
4863 MethodGenerator.prototype.visitBlockStatement = function(node) {
4864 this._pushBlock(node, false);
4865 this.writer.enterBlock("{");
4866 var exits = this._visitAllStatements(node.body, false);
4867 this.writer.exitBlock("}");
4868 this._popBlock(node);
4869 return exits;
4870 }
4871 MethodGenerator.prototype.visitLabeledStatement = function(node) {
4872 this.writer.writeln(("" + node.name.name + ":"));
4873 node.body.visit(this);
4874 return false;
4875 }
4876 MethodGenerator.prototype.visitExpressionStatement = function(node) {
4877 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi on)) {
4878 $globals.world.warning("variable used as statement", node.span);
4879 }
4880 var value = this.visitVoid(node.body);
4881 this.writer.writeln(("" + value.get$code() + ";"));
4882 return false;
4883 }
4884 MethodGenerator.prototype.visitEmptyStatement = function(node) {
4885 this.writer.writeln(";");
4886 return false;
4887 }
4888 MethodGenerator.prototype._checkNonStatic = function(node) {
4889 if (this.get$isStatic()) {
4890 $globals.world.warning("not allowed in static method", node.span);
4891 }
4892 }
4893 MethodGenerator.prototype._makeSuperValue = function(node) {
4894 var parentType = this.method.declaringType.get$parent();
4895 this._checkNonStatic(node);
4896 if ($eq$(parentType)) {
4897 $globals.world.error("no super class", node.span);
4898 }
4899 return new SuperValue(parentType, node.span);
4900 }
4901 MethodGenerator.prototype._getOutermostMethod = function() {
4902 var result = this;
4903 while (result.get$enclosingMethod() != null) {
4904 result = result.get$enclosingMethod();
4905 }
4906 return result;
4907 }
4908 MethodGenerator.prototype._makeThisCode = function() {
4909 if (this.enclosingMethod != null) {
4910 this._getOutermostMethod().set$needsThis(true);
4911 return "$this";
4912 }
4913 else {
4914 return "this";
4915 }
4916 }
4917 MethodGenerator.prototype._makeThisValue = function(node) {
4918 if (this.enclosingMethod != null) {
4919 var outermostMethod = this._getOutermostMethod();
4920 outermostMethod._checkNonStatic(node);
4921 outermostMethod.set$needsThis(true);
4922 return new ThisValue(outermostMethod.get$method().get$declaringType(), "$thi s", node != null ? node.span : null);
4923 }
4924 else {
4925 this._checkNonStatic(node);
4926 return new ThisValue(this.method.declaringType, "this", node != null ? node. span : null);
4927 }
4928 }
4929 MethodGenerator.prototype.visitLambdaExpression = function(node) {
4930 var name = (node.func.name != null) ? node.func.name.name : "";
4931 var meth = this._makeLambdaMethod(name, node.func);
4932 return meth.get$methodData().createLambda(node, this);
4933 }
4934 MethodGenerator.prototype.visitCallExpression = function(node) {
4935 var target;
4936 var position = node.target;
4937 var name = ":call";
4938 if ((node.target instanceof DotExpression)) {
4939 var dot = node.target;
4940 target = dot.self.visit(this);
4941 name = dot.name.name;
4942 position = dot.name;
4943 }
4944 else if ((node.target instanceof VarExpression)) {
4945 var varExpr = node.target;
4946 name = varExpr.name.name;
4947 target = this._scope.lookup(name);
4948 if ($ne$(target)) {
4949 return target.invoke(this, ":call", node, this._makeArgs(node.arguments));
4950 }
4951 target = this._makeThisOrType(varExpr.span);
4952 return target.invoke(this, name, node, this._makeArgs(node.arguments));
4953 }
4954 else {
4955 target = node.target.visit(this);
4956 }
4957 return target.invoke(this, name, position, this._makeArgs(node.arguments));
4958 }
4959 MethodGenerator.prototype.visitIndexExpression = function(node) {
4960 var target = this.visitValue(node.target);
4961 var index = this.visitValue(node.index);
4962 return target.invoke(this, ":index", node, new Arguments(null, [index]));
4963 }
4964 MethodGenerator.prototype._expressionNeedsParens = function(e) {
4965 return ((e instanceof BinaryExpression) || (e instanceof ConditionalExpression ) || (e instanceof PostfixExpression) || this._isUnaryIncrement(e));
4966 }
4967 MethodGenerator.prototype.visitBinaryExpression = function(node, isVoid) {
4968 var kind = node.op.kind;
4969 if ($eq$(kind, (35)) || $eq$(kind, (34))) {
4970 var x = this.visitTypedValue(node.x, $globals.world.nonNullBool);
4971 var y = this.visitTypedValue(node.y, $globals.world.nonNullBool);
4972 return x.binop(kind, y, this, node);
4973 }
4974 else if ($eq$(kind, (50)) || $eq$(kind, (51))) {
4975 var x = this.visitValue(node.x);
4976 var y = this.visitValue(node.y);
4977 return x.binop(kind, y, this, node);
4978 }
4979 var assignKind = TokenKind.kindFromAssign(node.op.kind);
4980 if ($eq$(assignKind, (-1))) {
4981 var x = this.visitValue(node.x);
4982 var y = this.visitValue(node.y);
4983 return x.binop(kind, y, this, node);
4984 }
4985 else if (($ne$(assignKind, (0))) && this._expressionNeedsParens(node.y)) {
4986 return this._visitAssign(assignKind, node.x, new ParenExpression(node.y, nod e.y.span), node, isVoid ? (1) : (2));
4987 }
4988 else {
4989 return this._visitAssign(assignKind, node.x, node.y, node, isVoid ? (1) : (2 ));
4990 }
4991 }
4992 MethodGenerator.prototype._visitAssign = function(kind, xn, yn, position, return Kind) {
4993 if ((xn instanceof VarExpression)) {
4994 return this._visitVarAssign(kind, xn, yn, position, returnKind);
4995 }
4996 else if ((xn instanceof IndexExpression)) {
4997 return this._visitIndexAssign(kind, xn, yn, position, returnKind);
4998 }
4999 else if ((xn instanceof DotExpression)) {
5000 return this._visitDotAssign(kind, xn, yn, position, returnKind);
5001 }
5002 else {
5003 $globals.world.error("illegal lhs", xn.span);
5004 }
5005 }
5006 MethodGenerator.prototype._visitVarAssign = function(kind, xn, yn, position, ret urnKind) {
5007 var name = xn.name.name;
5008 var x = this._scope.lookup(name);
5009 var y = this.visitValue(yn);
5010 if ($ne$(x)) {
5011 y = y.convertTo(this, x.get$staticType());
5012 this._scope.inferAssign(name, Value.union(x, y));
5013 if (x.get$isFinal()) {
5014 $globals.world.error(("final variable \"" + x.get$code() + "\" is not assi gnable"), position.span);
5015 }
5016 if (kind == (0)) {
5017 return new Value(y.get$type(), ("" + x.get$code() + " = " + y.get$code()), position.span);
5018 }
5019 else if (x.get$type().get$isNum() && y.get$type().get$isNum() && (kind != (4 6))) {
5020 if (returnKind == (3)) {
5021 $globals.world.internalError("should not be here", position.span);
5022 }
5023 var op = TokenKind.kindToString(kind);
5024 return new Value(y.get$type(), ("" + x.get$code() + " " + op + "= " + y.ge t$code()), position.span);
5025 }
5026 else {
5027 var right = x;
5028 y = right.binop(kind, y, this, position);
5029 if (returnKind == (3)) {
5030 var tmp = this.forceTemp(x);
5031 var ret = new Value(x.get$type(), ("(" + tmp.get$code() + " = " + x.get$ code() + ", " + x.get$code() + " = " + y.get$code() + ", " + tmp.get$code() + ") "), position.span);
5032 this.freeTemp(tmp);
5033 return ret;
5034 }
5035 else {
5036 return new Value(x.get$type(), ("" + x.get$code() + " = " + y.get$code() ), position.span);
5037 }
5038 }
5039 }
5040 else {
5041 x = this._makeThisOrType(position.span);
5042 return x.set_$4$kind$returnKind(this, name, position, y, kind, returnKind);
5043 }
5044 }
5045 MethodGenerator.prototype._visitIndexAssign = function(kind, xn, yn, position, r eturnKind) {
5046 var target = this.visitValue(xn.target);
5047 var index = this.visitValue(xn.index);
5048 var y = this.visitValue(yn);
5049 return target.setIndex$4$kind$returnKind(this, index, position, y, kind, retur nKind);
5050 }
5051 MethodGenerator.prototype._visitDotAssign = function(kind, xn, yn, position, ret urnKind) {
5052 var target = xn.self.visit(this);
5053 var y = this.visitValue(yn);
5054 return target.set_$4$kind$returnKind(this, xn.name.name, xn.name, y, kind, ret urnKind);
5055 }
5056 MethodGenerator.prototype.visitUnaryExpression = function(node) {
5057 var value = this.visitValue(node.self);
5058 switch (node.op.kind) {
5059 case (16):
5060 case (17):
5061
5062 if (value.get$type().get$isNum() && !value.get$isFinal() && (node.self ins tanceof VarExpression)) {
5063 return new Value(value.get$type(), ("" + node.op + value.get$code()), no de.span);
5064 }
5065 else {
5066 var kind = ((16) == node.op.kind ? (42) : (43));
5067 var operand = new LiteralExpression(Value.fromInt((1), node.span), node. span);
5068 var assignValue = this._visitAssign(kind, node.self, operand, node, (2)) ;
5069 return new Value(assignValue.get$type(), ("(" + assignValue.get$code() + ")"), node.span);
5070 }
5071
5072 }
5073 return value.unop(node.op.kind, this, node);
5074 }
5075 MethodGenerator.prototype.visitDeclaredIdentifier = function(node) {
5076 $globals.world.error("Expected expression", node.span);
5077 }
5078 MethodGenerator.prototype.visitAwaitExpression = function(node) {
5079 $globals.world.internalError("Await expressions should have been eliminated be fore code generation", node.span);
5080 }
5081 MethodGenerator.prototype.visitPostfixExpression = function(node, isVoid) {
5082 var value = this.visitValue(node.body);
5083 if (value.get$type().get$isNum() && !value.get$isFinal() && (node.body instanc eof VarExpression)) {
5084 return new Value(value.get$type(), ("" + value.get$code() + node.op), node.s pan);
5085 }
5086 var kind = ((16) == node.op.kind) ? (42) : (43);
5087 var operand = new LiteralExpression(Value.fromInt((1), node.span), node.span);
5088 var ret = this._visitAssign(kind, node.body, operand, node, isVoid ? (1) : (3) );
5089 return ret;
5090 }
5091 MethodGenerator.prototype.visitNewExpression = function(node) {
5092 var typeRef = node.type;
5093 var constructorName = "";
5094 if (node.name != null) {
5095 constructorName = node.name.name;
5096 }
5097 if ($eq$(constructorName, "") && (typeRef instanceof NameTypeReference) && typ eRef.get$names() != null) {
5098 var names = ListFactory.ListFactory$from$factory(typeRef.get$names());
5099 constructorName = names.removeLast().get$name();
5100 if (names.get$length() == (0)) names = null;
5101 typeRef = new NameTypeReference(typeRef.get$isFinal(), typeRef.get$name(), n ames, typeRef.get$span());
5102 }
5103 var type = this.method.resolveType(typeRef, true, true);
5104 if (type.get$isTop()) {
5105 type = type.get$library().findTypeByName(constructorName);
5106 constructorName = "";
5107 }
5108 if ((type instanceof ParameterType)) {
5109 $globals.world.error("cannot instantiate a type parameter", node.span);
5110 return this._makeMissingValue(constructorName);
5111 }
5112 var m = type.getConstructor(constructorName);
5113 if ($eq$(m)) {
5114 var name = type.get$jsname();
5115 if (type.get$isVar()) {
5116 name = typeRef.get$name().get$name();
5117 }
5118 $globals.world.error(("no matching constructor for " + name), node.span);
5119 return this._makeMissingValue(name);
5120 }
5121 if (node.isConst) {
5122 if (!m.get$isConst()) {
5123 $globals.world.error("can't use const on a non-const constructor", node.sp an);
5124 }
5125 var $$list = node.arguments;
5126 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5127 var arg = $$i.next();
5128 if (!this.visitValue(arg.get$value()).get$isConst()) {
5129 $globals.world.error("const constructor expects const arguments", arg.ge t$span());
5130 }
5131 }
5132 }
5133 var target = new TypeValue(type, typeRef.get$span());
5134 return m.invoke(this, node, target, this._makeArgs(node.arguments));
5135 }
5136 MethodGenerator.prototype.visitListExpression = function(node) {
5137 var argValues = [];
5138 var listType = $globals.world.listType;
5139 var type = $globals.world.varType;
5140 if (node.itemType != null) {
5141 type = this.method.resolveType(node.itemType, true, !node.isConst);
5142 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara ms())) {
5143 $globals.world.error("type parameter cannot be used in const list literals ");
5144 }
5145 listType = listType.getOrMakeConcreteType([type]);
5146 }
5147 var $$list = node.values;
5148 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5149 var item = $$i.next();
5150 var arg = this.visitTypedValue(item, type);
5151 argValues.add(arg);
5152 if (node.isConst && !arg.get$isConst()) {
5153 $globals.world.error("const list can only contain const values", arg.get$s pan());
5154 }
5155 }
5156 $globals.world.listFactoryType.markUsed();
5157 var ret = new ListValue(argValues, node.isConst, listType, node.span);
5158 if (ret.get$isConst()) return ret.getGlobalValue();
5159 return ret;
5160 }
5161 MethodGenerator.prototype.visitMapExpression = function(node) {
5162 if (node.items.get$length() == (0) && !node.isConst) {
5163 return $globals.world.mapType.getConstructor("").invoke(this, node, new Type Value($globals.world.mapType, node.span), Arguments.get$EMPTY());
5164 }
5165 var values = [];
5166 var valueType = $globals.world.varType, keyType = $globals.world.stringType;
5167 var mapType = $globals.world.mapType;
5168 if (null != node.valueType) {
5169 if (null != node.keyType) {
5170 keyType = this.method.resolveType(node.keyType, true, !node.isConst);
5171 if (!keyType.get$isString()) {
5172 $globals.world.error("the key type of a map literal must be \"String\"", keyType.get$span());
5173 }
5174 if (node.isConst && ((keyType instanceof ParameterType) || keyType.get$has TypeParams())) {
5175 $globals.world.error("type parameter cannot be used in const map literal s");
5176 }
5177 }
5178 valueType = this.method.resolveType(node.valueType, true, !node.isConst);
5179 if (node.isConst && ((valueType instanceof ParameterType) || valueType.get$h asTypeParams())) {
5180 $globals.world.error("type parameter cannot be used in const map literals" );
5181 }
5182 mapType = mapType.getOrMakeConcreteType([keyType, valueType]);
5183 }
5184 for (var i = (0);
5185 i < node.items.get$length(); i += (2)) {
5186 var key = this.visitTypedValue(node.items.$index(i), keyType);
5187 if (node.isConst && !key.get$isConst()) {
5188 $globals.world.error("const map can only contain const keys", key.get$span ());
5189 }
5190 values.add(key);
5191 var value = this.visitTypedValue(node.items.$index(i + (1)), valueType);
5192 if (node.isConst && !value.get$isConst()) {
5193 $globals.world.error("const map can only contain const values", value.get$ span());
5194 }
5195 values.add(value);
5196 }
5197 var ret = new MapValue(values, node.isConst, mapType, node.span);
5198 if (ret.get$isConst()) return ret.getGlobalValue();
5199 return ret;
5200 }
5201 MethodGenerator.prototype.visitConditionalExpression = function(node) {
5202 var test = this.visitBool(node.test);
5203 var trueBranch = this.visitValue(node.trueBranch);
5204 var falseBranch = this.visitValue(node.falseBranch);
5205 return new Value(Type.union(trueBranch.get$type(), falseBranch.get$type()), (" " + test.get$code() + " ? " + trueBranch.get$code() + " : " + falseBranch.get$co de()), node.span);
5206 }
5207 MethodGenerator.prototype.visitIsExpression = function(node) {
5208 var value = this.visitValue(node.x);
5209 var type = this.method.resolveType(node.type, true, true);
5210 if (type.get$isVar()) {
5211 return Value.comma(value, Value.fromBool(true, node.span));
5212 }
5213 return value.instanceOf$4(this, type, node.span, node.isTrue);
5214 }
5215 MethodGenerator.prototype.visitParenExpression = function(node) {
5216 var body = this.visitValue(node.body);
5217 if (body.get$isConst()) return body;
5218 return new Value(body.get$type(), ("(" + body.get$code() + ")"), node.span);
5219 }
5220 MethodGenerator.prototype.visitDotExpression = function(node) {
5221 var target = node.self.visit(this);
5222 return target.get_(this, node.name.name, node.name);
5223 }
5224 MethodGenerator.prototype.visitVarExpression = function(node) {
5225 var name = node.name.name;
5226 var ret = this._scope.lookup(name);
5227 if ($ne$(ret)) return ret;
5228 return this._makeThisOrType(node.span).get_(this, name, node);
5229 }
5230 MethodGenerator.prototype._makeMissingValue = function(name) {
5231 return new Value($globals.world.varType, ("" + name + "()/*NotFound*/"), null) ;
5232 }
5233 MethodGenerator.prototype._makeThisOrType = function(span) {
5234 return new BareValue(this, this._getOutermostMethod(), span);
5235 }
5236 MethodGenerator.prototype.visitThisExpression = function(node) {
5237 return this._makeThisValue(node);
5238 }
5239 MethodGenerator.prototype.visitSuperExpression = function(node) {
5240 return this._makeSuperValue(node);
5241 }
5242 MethodGenerator.prototype.visitLiteralExpression = function(node) {
5243 return node.value;
5244 }
5245 MethodGenerator.prototype._isUnaryIncrement = function(item) {
5246 if ((item instanceof UnaryExpression)) {
5247 var u = item;
5248 return u.op.kind == (16) || u.op.kind == (17);
5249 }
5250 else {
5251 return false;
5252 }
5253 }
5254 MethodGenerator.prototype.foldStrings = function(strings) {
5255 var buffer = new StringBufferImpl("");
5256 for (var $$i = strings.iterator(); $$i.hasNext(); ) {
5257 var part = $$i.next();
5258 buffer.add(part.get$constValue().get$actualValue());
5259 }
5260 return buffer.toString();
5261 }
5262 MethodGenerator.prototype.visitStringConcatExpression = function(node) {
5263 var items = [];
5264 var itemsConst = [];
5265 var $$list = node.strings;
5266 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5267 var item = $$i.next();
5268 var val = this.visitValue(item);
5269 if (val.get$isConst()) itemsConst.add(val);
5270 items.add(val.get$code());
5271 }
5272 if (items.get$length() == itemsConst.get$length()) {
5273 return new StringValue(this.foldStrings(itemsConst), true, node.span);
5274 }
5275 else {
5276 var code = ("(" + Strings.join(items, " + ") + ")");
5277 return new Value($globals.world.stringType, code, node.span);
5278 }
5279 }
5280 MethodGenerator.prototype.visitStringInterpExpression = function(node) {
5281 var items = [];
5282 var itemsConst = [];
5283 var $$list = node.pieces;
5284 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5285 var item = $$i.next();
5286 var val = this.visitValue(item);
5287 var isConst = val.get$isConst() && val.get$type().get$isString();
5288 if (!isConst) {
5289 val.invoke(this, "toString", item, Arguments.get$EMPTY());
5290 }
5291 var code = val.get$code();
5292 if (this._expressionNeedsParens(item)) {
5293 code = ("(" + code + ")");
5294 }
5295 if (items.get$length() == (0) || ($ne$(code, "''") && $ne$(code, "\"\""))) {
5296 items.add(code);
5297 if (isConst) itemsConst.add(val);
5298 }
5299 }
5300 if (items.get$length() == itemsConst.get$length()) {
5301 return new StringValue(this.foldStrings(itemsConst), true, node.span);
5302 }
5303 else {
5304 var code = ("(" + Strings.join(items, " + ") + ")");
5305 return new Value($globals.world.stringType, code, node.span);
5306 }
5307 }
5308 MethodGenerator.prototype._pushBlock$1 = function($0) {
5309 return this._pushBlock($0, false);
5310 };
5311 MethodGenerator.prototype.run$0 = MethodGenerator.prototype.run;
5312 MethodGenerator.prototype.visitBinaryExpression$1 = function($0) {
5313 return this.visitBinaryExpression($0, false);
5314 };
5315 MethodGenerator.prototype.visitCallExpression$1 = MethodGenerator.prototype.visi tCallExpression;
5316 MethodGenerator.prototype.visitPostfixExpression$1 = function($0) {
5317 return this.visitPostfixExpression($0, false);
5318 };
5319 // ********** Code for Arguments **************
5320 function Arguments(nodes, values) {
5321 this.nodes = nodes;
5322 this.values = values;
5323 }
5324 Arguments.Arguments$bare$factory = function(arity) {
5325 var values = [];
5326 for (var i = (0);
5327 i < arity; i++) {
5328 values.add(new VariableValue($globals.world.varType, ("$" + i), null, false) );
5329 }
5330 return new Arguments(null, values);
5331 }
5332 Arguments.get$EMPTY = function() {
5333 if ($globals.Arguments__empty == null) {
5334 $globals.Arguments__empty = new Arguments(null, []);
5335 }
5336 return $globals.Arguments__empty;
5337 }
5338 Arguments.prototype.get$nameCount = function() {
5339 return this.get$length() - this.get$bareCount();
5340 }
5341 Arguments.prototype.get$hasNames = function() {
5342 return this.get$bareCount() < this.get$length();
5343 }
5344 Arguments.prototype.get$length = function() {
5345 return this.values.get$length();
5346 }
5347 Arguments.prototype.getName = function(i) {
5348 return this.nodes.$index(i).label.name;
5349 }
5350 Arguments.prototype.getIndexOfName = function(name) {
5351 for (var i = this.get$bareCount();
5352 i < this.get$length(); i++) {
5353 if (this.getName(i) == name) {
5354 return i;
5355 }
5356 }
5357 return (-1);
5358 }
5359 Arguments.prototype.getValue = function(name) {
5360 var i = this.getIndexOfName(name);
5361 return i >= (0) ? this.values.$index(i) : null;
5362 }
5363 Arguments.prototype.get$bareCount = function() {
5364 if (this._bareCount == null) {
5365 this._bareCount = this.get$length();
5366 if (this.nodes != null) {
5367 for (var i = (0);
5368 i < this.nodes.get$length(); i++) {
5369 if (this.nodes.$index(i).label != null) {
5370 this._bareCount = i;
5371 break;
5372 }
5373 }
5374 }
5375 }
5376 return this._bareCount;
5377 }
5378 Arguments.prototype.getCode = function() {
5379 var argsCode = [];
5380 for (var i = (0);
5381 i < this.get$length(); i++) {
5382 argsCode.add(this.values.$index(i).get$code());
5383 }
5384 Arguments.removeTrailingNulls(argsCode);
5385 return Strings.join(argsCode, ", ");
5386 }
5387 Arguments.removeTrailingNulls = function(argsCode) {
5388 while (argsCode.get$length() > (0) && $eq$(argsCode.last(), "null")) {
5389 argsCode.removeLast();
5390 }
5391 }
5392 Arguments.prototype.getNames = function() {
5393 var names = [];
5394 for (var i = this.get$bareCount();
5395 i < this.get$length(); i++) {
5396 names.add(this.getName(i));
5397 }
5398 return names;
5399 }
5400 Arguments.prototype.toCallStubArgs = function() {
5401 var result = [];
5402 for (var i = (0);
5403 i < this.get$bareCount(); i++) {
5404 result.add(new VariableValue($globals.world.varType, ("$" + i), null, false) );
5405 }
5406 for (var i = this.get$bareCount();
5407 i < this.get$length(); i++) {
5408 var name = this.getName(i);
5409 if ($eq$(name)) name = ("$" + i);
5410 result.add(new VariableValue($globals.world.varType, name, null, false));
5411 }
5412 return new Arguments(this.nodes, result);
5413 }
5414 Arguments.prototype.matches = function(other) {
5415 if (this.get$length() != other.get$length()) return false;
5416 if (this.get$bareCount() != other.get$bareCount()) return false;
5417 for (var i = (0);
5418 i < this.get$bareCount(); i++) {
5419 if ($ne$(this.values.$index(i).get$type(), other.values.$index(i).get$type() )) return false;
5420 }
5421 return true;
5422 }
5423 // ********** Code for ReturnKind **************
5424 function ReturnKind() {}
5425 // ********** Code for LibraryImport **************
5426 function LibraryImport(library, prefix, span) {
5427 this.library = library;
5428 this.prefix = prefix;
5429 this.span = span;
5430 }
5431 LibraryImport.prototype.get$prefix = function() { return this.prefix; };
5432 LibraryImport.prototype.get$library = function() { return this.library; };
5433 LibraryImport.prototype.get$span = function() { return this.span; };
5434 // ********** Code for Member **************
5435 $inherits(Member, Element);
5436 function Member(name, declaringType) {
5437 this._provideGetter = false;
5438 this._provideSetter = false;
5439 this.declaringType = declaringType;
5440 Element.call(this, name, declaringType);
5441 }
5442 Member.prototype.get$declaringType = function() { return this.declaringType; };
5443 Member.prototype.get$genericMember = function() { return this.genericMember; };
5444 Member.prototype.set$genericMember = function(value) { return this.genericMember = value; };
5445 Member.prototype.mangleJsName = function() {
5446 var mangled = Element.prototype.mangleJsName.call(this);
5447 if (this.declaringType != null && this.declaringType.get$isTop()) {
5448 return JsNames.getValid(mangled);
5449 }
5450 else {
5451 return (this.get$isNative() && !this.name.contains(":")) ? this.name : mangl ed;
5452 }
5453 }
5454 Member.prototype.get$library = function() {
5455 return this.declaringType.get$library();
5456 }
5457 Member.prototype.get$isPrivate = function() {
5458 return null != this.name && this.name.startsWith("_");
5459 }
5460 Member.prototype.get$isConstructor = function() {
5461 return false;
5462 }
5463 Member.prototype.get$isField = function() {
5464 return false;
5465 }
5466 Member.prototype.get$isMethod = function() {
5467 return false;
5468 }
5469 Member.prototype.get$isProperty = function() {
5470 return false;
5471 }
5472 Member.prototype.get$isAbstract = function() {
5473 return false;
5474 }
5475 Member.prototype.get$isFinal = function() {
5476 return false;
5477 }
5478 Member.prototype.get$isConst = function() {
5479 return false;
5480 }
5481 Member.prototype.get$isFactory = function() {
5482 return false;
5483 }
5484 Member.prototype.get$isOperator = function() {
5485 return this.name.startsWith(":");
5486 }
5487 Member.prototype.get$isCallMethod = function() {
5488 return this.name == ":call";
5489 }
5490 Member.prototype.get$isNative = function() {
5491 return false;
5492 }
5493 Member.prototype.get$constructorName = function() {
5494 $globals.world.internalError("cannot be a constructor", this.get$span());
5495 }
5496 Member.prototype.provideGetter = function() {
5497
5498 }
5499 Member.prototype.provideSetter = function() {
5500
5501 }
5502 Member.prototype.get$initDelegate = function() {
5503 $globals.world.internalError("cannot have initializers", this.get$span());
5504 }
5505 Member.prototype.set$initDelegate = function(ctor) {
5506 $globals.world.internalError("cannot have initializers", this.get$span());
5507 }
5508 Member.prototype.computeValue = function() {
5509 $globals.world.internalError("cannot have value", this.get$span());
5510 }
5511 Member.prototype.get$inferredResult = function() {
5512 var t = this.get$returnType();
5513 if (t.get$isBool() && (this.get$library().get$isCore() || this.get$library().g et$isCoreImpl())) {
5514 return $globals.world.nonNullBool;
5515 }
5516 return t;
5517 }
5518 Member.prototype.get$definition = function() {
5519 return null;
5520 }
5521 Member.prototype.get$parameters = function() {
5522 return [];
5523 }
5524 Member.prototype.get$preciseMemberSet = function() {
5525 if (null == this._preciseMemberSet) {
5526 this._preciseMemberSet = new MemberSet(this, false);
5527 }
5528 return this._preciseMemberSet;
5529 }
5530 Member.prototype.get$potentialMemberSet = function() {
5531 if (null == this._potentialMemberSet) {
5532 if (this.name == ":call") {
5533 this._potentialMemberSet = this.get$preciseMemberSet();
5534 return this._potentialMemberSet;
5535 }
5536 var mems = new HashSetImplementation_Member();
5537 if (this.declaringType.get$isClass()) mems.add(this);
5538 var $$list = this.declaringType.get$genericType().get$subtypes();
5539 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5540 var subtype = $$i.next();
5541 if (!subtype.get$isClass()) continue;
5542 var mem = subtype.get$members().$index(this.name);
5543 if (null != mem) {
5544 if (mem.isDefinedOn(this.declaringType)) {
5545 mems.add(mem);
5546 }
5547 }
5548 else if (!this.declaringType.get$isClass()) {
5549 mem = subtype.getMember(this.name);
5550 if (null != mem && mem.isDefinedOn(this.declaringType)) {
5551 mems.add(mem);
5552 }
5553 }
5554 }
5555 if (mems.get$length() != (0)) {
5556 for (var $$i = mems.iterator(); $$i.hasNext(); ) {
5557 var mem = $$i.next();
5558 if ($ne$(this.declaringType.get$genericType(), this.declaringType) && me m.get$genericMember() != null && mems.contains$1(mem.get$genericMember())) {
5559 mems.remove$1(mem.get$genericMember());
5560 }
5561 }
5562 for (var $$i = mems.iterator(); $$i.hasNext(); ) {
5563 var mem = $$i.next();
5564 if (null == this._potentialMemberSet) {
5565 this._potentialMemberSet = new MemberSet(mem, false);
5566 }
5567 else {
5568 this._potentialMemberSet.add(mem);
5569 }
5570 }
5571 }
5572 }
5573 return this._potentialMemberSet;
5574 }
5575 Member.prototype.isDefinedOn = function(type) {
5576 if (type.get$isClass()) {
5577 if (this.declaringType.isSubtypeOf(type)) {
5578 return true;
5579 }
5580 else if (type.isSubtypeOf(this.declaringType)) {
5581 return $eq$(type.getMember(this.name), this);
5582 }
5583 else {
5584 return false;
5585 }
5586 }
5587 else {
5588 if (this.declaringType.isSubtypeOf(type)) {
5589 return true;
5590 }
5591 else {
5592 var $$list = this.declaringType.get$subtypes();
5593 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5594 var t = $$i.next();
5595 if (t.isSubtypeOf(type) && $eq$(t.getMember(this.name), this)) {
5596 return true;
5597 }
5598 }
5599 return false;
5600 }
5601 }
5602 }
5603 Member.prototype.canInvoke = function(context, args) {
5604 if (this.get$canGet() && (this.get$isField() || this.get$isProperty())) {
5605 return this.get$returnType().get$isFunction() || this.get$returnType().get$i sVar() || this.get$returnType().getCallMethod() != null;
5606 }
5607 return false;
5608 }
5609 Member.prototype.invoke = function(context, node, target, args) {
5610 var newTarget = this._get(context, node, target);
5611 return newTarget.invoke(context, ":call", node, args);
5612 }
5613 Member.prototype.override = function(other) {
5614 if (this.get$isStatic()) {
5615 $globals.world.error("static members cannot hide parent members", this.get$s pan(), other.get$span());
5616 return false;
5617 }
5618 else if (other.get$isStatic()) {
5619 $globals.world.error("cannot override static member", this.get$span(), other .get$span());
5620 return false;
5621 }
5622 return true;
5623 }
5624 Member.prototype.get$generatedFactoryName = function() {
5625 var prefix = ("" + this.declaringType.get$genericType().get$jsname() + "." + t his.get$constructorName() + "$");
5626 if (this.name == "") {
5627 return ("" + prefix + "factory");
5628 }
5629 else {
5630 return ("" + prefix + this.name + "$factory");
5631 }
5632 }
5633 Member.prototype.hashCode = function() {
5634 var typeCode = this.declaringType == null ? (1) : this.declaringType.hashCode( );
5635 var nameCode = this.get$isConstructor() ? this.get$constructorName().hashCode( ) : this.name.hashCode();
5636 return $bit_xor$(($shl$(typeCode, (4))), nameCode);
5637 }
5638 Member.prototype.$eq = function(other) {
5639 return (other instanceof Member) && $eq$(this.get$isConstructor(), other.get$i sConstructor()) && $eq$(this.declaringType, other.get$declaringType()) && (this. get$isConstructor() ? this.get$constructorName() == other.get$constructorName() : this.name == other.get$name());
5640 }
5641 Member.prototype.resolveType = function(node, typeErrors, allowTypeParams) {
5642 allowTypeParams = allowTypeParams && !(this.get$isStatic() && !this.get$isFact ory());
5643 return Element.prototype.resolveType.call(this, node, typeErrors, allowTypePar ams);
5644 }
5645 Member.prototype.makeConcrete = function(concreteType) {
5646 $globals.world.internalError("cannot make this concrete", this.get$span());
5647 }
5648 // ********** Code for AmbiguousMember **************
5649 $inherits(AmbiguousMember, Member);
5650 function AmbiguousMember(name, members) {
5651 this.members = members;
5652 Member.call(this, name, null);
5653 }
5654 AmbiguousMember.prototype.get$members = function() { return this.members; };
5655 // ********** Code for Library **************
5656 $inherits(Library, Element);
5657 function Library(baseSource) {
5658 this.isWritten = false;
5659 this.baseSource = baseSource;
5660 Element.call(this, null, null);
5661 this.sourceDir = dirname(this.baseSource.filename);
5662 this.topType = new DefinedType(null, this, null, true);
5663 this.types = _map(["", this.topType]);
5664 this.imports = [];
5665 this.natives = [];
5666 this.sources = [];
5667 this._privateMembers = new HashMapImplementation();
5668 }
5669 Library.prototype.get$baseSource = function() { return this.baseSource; };
5670 Library.prototype.get$types = function() { return this.types; };
5671 Library.prototype.get$imports = function() { return this.imports; };
5672 Library.prototype.get$_privateMembers = function() { return this._privateMembers ; };
5673 Library.prototype.get$enclosingElement = function() {
5674 return null;
5675 }
5676 Library.prototype.get$library = function() {
5677 return this;
5678 }
5679 Library.prototype.get$isNative = function() {
5680 return this.topType.isNative;
5681 }
5682 Library.prototype.get$isCore = function() {
5683 return $eq$(this, $globals.world.corelib);
5684 }
5685 Library.prototype.get$isCoreImpl = function() {
5686 return $eq$(this, $globals.world.coreimpl);
5687 }
5688 Library.prototype.get$isDom = function() {
5689 return $eq$(this, $globals.world.dom);
5690 }
5691 Library.prototype.get$span = function() {
5692 return new SourceSpan(this.baseSource, (0), (0));
5693 }
5694 Library.prototype.makeFullPath = function(filename) {
5695 if (filename.startsWith("dart:")) return filename;
5696 if (filename.startsWith("package:")) return filename;
5697 if (filename.startsWith("/")) return filename;
5698 if (filename.startsWith("file:///")) return filename;
5699 if (filename.startsWith("http://")) return filename;
5700 if (const$0009.hasMatch(filename)) return filename;
5701 return joinPaths(this.sourceDir, filename);
5702 }
5703 Library.prototype.addImport = function(fullname, prefix, span) {
5704 var newLib = $globals.world.getOrAddLibrary(fullname);
5705 if (newLib.get$isCore()) return;
5706 this.imports.add(new LibraryImport(newLib, prefix, span));
5707 return newLib;
5708 }
5709 Library.prototype.addNative = function(fullname) {
5710 this.natives.add($globals.world.reader.readFile(fullname));
5711 }
5712 Library.prototype._findMembers = function(name) {
5713 if (name.startsWith("_")) {
5714 return this._privateMembers.$index(name);
5715 }
5716 else {
5717 return $globals.world._members.$index(name);
5718 }
5719 }
5720 Library.prototype._addMember = function(member) {
5721 if (member.get$isPrivate()) {
5722 if (member.get$isStatic()) {
5723 if (member.declaringType.get$isTop()) {
5724 $globals.world._addTopName(member);
5725 }
5726 }
5727 else {
5728 var members = this._privateMembers.$index(member.name);
5729 if ($eq$(members)) {
5730 members = new MemberSet(member, true);
5731 this._privateMembers.$setindex(member.name, members);
5732 }
5733 else {
5734 members.add(member);
5735 }
5736 }
5737 }
5738 else {
5739 $globals.world._addMember(member);
5740 }
5741 }
5742 Library.prototype.getOrAddFunctionType = function(enclosingElement, name, func, data) {
5743 var def = new FunctionTypeDefinition(func, null, func.span);
5744 var type = new DefinedType(name, this, def, false);
5745 type.addMethod(":call", func);
5746 var m = type.get$members().$index(":call");
5747 m.set$enclosingElement(enclosingElement);
5748 m.resolve();
5749 m.set$_methodData(data);
5750 type.set$interfaces([$globals.world.functionType]);
5751 return type;
5752 }
5753 Library.prototype.addType = function(name, definition, isClass) {
5754 if (this.types.containsKey(name)) {
5755 var existingType = this.types.$index(name);
5756 if ((this.get$isCore() || this.get$isCoreImpl()) && $eq$(existingType.get$de finition())) {
5757 existingType.setDefinition(definition);
5758 }
5759 else {
5760 $globals.world.warning(("duplicate definition of " + name), definition.spa n, existingType.get$span());
5761 }
5762 }
5763 else {
5764 this.types.$setindex(name, new DefinedType(name, this, definition, isClass)) ;
5765 }
5766 return this.types.$index(name);
5767 }
5768 Library.prototype.findType = function(type) {
5769 var result = this.findTypeByName(type.name.name);
5770 if (result == null) return null;
5771 if (type.names != null) {
5772 if (type.names.get$length() > (1)) {
5773 return null;
5774 }
5775 if (!result.get$isTop()) {
5776 return null;
5777 }
5778 return result.get$library().findTypeByName(type.names.$index((0)).name);
5779 }
5780 return result;
5781 }
5782 Library.prototype.findTypeByName = function(name) {
5783 var ret = this.types.$index(name);
5784 var $$list = this.imports;
5785 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5786 var imported = $$i.next();
5787 var newRet = null;
5788 if (imported.get$prefix() == null) {
5789 newRet = imported.get$library().types.$index(name);
5790 }
5791 else if (imported.get$prefix() == name) {
5792 newRet = imported.get$library().topType;
5793 }
5794 if ($ne$(newRet)) {
5795 if ($ne$(ret) && $ne$(ret, newRet)) {
5796 $globals.world.error(("conflicting types for \"" + name + "\""), ret.get $span(), newRet.get$span());
5797 }
5798 else {
5799 ret = newRet;
5800 }
5801 }
5802 }
5803 return ret;
5804 }
5805 Library.prototype.resolveType = function(node, typeErrors, allowTypeParams) {
5806 if (node == null) return $globals.world.varType;
5807 var ret = this.findType(node);
5808 if ($eq$(ret)) {
5809 var message = ("cannot find type " + Library._getDottedName(node));
5810 if (typeErrors) {
5811 $globals.world.error(message, node.span);
5812 return $globals.world.objectType;
5813 }
5814 else {
5815 $globals.world.warning(message, node.span);
5816 return $globals.world.varType;
5817 }
5818 }
5819 return ret;
5820 }
5821 Library._getDottedName = function(type) {
5822 if (type.names != null) {
5823 var names = map(type.names, (function (n) {
5824 return n.get$name();
5825 })
5826 );
5827 return $add$($add$(type.name.name, "."), Strings.join(names, "."));
5828 }
5829 else {
5830 return type.name.name;
5831 }
5832 }
5833 Library.prototype.lookup = function(name, span) {
5834 return this._topNames.$index(name);
5835 }
5836 Library.prototype.resolve = function() {
5837 if (this.name == null) {
5838 this.name = this.baseSource.filename;
5839 var index = this.name.lastIndexOf("/", this.name.length);
5840 if ($gte$(index, (0))) {
5841 this.name = this.name.substring($add$(index, (1)));
5842 }
5843 index = this.name.indexOf(".");
5844 if ($gt$(index, (0))) {
5845 this.name = this.name.substring((0), index);
5846 }
5847 }
5848 this._jsname = this.name.replaceAll(".", "_").replaceAll(":", "_").replaceAll( " ", "_");
5849 var $$list = this.types.getValues();
5850 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5851 var type = $$i.next();
5852 type.resolve();
5853 }
5854 }
5855 Library.prototype._addTopName = function(name, member, localSpan) {
5856 var existing = this._topNames.$index(name);
5857 if (null == existing) {
5858 this._topNames.$setindex(name, member);
5859 }
5860 else {
5861 if ((existing instanceof AmbiguousMember)) {
5862 existing.get$members().add(member);
5863 }
5864 else {
5865 var newMember = new AmbiguousMember(name, [existing, member]);
5866 $globals.world.error(("conflicting members for \"" + name + "\""), existin g.get$span(), member.get$span(), localSpan);
5867 this._topNames.$setindex(name, newMember);
5868 }
5869 }
5870 }
5871 Library.prototype._addTopNames = function(lib) {
5872 var $$list = lib.topType.members.getValues();
5873 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5874 var member = $$i.next();
5875 if (member.get$isPrivate() && $ne$(lib, this)) continue;
5876 this._addTopName(member.get$name(), member);
5877 }
5878 var $$list = lib.types.getValues();
5879 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5880 var type = $$i.next();
5881 if (!type.get$isTop()) {
5882 if ($ne$(lib, this) && type.get$typeMember().get$isPrivate()) continue;
5883 this._addTopName(type.get$name(), type.get$typeMember());
5884 }
5885 }
5886 }
5887 Library.prototype.postResolveChecks = function() {
5888 this._topNames = new HashMapImplementation();
5889 this._addTopNames(this);
5890 var $$list = this.imports;
5891 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
5892 var imported = $$i.next();
5893 if (imported.get$prefix() == null) {
5894 this._addTopNames(imported.get$library());
5895 }
5896 else {
5897 this._addTopName(imported.get$prefix(), imported.get$library().topType.get $typeMember(), imported.get$span());
5898 }
5899 }
5900 }
5901 Library.prototype.visitSources = function() {
5902 var visitor = new _LibraryVisitor(this);
5903 visitor.addSource(this.baseSource);
5904 }
5905 Library.prototype.toString = function() {
5906 return this.baseSource.filename;
5907 }
5908 Library.prototype.hashCode = function() {
5909 return this.baseSource.filename.hashCode();
5910 }
5911 Library.prototype.$eq = function(other) {
5912 return (other instanceof Library) && other.get$baseSource().filename == this.b aseSource.filename;
5913 }
5914 Library.prototype.toString$0 = Library.prototype.toString;
5915 // ********** Code for _LibraryVisitor **************
5916 function _LibraryVisitor(library) {
5917 this.seenImport = false;
5918 this.seenSource = false;
5919 this.seenResource = false;
5920 this.isTop = true;
5921 this.library = library;
5922 this.currentType = this.library.topType;
5923 this.sources = [];
5924 }
5925 _LibraryVisitor.prototype.get$library = function() { return this.library; };
5926 _LibraryVisitor.prototype.get$isTop = function() { return this.isTop; };
5927 _LibraryVisitor.prototype.addSourceFromName = function(name, span) {
5928 var filename = this.library.makeFullPath(name);
5929 if ($eq$(filename, this.library.baseSource.filename)) {
5930 $globals.world.error("library cannot source itself", span);
5931 return;
5932 }
5933 else if (this.sources.some((function (s) {
5934 return s.get$filename() == filename;
5935 })
5936 )) {
5937 $globals.world.error(("file \"" + filename + "\" has already been sourced"), span);
5938 return;
5939 }
5940 var source = $globals.world.readFile(this.library.makeFullPath(name));
5941 this.sources.add(source);
5942 }
5943 _LibraryVisitor.prototype.addSource = function(source) {
5944 var $this = this; // closure support
5945 if (this.library.sources.some((function (s) {
5946 return s.get$filename() == source.filename;
5947 })
5948 )) {
5949 $globals.world.error(("duplicate source file \"" + source.filename + "\""));
5950 return;
5951 }
5952 this.library.sources.add(source);
5953 var parser = new Parser(source, $globals.options.dietParse, false, false, (0)) ;
5954 var unit = parser.compilationUnit();
5955 unit.forEach((function (def) {
5956 return def.visit($this);
5957 })
5958 );
5959 this.isTop = false;
5960 var newSources = this.sources;
5961 this.sources = [];
5962 for (var $$i = newSources.iterator(); $$i.hasNext(); ) {
5963 var newSource = $$i.next();
5964 this.addSource(newSource);
5965 }
5966 }
5967 _LibraryVisitor.prototype.visitDirectiveDefinition = function(node) {
5968 if (!this.isTop) {
5969 $globals.world.error("directives not allowed in sourced file", node.span);
5970 return;
5971 }
5972 var name;
5973 switch (node.name.name) {
5974 case "library":
5975
5976 name = this.getSingleStringArg(node);
5977 if (this.library.name == null) {
5978 this.library.name = name;
5979 if ($eq$(name, "node") || $eq$(name, "dom")) {
5980 this.library.topType.isNative = true;
5981 }
5982 if (this.seenImport || this.seenSource || this.seenResource) {
5983 $globals.world.error("#library must be first directive in file", node. span);
5984 }
5985 }
5986 else {
5987 $globals.world.error("already specified library name", node.span);
5988 }
5989 break;
5990
5991 case "import":
5992
5993 this.seenImport = true;
5994 name = this.getFirstStringArg(node);
5995 var prefix = this.tryGetNamedStringArg(node, "prefix");
5996 if (node.arguments.get$length() > (2) || node.arguments.get$length() == (2 ) && $eq$(prefix)) {
5997 $globals.world.error($add$("expected at most one \"name\" argument and o ne optional \"prefix\"", (" but found " + node.arguments.get$length())), node.sp an);
5998 }
5999 else if ($ne$(prefix) && $gte$(prefix.indexOf$1("."), (0))) {
6000 $globals.world.error("library prefix canot contain \".\"", node.span);
6001 }
6002 else if (this.seenSource || this.seenResource) {
6003 $globals.world.error("#imports must come before any #source or #resource ", node.span);
6004 }
6005 if ($eq$(prefix, "")) prefix = null;
6006 var filename = this.library.makeFullPath(name);
6007 if (this.library.imports.some((function (li) {
6008 return $eq$(li.get$library().baseSource, filename);
6009 })
6010 )) {
6011 $globals.world.error(("duplicate import of \"" + name + "\""), node.span );
6012 return;
6013 }
6014 var newLib = this.library.addImport(filename, prefix, node.span);
6015 break;
6016
6017 case "source":
6018
6019 this.seenSource = true;
6020 name = this.getSingleStringArg(node);
6021 this.addSourceFromName(name, node.span);
6022 if (this.seenResource) {
6023 $globals.world.error("#sources must come before any #resource", node.spa n);
6024 }
6025 break;
6026
6027 case "native":
6028
6029 name = this.getSingleStringArg(node);
6030 this.library.addNative(this.library.makeFullPath(name));
6031 break;
6032
6033 case "resource":
6034
6035 this.seenResource = true;
6036 this.getFirstStringArg(node);
6037 break;
6038
6039 default:
6040
6041 $globals.world.error(("unknown directive: " + node.name.name), node.span);
6042
6043 }
6044 }
6045 _LibraryVisitor.prototype.getSingleStringArg = function(node) {
6046 if (node.arguments.get$length() != (1)) {
6047 $globals.world.error(("expected exactly one argument but found " + node.argu ments.get$length()), node.span);
6048 }
6049 return this.getFirstStringArg(node);
6050 }
6051 _LibraryVisitor.prototype.getFirstStringArg = function(node) {
6052 if (node.arguments.get$length() < (1)) {
6053 $globals.world.error(("expected at least one argument but found " + node.arg uments.get$length()), node.span);
6054 }
6055 var arg = node.arguments.$index((0));
6056 if (arg.get$label() != null) {
6057 $globals.world.error("label not allowed for directive", node.span);
6058 }
6059 return this._parseStringArgument(arg);
6060 }
6061 _LibraryVisitor.prototype.tryGetNamedStringArg = function(node, argName) {
6062 var args = node.arguments.filter((function (a) {
6063 return a.get$label() != null && a.get$label().name == argName;
6064 })
6065 );
6066 if (args.get$length() == (0)) {
6067 return null;
6068 }
6069 if (args.get$length() > (1)) {
6070 $globals.world.error(("expected at most one \"" + argName + "\" argument but found ") + node.arguments.get$length(), node.span);
6071 }
6072 for (var $$i = args.iterator(); $$i.hasNext(); ) {
6073 var arg = $$i.next();
6074 return this._parseStringArgument(arg);
6075 }
6076 }
6077 _LibraryVisitor.prototype._parseStringArgument = function(arg) {
6078 var expr = arg.value;
6079 if (!(expr instanceof LiteralExpression) || !expr.get$value().get$type().get$i sString()) {
6080 $globals.world.error("expected string literal", expr.get$span());
6081 }
6082 return expr.get$value().get$actualValue();
6083 }
6084 _LibraryVisitor.prototype.visitTypeDefinition = function(node) {
6085 var oldType = this.currentType;
6086 this.currentType = this.library.addType(node.name.name, node, node.isClass);
6087 var $$list = node.body;
6088 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
6089 var member = $$i.next();
6090 member.visit(this);
6091 }
6092 this.currentType = oldType;
6093 }
6094 _LibraryVisitor.prototype.visitVariableDefinition = function(node) {
6095 this.currentType.addField(node);
6096 }
6097 _LibraryVisitor.prototype.visitFunctionDefinition = function(node) {
6098 this.currentType.addMethod(node.name.name, node);
6099 }
6100 _LibraryVisitor.prototype.visitFunctionTypeDefinition = function(node) {
6101 var type = this.library.addType(node.func.name.name, node, false);
6102 type.addMethod(":call", node.func);
6103 }
6104 // ********** Code for Parameter **************
6105 function Parameter(definition, method) {
6106 this.isInitializer = false;
6107 this.definition = definition;
6108 this.method = method;
6109 }
6110 Parameter.prototype.get$definition = function() { return this.definition; };
6111 Parameter.prototype.get$method = function() { return this.method; };
6112 Parameter.prototype.get$name = function() { return this.name; };
6113 Parameter.prototype.set$name = function(value) { return this.name = value; };
6114 Parameter.prototype.get$type = function() { return this.type; };
6115 Parameter.prototype.get$isInitializer = function() { return this.isInitializer; };
6116 Parameter.prototype.get$value = function() { return this.value; };
6117 Parameter.prototype.set$value = function(value) { return this.value = value; };
6118 Parameter.prototype.resolve = function() {
6119 this.name = this.definition.name.name;
6120 if (this.name.startsWith("this.")) {
6121 this.name = this.name.substring((5));
6122 this.isInitializer = true;
6123 }
6124 this.type = this.method.resolveType(this.definition.type, false, true);
6125 if (this.definition.value != null) {
6126 if (!this.get$hasDefaultValue()) return;
6127 if (this.method.name == ":call") {
6128 var methodDef = this.method.get$definition();
6129 if ($eq$(methodDef.get$body()) && !this.method.get$isNative()) {
6130 $globals.world.error("default value not allowed on function type", this. definition.span);
6131 }
6132 }
6133 else if (this.method.get$isAbstract()) {
6134 $globals.world.error("default value not allowed on abstract methods", this .definition.span);
6135 }
6136 }
6137 else if (this.isInitializer && !this.method.get$isConstructor()) {
6138 $globals.world.error("initializer parameters only allowed on constructors", this.definition.span);
6139 }
6140 }
6141 Parameter.prototype.genValue = function(method, context) {
6142 if (this.definition.value == null || this.value != null) return;
6143 if ((context instanceof MethodGenerator)) {
6144 var gen = context;
6145 this.value = this.definition.value.visit(gen);
6146 if (!this.value.get$isConst()) {
6147 $globals.world.error("default parameter values must be constant", this.val ue.span);
6148 }
6149 this.value = this.value.convertTo(context, this.type);
6150 }
6151 }
6152 Parameter.prototype.get$isOptional = function() {
6153 return this.definition != null && this.definition.value != null;
6154 }
6155 Parameter.prototype.get$hasDefaultValue = function() {
6156 return this.definition.value.span.start != this.definition.span.start;
6157 }
6158 // ********** Code for TypeMember **************
6159 $inherits(TypeMember, Member);
6160 function TypeMember(type) {
6161 this.type = type;
6162 Member.call(this, type.name, type.library.topType);
6163 }
6164 TypeMember.prototype.get$type = function() { return this.type; };
6165 TypeMember.prototype.get$span = function() {
6166 return null == this.type.definition ? null : this.type.definition.span;
6167 }
6168 TypeMember.prototype.get$isStatic = function() {
6169 return true;
6170 }
6171 TypeMember.prototype.get$returnType = function() {
6172 return $globals.world.varType;
6173 }
6174 TypeMember.prototype.canInvoke = function(context, args) {
6175 return false;
6176 }
6177 TypeMember.prototype.get$canGet = function() {
6178 return true;
6179 }
6180 TypeMember.prototype.get$canSet = function() {
6181 return false;
6182 }
6183 TypeMember.prototype._get = function(context, node, target) {
6184 return new TypeValue(this.type, node.span);
6185 }
6186 TypeMember.prototype._set = function(context, node, target, value) {
6187 $globals.world.error("cannot set type", node.span);
6188 }
6189 TypeMember.prototype.invoke = function(context, node, target, args) {
6190 $globals.world.error("cannot invoke type", node.span);
6191 }
6192 // ********** Code for FieldMember **************
6193 $inherits(FieldMember, Member);
6194 function FieldMember(name, declaringType, definition, value, isNative) {
6195 this._computing = false;
6196 this.definition = definition;
6197 this.value = value;
6198 this.isNative = isNative;
6199 Member.call(this, name, declaringType);
6200 }
6201 FieldMember.prototype.get$definition = function() { return this.definition; };
6202 FieldMember.prototype.get$value = function() { return this.value; };
6203 FieldMember.prototype.get$type = function() { return this.type; };
6204 FieldMember.prototype.get$isStatic = function() { return this.isStatic; };
6205 FieldMember.prototype.set$isStatic = function(value) { return this.isStatic = va lue; };
6206 FieldMember.prototype.get$isFinal = function() { return this.isFinal; };
6207 FieldMember.prototype.get$isNative = function() { return this.isNative; };
6208 FieldMember.prototype.override = function(other) {
6209 if (!Member.prototype.override.call(this, other)) return false;
6210 if (other.get$isProperty() || other.get$isField()) {
6211 return true;
6212 }
6213 else {
6214 $globals.world.error("field can only override field or property", this.get$s pan(), other.get$span());
6215 return false;
6216 }
6217 }
6218 FieldMember.prototype.provideGetter = function() {
6219 this._provideGetter = true;
6220 if (null != this.genericMember) {
6221 this.genericMember.provideGetter();
6222 }
6223 }
6224 FieldMember.prototype.provideSetter = function() {
6225 this._provideSetter = true;
6226 if (null != this.genericMember) {
6227 this.genericMember.provideSetter();
6228 }
6229 }
6230 FieldMember.prototype.makeConcrete = function(concreteType) {
6231 var ret = new FieldMember(this.name, concreteType, this.definition, this.value , false);
6232 ret.set$genericMember(this);
6233 ret.set$_jsname(this._jsname);
6234 return ret;
6235 }
6236 FieldMember.prototype.get$span = function() {
6237 return this.definition == null ? null : this.definition.span;
6238 }
6239 FieldMember.prototype.get$returnType = function() {
6240 return this.type;
6241 }
6242 FieldMember.prototype.get$canGet = function() {
6243 return true;
6244 }
6245 FieldMember.prototype.get$canSet = function() {
6246 return !this.isFinal;
6247 }
6248 FieldMember.prototype.get$isField = function() {
6249 return true;
6250 }
6251 FieldMember.prototype.resolve = function() {
6252 this.isStatic = this.declaringType.get$isTop();
6253 this.isFinal = false;
6254 if (this.definition.modifiers != null) {
6255 var $$list = this.definition.modifiers;
6256 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
6257 var mod = $$i.next();
6258 if (mod.get$kind() == (85)) {
6259 if (this.isStatic) {
6260 $globals.world.error("duplicate static modifier", mod.get$span());
6261 }
6262 this.isStatic = true;
6263 }
6264 else if (mod.get$kind() == (99)) {
6265 if (this.isFinal) {
6266 $globals.world.error("duplicate final modifier", mod.get$span());
6267 }
6268 this.isFinal = true;
6269 }
6270 else {
6271 $globals.world.error(("" + mod + " modifier not allowed on field"), mod. get$span());
6272 }
6273 }
6274 }
6275 this.type = this.resolveType(this.definition.type, false, true);
6276 if (this.isStatic && this.isFinal && this.value == null) {
6277 $globals.world.error("static final field is missing initializer", this.get$s pan());
6278 }
6279 if (this.declaringType.get$isClass()) this.get$library()._addMember(this);
6280 }
6281 FieldMember.prototype.computeValue = function() {
6282 if (this.value == null) return null;
6283 if (this._computedValue == null) {
6284 if (this._computing) {
6285 $globals.world.error("circular reference", this.value.span);
6286 return null;
6287 }
6288 this._computing = true;
6289 var finalMethod = new MethodMember("final_context", this.declaringType, null );
6290 finalMethod.set$isStatic(true);
6291 var finalGen = new MethodGenerator(finalMethod, null);
6292 this._computedValue = this.value.visit(finalGen);
6293 if (!this._computedValue.get$isConst()) {
6294 if (this.isStatic) {
6295 $globals.world.error("non constant static field must be initialized in f unctions", this.value.span);
6296 }
6297 else {
6298 $globals.world.error("non constant field must be initialized in construc tor", this.value.span);
6299 }
6300 }
6301 if (this.isStatic) {
6302 if (this.isFinal && this._computedValue.get$isConst()) {
6303 ;
6304 }
6305 else {
6306 this._computedValue = $globals.world.gen.globalForStaticField(this, this ._computedValue, [this._computedValue]);
6307 }
6308 }
6309 this._computing = false;
6310 }
6311 return this._computedValue;
6312 }
6313 FieldMember.prototype._get = function(context, node, target) {
6314 if (!context.get$needsCode()) {
6315 return new PureStaticValue(this.type, node.span, this.isStatic && this.isFin al, false);
6316 }
6317 if (this.isNative && this.get$returnType() != null) {
6318 this.get$returnType().markUsed();
6319 if ((this.get$returnType() instanceof DefinedType)) {
6320 var defaultType = this.get$returnType().get$genericType().defaultType;
6321 if ($ne$(defaultType) && defaultType.get$isNative()) {
6322 defaultType.markUsed();
6323 }
6324 }
6325 }
6326 if (this.isStatic) {
6327 this.declaringType.markUsed();
6328 var cv = this.computeValue();
6329 if (this.isFinal) {
6330 return cv;
6331 }
6332 $globals.world.gen.hasStatics = true;
6333 if (this.declaringType.get$isTop()) {
6334 if (this.declaringType.get$library().get$isDom()) {
6335 return new Value(this.type, ("" + this.get$jsname()), node.span);
6336 }
6337 else {
6338 return new Value(this.type, ("$globals." + this.get$jsname()), node.span );
6339 }
6340 }
6341 else if (this.declaringType.get$isNative()) {
6342 if (this.declaringType.get$isHiddenNativeType()) {
6343 $globals.world.error("static field of hidden native type is inaccessible ", node.span);
6344 }
6345 return new Value(this.type, ("" + this.declaringType.get$jsname() + "." + this.get$jsname()), node.span);
6346 }
6347 else {
6348 return new Value(this.type, ("$globals." + this.declaringType.get$jsname() + "_" + this.get$jsname()), node.span);
6349 }
6350 }
6351 return new Value(this.type, ("" + target.get$code() + "." + this.get$jsname()) , node.span);
6352 }
6353 FieldMember.prototype._set = function(context, node, target, value) {
6354 if (!context.get$needsCode()) {
6355 return new PureStaticValue(this.type, node.span, false, false);
6356 }
6357 var lhs = this._get(context, node, target);
6358 value = value.convertTo(context, this.type);
6359 return new Value(this.type, ("" + lhs.get$code() + " = " + value.get$code()), node.span);
6360 }
6361 // ********** Code for PropertyMember **************
6362 $inherits(PropertyMember, Member);
6363 function PropertyMember(name, declaringType) {
6364 Member.call(this, name, declaringType);
6365 }
6366 PropertyMember.prototype.get$getter = function() { return this.getter; };
6367 PropertyMember.prototype.set$getter = function(value) { return this.getter = val ue; };
6368 PropertyMember.prototype.get$setter = function() { return this.setter; };
6369 PropertyMember.prototype.set$setter = function(value) { return this.setter = val ue; };
6370 PropertyMember.prototype.get$span = function() {
6371 return this.getter != null ? this.getter.get$span() : null;
6372 }
6373 PropertyMember.prototype.get$canGet = function() {
6374 return this.getter != null;
6375 }
6376 PropertyMember.prototype.get$canSet = function() {
6377 return this.setter != null;
6378 }
6379 PropertyMember.prototype.get$needsFieldSyntax = function() {
6380 return this._overriddenField != null && this._overriddenField.get$isNative() & & !this._overriddenField.declaringType.get$isHiddenNativeType();
6381 }
6382 PropertyMember.prototype.get$isStatic = function() {
6383 return this.getter == null ? this.setter.isStatic : this.getter.isStatic;
6384 }
6385 PropertyMember.prototype.get$isProperty = function() {
6386 return true;
6387 }
6388 PropertyMember.prototype.get$returnType = function() {
6389 return this.getter == null ? this.setter.returnType : this.getter.returnType;
6390 }
6391 PropertyMember.prototype.makeConcrete = function(concreteType) {
6392 var ret = new PropertyMember(this.name, concreteType);
6393 if (null != this.getter) ret.set$getter(this.getter.makeConcrete(concreteType) );
6394 if (null != this.setter) ret.set$setter(this.setter.makeConcrete(concreteType) );
6395 ret.set$_jsname(this._jsname);
6396 return ret;
6397 }
6398 PropertyMember.prototype.override = function(other) {
6399 if (!Member.prototype.override.call(this, other)) return false;
6400 if (other.get$isProperty() || other.get$isField()) {
6401 if (other.get$isProperty()) this.addFromParent(other);
6402 else this._overriddenField = other;
6403 return true;
6404 }
6405 else {
6406 $globals.world.error("property can only override field or property", this.ge t$span(), other.get$span());
6407 return false;
6408 }
6409 }
6410 PropertyMember.prototype._get = function(context, node, target) {
6411 if (this.getter == null) {
6412 if (this._overriddenField != null) {
6413 return this._overriddenField._get(context, node, target);
6414 }
6415 return target.invokeNoSuchMethod$3(context, ("get:" + this.name), node);
6416 }
6417 return this.getter.invoke(context, node, target, Arguments.get$EMPTY());
6418 }
6419 PropertyMember.prototype._set = function(context, node, target, value) {
6420 if (this.setter == null) {
6421 if (this._overriddenField != null) {
6422 return this._overriddenField._set(context, node, target, value);
6423 }
6424 return target.invokeNoSuchMethod(context, ("set:" + this.name), node, new Ar guments(null, [value]));
6425 }
6426 return this.setter.invoke(context, node, target, new Arguments(null, [value])) ;
6427 }
6428 PropertyMember.prototype.addFromParent = function(parentMember) {
6429 var parent = parentMember;
6430 if (this.getter == null) this.getter = parent.get$getter();
6431 if (this.setter == null) this.setter = parent.get$setter();
6432 }
6433 PropertyMember.prototype.resolve = function() {
6434 if (this.getter != null) {
6435 this.getter.resolve();
6436 if (this.getter.parameters.get$length() != (0)) {
6437 $globals.world.error("getter methods should take no arguments", this.gette r.definition.span);
6438 }
6439 if (this.getter.returnType.get$isVoid()) {
6440 $globals.world.warning("getter methods should not be void", this.getter.de finition.returnType.span);
6441 }
6442 }
6443 if (this.setter != null) {
6444 this.setter.resolve();
6445 if (this.setter.parameters.get$length() != (1)) {
6446 $globals.world.error("setter methods should take a single argument", this. setter.definition.span);
6447 }
6448 if (!this.setter.returnType.get$isVoid() && this.setter.definition.returnTyp e != null) {
6449 $globals.world.warning("setter methods should be void", this.setter.defini tion.returnType.span);
6450 }
6451 }
6452 if (this.declaringType.get$isClass()) this.get$library()._addMember(this);
6453 }
6454 // ********** Code for MethodMember **************
6455 $inherits(MethodMember, Member);
6456 function MethodMember(name, declaringType, definition) {
6457 this.isStatic = false;
6458 this.isAbstract = false;
6459 this.isConst = false;
6460 this.isFactory = false;
6461 this._provideOptionalParamInfo = false;
6462 this._hasNativeBody = false;
6463 this.definition = definition;
6464 this.isLambda = false;
6465 Member.call(this, name, declaringType);
6466 if (this.get$isNative()) {
6467 if (const$0013.hasMatch(this.definition.nativeBody)) {
6468 this._jsname = this.definition.nativeBody;
6469 $globals.world._addHazardousMemberName(this._jsname);
6470 }
6471 this._hasNativeBody = this.definition.nativeBody != "" && this.definition.na tiveBody != this._jsname;
6472 }
6473 }
6474 MethodMember.lambda$ctor = function(name, declaringType, definition) {
6475 this.isStatic = false;
6476 this.isAbstract = false;
6477 this.isConst = false;
6478 this.isFactory = false;
6479 this._provideOptionalParamInfo = false;
6480 this._hasNativeBody = false;
6481 this.definition = definition;
6482 this.isLambda = true;
6483 Member.call(this, name, declaringType);
6484 }
6485 MethodMember.lambda$ctor.prototype = MethodMember.prototype;
6486 MethodMember.prototype.get$definition = function() { return this.definition; };
6487 MethodMember.prototype.get$returnType = function() { return this.returnType; };
6488 MethodMember.prototype.set$returnType = function(value) { return this.returnType = value; };
6489 MethodMember.prototype.get$parameters = function() { return this.parameters; };
6490 MethodMember.prototype.set$parameters = function(value) { return this.parameters = value; };
6491 MethodMember.prototype.set$_methodData = function(value) { return this._methodDa ta = value; };
6492 MethodMember.prototype.get$isStatic = function() { return this.isStatic; };
6493 MethodMember.prototype.set$isStatic = function(value) { return this.isStatic = v alue; };
6494 MethodMember.prototype.get$isAbstract = function() { return this.isAbstract; };
6495 MethodMember.prototype.set$isAbstract = function(value) { return this.isAbstract = value; };
6496 MethodMember.prototype.get$isConst = function() { return this.isConst; };
6497 MethodMember.prototype.get$isFactory = function() { return this.isFactory; };
6498 MethodMember.prototype.get$initDelegate = function() { return this.initDelegate; };
6499 MethodMember.prototype.set$initDelegate = function(value) { return this.initDele gate = value; };
6500 MethodMember.prototype.makeConcrete = function(concreteType) {
6501 var _name = this.get$isConstructor() ? concreteType.name : this.name;
6502 var ret = new MethodMember(_name, concreteType, this.definition);
6503 ret.set$genericMember(this);
6504 ret.set$_jsname(this._jsname);
6505 return ret;
6506 }
6507 MethodMember.prototype.get$methodData = function() {
6508 if (null != this.genericMember) return this.genericMember.get$dynamic().get$me thodData();
6509 if (null == this._methodData) {
6510 this._methodData = new MethodData(this);
6511 }
6512 return this._methodData;
6513 }
6514 MethodMember.prototype.get$isConstructor = function() {
6515 return this.name == this.declaringType.name;
6516 }
6517 MethodMember.prototype.get$isMethod = function() {
6518 return !this.get$isConstructor();
6519 }
6520 MethodMember.prototype.get$isNative = function() {
6521 if (this.definition == null) return false;
6522 return this.definition.nativeBody != null;
6523 }
6524 MethodMember.prototype.get$hasNativeBody = function() {
6525 return this._hasNativeBody;
6526 }
6527 MethodMember.prototype.get$canGet = function() {
6528 return true;
6529 }
6530 MethodMember.prototype.get$canSet = function() {
6531 return false;
6532 }
6533 MethodMember.prototype.get$span = function() {
6534 return this.definition == null ? null : this.definition.span;
6535 }
6536 MethodMember.prototype.get$constructorName = function() {
6537 var returnType = this.definition.returnType;
6538 if ($eq$(returnType)) return "";
6539 if ((returnType instanceof GenericTypeReference)) {
6540 return "";
6541 }
6542 if (returnType.get$names() != null) {
6543 return returnType.get$names().$index((0)).name;
6544 }
6545 else if ($ne$(returnType.get$name())) {
6546 return returnType.get$name().get$name();
6547 }
6548 $globals.world.internalError("no valid constructor name", this.definition.span );
6549 }
6550 MethodMember.prototype.get$functionType = function() {
6551 if (this._functionType == null) {
6552 this._functionType = this.get$library().getOrAddFunctionType(this.declaringT ype, this.name, this.definition, this.get$methodData());
6553 if (this.parameters == null) {
6554 this.resolve();
6555 }
6556 }
6557 return this._functionType;
6558 }
6559 MethodMember.prototype.override = function(other) {
6560 if (!Member.prototype.override.call(this, other)) return false;
6561 if (other.get$isMethod()) {
6562 return true;
6563 }
6564 else {
6565 $globals.world.error("method can only override methods", this.get$span(), ot her.get$span());
6566 return false;
6567 }
6568 }
6569 MethodMember.prototype.canInvoke = function(context, args) {
6570 var bareCount = args.get$bareCount();
6571 if (bareCount > this.parameters.get$length()) return false;
6572 if (bareCount == this.parameters.get$length()) {
6573 if (bareCount != args.get$length()) return false;
6574 }
6575 else {
6576 if (!this.parameters.$index(bareCount).get$isOptional()) return false;
6577 for (var i = bareCount;
6578 i < args.get$length(); i++) {
6579 if (this.indexOfParameter(args.getName(i)) < (0)) {
6580 return false;
6581 }
6582 }
6583 }
6584 return true;
6585 }
6586 MethodMember.prototype.indexOfParameter = function(name) {
6587 for (var i = (0);
6588 i < this.parameters.get$length(); i++) {
6589 var p = this.parameters.$index(i);
6590 if (p.get$isOptional() && $eq$(p.get$name(), name)) {
6591 return i;
6592 }
6593 }
6594 return (-1);
6595 }
6596 MethodMember.prototype.provideGetter = function() {
6597 this._provideGetter = true;
6598 }
6599 MethodMember.prototype.provideSetter = function() {
6600 this._provideSetter = true;
6601 }
6602 MethodMember.prototype._set = function(context, node, target, value) {
6603 $globals.world.error("cannot set method", node.span);
6604 }
6605 MethodMember.prototype._get = function(context, node, target) {
6606 if (!context.get$needsCode()) {
6607 return new PureStaticValue(this.get$functionType(), node.span, false, false) ;
6608 }
6609 this.declaringType.genMethod(this);
6610 this._provideOptionalParamInfo = true;
6611 if (this.isStatic) {
6612 this.declaringType.markUsed();
6613 var type = this.declaringType.get$isTop() ? "" : ("" + this.declaringType.ge t$jsname() + ".");
6614 return new Value(this.get$functionType(), ("" + type + this.get$jsname()), n ode.span);
6615 }
6616 this._provideGetter = true;
6617 return new Value(this.get$functionType(), ("" + target.get$code() + ".get$" + this.get$jsname() + "()"), node.span);
6618 }
6619 MethodMember.prototype.namesInHomePositions = function(args) {
6620 if (!args.get$hasNames()) return true;
6621 for (var i = args.get$bareCount();
6622 i < args.values.get$length(); i++) {
6623 if (i >= this.parameters.get$length()) {
6624 return false;
6625 }
6626 if (args.getName(i) != this.parameters.$index(i).name) {
6627 return false;
6628 }
6629 }
6630 return true;
6631 }
6632 MethodMember.prototype.namesInOrder = function(args) {
6633 if (!args.get$hasNames()) return true;
6634 var lastParameter = null;
6635 for (var i = args.get$bareCount();
6636 i < this.parameters.get$length(); i++) {
6637 var p = args.getIndexOfName(this.parameters.$index(i).name);
6638 if ($gte$(p, (0)) && args.values.$index(p).get$needsTemp()) {
6639 if (lastParameter != null && $gt$(lastParameter, p)) {
6640 return false;
6641 }
6642 lastParameter = p;
6643 }
6644 }
6645 return true;
6646 }
6647 MethodMember.prototype.needsArgumentConversion = function(args) {
6648 var bareCount = args.get$bareCount();
6649 for (var i = (0);
6650 i < bareCount; i++) {
6651 var arg = args.values.$index(i);
6652 if (arg.needsConversion(this.parameters.$index(i).type)) {
6653 return true;
6654 }
6655 }
6656 if (bareCount < this.parameters.get$length()) {
6657 for (var i = bareCount;
6658 i < this.parameters.get$length(); i++) {
6659 var arg = args.getValue(this.parameters.$index(i).name);
6660 if ($ne$(arg) && arg.needsConversion(this.parameters.$index(i).type)) {
6661 return true;
6662 }
6663 }
6664 }
6665 return false;
6666 }
6667 MethodMember.prototype.hasOptionalParameters = function() {
6668 return this.parameters.some((function (p) {
6669 return p.get$isOptional();
6670 })
6671 );
6672 }
6673 MethodMember.prototype._tooManyArgumentsMsg = function(actual, expected) {
6674 return this.hasOptionalParameters() ? ("too many arguments, expected at most " + expected + " but found " + actual) : this._wrongArgumentCountMsg(actual, expe cted);
6675 }
6676 MethodMember.prototype._tooFewArgumentsMsg = function(actual, expected) {
6677 return this.hasOptionalParameters() ? ("too few arguments, expected at least " + expected + " but found " + actual) : this._wrongArgumentCountMsg(actual, expe cted);
6678 }
6679 MethodMember.prototype._wrongArgumentCountMsg = function(actual, expected) {
6680 return ("wrong number of arguments, expected " + expected + " but found " + ac tual);
6681 }
6682 MethodMember.prototype._argError = function(context, node, target, args, msg, ar gIndex) {
6683 if (context.get$showWarnings()) {
6684 var span;
6685 if ((args.nodes == null) || (argIndex >= args.nodes.get$length())) {
6686 span = node.span;
6687 }
6688 else {
6689 span = args.nodes.$index(argIndex).span;
6690 }
6691 if (this.isStatic || this.get$isConstructor()) {
6692 $globals.world.error(msg, span);
6693 }
6694 else {
6695 $globals.world.warning(msg, span);
6696 }
6697 }
6698 return target.invokeNoSuchMethod(context, this.name, node, args);
6699 }
6700 MethodMember.prototype.genParameterValues = function(context) {
6701 if (context.get$needsCode()) {
6702 var $$list = this.parameters;
6703 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
6704 var p = $$i.next();
6705 p.genValue(this, context);
6706 }
6707 }
6708 }
6709 MethodMember.prototype.invoke = function(context, node, target, args) {
6710 var argValues = [];
6711 var bareCount = args.get$bareCount();
6712 for (var i = (0);
6713 i < bareCount; i++) {
6714 var arg = args.values.$index(i);
6715 if (i >= this.parameters.get$length()) {
6716 var msg = this._tooManyArgumentsMsg(args.get$length(), this.parameters.get $length());
6717 return this._argError(context, node, target, args, msg, i);
6718 }
6719 argValues.add(arg.convertTo(context, this.parameters.$index(i).type));
6720 }
6721 var namedArgsUsed = (0);
6722 if (bareCount < this.parameters.get$length()) {
6723 this.genParameterValues(context);
6724 for (var i = bareCount;
6725 i < this.parameters.get$length(); i++) {
6726 var param = this.parameters.$index(i);
6727 var arg = args.getValue(param.get$name());
6728 if ($eq$(arg)) {
6729 arg = param.get$value();
6730 if ($eq$(arg)) {
6731 arg = new PureStaticValue(param.get$type(), param.get$definition().get $span(), true, false);
6732 }
6733 }
6734 else {
6735 arg = arg.convertTo(context, this.parameters.$index(i).type);
6736 namedArgsUsed++;
6737 }
6738 if ($eq$(arg) || !this.parameters.$index(i).get$isOptional()) {
6739 var msg = this._tooFewArgumentsMsg(Math.min(i, args.get$length()), i + ( 1));
6740 return this._argError(context, node, target, args, msg, i);
6741 }
6742 else {
6743 argValues.add(arg);
6744 }
6745 }
6746 }
6747 if (namedArgsUsed < args.get$nameCount()) {
6748 var seen = new HashSetImplementation_dart_core_String();
6749 for (var i = bareCount;
6750 i < args.get$length(); i++) {
6751 var name = args.getName(i);
6752 if (seen.contains$1(name)) {
6753 return this._argError(context, node, target, args, ("duplicate argument \"" + name + "\""), i);
6754 }
6755 seen.add(name);
6756 var p = this.indexOfParameter(name);
6757 if (p < (0)) {
6758 return this._argError(context, node, target, args, ("method does not hav e optional parameter \"" + name + "\""), i);
6759 }
6760 else if (p < bareCount) {
6761 return this._argError(context, node, target, args, ("argument \"" + name + "\" passed as positional and named"), p);
6762 }
6763 }
6764 $globals.world.internalError(("wrong named arguments calling " + this.name), node.span);
6765 }
6766 if (!context.get$needsCode()) {
6767 return new PureStaticValue(this.returnType, node.span, false, false);
6768 }
6769 this.declaringType.genMethod(this);
6770 if (this.isStatic || this.isFactory) {
6771 this.declaringType.markUsed();
6772 }
6773 if (this.get$isNative() && this.returnType != null) this.returnType.markUsed() ;
6774 if (!this.namesInOrder(args)) {
6775 return context.findMembers(this.name).invokeOnVar(context, node, target, arg s);
6776 }
6777 var argsCode = argValues.map((function (v) {
6778 return v.get$code();
6779 })
6780 );
6781 if (!target.get$isType() && (this.get$isConstructor() || target.get$isSuper()) ) {
6782 argsCode.insertRange((0), (1), "this");
6783 }
6784 if (bareCount < this.parameters.get$length()) {
6785 Arguments.removeTrailingNulls(argsCode);
6786 }
6787 var argsString = Strings.join(argsCode, ", ");
6788 if (this.get$isConstructor()) {
6789 return this._invokeConstructor(context, node, target, args, argsString);
6790 }
6791 if (target.get$isSuper()) {
6792 return new Value(this.get$inferredResult(), ("" + this.declaringType.get$jsn ame() + ".prototype." + this.get$jsname() + ".call(" + argsString + ")"), node.s pan);
6793 }
6794 if (this.get$isOperator()) {
6795 return this._invokeBuiltin(context, node, target, args, argsCode);
6796 }
6797 if (this.isFactory) {
6798 return new Value(target.get$type(), ("" + this.get$generatedFactoryName() + "(" + argsString + ")"), null != node ? node.span : null);
6799 }
6800 if (this.isStatic) {
6801 if (this.declaringType.get$isTop()) {
6802 return new Value(this.get$inferredResult(), ("" + this.get$jsname() + "(" + argsString + ")"), null != node ? node.span : null);
6803 }
6804 return new Value(this.get$inferredResult(), ("" + this.declaringType.get$jsn ame() + "." + this.get$jsname() + "(" + argsString + ")"), node.span);
6805 }
6806 if (this.name == "get:typeName" && this.declaringType.get$library().get$isDom( )) {
6807 $globals.world.gen.corejs.ensureTypeNameOf();
6808 }
6809 var code = ("" + target.get$code() + "." + this.get$jsname() + "(" + argsStrin g + ")");
6810 return new Value(this.get$inferredResult(), code, node.span);
6811 }
6812 MethodMember.prototype._invokeConstructor = function(context, node, target, args , argsString) {
6813 this.declaringType.markUsed();
6814 var ctor = this.get$constructorName();
6815 if (ctor != "") ctor = ("." + ctor + "$ctor");
6816 var span = node != null ? node.span : target.span;
6817 if (!target.get$isType()) {
6818 var code = ("" + this.declaringType.get$nativeName() + ctor + ".call(" + arg sString + ")");
6819 return new Value(target.get$type(), code, span);
6820 }
6821 else {
6822 if (this.isConst && (node instanceof NewExpression) && node.get$dynamic().ge t$isConst()) {
6823 if (this.get$isNative() || this.declaringType.name == "JSSyntaxRegExp") {
6824 var code = ("new " + this.declaringType.get$nativeName() + ctor + "(" + argsString + ")");
6825 return $globals.world.gen.globalForConst(new Value(target.get$type(), co de, span), [args.values]);
6826 }
6827 var newType = this.declaringType;
6828 var newObject = new ObjectValue(true, newType, span);
6829 newObject.initFields();
6830 this._evalConstConstructor(newObject, args);
6831 return $globals.world.gen.globalForConst(newObject, [args.values]);
6832 }
6833 else {
6834 var code = ("new " + this.declaringType.get$nativeName() + ctor + "(" + ar gsString + ")");
6835 return new Value(target.get$type(), code, span);
6836 }
6837 }
6838 }
6839 MethodMember.prototype._evalConstConstructor = function(newObject, args) {
6840 this.declaringType.markUsed();
6841 this.get$methodData().eval(this, newObject, args);
6842 }
6843 MethodMember.prototype._invokeBuiltin = function(context, node, target, args, ar gsCode) {
6844 if (target.get$type().get$isNum()) {
6845 var code = null;
6846 if (args.get$length() == (0)) {
6847 if (this.name == ":negate") {
6848 code = ("-" + target.get$code());
6849 }
6850 else if (this.name == ":bit_not") {
6851 code = ("~" + target.get$code());
6852 }
6853 }
6854 else if (args.get$length() == (1) && args.values.$index((0)).get$type().get$ isNum()) {
6855 if (this.name == ":truncdiv" || this.name == ":mod") {
6856 $globals.world.gen.corejs.useOperator(this.name);
6857 code = ("" + this.get$jsname() + "$(" + target.get$code() + ", " + argsC ode.$index((0)) + ")");
6858 }
6859 else {
6860 var op = TokenKind.rawOperatorFromMethod(this.name);
6861 code = ("" + target.get$code() + " " + op + " " + argsCode.$index((0)));
6862 }
6863 }
6864 if (null != code) {
6865 return new Value(this.get$inferredResult(), code, node.span);
6866 }
6867 }
6868 else if (target.get$type().get$isString()) {
6869 if (this.name == ":index" && args.values.$index((0)).get$type().get$isNum()) {
6870 return new Value(this.declaringType, ("" + target.get$code() + "[" + argsC ode.$index((0)) + "]"), node.span);
6871 }
6872 else if (this.name == ":add" && args.values.$index((0)).get$type().get$isNum ()) {
6873 return new Value(this.declaringType, ("" + target.get$code() + " + " + arg sCode.$index((0))), node.span);
6874 }
6875 }
6876 else if (this.declaringType.get$isNative() && $globals.options.disableBoundsCh ecks) {
6877 if (args.get$length() > (0) && args.values.$index((0)).get$type().get$isNum( )) {
6878 if (this.name == ":index") {
6879 return new Value(this.returnType, ("" + target.get$code() + "[" + argsCo de.$index((0)) + "]"), node.span);
6880 }
6881 else if (this.name == ":setindex") {
6882 return new Value(this.returnType, ("" + target.get$code() + "[" + argsCo de.$index((0)) + "] = " + argsCode.$index((1))), node.span);
6883 }
6884 }
6885 }
6886 if (this.name == ":eq" || this.name == ":ne") {
6887 var op = this.name == ":eq" ? "==" : "!=";
6888 if (this.name == ":ne") {
6889 target.invoke(context, ":eq", node, args);
6890 }
6891 if ($eq$(argsCode.$index((0)), "null")) {
6892 return new Value(this.get$inferredResult(), ("" + target.get$code() + " " + op + " null"), node.span);
6893 }
6894 else if (target.get$type().get$isNum() || target.get$type().get$isString()) {
6895 return new Value(this.get$inferredResult(), ("" + target.get$code() + " " + op + " " + argsCode.$index((0))), node.span);
6896 }
6897 $globals.world.gen.corejs.useOperator(this.name);
6898 return new Value(this.get$inferredResult(), ("" + this.get$jsname() + "$(" + target.get$code() + ", " + argsCode.$index((0)) + ")"), node.span);
6899 }
6900 if (this.get$isCallMethod()) {
6901 this.declaringType.markUsed();
6902 return new Value(this.get$inferredResult(), ("" + target.get$code() + "(" + Strings.join(argsCode, ", ") + ")"), node.span);
6903 }
6904 if (this.name == ":index") {
6905 $globals.world.gen.corejs.useIndex = true;
6906 }
6907 else if (this.name == ":setindex") {
6908 $globals.world.gen.corejs.useSetIndex = true;
6909 }
6910 else {
6911 $globals.world.gen.corejs.useOperator(this.name);
6912 var argsString = argsCode.get$length() == (0) ? "" : (", " + argsCode.$index ((0)));
6913 return new Value(this.returnType, ("" + this.get$jsname() + "$(" + target.ge t$code() + argsString + ")"), node.span);
6914 }
6915 var argsString = Strings.join(argsCode, ", ");
6916 return new Value(this.get$inferredResult(), ("" + target.get$code() + "." + th is.get$jsname() + "(" + argsString + ")"), node.span);
6917 }
6918 MethodMember.prototype.resolve = function() {
6919 this.isStatic = this.declaringType.get$isTop();
6920 this.isConst = false;
6921 this.isFactory = false;
6922 this.isAbstract = !this.declaringType.get$isClass();
6923 if (this.definition.modifiers != null) {
6924 var $$list = this.definition.modifiers;
6925 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
6926 var mod = $$i.next();
6927 if (mod.get$kind() == (85)) {
6928 if (this.isStatic) {
6929 $globals.world.error("duplicate static modifier", mod.get$span());
6930 }
6931 this.isStatic = true;
6932 }
6933 else if (this.get$isConstructor() && mod.get$kind() == (92)) {
6934 if (this.isConst) {
6935 $globals.world.error("duplicate const modifier", mod.get$span());
6936 }
6937 if (this.isFactory) {
6938 $globals.world.error("const factory not allowed", mod.get$span());
6939 }
6940 this.isConst = true;
6941 }
6942 else if (mod.get$kind() == (74)) {
6943 if (this.isFactory) {
6944 $globals.world.error("duplicate factory modifier", mod.get$span());
6945 }
6946 if (this.isConst) {
6947 $globals.world.error("const factory not allowed", mod.get$span());
6948 }
6949 if (this.isStatic) {
6950 $globals.world.error("static factory not allowed", mod.get$span());
6951 }
6952 this.isFactory = true;
6953 }
6954 else if (mod.get$kind() == (71)) {
6955 if (this.isAbstract) {
6956 if (this.declaringType.get$isClass()) {
6957 $globals.world.error("duplicate abstract modifier", mod.get$span());
6958 }
6959 else if (!this.get$isCallMethod()) {
6960 $globals.world.error("abstract modifier not allowed on interface mem bers", mod.get$span());
6961 }
6962 }
6963 this.isAbstract = true;
6964 }
6965 else {
6966 $globals.world.error(("" + mod + " modifier not allowed on method"), mod .get$span());
6967 }
6968 }
6969 }
6970 if (this.isFactory) {
6971 this.isStatic = true;
6972 }
6973 if (this.get$isOperator() && this.isStatic && !this.get$isCallMethod()) {
6974 $globals.world.error(("operator method may not be static \"" + this.name + " \""), this.get$span());
6975 }
6976 if (this.isAbstract) {
6977 if (this.definition.body != null && !(this.declaringType.get$definition() in stanceof FunctionTypeDefinition)) {
6978 $globals.world.error("abstract method cannot have a body", this.get$span() );
6979 }
6980 if (this.isStatic && !(this.declaringType.get$definition() instanceof Functi onTypeDefinition)) {
6981 $globals.world.error("static method cannot be abstract", this.get$span());
6982 }
6983 }
6984 else {
6985 if (this.definition.body == null && !this.get$isConstructor() && !this.get$i sNative()) {
6986 $globals.world.error("method needs a body", this.get$span());
6987 }
6988 }
6989 if (this.get$isConstructor() && !this.isFactory) {
6990 this.returnType = this.declaringType;
6991 }
6992 else {
6993 if ((this.definition.returnType instanceof SimpleTypeReference) && $eq$(this .definition.returnType.get$dynamic().get$type(), $globals.world.voidType)) {
6994 this.returnType = $globals.world.voidType;
6995 }
6996 else {
6997 this.returnType = this.resolveType(this.definition.returnType, false, !thi s.isStatic);
6998 }
6999 }
7000 this.parameters = [];
7001 var $$list = this.definition.formals;
7002 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7003 var formal = $$i.next();
7004 var param = new Parameter(formal, this);
7005 param.resolve();
7006 this.parameters.add(param);
7007 }
7008 if (!this.isLambda && this.declaringType.get$isClass()) {
7009 this.get$library()._addMember(this);
7010 }
7011 }
7012 // ********** Code for FactoryMap **************
7013 function FactoryMap() {
7014 this.factories = new HashMapImplementation();
7015 }
7016 FactoryMap.prototype.get$factories = function() { return this.factories; };
7017 FactoryMap.prototype.getFactoriesFor = function(typeName) {
7018 var ret = this.factories.$index(typeName);
7019 if ($eq$(ret)) {
7020 ret = new HashMapImplementation();
7021 this.factories.$setindex(typeName, ret);
7022 }
7023 return ret;
7024 }
7025 FactoryMap.prototype.addFactory = function(typeName, name, member) {
7026 this.getFactoriesFor(typeName).$setindex(name, member);
7027 }
7028 FactoryMap.prototype.getFactory = function(typeName, name) {
7029 return this.getFactoriesFor(typeName).$index(name);
7030 }
7031 FactoryMap.prototype.forEach = function(f) {
7032 this.factories.forEach((function (_, constructors) {
7033 constructors.forEach((function (_, member) {
7034 f(member);
7035 })
7036 );
7037 })
7038 );
7039 }
7040 FactoryMap.prototype.isEmpty = function() {
7041 return this.factories.getValues().every((function (constructors) {
7042 return constructors.isEmpty();
7043 })
7044 );
7045 }
7046 // ********** Code for MemberSet **************
7047 function MemberSet(member, isVar) {
7048 this._preparedForSet = false;
7049 this.name = member.name;
7050 this.members = [member];
7051 this.jsname = member.get$jsname();
7052 this.isVar = isVar;
7053 }
7054 MemberSet.prototype.get$name = function() { return this.name; };
7055 MemberSet.prototype.get$members = function() { return this.members; };
7056 MemberSet.prototype.get$isVar = function() { return this.isVar; };
7057 MemberSet.prototype.get$jsname = function() { return this.jsname; };
7058 MemberSet.prototype.set$jsname = function(value) { return this.jsname = value; } ;
7059 MemberSet.prototype.toString = function() {
7060 return ("" + this.name + ":" + this.members.get$length());
7061 }
7062 MemberSet.prototype.add = function(member) {
7063 this.members.add(member);
7064 }
7065 MemberSet.prototype.get$isOperator = function() {
7066 return this.members.$index((0)).get$isOperator();
7067 }
7068 MemberSet.prototype.get$treatAsField = function() {
7069 if (this._treatAsField == null) {
7070 this._treatAsField = !this.isVar && this.members.every((function (m) {
7071 return m.get$isField();
7072 })
7073 );
7074 }
7075 return this._treatAsField;
7076 }
7077 MemberSet.unionTypes = function(t1, t2) {
7078 if (t1 == null) return t2;
7079 if (t2 == null) return t1;
7080 return Type.union(t1, t2);
7081 }
7082 MemberSet.prototype._get = function(context, node, target) {
7083 if (this.members.get$length() == (1) && !this.isVar) {
7084 return this.members.$index((0))._get(context, node, target);
7085 }
7086 if (this._returnTypeForGet == null) {
7087 var $$list = this.members;
7088 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7089 var member = $$i.next();
7090 if (!member.get$canGet()) continue;
7091 if (!this.get$treatAsField()) member.provideGetter();
7092 var r = member._get(context, node, target);
7093 this._returnTypeForGet = MemberSet.unionTypes(this._returnTypeForGet, r.ge t$type());
7094 }
7095 if (this._returnTypeForGet == null) {
7096 $globals.world.error(("no valid getters for \"" + this.name + "\""), node. span);
7097 }
7098 }
7099 if (this._treatAsField) {
7100 return new Value(this._returnTypeForGet, ("" + target.get$code() + "." + thi s.jsname), node.span);
7101 }
7102 else {
7103 return new Value(this._returnTypeForGet, ("" + target.get$code() + ".get$" + this.jsname + "()"), node.span);
7104 }
7105 }
7106 MemberSet.prototype._set = function(context, node, target, value) {
7107 if (this.members.get$length() == (1) && !this.isVar) {
7108 return this.members.$index((0))._set(context, node, target, value);
7109 }
7110 if (!this._preparedForSet) {
7111 this._preparedForSet = true;
7112 var $$list = this.members;
7113 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7114 var member = $$i.next();
7115 if (!member.get$canSet()) continue;
7116 if (!this.get$treatAsField()) member.provideSetter();
7117 var r = member._set(context, node, target, value);
7118 }
7119 }
7120 if (this.get$treatAsField()) {
7121 return new Value(value.get$type(), ("" + target.get$code() + "." + this.jsna me + " = " + value.get$code()), node.span);
7122 }
7123 else {
7124 return new Value(value.get$type(), ("" + target.get$code() + ".set$" + this. jsname + "(" + value.get$code() + ")"), node.span);
7125 }
7126 }
7127 MemberSet.prototype.invoke = function(context, node, target, args) {
7128 if (this.members.get$length() == (1) && !this.isVar) {
7129 return this.members.$index((0)).invoke(context, node, target, args);
7130 }
7131 var invokeKey = null;
7132 if (this._invokes == null) {
7133 this._invokes = [];
7134 invokeKey = null;
7135 }
7136 else {
7137 var $$list = this._invokes;
7138 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7139 var ik = $$i.next();
7140 if (ik.matches(args)) {
7141 invokeKey = ik;
7142 break;
7143 }
7144 }
7145 }
7146 if ($eq$(invokeKey)) {
7147 invokeKey = new InvokeKey(args);
7148 this._invokes.add(invokeKey);
7149 invokeKey.addMembers(this.members, context, target, args);
7150 }
7151 if (invokeKey.get$needsVarCall() || this.get$isOperator()) {
7152 if (this.name == ":call") {
7153 return target._varCall(context, node, args);
7154 }
7155 else if (this.get$isOperator()) {
7156 return this.invokeSpecial(target, args, invokeKey.get$returnType());
7157 }
7158 else {
7159 return this.invokeOnVar(context, node, target, args);
7160 }
7161 }
7162 else {
7163 var code = ("" + target.get$code() + "." + this.jsname + "(" + args.getCode( ) + ")");
7164 return new Value(invokeKey.get$returnType(), code, node.span);
7165 }
7166 }
7167 MemberSet.prototype.invokeSpecial = function(target, args, returnType) {
7168 var argsString = args.getCode();
7169 if (this.name == ":index" || this.name == ":setindex") {
7170 if (this.name == ":index") {
7171 $globals.world.gen.corejs.useIndex = true;
7172 }
7173 else if (this.name == ":setindex") {
7174 $globals.world.gen.corejs.useSetIndex = true;
7175 }
7176 return new Value(returnType, ("" + target.get$code() + "." + this.jsname + " (" + argsString + ")"), target.span);
7177 }
7178 else {
7179 if (argsString.get$length() > (0)) argsString = (", " + argsString);
7180 $globals.world.gen.corejs.useOperator(this.name);
7181 return new Value(returnType, ("" + this.jsname + "$(" + target.get$code() + argsString + ")"), target.span);
7182 }
7183 }
7184 MemberSet.prototype.invokeOnVar = function(context, node, target, args) {
7185 var $0;
7186 ($0 = context.get$counters()).dynamicMethodCalls = $0.dynamicMethodCalls + (1) ;
7187 var member = this.getVarMember(context, node, args);
7188 return member.invoke(context, node, target, args);
7189 }
7190 MemberSet.prototype.getVarMember = function(context, node, args) {
7191 if ($globals.world.objectType.varStubs == null) {
7192 $globals.world.objectType.varStubs = new HashMapImplementation();
7193 }
7194 var stubName = _getCallStubName(this.name, args);
7195 var stub = $globals.world.objectType.varStubs.$index(stubName);
7196 if ($eq$(stub)) {
7197 var mset = context.findMembers(this.name).members;
7198 var targets = mset.filter((function (m) {
7199 return m.canInvoke(context, args);
7200 })
7201 );
7202 stub = new VarMethodSet(this.name, stubName, targets, args, this._foldTypes( targets));
7203 $globals.world.objectType.varStubs.$setindex(stubName, stub);
7204 }
7205 return stub;
7206 }
7207 MemberSet.prototype._foldTypes = function(targets) {
7208 return reduce(map(targets, (function (t) {
7209 return t.get$returnType();
7210 })
7211 ), Type.union, $globals.world.varType);
7212 }
7213 MemberSet.prototype.toString$0 = MemberSet.prototype.toString;
7214 // ********** Code for InvokeKey **************
7215 function InvokeKey(args) {
7216 this.needsVarCall = false;
7217 this.bareArgs = args.get$bareCount();
7218 if (this.bareArgs != args.get$length()) {
7219 this.namedArgs = args.getNames();
7220 }
7221 }
7222 InvokeKey.prototype.get$returnType = function() { return this.returnType; };
7223 InvokeKey.prototype.set$returnType = function(value) { return this.returnType = value; };
7224 InvokeKey.prototype.get$needsVarCall = function() { return this.needsVarCall; };
7225 InvokeKey.prototype.matches = function(args) {
7226 if (this.namedArgs == null) {
7227 if (this.bareArgs != args.get$length()) return false;
7228 }
7229 else {
7230 if (this.bareArgs + this.namedArgs.get$length() != args.get$length()) return false;
7231 }
7232 if (this.bareArgs != args.get$bareCount()) return false;
7233 if (this.namedArgs == null) return true;
7234 for (var i = (0);
7235 i < this.namedArgs.get$length(); i++) {
7236 if (this.namedArgs.$index(i) != args.getName(this.bareArgs + i)) return fals e;
7237 }
7238 return true;
7239 }
7240 InvokeKey.prototype.addMembers = function(members, context, target, args) {
7241 for (var $$i = members.iterator(); $$i.hasNext(); ) {
7242 var member = $$i.next();
7243 if (!(member.get$parameters().get$length() == this.bareArgs && this.namedArg s == null)) {
7244 this.needsVarCall = true;
7245 }
7246 else if ($globals.options.enableTypeChecks && member.get$isMethod() && membe r.needsArgumentConversion(args)) {
7247 this.needsVarCall = true;
7248 }
7249 else if (member.get$jsname() != members.$index((0)).get$jsname()) {
7250 this.needsVarCall = true;
7251 }
7252 else if ($eq$(member.get$library(), $globals.world.dom)) {
7253 var $$list = member.get$parameters();
7254 for (var $i0 = $$list.iterator(); $i0.hasNext(); ) {
7255 var p = $i0.next();
7256 if (p.get$type().getCallMethod() != null) {
7257 this.needsVarCall = true;
7258 }
7259 }
7260 }
7261 if (member.canInvoke(context, args)) {
7262 if (member.get$isMethod()) {
7263 this.returnType = MemberSet.unionTypes(this.returnType, member.get$retur nType());
7264 member.get$declaringType().genMethod(member);
7265 }
7266 else {
7267 this.needsVarCall = true;
7268 this.returnType = $globals.world.varType;
7269 }
7270 }
7271 }
7272 if (this.returnType == null) {
7273 this.returnType = $globals.world.varType;
7274 }
7275 }
7276 // ********** Code for MethodCallData **************
7277 function MethodCallData(data, method) {
7278 this.data = data;
7279 this.method = method;
7280 }
7281 MethodCallData.prototype.get$method = function() { return this.method; };
7282 MethodCallData.prototype.get$_methodGenerator = function() { return this._method Generator; };
7283 MethodCallData.prototype.matches = function(other) {
7284 return $eq$(this.method, other.method);
7285 }
7286 MethodCallData.prototype.run = function() {
7287 if (null != this._methodGenerator) return;
7288 this._methodGenerator = new MethodGenerator(this.method, this.data.context);
7289 this._methodGenerator.run();
7290 }
7291 MethodCallData.prototype.run$0 = MethodCallData.prototype.run;
7292 // ********** Code for MethodData **************
7293 function MethodData(baseMethod, context) {
7294 this.needsTypeParams = false;
7295 this.baseMethod = baseMethod;
7296 this.context = context;
7297 this._calls = [];
7298 this.body = this.baseMethod.definition.body;
7299 if (this.baseMethod.get$isConstructor()) {
7300 this.needsTypeParams = true;
7301 }
7302 }
7303 MethodData.prototype.get$body = function() { return this.body; };
7304 MethodData.prototype.analyze = function() {
7305 var ma = new MethodAnalyzer(this.baseMethod, this.body);
7306 ma.analyze$1(this.context);
7307 }
7308 MethodData.prototype.eval = function(method, newObject, args) {
7309 if ((null == method ? null != (this.baseMethod) : method !== this.baseMethod)) {
7310 if (!this.needsTypeParams) method = this.baseMethod;
7311 }
7312 var gen = new MethodGenerator(method, this.context);
7313 return gen.evalBody(newObject, args);
7314 }
7315 MethodData.prototype.invokeCall = function(callData) {
7316 var $$list = this._calls;
7317 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7318 var cd = $$i.next();
7319 if (cd.matches(callData)) {
7320 return cd.run$0();
7321 }
7322 }
7323 this._calls.add(callData);
7324 callData.run();
7325 }
7326 MethodData.prototype.run = function(method) {
7327 if (null == this.body && !method.get$isConstructor() && !method.get$isNative() ) return;
7328 if ((null == method ? null != (this.baseMethod) : method !== this.baseMethod)) {
7329 if (!this.needsTypeParams) method = this.baseMethod;
7330 }
7331 var callData = new MethodCallData(this, method);
7332 method.declaringType.get$genericType().markUsed();
7333 this.invokeCall(callData);
7334 }
7335 MethodData.prototype.writeDefinition = function(method, writer) {
7336 var gen = null;
7337 var $$list = this._calls;
7338 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
7339 var cd = $$i.next();
7340 if ($eq$(cd.get$method(), method)) {
7341 gen = cd.get$_methodGenerator();
7342 }
7343 }
7344 if ($ne$(gen)) {
7345 if (method.get$isNative() && $eq$(method, this.baseMethod)) {
7346 if (!method.get$hasNativeBody()) return true;
7347 gen.set$writer(new CodeWriter());
7348 gen.get$writer().write(method.definition.nativeBody);
7349 gen.set$_paramCode(map(method.parameters, (function (p) {
7350 return p.get$name();
7351 })
7352 ));
7353 }
7354 gen.writeDefinition(writer);
7355 return true;
7356 }
7357 else {
7358 return false;
7359 }
7360 }
7361 MethodData.prototype.createFunction = function(writer) {
7362 this.run(this.baseMethod);
7363 this.writeDefinition(this.baseMethod, writer);
7364 }
7365 MethodData.prototype.createLambda = function(node, context) {
7366 var lambdaGen = new MethodGenerator(this.baseMethod, context);
7367 if (this.baseMethod.name != "") {
7368 lambdaGen.get$_scope().create$3$isFinal(this.baseMethod.name, this.baseMetho d.get$functionType(), this.baseMethod.definition.span, true);
7369 lambdaGen._pushBlock$1(this.baseMethod.definition);
7370 }
7371 this._calls.add(new MethodCallData(this, this.baseMethod));
7372 lambdaGen.run$0();
7373 if (this.baseMethod.name != "") {
7374 lambdaGen._popBlock(this.baseMethod.definition);
7375 }
7376 var writer = new CodeWriter();
7377 lambdaGen.writeDefinition(writer, node);
7378 return new Value(this.baseMethod.get$functionType(), writer.get$text(), this.b aseMethod.definition.span);
7379 }
7380 // ********** Code for Token **************
7381 function Token(kind, source, start, end) {
7382 this.kind = kind;
7383 this.source = source;
7384 this.start = start;
7385 this.end = end;
7386 }
7387 Token.prototype.get$kind = function() { return this.kind; };
7388 Token.prototype.get$start = function() { return this.start; };
7389 Token.prototype.get$text = function() {
7390 return this.source.get$text().substring(this.start, this.end);
7391 }
7392 Token.prototype.toString = function() {
7393 var kindText = TokenKind.kindToString(this.kind);
7394 var actualText = this.get$text();
7395 if ($ne$(kindText, actualText)) {
7396 if (actualText.get$length() > (10)) {
7397 actualText = $add$(actualText.substring((0), (8)), "...");
7398 }
7399 return ("" + kindText + "(" + actualText + ")");
7400 }
7401 else {
7402 return kindText;
7403 }
7404 }
7405 Token.prototype.get$span = function() {
7406 return new SourceSpan(this.source, this.start, this.end);
7407 }
7408 Token.prototype.toString$0 = Token.prototype.toString;
7409 // ********** Code for LiteralToken **************
7410 $inherits(LiteralToken, Token);
7411 function LiteralToken(kind, source, start, end, value) {
7412 this.value = value;
7413 Token.call(this, kind, source, start, end);
7414 }
7415 LiteralToken.prototype.get$value = function() { return this.value; };
7416 LiteralToken.prototype.set$value = function(value) { return this.value = value; };
7417 // ********** Code for ErrorToken **************
7418 $inherits(ErrorToken, Token);
7419 function ErrorToken(kind, source, start, end, message) {
7420 this.message = message;
7421 Token.call(this, kind, source, start, end);
7422 }
7423 ErrorToken.prototype.get$message = function() { return this.message; };
7424 // ********** Code for SourceFile **************
7425 function SourceFile(filename, _text) {
7426 this.filename = filename;
7427 this._text = _text;
7428 }
7429 SourceFile.prototype.get$filename = function() { return this.filename; };
7430 SourceFile.prototype.get$text = function() {
7431 return this._text;
7432 }
7433 SourceFile.prototype.get$lineStarts = function() {
7434 if (this._lineStarts == null) {
7435 var starts = [(0)];
7436 var index = (0);
7437 while ($lt$(index, this.get$text().length)) {
7438 index = this.get$text().indexOf("\n", index) + (1);
7439 if ($lte$(index, (0))) break;
7440 starts.add(index);
7441 }
7442 starts.add(this.get$text().length + (1));
7443 this._lineStarts = starts;
7444 }
7445 return this._lineStarts;
7446 }
7447 SourceFile.prototype.getLine = function(position) {
7448 var starts = this.get$lineStarts();
7449 for (var i = (0);
7450 i < starts.get$length(); i++) {
7451 if ($gt$(starts.$index(i), position)) return i - (1);
7452 }
7453 $globals.world.internalError("bad position");
7454 }
7455 SourceFile.prototype.getColumn = function(line, position) {
7456 return position - this.get$lineStarts().$index(line);
7457 }
7458 SourceFile.prototype.getLocationMessage = function(message, start, end, includeT ext) {
7459 var line = this.getLine(start);
7460 var column = this.getColumn(line, start);
7461 var buf = new StringBufferImpl(("" + this.filename + ":" + ($add$(line, (1))) + ":" + ($add$(column, (1))) + ": " + message));
7462 if (includeText) {
7463 buf.add("\n");
7464 var textLine;
7465 if ($lt$(($add$(line, (2))), this._lineStarts.get$length())) {
7466 textLine = this.get$text().substring(this._lineStarts.$index(line), this._ lineStarts.$index($add$(line, (1))));
7467 }
7468 else {
7469 textLine = $add$(this.get$text().substring(this._lineStarts.$index(line)), "\n");
7470 }
7471 var toColumn = Math.min($add$(column, (end - start)), textLine.get$length()) ;
7472 if ($globals.options.useColors) {
7473 buf.add(textLine.substring((0), column));
7474 buf.add($globals._RED_COLOR);
7475 buf.add(textLine.substring(column, toColumn));
7476 buf.add($globals._NO_COLOR);
7477 buf.add(textLine.substring$1(toColumn));
7478 }
7479 else {
7480 buf.add(textLine);
7481 }
7482 var i = (0);
7483 for (; $lt$(i, column); i++) {
7484 buf.add(" ");
7485 }
7486 if ($globals.options.useColors) buf.add($globals._RED_COLOR);
7487 for (; i < toColumn; i++) {
7488 buf.add("^");
7489 }
7490 if ($globals.options.useColors) buf.add($globals._NO_COLOR);
7491 }
7492 return buf.toString$0();
7493 }
7494 SourceFile.prototype.compareTo = function(other) {
7495 if (this.orderInLibrary != null && other.orderInLibrary != null) {
7496 return this.orderInLibrary - other.orderInLibrary;
7497 }
7498 else {
7499 return this.filename.compareTo(other.filename);
7500 }
7501 }
7502 // ********** Code for SourceSpan **************
7503 function SourceSpan(file, start, end) {
7504 this.file = file;
7505 this.start = start;
7506 this.end = end;
7507 }
7508 SourceSpan.prototype.get$file = function() { return this.file; };
7509 SourceSpan.prototype.get$start = function() { return this.start; };
7510 SourceSpan.prototype.get$text = function() {
7511 return this.file.get$text().substring(this.start, this.end);
7512 }
7513 SourceSpan.prototype.toMessageString = function(message) {
7514 return this.file.getLocationMessage(message, this.start, this.end, true);
7515 }
7516 SourceSpan.prototype.get$locationText = function() {
7517 var line = this.file.getLine(this.start);
7518 var column = this.file.getColumn(line, this.start);
7519 return ("" + this.file.filename + ":" + ($add$(line, (1))) + ":" + ($add$(colu mn, (1))));
7520 }
7521 SourceSpan.prototype.compareTo = function(other) {
7522 if ($eq$(this.file, other.file)) {
7523 var d = this.start - other.start;
7524 return d == (0) ? (this.end - other.end) : d;
7525 }
7526 return this.file.compareTo(other.file);
7527 }
7528 // ********** Code for InterpStack **************
7529 function InterpStack(previous, quote, isMultiline) {
7530 this.previous = previous;
7531 this.quote = quote;
7532 this.isMultiline = isMultiline;
7533 this.depth = (-1);
7534 }
7535 InterpStack.prototype.set$previous = function(value) { return this.previous = va lue; };
7536 InterpStack.prototype.get$quote = function() { return this.quote; };
7537 InterpStack.prototype.get$isMultiline = function() { return this.isMultiline; };
7538 InterpStack.prototype.get$depth = function() { return this.depth; };
7539 InterpStack.prototype.pop = function() {
7540 return this.previous;
7541 }
7542 InterpStack.push = function(stack, quote, isMultiline) {
7543 var newStack = new InterpStack(stack, quote, isMultiline);
7544 if (stack != null) newStack.set$previous(stack);
7545 return newStack;
7546 }
7547 // ********** Code for TokenizerHelpers **************
7548 function TokenizerHelpers() {
7549
7550 }
7551 TokenizerHelpers.isIdentifierStart = function(c) {
7552 return ((c >= (97) && c <= (122)) || (c >= (65) && c <= (90)) || c == (95));
7553 }
7554 TokenizerHelpers.isDigit = function(c) {
7555 return (c >= (48) && c <= (57));
7556 }
7557 TokenizerHelpers.isIdentifierPart = function(c) {
7558 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c) | | c == (36));
7559 }
7560 TokenizerHelpers.isInterpIdentifierPart = function(c) {
7561 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c));
7562 }
7563 // ********** Code for TokenizerBase **************
7564 $inherits(TokenizerBase, TokenizerHelpers);
7565 function TokenizerBase(_source, _skipWhitespace, index) {
7566 this._source = _source;
7567 this._skipWhitespace = _skipWhitespace;
7568 this._lang_index = index;
7569 TokenizerHelpers.call(this);
7570 this._text = this._source.get$text();
7571 }
7572 TokenizerBase.prototype._nextChar = function() {
7573 if (this._lang_index < this._text.length) {
7574 return this._text.charCodeAt(this._lang_index++);
7575 }
7576 else {
7577 return (0);
7578 }
7579 }
7580 TokenizerBase.prototype._peekChar = function() {
7581 if (this._lang_index < this._text.length) {
7582 return this._text.charCodeAt(this._lang_index);
7583 }
7584 else {
7585 return (0);
7586 }
7587 }
7588 TokenizerBase.prototype._maybeEatChar = function(ch) {
7589 if (this._lang_index < this._text.length) {
7590 if (this._text.charCodeAt(this._lang_index) == ch) {
7591 this._lang_index++;
7592 return true;
7593 }
7594 else {
7595 return false;
7596 }
7597 }
7598 else {
7599 return false;
7600 }
7601 }
7602 TokenizerBase.prototype._finishToken = function(kind) {
7603 return new Token(kind, this._source, this._startIndex, this._lang_index);
7604 }
7605 TokenizerBase.prototype._errorToken = function(message) {
7606 return new ErrorToken((65), this._source, this._startIndex, this._lang_index, message);
7607 }
7608 TokenizerBase.prototype.finishWhitespace = function() {
7609 this._lang_index--;
7610 while (this._lang_index < this._text.length) {
7611 var ch = this._text.charCodeAt(this._lang_index++);
7612 if ($eq$(ch, (32)) || $eq$(ch, (9)) || $eq$(ch, (13))) {
7613 }
7614 else if ($eq$(ch, (10))) {
7615 if (!this._skipWhitespace) {
7616 return this._finishToken((63));
7617 }
7618 }
7619 else {
7620 this._lang_index--;
7621 if (this._skipWhitespace) {
7622 return this.next();
7623 }
7624 else {
7625 return this._finishToken((63));
7626 }
7627 }
7628 }
7629 return this._finishToken((1));
7630 }
7631 TokenizerBase.prototype.finishHashBang = function() {
7632 while (true) {
7633 var ch = this._nextChar();
7634 if (ch == (0) || ch == (10) || ch == (13)) {
7635 return this._finishToken((13));
7636 }
7637 }
7638 }
7639 TokenizerBase.prototype.finishSingleLineComment = function() {
7640 while (true) {
7641 var ch = this._nextChar();
7642 if (ch == (0) || ch == (10) || ch == (13)) {
7643 if (this._skipWhitespace) {
7644 return this.next();
7645 }
7646 else {
7647 return this._finishToken((64));
7648 }
7649 }
7650 }
7651 }
7652 TokenizerBase.prototype.finishMultiLineComment = function() {
7653 var nesting = (1);
7654 do {
7655 var ch = this._nextChar();
7656 if (ch == (0)) {
7657 return this._errorToken();
7658 }
7659 else if (ch == (42)) {
7660 if (this._maybeEatChar((47))) {
7661 nesting--;
7662 }
7663 }
7664 else if (ch == (47)) {
7665 if (this._maybeEatChar((42))) {
7666 nesting++;
7667 }
7668 }
7669 }
7670 while (nesting > (0))
7671 if (this._skipWhitespace) {
7672 return this.next();
7673 }
7674 else {
7675 return this._finishToken((64));
7676 }
7677 }
7678 TokenizerBase.prototype.eatDigits = function() {
7679 while (this._lang_index < this._text.length) {
7680 if (TokenizerHelpers.isDigit(this._text.charCodeAt(this._lang_index))) {
7681 this._lang_index++;
7682 }
7683 else {
7684 return;
7685 }
7686 }
7687 }
7688 TokenizerBase._hexDigit = function(c) {
7689 if (c >= (48) && c <= (57)) {
7690 return c - (48);
7691 }
7692 else if (c >= (97) && c <= (102)) {
7693 return c - (87);
7694 }
7695 else if (c >= (65) && c <= (70)) {
7696 return c - (55);
7697 }
7698 else {
7699 return (-1);
7700 }
7701 }
7702 TokenizerBase.prototype.readHex = function(hexLength) {
7703 var maxIndex;
7704 if (null == hexLength) {
7705 maxIndex = this._text.length - (1);
7706 }
7707 else {
7708 maxIndex = this._lang_index + hexLength;
7709 if (maxIndex >= this._text.length) return (-1);
7710 }
7711 var result = (0);
7712 while (this._lang_index < maxIndex) {
7713 var digit = TokenizerBase._hexDigit(this._text.charCodeAt(this._lang_index)) ;
7714 if ($eq$(digit, (-1))) {
7715 if (null == hexLength) {
7716 return result;
7717 }
7718 else {
7719 return (-1);
7720 }
7721 }
7722 TokenizerBase._hexDigit(this._text.charCodeAt(this._lang_index));
7723 result = $add$(($mul$(result, (16))), digit);
7724 this._lang_index++;
7725 }
7726 return result;
7727 }
7728 TokenizerBase.prototype.finishHex = function() {
7729 var value = this.readHex();
7730 return new LiteralToken((61), this._source, this._startIndex, this._lang_index , value);
7731 }
7732 TokenizerBase.prototype.finishNumber = function() {
7733 this.eatDigits();
7734 if (this._peekChar() == (46)) {
7735 this._nextChar();
7736 if (TokenizerHelpers.isDigit(this._peekChar())) {
7737 this.eatDigits();
7738 return this.finishNumberExtra((62));
7739 }
7740 else {
7741 this._lang_index--;
7742 }
7743 }
7744 return this.finishNumberExtra((60));
7745 }
7746 TokenizerBase.prototype.finishNumberExtra = function(kind) {
7747 if (this._maybeEatChar((101)) || this._maybeEatChar((69))) {
7748 kind = (62);
7749 this._maybeEatChar((45));
7750 this._maybeEatChar((43));
7751 this.eatDigits();
7752 }
7753 if (this._peekChar() != (0) && TokenizerHelpers.isIdentifierStart(this._peekCh ar())) {
7754 this._nextChar();
7755 return this._errorToken("illegal character in number");
7756 }
7757 return this._finishToken(kind);
7758 }
7759 TokenizerBase.prototype._makeStringToken = function(buf, isPart) {
7760 var s = Strings.String$fromCharCodes$factory(buf);
7761 var kind = isPart ? (59) : (58);
7762 return new LiteralToken(kind, this._source, this._startIndex, this._lang_index , s);
7763 }
7764 TokenizerBase.prototype._makeRawStringToken = function(isMultiline) {
7765 var s;
7766 if (isMultiline) {
7767 var start = this._startIndex + (4);
7768 if (this._source.get$text()[start] == "\n") start++;
7769 s = this._source.get$text().substring(start, this._lang_index - (3));
7770 }
7771 else {
7772 s = this._source.get$text().substring(this._startIndex + (2), this._lang_ind ex - (1));
7773 }
7774 return new LiteralToken((58), this._source, this._startIndex, this._lang_index , s);
7775 }
7776 TokenizerBase.prototype.finishMultilineString = function(quote) {
7777 var buf = [];
7778 while (true) {
7779 var ch = this._nextChar();
7780 if (ch == (0)) {
7781 return this._errorToken();
7782 }
7783 else if (ch == quote) {
7784 if (this._maybeEatChar(quote)) {
7785 if (this._maybeEatChar(quote)) {
7786 return this._makeStringToken(buf, false);
7787 }
7788 buf.add(quote);
7789 }
7790 buf.add(quote);
7791 }
7792 else if (ch == (36)) {
7793 this._interpStack = InterpStack.push(this._interpStack, quote, true);
7794 return this._makeStringToken(buf, true);
7795 }
7796 else if (ch == (92)) {
7797 var escapeVal = this.readEscapeSequence();
7798 if ($eq$(escapeVal, (-1))) {
7799 return this._errorToken("invalid hex escape sequence");
7800 }
7801 else {
7802 buf.add(escapeVal);
7803 }
7804 }
7805 else {
7806 buf.add(ch);
7807 }
7808 }
7809 }
7810 TokenizerBase.prototype._finishOpenBrace = function() {
7811 var $0;
7812 if (this._interpStack != null) {
7813 if (this._interpStack.depth == (-1)) {
7814 this._interpStack.depth = (1);
7815 }
7816 else {
7817 ($0 = this._interpStack).depth = $0.depth + (1);
7818 }
7819 }
7820 return this._finishToken((6));
7821 }
7822 TokenizerBase.prototype._finishCloseBrace = function() {
7823 var $0;
7824 if (this._interpStack != null) {
7825 ($0 = this._interpStack).depth = $0.depth - (1);
7826 }
7827 return this._finishToken((7));
7828 }
7829 TokenizerBase.prototype.finishString = function(quote) {
7830 if (this._maybeEatChar(quote)) {
7831 if (this._maybeEatChar(quote)) {
7832 this._maybeEatChar((10));
7833 return this.finishMultilineString(quote);
7834 }
7835 else {
7836 return this._makeStringToken(new Array(), false);
7837 }
7838 }
7839 return this.finishStringBody(quote);
7840 }
7841 TokenizerBase.prototype.finishRawString = function(quote) {
7842 if (this._maybeEatChar(quote)) {
7843 if (this._maybeEatChar(quote)) {
7844 return this.finishMultilineRawString(quote);
7845 }
7846 else {
7847 return this._makeStringToken([], false);
7848 }
7849 }
7850 while (true) {
7851 var ch = this._nextChar();
7852 if (ch == quote) {
7853 return this._makeRawStringToken(false);
7854 }
7855 else if (ch == (0)) {
7856 return this._errorToken();
7857 }
7858 }
7859 }
7860 TokenizerBase.prototype.finishMultilineRawString = function(quote) {
7861 while (true) {
7862 var ch = this._nextChar();
7863 if (ch == (0)) {
7864 return this._errorToken();
7865 }
7866 else if (ch == quote && this._maybeEatChar(quote) && this._maybeEatChar(quot e)) {
7867 return this._makeRawStringToken(true);
7868 }
7869 }
7870 }
7871 TokenizerBase.prototype.finishStringBody = function(quote) {
7872 var buf = new Array();
7873 while (true) {
7874 var ch = this._nextChar();
7875 if (ch == quote) {
7876 return this._makeStringToken(buf, false);
7877 }
7878 else if (ch == (36)) {
7879 this._interpStack = InterpStack.push(this._interpStack, quote, false);
7880 return this._makeStringToken(buf, true);
7881 }
7882 else if (ch == (0)) {
7883 return this._errorToken();
7884 }
7885 else if (ch == (92)) {
7886 var escapeVal = this.readEscapeSequence();
7887 if ($eq$(escapeVal, (-1))) {
7888 return this._errorToken("invalid hex escape sequence");
7889 }
7890 else {
7891 buf.add(escapeVal);
7892 }
7893 }
7894 else {
7895 buf.add(ch);
7896 }
7897 }
7898 }
7899 TokenizerBase.prototype.readEscapeSequence = function() {
7900 var ch = this._nextChar();
7901 var hexValue;
7902 switch (ch) {
7903 case (110):
7904
7905 return (10);
7906
7907 case (114):
7908
7909 return (13);
7910
7911 case (102):
7912
7913 return (12);
7914
7915 case (98):
7916
7917 return (8);
7918
7919 case (116):
7920
7921 return (9);
7922
7923 case (118):
7924
7925 return (11);
7926
7927 case (120):
7928
7929 hexValue = this.readHex((2));
7930 break;
7931
7932 case (117):
7933
7934 if (this._maybeEatChar((123))) {
7935 hexValue = this.readHex();
7936 if (!this._maybeEatChar((125))) {
7937 return (-1);
7938 }
7939 else {
7940 break;
7941 }
7942 }
7943 else {
7944 hexValue = this.readHex((4));
7945 break;
7946 }
7947
7948 default:
7949
7950 return ch;
7951
7952 }
7953 if (hexValue == (-1)) return (-1);
7954 if (hexValue < (55296) || hexValue > (57343) && hexValue <= (65535)) {
7955 return hexValue;
7956 }
7957 else if (hexValue <= (1114111)) {
7958 $globals.world.fatal("unicode values greater than 2 bytes not implemented ye t");
7959 return (-1);
7960 }
7961 else {
7962 return (-1);
7963 }
7964 }
7965 TokenizerBase.prototype.finishDot = function() {
7966 if (TokenizerHelpers.isDigit(this._peekChar())) {
7967 this.eatDigits();
7968 return this.finishNumberExtra((62));
7969 }
7970 else {
7971 return this._finishToken((14));
7972 }
7973 }
7974 TokenizerBase.prototype.finishIdentifier = function(ch) {
7975 if (this._interpStack != null && this._interpStack.depth == (-1)) {
7976 this._interpStack.depth = (0);
7977 if (ch == (36)) {
7978 return this._errorToken("illegal character after $ in string interpolation ");
7979 }
7980 while (this._lang_index < this._text.length) {
7981 if (!TokenizerHelpers.isInterpIdentifierPart(this._text.charCodeAt(this._l ang_index++))) {
7982 this._lang_index--;
7983 break;
7984 }
7985 }
7986 }
7987 else {
7988 while (this._lang_index < this._text.length) {
7989 if (!TokenizerHelpers.isIdentifierPart(this._text.charCodeAt(this._lang_in dex++))) {
7990 this._lang_index--;
7991 break;
7992 }
7993 }
7994 }
7995 var kind = this.getIdentifierKind();
7996 if (kind == (70)) {
7997 return this._finishToken((70));
7998 }
7999 else {
8000 return this._finishToken(kind);
8001 }
8002 }
8003 // ********** Code for Tokenizer **************
8004 $inherits(Tokenizer, TokenizerBase);
8005 function Tokenizer(source, skipWhitespace, index) {
8006 TokenizerBase.call(this, source, skipWhitespace, index);
8007 }
8008 Tokenizer.prototype.next = function() {
8009 this._startIndex = this._lang_index;
8010 if (this._interpStack != null && this._interpStack.depth == (0)) {
8011 var istack = this._interpStack;
8012 this._interpStack = this._interpStack.pop();
8013 if (istack.get$isMultiline()) {
8014 return this.finishMultilineString(istack.get$quote());
8015 }
8016 else {
8017 return this.finishStringBody(istack.get$quote());
8018 }
8019 }
8020 var ch;
8021 ch = this._nextChar();
8022 switch (ch) {
8023 case (0):
8024
8025 return this._finishToken((1));
8026
8027 case (32):
8028 case (9):
8029 case (10):
8030 case (13):
8031
8032 return this.finishWhitespace();
8033
8034 case (33):
8035
8036 if (this._maybeEatChar((61))) {
8037 if (this._maybeEatChar((61))) {
8038 return this._finishToken((51));
8039 }
8040 else {
8041 return this._finishToken((49));
8042 }
8043 }
8044 else {
8045 return this._finishToken((19));
8046 }
8047
8048 case (34):
8049
8050 return this.finishString((34));
8051
8052 case (35):
8053
8054 if (this._maybeEatChar((33))) {
8055 return this.finishHashBang();
8056 }
8057 else {
8058 return this._finishToken((12));
8059 }
8060
8061 case (36):
8062
8063 if (this._maybeEatChar((34))) {
8064 return this.finishString((34));
8065 }
8066 else if (this._maybeEatChar((39))) {
8067 return this.finishString((39));
8068 }
8069 else {
8070 return this.finishIdentifier((36));
8071 }
8072
8073 case (37):
8074
8075 if (this._maybeEatChar((61))) {
8076 return this._finishToken((32));
8077 }
8078 else {
8079 return this._finishToken((47));
8080 }
8081
8082 case (38):
8083
8084 if (this._maybeEatChar((38))) {
8085 return this._finishToken((35));
8086 }
8087 else if (this._maybeEatChar((61))) {
8088 return this._finishToken((23));
8089 }
8090 else {
8091 return this._finishToken((38));
8092 }
8093
8094 case (39):
8095
8096 return this.finishString((39));
8097
8098 case (40):
8099
8100 return this._finishToken((2));
8101
8102 case (41):
8103
8104 return this._finishToken((3));
8105
8106 case (42):
8107
8108 if (this._maybeEatChar((61))) {
8109 return this._finishToken((29));
8110 }
8111 else {
8112 return this._finishToken((44));
8113 }
8114
8115 case (43):
8116
8117 if (this._maybeEatChar((43))) {
8118 return this._finishToken((16));
8119 }
8120 else if (this._maybeEatChar((61))) {
8121 return this._finishToken((27));
8122 }
8123 else {
8124 return this._finishToken((42));
8125 }
8126
8127 case (44):
8128
8129 return this._finishToken((11));
8130
8131 case (45):
8132
8133 if (this._maybeEatChar((45))) {
8134 return this._finishToken((17));
8135 }
8136 else if (this._maybeEatChar((61))) {
8137 return this._finishToken((28));
8138 }
8139 else {
8140 return this._finishToken((43));
8141 }
8142
8143 case (46):
8144
8145 if (this._maybeEatChar((46))) {
8146 if (this._maybeEatChar((46))) {
8147 return this._finishToken((15));
8148 }
8149 else {
8150 return this._errorToken();
8151 }
8152 }
8153 else {
8154 return this.finishDot();
8155 }
8156
8157 case (47):
8158
8159 if (this._maybeEatChar((42))) {
8160 return this.finishMultiLineComment();
8161 }
8162 else if (this._maybeEatChar((47))) {
8163 return this.finishSingleLineComment();
8164 }
8165 else if (this._maybeEatChar((61))) {
8166 return this._finishToken((30));
8167 }
8168 else {
8169 return this._finishToken((45));
8170 }
8171
8172 case (48):
8173
8174 if (this._maybeEatChar((88))) {
8175 return this.finishHex();
8176 }
8177 else if (this._maybeEatChar((120))) {
8178 return this.finishHex();
8179 }
8180 else {
8181 return this.finishNumber();
8182 }
8183
8184 case (58):
8185
8186 return this._finishToken((8));
8187
8188 case (59):
8189
8190 return this._finishToken((10));
8191
8192 case (60):
8193
8194 if (this._maybeEatChar((60))) {
8195 if (this._maybeEatChar((61))) {
8196 return this._finishToken((24));
8197 }
8198 else {
8199 return this._finishToken((39));
8200 }
8201 }
8202 else if (this._maybeEatChar((61))) {
8203 return this._finishToken((54));
8204 }
8205 else {
8206 return this._finishToken((52));
8207 }
8208
8209 case (61):
8210
8211 if (this._maybeEatChar((61))) {
8212 if (this._maybeEatChar((61))) {
8213 return this._finishToken((50));
8214 }
8215 else {
8216 return this._finishToken((48));
8217 }
8218 }
8219 else if (this._maybeEatChar((62))) {
8220 return this._finishToken((9));
8221 }
8222 else {
8223 return this._finishToken((20));
8224 }
8225
8226 case (62):
8227
8228 if (this._maybeEatChar((61))) {
8229 return this._finishToken((55));
8230 }
8231 else if (this._maybeEatChar((62))) {
8232 if (this._maybeEatChar((61))) {
8233 return this._finishToken((25));
8234 }
8235 else if (this._maybeEatChar((62))) {
8236 if (this._maybeEatChar((61))) {
8237 return this._finishToken((26));
8238 }
8239 else {
8240 return this._finishToken((41));
8241 }
8242 }
8243 else {
8244 return this._finishToken((40));
8245 }
8246 }
8247 else {
8248 return this._finishToken((53));
8249 }
8250
8251 case (63):
8252
8253 return this._finishToken((33));
8254
8255 case (64):
8256
8257 if (this._maybeEatChar((34))) {
8258 return this.finishRawString((34));
8259 }
8260 else if (this._maybeEatChar((39))) {
8261 return this.finishRawString((39));
8262 }
8263 else {
8264 return this._errorToken();
8265 }
8266
8267 case (91):
8268
8269 if (this._maybeEatChar((93))) {
8270 if (this._maybeEatChar((61))) {
8271 return this._finishToken((57));
8272 }
8273 else {
8274 return this._finishToken((56));
8275 }
8276 }
8277 else {
8278 return this._finishToken((4));
8279 }
8280
8281 case (93):
8282
8283 return this._finishToken((5));
8284
8285 case (94):
8286
8287 if (this._maybeEatChar((61))) {
8288 return this._finishToken((22));
8289 }
8290 else {
8291 return this._finishToken((37));
8292 }
8293
8294 case (123):
8295
8296 return this._finishOpenBrace();
8297
8298 case (124):
8299
8300 if (this._maybeEatChar((61))) {
8301 return this._finishToken((21));
8302 }
8303 else if (this._maybeEatChar((124))) {
8304 return this._finishToken((34));
8305 }
8306 else {
8307 return this._finishToken((36));
8308 }
8309
8310 case (125):
8311
8312 return this._finishCloseBrace();
8313
8314 case (126):
8315
8316 if (this._maybeEatChar((47))) {
8317 if (this._maybeEatChar((61))) {
8318 return this._finishToken((31));
8319 }
8320 else {
8321 return this._finishToken((46));
8322 }
8323 }
8324 else {
8325 return this._finishToken((18));
8326 }
8327
8328 default:
8329
8330 if (TokenizerHelpers.isIdentifierStart(ch)) {
8331 return this.finishIdentifier(ch);
8332 }
8333 else if (TokenizerHelpers.isDigit(ch)) {
8334 return this.finishNumber();
8335 }
8336 else {
8337 return this._errorToken();
8338 }
8339
8340 }
8341 }
8342 Tokenizer.prototype.getIdentifierKind = function() {
8343 var i0 = this._startIndex;
8344 var ch;
8345 switch ($sub$(this._lang_index, i0)) {
8346 case (2):
8347
8348 ch = this._text.charCodeAt(i0);
8349 if (ch == (100)) {
8350 if (this._text.charCodeAt($add$(i0, (1))) == (111)) return (95);
8351 }
8352 else if (ch == (105)) {
8353 ch = this._text.charCodeAt($add$(i0, (1)));
8354 if (ch == (102)) {
8355 return (102);
8356 }
8357 else if (ch == (110)) {
8358 return (103);
8359 }
8360 else if (ch == (115)) {
8361 return (104);
8362 }
8363 }
8364 return (70);
8365
8366 case (3):
8367
8368 ch = this._text.charCodeAt(i0);
8369 if (ch == (102)) {
8370 if (this._text.charCodeAt($add$(i0, (1))) == (111) && this._text.charCod eAt($add$(i0, (2))) == (114)) return (101);
8371 }
8372 else if (ch == (103)) {
8373 if (this._text.charCodeAt($add$(i0, (1))) == (101) && this._text.charCod eAt($add$(i0, (2))) == (116)) return (75);
8374 }
8375 else if (ch == (110)) {
8376 if (this._text.charCodeAt($add$(i0, (1))) == (101) && this._text.charCod eAt($add$(i0, (2))) == (119)) return (105);
8377 }
8378 else if (ch == (115)) {
8379 if (this._text.charCodeAt($add$(i0, (1))) == (101) && this._text.charCod eAt($add$(i0, (2))) == (116)) return (83);
8380 }
8381 else if (ch == (116)) {
8382 if (this._text.charCodeAt($add$(i0, (1))) == (114) && this._text.charCod eAt($add$(i0, (2))) == (121)) return (113);
8383 }
8384 else if (ch == (118)) {
8385 if (this._text.charCodeAt($add$(i0, (1))) == (97) && this._text.charCode At($add$(i0, (2))) == (114)) return (114);
8386 }
8387 return (70);
8388
8389 case (4):
8390
8391 ch = this._text.charCodeAt(i0);
8392 if (ch == (99)) {
8393 ch = this._text.charCodeAt($add$(i0, (1)));
8394 if (ch == (97)) {
8395 ch = this._text.charCodeAt($add$(i0, (2)));
8396 if (ch == (108)) {
8397 if (this._text.charCodeAt($add$(i0, (3))) == (108)) return (73);
8398 }
8399 else if (ch == (115)) {
8400 if (this._text.charCodeAt($add$(i0, (3))) == (101)) return (89);
8401 }
8402 }
8403 }
8404 else if (ch == (101)) {
8405 if (this._text.charCodeAt($add$(i0, (1))) == (108) && this._text.charCod eAt($add$(i0, (2))) == (115) && this._text.charCodeAt($add$(i0, (3))) == (101)) return (96);
8406 }
8407 else if (ch == (110)) {
8408 if (this._text.charCodeAt($add$(i0, (1))) == (117) && this._text.charCod eAt($add$(i0, (2))) == (108) && this._text.charCodeAt($add$(i0, (3))) == (108)) return (106);
8409 }
8410 else if (ch == (116)) {
8411 ch = this._text.charCodeAt($add$(i0, (1)));
8412 if (ch == (104)) {
8413 if (this._text.charCodeAt($add$(i0, (2))) == (105) && this._text.charC odeAt($add$(i0, (3))) == (115)) return (110);
8414 }
8415 else if (ch == (114)) {
8416 if (this._text.charCodeAt($add$(i0, (2))) == (117) && this._text.charC odeAt($add$(i0, (3))) == (101)) return (112);
8417 }
8418 }
8419 else if (ch == (118)) {
8420 if (this._text.charCodeAt($add$(i0, (1))) == (111) && this._text.charCod eAt($add$(i0, (2))) == (105) && this._text.charCodeAt($add$(i0, (3))) == (100)) return (115);
8421 }
8422 return (70);
8423
8424 case (5):
8425
8426 ch = this._text.charCodeAt(i0);
8427 if (ch == (97)) {
8428 if (this._text.charCodeAt($add$(i0, (1))) == (119) && this._text.charCod eAt($add$(i0, (2))) == (97) && this._text.charCodeAt($add$(i0, (3))) == (105) && this._text.charCodeAt($add$(i0, (4))) == (116)) return (87);
8429 }
8430 else if (ch == (98)) {
8431 if (this._text.charCodeAt($add$(i0, (1))) == (114) && this._text.charCod eAt($add$(i0, (2))) == (101) && this._text.charCodeAt($add$(i0, (3))) == (97) && this._text.charCodeAt($add$(i0, (4))) == (107)) return (88);
8432 }
8433 else if (ch == (99)) {
8434 ch = this._text.charCodeAt($add$(i0, (1)));
8435 if (ch == (97)) {
8436 if (this._text.charCodeAt($add$(i0, (2))) == (116) && this._text.charC odeAt($add$(i0, (3))) == (99) && this._text.charCodeAt($add$(i0, (4))) == (104)) return (90);
8437 }
8438 else if (ch == (108)) {
8439 if (this._text.charCodeAt($add$(i0, (2))) == (97) && this._text.charCo deAt($add$(i0, (3))) == (115) && this._text.charCodeAt($add$(i0, (4))) == (115)) return (91);
8440 }
8441 else if (ch == (111)) {
8442 if (this._text.charCodeAt($add$(i0, (2))) == (110) && this._text.charC odeAt($add$(i0, (3))) == (115) && this._text.charCodeAt($add$(i0, (4))) == (116) ) return (92);
8443 }
8444 }
8445 else if (ch == (102)) {
8446 ch = this._text.charCodeAt($add$(i0, (1)));
8447 if (ch == (97)) {
8448 if (this._text.charCodeAt($add$(i0, (2))) == (108) && this._text.charC odeAt($add$(i0, (3))) == (115) && this._text.charCodeAt($add$(i0, (4))) == (101) ) return (98);
8449 }
8450 else if (ch == (105)) {
8451 if (this._text.charCodeAt($add$(i0, (2))) == (110) && this._text.charC odeAt($add$(i0, (3))) == (97) && this._text.charCodeAt($add$(i0, (4))) == (108)) return (99);
8452 }
8453 }
8454 else if (ch == (115)) {
8455 if (this._text.charCodeAt($add$(i0, (1))) == (117) && this._text.charCod eAt($add$(i0, (2))) == (112) && this._text.charCodeAt($add$(i0, (3))) == (101) & & this._text.charCodeAt($add$(i0, (4))) == (114)) return (108);
8456 }
8457 else if (ch == (116)) {
8458 if (this._text.charCodeAt($add$(i0, (1))) == (104) && this._text.charCod eAt($add$(i0, (2))) == (114) && this._text.charCodeAt($add$(i0, (3))) == (111) & & this._text.charCodeAt($add$(i0, (4))) == (119)) return (111);
8459 }
8460 else if (ch == (119)) {
8461 if (this._text.charCodeAt($add$(i0, (1))) == (104) && this._text.charCod eAt($add$(i0, (2))) == (105) && this._text.charCodeAt($add$(i0, (3))) == (108) & & this._text.charCodeAt($add$(i0, (4))) == (101)) return (116);
8462 }
8463 return (70);
8464
8465 case (6):
8466
8467 ch = this._text.charCodeAt(i0);
8468 if (ch == (97)) {
8469 if (this._text.charCodeAt($add$(i0, (1))) == (115) && this._text.charCod eAt($add$(i0, (2))) == (115) && this._text.charCodeAt($add$(i0, (3))) == (101) & & this._text.charCodeAt($add$(i0, (4))) == (114) && this._text.charCodeAt($add$( i0, (5))) == (116)) return (72);
8470 }
8471 else if (ch == (105)) {
8472 if (this._text.charCodeAt($add$(i0, (1))) == (109) && this._text.charCod eAt($add$(i0, (2))) == (112) && this._text.charCodeAt($add$(i0, (3))) == (111) & & this._text.charCodeAt($add$(i0, (4))) == (114) && this._text.charCodeAt($add$( i0, (5))) == (116)) return (77);
8473 }
8474 else if (ch == (110)) {
8475 ch = this._text.charCodeAt($add$(i0, (1)));
8476 if (ch == (97)) {
8477 if (this._text.charCodeAt($add$(i0, (2))) == (116) && this._text.charC odeAt($add$(i0, (3))) == (105) && this._text.charCodeAt($add$(i0, (4))) == (118) && this._text.charCodeAt($add$(i0, (5))) == (101)) return (80);
8478 }
8479 else if (ch == (101)) {
8480 if (this._text.charCodeAt($add$(i0, (2))) == (103) && this._text.charC odeAt($add$(i0, (3))) == (97) && this._text.charCodeAt($add$(i0, (4))) == (116) && this._text.charCodeAt($add$(i0, (5))) == (101)) return (81);
8481 }
8482 }
8483 else if (ch == (114)) {
8484 if (this._text.charCodeAt($add$(i0, (1))) == (101) && this._text.charCod eAt($add$(i0, (2))) == (116) && this._text.charCodeAt($add$(i0, (3))) == (117) & & this._text.charCodeAt($add$(i0, (4))) == (114) && this._text.charCodeAt($add$( i0, (5))) == (110)) return (107);
8485 }
8486 else if (ch == (115)) {
8487 ch = this._text.charCodeAt($add$(i0, (1)));
8488 if (ch == (111)) {
8489 if (this._text.charCodeAt($add$(i0, (2))) == (117) && this._text.charC odeAt($add$(i0, (3))) == (114) && this._text.charCodeAt($add$(i0, (4))) == (99) && this._text.charCodeAt($add$(i0, (5))) == (101)) return (84);
8490 }
8491 else if (ch == (116)) {
8492 if (this._text.charCodeAt($add$(i0, (2))) == (97) && this._text.charCo deAt($add$(i0, (3))) == (116) && this._text.charCodeAt($add$(i0, (4))) == (105) && this._text.charCodeAt($add$(i0, (5))) == (99)) return (85);
8493 }
8494 else if (ch == (119)) {
8495 if (this._text.charCodeAt($add$(i0, (2))) == (105) && this._text.charC odeAt($add$(i0, (3))) == (116) && this._text.charCodeAt($add$(i0, (4))) == (99) && this._text.charCodeAt($add$(i0, (5))) == (104)) return (109);
8496 }
8497 }
8498 return (70);
8499
8500 case (7):
8501
8502 ch = this._text.charCodeAt(i0);
8503 if (ch == (100)) {
8504 if (this._text.charCodeAt($add$(i0, (1))) == (101) && this._text.charCod eAt($add$(i0, (2))) == (102) && this._text.charCodeAt($add$(i0, (3))) == (97) && this._text.charCodeAt($add$(i0, (4))) == (117) && this._text.charCodeAt($add$(i 0, (5))) == (108) && this._text.charCodeAt($add$(i0, (6))) == (116)) return (94) ;
8505 }
8506 else if (ch == (101)) {
8507 if (this._text.charCodeAt($add$(i0, (1))) == (120) && this._text.charCod eAt($add$(i0, (2))) == (116) && this._text.charCodeAt($add$(i0, (3))) == (101) & & this._text.charCodeAt($add$(i0, (4))) == (110) && this._text.charCodeAt($add$( i0, (5))) == (100) && this._text.charCodeAt($add$(i0, (6))) == (115)) return (97 );
8508 }
8509 else if (ch == (102)) {
8510 ch = this._text.charCodeAt($add$(i0, (1)));
8511 if (ch == (97)) {
8512 if (this._text.charCodeAt($add$(i0, (2))) == (99) && this._text.charCo deAt($add$(i0, (3))) == (116) && this._text.charCodeAt($add$(i0, (4))) == (111) && this._text.charCodeAt($add$(i0, (5))) == (114) && this._text.charCodeAt($add$ (i0, (6))) == (121)) return (74);
8513 }
8514 else if (ch == (105)) {
8515 if (this._text.charCodeAt($add$(i0, (2))) == (110) && this._text.charC odeAt($add$(i0, (3))) == (97) && this._text.charCodeAt($add$(i0, (4))) == (108) && this._text.charCodeAt($add$(i0, (5))) == (108) && this._text.charCodeAt($add$ (i0, (6))) == (121)) return (100);
8516 }
8517 }
8518 else if (ch == (108)) {
8519 if (this._text.charCodeAt($add$(i0, (1))) == (105) && this._text.charCod eAt($add$(i0, (2))) == (98) && this._text.charCodeAt($add$(i0, (3))) == (114) && this._text.charCodeAt($add$(i0, (4))) == (97) && this._text.charCodeAt($add$(i0 , (5))) == (114) && this._text.charCodeAt($add$(i0, (6))) == (121)) return (79);
8520 }
8521 else if (ch == (116)) {
8522 if (this._text.charCodeAt($add$(i0, (1))) == (121) && this._text.charCod eAt($add$(i0, (2))) == (112) && this._text.charCodeAt($add$(i0, (3))) == (101) & & this._text.charCodeAt($add$(i0, (4))) == (100) && this._text.charCodeAt($add$( i0, (5))) == (101) && this._text.charCodeAt($add$(i0, (6))) == (102)) return (86 );
8523 }
8524 return (70);
8525
8526 case (8):
8527
8528 ch = this._text.charCodeAt(i0);
8529 if (ch == (97)) {
8530 if (this._text.charCodeAt($add$(i0, (1))) == (98) && this._text.charCode At($add$(i0, (2))) == (115) && this._text.charCodeAt($add$(i0, (3))) == (116) && this._text.charCodeAt($add$(i0, (4))) == (114) && this._text.charCodeAt($add$(i 0, (5))) == (97) && this._text.charCodeAt($add$(i0, (6))) == (99) && this._text. charCodeAt($add$(i0, (7))) == (116)) return (71);
8531 }
8532 else if (ch == (99)) {
8533 if (this._text.charCodeAt($add$(i0, (1))) == (111) && this._text.charCod eAt($add$(i0, (2))) == (110) && this._text.charCodeAt($add$(i0, (3))) == (116) & & this._text.charCodeAt($add$(i0, (4))) == (105) && this._text.charCodeAt($add$( i0, (5))) == (110) && this._text.charCodeAt($add$(i0, (6))) == (117) && this._te xt.charCodeAt($add$(i0, (7))) == (101)) return (93);
8534 }
8535 else if (ch == (111)) {
8536 if (this._text.charCodeAt($add$(i0, (1))) == (112) && this._text.charCod eAt($add$(i0, (2))) == (101) && this._text.charCodeAt($add$(i0, (3))) == (114) & & this._text.charCodeAt($add$(i0, (4))) == (97) && this._text.charCodeAt($add$(i 0, (5))) == (116) && this._text.charCodeAt($add$(i0, (6))) == (111) && this._tex t.charCodeAt($add$(i0, (7))) == (114)) return (82);
8537 }
8538 return (70);
8539
8540 case (9):
8541
8542 if (this._text.charCodeAt(i0) == (105) && this._text.charCodeAt($add$(i0, (1))) == (110) && this._text.charCodeAt($add$(i0, (2))) == (116) && this._text.c harCodeAt($add$(i0, (3))) == (101) && this._text.charCodeAt($add$(i0, (4))) == ( 114) && this._text.charCodeAt($add$(i0, (5))) == (102) && this._text.charCodeAt( $add$(i0, (6))) == (97) && this._text.charCodeAt($add$(i0, (7))) == (99) && this ._text.charCodeAt($add$(i0, (8))) == (101)) return (78);
8543 return (70);
8544
8545 case (10):
8546
8547 if (this._text.charCodeAt(i0) == (105) && this._text.charCodeAt($add$(i0, (1))) == (109) && this._text.charCodeAt($add$(i0, (2))) == (112) && this._text.c harCodeAt($add$(i0, (3))) == (108) && this._text.charCodeAt($add$(i0, (4))) == ( 101) && this._text.charCodeAt($add$(i0, (5))) == (109) && this._text.charCodeAt( $add$(i0, (6))) == (101) && this._text.charCodeAt($add$(i0, (7))) == (110) && th is._text.charCodeAt($add$(i0, (8))) == (116) && this._text.charCodeAt($add$(i0, (9))) == (115)) return (76);
8548 return (70);
8549
8550 default:
8551
8552 return (70);
8553
8554 }
8555 }
8556 // ********** Code for TokenKind **************
8557 function TokenKind() {}
8558 TokenKind.kindToString = function(kind) {
8559 switch (kind) {
8560 case (1):
8561
8562 return "end of file";
8563
8564 case (2):
8565
8566 return "(";
8567
8568 case (3):
8569
8570 return ")";
8571
8572 case (4):
8573
8574 return "[";
8575
8576 case (5):
8577
8578 return "]";
8579
8580 case (6):
8581
8582 return "{";
8583
8584 case (7):
8585
8586 return "}";
8587
8588 case (8):
8589
8590 return ":";
8591
8592 case (9):
8593
8594 return "=>";
8595
8596 case (10):
8597
8598 return ";";
8599
8600 case (11):
8601
8602 return ",";
8603
8604 case (12):
8605
8606 return "#";
8607
8608 case (13):
8609
8610 return "#!";
8611
8612 case (14):
8613
8614 return ".";
8615
8616 case (15):
8617
8618 return "...";
8619
8620 case (16):
8621
8622 return "++";
8623
8624 case (17):
8625
8626 return "--";
8627
8628 case (18):
8629
8630 return "~";
8631
8632 case (19):
8633
8634 return "!";
8635
8636 case (20):
8637
8638 return "=";
8639
8640 case (21):
8641
8642 return "|=";
8643
8644 case (22):
8645
8646 return "^=";
8647
8648 case (23):
8649
8650 return "&=";
8651
8652 case (24):
8653
8654 return "<<=";
8655
8656 case (25):
8657
8658 return ">>=";
8659
8660 case (26):
8661
8662 return ">>>=";
8663
8664 case (27):
8665
8666 return "+=";
8667
8668 case (28):
8669
8670 return "-=";
8671
8672 case (29):
8673
8674 return "*=";
8675
8676 case (30):
8677
8678 return "/=";
8679
8680 case (31):
8681
8682 return "~/=";
8683
8684 case (32):
8685
8686 return "%=";
8687
8688 case (33):
8689
8690 return "?";
8691
8692 case (34):
8693
8694 return "||";
8695
8696 case (35):
8697
8698 return "&&";
8699
8700 case (36):
8701
8702 return "|";
8703
8704 case (37):
8705
8706 return "^";
8707
8708 case (38):
8709
8710 return "&";
8711
8712 case (39):
8713
8714 return "<<";
8715
8716 case (40):
8717
8718 return ">>";
8719
8720 case (41):
8721
8722 return ">>>";
8723
8724 case (42):
8725
8726 return "+";
8727
8728 case (43):
8729
8730 return "-";
8731
8732 case (44):
8733
8734 return "*";
8735
8736 case (45):
8737
8738 return "/";
8739
8740 case (46):
8741
8742 return "~/";
8743
8744 case (47):
8745
8746 return "%";
8747
8748 case (48):
8749
8750 return "==";
8751
8752 case (49):
8753
8754 return "!=";
8755
8756 case (50):
8757
8758 return "===";
8759
8760 case (51):
8761
8762 return "!==";
8763
8764 case (52):
8765
8766 return "<";
8767
8768 case (53):
8769
8770 return ">";
8771
8772 case (54):
8773
8774 return "<=";
8775
8776 case (55):
8777
8778 return ">=";
8779
8780 case (56):
8781
8782 return "[]";
8783
8784 case (57):
8785
8786 return "[]=";
8787
8788 case (58):
8789
8790 return "string";
8791
8792 case (59):
8793
8794 return "string part";
8795
8796 case (60):
8797
8798 return "integer";
8799
8800 case (61):
8801
8802 return "hex integer";
8803
8804 case (62):
8805
8806 return "double";
8807
8808 case (63):
8809
8810 return "whitespace";
8811
8812 case (64):
8813
8814 return "comment";
8815
8816 case (65):
8817
8818 return "error";
8819
8820 case (66):
8821
8822 return "incomplete string";
8823
8824 case (67):
8825
8826 return "incomplete comment";
8827
8828 case (68):
8829
8830 return "incomplete multiline string dq";
8831
8832 case (69):
8833
8834 return "incomplete multiline string sq";
8835
8836 case (70):
8837
8838 return "identifier";
8839
8840 case (71):
8841
8842 return "pseudo-keyword 'abstract'";
8843
8844 case (72):
8845
8846 return "pseudo-keyword 'assert'";
8847
8848 case (73):
8849
8850 return "pseudo-keyword 'call'";
8851
8852 case (74):
8853
8854 return "pseudo-keyword 'factory'";
8855
8856 case (75):
8857
8858 return "pseudo-keyword 'get'";
8859
8860 case (76):
8861
8862 return "pseudo-keyword 'implements'";
8863
8864 case (77):
8865
8866 return "pseudo-keyword 'import'";
8867
8868 case (78):
8869
8870 return "pseudo-keyword 'interface'";
8871
8872 case (79):
8873
8874 return "pseudo-keyword 'library'";
8875
8876 case (80):
8877
8878 return "pseudo-keyword 'native'";
8879
8880 case (81):
8881
8882 return "pseudo-keyword 'negate'";
8883
8884 case (82):
8885
8886 return "pseudo-keyword 'operator'";
8887
8888 case (83):
8889
8890 return "pseudo-keyword 'set'";
8891
8892 case (84):
8893
8894 return "pseudo-keyword 'source'";
8895
8896 case (85):
8897
8898 return "pseudo-keyword 'static'";
8899
8900 case (86):
8901
8902 return "pseudo-keyword 'typedef'";
8903
8904 case (87):
8905
8906 return "keyword 'await'";
8907
8908 case (88):
8909
8910 return "keyword 'break'";
8911
8912 case (89):
8913
8914 return "keyword 'case'";
8915
8916 case (90):
8917
8918 return "keyword 'catch'";
8919
8920 case (91):
8921
8922 return "keyword 'class'";
8923
8924 case (92):
8925
8926 return "keyword 'const'";
8927
8928 case (93):
8929
8930 return "keyword 'continue'";
8931
8932 case (94):
8933
8934 return "keyword 'default'";
8935
8936 case (95):
8937
8938 return "keyword 'do'";
8939
8940 case (96):
8941
8942 return "keyword 'else'";
8943
8944 case (97):
8945
8946 return "keyword 'extends'";
8947
8948 case (98):
8949
8950 return "keyword 'false'";
8951
8952 case (99):
8953
8954 return "keyword 'final'";
8955
8956 case (100):
8957
8958 return "keyword 'finally'";
8959
8960 case (101):
8961
8962 return "keyword 'for'";
8963
8964 case (102):
8965
8966 return "keyword 'if'";
8967
8968 case (103):
8969
8970 return "keyword 'in'";
8971
8972 case (104):
8973
8974 return "keyword 'is'";
8975
8976 case (105):
8977
8978 return "keyword 'new'";
8979
8980 case (106):
8981
8982 return "keyword 'null'";
8983
8984 case (107):
8985
8986 return "keyword 'return'";
8987
8988 case (108):
8989
8990 return "keyword 'super'";
8991
8992 case (109):
8993
8994 return "keyword 'switch'";
8995
8996 case (110):
8997
8998 return "keyword 'this'";
8999
9000 case (111):
9001
9002 return "keyword 'throw'";
9003
9004 case (112):
9005
9006 return "keyword 'true'";
9007
9008 case (113):
9009
9010 return "keyword 'try'";
9011
9012 case (114):
9013
9014 return "keyword 'var'";
9015
9016 case (115):
9017
9018 return "keyword 'void'";
9019
9020 case (116):
9021
9022 return "keyword 'while'";
9023
9024 default:
9025
9026 return $add$($add$("TokenKind(", kind.toString$0()), ")");
9027
9028 }
9029 }
9030 TokenKind.isIdentifier = function(kind) {
9031 return kind >= (70) && kind < (87);
9032 }
9033 TokenKind.infixPrecedence = function(kind) {
9034 switch (kind) {
9035 case (20):
9036
9037 return (2);
9038
9039 case (21):
9040
9041 return (2);
9042
9043 case (22):
9044
9045 return (2);
9046
9047 case (23):
9048
9049 return (2);
9050
9051 case (24):
9052
9053 return (2);
9054
9055 case (25):
9056
9057 return (2);
9058
9059 case (26):
9060
9061 return (2);
9062
9063 case (27):
9064
9065 return (2);
9066
9067 case (28):
9068
9069 return (2);
9070
9071 case (29):
9072
9073 return (2);
9074
9075 case (30):
9076
9077 return (2);
9078
9079 case (31):
9080
9081 return (2);
9082
9083 case (32):
9084
9085 return (2);
9086
9087 case (33):
9088
9089 return (3);
9090
9091 case (34):
9092
9093 return (4);
9094
9095 case (35):
9096
9097 return (5);
9098
9099 case (36):
9100
9101 return (6);
9102
9103 case (37):
9104
9105 return (7);
9106
9107 case (38):
9108
9109 return (8);
9110
9111 case (39):
9112
9113 return (11);
9114
9115 case (40):
9116
9117 return (11);
9118
9119 case (41):
9120
9121 return (11);
9122
9123 case (42):
9124
9125 return (12);
9126
9127 case (43):
9128
9129 return (12);
9130
9131 case (44):
9132
9133 return (13);
9134
9135 case (45):
9136
9137 return (13);
9138
9139 case (46):
9140
9141 return (13);
9142
9143 case (47):
9144
9145 return (13);
9146
9147 case (48):
9148
9149 return (9);
9150
9151 case (49):
9152
9153 return (9);
9154
9155 case (50):
9156
9157 return (9);
9158
9159 case (51):
9160
9161 return (9);
9162
9163 case (52):
9164
9165 return (10);
9166
9167 case (53):
9168
9169 return (10);
9170
9171 case (54):
9172
9173 return (10);
9174
9175 case (55):
9176
9177 return (10);
9178
9179 case (104):
9180
9181 return (10);
9182
9183 default:
9184
9185 return (-1);
9186
9187 }
9188 }
9189 TokenKind.rawOperatorFromMethod = function(name) {
9190 switch (name) {
9191 case ":bit_not":
9192
9193 return "~";
9194
9195 case ":bit_or":
9196
9197 return "|";
9198
9199 case ":bit_xor":
9200
9201 return "^";
9202
9203 case ":bit_and":
9204
9205 return "&";
9206
9207 case ":shl":
9208
9209 return "<<";
9210
9211 case ":sar":
9212
9213 return ">>";
9214
9215 case ":shr":
9216
9217 return ">>>";
9218
9219 case ":add":
9220
9221 return "+";
9222
9223 case ":sub":
9224
9225 return "-";
9226
9227 case ":mul":
9228
9229 return "*";
9230
9231 case ":div":
9232
9233 return "/";
9234
9235 case ":truncdiv":
9236
9237 return "~/";
9238
9239 case ":mod":
9240
9241 return "%";
9242
9243 case ":eq":
9244
9245 return "==";
9246
9247 case ":lt":
9248
9249 return "<";
9250
9251 case ":gt":
9252
9253 return ">";
9254
9255 case ":lte":
9256
9257 return "<=";
9258
9259 case ":gte":
9260
9261 return ">=";
9262
9263 case ":index":
9264
9265 return "[]";
9266
9267 case ":setindex":
9268
9269 return "[]=";
9270
9271 case ":ne":
9272
9273 return "!=";
9274
9275 }
9276 }
9277 TokenKind.binaryMethodName = function(kind) {
9278 switch (kind) {
9279 case (18):
9280
9281 return ":bit_not";
9282
9283 case (36):
9284
9285 return ":bit_or";
9286
9287 case (37):
9288
9289 return ":bit_xor";
9290
9291 case (38):
9292
9293 return ":bit_and";
9294
9295 case (39):
9296
9297 return ":shl";
9298
9299 case (40):
9300
9301 return ":sar";
9302
9303 case (41):
9304
9305 return ":shr";
9306
9307 case (42):
9308
9309 return ":add";
9310
9311 case (43):
9312
9313 return ":sub";
9314
9315 case (44):
9316
9317 return ":mul";
9318
9319 case (45):
9320
9321 return ":div";
9322
9323 case (46):
9324
9325 return ":truncdiv";
9326
9327 case (47):
9328
9329 return ":mod";
9330
9331 case (48):
9332
9333 return ":eq";
9334
9335 case (52):
9336
9337 return ":lt";
9338
9339 case (53):
9340
9341 return ":gt";
9342
9343 case (54):
9344
9345 return ":lte";
9346
9347 case (55):
9348
9349 return ":gte";
9350
9351 case (56):
9352
9353 return ":index";
9354
9355 case (57):
9356
9357 return ":setindex";
9358
9359 }
9360 }
9361 TokenKind.kindFromAssign = function(kind) {
9362 if (kind == (20)) return (0);
9363 if (kind > (20) && kind <= (32)) {
9364 return kind + (15);
9365 }
9366 return (-1);
9367 }
9368 // ********** Code for Parser **************
9369 function Parser(source, diet, throwOnIncomplete, optionalSemicolons, startOffset ) {
9370 this._inhibitLambda = false;
9371 this._afterParensIndex = (0);
9372 this._recover = false;
9373 this.source = source;
9374 this.diet = diet;
9375 this.throwOnIncomplete = throwOnIncomplete;
9376 this.optionalSemicolons = optionalSemicolons;
9377 this.tokenizer = new Tokenizer(this.source, true, startOffset);
9378 this._peekToken = this.tokenizer.next();
9379 this._afterParens = [];
9380 }
9381 Parser.prototype.get$enableAwait = function() {
9382 return $globals.experimentalAwaitPhase != null;
9383 }
9384 Parser.prototype.isPrematureEndOfFile = function() {
9385 if (this.throwOnIncomplete && this._maybeEat((1))) {
9386 $throw(new IncompleteSourceException(this._previousToken));
9387 }
9388 else if (this._maybeEat((1))) {
9389 this._error("unexpected end of file", this._peekToken.get$span());
9390 return true;
9391 }
9392 else {
9393 return false;
9394 }
9395 }
9396 Parser.prototype._recoverTo = function(kind1, kind2, kind3) {
9397 while (!this.isPrematureEndOfFile()) {
9398 var kind = this._peek();
9399 if (kind == kind1 || kind == kind2 || kind == kind3) {
9400 this._recover = false;
9401 return true;
9402 }
9403 this._lang_next();
9404 }
9405 return false;
9406 }
9407 Parser.prototype._peek = function() {
9408 return this._peekToken.kind;
9409 }
9410 Parser.prototype._lang_next = function() {
9411 this._previousToken = this._peekToken;
9412 this._peekToken = this.tokenizer.next();
9413 return this._previousToken;
9414 }
9415 Parser.prototype._peekKind = function(kind) {
9416 return this._peekToken.kind == kind;
9417 }
9418 Parser.prototype._peekIdentifier = function() {
9419 return this._isIdentifier(this._peekToken.kind);
9420 }
9421 Parser.prototype._isIdentifier = function(kind) {
9422 return TokenKind.isIdentifier(kind) || (!this.get$enableAwait() && $eq$(kind, (87)));
9423 }
9424 Parser.prototype._maybeEat = function(kind) {
9425 if (this._peekToken.kind == kind) {
9426 this._previousToken = this._peekToken;
9427 this._peekToken = this.tokenizer.next();
9428 return true;
9429 }
9430 else {
9431 return false;
9432 }
9433 }
9434 Parser.prototype._eat = function(kind) {
9435 if (!this._maybeEat(kind)) {
9436 this._errorExpected(TokenKind.kindToString(kind));
9437 }
9438 }
9439 Parser.prototype._eatSemicolon = function() {
9440 if (this.optionalSemicolons && this._peekKind((1))) return;
9441 this._eat((10));
9442 }
9443 Parser.prototype._errorExpected = function(expected) {
9444 if (this.throwOnIncomplete) this.isPrematureEndOfFile();
9445 var tok = this._lang_next();
9446 if ((tok instanceof ErrorToken) && tok.get$message() != null) {
9447 this._error(tok.get$message(), tok.get$span());
9448 }
9449 else {
9450 this._error(("expected " + expected + ", but found " + tok), tok.get$span()) ;
9451 }
9452 }
9453 Parser.prototype._error = function(message, location) {
9454 if (this._recover) return;
9455 if (location == null) {
9456 location = this._peekToken.get$span();
9457 }
9458 $globals.world.fatal(message, location);
9459 this._recover = true;
9460 }
9461 Parser.prototype._skipBlock = function() {
9462 var depth = (1);
9463 this._eat((6));
9464 while (true) {
9465 var tok = this._lang_next();
9466 if (tok.get$kind() == (6)) {
9467 depth += (1);
9468 }
9469 else if (tok.get$kind() == (7)) {
9470 depth -= (1);
9471 if (depth == (0)) return;
9472 }
9473 else if (tok.get$kind() == (1)) {
9474 this._error("unexpected end of file during diet parse", tok.get$span());
9475 return;
9476 }
9477 }
9478 }
9479 Parser.prototype._makeSpan = function(start) {
9480 return new SourceSpan(this.source, start, this._previousToken.end);
9481 }
9482 Parser.prototype.compilationUnit = function() {
9483 var ret = [];
9484 this._maybeEat((13));
9485 while (this._peekKind((12))) {
9486 ret.add(this.directive());
9487 }
9488 this._recover = false;
9489 while (!this._maybeEat((1))) {
9490 ret.add(this.topLevelDefinition());
9491 }
9492 this._recover = false;
9493 return ret;
9494 }
9495 Parser.prototype.directive = function() {
9496 var start = this._peekToken.start;
9497 this._eat((12));
9498 var name = this.identifier();
9499 var args = this.arguments();
9500 this._eatSemicolon();
9501 return new DirectiveDefinition(name, args, this._makeSpan(start));
9502 }
9503 Parser.prototype.topLevelDefinition = function() {
9504 switch (this._peek()) {
9505 case (91):
9506
9507 return this.classDefinition((91));
9508
9509 case (78):
9510
9511 return this.classDefinition((78));
9512
9513 case (86):
9514
9515 return this.functionTypeAlias();
9516
9517 default:
9518
9519 return this.declaration(true);
9520
9521 }
9522 }
9523 Parser.prototype.classDefinition = function(kind) {
9524 var start = this._peekToken.start;
9525 this._eat(kind);
9526 var name = this.identifierForType();
9527 var typeParams = null;
9528 if (this._peekKind((52))) {
9529 typeParams = this.typeParameters();
9530 }
9531 var _extends = null;
9532 if (this._maybeEat((97))) {
9533 _extends = this.typeList();
9534 }
9535 var _implements = null;
9536 if (this._maybeEat((76))) {
9537 _implements = this.typeList();
9538 }
9539 var _native = null;
9540 if (this._maybeEat((80))) {
9541 _native = this.maybeStringLiteral();
9542 if ($ne$(_native)) _native = new NativeType(_native);
9543 }
9544 var oldFactory = this._maybeEat((74));
9545 var defaultType = null;
9546 if (oldFactory || this._maybeEat((94))) {
9547 if (oldFactory) {
9548 $globals.world.warning("factory no longer supported, use \"default\" inste ad", this._previousToken.get$span());
9549 }
9550 var baseType = this.nameTypeReference();
9551 var factTypeParams = null;
9552 if (this._peekKind((52))) {
9553 factTypeParams = this.typeParameters();
9554 }
9555 defaultType = new DefaultTypeReference(oldFactory, baseType, factTypeParams, this._makeSpan(baseType.get$span().start));
9556 }
9557 var body = [];
9558 if (this._maybeEat((6))) {
9559 while (!this._maybeEat((7))) {
9560 body.add(this.declaration(true));
9561 if (this._recover) {
9562 if (!this._recoverTo((7), (10))) break;
9563 this._maybeEat((10));
9564 }
9565 }
9566 }
9567 else {
9568 this._errorExpected("block starting with \"{\" or \";\"");
9569 }
9570 return new TypeDefinition(kind == (91), name, typeParams, _extends, _implement s, _native, defaultType, body, this._makeSpan(start));
9571 }
9572 Parser.prototype.functionTypeAlias = function() {
9573 var start = this._peekToken.start;
9574 this._eat((86));
9575 var di = this.declaredIdentifier(false);
9576 var typeParams = null;
9577 if (this._peekKind((52))) {
9578 typeParams = this.typeParameters();
9579 }
9580 var formals = this.formalParameterList();
9581 this._eatSemicolon();
9582 var func = new FunctionDefinition(null, di.get$type(), di.get$name(), formals, null, null, null, this._makeSpan(start));
9583 return new FunctionTypeDefinition(func, typeParams, this._makeSpan(start));
9584 }
9585 Parser.prototype.initializers = function() {
9586 this._inhibitLambda = true;
9587 var ret = [];
9588 do {
9589 ret.add(this.expression());
9590 }
9591 while (this._maybeEat((11)))
9592 this._inhibitLambda = false;
9593 return ret;
9594 }
9595 Parser.prototype.get$initializers = function() {
9596 return this.initializers.bind(this);
9597 }
9598 Parser.prototype.functionBody = function(inExpression) {
9599 var start = this._peekToken.start;
9600 if (this._maybeEat((9))) {
9601 var expr = this.expression();
9602 if (!inExpression) {
9603 this._eatSemicolon();
9604 }
9605 return new ReturnStatement(expr, this._makeSpan(start));
9606 }
9607 else if (this._peekKind((6))) {
9608 if (this.diet) {
9609 this._skipBlock();
9610 return new DietStatement(this._makeSpan(start));
9611 }
9612 else {
9613 return this.block();
9614 }
9615 }
9616 else if (!inExpression) {
9617 if (this._maybeEat((10))) {
9618 return null;
9619 }
9620 }
9621 this._error("Expected function body (neither { nor => found)");
9622 }
9623 Parser.prototype.finishField = function(start, modifiers, type, name, value) {
9624 var names = [name];
9625 var values = [value];
9626 while (this._maybeEat((11))) {
9627 names.add(this.identifier());
9628 if (this._maybeEat((20))) {
9629 values.add(this.expression());
9630 }
9631 else {
9632 values.add();
9633 }
9634 }
9635 this._eatSemicolon();
9636 return new VariableDefinition(modifiers, type, names, values, this._makeSpan(s tart));
9637 }
9638 Parser.prototype.finishDefinition = function(start, modifiers, di) {
9639 switch (this._peek()) {
9640 case (2):
9641
9642 var formals = this.formalParameterList();
9643 var inits = null, native_ = null;
9644 if (this._maybeEat((8))) {
9645 inits = this.initializers();
9646 }
9647 if (this._maybeEat((80))) {
9648 native_ = this.maybeStringLiteral();
9649 if ($eq$(native_)) native_ = "";
9650 }
9651 var body = this.functionBody(false);
9652 if ($eq$(di.get$name())) {
9653 di.set$name(di.get$type().get$name());
9654 }
9655 return new FunctionDefinition(modifiers, di.get$type(), di.get$name(), for mals, inits, native_, body, this._makeSpan(start));
9656
9657 case (20):
9658
9659 this._eat((20));
9660 var value = this.expression();
9661 return this.finishField(start, modifiers, di.get$type(), di.get$name(), va lue);
9662
9663 case (11):
9664 case (10):
9665
9666 return this.finishField(start, modifiers, di.get$type(), di.get$name(), nu ll);
9667
9668 default:
9669
9670 this._errorExpected("declaration");
9671 return null;
9672
9673 }
9674 }
9675 Parser.prototype.declaration = function(includeOperators) {
9676 var start = this._peekToken.start;
9677 if (this._peekKind((74))) {
9678 return this.factoryConstructorDeclaration();
9679 }
9680 var modifiers = this._readModifiers();
9681 return this.finishDefinition(start, modifiers, this.declaredIdentifier(include Operators));
9682 }
9683 Parser.prototype.factoryConstructorDeclaration = function() {
9684 var start = this._peekToken.start;
9685 var factoryToken = this._lang_next();
9686 var names = [this.identifier()];
9687 while (this._maybeEat((14))) {
9688 names.add(this.identifier());
9689 }
9690 if (this._peekKind((52))) {
9691 var tp = this.typeParameters();
9692 $globals.world.warning("type parameters on factories are no longer supported , place them on the class instead", this._makeSpan(tp.$index((0)).get$span().sta rt));
9693 }
9694 var name = null;
9695 var type = null;
9696 if (this._maybeEat((14))) {
9697 name = this.identifier();
9698 }
9699 else {
9700 if (names.get$length() > (1)) {
9701 name = names.removeLast();
9702 }
9703 else {
9704 name = new Identifier("", names.$index((0)).get$span());
9705 }
9706 }
9707 if (names.get$length() > (1)) {
9708 this._error("unsupported qualified name for factory", names.$index((0)).get$ span());
9709 }
9710 type = new NameTypeReference(false, names.$index((0)), null, names.$index((0)) .get$span());
9711 var di = new DeclaredIdentifier(type, name, false, this._makeSpan(start));
9712 return this.finishDefinition(start, [factoryToken], di);
9713 }
9714 Parser.prototype.statement = function() {
9715 switch (this._peek()) {
9716 case (88):
9717
9718 return this.breakStatement();
9719
9720 case (93):
9721
9722 return this.continueStatement();
9723
9724 case (107):
9725
9726 return this.returnStatement();
9727
9728 case (111):
9729
9730 return this.throwStatement();
9731
9732 case (72):
9733
9734 return this.assertStatement();
9735
9736 case (116):
9737
9738 return this.whileStatement();
9739
9740 case (95):
9741
9742 return this.doStatement();
9743
9744 case (101):
9745
9746 return this.forStatement();
9747
9748 case (102):
9749
9750 return this.ifStatement();
9751
9752 case (109):
9753
9754 return this.switchStatement();
9755
9756 case (113):
9757
9758 return this.tryStatement();
9759
9760 case (6):
9761
9762 return this.block();
9763
9764 case (10):
9765
9766 return this.emptyStatement();
9767
9768 case (99):
9769
9770 return this.declaration(false);
9771
9772 case (114):
9773
9774 return this.declaration(false);
9775
9776 default:
9777
9778 return this.finishExpressionAsStatement(this.expression());
9779
9780 }
9781 }
9782 Parser.prototype.finishExpressionAsStatement = function(expr) {
9783 var start = expr.get$span().start;
9784 if (this._maybeEat((8))) {
9785 var label = this._makeLabel(expr);
9786 return new LabeledStatement(label, this.statement(), this._makeSpan(start));
9787 }
9788 if ((expr instanceof LambdaExpression)) {
9789 if (!(expr.get$func().body instanceof BlockStatement)) {
9790 this._eatSemicolon();
9791 expr.get$func().span = this._makeSpan(start);
9792 }
9793 return expr.get$func();
9794 }
9795 else if ((expr instanceof DeclaredIdentifier)) {
9796 var value = null;
9797 if (this._maybeEat((20))) {
9798 value = this.expression();
9799 }
9800 return this.finishField(start, null, expr.get$type(), expr.get$name(), value );
9801 }
9802 else if (this._isBin(expr, (20)) && ((expr.get$x() instanceof DeclaredIdentifi er))) {
9803 var di = expr.get$x();
9804 return this.finishField(start, null, di.type, di.name, expr.get$y());
9805 }
9806 else if (this._isBin(expr, (52)) && this._maybeEat((11))) {
9807 var baseType = this._makeType(expr.get$x());
9808 var typeArgs = [this._makeType(expr.get$y())];
9809 var gt = this._finishTypeArguments(baseType, (0), typeArgs);
9810 var name = this.identifier();
9811 var value = null;
9812 if (this._maybeEat((20))) {
9813 value = this.expression();
9814 }
9815 return this.finishField(expr.get$span().start, null, gt, name, value);
9816 }
9817 else {
9818 this._eatSemicolon();
9819 return new ExpressionStatement(expr, this._makeSpan(expr.get$span().start));
9820 }
9821 }
9822 Parser.prototype.testCondition = function() {
9823 this._eatLeftParen();
9824 var ret = this.expression();
9825 this._eat((3));
9826 return ret;
9827 }
9828 Parser.prototype.block = function() {
9829 var start = this._peekToken.start;
9830 this._eat((6));
9831 var stmts = [];
9832 while (!this._maybeEat((7))) {
9833 stmts.add(this.statement());
9834 if (this._recover && !this._recoverTo((7), (10))) break;
9835 }
9836 this._recover = false;
9837 return new BlockStatement(stmts, this._makeSpan(start));
9838 }
9839 Parser.prototype.emptyStatement = function() {
9840 var start = this._peekToken.start;
9841 this._eat((10));
9842 return new EmptyStatement(this._makeSpan(start));
9843 }
9844 Parser.prototype.ifStatement = function() {
9845 var start = this._peekToken.start;
9846 this._eat((102));
9847 var test = this.testCondition();
9848 var trueBranch = this.statement();
9849 var falseBranch = null;
9850 if (this._maybeEat((96))) {
9851 falseBranch = this.statement();
9852 }
9853 return new IfStatement(test, trueBranch, falseBranch, this._makeSpan(start));
9854 }
9855 Parser.prototype.whileStatement = function() {
9856 var start = this._peekToken.start;
9857 this._eat((116));
9858 var test = this.testCondition();
9859 var body = this.statement();
9860 return new WhileStatement(test, body, this._makeSpan(start));
9861 }
9862 Parser.prototype.doStatement = function() {
9863 var start = this._peekToken.start;
9864 this._eat((95));
9865 var body = this.statement();
9866 this._eat((116));
9867 var test = this.testCondition();
9868 this._eatSemicolon();
9869 return new DoStatement(body, test, this._makeSpan(start));
9870 }
9871 Parser.prototype.forStatement = function() {
9872 var start = this._peekToken.start;
9873 this._eat((101));
9874 this._eatLeftParen();
9875 var init = this.forInitializerStatement(start);
9876 if ((init instanceof ForInStatement)) {
9877 return init;
9878 }
9879 var test = null;
9880 if (!this._maybeEat((10))) {
9881 test = this.expression();
9882 this._eatSemicolon();
9883 }
9884 var step = [];
9885 if (!this._maybeEat((3))) {
9886 step.add(this.expression());
9887 while (this._maybeEat((11))) {
9888 step.add(this.expression());
9889 }
9890 this._eat((3));
9891 }
9892 var body = this.statement();
9893 return new ForStatement(init, test, step, body, this._makeSpan(start));
9894 }
9895 Parser.prototype.forInitializerStatement = function(start) {
9896 if (this._maybeEat((10))) {
9897 return null;
9898 }
9899 else {
9900 var init = this.expression();
9901 if (this._peekKind((11)) && this._isBin(init, (52))) {
9902 this._eat((11));
9903 var baseType = this._makeType(init.get$x());
9904 var typeArgs = [this._makeType(init.get$y())];
9905 var gt = this._finishTypeArguments(baseType, (0), typeArgs);
9906 var name = this.identifier();
9907 init = new DeclaredIdentifier(gt, name, false, this._makeSpan(init.get$spa n().start));
9908 }
9909 if (this._maybeEat((103))) {
9910 return this._finishForIn(start, this._makeDeclaredIdentifier(init));
9911 }
9912 else {
9913 return this.finishExpressionAsStatement(init);
9914 }
9915 }
9916 }
9917 Parser.prototype._finishForIn = function(start, di) {
9918 var expr = this.expression();
9919 this._eat((3));
9920 var body = this.statement();
9921 return new ForInStatement(di, expr, body, this._makeSpan(start));
9922 }
9923 Parser.prototype.tryStatement = function() {
9924 var start = this._peekToken.start;
9925 this._eat((113));
9926 var body = this.block();
9927 var catches = [];
9928 while (this._peekKind((90))) {
9929 catches.add(this.catchNode());
9930 }
9931 var finallyBlock = null;
9932 if (this._maybeEat((100))) {
9933 finallyBlock = this.block();
9934 }
9935 return new TryStatement(body, catches, finallyBlock, this._makeSpan(start));
9936 }
9937 Parser.prototype.catchNode = function() {
9938 var start = this._peekToken.start;
9939 this._eat((90));
9940 this._eatLeftParen();
9941 var exc = this.declaredIdentifier(false);
9942 var trace = null;
9943 if (this._maybeEat((11))) {
9944 trace = this.declaredIdentifier(false);
9945 }
9946 this._eat((3));
9947 var body = this.block();
9948 return new CatchNode(exc, trace, body, this._makeSpan(start));
9949 }
9950 Parser.prototype.switchStatement = function() {
9951 var start = this._peekToken.start;
9952 this._eat((109));
9953 var test = this.testCondition();
9954 var cases = [];
9955 this._eat((6));
9956 while (!this._maybeEat((7))) {
9957 cases.add(this.caseNode());
9958 }
9959 return new SwitchStatement(test, cases, this._makeSpan(start));
9960 }
9961 Parser.prototype._peekCaseEnd = function() {
9962 var kind = this._peek();
9963 return $eq$(kind, (7)) || $eq$(kind, (89)) || $eq$(kind, (94));
9964 }
9965 Parser.prototype.caseNode = function() {
9966 var start = this._peekToken.start;
9967 var label = null;
9968 if (this._peekIdentifier()) {
9969 label = this.identifier();
9970 this._eat((8));
9971 }
9972 var cases = [];
9973 while (true) {
9974 if (this._maybeEat((89))) {
9975 cases.add(this.expression());
9976 this._eat((8));
9977 }
9978 else if (this._maybeEat((94))) {
9979 cases.add();
9980 this._eat((8));
9981 }
9982 else {
9983 break;
9984 }
9985 }
9986 if (cases.get$length() == (0)) {
9987 this._error("case or default");
9988 }
9989 var stmts = [];
9990 while (!this._peekCaseEnd()) {
9991 stmts.add(this.statement());
9992 if (this._recover && !this._recoverTo((7), (89), (94))) {
9993 break;
9994 }
9995 }
9996 return new CaseNode(label, cases, stmts, this._makeSpan(start));
9997 }
9998 Parser.prototype.returnStatement = function() {
9999 var start = this._peekToken.start;
10000 this._eat((107));
10001 var expr;
10002 if (this._maybeEat((10))) {
10003 expr = null;
10004 }
10005 else {
10006 expr = this.expression();
10007 this._eatSemicolon();
10008 }
10009 return new ReturnStatement(expr, this._makeSpan(start));
10010 }
10011 Parser.prototype.throwStatement = function() {
10012 var start = this._peekToken.start;
10013 this._eat((111));
10014 var expr;
10015 if (this._maybeEat((10))) {
10016 expr = null;
10017 }
10018 else {
10019 expr = this.expression();
10020 this._eatSemicolon();
10021 }
10022 return new ThrowStatement(expr, this._makeSpan(start));
10023 }
10024 Parser.prototype.assertStatement = function() {
10025 var start = this._peekToken.start;
10026 this._eat((72));
10027 this._eatLeftParen();
10028 var expr = this.expression();
10029 this._eat((3));
10030 this._eatSemicolon();
10031 return new AssertStatement(expr, this._makeSpan(start));
10032 }
10033 Parser.prototype.breakStatement = function() {
10034 var start = this._peekToken.start;
10035 this._eat((88));
10036 var name = null;
10037 if (this._peekIdentifier()) {
10038 name = this.identifier();
10039 }
10040 this._eatSemicolon();
10041 return new BreakStatement(name, this._makeSpan(start));
10042 }
10043 Parser.prototype.continueStatement = function() {
10044 var start = this._peekToken.start;
10045 this._eat((93));
10046 var name = null;
10047 if (this._peekIdentifier()) {
10048 name = this.identifier();
10049 }
10050 this._eatSemicolon();
10051 return new ContinueStatement(name, this._makeSpan(start));
10052 }
10053 Parser.prototype.expression = function() {
10054 return this.infixExpression((0));
10055 }
10056 Parser.prototype._makeType = function(expr) {
10057 if ((expr instanceof VarExpression)) {
10058 return new NameTypeReference(false, expr.get$name(), null, expr.get$span());
10059 }
10060 else if ((expr instanceof DotExpression)) {
10061 var type = this._makeType(expr.get$self());
10062 if (type.get$names() == null) {
10063 type.set$names([expr.get$name()]);
10064 }
10065 else {
10066 type.get$names().add(expr.get$name());
10067 }
10068 type.set$span(expr.get$span());
10069 return type;
10070 }
10071 else {
10072 this._error("expected type reference");
10073 return null;
10074 }
10075 }
10076 Parser.prototype.infixExpression = function(precedence) {
10077 return this.finishInfixExpression(this.unaryExpression(), precedence);
10078 }
10079 Parser.prototype._finishDeclaredId = function(type) {
10080 var name = this.identifier();
10081 return this.finishPostfixExpression(new DeclaredIdentifier(type, name, false, this._makeSpan(type.get$span().start)));
10082 }
10083 Parser.prototype._fixAsType = function(x) {
10084 if (this._maybeEat((53))) {
10085 var base = this._makeType(x.x);
10086 var typeParam = this._makeType(x.y);
10087 var type = new GenericTypeReference(base, [typeParam], (0), this._makeSpan(x .span.start));
10088 return this._finishDeclaredId(type);
10089 }
10090 else {
10091 var base = this._makeType(x.x);
10092 var paramBase = this._makeType(x.y);
10093 var firstParam = this.addTypeArguments(paramBase, (1));
10094 var type;
10095 if (firstParam.get$depth() <= (0)) {
10096 type = new GenericTypeReference(base, [firstParam], (0), this._makeSpan(x. span.start));
10097 }
10098 else if (this._maybeEat((11))) {
10099 type = this._finishTypeArguments(base, (0), [firstParam]);
10100 }
10101 else {
10102 this._eat((53));
10103 type = new GenericTypeReference(base, [firstParam], (0), this._makeSpan(x. span.start));
10104 }
10105 return this._finishDeclaredId(type);
10106 }
10107 }
10108 Parser.prototype.finishInfixExpression = function(x, precedence) {
10109 while (true) {
10110 var kind = this._peek();
10111 var prec = TokenKind.infixPrecedence(this._peek());
10112 if ($gte$(prec, precedence)) {
10113 if (kind == (52) || kind == (53)) {
10114 if (this._isBin(x, (52))) {
10115 return this._fixAsType(x);
10116 }
10117 }
10118 var op = this._lang_next();
10119 if (op.get$kind() == (104)) {
10120 var isTrue = !this._maybeEat((19));
10121 var typeRef = this.type((0));
10122 x = new IsExpression(isTrue, x, typeRef, this._makeSpan(x.span.start));
10123 continue;
10124 }
10125 var y = this.infixExpression($eq$(prec, (2)) ? prec : $add$(prec, (1)));
10126 if (op.get$kind() == (33)) {
10127 this._eat((8));
10128 var z = this.infixExpression(prec);
10129 x = new ConditionalExpression(x, y, z, this._makeSpan(x.span.start));
10130 }
10131 else {
10132 x = new BinaryExpression(op, x, y, this._makeSpan(x.span.start));
10133 }
10134 }
10135 else {
10136 break;
10137 }
10138 }
10139 return x;
10140 }
10141 Parser.prototype._isPrefixUnaryOperator = function(kind) {
10142 switch (kind) {
10143 case (42):
10144 case (43):
10145 case (19):
10146 case (18):
10147 case (16):
10148 case (17):
10149
10150 return true;
10151
10152 default:
10153
10154 return false;
10155
10156 }
10157 }
10158 Parser.prototype.unaryExpression = function() {
10159 var start = this._peekToken.start;
10160 if (this._isPrefixUnaryOperator(this._peek())) {
10161 var tok = this._lang_next();
10162 var expr = this.unaryExpression();
10163 return new UnaryExpression(tok, expr, this._makeSpan(start));
10164 }
10165 else if (this.get$enableAwait() && this._maybeEat((87))) {
10166 var expr = this.unaryExpression();
10167 return new AwaitExpression(expr, this._makeSpan(start));
10168 }
10169 return this.finishPostfixExpression(this.primary());
10170 }
10171 Parser.prototype.argument = function() {
10172 var start = this._peekToken.start;
10173 var expr;
10174 var label = null;
10175 if (this._maybeEat((15))) {
10176 label = new Identifier("...", this._makeSpan(start));
10177 }
10178 expr = this.expression();
10179 if ($eq$(label) && this._maybeEat((8))) {
10180 label = this._makeLabel(expr);
10181 expr = this.expression();
10182 }
10183 return new ArgumentNode(label, expr, this._makeSpan(start));
10184 }
10185 Parser.prototype.arguments = function() {
10186 var args = [];
10187 this._eatLeftParen();
10188 var saved = this._inhibitLambda;
10189 this._inhibitLambda = false;
10190 if (!this._maybeEat((3))) {
10191 do {
10192 args.add(this.argument());
10193 }
10194 while (this._maybeEat((11)))
10195 this._eat((3));
10196 }
10197 this._inhibitLambda = saved;
10198 return args;
10199 }
10200 Parser.prototype.finishPostfixExpression = function(expr) {
10201 switch (this._peek()) {
10202 case (2):
10203
10204 return this.finishCallOrLambdaExpression(expr);
10205
10206 case (4):
10207
10208 this._eat((4));
10209 var index = this.expression();
10210 this._eat((5));
10211 return this.finishPostfixExpression(new IndexExpression(expr, index, this. _makeSpan(expr.get$span().start)));
10212
10213 case (14):
10214
10215 this._eat((14));
10216 var name = this.identifier();
10217 var ret = new DotExpression(expr, name, this._makeSpan(expr.get$span().sta rt));
10218 return this.finishPostfixExpression(ret);
10219
10220 case (16):
10221 case (17):
10222
10223 var tok = this._lang_next();
10224 return new PostfixExpression(expr, tok, this._makeSpan(expr.get$span().sta rt));
10225
10226 case (9):
10227 case (6):
10228
10229 return expr;
10230
10231 default:
10232
10233 if (this._peekIdentifier()) {
10234 return this.finishPostfixExpression(new DeclaredIdentifier(this._makeTyp e(expr), this.identifier(), false, this._makeSpan(expr.get$span().start)));
10235 }
10236 else {
10237 return expr;
10238 }
10239
10240 }
10241 }
10242 Parser.prototype.finishCallOrLambdaExpression = function(expr) {
10243 if (this._atClosureParameters()) {
10244 var formals = this.formalParameterList();
10245 var body = this.functionBody(true);
10246 return this._makeFunction(expr, formals, body);
10247 }
10248 else {
10249 if ((expr instanceof DeclaredIdentifier)) {
10250 this._error("illegal target for call, did you mean to declare a function?" , expr.get$span());
10251 }
10252 var args = this.arguments();
10253 return this.finishPostfixExpression(new CallExpression(expr, args, this._mak eSpan(expr.get$span().start)));
10254 }
10255 }
10256 Parser.prototype._isBin = function(expr, kind) {
10257 return (expr instanceof BinaryExpression) && expr.get$op().kind == kind;
10258 }
10259 Parser.prototype._makeLiteral = function(value) {
10260 return new LiteralExpression(value, value.span);
10261 }
10262 Parser.prototype.primary = function() {
10263 var start = this._peekToken.start;
10264 switch (this._peek()) {
10265 case (110):
10266
10267 this._eat((110));
10268 return new ThisExpression(this._makeSpan(start));
10269
10270 case (108):
10271
10272 this._eat((108));
10273 return new SuperExpression(this._makeSpan(start));
10274
10275 case (92):
10276
10277 this._eat((92));
10278 if (this._peekKind((4)) || this._peekKind((56))) {
10279 return this.finishListLiteral(start, true, null);
10280 }
10281 else if (this._peekKind((6))) {
10282 return this.finishMapLiteral(start, true, null, null);
10283 }
10284 else if (this._peekKind((52))) {
10285 return this.finishTypedLiteral(start, true);
10286 }
10287 else {
10288 return this.finishNewExpression(start, true);
10289 }
10290
10291 case (105):
10292
10293 this._eat((105));
10294 return this.finishNewExpression(start, false);
10295
10296 case (2):
10297
10298 return this._parenOrLambda();
10299
10300 case (4):
10301 case (56):
10302
10303 return this.finishListLiteral(start, false, null);
10304
10305 case (6):
10306
10307 return this.finishMapLiteral(start, false, null, null);
10308
10309 case (106):
10310
10311 this._eat((106));
10312 return this._makeLiteral(Value.fromNull(this._makeSpan(start)));
10313
10314 case (112):
10315
10316 this._eat((112));
10317 return this._makeLiteral(Value.fromBool(true, this._makeSpan(start)));
10318
10319 case (98):
10320
10321 this._eat((98));
10322 return this._makeLiteral(Value.fromBool(false, this._makeSpan(start)));
10323
10324 case (61):
10325
10326 var t = this._lang_next();
10327 return this._makeLiteral(Value.fromInt(t.get$value(), t.get$span()));
10328
10329 case (60):
10330
10331 var t = this._lang_next();
10332 return this._makeLiteral(Value.fromInt(Math.parseInt(t.get$text()), t.get$ span()));
10333
10334 case (62):
10335
10336 var t = this._lang_next();
10337 return this._makeLiteral(Value.fromDouble(Math.parseDouble(t.get$text()), t.get$span()));
10338
10339 case (58):
10340 case (59):
10341
10342 return this.adjacentStrings();
10343
10344 case (52):
10345
10346 return this.finishTypedLiteral(start, false);
10347
10348 case (115):
10349 case (114):
10350 case (99):
10351
10352 return this.declaredIdentifier(false);
10353
10354 default:
10355
10356 if (!this._peekIdentifier()) {
10357 this._errorExpected("expression");
10358 }
10359 return new VarExpression(this.identifier(), this._makeSpan(start));
10360
10361 }
10362 }
10363 Parser.prototype.adjacentStrings = function() {
10364 var start = this._peekToken.start;
10365 var strings = [];
10366 while (this._peek() == (58) || this._peek() == (59)) {
10367 var part = null;
10368 if (this._peek() == (58)) {
10369 var t = this._lang_next();
10370 part = this._makeLiteral(Value.fromString(t.get$value(), t.get$span()));
10371 }
10372 else {
10373 part = this.stringInterpolation();
10374 }
10375 strings.add(part);
10376 }
10377 if (strings.get$length() == (1)) {
10378 return strings.$index((0));
10379 }
10380 else {
10381 return new StringConcatExpression(strings, this._makeSpan(start));
10382 }
10383 }
10384 Parser.prototype.stringInterpolation = function() {
10385 var start = this._peekToken.start;
10386 var pieces = new Array();
10387 var startQuote = null, endQuote = null;
10388 while (this._peekKind((59))) {
10389 var token = this._lang_next();
10390 pieces.add(this._makeLiteral(Value.fromString(token.get$value(), token.get$s pan())));
10391 if (this._maybeEat((6))) {
10392 pieces.add(this.expression());
10393 this._eat((7));
10394 }
10395 else if (this._maybeEat((110))) {
10396 pieces.add(new ThisExpression(this._previousToken.get$span()));
10397 }
10398 else {
10399 var id = this.identifier();
10400 pieces.add(new VarExpression(id, id.get$span()));
10401 }
10402 }
10403 var tok = this._lang_next();
10404 if (tok.get$kind() != (58)) {
10405 this._errorExpected("interpolated string");
10406 }
10407 pieces.add(this._makeLiteral(Value.fromString(tok.get$value(), tok.get$span()) ));
10408 var span = this._makeSpan(start);
10409 return new StringInterpExpression(pieces, span);
10410 }
10411 Parser.prototype.maybeStringLiteral = function() {
10412 var kind = this._peek();
10413 if ($eq$(kind, (58))) {
10414 var t = this._lang_next();
10415 return t.get$value();
10416 }
10417 else if ($eq$(kind, (59))) {
10418 this._lang_next();
10419 this._errorExpected("string literal, but found interpolated string start");
10420 }
10421 return null;
10422 }
10423 Parser.prototype._parenOrLambda = function() {
10424 var start = this._peekToken.start;
10425 if (this._atClosureParameters()) {
10426 var formals = this.formalParameterList();
10427 var body = this.functionBody(true);
10428 var func = new FunctionDefinition(null, null, null, formals, null, null, bod y, this._makeSpan(start));
10429 return new LambdaExpression(func, func.get$span());
10430 }
10431 else {
10432 this._eatLeftParen();
10433 var saved = this._inhibitLambda;
10434 this._inhibitLambda = false;
10435 var expr = this.expression();
10436 this._eat((3));
10437 this._inhibitLambda = saved;
10438 return new ParenExpression(expr, this._makeSpan(start));
10439 }
10440 }
10441 Parser.prototype._atClosureParameters = function() {
10442 if (this._inhibitLambda) return false;
10443 var after = this._peekAfterCloseParen();
10444 return after.kind == (9) || after.kind == (6);
10445 }
10446 Parser.prototype._eatLeftParen = function() {
10447 this._eat((2));
10448 this._afterParensIndex++;
10449 }
10450 Parser.prototype._peekAfterCloseParen = function() {
10451 if (this._afterParensIndex < this._afterParens.get$length()) {
10452 return this._afterParens.$index(this._afterParensIndex);
10453 }
10454 this._afterParensIndex = (0);
10455 this._afterParens.clear();
10456 var tokens = [this._lang_next()];
10457 this._lookaheadAfterParens(tokens);
10458 var after = this._peekToken;
10459 tokens.add(after);
10460 this.tokenizer = new DivertedTokenSource(tokens, this, this.tokenizer);
10461 this._lang_next();
10462 return after;
10463 }
10464 Parser.prototype._lookaheadAfterParens = function(tokens) {
10465 var saved = this._afterParens.get$length();
10466 this._afterParens.add();
10467 while (true) {
10468 var token = this._lang_next();
10469 tokens.add(token);
10470 var kind = token.kind;
10471 if (kind == (3) || kind == (1)) {
10472 this._afterParens.$setindex(saved, this._peekToken);
10473 return;
10474 }
10475 else if (kind == (2)) {
10476 this._lookaheadAfterParens(tokens);
10477 }
10478 }
10479 }
10480 Parser.prototype._typeAsIdentifier = function(type) {
10481 if ($eq$(type.get$name().get$name(), "void")) {
10482 this._errorExpected(("identifer, but found \"" + type.get$name().get$name() + "\""));
10483 }
10484 return type.get$name();
10485 }
10486 Parser.prototype._specialIdentifier = function(includeOperators) {
10487 var start = this._peekToken.start;
10488 var name;
10489 switch (this._peek()) {
10490 case (15):
10491
10492 this._eat((15));
10493 this._error("rest no longer supported", this._previousToken.get$span());
10494 name = this.identifier().get$name();
10495 break;
10496
10497 case (110):
10498
10499 this._eat((110));
10500 this._eat((14));
10501 name = ("this." + this.identifier().get$name());
10502 break;
10503
10504 case (75):
10505
10506 if (!includeOperators) return null;
10507 this._eat((75));
10508 if (this._peekIdentifier()) {
10509 name = ("get:" + this.identifier().get$name());
10510 }
10511 else {
10512 name = "get";
10513 }
10514 break;
10515
10516 case (83):
10517
10518 if (!includeOperators) return null;
10519 this._eat((83));
10520 if (this._peekIdentifier()) {
10521 name = ("set:" + this.identifier().get$name());
10522 }
10523 else {
10524 name = "set";
10525 }
10526 break;
10527
10528 case (82):
10529
10530 if (!includeOperators) return null;
10531 this._eat((82));
10532 var kind = this._peek();
10533 if ($eq$(kind, (81))) {
10534 name = ":negate";
10535 this._lang_next();
10536 }
10537 else {
10538 name = TokenKind.binaryMethodName(kind);
10539 if (name == null) {
10540 name = "operator";
10541 }
10542 else {
10543 this._lang_next();
10544 }
10545 }
10546 break;
10547
10548 default:
10549
10550 return null;
10551
10552 }
10553 return new Identifier(name, this._makeSpan(start));
10554 }
10555 Parser.prototype.declaredIdentifier = function(includeOperators) {
10556 var start = this._peekToken.start;
10557 var myType = null;
10558 var name = this._specialIdentifier(includeOperators);
10559 var isFinal = false;
10560 if ($eq$(name)) {
10561 myType = this.type((0));
10562 name = this._specialIdentifier(includeOperators);
10563 if ($eq$(name)) {
10564 if (this._peekIdentifier()) {
10565 name = this.identifier();
10566 }
10567 else if ((myType instanceof NameTypeReference) && myType.get$names() == nu ll) {
10568 name = this._typeAsIdentifier(myType);
10569 isFinal = myType.get$isFinal();
10570 myType = null;
10571 }
10572 else {
10573 }
10574 }
10575 }
10576 return new DeclaredIdentifier(myType, name, isFinal, this._makeSpan(start));
10577 }
10578 Parser.prototype.finishNewExpression = function(start, isConst) {
10579 var type = this.type((0));
10580 var name = null;
10581 if (this._maybeEat((14))) {
10582 name = this.identifier();
10583 }
10584 var args = this.arguments();
10585 return new NewExpression(isConst, type, name, args, this._makeSpan(start));
10586 }
10587 Parser.prototype.finishListLiteral = function(start, isConst, itemType) {
10588 if (this._maybeEat((56))) {
10589 return new ListExpression(isConst, itemType, [], this._makeSpan(start));
10590 }
10591 var values = [];
10592 this._eat((4));
10593 while (!this._maybeEat((5))) {
10594 values.add(this.expression());
10595 if (this._recover && !this._recoverTo((5), (11))) break;
10596 if (!this._maybeEat((11))) {
10597 this._eat((5));
10598 break;
10599 }
10600 }
10601 return new ListExpression(isConst, itemType, values, this._makeSpan(start));
10602 }
10603 Parser.prototype.finishMapLiteral = function(start, isConst, keyType, valueType) {
10604 var items = [];
10605 this._eat((6));
10606 while (!this._maybeEat((7))) {
10607 items.add(this.expression());
10608 this._eat((8));
10609 items.add(this.expression());
10610 if (this._recover && !this._recoverTo((7), (11))) break;
10611 if (!this._maybeEat((11))) {
10612 this._eat((7));
10613 break;
10614 }
10615 }
10616 return new MapExpression(isConst, keyType, valueType, items, this._makeSpan(st art));
10617 }
10618 Parser.prototype.finishTypedLiteral = function(start, isConst) {
10619 var span = this._makeSpan(start);
10620 var typeToBeNamedLater = new NameTypeReference(false, null, null, span);
10621 var genericType = this.addTypeArguments(typeToBeNamedLater, (0));
10622 var typeArgs = genericType.get$typeArguments();
10623 if (this._peekKind((4)) || this._peekKind((56))) {
10624 if (typeArgs.get$length() != (1)) {
10625 $globals.world.error("exactly one type argument expected for list", generi cType.get$span());
10626 }
10627 return this.finishListLiteral(start, isConst, typeArgs.$index((0)));
10628 }
10629 else if (this._peekKind((6))) {
10630 var keyType, valueType;
10631 if (typeArgs.get$length() == (1)) {
10632 keyType = null;
10633 valueType = typeArgs.$index((0));
10634 }
10635 else if (typeArgs.get$length() == (2)) {
10636 keyType = typeArgs.$index((0));
10637 $globals.world.warning("a map literal takes one type argument specifying t he value type", keyType.get$span());
10638 valueType = typeArgs.$index((1));
10639 }
10640 return this.finishMapLiteral(start, isConst, keyType, valueType);
10641 }
10642 else {
10643 this._errorExpected("array or map literal");
10644 }
10645 }
10646 Parser.prototype._readModifiers = function() {
10647 var modifiers = null;
10648 while (true) {
10649 switch (this._peek()) {
10650 case (85):
10651 case (99):
10652 case (92):
10653 case (71):
10654 case (74):
10655
10656 if ($eq$(modifiers)) modifiers = [];
10657 modifiers.add(this._lang_next());
10658 break;
10659
10660 default:
10661
10662 return modifiers;
10663
10664 }
10665 }
10666 return null;
10667 }
10668 Parser.prototype.typeParameter = function() {
10669 var start = this._peekToken.start;
10670 var name = this.identifier();
10671 var myType = null;
10672 if (this._maybeEat((97))) {
10673 myType = this.type((1));
10674 }
10675 var tp = new TypeParameter(name, myType, this._makeSpan(start));
10676 return new ParameterType(name.get$name(), tp);
10677 }
10678 Parser.prototype.get$typeParameter = function() {
10679 return this.typeParameter.bind(this);
10680 }
10681 Parser.prototype.typeParameters = function() {
10682 this._eat((52));
10683 var closed = false;
10684 var ret = [];
10685 do {
10686 var tp = this.typeParameter();
10687 ret.add(tp);
10688 if ((tp.get$typeParameter().get$extendsType() instanceof GenericTypeReferenc e) && tp.get$typeParameter().get$extendsType().get$dynamic().get$depth() == (0)) {
10689 closed = true;
10690 break;
10691 }
10692 }
10693 while (this._maybeEat((11)))
10694 if (!closed) {
10695 this._eat((53));
10696 }
10697 return ret;
10698 }
10699 Parser.prototype.get$typeParameters = function() {
10700 return this.typeParameters.bind(this);
10701 }
10702 Parser.prototype._eatClosingAngle = function(depth) {
10703 if (this._maybeEat((53))) {
10704 return depth;
10705 }
10706 else if (depth > (0) && this._maybeEat((40))) {
10707 return depth - (1);
10708 }
10709 else if (depth > (1) && this._maybeEat((41))) {
10710 return depth - (2);
10711 }
10712 else {
10713 this._errorExpected(">");
10714 return depth;
10715 }
10716 }
10717 Parser.prototype.addTypeArguments = function(baseType, depth) {
10718 this._eat((52));
10719 return this._finishTypeArguments(baseType, depth, []);
10720 }
10721 Parser.prototype._finishTypeArguments = function(baseType, depth, types) {
10722 var delta = (-1);
10723 do {
10724 var myType = this.type(depth + (1));
10725 types.add(myType);
10726 if ((myType instanceof GenericTypeReference) && myType.get$depth() <= depth) {
10727 delta = depth - myType.get$depth();
10728 break;
10729 }
10730 }
10731 while (this._maybeEat((11)))
10732 if ($gte$(delta, (0))) {
10733 depth = $sub$(depth, delta);
10734 }
10735 else {
10736 depth = this._eatClosingAngle(depth);
10737 }
10738 var span = this._makeSpan(baseType.span.start);
10739 return new GenericTypeReference(baseType, types, depth, span);
10740 }
10741 Parser.prototype.typeList = function() {
10742 var types = [];
10743 do {
10744 types.add(this.type((0)));
10745 }
10746 while (this._maybeEat((11)))
10747 return types;
10748 }
10749 Parser.prototype.nameTypeReference = function() {
10750 var start = this._peekToken.start;
10751 var name;
10752 var names = null;
10753 var typeArgs = null;
10754 var isFinal = false;
10755 switch (this._peek()) {
10756 case (115):
10757
10758 return new SimpleTypeReference($globals.world.voidType, this._lang_next(). get$span());
10759
10760 case (114):
10761
10762 return new SimpleTypeReference($globals.world.varType, this._lang_next().g et$span());
10763
10764 case (99):
10765
10766 this._eat((99));
10767 isFinal = true;
10768 name = this.identifier();
10769 break;
10770
10771 default:
10772
10773 name = this.identifier();
10774 break;
10775
10776 }
10777 while (this._maybeEat((14))) {
10778 if ($eq$(names)) names = [];
10779 names.add(this.identifier());
10780 }
10781 return new NameTypeReference(isFinal, name, names, this._makeSpan(start));
10782 }
10783 Parser.prototype.type = function(depth) {
10784 var typeRef = this.nameTypeReference();
10785 if (this._peekKind((52))) {
10786 return this.addTypeArguments(typeRef, depth);
10787 }
10788 else {
10789 return typeRef;
10790 }
10791 }
10792 Parser.prototype.type.$optional = ['depth', '(0)']
10793 Parser.prototype.get$type = function() {
10794 return this.type.bind(this);
10795 }
10796 Parser.prototype.formalParameter = function(inOptionalBlock) {
10797 var start = this._peekToken.start;
10798 var isThis = false;
10799 var isRest = false;
10800 var di = this.declaredIdentifier(false);
10801 var type = di.get$type();
10802 var name = di.get$name();
10803 if ($eq$(name)) {
10804 this._error("Formal parameter invalid", this._makeSpan(start));
10805 }
10806 var value = null;
10807 if (this._maybeEat((20))) {
10808 if (!inOptionalBlock) {
10809 this._error("default values only allowed inside [optional] section");
10810 }
10811 value = this.expression();
10812 }
10813 else if (this._peekKind((2))) {
10814 var formals = this.formalParameterList();
10815 var func = new FunctionDefinition(null, type, name, formals, null, null, nul l, this._makeSpan(start));
10816 type = new FunctionTypeReference(false, func, func.get$span());
10817 }
10818 if (inOptionalBlock && $eq$(value)) {
10819 value = this._makeLiteral(Value.fromNull(this._makeSpan(start)));
10820 }
10821 return new FormalNode(isThis, isRest, type, name, value, this._makeSpan(start) );
10822 }
10823 Parser.prototype.formalParameterList = function() {
10824 this._eatLeftParen();
10825 var formals = [];
10826 var inOptionalBlock = false;
10827 if (!this._maybeEat((3))) {
10828 if (this._maybeEat((4))) {
10829 inOptionalBlock = true;
10830 }
10831 formals.add(this.formalParameter(inOptionalBlock));
10832 while (this._maybeEat((11))) {
10833 if (this._maybeEat((4))) {
10834 if (inOptionalBlock) {
10835 this._error("already inside an optional block", this._previousToken.ge t$span());
10836 }
10837 inOptionalBlock = true;
10838 }
10839 formals.add(this.formalParameter(inOptionalBlock));
10840 }
10841 if (inOptionalBlock) {
10842 this._eat((5));
10843 }
10844 this._eat((3));
10845 }
10846 return formals;
10847 }
10848 Parser.prototype.identifierForType = function() {
10849 var $0;
10850 var tok = this._lang_next();
10851 if (!this._isIdentifier(tok.get$kind())) {
10852 this._error(("expected identifier, but found " + tok), tok.get$span());
10853 }
10854 if ((($0 = tok.get$kind()) == null ? null != ((70)) : $0 !== (70)) && tok.get$ kind() != (80)) {
10855 this._error(("" + tok + " may not be used as a type name"), tok.get$span());
10856 }
10857 return new Identifier(tok.get$text(), this._makeSpan(tok.get$start()));
10858 }
10859 Parser.prototype.identifier = function() {
10860 var tok = this._lang_next();
10861 if (!this._isIdentifier(tok.get$kind())) {
10862 this._error(("expected identifier, but found " + tok), tok.get$span());
10863 }
10864 return new Identifier(tok.get$text(), this._makeSpan(tok.get$start()));
10865 }
10866 Parser.prototype._makeFunction = function(expr, formals, body) {
10867 var name, type;
10868 if ((expr instanceof VarExpression)) {
10869 name = expr.get$name();
10870 type = null;
10871 }
10872 else if ((expr instanceof DeclaredIdentifier)) {
10873 name = expr.get$name();
10874 type = expr.get$type();
10875 if ($eq$(name)) {
10876 this._error("expected name and type", expr.get$span());
10877 }
10878 }
10879 else {
10880 this._error("bad function body", expr.get$span());
10881 }
10882 var span = new SourceSpan(expr.get$span().file, expr.get$span().start, body.ge t$span().end);
10883 var func = new FunctionDefinition(null, type, name, formals, null, null, body, span);
10884 return new LambdaExpression(func, func.get$span());
10885 }
10886 Parser.prototype._makeDeclaredIdentifier = function(e) {
10887 if ((e instanceof VarExpression)) {
10888 return new DeclaredIdentifier(null, e.get$name(), false, e.get$span());
10889 }
10890 else if ((e instanceof DeclaredIdentifier)) {
10891 return e;
10892 }
10893 else {
10894 this._error("expected declared identifier");
10895 return new DeclaredIdentifier(null, null, false, e.get$span());
10896 }
10897 }
10898 Parser.prototype._makeLabel = function(expr) {
10899 if ((expr instanceof VarExpression)) {
10900 return expr.get$name();
10901 }
10902 else {
10903 this._errorExpected("label");
10904 return null;
10905 }
10906 }
10907 // ********** Code for IncompleteSourceException **************
10908 function IncompleteSourceException(token) {
10909 this.token = token;
10910 }
10911 IncompleteSourceException.prototype.toString = function() {
10912 if (this.token.get$span() == null) return ("Unexpected " + this.token);
10913 return this.token.get$span().toMessageString(("Unexpected " + this.token));
10914 }
10915 IncompleteSourceException.prototype.toString$0 = IncompleteSourceException.proto type.toString;
10916 // ********** Code for DivertedTokenSource **************
10917 function DivertedTokenSource(tokens, parser, previousTokenizer) {
10918 this._lang_pos = (0);
10919 this.tokens = tokens;
10920 this.parser = parser;
10921 this.previousTokenizer = previousTokenizer;
10922 }
10923 DivertedTokenSource.prototype.next = function() {
10924 var token = this.tokens.$index(this._lang_pos);
10925 ++this._lang_pos;
10926 if (this._lang_pos == this.tokens.get$length()) {
10927 this.parser.tokenizer = this.previousTokenizer;
10928 }
10929 return token;
10930 }
10931 // ********** Code for Node **************
10932 function Node(span) {
10933 this.span = span;
10934 }
10935 Node.prototype.get$span = function() { return this.span; };
10936 Node.prototype.set$span = function(value) { return this.span = value; };
10937 // ********** Code for Statement **************
10938 $inherits(Statement, Node);
10939 function Statement(span) {
10940 Node.call(this, span);
10941 }
10942 // ********** Code for Definition **************
10943 $inherits(Definition, Statement);
10944 function Definition(span) {
10945 Statement.call(this, span);
10946 }
10947 Definition.prototype.get$typeParameters = function() {
10948 return null;
10949 }
10950 Definition.prototype.get$nativeType = function() {
10951 return null;
10952 }
10953 // ********** Code for Expression **************
10954 $inherits(Expression, Node);
10955 function Expression(span) {
10956 Node.call(this, span);
10957 }
10958 // ********** Code for TypeReference **************
10959 $inherits(TypeReference, Node);
10960 function TypeReference(span) {
10961 Node.call(this, span);
10962 }
10963 // ********** Code for DirectiveDefinition **************
10964 $inherits(DirectiveDefinition, Definition);
10965 function DirectiveDefinition(name, arguments, span) {
10966 this.name = name;
10967 this.arguments = arguments;
10968 Definition.call(this, span);
10969 }
10970 DirectiveDefinition.prototype.get$name = function() { return this.name; };
10971 DirectiveDefinition.prototype.set$name = function(value) { return this.name = va lue; };
10972 DirectiveDefinition.prototype.visit = function(visitor) {
10973 return visitor.visitDirectiveDefinition(this);
10974 }
10975 // ********** Code for TypeDefinition **************
10976 $inherits(TypeDefinition, Definition);
10977 function TypeDefinition(isClass, name, typeParameters, extendsTypes, implementsT ypes, nativeType, defaultType, body, span) {
10978 this.isClass = isClass;
10979 this.name = name;
10980 this.typeParameters = typeParameters;
10981 this.extendsTypes = extendsTypes;
10982 this.implementsTypes = implementsTypes;
10983 this.nativeType = nativeType;
10984 this.defaultType = defaultType;
10985 this.body = body;
10986 Definition.call(this, span);
10987 }
10988 TypeDefinition.prototype.get$isClass = function() { return this.isClass; };
10989 TypeDefinition.prototype.get$name = function() { return this.name; };
10990 TypeDefinition.prototype.set$name = function(value) { return this.name = value; };
10991 TypeDefinition.prototype.get$typeParameters = function() { return this.typeParam eters; };
10992 TypeDefinition.prototype.get$nativeType = function() { return this.nativeType; } ;
10993 TypeDefinition.prototype.get$body = function() { return this.body; };
10994 TypeDefinition.prototype.visit = function(visitor) {
10995 return visitor.visitTypeDefinition(this);
10996 }
10997 // ********** Code for FunctionTypeDefinition **************
10998 $inherits(FunctionTypeDefinition, Definition);
10999 function FunctionTypeDefinition(func, typeParameters, span) {
11000 this.func = func;
11001 this.typeParameters = typeParameters;
11002 Definition.call(this, span);
11003 }
11004 FunctionTypeDefinition.prototype.get$func = function() { return this.func; };
11005 FunctionTypeDefinition.prototype.get$typeParameters = function() { return this.t ypeParameters; };
11006 FunctionTypeDefinition.prototype.visit = function(visitor) {
11007 return visitor.visitFunctionTypeDefinition(this);
11008 }
11009 // ********** Code for VariableDefinition **************
11010 $inherits(VariableDefinition, Definition);
11011 function VariableDefinition(modifiers, type, names, values, span) {
11012 this.modifiers = modifiers;
11013 this.type = type;
11014 this.names = names;
11015 this.values = values;
11016 Definition.call(this, span);
11017 }
11018 VariableDefinition.prototype.get$type = function() { return this.type; };
11019 VariableDefinition.prototype.get$names = function() { return this.names; };
11020 VariableDefinition.prototype.set$names = function(value) { return this.names = v alue; };
11021 VariableDefinition.prototype.visit = function(visitor) {
11022 return visitor.visitVariableDefinition(this);
11023 }
11024 // ********** Code for FunctionDefinition **************
11025 $inherits(FunctionDefinition, Definition);
11026 function FunctionDefinition(modifiers, returnType, name, formals, initializers, nativeBody, body, span) {
11027 this.modifiers = modifiers;
11028 this.returnType = returnType;
11029 this.name = name;
11030 this.formals = formals;
11031 this.initializers = initializers;
11032 this.nativeBody = nativeBody;
11033 this.body = body;
11034 Definition.call(this, span);
11035 }
11036 FunctionDefinition.prototype.get$returnType = function() { return this.returnTyp e; };
11037 FunctionDefinition.prototype.set$returnType = function(value) { return this.retu rnType = value; };
11038 FunctionDefinition.prototype.get$name = function() { return this.name; };
11039 FunctionDefinition.prototype.set$name = function(value) { return this.name = val ue; };
11040 FunctionDefinition.prototype.get$initializers = function() { return this.initial izers; };
11041 FunctionDefinition.prototype.get$body = function() { return this.body; };
11042 FunctionDefinition.prototype.visit = function(visitor) {
11043 return visitor.visitFunctionDefinition(this);
11044 }
11045 // ********** Code for ReturnStatement **************
11046 $inherits(ReturnStatement, Statement);
11047 function ReturnStatement(value, span) {
11048 this.value = value;
11049 Statement.call(this, span);
11050 }
11051 ReturnStatement.prototype.get$value = function() { return this.value; };
11052 ReturnStatement.prototype.set$value = function(value) { return this.value = valu e; };
11053 ReturnStatement.prototype.visit = function(visitor) {
11054 return visitor.visitReturnStatement(this);
11055 }
11056 // ********** Code for ThrowStatement **************
11057 $inherits(ThrowStatement, Statement);
11058 function ThrowStatement(value, span) {
11059 this.value = value;
11060 Statement.call(this, span);
11061 }
11062 ThrowStatement.prototype.get$value = function() { return this.value; };
11063 ThrowStatement.prototype.set$value = function(value) { return this.value = value ; };
11064 ThrowStatement.prototype.visit = function(visitor) {
11065 return visitor.visitThrowStatement(this);
11066 }
11067 // ********** Code for AssertStatement **************
11068 $inherits(AssertStatement, Statement);
11069 function AssertStatement(test, span) {
11070 this.test = test;
11071 Statement.call(this, span);
11072 }
11073 AssertStatement.prototype.visit = function(visitor) {
11074 return visitor.visitAssertStatement(this);
11075 }
11076 // ********** Code for BreakStatement **************
11077 $inherits(BreakStatement, Statement);
11078 function BreakStatement(label, span) {
11079 this.label = label;
11080 Statement.call(this, span);
11081 }
11082 BreakStatement.prototype.get$label = function() { return this.label; };
11083 BreakStatement.prototype.visit = function(visitor) {
11084 return visitor.visitBreakStatement(this);
11085 }
11086 // ********** Code for ContinueStatement **************
11087 $inherits(ContinueStatement, Statement);
11088 function ContinueStatement(label, span) {
11089 this.label = label;
11090 Statement.call(this, span);
11091 }
11092 ContinueStatement.prototype.get$label = function() { return this.label; };
11093 ContinueStatement.prototype.visit = function(visitor) {
11094 return visitor.visitContinueStatement(this);
11095 }
11096 // ********** Code for IfStatement **************
11097 $inherits(IfStatement, Statement);
11098 function IfStatement(test, trueBranch, falseBranch, span) {
11099 this.test = test;
11100 this.trueBranch = trueBranch;
11101 this.falseBranch = falseBranch;
11102 Statement.call(this, span);
11103 }
11104 IfStatement.prototype.visit = function(visitor) {
11105 return visitor.visitIfStatement(this);
11106 }
11107 // ********** Code for WhileStatement **************
11108 $inherits(WhileStatement, Statement);
11109 function WhileStatement(test, body, span) {
11110 this.test = test;
11111 this.body = body;
11112 Statement.call(this, span);
11113 }
11114 WhileStatement.prototype.get$body = function() { return this.body; };
11115 WhileStatement.prototype.visit = function(visitor) {
11116 return visitor.visitWhileStatement(this);
11117 }
11118 // ********** Code for DoStatement **************
11119 $inherits(DoStatement, Statement);
11120 function DoStatement(body, test, span) {
11121 this.body = body;
11122 this.test = test;
11123 Statement.call(this, span);
11124 }
11125 DoStatement.prototype.get$body = function() { return this.body; };
11126 DoStatement.prototype.visit = function(visitor) {
11127 return visitor.visitDoStatement(this);
11128 }
11129 // ********** Code for ForStatement **************
11130 $inherits(ForStatement, Statement);
11131 function ForStatement(init, test, step, body, span) {
11132 this.init = init;
11133 this.test = test;
11134 this.step = step;
11135 this.body = body;
11136 Statement.call(this, span);
11137 }
11138 ForStatement.prototype.get$body = function() { return this.body; };
11139 ForStatement.prototype.visit = function(visitor) {
11140 return visitor.visitForStatement(this);
11141 }
11142 // ********** Code for ForInStatement **************
11143 $inherits(ForInStatement, Statement);
11144 function ForInStatement(item, list, body, span) {
11145 this.item = item;
11146 this.list = list;
11147 this.body = body;
11148 Statement.call(this, span);
11149 }
11150 ForInStatement.prototype.get$body = function() { return this.body; };
11151 ForInStatement.prototype.visit = function(visitor) {
11152 return visitor.visitForInStatement(this);
11153 }
11154 // ********** Code for TryStatement **************
11155 $inherits(TryStatement, Statement);
11156 function TryStatement(body, catches, finallyBlock, span) {
11157 this.body = body;
11158 this.catches = catches;
11159 this.finallyBlock = finallyBlock;
11160 Statement.call(this, span);
11161 }
11162 TryStatement.prototype.get$body = function() { return this.body; };
11163 TryStatement.prototype.visit = function(visitor) {
11164 return visitor.visitTryStatement(this);
11165 }
11166 // ********** Code for SwitchStatement **************
11167 $inherits(SwitchStatement, Statement);
11168 function SwitchStatement(test, cases, span) {
11169 this.test = test;
11170 this.cases = cases;
11171 Statement.call(this, span);
11172 }
11173 SwitchStatement.prototype.get$cases = function() { return this.cases; };
11174 SwitchStatement.prototype.visit = function(visitor) {
11175 return visitor.visitSwitchStatement(this);
11176 }
11177 // ********** Code for BlockStatement **************
11178 $inherits(BlockStatement, Statement);
11179 function BlockStatement(body, span) {
11180 this.body = body;
11181 Statement.call(this, span);
11182 }
11183 BlockStatement.prototype.get$body = function() { return this.body; };
11184 BlockStatement.prototype.visit = function(visitor) {
11185 return visitor.visitBlockStatement(this);
11186 }
11187 // ********** Code for LabeledStatement **************
11188 $inherits(LabeledStatement, Statement);
11189 function LabeledStatement(name, body, span) {
11190 this.name = name;
11191 this.body = body;
11192 Statement.call(this, span);
11193 }
11194 LabeledStatement.prototype.get$name = function() { return this.name; };
11195 LabeledStatement.prototype.set$name = function(value) { return this.name = value ; };
11196 LabeledStatement.prototype.get$body = function() { return this.body; };
11197 LabeledStatement.prototype.visit = function(visitor) {
11198 return visitor.visitLabeledStatement(this);
11199 }
11200 // ********** Code for ExpressionStatement **************
11201 $inherits(ExpressionStatement, Statement);
11202 function ExpressionStatement(body, span) {
11203 this.body = body;
11204 Statement.call(this, span);
11205 }
11206 ExpressionStatement.prototype.get$body = function() { return this.body; };
11207 ExpressionStatement.prototype.visit = function(visitor) {
11208 return visitor.visitExpressionStatement(this);
11209 }
11210 // ********** Code for EmptyStatement **************
11211 $inherits(EmptyStatement, Statement);
11212 function EmptyStatement(span) {
11213 Statement.call(this, span);
11214 }
11215 EmptyStatement.prototype.visit = function(visitor) {
11216 return visitor.visitEmptyStatement(this);
11217 }
11218 // ********** Code for DietStatement **************
11219 $inherits(DietStatement, Statement);
11220 function DietStatement(span) {
11221 Statement.call(this, span);
11222 }
11223 DietStatement.prototype.visit = function(visitor) {
11224 return visitor.visitDietStatement(this);
11225 }
11226 // ********** Code for LambdaExpression **************
11227 $inherits(LambdaExpression, Expression);
11228 function LambdaExpression(func, span) {
11229 this.func = func;
11230 Expression.call(this, span);
11231 }
11232 LambdaExpression.prototype.get$func = function() { return this.func; };
11233 LambdaExpression.prototype.visit = function(visitor) {
11234 return visitor.visitLambdaExpression(this);
11235 }
11236 // ********** Code for CallExpression **************
11237 $inherits(CallExpression, Expression);
11238 function CallExpression(target, arguments, span) {
11239 this.target = target;
11240 this.arguments = arguments;
11241 Expression.call(this, span);
11242 }
11243 CallExpression.prototype.visit = function(visitor) {
11244 return visitor.visitCallExpression$1(this);
11245 }
11246 // ********** Code for IndexExpression **************
11247 $inherits(IndexExpression, Expression);
11248 function IndexExpression(target, index, span) {
11249 this.target = target;
11250 this.index = index;
11251 Expression.call(this, span);
11252 }
11253 IndexExpression.prototype.visit = function(visitor) {
11254 return visitor.visitIndexExpression(this);
11255 }
11256 // ********** Code for BinaryExpression **************
11257 $inherits(BinaryExpression, Expression);
11258 function BinaryExpression(op, x, y, span) {
11259 this.op = op;
11260 this.x = x;
11261 this.y = y;
11262 Expression.call(this, span);
11263 }
11264 BinaryExpression.prototype.get$op = function() { return this.op; };
11265 BinaryExpression.prototype.get$x = function() { return this.x; };
11266 BinaryExpression.prototype.get$y = function() { return this.y; };
11267 BinaryExpression.prototype.visit = function(visitor) {
11268 return visitor.visitBinaryExpression$1(this);
11269 }
11270 // ********** Code for UnaryExpression **************
11271 $inherits(UnaryExpression, Expression);
11272 function UnaryExpression(op, self, span) {
11273 this.op = op;
11274 this.self = self;
11275 Expression.call(this, span);
11276 }
11277 UnaryExpression.prototype.get$op = function() { return this.op; };
11278 UnaryExpression.prototype.get$self = function() { return this.self; };
11279 UnaryExpression.prototype.visit = function(visitor) {
11280 return visitor.visitUnaryExpression(this);
11281 }
11282 // ********** Code for PostfixExpression **************
11283 $inherits(PostfixExpression, Expression);
11284 function PostfixExpression(body, op, span) {
11285 this.body = body;
11286 this.op = op;
11287 Expression.call(this, span);
11288 }
11289 PostfixExpression.prototype.get$body = function() { return this.body; };
11290 PostfixExpression.prototype.get$op = function() { return this.op; };
11291 PostfixExpression.prototype.visit = function(visitor) {
11292 return visitor.visitPostfixExpression$1(this);
11293 }
11294 // ********** Code for NewExpression **************
11295 $inherits(NewExpression, Expression);
11296 function NewExpression(isConst, type, name, arguments, span) {
11297 this.isConst = isConst;
11298 this.type = type;
11299 this.name = name;
11300 this.arguments = arguments;
11301 Expression.call(this, span);
11302 }
11303 NewExpression.prototype.get$isConst = function() { return this.isConst; };
11304 NewExpression.prototype.get$type = function() { return this.type; };
11305 NewExpression.prototype.get$name = function() { return this.name; };
11306 NewExpression.prototype.set$name = function(value) { return this.name = value; } ;
11307 NewExpression.prototype.visit = function(visitor) {
11308 return visitor.visitNewExpression(this);
11309 }
11310 // ********** Code for ListExpression **************
11311 $inherits(ListExpression, Expression);
11312 function ListExpression(isConst, itemType, values, span) {
11313 this.isConst = isConst;
11314 this.itemType = itemType;
11315 this.values = values;
11316 Expression.call(this, span);
11317 }
11318 ListExpression.prototype.get$isConst = function() { return this.isConst; };
11319 ListExpression.prototype.visit = function(visitor) {
11320 return visitor.visitListExpression(this);
11321 }
11322 // ********** Code for MapExpression **************
11323 $inherits(MapExpression, Expression);
11324 function MapExpression(isConst, keyType, valueType, items, span) {
11325 this.isConst = isConst;
11326 this.keyType = keyType;
11327 this.valueType = valueType;
11328 this.items = items;
11329 Expression.call(this, span);
11330 }
11331 MapExpression.prototype.get$isConst = function() { return this.isConst; };
11332 MapExpression.prototype.visit = function(visitor) {
11333 return visitor.visitMapExpression(this);
11334 }
11335 // ********** Code for ConditionalExpression **************
11336 $inherits(ConditionalExpression, Expression);
11337 function ConditionalExpression(test, trueBranch, falseBranch, span) {
11338 this.test = test;
11339 this.trueBranch = trueBranch;
11340 this.falseBranch = falseBranch;
11341 Expression.call(this, span);
11342 }
11343 ConditionalExpression.prototype.visit = function(visitor) {
11344 return visitor.visitConditionalExpression(this);
11345 }
11346 // ********** Code for IsExpression **************
11347 $inherits(IsExpression, Expression);
11348 function IsExpression(isTrue, x, type, span) {
11349 this.isTrue = isTrue;
11350 this.x = x;
11351 this.type = type;
11352 Expression.call(this, span);
11353 }
11354 IsExpression.prototype.get$x = function() { return this.x; };
11355 IsExpression.prototype.get$type = function() { return this.type; };
11356 IsExpression.prototype.visit = function(visitor) {
11357 return visitor.visitIsExpression(this);
11358 }
11359 // ********** Code for ParenExpression **************
11360 $inherits(ParenExpression, Expression);
11361 function ParenExpression(body, span) {
11362 this.body = body;
11363 Expression.call(this, span);
11364 }
11365 ParenExpression.prototype.get$body = function() { return this.body; };
11366 ParenExpression.prototype.visit = function(visitor) {
11367 return visitor.visitParenExpression(this);
11368 }
11369 // ********** Code for AwaitExpression **************
11370 $inherits(AwaitExpression, Expression);
11371 function AwaitExpression(body, span) {
11372 this.body = body;
11373 Expression.call(this, span);
11374 }
11375 AwaitExpression.prototype.get$body = function() { return this.body; };
11376 AwaitExpression.prototype.visit = function(visitor) {
11377 return visitor.visitAwaitExpression(this);
11378 }
11379 // ********** Code for DotExpression **************
11380 $inherits(DotExpression, Expression);
11381 function DotExpression(self, name, span) {
11382 this.self = self;
11383 this.name = name;
11384 Expression.call(this, span);
11385 }
11386 DotExpression.prototype.get$self = function() { return this.self; };
11387 DotExpression.prototype.get$name = function() { return this.name; };
11388 DotExpression.prototype.set$name = function(value) { return this.name = value; } ;
11389 DotExpression.prototype.visit = function(visitor) {
11390 return visitor.visitDotExpression(this);
11391 }
11392 // ********** Code for VarExpression **************
11393 $inherits(VarExpression, Expression);
11394 function VarExpression(name, span) {
11395 this.name = name;
11396 Expression.call(this, span);
11397 }
11398 VarExpression.prototype.get$name = function() { return this.name; };
11399 VarExpression.prototype.set$name = function(value) { return this.name = value; } ;
11400 VarExpression.prototype.visit = function(visitor) {
11401 return visitor.visitVarExpression(this);
11402 }
11403 // ********** Code for ThisExpression **************
11404 $inherits(ThisExpression, Expression);
11405 function ThisExpression(span) {
11406 Expression.call(this, span);
11407 }
11408 ThisExpression.prototype.visit = function(visitor) {
11409 return visitor.visitThisExpression(this);
11410 }
11411 // ********** Code for SuperExpression **************
11412 $inherits(SuperExpression, Expression);
11413 function SuperExpression(span) {
11414 Expression.call(this, span);
11415 }
11416 SuperExpression.prototype.visit = function(visitor) {
11417 return visitor.visitSuperExpression(this);
11418 }
11419 // ********** Code for LiteralExpression **************
11420 $inherits(LiteralExpression, Expression);
11421 function LiteralExpression(value, span) {
11422 this.value = value;
11423 Expression.call(this, span);
11424 }
11425 LiteralExpression.prototype.get$value = function() { return this.value; };
11426 LiteralExpression.prototype.set$value = function(value) { return this.value = va lue; };
11427 LiteralExpression.prototype.visit = function(visitor) {
11428 return visitor.visitLiteralExpression(this);
11429 }
11430 // ********** Code for StringConcatExpression **************
11431 $inherits(StringConcatExpression, Expression);
11432 function StringConcatExpression(strings, span) {
11433 this.strings = strings;
11434 Expression.call(this, span);
11435 }
11436 StringConcatExpression.prototype.visit = function(visitor) {
11437 return visitor.visitStringConcatExpression(this);
11438 }
11439 // ********** Code for StringInterpExpression **************
11440 $inherits(StringInterpExpression, Expression);
11441 function StringInterpExpression(pieces, span) {
11442 this.pieces = pieces;
11443 Expression.call(this, span);
11444 }
11445 StringInterpExpression.prototype.visit = function(visitor) {
11446 return visitor.visitStringInterpExpression(this);
11447 }
11448 // ********** Code for SimpleTypeReference **************
11449 $inherits(SimpleTypeReference, TypeReference);
11450 function SimpleTypeReference(type, span) {
11451 this.type = type;
11452 TypeReference.call(this, span);
11453 }
11454 SimpleTypeReference.prototype.get$type = function() { return this.type; };
11455 SimpleTypeReference.prototype.visit = function(visitor) {
11456 return visitor.visitSimpleTypeReference(this);
11457 }
11458 // ********** Code for NameTypeReference **************
11459 $inherits(NameTypeReference, TypeReference);
11460 function NameTypeReference(isFinal, name, names, span) {
11461 this.isFinal = isFinal;
11462 this.name = name;
11463 this.names = names;
11464 TypeReference.call(this, span);
11465 }
11466 NameTypeReference.prototype.get$isFinal = function() { return this.isFinal; };
11467 NameTypeReference.prototype.get$name = function() { return this.name; };
11468 NameTypeReference.prototype.set$name = function(value) { return this.name = valu e; };
11469 NameTypeReference.prototype.get$names = function() { return this.names; };
11470 NameTypeReference.prototype.set$names = function(value) { return this.names = va lue; };
11471 NameTypeReference.prototype.visit = function(visitor) {
11472 return visitor.visitNameTypeReference(this);
11473 }
11474 // ********** Code for GenericTypeReference **************
11475 $inherits(GenericTypeReference, TypeReference);
11476 function GenericTypeReference(baseType, typeArguments, depth, span) {
11477 this.baseType = baseType;
11478 this.typeArguments = typeArguments;
11479 this.depth = depth;
11480 TypeReference.call(this, span);
11481 }
11482 GenericTypeReference.prototype.get$baseType = function() { return this.baseType; };
11483 GenericTypeReference.prototype.get$typeArguments = function() { return this.type Arguments; };
11484 GenericTypeReference.prototype.get$depth = function() { return this.depth; };
11485 GenericTypeReference.prototype.visit = function(visitor) {
11486 return visitor.visitGenericTypeReference(this);
11487 }
11488 // ********** Code for FunctionTypeReference **************
11489 $inherits(FunctionTypeReference, TypeReference);
11490 function FunctionTypeReference(isFinal, func, span) {
11491 this.isFinal = isFinal;
11492 this.func = func;
11493 TypeReference.call(this, span);
11494 }
11495 FunctionTypeReference.prototype.get$isFinal = function() { return this.isFinal; };
11496 FunctionTypeReference.prototype.get$func = function() { return this.func; };
11497 FunctionTypeReference.prototype.visit = function(visitor) {
11498 return visitor.visitFunctionTypeReference(this);
11499 }
11500 // ********** Code for DefaultTypeReference **************
11501 $inherits(DefaultTypeReference, TypeReference);
11502 function DefaultTypeReference(oldFactory, baseType, typeParameters, span) {
11503 this.oldFactory = oldFactory;
11504 this.baseType = baseType;
11505 this.typeParameters = typeParameters;
11506 TypeReference.call(this, span);
11507 }
11508 DefaultTypeReference.prototype.get$baseType = function() { return this.baseType; };
11509 DefaultTypeReference.prototype.get$typeParameters = function() { return this.typ eParameters; };
11510 DefaultTypeReference.prototype.visit = function(visitor) {
11511 return visitor.visitDefaultTypeReference(this);
11512 }
11513 // ********** Code for ArgumentNode **************
11514 $inherits(ArgumentNode, Node);
11515 function ArgumentNode(label, value, span) {
11516 this.label = label;
11517 this.value = value;
11518 Node.call(this, span);
11519 }
11520 ArgumentNode.prototype.get$label = function() { return this.label; };
11521 ArgumentNode.prototype.get$value = function() { return this.value; };
11522 ArgumentNode.prototype.set$value = function(value) { return this.value = value; };
11523 ArgumentNode.prototype.visit = function(visitor) {
11524 return visitor.visitArgumentNode(this);
11525 }
11526 // ********** Code for FormalNode **************
11527 $inherits(FormalNode, Node);
11528 function FormalNode(isThis, isRest, type, name, value, span) {
11529 this.isThis = isThis;
11530 this.isRest = isRest;
11531 this.type = type;
11532 this.name = name;
11533 this.value = value;
11534 Node.call(this, span);
11535 }
11536 FormalNode.prototype.get$type = function() { return this.type; };
11537 FormalNode.prototype.get$name = function() { return this.name; };
11538 FormalNode.prototype.set$name = function(value) { return this.name = value; };
11539 FormalNode.prototype.get$value = function() { return this.value; };
11540 FormalNode.prototype.set$value = function(value) { return this.value = value; };
11541 FormalNode.prototype.visit = function(visitor) {
11542 return visitor.visitFormalNode(this);
11543 }
11544 // ********** Code for CatchNode **************
11545 $inherits(CatchNode, Node);
11546 function CatchNode(exception, trace, body, span) {
11547 this.exception = exception;
11548 this.trace = trace;
11549 this.body = body;
11550 Node.call(this, span);
11551 }
11552 CatchNode.prototype.get$exception = function() { return this.exception; };
11553 CatchNode.prototype.get$trace = function() { return this.trace; };
11554 CatchNode.prototype.get$body = function() { return this.body; };
11555 CatchNode.prototype.visit = function(visitor) {
11556 return visitor.visitCatchNode(this);
11557 }
11558 // ********** Code for CaseNode **************
11559 $inherits(CaseNode, Node);
11560 function CaseNode(label, cases, statements, span) {
11561 this.label = label;
11562 this.cases = cases;
11563 this.statements = statements;
11564 Node.call(this, span);
11565 }
11566 CaseNode.prototype.get$label = function() { return this.label; };
11567 CaseNode.prototype.get$cases = function() { return this.cases; };
11568 CaseNode.prototype.get$statements = function() { return this.statements; };
11569 CaseNode.prototype.visit = function(visitor) {
11570 return visitor.visitCaseNode(this);
11571 }
11572 // ********** Code for TypeParameter **************
11573 $inherits(TypeParameter, Node);
11574 function TypeParameter(name, extendsType, span) {
11575 this.name = name;
11576 this.extendsType = extendsType;
11577 Node.call(this, span);
11578 }
11579 TypeParameter.prototype.get$name = function() { return this.name; };
11580 TypeParameter.prototype.set$name = function(value) { return this.name = value; } ;
11581 TypeParameter.prototype.get$extendsType = function() { return this.extendsType; };
11582 TypeParameter.prototype.visit = function(visitor) {
11583 return visitor.visitTypeParameter(this);
11584 }
11585 // ********** Code for Identifier **************
11586 $inherits(Identifier, Node);
11587 function Identifier(name, span) {
11588 this.name = name;
11589 Node.call(this, span);
11590 }
11591 Identifier.prototype.get$name = function() { return this.name; };
11592 Identifier.prototype.set$name = function(value) { return this.name = value; };
11593 Identifier.prototype.visit = function(visitor) {
11594 return visitor.visitIdentifier(this);
11595 }
11596 // ********** Code for DeclaredIdentifier **************
11597 $inherits(DeclaredIdentifier, Expression);
11598 function DeclaredIdentifier(type, name, isFinal, span) {
11599 this.type = type;
11600 this.name = name;
11601 this.isFinal = isFinal;
11602 Expression.call(this, span);
11603 }
11604 DeclaredIdentifier.prototype.get$type = function() { return this.type; };
11605 DeclaredIdentifier.prototype.get$name = function() { return this.name; };
11606 DeclaredIdentifier.prototype.set$name = function(value) { return this.name = val ue; };
11607 DeclaredIdentifier.prototype.get$isFinal = function() { return this.isFinal; };
11608 DeclaredIdentifier.prototype.visit = function(visitor) {
11609 return visitor.visitDeclaredIdentifier(this);
11610 }
11611 // ********** Code for Type **************
11612 $inherits(Type, Element);
11613 function Type(name) {
11614 this.isTested = false;
11615 this.isChecked = false;
11616 this.isWritten = false;
11617 this._foundMembers = new HashMapImplementation();
11618 this.varStubs = new HashMapImplementation();
11619 Element.call(this, name, null);
11620 }
11621 Type.prototype.get$typeCheckCode = function() { return this.typeCheckCode; };
11622 Type.prototype.get$varStubs = function() { return this.varStubs; };
11623 Type.prototype.markUsed = function() {
11624
11625 }
11626 Type.prototype.get$typeMember = function() {
11627 if (this._typeMember == null) {
11628 this._typeMember = new TypeMember(this);
11629 }
11630 return this._typeMember;
11631 }
11632 Type.prototype.getMember = function(name) {
11633 return null;
11634 }
11635 Type.prototype.get$subtypes = function() {
11636 return null;
11637 }
11638 Type.prototype.get$isVar = function() {
11639 return false;
11640 }
11641 Type.prototype.get$isTop = function() {
11642 return false;
11643 }
11644 Type.prototype.get$isObject = function() {
11645 return false;
11646 }
11647 Type.prototype.get$isString = function() {
11648 return false;
11649 }
11650 Type.prototype.get$isBool = function() {
11651 return false;
11652 }
11653 Type.prototype.get$isFunction = function() {
11654 return false;
11655 }
11656 Type.prototype.get$isNum = function() {
11657 return false;
11658 }
11659 Type.prototype.get$isVoid = function() {
11660 return false;
11661 }
11662 Type.prototype.get$isNullable = function() {
11663 return true;
11664 }
11665 Type.prototype.get$isVarOrFunction = function() {
11666 return this.get$isVar() || this.get$isFunction();
11667 }
11668 Type.prototype.get$isVarOrObject = function() {
11669 return this.get$isVar() || this.get$isObject();
11670 }
11671 Type.prototype.getCallMethod = function() {
11672 return null;
11673 }
11674 Type.prototype.get$isClosed = function() {
11675 return this.get$isString() || this.get$isBool() || this.get$isNum() || this.ge t$isFunction() || this.get$isVar();
11676 }
11677 Type.prototype.get$isUsed = function() {
11678 return false;
11679 }
11680 Type.prototype.get$isGeneric = function() {
11681 return false;
11682 }
11683 Type.prototype.get$nativeType = function() {
11684 return null;
11685 }
11686 Type.prototype.get$isHiddenNativeType = function() {
11687 return (this.get$nativeType() != null && this.get$nativeType().isConstructorHi dden);
11688 }
11689 Type.prototype.get$isSingletonNative = function() {
11690 return (this.get$nativeType() != null && this.get$nativeType().isSingleton);
11691 }
11692 Type.prototype.get$isJsGlobalObject = function() {
11693 return (this.get$nativeType() != null && this.get$nativeType().isJsGlobalObjec t);
11694 }
11695 Type.prototype.get$hasTypeParams = function() {
11696 return false;
11697 }
11698 Type.prototype.get$typeofName = function() {
11699 return null;
11700 }
11701 Type.prototype.get$fullname = function() {
11702 return null != this.get$library().name ? ("" + this.get$library().name + "." + this.name) : this.name;
11703 }
11704 Type.prototype.get$members = function() {
11705 return null;
11706 }
11707 Type.prototype.get$definition = function() {
11708 return null;
11709 }
11710 Type.prototype.get$factories = function() {
11711 return null;
11712 }
11713 Type.prototype.get$typeArgsInOrder = function() {
11714 return const$0007;
11715 }
11716 Type.prototype.get$genericType = function() {
11717 return this;
11718 }
11719 Type.prototype.get$isConcreteGeneric = function() {
11720 return $ne$(this.get$genericType(), this);
11721 }
11722 Type.prototype.get$interfaces = function() {
11723 return null;
11724 }
11725 Type.prototype.get$parent = function() {
11726 return null;
11727 }
11728 Type.prototype.get$nativeName = function() {
11729 return this.get$isNative() ? this.get$definition().get$nativeType().name : thi s.get$jsname();
11730 }
11731 Type.prototype.get$avoidNativeName = function() {
11732 return this.get$isHiddenNativeType();
11733 }
11734 Type.prototype.get$hasNativeSubtypes = function() {
11735 if (this._hasNativeSubtypes == null) {
11736 this._hasNativeSubtypes = this.get$subtypes().some((function (t) {
11737 return t.get$isNative();
11738 })
11739 );
11740 }
11741 return this._hasNativeSubtypes;
11742 }
11743 Type.prototype._checkExtends = function() {
11744 var typeParams = this.get$genericType().typeParameters;
11745 if ($ne$(typeParams)) {
11746 for (var i = (0);
11747 i < typeParams.get$length(); i++) {
11748 if ($ne$(typeParams.$index(i).get$extendsType())) {
11749 this.get$typeArgsInOrder().$index(i).get$dynamic().ensureSubtypeOf(typeP arams.$index(i).get$extendsType(), typeParams.$index(i).get$span(), false);
11750 }
11751 }
11752 }
11753 if (this.get$interfaces() != null) {
11754 var $$list = this.get$interfaces();
11755 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
11756 var i = $$i.next();
11757 i._checkExtends();
11758 }
11759 }
11760 }
11761 Type.prototype._checkOverride = function(member) {
11762 var parentMember = this._getMemberInParents(member.name);
11763 if ($ne$(parentMember)) {
11764 if (!member.get$isPrivate() || $eq$(member.get$library(), parentMember.get$l ibrary())) {
11765 member.override(parentMember);
11766 }
11767 }
11768 }
11769 Type.prototype._createNotEqualMember = function() {
11770 var eq = this.get$members().$index(":eq");
11771 if (eq == null) {
11772 return;
11773 }
11774 var ne = new MethodMember(":ne", this, eq.definition);
11775 ne.set$returnType(eq.returnType);
11776 ne.set$parameters(eq.parameters);
11777 ne.set$isStatic(eq.isStatic);
11778 ne.set$isAbstract(eq.isAbstract);
11779 this.get$members().$setindex(":ne", ne);
11780 }
11781 Type.prototype._getMemberInParents = function(memberName) {
11782 if (this.get$isClass()) {
11783 if (this.get$parent() != null) {
11784 return this.get$parent().getMember(memberName);
11785 }
11786 else {
11787 return null;
11788 }
11789 }
11790 else {
11791 if (this.get$interfaces() != null && this.get$interfaces().get$length() > (0 )) {
11792 var $$list = this.get$interfaces();
11793 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
11794 var i = $$i.next();
11795 var ret = i.getMember(memberName);
11796 if ($ne$(ret)) {
11797 return ret;
11798 }
11799 }
11800 }
11801 return $globals.world.objectType.getMember(memberName);
11802 }
11803 }
11804 Type.prototype.ensureSubtypeOf = function(other, span, typeErrors) {
11805 if (!this.isSubtypeOf(other)) {
11806 var msg = ("type " + this.name + " is not a subtype of " + other.name);
11807 if (typeErrors) {
11808 $globals.world.error(msg, span);
11809 }
11810 else {
11811 $globals.world.warning(msg, span);
11812 }
11813 }
11814 }
11815 Type.prototype.needsVarCall = function(args) {
11816 if (this.get$isVarOrFunction()) {
11817 return true;
11818 }
11819 var call = this.getCallMethod();
11820 if ($ne$(call)) {
11821 if (args.get$length() != call.get$parameters().get$length() || !call.namesIn Order(args)) {
11822 return true;
11823 }
11824 }
11825 return false;
11826 }
11827 Type.prototype.get$needsVarCall = function() {
11828 return this.needsVarCall.bind(this);
11829 }
11830 Type.union = function(x, y) {
11831 if ($eq$(x, y)) return x;
11832 if (x.get$isNum() && y.get$isNum()) return $globals.world.numType;
11833 if (x.get$isString() && y.get$isString()) return $globals.world.stringType;
11834 return $globals.world.varType;
11835 }
11836 Type.prototype.isAssignable = function(other) {
11837 return this.isSubtypeOf(other) || other.isSubtypeOf(this);
11838 }
11839 Type.prototype._isDirectSupertypeOf = function(other) {
11840 var $this = this; // closure support
11841 if (other.get$isClass()) {
11842 return $eq$(other.get$parent(), this) || this.get$isObject() && other.get$pa rent() == null;
11843 }
11844 else {
11845 if (other.get$interfaces() == null || other.get$interfaces().isEmpty()) {
11846 return this.get$isObject();
11847 }
11848 else {
11849 return other.get$interfaces().some((function (i) {
11850 return $eq$(i, $this);
11851 })
11852 );
11853 }
11854 }
11855 }
11856 Type.prototype.isSubtypeOf = function(other) {
11857 var $0;
11858 if ($eq$(this, other)) return true;
11859 if (this.get$isVar() || other.get$isVar()) return true;
11860 if (other._isDirectSupertypeOf(this)) return true;
11861 var call = this.getCallMethod();
11862 var otherCall = other.getCallMethod();
11863 if ($ne$(call) && $ne$(otherCall)) {
11864 return Type._isFunctionSubtypeOf(call, otherCall);
11865 }
11866 if ((($0 = this.get$genericType()) == null ? null == (other.get$genericType()) : $0 === other.get$genericType())) {
11867 for (var i = (0);
11868 i < this.get$typeArgsInOrder().get$length(); i++) {
11869 if (!this.get$typeArgsInOrder().$index(i).get$dynamic().isSubtypeOf(other. get$typeArgsInOrder().$index(i))) {
11870 return false;
11871 }
11872 }
11873 return true;
11874 }
11875 if (this.get$parent() != null && this.get$parent().isSubtypeOf(other)) {
11876 return true;
11877 }
11878 if (this.get$interfaces() != null && this.get$interfaces().some((function (i) {
11879 return i.isSubtypeOf(other);
11880 })
11881 )) {
11882 return true;
11883 }
11884 return false;
11885 }
11886 Type.prototype.hashCode = function() {
11887 var libraryCode = this.get$library() == null ? (1) : this.get$library().hashCo de();
11888 var nameCode = this.name == null ? (1) : this.name.hashCode();
11889 return $bit_xor$(($shl$(libraryCode, (4))), nameCode);
11890 }
11891 Type.prototype.$eq = function(other) {
11892 return (other instanceof Type) && $eq$(other.get$name(), this.name) && $eq$(th is.get$library(), other.get$library());
11893 }
11894 Type._isFunctionSubtypeOf = function(t, s) {
11895 if (!s.returnType.get$isVoid() && !s.returnType.isAssignable(t.returnType)) {
11896 return false;
11897 }
11898 var tp = t.parameters;
11899 var sp = s.parameters;
11900 if (tp.get$length() < sp.get$length()) return false;
11901 for (var i = (0);
11902 i < sp.get$length(); i++) {
11903 if ($ne$(tp.$index(i).get$isOptional(), sp.$index(i).get$isOptional())) retu rn false;
11904 if (tp.$index(i).get$isOptional() && $ne$(tp.$index(i).get$name(), sp.$index (i).get$name())) return false;
11905 if (!tp.$index(i).get$type().isAssignable(sp.$index(i).get$type())) return f alse;
11906 }
11907 if (tp.get$length() > sp.get$length() && !tp.$index(sp.get$length()).get$isOpt ional()) return false;
11908 return true;
11909 }
11910 // ********** Code for ParameterType **************
11911 $inherits(ParameterType, Type);
11912 function ParameterType(name, typeParameter) {
11913 this.typeParameter = typeParameter;
11914 Type.call(this, name);
11915 }
11916 ParameterType.prototype.get$typeParameter = function() { return this.typeParamet er; };
11917 ParameterType.prototype.get$extendsType = function() { return this.extendsType; };
11918 ParameterType.prototype.get$isClass = function() {
11919 return false;
11920 }
11921 ParameterType.prototype.get$library = function() {
11922 return null;
11923 }
11924 ParameterType.prototype.get$span = function() {
11925 return this.typeParameter.span;
11926 }
11927 ParameterType.prototype.get$constructors = function() {
11928 $globals.world.internalError("no constructors on type parameters yet");
11929 }
11930 ParameterType.prototype.getCallMethod = function() {
11931 return this.extendsType.getCallMethod();
11932 }
11933 ParameterType.prototype.genMethod = function(method) {
11934 this.extendsType.genMethod(method);
11935 }
11936 ParameterType.prototype.isSubtypeOf = function(other) {
11937 return true;
11938 }
11939 ParameterType.prototype.getConstructor = function(constructorName) {
11940 $globals.world.internalError("no constructors on type parameters yet");
11941 }
11942 ParameterType.prototype.getOrMakeConcreteType = function(typeArgs) {
11943 $globals.world.internalError("no concrete types of type parameters yet", this. get$span());
11944 }
11945 ParameterType.prototype.addDirectSubtype = function(type) {
11946 $globals.world.internalError("no subtypes of type parameters yet", this.get$sp an());
11947 }
11948 ParameterType.prototype.resolve = function() {
11949 if (this.typeParameter.extendsType != null) {
11950 this.extendsType = this.get$enclosingElement().resolveType(this.typeParamete r.extendsType, true, true);
11951 }
11952 else {
11953 this.extendsType = $globals.world.objectType;
11954 }
11955 }
11956 // ********** Code for NonNullableType **************
11957 $inherits(NonNullableType, Type);
11958 function NonNullableType(type) {
11959 this.type = type;
11960 Type.call(this, type.name);
11961 }
11962 NonNullableType.prototype.get$type = function() { return this.type; };
11963 NonNullableType.prototype.get$isNullable = function() {
11964 return false;
11965 }
11966 NonNullableType.prototype.get$isBool = function() {
11967 return this.type.get$isBool();
11968 }
11969 NonNullableType.prototype.get$isUsed = function() {
11970 return false;
11971 }
11972 NonNullableType.prototype.isSubtypeOf = function(other) {
11973 return $eq$(this, other) || $eq$(this.type, other) || this.type.isSubtypeOf(ot her);
11974 }
11975 NonNullableType.prototype.resolveType = function(node, isRequired, allowTypePara ms) {
11976 return this.type.resolveType(node, isRequired, allowTypeParams);
11977 }
11978 NonNullableType.prototype.addDirectSubtype = function(subtype) {
11979 this.type.addDirectSubtype(subtype);
11980 }
11981 NonNullableType.prototype.markUsed = function() {
11982 this.type.markUsed();
11983 }
11984 NonNullableType.prototype.genMethod = function(method) {
11985 this.type.genMethod(method);
11986 }
11987 NonNullableType.prototype.get$span = function() {
11988 return this.type.get$span();
11989 }
11990 NonNullableType.prototype.getMember = function(name) {
11991 return this.type.getMember(name);
11992 }
11993 NonNullableType.prototype.getConstructor = function(name) {
11994 return this.type.getConstructor(name);
11995 }
11996 NonNullableType.prototype.getOrMakeConcreteType = function(typeArgs) {
11997 return this.type.getOrMakeConcreteType(typeArgs);
11998 }
11999 NonNullableType.prototype.get$constructors = function() {
12000 return this.type.get$constructors();
12001 }
12002 NonNullableType.prototype.get$isClass = function() {
12003 return this.type.get$isClass();
12004 }
12005 NonNullableType.prototype.get$library = function() {
12006 return this.type.get$library();
12007 }
12008 NonNullableType.prototype.getCallMethod = function() {
12009 return this.type.getCallMethod();
12010 }
12011 NonNullableType.prototype.get$isGeneric = function() {
12012 return this.type.get$isGeneric();
12013 }
12014 NonNullableType.prototype.get$hasTypeParams = function() {
12015 return this.type.get$hasTypeParams();
12016 }
12017 NonNullableType.prototype.get$typeofName = function() {
12018 return this.type.get$typeofName();
12019 }
12020 NonNullableType.prototype.get$jsname = function() {
12021 return this.type.get$jsname();
12022 }
12023 NonNullableType.prototype.get$members = function() {
12024 return this.type.get$members();
12025 }
12026 NonNullableType.prototype.get$definition = function() {
12027 return this.type.get$definition();
12028 }
12029 NonNullableType.prototype.get$factories = function() {
12030 return this.type.get$factories();
12031 }
12032 NonNullableType.prototype.get$typeArgsInOrder = function() {
12033 return this.type.get$typeArgsInOrder();
12034 }
12035 NonNullableType.prototype.get$genericType = function() {
12036 return this.type.get$genericType();
12037 }
12038 NonNullableType.prototype.get$interfaces = function() {
12039 return this.type.get$interfaces();
12040 }
12041 NonNullableType.prototype.get$parent = function() {
12042 return this.type.get$parent();
12043 }
12044 NonNullableType.prototype.get$isNative = function() {
12045 return this.type.get$isNative();
12046 }
12047 // ********** Code for DefinedType **************
12048 $inherits(DefinedType, Type);
12049 function DefinedType(name, library, definition, isClass) {
12050 this.isUsed = false;
12051 this.isNative = false;
12052 this.library = library;
12053 this.isClass = isClass;
12054 this.directSubtypes = new HashSetImplementation_Type();
12055 this.constructors = new HashMapImplementation();
12056 this.members = new HashMapImplementation();
12057 this.factories = new FactoryMap();
12058 Type.call(this, name);
12059 this.setDefinition(definition);
12060 }
12061 DefinedType.prototype.get$definition = function() { return this.definition; };
12062 DefinedType.prototype.get$library = function() { return this.library; };
12063 DefinedType.prototype.get$isClass = function() { return this.isClass; };
12064 DefinedType.prototype.get$parent = function() {
12065 return this._parent;
12066 }
12067 DefinedType.prototype.set$parent = function(p) {
12068 this._parent = p;
12069 }
12070 DefinedType.prototype.get$interfaces = function() { return this.interfaces; };
12071 DefinedType.prototype.set$interfaces = function(value) { return this.interfaces = value; };
12072 DefinedType.prototype.get$directSubtypes = function() { return this.directSubtyp es; };
12073 DefinedType.prototype.get$typeParameters = function() { return this.typeParamete rs; };
12074 DefinedType.prototype.get$typeArgsInOrder = function() { return this.typeArgsInO rder; };
12075 DefinedType.prototype.set$typeArgsInOrder = function(value) { return this.typeAr gsInOrder = value; };
12076 DefinedType.prototype.get$constructors = function() { return this.constructors; };
12077 DefinedType.prototype.get$members = function() { return this.members; };
12078 DefinedType.prototype.get$factories = function() { return this.factories; };
12079 DefinedType.prototype.get$_concreteTypes = function() { return this._concreteTyp es; };
12080 DefinedType.prototype.get$isUsed = function() { return this.isUsed; };
12081 DefinedType.prototype.get$isNative = function() { return this.isNative; };
12082 DefinedType.prototype.set$baseGenericType = function(value) { return this.baseGe nericType = value; };
12083 DefinedType.prototype.get$genericType = function() {
12084 return null == this.baseGenericType ? this : this.baseGenericType;
12085 }
12086 DefinedType.prototype.setDefinition = function(def) {
12087 this.definition = def;
12088 if ((this.definition instanceof TypeDefinition) && this.definition.get$nativeT ype() != null) {
12089 this.isNative = true;
12090 }
12091 if (this.definition != null && $ne$(this.definition.get$typeParameters())) {
12092 this._concreteTypes = new HashMapImplementation();
12093 this.typeParameters = this.definition.get$typeParameters();
12094 this.typeArgsInOrder = new Array(this.typeParameters.get$length());
12095 for (var i = (0);
12096 i < this.typeArgsInOrder.get$length(); i++) {
12097 this.typeArgsInOrder.$setindex(i, $globals.world.varType);
12098 }
12099 }
12100 else {
12101 this.typeArgsInOrder = const$0007;
12102 }
12103 }
12104 DefinedType.prototype.get$nativeType = function() {
12105 return (this.definition != null ? this.definition.get$nativeType() : null);
12106 }
12107 DefinedType.prototype.get$isVar = function() {
12108 return $eq$(this, $globals.world.varType);
12109 }
12110 DefinedType.prototype.get$isVoid = function() {
12111 return $eq$(this, $globals.world.voidType);
12112 }
12113 DefinedType.prototype.get$isTop = function() {
12114 return this.name == null;
12115 }
12116 DefinedType.prototype.get$isObject = function() {
12117 return $eq$(this, $globals.world.objectType);
12118 }
12119 DefinedType.prototype.get$isString = function() {
12120 return $eq$(this, $globals.world.stringType) || $eq$(this, $globals.world.stri ngImplType);
12121 }
12122 DefinedType.prototype.get$isBool = function() {
12123 return $eq$(this, $globals.world.boolType);
12124 }
12125 DefinedType.prototype.get$isFunction = function() {
12126 return $eq$(this, $globals.world.functionType) || $eq$(this, $globals.world.fu nctionImplType);
12127 }
12128 DefinedType.prototype.get$isGeneric = function() {
12129 return this.typeParameters != null;
12130 }
12131 DefinedType.prototype.get$span = function() {
12132 return this.definition == null ? null : this.definition.span;
12133 }
12134 DefinedType.prototype.get$typeofName = function() {
12135 if (!this.library.get$isCore()) return null;
12136 if (this.get$isBool()) return "boolean";
12137 else if (this.get$isNum()) return "number";
12138 else if (this.get$isString()) return "string";
12139 else if (this.get$isFunction()) return "function";
12140 else return null;
12141 }
12142 DefinedType.prototype.get$isNum = function() {
12143 return $eq$(this, $globals.world.numType) || $eq$(this, $globals.world.intType ) || $eq$(this, $globals.world.doubleType) || $eq$(this, $globals.world.numImplT ype);
12144 }
12145 DefinedType.prototype.getCallMethod = function() {
12146 return this.get$genericType().members.$index(":call");
12147 }
12148 DefinedType.prototype.getAllMembers = function() {
12149 return HashMapImplementation.HashMapImplementation$from$factory(this.members);
12150 }
12151 DefinedType.prototype.markUsed = function() {
12152 if (this.isUsed) return;
12153 this.isUsed = true;
12154 this._checkExtends();
12155 if (this._lazyGenMethods != null) {
12156 var $$list = orderValuesByKeys(this._lazyGenMethods);
12157 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12158 var method = $$i.next();
12159 $globals.world.gen.genMethod(method);
12160 }
12161 this._lazyGenMethods = null;
12162 }
12163 if (this.get$parent() != null) this.get$parent().markUsed();
12164 }
12165 DefinedType.prototype.genMethod = function(method) {
12166 if (this.isUsed || this.baseGenericType != null) {
12167 $globals.world.gen.genMethod(method);
12168 }
12169 else if (this.isClass) {
12170 if (this._lazyGenMethods == null) this._lazyGenMethods = new HashMapImplemen tation();
12171 this._lazyGenMethods.$setindex(method.name, method);
12172 }
12173 }
12174 DefinedType.prototype._resolveInterfaces = function(types) {
12175 if (types == null) return [];
12176 var interfaces = [];
12177 for (var $$i = types.iterator(); $$i.hasNext(); ) {
12178 var type = $$i.next();
12179 var resolvedInterface = this.resolveType(type, true, true);
12180 if (resolvedInterface.get$isClosed() && !(this.library.get$isCore() || this. library.get$isCoreImpl())) {
12181 $globals.world.error((("cannot implement \"" + resolvedInterface.get$name( ) + "\": ") + "only native implementation allowed"), type.get$span());
12182 }
12183 resolvedInterface.addDirectSubtype(this);
12184 interfaces.add(resolvedInterface);
12185 }
12186 return interfaces;
12187 }
12188 DefinedType.prototype.addDirectSubtype = function(type) {
12189 this.directSubtypes.add(type);
12190 if (this.baseGenericType != null) {
12191 this.baseGenericType.addDirectSubtype(type);
12192 }
12193 }
12194 DefinedType.prototype.get$subtypes = function() {
12195 if (this._subtypes == null) {
12196 this._subtypes = new HashSetImplementation_Type();
12197 var $$list = this.directSubtypes;
12198 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12199 var st = $$i.next();
12200 this._subtypes.add(st);
12201 this._subtypes.addAll(st.get$subtypes());
12202 }
12203 }
12204 return this._subtypes;
12205 }
12206 DefinedType.prototype._cycleInClassExtends = function() {
12207 var seen = new HashSetImplementation();
12208 seen.add(this);
12209 var ancestor = this.get$parent();
12210 while ($ne$(ancestor)) {
12211 if ((null == ancestor ? null == (this) : ancestor === this)) {
12212 return true;
12213 }
12214 if (seen.contains$1(ancestor)) {
12215 return false;
12216 }
12217 seen.add(ancestor);
12218 ancestor = ancestor.get$parent();
12219 }
12220 return false;
12221 }
12222 DefinedType.prototype._cycleInInterfaceExtends = function() {
12223 var $this = this; // closure support
12224 var seen = new HashSetImplementation();
12225 seen.add(this);
12226 function _helper(ancestor) {
12227 if ($eq$(ancestor)) return false;
12228 if ((null == ancestor ? null == ($this) : ancestor === $this)) return true;
12229 if (seen.contains$1(ancestor)) {
12230 return false;
12231 }
12232 seen.add(ancestor);
12233 if (ancestor.get$interfaces() != null) {
12234 var $$list = ancestor.get$interfaces();
12235 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12236 var parent = $$i.next();
12237 if (_helper(parent)) return true;
12238 }
12239 }
12240 return false;
12241 }
12242 for (var i = (0);
12243 i < this.interfaces.get$length(); i++) {
12244 if (_helper(this.interfaces.$index(i))) return i;
12245 }
12246 return (-1);
12247 }
12248 DefinedType.prototype.resolve = function() {
12249 if ((this.definition instanceof TypeDefinition)) {
12250 var typeDef = this.definition;
12251 if (this.isClass) {
12252 if (typeDef.extendsTypes != null && typeDef.extendsTypes.get$length() > (0 )) {
12253 if (typeDef.extendsTypes.get$length() > (1)) {
12254 $globals.world.error("more than one base class", typeDef.extendsTypes. $index((1)).span);
12255 }
12256 var extendsTypeRef = typeDef.extendsTypes.$index((0));
12257 if ((extendsTypeRef instanceof GenericTypeReference)) {
12258 var g = extendsTypeRef;
12259 this.set$parent(this.resolveType(g.baseType, true, true));
12260 }
12261 this.set$parent(this.resolveType(extendsTypeRef, true, true));
12262 if (!this.get$parent().get$isClass()) {
12263 $globals.world.error("class may not extend an interface - use implemen ts", typeDef.extendsTypes.$index((0)).span);
12264 }
12265 this.get$parent().addDirectSubtype(this);
12266 if (this._cycleInClassExtends()) {
12267 $globals.world.error(("class \"" + this.name + "\" has a cycle in its inheritance chain"), extendsTypeRef.get$span());
12268 }
12269 }
12270 else {
12271 if (!this.get$isObject()) {
12272 this.set$parent($globals.world.objectType);
12273 this.get$parent().addDirectSubtype(this);
12274 }
12275 }
12276 this.interfaces = this._resolveInterfaces(typeDef.implementsTypes);
12277 if (typeDef.defaultType != null) {
12278 $globals.world.error("default not allowed on classes", typeDef.defaultTy pe.span);
12279 }
12280 }
12281 else {
12282 if (typeDef.implementsTypes != null && typeDef.implementsTypes.get$length( ) > (0)) {
12283 $globals.world.error("implements not allowed on interfaces (use extends) ", typeDef.implementsTypes.$index((0)).span);
12284 }
12285 this.interfaces = this._resolveInterfaces(typeDef.extendsTypes);
12286 var res = this._cycleInInterfaceExtends();
12287 if ($gte$(res, (0))) {
12288 $globals.world.error(("interface \"" + this.name + "\" has a cycle in it s inheritance chain"), typeDef.extendsTypes.$index(res).span);
12289 }
12290 if (typeDef.defaultType != null) {
12291 this.defaultType = this.resolveType(typeDef.defaultType.baseType, true, true);
12292 if (this.defaultType == null) {
12293 $globals.world.warning("unresolved default class", typeDef.defaultType .span);
12294 }
12295 else {
12296 if (this.baseGenericType != null) {
12297 if (!this.defaultType.get$isGeneric()) {
12298 $globals.world.error("default type of generic interface must be ge neric", typeDef.defaultType.span);
12299 }
12300 this.defaultType = this.defaultType.getOrMakeConcreteType(this.typeA rgsInOrder);
12301 }
12302 }
12303 }
12304 }
12305 }
12306 else if ((this.definition instanceof FunctionTypeDefinition)) {
12307 this.interfaces = [$globals.world.functionType];
12308 }
12309 this._resolveTypeParams(this.typeParameters);
12310 if (this.get$isObject()) this._createNotEqualMember();
12311 if ($ne$(this.baseGenericType, $globals.world.listFactoryType)) $globals.world ._addType(this);
12312 var $$list = this.constructors.getValues();
12313 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12314 var c = $$i.next();
12315 c.resolve();
12316 }
12317 var $$list = this.members.getValues();
12318 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12319 var m = $$i.next();
12320 m.resolve();
12321 }
12322 this.factories.forEach((function (f) {
12323 return f.resolve();
12324 })
12325 );
12326 if (this.get$isJsGlobalObject()) {
12327 var $$list = this.members.getValues();
12328 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
12329 var m = $$i.next();
12330 if (!m.get$isStatic()) $globals.world._addTopName(new ExistingJsGlobal(m.g et$name(), m));
12331 }
12332 }
12333 }
12334 DefinedType.prototype._resolveTypeParams = function(params) {
12335 if (params == null) return;
12336 for (var $$i = params.iterator(); $$i.hasNext(); ) {
12337 var tp = $$i.next();
12338 tp.set$enclosingElement(this);
12339 tp.resolve();
12340 }
12341 }
12342 DefinedType.prototype.addMethod = function(methodName, definition) {
12343 if (methodName == null) methodName = definition.name.name;
12344 var method = new MethodMember(methodName, this, definition);
12345 if (method.get$isConstructor()) {
12346 if (this.constructors.containsKey(method.get$constructorName())) {
12347 $globals.world.error(("duplicate constructor definition of " + method.get$ name()), definition.span);
12348 return;
12349 }
12350 this.constructors.$setindex(method.get$constructorName(), method);
12351 return;
12352 }
12353 if (definition.modifiers != null && definition.modifiers.get$length() == (1) & & definition.modifiers.$index((0)).kind == (74)) {
12354 if (this.factories.getFactory(method.get$constructorName(), method.get$name( )) != null) {
12355 $globals.world.error(("duplicate factory definition of \"" + method.get$na me() + "\""), definition.span);
12356 return;
12357 }
12358 this.factories.addFactory(method.get$constructorName(), method.get$name(), m ethod);
12359 return;
12360 }
12361 if (methodName.startsWith("get:") || methodName.startsWith("set:")) {
12362 var propName = methodName.substring((4));
12363 var prop = this.members.$index(propName);
12364 if ($eq$(prop)) {
12365 prop = new PropertyMember(propName, this);
12366 this.members.$setindex(propName, prop);
12367 }
12368 if (!(prop instanceof PropertyMember)) {
12369 $globals.world.error(("property conflicts with field \"" + propName + "\"" ), definition.span);
12370 return;
12371 }
12372 if (methodName[(0)] == "g") {
12373 if (prop.get$getter() != null) {
12374 $globals.world.error(("duplicate getter definition for \"" + propName + "\""), definition.span);
12375 }
12376 prop.set$getter(method);
12377 }
12378 else {
12379 if (prop.get$setter() != null) {
12380 $globals.world.error(("duplicate setter definition for \"" + propName + "\""), definition.span);
12381 }
12382 prop.set$setter(method);
12383 }
12384 return;
12385 }
12386 if (this.members.containsKey(methodName)) {
12387 $globals.world.error(("duplicate method definition of \"" + method.get$name( ) + "\""), definition.span);
12388 return;
12389 }
12390 this.members.$setindex(methodName, method);
12391 }
12392 DefinedType.prototype.addField = function(definition) {
12393 for (var i = (0);
12394 i < definition.names.get$length(); i++) {
12395 var name = definition.names.$index(i).name;
12396 if (this.members.containsKey(name)) {
12397 $globals.world.error(("duplicate field definition of \"" + name + "\""), d efinition.span);
12398 return;
12399 }
12400 var value = null;
12401 if (definition.values != null) {
12402 value = definition.values.$index(i);
12403 }
12404 var field = new FieldMember(name, this, definition, value, this.isNative);
12405 this.members.$setindex(name, field);
12406 }
12407 }
12408 DefinedType.prototype.getFactory = function(type, constructorName) {
12409 if (this.baseGenericType != null) {
12410 var rr = this.baseGenericType.get$factories().getFactory(type.get$genericTyp e().name, constructorName);
12411 if ($ne$(rr)) {
12412 $globals.world.info(("need to remap factory on " + this.name + " from " + rr.get$declaringType().name));
12413 return rr;
12414 }
12415 else {
12416 var ret = this.getConstructor(constructorName);
12417 return ret;
12418 }
12419 }
12420 var ret = this.factories.getFactory(type.get$genericType().name, constructorNa me);
12421 if ($ne$(ret)) return ret;
12422 ret = this.factories.getFactory(this.name, constructorName);
12423 if ($ne$(ret)) return ret;
12424 ret = this.constructors.$index(constructorName);
12425 if ($ne$(ret)) return ret;
12426 return this._tryCreateDefaultConstructor(constructorName);
12427 }
12428 DefinedType.prototype.getConstructor = function(constructorName) {
12429 if (this.baseGenericType != null) {
12430 var rr = this.constructors.$index(constructorName);
12431 if ($ne$(rr)) return rr;
12432 rr = this.baseGenericType.get$constructors().$index(constructorName);
12433 if ($ne$(rr)) {
12434 if (this.defaultType != null) {
12435 var ret = this.defaultType.getFactory(this, constructorName);
12436 return ret;
12437 }
12438 }
12439 else {
12440 rr = this.baseGenericType.get$factories().getFactory(this.baseGenericType. name, constructorName);
12441 }
12442 if ($eq$(rr)) {
12443 rr = this.baseGenericType.get$dynamic()._tryCreateDefaultConstructor(const ructorName);
12444 }
12445 if ($eq$(rr)) return null;
12446 var rr1 = rr.makeConcrete(this);
12447 rr1.resolve();
12448 this.constructors.$setindex(constructorName, rr1);
12449 return rr1;
12450 }
12451 var ret = this.constructors.$index(constructorName);
12452 if ($ne$(ret)) {
12453 if (this.defaultType != null) {
12454 return this.defaultType.getFactory(this, constructorName);
12455 }
12456 return ret;
12457 }
12458 ret = this.factories.getFactory(this.name, constructorName);
12459 if ($ne$(ret)) return ret;
12460 return this._tryCreateDefaultConstructor(constructorName);
12461 }
12462 DefinedType.prototype._tryCreateDefaultConstructor = function(name) {
12463 if (name == "" && this.definition != null && this.isClass && this.constructors .get$length() == (0)) {
12464 var span = this.definition.span;
12465 var inits = null, native_ = null, body = null;
12466 if (this.isNative) {
12467 native_ = "";
12468 inits = null;
12469 }
12470 else {
12471 body = null;
12472 inits = [new CallExpression(new SuperExpression(span), [], span)];
12473 }
12474 var typeDef = this.definition;
12475 var c = new FunctionDefinition(null, null, typeDef.name, [], inits, native_, body, span);
12476 this.addMethod(null, c);
12477 this.constructors.$index("").resolve();
12478 return this.constructors.$index("");
12479 }
12480 return null;
12481 }
12482 DefinedType.prototype.getMember = function(memberName) {
12483 var member = this._foundMembers.$index(memberName);
12484 if (member != null) return member;
12485 if (this.baseGenericType != null) {
12486 member = this.baseGenericType.getMember(memberName);
12487 if (member == null) return null;
12488 if (member.get$isStatic() || $ne$(member.declaringType, this.baseGenericType )) {
12489 this._foundMembers.$setindex(memberName, member);
12490 return member;
12491 }
12492 var rr = member.makeConcrete(this);
12493 if (null != member.get$definition() || (member instanceof PropertyMember)) {
12494 rr.resolve();
12495 }
12496 else {
12497 $globals.world.info(("no definition for " + member.name + " on " + this.na me));
12498 }
12499 this.members.$setindex(memberName, rr);
12500 this._foundMembers.$setindex(memberName, rr);
12501 return rr;
12502 }
12503 member = this.members.$index(memberName);
12504 if (member != null) {
12505 this._checkOverride(member);
12506 this._foundMembers.$setindex(memberName, member);
12507 return member;
12508 }
12509 if (this.get$isTop()) {
12510 var libType = this.library.findTypeByName(memberName);
12511 if ($ne$(libType)) {
12512 member = libType.get$typeMember();
12513 this._foundMembers.$setindex(memberName, member);
12514 return member;
12515 }
12516 }
12517 member = this._getMemberInParents(memberName);
12518 this._foundMembers.$setindex(memberName, member);
12519 return member;
12520 }
12521 DefinedType.prototype.getOrMakeConcreteType = function(typeArgs) {
12522 var jsnames = [];
12523 var names = [];
12524 var typeMap = new HashMapImplementation();
12525 var allVar = true;
12526 for (var i = (0);
12527 i < typeArgs.get$length(); i++) {
12528 var typeArg = typeArgs.$index(i);
12529 if ((typeArg instanceof ParameterType)) {
12530 typeArg = $globals.world.varType;
12531 typeArgs.$setindex(i, typeArg);
12532 }
12533 if (!typeArg.get$isVar()) allVar = false;
12534 var paramName = this.typeParameters.$index(i).name;
12535 typeMap.$setindex(paramName, typeArg);
12536 names.add(typeArg.get$fullname());
12537 jsnames.add(typeArg.get$jsname());
12538 }
12539 if (allVar) return this;
12540 var jsname = ("" + this.get$jsname() + "_" + Strings.join(jsnames, "$"));
12541 var simpleName = ("" + this.name + "<" + Strings.join(names, ", ") + ">");
12542 var ret = this._concreteTypes.$index(simpleName);
12543 if ($eq$(ret)) {
12544 ret = new DefinedType(simpleName, this.library, this.definition, this.isClas s);
12545 ret.set$baseGenericType(this);
12546 ret.set$typeArgsInOrder(typeArgs);
12547 ret.set$_jsname(jsname);
12548 this._concreteTypes.$setindex(simpleName, ret);
12549 ret.resolve();
12550 }
12551 return ret;
12552 }
12553 DefinedType.prototype.getCallStub = function(args) {
12554 var name = _getCallStubName("call", args);
12555 var stub = this.varStubs.$index(name);
12556 if ($eq$(stub)) {
12557 stub = new VarFunctionStub(name, args);
12558 this.varStubs.$setindex(name, stub);
12559 }
12560 return stub;
12561 }
12562 // ********** Code for NativeType **************
12563 function NativeType(name) {
12564 this.isConstructorHidden = false;
12565 this.isJsGlobalObject = false;
12566 this.isSingleton = false;
12567 this.name = name;
12568 while (true) {
12569 if (this.name.startsWith("@")) {
12570 this.name = this.name.substring((1));
12571 this.isJsGlobalObject = true;
12572 }
12573 else if (this.name.startsWith("*")) {
12574 this.name = this.name.substring((1));
12575 this.isConstructorHidden = true;
12576 }
12577 else {
12578 break;
12579 }
12580 }
12581 if (this.name.startsWith("=")) {
12582 this.name = this.name.substring((1));
12583 this.isSingleton = true;
12584 }
12585 }
12586 NativeType.prototype.get$name = function() { return this.name; };
12587 NativeType.prototype.set$name = function(value) { return this.name = value; };
12588 // ********** Code for _SharedBackingMap **************
12589 $inherits(_SharedBackingMap, HashMapImplementation);
12590 function _SharedBackingMap() {
12591 this.shared = (0);
12592 HashMapImplementation.call(this);
12593 }
12594 _SharedBackingMap._SharedBackingMap$from$factory = function(other) {
12595 var result = new _SharedBackingMap();
12596 other.forEach((function (k, v) {
12597 result.$setindex(k, v);
12598 })
12599 );
12600 return result;
12601 }
12602 // ********** Code for _SharedBackingMap_dart_core_String$VariableValue ******** ******
12603 $inherits(_SharedBackingMap_dart_core_String$VariableValue, _SharedBackingMap);
12604 function _SharedBackingMap_dart_core_String$VariableValue() {
12605 this.shared = (0);
12606 HashMapImplementation_dart_core_String$VariableValue.call(this);
12607 }
12608 // ********** Code for CopyOnWriteMap **************
12609 CopyOnWriteMap._wrap$ctor = function(_map) {
12610 this._lang_map = _map;
12611 }
12612 CopyOnWriteMap._wrap$ctor.prototype = CopyOnWriteMap.prototype;
12613 function CopyOnWriteMap() {}
12614 CopyOnWriteMap.prototype.is$Map = function(){return true};
12615 CopyOnWriteMap.prototype.clone = function() {
12616 var $0;
12617 ($0 = this._lang_map).shared = $0.shared + (1);
12618 return new CopyOnWriteMap._wrap$ctor(this._lang_map);
12619 }
12620 CopyOnWriteMap.prototype._ensureWritable = function() {
12621 var $0;
12622 if (this._lang_map.shared > (0)) {
12623 ($0 = this._lang_map).shared = $0.shared - (1);
12624 this._lang_map = _SharedBackingMap._SharedBackingMap$from$factory(this._lang _map);
12625 }
12626 }
12627 CopyOnWriteMap.prototype.$setindex = function(key, value) {
12628 this._ensureWritable();
12629 this._lang_map.$setindex(key, value);
12630 }
12631 CopyOnWriteMap.prototype.putIfAbsent = function(key, ifAbsent) {
12632 this._ensureWritable();
12633 return this._lang_map.putIfAbsent(key, ifAbsent);
12634 }
12635 CopyOnWriteMap.prototype.remove = function(key) {
12636 this._ensureWritable();
12637 return this._lang_map.remove(key);
12638 }
12639 CopyOnWriteMap.prototype.$index = function(key) {
12640 return this._lang_map.$index(key);
12641 }
12642 CopyOnWriteMap.prototype.isEmpty = function() {
12643 return this._lang_map.isEmpty();
12644 }
12645 CopyOnWriteMap.prototype.get$length = function() {
12646 return this._lang_map.get$length();
12647 }
12648 CopyOnWriteMap.prototype.forEach = function(f) {
12649 return this._lang_map.forEach(f);
12650 }
12651 CopyOnWriteMap.prototype.getKeys = function() {
12652 return this._lang_map.getKeys();
12653 }
12654 CopyOnWriteMap.prototype.getValues = function() {
12655 return this._lang_map.getValues();
12656 }
12657 CopyOnWriteMap.prototype.containsKey = function(key) {
12658 return this._lang_map.containsKey(key);
12659 }
12660 CopyOnWriteMap.prototype.remove$1 = CopyOnWriteMap.prototype.remove;
12661 // ********** Code for CopyOnWriteMap_dart_core_String$VariableValue *********** ***
12662 $inherits(CopyOnWriteMap_dart_core_String$VariableValue, CopyOnWriteMap);
12663 function CopyOnWriteMap_dart_core_String$VariableValue() {
12664 this._lang_map = new _SharedBackingMap_dart_core_String$VariableValue();
12665 }
12666 CopyOnWriteMap_dart_core_String$VariableValue.prototype.remove$1 = CopyOnWriteMa p_dart_core_String$VariableValue.prototype.remove;
12667 // ********** Code for Value **************
12668 function Value(type, code, span) {
12669 this.type = type;
12670 this.code = code;
12671 this.span = span;
12672 if (this.get$type() == null) $globals.world.internalError("type passed as null ", this.span);
12673 }
12674 Value.prototype.get$type = function() { return this.type; };
12675 Value.prototype.get$code = function() { return this.code; };
12676 Value.prototype.get$span = function() { return this.span; };
12677 Value.prototype.get$isType = function() {
12678 return false;
12679 }
12680 Value.prototype.get$isSuper = function() {
12681 return false;
12682 }
12683 Value.prototype.get$isConst = function() {
12684 return false;
12685 }
12686 Value.prototype.get$isFinal = function() {
12687 return false;
12688 }
12689 Value.prototype.get$needsTemp = function() {
12690 return true;
12691 }
12692 Value.prototype.get$staticType = function() {
12693 return this.get$type();
12694 }
12695 Value.prototype.get$constValue = function() {
12696 return null;
12697 }
12698 Value.comma = function(x, y) {
12699 return new Value(y.get$type(), ("(" + x.get$code() + ", " + y.get$code() + ")" ), null);
12700 }
12701 Value.union = function(x, y) {
12702 if (null == y || $eq$(x, y)) return x;
12703 if (null == x) return y;
12704 var ret = x._tryUnion(y);
12705 if ($ne$(ret)) return ret;
12706 ret = y._tryUnion(x);
12707 if ($ne$(ret)) return ret;
12708 return new Value(Type.union(x.get$type(), y.get$type()), null, null);
12709 }
12710 Value.prototype._tryUnion = function(right) {
12711 return null;
12712 }
12713 Value.prototype.validateInitialized = function(span) {
12714
12715 }
12716 Value.prototype.get_ = function(context, name, node) {
12717 var member = this._resolveMember(context, name, node);
12718 if ($ne$(member)) {
12719 return member._get(context, node, this);
12720 }
12721 else {
12722 return this.invokeNoSuchMethod$3(context, ("get:" + name), node);
12723 }
12724 }
12725 Value.prototype.set_ = function(context, name, node, value, kind, returnKind) {
12726 var member = this._resolveMember(context, name, node);
12727 if ($ne$(member)) {
12728 var thisValue = this;
12729 var thisTmp = null;
12730 var retTmp = null;
12731 if (kind != (0)) {
12732 thisTmp = context.getTemp(thisValue);
12733 thisValue = context.assignTemp(thisTmp, thisValue);
12734 var lhs = member._get(context, node, thisTmp);
12735 if (returnKind == (3)) {
12736 retTmp = context.forceTemp(lhs);
12737 lhs = context.assignTemp(retTmp, lhs);
12738 }
12739 value = lhs.binop(kind, value, context, node);
12740 }
12741 if (returnKind == (2)) {
12742 retTmp = context.forceTemp(value);
12743 value = context.assignTemp(retTmp, value);
12744 }
12745 var ret = member._set(context, node, thisValue, value);
12746 if ($ne$(thisTmp) && $ne$(thisTmp, this)) context.freeTemp(thisTmp);
12747 if ($ne$(retTmp)) {
12748 context.freeTemp(retTmp);
12749 return Value.comma(ret, retTmp);
12750 }
12751 else {
12752 return ret;
12753 }
12754 }
12755 else {
12756 return this.invokeNoSuchMethod(context, ("set:" + name), node, new Arguments (null, [value]));
12757 }
12758 }
12759 Value.prototype.setIndex = function(context, index, node, value, kind, returnKin d) {
12760 var member = this._resolveMember(context, ":setindex", node);
12761 if ($ne$(member)) {
12762 var thisValue = this;
12763 var indexValue = index;
12764 var thisTmp = null;
12765 var indexTmp = null;
12766 var retTmp = null;
12767 if (returnKind == (2)) {
12768 retTmp = context.forceTemp(value);
12769 }
12770 if (kind != (0)) {
12771 thisTmp = context.getTemp(this);
12772 indexTmp = context.getTemp(index);
12773 thisValue = context.assignTemp(thisTmp, thisValue);
12774 indexValue = context.assignTemp(indexTmp, indexValue);
12775 if (returnKind == (3)) {
12776 retTmp = context.forceTemp(value);
12777 }
12778 var lhs = thisTmp.invoke(context, ":index", node, new Arguments(null, [ind exTmp]));
12779 if (returnKind == (3)) {
12780 lhs = context.assignTemp(retTmp, lhs);
12781 }
12782 value = lhs.binop(kind, value, context, node);
12783 }
12784 if (returnKind == (2)) {
12785 value = context.assignTemp(retTmp, value);
12786 }
12787 var ret = member.invoke(context, node, thisValue, new Arguments(null, [index Value, value]));
12788 if ($ne$(thisTmp) && $ne$(thisTmp, this)) context.freeTemp(thisTmp);
12789 if ($ne$(indexTmp) && $ne$(indexTmp, index)) context.freeTemp(indexTmp);
12790 if ($ne$(retTmp)) {
12791 context.freeTemp(retTmp);
12792 return Value.comma(ret, retTmp);
12793 }
12794 else {
12795 return ret;
12796 }
12797 }
12798 else {
12799 return this.invokeNoSuchMethod(context, ":index", node, new Arguments(null, [index, value]));
12800 }
12801 }
12802 Value.prototype.unop = function(kind, context, node) {
12803 switch (kind) {
12804 case (19):
12805
12806 var newVal = this.convertTo(context, $globals.world.nonNullBool);
12807 return new Value(newVal.get$type(), ("!" + newVal.get$code()), node.get$sp an());
12808
12809 case (42):
12810
12811 $globals.world.error("no unary add operator in dart", node.get$span());
12812 break;
12813
12814 case (43):
12815
12816 return this.invoke(context, ":negate", node, Arguments.get$EMPTY());
12817
12818 case (18):
12819
12820 return this.invoke(context, ":bit_not", node, Arguments.get$EMPTY());
12821
12822 }
12823 $globals.world.internalError(("unimplemented: " + node.get$op()), node.get$spa n());
12824 }
12825 Value.prototype._mayOverrideEqual = function() {
12826 return this.get$type().get$isVar() || this.get$type().get$isObject() || !this. get$type().getMember(":eq").declaringType.get$isObject();
12827 }
12828 Value.prototype.binop = function(kind, other, context, node) {
12829 switch (kind) {
12830 case (35):
12831 case (34):
12832
12833 var code = ("" + this.get$code() + " " + node.get$op() + " " + other.get$c ode());
12834 return new Value($globals.world.nonNullBool, code, node.get$span());
12835
12836 case (50):
12837 case (51):
12838
12839 var op = kind == (50) ? "==" : "!=";
12840 if (this.get$code() == "null") {
12841 return new Value($globals.world.nonNullBool, ("null " + op + " " + other .get$code()), node.get$span());
12842 }
12843 else if (other.get$code() == "null") {
12844 return new Value($globals.world.nonNullBool, ("null " + op + " " + this. get$code()), node.get$span());
12845 }
12846 else {
12847 var ret;
12848 var check;
12849 if (this.get$needsTemp()) {
12850 var tmp = context.forceTemp(this);
12851 ret = tmp.get$code();
12852 check = ("(" + ret + " = " + this.get$code() + ") == null");
12853 }
12854 else {
12855 ret = this.get$code();
12856 check = ("null == " + this.get$code());
12857 }
12858 return new Value($globals.world.nonNullBool, ("(" + check + " ? null " + op + " (" + other.get$code() + ") : " + ret + " " + op + "= " + other.get$code( ) + ")"), node.get$span());
12859 }
12860
12861 case (48):
12862
12863 if (other.get$code() == "null") {
12864 if (!this._mayOverrideEqual()) {
12865 return new Value($globals.world.nonNullBool, ("" + this.get$code() + " == " + other.get$code()), node.get$span());
12866 }
12867 }
12868 else if (this.get$code() == "null") {
12869 return new Value($globals.world.nonNullBool, ("" + this.get$code() + " = = " + other.get$code()), node.get$span());
12870 }
12871 break;
12872
12873 case (49):
12874
12875 if (other.get$code() == "null") {
12876 if (!this._mayOverrideEqual()) {
12877 return new Value($globals.world.nonNullBool, ("" + this.get$code() + " != " + other.get$code()), node.get$span());
12878 }
12879 }
12880 else if (this.get$code() == "null") {
12881 return new Value($globals.world.nonNullBool, ("" + this.get$code() + " ! = " + other.get$code()), node.get$span());
12882 }
12883 break;
12884
12885 }
12886 var name = kind == (49) ? ":ne" : TokenKind.binaryMethodName(kind);
12887 return this.invoke(context, name, node, new Arguments(null, [other]));
12888 }
12889 Value.prototype.invoke = function(context, name, node, args) {
12890 if (name == ":call") {
12891 if (this.get$isType()) {
12892 $globals.world.error("must use \"new\" or \"const\" to construct a new ins tance", node.span);
12893 }
12894 if (this.get$type().needsVarCall(args)) {
12895 return this._varCall(context, node, args);
12896 }
12897 }
12898 var member = this._resolveMember(context, name, node);
12899 if ($eq$(member)) {
12900 return this.invokeNoSuchMethod(context, name, node, args);
12901 }
12902 else {
12903 return member.invoke(context, node, this, args);
12904 }
12905 }
12906 Value.prototype._hasOverriddenNoSuchMethod = function() {
12907 var m = this.get$type().getMember("noSuchMethod");
12908 return $ne$(m) && !m.get$declaringType().get$isObject();
12909 }
12910 Value.prototype.get$isPreciseType = function() {
12911 return this.get$isSuper() || this.get$isType();
12912 }
12913 Value.prototype._missingMemberError = function(context, name, node) {
12914 var onStaticType = false;
12915 if ($ne$(this.get$type(), this.get$staticType())) {
12916 onStaticType = null != this.get$staticType().getMember(name);
12917 }
12918 if (!onStaticType && context.get$showWarnings() && !this._isVarOrParameterType (this.get$staticType()) && !this._hasOverriddenNoSuchMethod()) {
12919 var typeName = this.get$staticType().name;
12920 if ($eq$(typeName)) typeName = this.get$staticType().get$library().name;
12921 var message = ("cannot resolve \"" + name + "\" on \"" + typeName + "\"");
12922 if (this.get$isType()) {
12923 $globals.world.error(message, node.span);
12924 }
12925 else {
12926 $globals.world.warning(message, node.span);
12927 }
12928 }
12929 }
12930 Value.prototype._tryResolveMember = function(context, name, node) {
12931 var member = this.get$type().getMember(name);
12932 if ($eq$(member)) {
12933 this._missingMemberError(context, name, node);
12934 return null;
12935 }
12936 else {
12937 if (this.get$isType() && !member.get$isStatic() && context.get$showWarnings( )) {
12938 $globals.world.error("cannot refer to instance member as static", node.spa n);
12939 return null;
12940 }
12941 }
12942 if (this.get$isPreciseType() || member.get$isStatic()) {
12943 return member.get$preciseMemberSet();
12944 }
12945 else {
12946 return member.get$potentialMemberSet();
12947 }
12948 }
12949 Value.prototype._isVarOrParameterType = function(t) {
12950 return t.get$isVar() || (t instanceof ParameterType);
12951 }
12952 Value.prototype._shouldBindDynamically = function() {
12953 return this._isVarOrParameterType(this.get$type()) || $globals.options.forceDy namic && !this.get$isConst();
12954 }
12955 Value.prototype._resolveMember = function(context, name, node) {
12956 var member = null;
12957 if (!this._shouldBindDynamically()) {
12958 member = this._tryResolveMember(context, name, node);
12959 }
12960 if ($eq$(member) && !this.get$isSuper() && !this.get$isType()) {
12961 member = context.findMembers(name);
12962 if ($eq$(member) && context.get$showWarnings()) {
12963 var where = "the world";
12964 if (name.startsWith("_")) {
12965 where = ("library \"" + context.get$library().name + "\"");
12966 }
12967 $globals.world.warning(("" + name + " is not defined anywhere in " + where + "."), node.span);
12968 }
12969 }
12970 return member;
12971 }
12972 Value.prototype.checkFirstClass = function(span) {
12973 if (this.get$isType()) {
12974 $globals.world.error("Types are not first class", span);
12975 }
12976 }
12977 Value.prototype._varCall = function(context, node, args) {
12978 var stub = $globals.world.functionType.getCallStub(args);
12979 return stub.invoke(context, node, this, args);
12980 }
12981 Value.prototype.needsConversion = function(toType) {
12982 var c = this.convertTo(null, toType);
12983 return $eq$(c) || this.get$code() != c.get$code();
12984 }
12985 Value.prototype.convertTo = function(context, toType) {
12986 var checked = context != null && context.get$showWarnings();
12987 var callMethod = toType.getCallMethod();
12988 if ($ne$(callMethod)) {
12989 if (checked && !toType.isAssignable(this.get$type())) {
12990 this.convertWarning(toType);
12991 }
12992 return this._maybeWrapFunction(toType, callMethod);
12993 }
12994 var fromType = this.get$type();
12995 if (this.get$type().get$isVar() && (this.get$code() != "null" || !toType.get$i sNullable())) {
12996 fromType = $globals.world.objectType;
12997 }
12998 var bothNum = this.get$type().get$isNum() && toType.get$isNum();
12999 if (!fromType.isSubtypeOf(toType) && !bothNum) {
13000 if (checked && !toType.isSubtypeOf(this.get$type())) {
13001 this.convertWarning(toType);
13002 }
13003 if ($globals.options.enableTypeChecks) {
13004 if (context == null) {
13005 return null;
13006 }
13007 return this._typeAssert(context, toType);
13008 }
13009 }
13010 return this._changeStaticType(toType);
13011 }
13012 Value.prototype._changeStaticType = function(toType) {
13013 return this;
13014 }
13015 Value.prototype._maybeWrapFunction = function(toType, callMethod) {
13016 var arity = callMethod.parameters.get$length();
13017 var myCall = this.get$type().getCallMethod();
13018 var result = this;
13019 if ($eq$(myCall) || myCall.get$parameters().get$length() != arity) {
13020 var stub = $globals.world.functionType.getCallStub(Arguments.Arguments$bare$ factory(arity));
13021 result = new Value(toType, ("to$" + stub.get$name() + "(" + this.get$code() + ")"), this.span);
13022 }
13023 if ($eq$(toType.get$library(), $globals.world.dom) && $ne$(this.get$type().get $library(), $globals.world.dom)) {
13024 if (arity == (0)) {
13025 $globals.world.gen.corejs.useWrap0 = true;
13026 }
13027 else {
13028 $globals.world.gen.corejs.useWrap1 = true;
13029 }
13030 result = new Value(toType, ("$wrap_call$" + arity + "(" + result.get$code() + ")"), this.span);
13031 }
13032 return result._changeStaticType(toType);
13033 }
13034 Value.prototype._typeAssert = function(context, toType) {
13035 var $0;
13036 if ((toType instanceof ParameterType)) {
13037 var p = toType;
13038 toType = p.extendsType;
13039 }
13040 if (toType.get$isObject() || toType.get$isVar()) {
13041 $globals.world.internalError(("We thought " + this.get$type().name + " is no t a subtype of " + toType.name + "?"));
13042 }
13043 function throwTypeError(paramName) {
13044 return $globals.world.withoutForceDynamic((function () {
13045 var typeErrorCtor = $globals.world.typeErrorType.getConstructor("_internal ");
13046 $globals.world.gen.corejs.ensureTypeNameOf();
13047 var result = typeErrorCtor.invoke(context, null, new TypeValue($globals.wo rld.typeErrorType, null), new Arguments(null, [new Value($globals.world.objectTy pe, paramName, null), new Value($globals.world.stringType, ("\"" + toType.name + "\""), null)]));
13048 $globals.world.gen.corejs.useThrow = true;
13049 return ("$throw(" + result.get$code() + ")");
13050 })
13051 );
13052 }
13053 if (toType.get$isNum()) toType = $globals.world.numType;
13054 var check;
13055 if (toType.get$isVoid()) {
13056 check = ("$assert_void(" + this.get$code() + ")");
13057 if (toType.typeCheckCode == null) {
13058 toType.typeCheckCode = ("function $assert_void(x) {\n if (x == null) retu rn null;\n " + throwTypeError("x") + "\n}");
13059 }
13060 }
13061 else if ($eq$(toType, $globals.world.nonNullBool)) {
13062 $globals.world.gen.corejs.useNotNullBool = true;
13063 check = ("$notnull_bool(" + this.get$code() + ")");
13064 }
13065 else if (toType.get$library().get$isCore() && toType.get$typeofName() != null) {
13066 check = ("$assert_" + toType.name + "(" + this.get$code() + ")");
13067 if (toType.typeCheckCode == null) {
13068 toType.typeCheckCode = ("function $assert_" + toType.name + "(x) {\n if ( x == null || typeof(x) == \"" + toType.get$typeofName() + "\") return x;\n " + throwTypeError("x") + "\n}");
13069 }
13070 }
13071 else {
13072 toType.isChecked = true;
13073 var checkName = ("assert$" + toType.get$jsname());
13074 var temp = context.getTemp(this);
13075 check = ("(" + context.assignTemp(temp, this).get$code() + " == null ? null :");
13076 check = $add$(check, (" " + temp.get$code() + "." + checkName + "())"));
13077 if ($ne$(this, temp)) context.freeTemp(temp);
13078 $globals.world.objectType.varStubs.putIfAbsent(checkName, (function () {
13079 return new VarMethodStub(checkName, null, Arguments.get$EMPTY(), throwType Error("this"));
13080 })
13081 );
13082 }
13083 ($0 = context.get$counters()).typeAsserts = $0.typeAsserts + (1);
13084 return new Value(toType, check, this.span);
13085 }
13086 Value.prototype.instanceOf = function(context, toType, span, isTrue, forceCheck) {
13087 if (toType.get$isVar()) {
13088 $globals.world.error("cannot resolve type", span);
13089 }
13090 var testCode = null;
13091 if (toType.get$isVar() || toType.get$isObject() || (toType instanceof Paramete rType)) {
13092 if (this.get$needsTemp()) {
13093 return new Value($globals.world.nonNullBool, ("(" + this.get$code() + ", t rue)"), span);
13094 }
13095 else {
13096 return Value.fromBool(true, span);
13097 }
13098 }
13099 if (toType.get$library().get$isCore()) {
13100 var typeofName = toType.get$typeofName();
13101 if ($ne$(typeofName)) {
13102 testCode = ("(typeof(" + this.get$code() + ") " + (isTrue ? "==" : "!=") + " '" + typeofName + "')");
13103 }
13104 }
13105 if (toType.get$isClass() && !toType.get$isHiddenNativeType() && !toType.get$is ConcreteGeneric()) {
13106 toType.markUsed();
13107 testCode = ("(" + this.get$code() + " instanceof " + toType.get$jsname() + " )");
13108 if (!isTrue) {
13109 testCode = ("!" + testCode);
13110 }
13111 }
13112 if (testCode == null) {
13113 toType.isTested = true;
13114 var temp = context.getTemp(this);
13115 var checkName = ("is$" + toType.get$jsname());
13116 testCode = (("(" + context.assignTemp(temp, this).get$code() + " &&") + (" " + temp.get$code() + "." + checkName + "())"));
13117 if (isTrue) {
13118 testCode = ("!!" + testCode);
13119 }
13120 else {
13121 testCode = ("!" + testCode);
13122 }
13123 if ($ne$(this, temp)) context.freeTemp(temp);
13124 if (!$globals.world.objectType.varStubs.containsKey(checkName)) {
13125 $globals.world.objectType.varStubs.$setindex(checkName, new VarMethodStub( checkName, null, Arguments.get$EMPTY(), "return false"));
13126 }
13127 }
13128 return new Value($globals.world.nonNullBool, testCode, span);
13129 }
13130 Value.prototype.convertWarning = function(toType) {
13131 $globals.world.warning(("type \"" + this.get$type().get$fullname() + "\" is no t assignable to \"" + toType.get$fullname() + "\""), this.span);
13132 }
13133 Value.prototype.invokeNoSuchMethod = function(context, name, node, args) {
13134 if (this.get$isType()) {
13135 $globals.world.error(("member lookup failed for \"" + name + "\""), node.spa n);
13136 }
13137 var pos = "";
13138 if (args != null) {
13139 var argsCode = [];
13140 for (var i = (0);
13141 i < args.get$length(); i++) {
13142 argsCode.add(args.values.$index(i).get$code());
13143 }
13144 pos = Strings.join(argsCode, ", ");
13145 }
13146 var noSuchArgs = [new Value($globals.world.stringType, ("\"" + name + "\""), n ode.span), new Value($globals.world.listType, ("[" + pos + "]"), node.span)];
13147 return this._resolveMember(context, "noSuchMethod", node).invoke(context, node , this, new Arguments(null, noSuchArgs));
13148 }
13149 Value.fromBool = function(value, span) {
13150 return new BoolValue(value, true, span);
13151 }
13152 Value.fromInt = function(value, span) {
13153 return new IntValue(value, true, span);
13154 }
13155 Value.fromDouble = function(value, span) {
13156 return new DoubleValue(value, true, span);
13157 }
13158 Value.fromString = function(value, span) {
13159 return new StringValue(value, true, span);
13160 }
13161 Value.fromNull = function(span) {
13162 return new NullValue(true, span);
13163 }
13164 Value.prototype.instanceOf$3$isTrue$forceCheck = Value.prototype.instanceOf;
13165 Value.prototype.instanceOf$4 = function($0, $1, $2, $3) {
13166 return this.instanceOf($0, $1, $2, $3, false);
13167 };
13168 Value.prototype.invokeNoSuchMethod$3 = Value.prototype.invokeNoSuchMethod;
13169 Value.prototype.setIndex$4$kind = function($0, $1, $2, $3, kind) {
13170 return this.setIndex($0, $1, $2, $3, kind, (1));
13171 };
13172 Value.prototype.setIndex$4$kind$returnKind = Value.prototype.setIndex;
13173 Value.prototype.set_$4$kind = function($0, $1, $2, $3, kind) {
13174 return this.set_($0, $1, $2, $3, kind, (1));
13175 };
13176 Value.prototype.set_$4$kind$returnKind = Value.prototype.set_;
13177 // ********** Code for PureStaticValue **************
13178 $inherits(PureStaticValue, Value);
13179 function PureStaticValue(type, span, isConst, isType) {
13180 this.isConst = isConst;
13181 this.isType = isType;
13182 Value.call(this, type, null, span);
13183 }
13184 PureStaticValue.prototype.get$isConst = function() { return this.isConst; };
13185 PureStaticValue.prototype.get$isType = function() { return this.isType; };
13186 PureStaticValue.prototype.getMem = function(context, name, node) {
13187 var member = this.get$type().getMember(name);
13188 if ($eq$(member)) {
13189 $globals.world.warning(("cannot find \"" + name + "\" on \"" + this.get$type ().name + "\""), node.span);
13190 return null;
13191 }
13192 if (this.isType && !member.get$isStatic()) {
13193 $globals.world.error("cannot refer to instance member as static", node.span) ;
13194 }
13195 return member;
13196 }
13197 PureStaticValue.prototype.get_ = function(context, name, node) {
13198 if (this.get$type().get$isVar()) return new PureStaticValue($globals.world.var Type, node.span, false, false);
13199 var member = this.getMem(context, name, node);
13200 if ($eq$(member)) return new PureStaticValue($globals.world.varType, node.span , false, false);
13201 return member._get(context, node, this);
13202 }
13203 PureStaticValue.prototype.set_ = function(context, name, node, value, kind, retu rnKind) {
13204 if (this.get$type().get$isVar()) return new PureStaticValue($globals.world.var Type, node.span, false, false);
13205 var member = this.getMem(context, name, node);
13206 if ($ne$(member)) {
13207 member._set(context, node, this, value);
13208 }
13209 return new PureStaticValue(value.get$type(), node.span, false, false);
13210 }
13211 PureStaticValue.prototype.setIndex = function(context, index, node, value, kind, returnKind) {
13212 var tmp = this.invoke(context, ":setindex", node, new Arguments(null, [index, value]));
13213 return new PureStaticValue(value.get$type(), node.span, false, false);
13214 }
13215 PureStaticValue.prototype.unop = function(kind, context, node) {
13216 switch (kind) {
13217 case (19):
13218
13219 return new PureStaticValue($globals.world.boolType, node.get$span(), false , false);
13220
13221 case (42):
13222
13223 if (!this.isConst && !this.get$type().get$isNum()) {
13224 $globals.world.error("no unary add operator in dart", node.get$span());
13225 }
13226 return new PureStaticValue($globals.world.numType, node.get$span(), false, false);
13227
13228 case (43):
13229
13230 return this.invoke(context, ":negate", node, Arguments.get$EMPTY());
13231
13232 case (18):
13233
13234 return this.invoke(context, ":bit_not", node, Arguments.get$EMPTY());
13235
13236 }
13237 $globals.world.internalError(("unimplemented: " + node.get$op()), node.get$spa n());
13238 }
13239 PureStaticValue.prototype.binop = function(kind, other, context, node) {
13240 var isConst = this.isConst && other.get$isConst();
13241 switch (kind) {
13242 case (35):
13243 case (34):
13244
13245 return new PureStaticValue($globals.world.boolType, node.get$span(), isCon st, false);
13246
13247 case (50):
13248
13249 return new PureStaticValue($globals.world.boolType, node.get$span(), isCon st, false);
13250
13251 case (51):
13252
13253 return new PureStaticValue($globals.world.boolType, node.get$span(), isCon st, false);
13254
13255 }
13256 var name = kind == (49) ? ":ne" : TokenKind.binaryMethodName(kind);
13257 var ret = this.invoke(context, name, node, new Arguments(null, [other]));
13258 if (isConst) {
13259 ret = new PureStaticValue(ret.get$type(), node.get$span(), isConst, false);
13260 }
13261 return ret;
13262 }
13263 PureStaticValue.prototype.invoke = function(context, name, node, args) {
13264 if (this.get$type().get$isVar()) return new PureStaticValue($globals.world.var Type, node.span, false, false);
13265 if (this.get$type().get$isFunction() && name == ":call") {
13266 return new PureStaticValue($globals.world.varType, node.span, false, false);
13267 }
13268 var member = this.getMem(context, name, node);
13269 if ($eq$(member)) return new PureStaticValue($globals.world.varType, node.span , false, false);
13270 return member.invoke(context, node, this, args);
13271 }
13272 PureStaticValue.prototype.invokeNoSuchMethod = function(context, name, node, arg s) {
13273 if (this.isType) {
13274 $globals.world.error(("member lookup failed for \"" + name + "\""), node.spa n);
13275 }
13276 var member = this.getMem(context, "noSuchMethod", node);
13277 if ($eq$(member)) return new PureStaticValue($globals.world.varType, node.span , false, false);
13278 var noSuchArgs = new Arguments(null, [new PureStaticValue($globals.world.strin gType, node.span, false, false), new PureStaticValue($globals.world.listType, no de.span, false, false)]);
13279 return member.invoke(context, node, this, noSuchArgs);
13280 }
13281 PureStaticValue.prototype._typeAssert = function(context, toType) {
13282 return this._changeStaticType(toType);
13283 }
13284 PureStaticValue.prototype._changeStaticType = function(toType) {
13285 if ((null == toType ? null == (this.get$type()) : toType === this.get$type())) return this;
13286 return new PureStaticValue(toType, this.span, this.isConst, this.isType);
13287 }
13288 PureStaticValue.prototype.invokeNoSuchMethod$3 = PureStaticValue.prototype.invok eNoSuchMethod;
13289 PureStaticValue.prototype.setIndex$4$kind = function($0, $1, $2, $3, kind) {
13290 return this.setIndex($0, $1, $2, $3, kind, (1));
13291 };
13292 PureStaticValue.prototype.setIndex$4$kind$returnKind = PureStaticValue.prototype .setIndex;
13293 PureStaticValue.prototype.set_$4$kind = function($0, $1, $2, $3, kind) {
13294 return this.set_($0, $1, $2, $3, kind, (1));
13295 };
13296 PureStaticValue.prototype.set_$4$kind$returnKind = PureStaticValue.prototype.set _;
13297 // ********** Code for EvaluatedValue **************
13298 $inherits(EvaluatedValue, Value);
13299 function EvaluatedValue(isConst, type, span) {
13300 this.isConst = isConst;
13301 Value.call(this, type, "@@@", span);
13302 }
13303 EvaluatedValue.prototype.get$isConst = function() { return this.isConst; };
13304 EvaluatedValue.prototype.get$code = function() {
13305 $globals.world.internalError("Should not be getting code from raw EvaluatedVal ue", this.span);
13306 }
13307 EvaluatedValue.prototype.get$actualValue = function() {
13308 $globals.world.internalError("Should not be getting actual value from raw Eval uatedValue", this.span);
13309 }
13310 EvaluatedValue.prototype.get$needsTemp = function() {
13311 return false;
13312 }
13313 EvaluatedValue.prototype.get$constValue = function() {
13314 return this;
13315 }
13316 EvaluatedValue.prototype.hashCode = function() {
13317 return this.get$code().hashCode();
13318 }
13319 EvaluatedValue.prototype.$eq = function(other) {
13320 return (other instanceof EvaluatedValue) && $eq$(other.get$type(), this.get$ty pe()) && $eq$(other.get$code(), this.get$code());
13321 }
13322 // ********** Code for NullValue **************
13323 $inherits(NullValue, EvaluatedValue);
13324 function NullValue(isConst, span) {
13325 EvaluatedValue.call(this, isConst, $globals.world.varType, span);
13326 }
13327 NullValue.prototype.get$actualValue = function() {
13328 return null;
13329 }
13330 NullValue.prototype.get$code = function() {
13331 return "null";
13332 }
13333 NullValue.prototype.binop = function(kind, other, context, node) {
13334 if (!(other instanceof NullValue)) return Value.prototype.binop.call(this, kin d, other, context, node);
13335 var c = this.isConst && other.get$isConst();
13336 var s = node.get$span();
13337 switch (kind) {
13338 case (50):
13339 case (48):
13340
13341 return new BoolValue(true, c, s);
13342
13343 case (51):
13344 case (49):
13345
13346 return new BoolValue(false, c, s);
13347
13348 }
13349 return Value.prototype.binop.call(this, kind, other, context, node);
13350 }
13351 // ********** Code for BoolValue **************
13352 $inherits(BoolValue, EvaluatedValue);
13353 function BoolValue(actualValue, isConst, span) {
13354 this.actualValue = actualValue;
13355 EvaluatedValue.call(this, isConst, $globals.world.nonNullBool, span);
13356 }
13357 BoolValue.prototype.get$actualValue = function() { return this.actualValue; };
13358 BoolValue.prototype.get$code = function() {
13359 return this.actualValue ? "true" : "false";
13360 }
13361 BoolValue.prototype.unop = function(kind, context, node) {
13362 switch (kind) {
13363 case (19):
13364
13365 return new BoolValue(!this.actualValue, this.isConst, node.get$span());
13366
13367 }
13368 return Value.prototype.unop.call(this, kind, context, node);
13369 }
13370 BoolValue.prototype.binop = function(kind, other, context, node) {
13371 if (!(other instanceof BoolValue)) return Value.prototype.binop.call(this, kin d, other, context, node);
13372 var c = this.isConst && other.get$isConst();
13373 var s = node.get$span();
13374 var x = this.actualValue, y = other.get$actualValue();
13375 switch (kind) {
13376 case (50):
13377 case (48):
13378
13379 return new BoolValue($eq$(x, y), c, s);
13380
13381 case (51):
13382 case (49):
13383
13384 return new BoolValue($ne$(x, y), c, s);
13385
13386 case (35):
13387
13388 return new BoolValue(x && y, c, s);
13389
13390 case (34):
13391
13392 return new BoolValue(x || y, c, s);
13393
13394 }
13395 return Value.prototype.binop.call(this, kind, other, context, node);
13396 }
13397 // ********** Code for IntValue **************
13398 $inherits(IntValue, EvaluatedValue);
13399 function IntValue(actualValue, isConst, span) {
13400 this.actualValue = actualValue;
13401 EvaluatedValue.call(this, isConst, $globals.world.intType, span);
13402 }
13403 IntValue.prototype.get$actualValue = function() { return this.actualValue; };
13404 IntValue.prototype.get$code = function() {
13405 return ("(" + this.actualValue + ")");
13406 }
13407 IntValue.prototype.unop = function(kind, context, node) {
13408 switch (kind) {
13409 case (42):
13410
13411 return new IntValue(this.actualValue, this.isConst, this.span);
13412
13413 case (43):
13414
13415 return new IntValue(-this.actualValue, this.isConst, this.span);
13416
13417 case (18):
13418
13419 return new IntValue(~this.actualValue, this.isConst, this.span);
13420
13421 }
13422 return Value.prototype.unop.call(this, kind, context, node);
13423 }
13424 IntValue.prototype.binop = function(kind, other, context, node) {
13425 var c = this.isConst && other.get$isConst();
13426 var s = node.get$span();
13427 if ((other instanceof IntValue)) {
13428 var x = this.actualValue;
13429 var y = other.get$actualValue();
13430 switch (kind) {
13431 case (50):
13432 case (48):
13433
13434 return new BoolValue(x == y, c, s);
13435
13436 case (51):
13437 case (49):
13438
13439 return new BoolValue(x != y, c, s);
13440
13441 case (36):
13442
13443 return new IntValue(x | y, c, s);
13444
13445 case (37):
13446
13447 return new IntValue(x ^ y, c, s);
13448
13449 case (38):
13450
13451 return new IntValue(x & y, c, s);
13452
13453 case (39):
13454
13455 return new IntValue(x << y, c, s);
13456
13457 case (40):
13458
13459 return new IntValue(x >> y, c, s);
13460
13461 case (42):
13462
13463 return new IntValue(x + y, c, s);
13464
13465 case (43):
13466
13467 return new IntValue(x - y, c, s);
13468
13469 case (44):
13470
13471 return new IntValue(x * y, c, s);
13472
13473 case (45):
13474
13475 return new DoubleValue(x / y, c, s);
13476
13477 case (46):
13478
13479 return new IntValue($truncdiv$(x, y), c, s);
13480
13481 case (47):
13482
13483 return new IntValue($mod$(x, y), c, s);
13484
13485 case (52):
13486
13487 return new BoolValue(x < y, c, s);
13488
13489 case (53):
13490
13491 return new BoolValue(x > y, c, s);
13492
13493 case (54):
13494
13495 return new BoolValue(x <= y, c, s);
13496
13497 case (55):
13498
13499 return new BoolValue(x >= y, c, s);
13500
13501 }
13502 }
13503 else if ((other instanceof DoubleValue)) {
13504 var x = this.actualValue;
13505 var y = other.get$actualValue();
13506 switch (kind) {
13507 case (50):
13508 case (48):
13509
13510 return new BoolValue(x == y, c, s);
13511
13512 case (51):
13513 case (49):
13514
13515 return new BoolValue(x != y, c, s);
13516
13517 case (42):
13518
13519 return new DoubleValue(x + y, c, s);
13520
13521 case (43):
13522
13523 return new DoubleValue(x - y, c, s);
13524
13525 case (44):
13526
13527 return new DoubleValue(x * y, c, s);
13528
13529 case (45):
13530
13531 return new DoubleValue(x / y, c, s);
13532
13533 case (46):
13534
13535 return new DoubleValue($truncdiv$(x, y), c, s);
13536
13537 case (47):
13538
13539 return new DoubleValue($mod$(x, y), c, s);
13540
13541 case (52):
13542
13543 return new BoolValue(x < y, c, s);
13544
13545 case (53):
13546
13547 return new BoolValue(x > y, c, s);
13548
13549 case (54):
13550
13551 return new BoolValue(x <= y, c, s);
13552
13553 case (55):
13554
13555 return new BoolValue(x >= y, c, s);
13556
13557 }
13558 }
13559 return Value.prototype.binop.call(this, kind, other, context, node);
13560 }
13561 // ********** Code for DoubleValue **************
13562 $inherits(DoubleValue, EvaluatedValue);
13563 function DoubleValue(actualValue, isConst, span) {
13564 this.actualValue = actualValue;
13565 EvaluatedValue.call(this, isConst, $globals.world.doubleType, span);
13566 }
13567 DoubleValue.prototype.get$actualValue = function() { return this.actualValue; };
13568 DoubleValue.prototype.get$code = function() {
13569 return ("(" + this.actualValue + ")");
13570 }
13571 DoubleValue.prototype.unop = function(kind, context, node) {
13572 switch (kind) {
13573 case (42):
13574
13575 return new DoubleValue(this.actualValue, this.isConst, this.span);
13576
13577 case (43):
13578
13579 return new DoubleValue(-this.actualValue, this.isConst, this.span);
13580
13581 }
13582 return Value.prototype.unop.call(this, kind, context, node);
13583 }
13584 DoubleValue.prototype.binop = function(kind, other, context, node) {
13585 var c = this.isConst && other.get$isConst();
13586 var s = node.get$span();
13587 if ((other instanceof DoubleValue)) {
13588 var x = this.actualValue;
13589 var y = other.get$actualValue();
13590 switch (kind) {
13591 case (50):
13592 case (48):
13593
13594 return new BoolValue(x == y, c, s);
13595
13596 case (51):
13597 case (49):
13598
13599 return new BoolValue(x != y, c, s);
13600
13601 case (42):
13602
13603 return new DoubleValue(x + y, c, s);
13604
13605 case (43):
13606
13607 return new DoubleValue(x - y, c, s);
13608
13609 case (44):
13610
13611 return new DoubleValue(x * y, c, s);
13612
13613 case (45):
13614
13615 return new DoubleValue(x / y, c, s);
13616
13617 case (46):
13618
13619 return new DoubleValue($truncdiv$(x, y), c, s);
13620
13621 case (47):
13622
13623 return new DoubleValue($mod$(x, y), c, s);
13624
13625 case (52):
13626
13627 return new BoolValue(x < y, c, s);
13628
13629 case (53):
13630
13631 return new BoolValue(x > y, c, s);
13632
13633 case (54):
13634
13635 return new BoolValue(x <= y, c, s);
13636
13637 case (55):
13638
13639 return new BoolValue(x >= y, c, s);
13640
13641 }
13642 }
13643 else if ((other instanceof IntValue)) {
13644 var x = this.actualValue;
13645 var y = other.get$actualValue();
13646 switch (kind) {
13647 case (50):
13648 case (48):
13649
13650 return new BoolValue(x == y, c, s);
13651
13652 case (51):
13653 case (49):
13654
13655 return new BoolValue(x != y, c, s);
13656
13657 case (42):
13658
13659 return new DoubleValue(x + y, c, s);
13660
13661 case (43):
13662
13663 return new DoubleValue(x - y, c, s);
13664
13665 case (44):
13666
13667 return new DoubleValue(x * y, c, s);
13668
13669 case (45):
13670
13671 return new DoubleValue(x / y, c, s);
13672
13673 case (46):
13674
13675 return new DoubleValue($truncdiv$(x, y), c, s);
13676
13677 case (47):
13678
13679 return new DoubleValue($mod$(x, y), c, s);
13680
13681 case (52):
13682
13683 return new BoolValue(x < y, c, s);
13684
13685 case (53):
13686
13687 return new BoolValue(x > y, c, s);
13688
13689 case (54):
13690
13691 return new BoolValue(x <= y, c, s);
13692
13693 case (55):
13694
13695 return new BoolValue(x >= y, c, s);
13696
13697 }
13698 }
13699 return Value.prototype.binop.call(this, kind, other, context, node);
13700 }
13701 // ********** Code for StringValue **************
13702 $inherits(StringValue, EvaluatedValue);
13703 function StringValue(actualValue, isConst, span) {
13704 this.actualValue = actualValue;
13705 EvaluatedValue.call(this, isConst, $globals.world.stringType, span);
13706 }
13707 StringValue.prototype.get$actualValue = function() { return this.actualValue; };
13708 StringValue.prototype.binop = function(kind, other, context, node) {
13709 if (!(other instanceof StringValue)) return Value.prototype.binop.call(this, k ind, other, context, node);
13710 var c = this.isConst && other.get$isConst();
13711 var s = node.get$span();
13712 var x = this.actualValue, y = other.get$actualValue();
13713 switch (kind) {
13714 case (50):
13715 case (48):
13716
13717 return new BoolValue(x == y, c, s);
13718
13719 case (51):
13720 case (49):
13721
13722 return new BoolValue(x != y, c, s);
13723
13724 case (42):
13725
13726 return new StringValue($add$(x, y), c, s);
13727
13728 }
13729 return Value.prototype.binop.call(this, kind, other, context, node);
13730 }
13731 StringValue.prototype.get$code = function() {
13732 var buf = new StringBufferImpl("");
13733 buf.add("\"");
13734 for (var i = (0);
13735 i < this.actualValue.length; i++) {
13736 var ch = this.actualValue.charCodeAt(i);
13737 switch (ch) {
13738 case (9):
13739
13740 buf.add("\\t");
13741 break;
13742
13743 case (10):
13744
13745 buf.add("\\n");
13746 break;
13747
13748 case (13):
13749
13750 buf.add("\\r");
13751 break;
13752
13753 case (34):
13754
13755 buf.add("\\\"");
13756 break;
13757
13758 case (92):
13759
13760 buf.add("\\\\");
13761 break;
13762
13763 default:
13764
13765 if ($gte$(ch, (32)) && $lte$(ch, (126))) {
13766 buf.add(this.actualValue[i]);
13767 }
13768 else {
13769 var hex = ch.toRadixString((16));
13770 switch (hex.get$length()) {
13771 case (1):
13772
13773 buf.add("\\x0");
13774 buf.add(hex);
13775 break;
13776
13777 case (2):
13778
13779 buf.add("\\x");
13780 buf.add(hex);
13781 break;
13782
13783 case (3):
13784
13785 buf.add("\\u0");
13786 buf.add(hex);
13787 break;
13788
13789 case (4):
13790
13791 buf.add("\\u");
13792 buf.add(hex);
13793 break;
13794
13795 default:
13796
13797 $globals.world.internalError("unicode values greater than 2 bytes not implemented");
13798 break;
13799
13800 }
13801 }
13802 break;
13803
13804 }
13805 }
13806 buf.add("\"");
13807 return buf.toString();
13808 }
13809 // ********** Code for ListValue **************
13810 $inherits(ListValue, EvaluatedValue);
13811 function ListValue(values, isConst, type, span) {
13812 this.values = values;
13813 EvaluatedValue.call(this, isConst, type, span);
13814 }
13815 ListValue.prototype.get$code = function() {
13816 var buf = new StringBufferImpl("");
13817 buf.add("[");
13818 for (var i = (0);
13819 $lt$(i, this.values.get$length()); i = $add$(i, (1))) {
13820 if ($gt$(i, (0))) buf.add(", ");
13821 buf.add(this.values.$index(i).get$code());
13822 }
13823 buf.add("]");
13824 var listCode = buf.toString$0();
13825 if (!this.isConst) return listCode;
13826 var v = new Value($globals.world.listType, listCode, this.span);
13827 var immutableListCtor = $globals.world.immutableListType.getConstructor("from" );
13828 var result = immutableListCtor.invoke($globals.world.gen.mainContext, null, ne w TypeValue(v.get$type(), this.span), new Arguments(null, [v]));
13829 return result.get$code();
13830 }
13831 ListValue.prototype.binop = function(kind, other, context, node) {
13832 if (!(other instanceof ListValue)) return Value.prototype.binop.call(this, kin d, other, context, node);
13833 switch (kind) {
13834 case (50):
13835
13836 return new BoolValue($eq$(this.get$type(), other.get$type()) && this.get$c ode() == other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13837
13838 case (51):
13839
13840 return new BoolValue($ne$(this.get$type(), other.get$type()) || this.get$c ode() != other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13841
13842 }
13843 return Value.prototype.binop.call(this, kind, other, context, node);
13844 }
13845 ListValue.prototype.getGlobalValue = function() {
13846 return $globals.world.gen.globalForConst(this, this.values);
13847 }
13848 // ********** Code for MapValue **************
13849 $inherits(MapValue, EvaluatedValue);
13850 function MapValue(values, isConst, type, span) {
13851 this.values = values;
13852 EvaluatedValue.call(this, isConst, type, span);
13853 }
13854 MapValue.prototype.get$code = function() {
13855 var items = new ListValue(this.values, false, $globals.world.listType, this.sp an);
13856 var tp = $globals.world.coreimpl.topType;
13857 var f = this.isConst ? tp.getMember("_constMap") : tp.getMember("_map");
13858 var value = f.invoke($globals.world.gen.mainContext, null, new TypeValue(tp, n ull), new Arguments(null, [items]));
13859 return value.get$code();
13860 }
13861 MapValue.prototype.getGlobalValue = function() {
13862 return $globals.world.gen.globalForConst(this, this.values);
13863 }
13864 MapValue.prototype.binop = function(kind, other, context, node) {
13865 if (!(other instanceof MapValue)) return Value.prototype.binop.call(this, kind , other, context, node);
13866 switch (kind) {
13867 case (50):
13868
13869 return new BoolValue($eq$(this.get$type(), other.get$type()) && this.get$c ode() == other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13870
13871 case (51):
13872
13873 return new BoolValue($ne$(this.get$type(), other.get$type()) || this.get$c ode() != other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13874
13875 }
13876 return Value.prototype.binop.call(this, kind, other, context, node);
13877 }
13878 // ********** Code for ObjectValue **************
13879 $inherits(ObjectValue, EvaluatedValue);
13880 function ObjectValue(isConst, type, span) {
13881 this.seenNativeInitializer = false;
13882 this.fields = new HashMapImplementation_FieldMember$Value();
13883 this.fieldsInInitOrder = [];
13884 EvaluatedValue.call(this, isConst, type, span);
13885 }
13886 ObjectValue.prototype.get$fields = function() { return this.fields; };
13887 ObjectValue.prototype.get$fieldsInInitOrder = function() { return this.fieldsInI nitOrder; };
13888 ObjectValue.prototype.get$seenNativeInitializer = function() { return this.seenN ativeInitializer; };
13889 ObjectValue.prototype.set$seenNativeInitializer = function(value) { return this. seenNativeInitializer = value; };
13890 ObjectValue.prototype.get$code = function() {
13891 if (null == this._code) this.validateInitialized(null);
13892 return this._code;
13893 }
13894 ObjectValue.prototype.initFields = function() {
13895 var allMembers = $globals.world.gen._orderValues(this.get$type().get$genericTy pe().getAllMembers());
13896 for (var $$i = allMembers.iterator(); $$i.hasNext(); ) {
13897 var f = $$i.next();
13898 if (f.get$isField() && !f.get$isStatic() && f.get$declaringType().get$isClas s()) {
13899 this._replaceField(f, f.computeValue(), true);
13900 }
13901 }
13902 }
13903 ObjectValue.prototype.setField = function(field, value, duringInit) {
13904 if (value.get$isConst() && (value instanceof VariableValue)) {
13905 value = value.get$dynamic().get$value();
13906 }
13907 var currentValue = this.fields.$index(field);
13908 if (this.isConst && !value.get$isConst()) {
13909 $globals.world.error("used of non-const value in const intializer", value.sp an);
13910 }
13911 if (null == currentValue) {
13912 this._replaceField(field, value, duringInit);
13913 if (field.get$isFinal() && !duringInit) {
13914 $globals.world.error("cannot initialize final fields outside of initialize r", value.span);
13915 }
13916 }
13917 else {
13918 if (field.get$isFinal() && null == field.computeValue()) {
13919 $globals.world.error("reassignment of field not allowed", value.span, fiel d.get$span());
13920 }
13921 else {
13922 this._replaceField(field, value, duringInit);
13923 }
13924 }
13925 }
13926 ObjectValue.prototype._replaceField = function(field, value, duringInit) {
13927 if (duringInit) {
13928 for (var i = (0);
13929 i < this.fieldsInInitOrder.get$length(); i++) {
13930 if ($eq$(this.fieldsInInitOrder.$index(i), field)) {
13931 this.fieldsInInitOrder.$setindex(i);
13932 break;
13933 }
13934 }
13935 this.fieldsInInitOrder.add(field);
13936 }
13937 this.fields.$setindex(field, value);
13938 }
13939 ObjectValue.prototype.validateInitialized = function(span) {
13940 var buf = new StringBufferImpl("");
13941 buf.add("Object.create(");
13942 buf.add(("" + this.get$type().get$jsname() + ".prototype, "));
13943 buf.add("{");
13944 var addComma = false;
13945 var $$list = this.fields.getKeys();
13946 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
13947 var field = $$i.next();
13948 if (addComma) buf.add(", ");
13949 buf.add(field.get$jsname());
13950 buf.add(": ");
13951 buf.add("{\"value\": ");
13952 if (null == this.fields.$index(field)) {
13953 $globals.world.error(("Required field '" + field.get$name() + "' was not i nitialized"), span, field.get$span());
13954 buf.add("null");
13955 }
13956 else {
13957 buf.add(this.fields.$index(field).get$code());
13958 }
13959 buf.add(", writeable: false}");
13960 addComma = true;
13961 }
13962 buf.add("})");
13963 this._code = buf.toString$0();
13964 }
13965 ObjectValue.prototype.binop = function(kind, other, context, node) {
13966 if (!(other instanceof ObjectValue)) return Value.prototype.binop.call(this, k ind, other, context, node);
13967 switch (kind) {
13968 case (50):
13969 case (48):
13970
13971 return new BoolValue($eq$(this.get$type(), other.get$type()) && this.get$c ode() == other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13972
13973 case (51):
13974 case (49):
13975
13976 return new BoolValue($ne$(this.get$type(), other.get$type()) || this.get$c ode() != other.get$code(), this.isConst && other.get$isConst(), node.get$span()) ;
13977
13978 }
13979 return Value.prototype.binop.call(this, kind, other, context, node);
13980 }
13981 // ********** Code for GlobalValue **************
13982 $inherits(GlobalValue, Value);
13983 function GlobalValue(type, code, isConst, field, name, exp, span, deps) {
13984 this.field = field;
13985 this.name = name;
13986 this.exp = exp;
13987 this.isConst = isConst;
13988 this.dependencies = [];
13989 Value.call(this, type, code, span);
13990 for (var $$i = deps.iterator(); $$i.hasNext(); ) {
13991 var dep = $$i.next();
13992 if ((dep instanceof GlobalValue)) {
13993 this.dependencies.add(dep);
13994 this.dependencies.addAll(dep.get$dependencies());
13995 }
13996 }
13997 }
13998 GlobalValue.prototype.get$field = function() { return this.field; };
13999 GlobalValue.prototype.get$name = function() { return this.name; };
14000 GlobalValue.prototype.get$exp = function() { return this.exp; };
14001 GlobalValue.prototype.get$isConst = function() { return this.isConst; };
14002 GlobalValue.prototype.get$actualValue = function() {
14003 return this.exp.get$dynamic().get$actualValue();
14004 }
14005 GlobalValue.prototype.get$constValue = function() {
14006 return this.isConst ? this.exp.get$constValue() : null;
14007 }
14008 GlobalValue.prototype.get$dependencies = function() { return this.dependencies; };
14009 GlobalValue.prototype.get$needsTemp = function() {
14010 return !this.isConst;
14011 }
14012 GlobalValue.prototype.compareTo = function(other) {
14013 if ($eq$(other, this)) {
14014 return (0);
14015 }
14016 else if (this.dependencies.indexOf(other) >= (0)) {
14017 return (1);
14018 }
14019 else if (other.dependencies.indexOf(this) >= (0)) {
14020 return (-1);
14021 }
14022 else if (this.dependencies.get$length() > other.dependencies.get$length()) {
14023 return (1);
14024 }
14025 else if (this.dependencies.get$length() < other.dependencies.get$length()) {
14026 return (-1);
14027 }
14028 else if (this.name == null && other.name != null) {
14029 return (1);
14030 }
14031 else if (this.name != null && other.name == null) {
14032 return (-1);
14033 }
14034 else if (this.name != null) {
14035 return this.name.compareTo(other.name);
14036 }
14037 else {
14038 return this.field.name.compareTo(other.field.name);
14039 }
14040 }
14041 // ********** Code for BareValue **************
14042 $inherits(BareValue, Value);
14043 function BareValue(home, outermost, span) {
14044 this.home = home;
14045 this.isType = outermost.get$isStatic();
14046 Value.call(this, outermost.method.get$declaringType(), null, span);
14047 }
14048 BareValue.prototype.get$isType = function() { return this.isType; };
14049 BareValue.prototype.get$needsTemp = function() {
14050 return false;
14051 }
14052 BareValue.prototype._shouldBindDynamically = function() {
14053 return false;
14054 }
14055 BareValue.prototype.get$code = function() {
14056 return this._code;
14057 }
14058 BareValue.prototype._ensureCode = function() {
14059 if (null == this._code) this._code = this.isType ? this.get$type().get$jsname( ) : this.home._makeThisCode();
14060 }
14061 BareValue.prototype._tryResolveMember = function(context, name, node) {
14062 var member = this.get$type().getMember(name);
14063 if ($eq$(member) || $ne$(member.get$declaringType(), this.get$type())) {
14064 var libMember = this.home.get$library().lookup(name, this.span);
14065 if (null != libMember) {
14066 return libMember.get$preciseMemberSet();
14067 }
14068 }
14069 this._ensureCode();
14070 return Value.prototype._tryResolveMember.call(this, context, name, node);
14071 }
14072 // ********** Code for SuperValue **************
14073 $inherits(SuperValue, Value);
14074 function SuperValue(parentType, span) {
14075 Value.call(this, parentType, "this", span);
14076 }
14077 SuperValue.prototype.get$needsTemp = function() {
14078 return false;
14079 }
14080 SuperValue.prototype.get$isSuper = function() {
14081 return true;
14082 }
14083 SuperValue.prototype._shouldBindDynamically = function() {
14084 return false;
14085 }
14086 SuperValue.prototype._tryUnion = function(right) {
14087 return (right instanceof SuperValue) ? this : null;
14088 }
14089 // ********** Code for ThisValue **************
14090 $inherits(ThisValue, Value);
14091 function ThisValue(type, code, span) {
14092 Value.call(this, type, code, span);
14093 }
14094 ThisValue.prototype.get$needsTemp = function() {
14095 return false;
14096 }
14097 ThisValue.prototype._shouldBindDynamically = function() {
14098 return false;
14099 }
14100 ThisValue.prototype._tryUnion = function(right) {
14101 return (right instanceof ThisValue) ? this : null;
14102 }
14103 // ********** Code for TypeValue **************
14104 $inherits(TypeValue, Value);
14105 function TypeValue(type, span) {
14106 Value.call(this, type, null, span);
14107 }
14108 TypeValue.prototype.get$needsTemp = function() {
14109 return false;
14110 }
14111 TypeValue.prototype.get$isType = function() {
14112 return true;
14113 }
14114 TypeValue.prototype._shouldBindDynamically = function() {
14115 return false;
14116 }
14117 TypeValue.prototype._tryUnion = function(right) {
14118 return (right instanceof TypeValue) ? this : null;
14119 }
14120 // ********** Code for VariableValue **************
14121 $inherits(VariableValue, Value);
14122 function VariableValue(staticType, code, span, isFinal, value) {
14123 this.isFinal = isFinal;
14124 this.value = VariableValue._unwrap(value);
14125 Value.call(this, staticType, code, span);
14126 }
14127 VariableValue.prototype.get$isFinal = function() { return this.isFinal; };
14128 VariableValue.prototype.get$value = function() { return this.value; };
14129 VariableValue._unwrap = function(v) {
14130 if (null == v) return null;
14131 if ((v instanceof VariableValue)) {
14132 v = v.get$dynamic().get$value();
14133 }
14134 return v;
14135 }
14136 VariableValue.prototype._tryUnion = function(right) {
14137 return Value.union(this.value, right);
14138 }
14139 VariableValue.prototype.get$needsTemp = function() {
14140 return false;
14141 }
14142 VariableValue.prototype.get$type = function() {
14143 return null != this.value ? this.value.get$type() : this.get$staticType();
14144 }
14145 VariableValue.prototype.get$staticType = function() {
14146 return this.type;
14147 }
14148 VariableValue.prototype.get$isConst = function() {
14149 return null != this.value ? this.value.get$isConst() : false;
14150 }
14151 VariableValue.prototype.replaceValue = function(v) {
14152 return new VariableValue(this.get$staticType(), this.get$code(), this.span, th is.isFinal, v);
14153 }
14154 VariableValue.prototype.unop = function(kind, context, node) {
14155 if (this.value != null) {
14156 return this.replaceValue(this.value.unop(kind, context, node));
14157 }
14158 return Value.prototype.unop.call(this, kind, context, node);
14159 }
14160 VariableValue.prototype.binop = function(kind, other, context, node) {
14161 if (this.value != null) {
14162 return this.replaceValue(this.value.binop(kind, VariableValue._unwrap(other) , context, node));
14163 }
14164 return Value.prototype.binop.call(this, kind, other, context, node);
14165 }
14166 // ********** Code for CompilerException **************
14167 function CompilerException(_message, _location) {
14168 this._lang_message = _message;
14169 this._location = _location;
14170 }
14171 CompilerException.prototype.toString = function() {
14172 if (this._location != null) {
14173 return ("CompilerException: " + this._location.toMessageString(this._lang_me ssage));
14174 }
14175 else {
14176 return ("CompilerException: " + this._lang_message);
14177 }
14178 }
14179 CompilerException.prototype.toString$0 = CompilerException.prototype.toString;
14180 // ********** Code for CounterLog **************
14181 function CounterLog() {
14182 this.dynamicMethodCalls = (0);
14183 this.typeAsserts = (0);
14184 this.objectProtoMembers = (0);
14185 this.invokeCalls = (0);
14186 this.msetN = (0);
14187 }
14188 CounterLog.prototype.info = function() {
14189 if ($globals.options.legOnly) return;
14190 $globals.world.info(("Dynamically typed method calls: " + this.dynamicMethodCa lls));
14191 $globals.world.info(("Generated type assertions: " + this.typeAsserts));
14192 $globals.world.info(("Members on Object.prototype: " + this.objectProtoMembers ));
14193 $globals.world.info(("Invoke calls: " + this.invokeCalls));
14194 $globals.world.info(("msetN calls: " + this.msetN));
14195 }
14196 CounterLog.prototype.add = function(other) {
14197 this.dynamicMethodCalls = this.dynamicMethodCalls + other.dynamicMethodCalls;
14198 this.typeAsserts = this.typeAsserts + other.typeAsserts;
14199 this.objectProtoMembers = this.objectProtoMembers + other.objectProtoMembers;
14200 this.invokeCalls = this.invokeCalls + other.invokeCalls;
14201 this.msetN = this.msetN + other.msetN;
14202 }
14203 // ********** Code for World **************
14204 function World(files) {
14205 this.errors = (0);
14206 this.warnings = (0);
14207 this.dartBytesRead = (0);
14208 this.jsBytesWritten = (0);
14209 this.seenFatal = false;
14210 this.files = files;
14211 this.libraries = new HashMapImplementation();
14212 this._todo = [];
14213 this._members = new HashMapImplementation();
14214 this._topNames = new HashMapImplementation();
14215 this._hazardousMemberNames = new HashSetImplementation_dart_core_String();
14216 this.reader = new LibraryReader();
14217 this.counters = new CounterLog();
14218 }
14219 World.prototype.get$functionType = function() { return this.functionType; };
14220 World.prototype.init = function() {
14221 this._addHazardousMemberName("split");
14222 this.corelib = new Library(this.readFile("dart:core"));
14223 this.libraries.$setindex("dart:core", this.corelib);
14224 this._todo.add(this.corelib);
14225 this.coreimpl = this.getOrAddLibrary("dart:coreimpl");
14226 this.voidType = this.corelib.addType("void", null, false);
14227 this.dynamicType = this.corelib.addType("Dynamic", null, false);
14228 this.varType = this.dynamicType;
14229 this.objectType = this.corelib.addType("Object", null, true);
14230 this.numType = this.corelib.addType("num", null, false);
14231 this.intType = this.corelib.addType("int", null, false);
14232 this.doubleType = this.corelib.addType("double", null, false);
14233 this.boolType = this.corelib.addType("bool", null, false);
14234 this.stringType = this.corelib.addType("String", null, false);
14235 this.listType = this.corelib.addType("List", null, false);
14236 this.mapType = this.corelib.addType("Map", null, false);
14237 this.functionType = this.corelib.addType("Function", null, false);
14238 this.typeErrorType = this.corelib.addType("TypeError", null, true);
14239 this.numImplType = this.coreimpl.addType("NumImplementation", null, true);
14240 this.stringImplType = this.coreimpl.addType("StringImplementation", null, true );
14241 this.immutableListType = this.coreimpl.addType("ImmutableList", null, true);
14242 this.listFactoryType = this.coreimpl.addType("ListFactory", null, true);
14243 this.functionImplType = this.coreimpl.addType("_FunctionImplementation", null, true);
14244 this.nonNullBool = new NonNullableType(this.boolType);
14245 }
14246 World.prototype._addHazardousMemberName = function(name) {
14247 return this._hazardousMemberNames.add(name);
14248 }
14249 World.prototype._addMember = function(member) {
14250 if (member.get$isStatic()) {
14251 if (member.declaringType.get$isTop()) {
14252 this._addTopName(member);
14253 }
14254 return;
14255 }
14256 var mset = this._members.$index(member.name);
14257 if ($eq$(mset)) {
14258 mset = new MemberSet(member, true);
14259 this._members.$setindex(mset.get$name(), mset);
14260 }
14261 else {
14262 mset.get$members().add(member);
14263 }
14264 }
14265 World.prototype._addTopName = function(named) {
14266 if ((named instanceof Type) && named.get$isNative()) {
14267 if (named.get$avoidNativeName()) {
14268 this._addJavascriptTopName(new ExistingJsGlobal(named.get$nativeName(), na med), named.get$nativeName());
14269 }
14270 else {
14271 this._addJavascriptTopName(named, named.get$nativeName());
14272 }
14273 }
14274 this._addJavascriptTopName(named, named.get$jsname());
14275 }
14276 World.prototype._addJavascriptTopName = function(named, name) {
14277 var existing = this._topNames.$index(name);
14278 if ($eq$(existing)) {
14279 this._topNames.$setindex(name, named);
14280 return;
14281 }
14282 if ((null == existing ? null == (named) : existing === named)) {
14283 return;
14284 }
14285 this.info($add$(("mangling matching top level name \"" + named.get$jsname() + "\" in "), ("both \"" + named.get$library().get$jsname() + "\" and \"" + existin g.get$library().get$jsname() + "\"")));
14286 var existingPri = existing.get$jsnamePriority();
14287 var namedPri = named.get$jsnamePriority();
14288 if (existingPri > namedPri || namedPri == (0)) {
14289 this._renameJavascriptTopName(named);
14290 }
14291 else if (namedPri > existingPri) {
14292 this._renameJavascriptTopName(existing);
14293 }
14294 else {
14295 if (named.get$isNative()) {
14296 var msg = $add$($add$(("conflicting JS name \"" + name + "\" of same "), ( "priority " + existingPri + ": (already defined in) ")), ("" + existing.get$span ().get$locationText() + " with priority " + namedPri + ")"));
14297 $globals.world.info(msg, named.get$span(), existing.get$span());
14298 }
14299 else {
14300 this._renameJavascriptTopName(existing);
14301 }
14302 }
14303 }
14304 World.prototype._renameJavascriptTopName = function(named) {
14305 named._jsname = ("" + named.get$library().get$jsname() + "_" + named.get$jsnam e());
14306 var existing = this._topNames.$index(named.get$jsname());
14307 if ($ne$(existing) && $ne$(existing, named)) {
14308 $globals.world.internalError($add$(("name mangling failed for \"" + named.ge t$jsname() + "\" "), ("(\"" + named.get$jsname() + "\" defined also in " + exist ing.get$span().get$locationText() + ")")), named.get$span());
14309 }
14310 this._topNames.$setindex(named.get$jsname(), named);
14311 }
14312 World.prototype._addType = function(type) {
14313 if (!type.get$isTop()) this._addTopName(type);
14314 }
14315 World.prototype.toJsIdentifier = function(name) {
14316 if (name == null) return null;
14317 if (this._jsKeywords == null) {
14318 this._jsKeywords = HashSetImplementation.HashSetImplementation$from$factory( ["break", "case", "catch", "continue", "debugger", "default", "delete", "do", "e lse", "finally", "for", "function", "if", "in", "instanceof", "new", "return", " switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "clas s", "enum", "export", "extends", "import", "super", "implements", "interface", " let", "package", "private", "protected", "public", "static", "yield", "native"]) ;
14319 }
14320 if (this._jsKeywords.contains(name)) {
14321 return $add$(name, "_");
14322 }
14323 else {
14324 return name.replaceAll("$", "$$").replaceAll(":", "$");
14325 }
14326 }
14327 World.prototype.compileAndSave = function() {
14328 var success = this.compile();
14329 if ($globals.options.outfile != null) {
14330 if (success) {
14331 var code = $globals.world.getGeneratedCode();
14332 if (!$globals.options.outfile.endsWith(".js")) {
14333 code = ("#!/usr/bin/env node\n" + code);
14334 }
14335 $globals.world.files.writeString($globals.options.outfile, code);
14336 }
14337 else {
14338 $globals.world.files.writeString($globals.options.outfile, "throw 'Sorry, but I could not generate reasonable code to run.\\n';");
14339 }
14340 }
14341 return success;
14342 }
14343 World.prototype.compile = function() {
14344 if ($globals.options.dartScript == null) {
14345 this.fatal("no script provided to compile");
14346 return false;
14347 }
14348 try {
14349 if ($globals.options.legOnly) {
14350 this.info(("[leg] compiling " + $globals.options.dartScript));
14351 }
14352 else {
14353 this.info(("compiling " + $globals.options.dartScript + " with corelib " + this.corelib));
14354 }
14355 if (!this.runLeg()) this.runCompilationPhases();
14356 } catch (exc) {
14357 exc = _toDartException(exc);
14358 if (this.get$hasErrors() && !$globals.options.throwOnErrors) {
14359 }
14360 else {
14361 throw exc;
14362 }
14363 }
14364 this.printStatus();
14365 return !this.get$hasErrors();
14366 }
14367 World.prototype.runLeg = function() {
14368 var $this = this; // closure support
14369 if (!$globals.options.legOnly) return false;
14370 if ($globals.legCompile == null) {
14371 this.fatal("requested leg enabled, but no leg compiler available");
14372 }
14373 var res = this.withTiming("[leg] compile", (function () {
14374 return $globals.legCompile($this);
14375 })
14376 );
14377 if (!res && $globals.options.legOnly) {
14378 this.fatal(("Leg could not compile " + $globals.options.dartScript));
14379 return true;
14380 }
14381 return res;
14382 }
14383 World.prototype.runCompilationPhases = function() {
14384 var $this = this; // closure support
14385 var lib = this.withTiming("first pass", (function () {
14386 return $this.processDartScript();
14387 })
14388 );
14389 this.withTiming("resolve top level", this.get$resolveAll());
14390 this.withTiming("name safety", (function () {
14391 $this.nameSafety(lib);
14392 })
14393 );
14394 if ($globals.experimentalAwaitPhase != null) {
14395 this.withTiming("await translation", to$call$0($globals.experimentalAwaitPha se));
14396 }
14397 this.withTiming("analyze pass", (function () {
14398 $this.analyzeCode(lib);
14399 })
14400 );
14401 if ($globals.options.checkOnly) return;
14402 this.withTiming("generate code", (function () {
14403 $this.generateCode(lib);
14404 })
14405 );
14406 }
14407 World.prototype.getGeneratedCode = function() {
14408 if (this.legCode != null) {
14409 return this.legCode;
14410 }
14411 else {
14412 return this.frogCode;
14413 }
14414 }
14415 World.prototype.readFile = function(filename) {
14416 try {
14417 var sourceFile = this.reader.readFile(filename);
14418 this.dartBytesRead = this.dartBytesRead + sourceFile.get$text().length;
14419 return sourceFile;
14420 } catch (e) {
14421 e = _toDartException(e);
14422 this.warning(("Error reading file: " + filename));
14423 return new SourceFile(filename, "");
14424 }
14425 }
14426 World.prototype.getOrAddLibrary = function(filename) {
14427 var library = this.libraries.$index(filename);
14428 if (library == null) {
14429 library = new Library(this.readFile(filename));
14430 this.info(("read library " + filename));
14431 if (!library.get$isCore() && !library.imports.some((function (li) {
14432 return li.get$library().get$isCore();
14433 })
14434 )) {
14435 library.imports.add(new LibraryImport(this.corelib));
14436 }
14437 this.libraries.$setindex(filename, library);
14438 this._todo.add(library);
14439 if (filename == "dart:dom") {
14440 this.dom = library;
14441 }
14442 else if (filename == "dart:isolate") {
14443 this.isolatelib = library;
14444 }
14445 }
14446 return library;
14447 }
14448 World.prototype.process = function() {
14449 while (this._todo.get$length() > (0)) {
14450 var todo = this._todo;
14451 this._todo = [];
14452 for (var $$i = todo.iterator(); $$i.hasNext(); ) {
14453 var lib = $$i.next();
14454 lib.visitSources();
14455 }
14456 }
14457 }
14458 World.prototype.processDartScript = function(script) {
14459 if (script == null) script = $globals.options.dartScript;
14460 var library = this.getOrAddLibrary(script);
14461 this.process();
14462 return library;
14463 }
14464 World.prototype.resolveAll = function() {
14465 var $$list = this.libraries.getValues();
14466 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
14467 var lib = $$i.next();
14468 lib.resolve();
14469 }
14470 var $$list = this.libraries.getValues();
14471 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
14472 var lib = $$i.next();
14473 lib.postResolveChecks();
14474 }
14475 }
14476 World.prototype.get$resolveAll = function() {
14477 return this.resolveAll.bind(this);
14478 }
14479 World.prototype.nameSafety = function(rootLib) {
14480 this.makePrivateMembersUnique(rootLib);
14481 this.avoidHazardousMemberNames();
14482 }
14483 World.prototype.makePrivateMembersUnique = function(rootLib) {
14484 var usedNames = new HashSetImplementation_dart_core_String();
14485 function process(lib) {
14486 var $$list = lib.get$_privateMembers().getKeys();
14487 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
14488 var name = $$i.next();
14489 if (usedNames.contains$1(name)) {
14490 var mset = lib.get$_privateMembers().$index(name);
14491 var uniqueName = ("_" + lib.get$jsname() + mset.get$jsname());
14492 mset.set$jsname(uniqueName);
14493 var $list0 = mset.get$members();
14494 for (var $i0 = $list0.iterator(); $i0.hasNext(); ) {
14495 var member = $i0.next();
14496 member.set$_jsname(uniqueName);
14497 }
14498 }
14499 else {
14500 usedNames.add(name);
14501 }
14502 }
14503 }
14504 var visited = new HashSetImplementation_Library();
14505 function visit(lib) {
14506 if (visited.contains$1(lib)) return;
14507 visited.add(lib);
14508 process(lib);
14509 var $$list = lib.get$imports();
14510 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
14511 var import_ = $$i.next();
14512 visit(import_.get$library());
14513 }
14514 }
14515 visit(rootLib);
14516 }
14517 World.prototype.avoidHazardousMemberNames = function() {
14518 var $this = this; // closure support
14519 function rename(jsname) {
14520 if ($this._hazardousMemberNames.contains(jsname)) {
14521 jsname = ("" + jsname + "$_");
14522 }
14523 return jsname;
14524 }
14525 var $$list = this._members.getKeys();
14526 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
14527 var name = $$i.next();
14528 var mset = this._members.$index(name);
14529 var renamed = false;
14530 var $list0 = mset.get$members();
14531 for (var $i0 = $list0.iterator(); $i0.hasNext(); ) {
14532 var member = $i0.next();
14533 if (!member.get$isNative() || ((member instanceof MethodMember) && member. get$hasNativeBody())) {
14534 var oldName = member.get$_jsname();
14535 member.set$_jsname(rename(oldName));
14536 if (member.get$_jsname() != oldName) renamed = true;
14537 }
14538 }
14539 if (renamed) {
14540 mset.set$jsname(rename(mset.get$jsname()));
14541 }
14542 }
14543 }
14544 World.prototype.findMainMethod = function(lib) {
14545 var main = lib.lookup("main", lib.get$span());
14546 if ($eq$(main)) {
14547 if (!$globals.options.checkOnly) this.fatal("no main method specified");
14548 }
14549 return main;
14550 }
14551 World.prototype.analyzeCode = function(lib) {
14552 this.gen = new WorldGenerator(this.findMainMethod(lib), new CodeWriter());
14553 this.gen.analyze();
14554 }
14555 World.prototype.generateCode = function(lib) {
14556 this.gen.run();
14557 this.frogCode = this.gen.writer.get$text();
14558 this.jsBytesWritten = this.frogCode.length;
14559 this.gen = null;
14560 }
14561 World.prototype._lang_message = function(color, prefix, message, span, span1, sp an2, throwing) {
14562 if (this.messageHandler != null) {
14563 this.messageHandler(prefix, message, span);
14564 if (span1 != null) {
14565 this.messageHandler(prefix, message, span1);
14566 }
14567 if (span2 != null) {
14568 this.messageHandler(prefix, message, span2);
14569 }
14570 }
14571 else {
14572 var messageWithPrefix = $globals.options.useColors ? ($add$($add$($add$(colo r, prefix), $globals._NO_COLOR), message)) : ($add$(prefix, message));
14573 var text = messageWithPrefix;
14574 if (span != null) {
14575 text = span.toMessageString(messageWithPrefix);
14576 }
14577 print$(text);
14578 if (span1 != null) {
14579 print$(span1.toMessageString(messageWithPrefix));
14580 }
14581 if (span2 != null) {
14582 print$(span2.toMessageString(messageWithPrefix));
14583 }
14584 }
14585 if (throwing) {
14586 $throw(new CompilerException($add$(prefix, message), span));
14587 }
14588 }
14589 World.prototype.error = function(message, span, span1, span2) {
14590 this.errors++;
14591 this._lang_message($globals._RED_COLOR, "error: ", message, span, span1, span2 , $globals.options.throwOnErrors);
14592 }
14593 World.prototype.warning = function(message, span, span1, span2) {
14594 if ($globals.options.warningsAsErrors) {
14595 this.error(message, span, span1, span2);
14596 return;
14597 }
14598 this.warnings++;
14599 if ($globals.options.showWarnings) {
14600 this._lang_message($globals._MAGENTA_COLOR, "warning: ", message, span, span 1, span2, $globals.options.throwOnWarnings);
14601 }
14602 }
14603 World.prototype.fatal = function(message, span, span1, span2) {
14604 this.errors++;
14605 this.seenFatal = true;
14606 this._lang_message($globals._RED_COLOR, "fatal: ", message, span, span1, span2 , $globals.options.throwOnFatal || $globals.options.throwOnErrors);
14607 }
14608 World.prototype.internalError = function(message, span, span1, span2) {
14609 this._lang_message($globals._NO_COLOR, "We are sorry, but...", message, span, span1, span2, true);
14610 }
14611 World.prototype.info = function(message, span, span1, span2) {
14612 if ($globals.options.showInfo) {
14613 this._lang_message($globals._GREEN_COLOR, "info: ", message, span, span1, sp an2, false);
14614 }
14615 }
14616 World.prototype.withoutForceDynamic = function(fn) {
14617 var oldForceDynamic = $globals.options.forceDynamic;
14618 $globals.options.forceDynamic = false;
14619 try {
14620 return fn();
14621 } finally {
14622 $globals.options.forceDynamic = oldForceDynamic;
14623 }
14624 }
14625 World.prototype.get$hasErrors = function() {
14626 return this.errors > (0);
14627 }
14628 World.prototype.printStatus = function() {
14629 this.counters.info();
14630 this.info(("compiled " + this.dartBytesRead + " bytes Dart -> " + this.jsBytes Written + " bytes JS"));
14631 if (this.get$hasErrors()) {
14632 print$(("compilation failed with " + this.errors + " errors"));
14633 }
14634 else {
14635 if (this.warnings > (0)) {
14636 this.info(("compilation completed successfully with " + this.warnings + " warnings"));
14637 }
14638 else {
14639 this.info("compilation completed sucessfully");
14640 }
14641 }
14642 }
14643 World.prototype.withTiming = function(name, f) {
14644 var sw = new StopwatchImplementation();
14645 sw.start();
14646 var result = f();
14647 sw.stop();
14648 this.info(("" + name + " in " + sw.elapsedInMs() + "msec"));
14649 return result;
14650 }
14651 // ********** Code for FrogOptions **************
14652 function FrogOptions(homedir, args, files) {
14653 this.config = "dev";
14654 this.legOnly = false;
14655 this.allowMockCompilation = false;
14656 this.enableAsserts = false;
14657 this.enableTypeChecks = false;
14658 this.warningsAsErrors = false;
14659 this.verifyImplements = false;
14660 this.compileAll = false;
14661 this.forceDynamic = false;
14662 this.dietParse = false;
14663 this.compileOnly = false;
14664 this.inferTypes = false;
14665 this.checkOnly = false;
14666 this.ignoreUnrecognizedFlags = false;
14667 this.disableBoundsChecks = false;
14668 this.throwOnErrors = false;
14669 this.throwOnWarnings = false;
14670 this.throwOnFatal = false;
14671 this.showInfo = false;
14672 this.showWarnings = true;
14673 this.useColors = true;
14674 this.maxInferenceIterations = (4);
14675 if ($eq$(this.config, "dev")) {
14676 this.libDir = joinPaths(homedir, "/lib");
14677 }
14678 else if ($eq$(this.config, "sdk")) {
14679 this.libDir = joinPaths(homedir, "/../lib");
14680 }
14681 else {
14682 $globals.world.error(("Invalid configuration " + this.config));
14683 $throw("Invalid configuration");
14684 }
14685 var passedLibDir = false;
14686 this.childArgs = [];
14687 loop:
14688 for (var i = (2);
14689 i < args.get$length(); i++) {
14690 var arg = args.$index(i);
14691 if (this.tryParseSimpleOption(arg)) continue;
14692 if (arg.endsWith(".dart")) {
14693 this.dartScript = arg;
14694 this.childArgs = args.getRange(i + (1), args.get$length() - i - (1));
14695 break loop;
14696 }
14697 else if (arg.startsWith("--out=")) {
14698 this.outfile = arg.substring$1("--out=".length);
14699 }
14700 else if (arg.startsWith("--libdir=")) {
14701 this.libDir = arg.substring$1("--libdir=".length);
14702 passedLibDir = true;
14703 }
14704 else if (!this.ignoreUnrecognizedFlags) {
14705 print$(("unrecognized flag: \"" + arg + "\""));
14706 }
14707 }
14708 if (!passedLibDir && $eq$(this.config, "dev") && !files.fileExists(this.libDir )) {
14709 var temp = "frog/lib";
14710 if (files.fileExists(temp)) {
14711 this.libDir = temp;
14712 }
14713 else {
14714 this.libDir = "lib";
14715 }
14716 }
14717 }
14718 FrogOptions.prototype.tryParseSimpleOption = function(option) {
14719 if (!option.startsWith("--")) return false;
14720 switch (option.replaceAll("_", "-")) {
14721 case "--leg":
14722 case "--enable-leg":
14723 case "--leg-only":
14724
14725 this.legOnly = true;
14726 return true;
14727
14728 case "--allow-mock-compilation":
14729
14730 this.allowMockCompilation = true;
14731 return true;
14732
14733 case "--enable-asserts":
14734
14735 this.enableAsserts = true;
14736 return true;
14737
14738 case "--enable-type-checks":
14739
14740 this.enableTypeChecks = true;
14741 this.enableAsserts = true;
14742 return true;
14743
14744 case "--verify-implements":
14745
14746 this.verifyImplements = true;
14747 return true;
14748
14749 case "--compile-all":
14750
14751 this.compileAll = true;
14752 return true;
14753
14754 case "--check-only":
14755
14756 this.checkOnly = true;
14757 return true;
14758
14759 case "--diet-parse":
14760
14761 this.dietParse = true;
14762 return true;
14763
14764 case "--ignore-unrecognized-flags":
14765
14766 this.ignoreUnrecognizedFlags = true;
14767 return true;
14768
14769 case "--verbose":
14770
14771 this.showInfo = true;
14772 return true;
14773
14774 case "--suppress-warnings":
14775
14776 this.showWarnings = false;
14777 return true;
14778
14779 case "--warnings-as-errors":
14780
14781 this.warningsAsErrors = true;
14782 return true;
14783
14784 case "--throw-on-errors":
14785
14786 this.throwOnErrors = true;
14787 return true;
14788
14789 case "--throw-on-warnings":
14790
14791 this.throwOnWarnings = true;
14792 return true;
14793
14794 case "--compile-only":
14795
14796 this.compileOnly = true;
14797 return true;
14798
14799 case "--Xforce-dynamic":
14800
14801 this.forceDynamic = true;
14802 return true;
14803
14804 case "--no-colors":
14805
14806 this.useColors = false;
14807 return true;
14808
14809 case "--Xinfer-types":
14810
14811 this.inferTypes = true;
14812 return true;
14813
14814 case "--enable-checked-mode":
14815 case "--checked":
14816
14817 this.enableTypeChecks = true;
14818 this.enableAsserts = true;
14819 return true;
14820
14821 case "--unchecked":
14822
14823 this.disableBoundsChecks = true;
14824 return true;
14825
14826 }
14827 return false;
14828 }
14829 // ********** Code for LibraryReader **************
14830 function LibraryReader() {
14831 if ($eq$($globals.options.config, "dev")) {
14832 this._specialLibs = _map(["dart:core", joinPaths($globals.options.libDir, "c orelib.dart"), "dart:coreimpl", joinPaths($globals.options.libDir, "corelib_impl .dart"), "dart:html", joinPaths($globals.options.libDir, "../../lib/html/frog/ht ml_frog.dart"), "dart:dom", joinPaths($globals.options.libDir, "../../lib/dom/fr og/dom_frog.dart"), "dart:json", joinPaths($globals.options.libDir, "../../lib/j son/json_frog.dart"), "dart:io", joinPaths($globals.options.libDir, "../../lib/c ompiler/implementation/lib/io.dart"), "dart:isolate", joinPaths($globals.options .libDir, "../../lib/isolate/isolate_frog.dart"), "dart:uri", joinPaths($globals. options.libDir, "../../lib/uri/uri.dart"), "dart:utf", joinPaths($globals.option s.libDir, "../../lib/utf/utf.dart")]);
14833 }
14834 else if ($eq$($globals.options.config, "sdk")) {
14835 this._specialLibs = _map(["dart:core", joinPaths($globals.options.libDir, "c ore/core_frog.dart"), "dart:coreimpl", joinPaths($globals.options.libDir, "corei mpl/coreimpl_frog.dart"), "dart:html", joinPaths($globals.options.libDir, "html/ html_frog.dart"), "dart:dom", joinPaths($globals.options.libDir, "dom/dom_frog.d art"), "dart:isolate", joinPaths($globals.options.libDir, "isolate/isolate_frog. dart"), "dart:json", joinPaths($globals.options.libDir, "json/json_frog.dart"), "dart:uri", joinPaths($globals.options.libDir, "uri/uri.dart"), "dart:utf", join Paths($globals.options.libDir, "utf/utf.dart")]);
14836 }
14837 else {
14838 $globals.world.error(("Invalid configuration " + $globals.options.config));
14839 }
14840 }
14841 LibraryReader.prototype.readFile = function(fullName) {
14842 var filename;
14843 if (fullName.startsWith("package:")) {
14844 filename = joinPaths(dirname($globals.options.dartScript), joinPaths("packag es", fullName.substring("package:".length)));
14845 }
14846 else {
14847 filename = this._specialLibs.$index(fullName);
14848 }
14849 if (filename == null) {
14850 filename = fullName;
14851 }
14852 if ($globals.world.files.fileExists(filename)) {
14853 return new SourceFile(filename, $globals.world.files.readAll(filename));
14854 }
14855 else {
14856 $globals.world.error(("File not found: " + filename));
14857 return new SourceFile(filename, "");
14858 }
14859 }
14860 // ********** Code for VarMember **************
14861 function VarMember(name) {
14862 this.isGenerated = false;
14863 this.name = name;
14864 }
14865 VarMember.prototype.get$name = function() { return this.name; };
14866 VarMember.prototype.get$isGenerated = function() { return this.isGenerated; };
14867 VarMember.prototype.get$body = function() {
14868 return null;
14869 }
14870 VarMember.prototype.get$returnType = function() {
14871 return $globals.world.varType;
14872 }
14873 VarMember.prototype.invoke = function(context, node, target, args) {
14874 return new Value(this.get$returnType(), ("" + target.get$code() + "." + this.n ame + "(" + args.getCode() + ")"), node.span);
14875 }
14876 // ********** Code for VarFunctionStub **************
14877 $inherits(VarFunctionStub, VarMember);
14878 function VarFunctionStub(name, callArgs) {
14879 this.args = callArgs.toCallStubArgs();
14880 VarMember.call(this, name);
14881 $globals.world.functionImplType.markUsed();
14882 $globals.world.gen.genMethod($globals.world.functionImplType.getMember("_genSt ub"));
14883 }
14884 VarFunctionStub.prototype.invoke = function(context, node, target, args) {
14885 return VarMember.prototype.invoke.call(this, context, node, target, args);
14886 }
14887 VarFunctionStub.prototype.generate = function(code) {
14888 this.isGenerated = true;
14889 if (this.args.get$hasNames()) {
14890 this.generateNamed(code);
14891 }
14892 else {
14893 this.generatePositional(code);
14894 }
14895 }
14896 VarFunctionStub.prototype.generatePositional = function(w) {
14897 var arity = this.args.get$length();
14898 w.enterBlock(("Function.prototype.to$" + this.name + " = function() {"));
14899 w.writeln(("this." + this.name + " = this._genStub(" + arity + ");"));
14900 w.writeln(("this.to$" + this.name + " = function() { return this." + this.name + "; };"));
14901 w.writeln(("return this." + this.name + ";"));
14902 w.exitBlock("};");
14903 var argsCode = this.args.getCode();
14904 w.enterBlock(("Function.prototype." + this.name + " = function(" + argsCode + ") {"));
14905 w.writeln(("return this.to$" + this.name + "()(" + argsCode + ");"));
14906 w.exitBlock("};");
14907 w.writeln(("function to$" + this.name + "(f) { return f && f.to$" + this.name + "(); }"));
14908 }
14909 VarFunctionStub.prototype.generateNamed = function(w) {
14910 var named = Strings.join(this.args.getNames(), "\", \"");
14911 var argsCode = this.args.getCode();
14912 w.enterBlock(("Function.prototype." + this.name + " = function(" + argsCode + ") {"));
14913 w.writeln(("this." + this.name + " = this._genStub(" + this.args.get$length() + ", [\"" + named + "\"]);"));
14914 w.writeln(("return this." + this.name + "(" + argsCode + ");"));
14915 w.exitBlock("}");
14916 }
14917 // ********** Code for VarMethodStub **************
14918 $inherits(VarMethodStub, VarMember);
14919 function VarMethodStub(name, member, args, body) {
14920 this.member = member;
14921 this.args = args;
14922 this.body = body;
14923 VarMember.call(this, name);
14924 }
14925 VarMethodStub.prototype.get$body = function() { return this.body; };
14926 VarMethodStub.prototype.get$isHidden = function() {
14927 return this.member != null ? this.member.declaringType.get$isHiddenNativeType( ) : false;
14928 }
14929 VarMethodStub.prototype.get$returnType = function() {
14930 return this.member != null ? this.member.get$returnType() : $globals.world.var Type;
14931 }
14932 VarMethodStub.prototype.get$declaringType = function() {
14933 return this.member != null ? this.member.declaringType : $globals.world.object Type;
14934 }
14935 VarMethodStub.prototype.generate = function(code) {
14936 this.isGenerated = true;
14937 if (!this.get$isHidden() && this._useDirectCall(this.args)) {
14938 $globals.world.gen._writePrototypePatch(this.get$declaringType(), this.name, $globals.world.gen._prototypeOf(this.get$declaringType(), this.member.get$jsnam e()), code, true);
14939 }
14940 else {
14941 var suffix = $globals.world.gen._writePrototypePatch(this.get$declaringType( ), this.name, ("function(" + this.args.getCode() + ") {"), code, false);
14942 if (!suffix.endsWith(";")) {
14943 suffix = $add$(suffix, ";");
14944 }
14945 if (this._needsExactTypeCheck()) {
14946 code.enterBlock(("if (Object.getPrototypeOf(this).hasOwnProperty(\"" + thi s.name + "\")) {"));
14947 code.writeln(("" + this.body + ";"));
14948 code.exitBlock("}");
14949 var argsCode = this.args.getCode();
14950 if (argsCode != "") argsCode = $add$(", ", argsCode);
14951 code.writeln(("return Object.prototype." + this.name + ".call(this" + args Code + ");"));
14952 code.exitBlock(suffix);
14953 }
14954 else {
14955 code.writeln(("" + this.body + ";"));
14956 code.exitBlock(suffix);
14957 }
14958 }
14959 }
14960 VarMethodStub.prototype._needsExactTypeCheck = function() {
14961 var $this = this; // closure support
14962 if (this.member == null || this.member.declaringType.get$isObject()) return fa lse;
14963 var members = this.member.get$potentialMemberSet().members;
14964 return members.filter((function (m) {
14965 return $ne$(m, $this.member) && m.get$declaringType().get$isHiddenNativeType ();
14966 })
14967 ).get$length() >= (1);
14968 }
14969 VarMethodStub.prototype._useDirectCall = function(args) {
14970 if ((this.member instanceof MethodMember) && !this.member.declaringType.get$ha sNativeSubtypes()) {
14971 var method = this.member;
14972 if (method.needsArgumentConversion(args)) {
14973 return false;
14974 }
14975 for (var i = args.get$length();
14976 i < method.parameters.get$length(); i++) {
14977 if (method.parameters.$index(i).value.get$code() != "null") {
14978 return false;
14979 }
14980 }
14981 return method.namesInHomePositions(args);
14982 }
14983 else {
14984 return false;
14985 }
14986 }
14987 // ********** Code for VarMethodSet **************
14988 $inherits(VarMethodSet, VarMember);
14989 function VarMethodSet(baseName, name, members, callArgs, returnType) {
14990 this.invoked = false;
14991 this.baseName = baseName;
14992 this.members = members;
14993 this.returnType = returnType;
14994 this.args = callArgs.toCallStubArgs();
14995 VarMember.call(this, name);
14996 }
14997 VarMethodSet.prototype.get$members = function() { return this.members; };
14998 VarMethodSet.prototype.get$returnType = function() { return this.returnType; };
14999 VarMethodSet.prototype.invoke = function(context, node, target, args) {
15000 this._invokeMembers(context, node);
15001 return VarMember.prototype.invoke.call(this, context, node, target, args);
15002 }
15003 VarMethodSet.prototype._invokeMembers = function(context, node) {
15004 if (this.invoked) return;
15005 this.invoked = true;
15006 var hasObjectType = false;
15007 var $$list = this.members;
15008 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
15009 var member = $$i.next();
15010 var type = member.get$declaringType();
15011 var target = new Value(type, "this", node.span);
15012 var result = member.invoke(context, node, target, this.args);
15013 var stub = new VarMethodStub(this.name, member, this.args, ("return " + resu lt.get$code()));
15014 type.get$varStubs().$setindex(stub.get$name(), stub);
15015 if (type.get$isObject()) hasObjectType = true;
15016 }
15017 if (!hasObjectType) {
15018 var target = new Value($globals.world.objectType, "this", node.span);
15019 var result = target.invokeNoSuchMethod(context, this.baseName, node, this.ar gs);
15020 var stub = new VarMethodStub(this.name, null, this.args, ("return " + result .get$code()));
15021 $globals.world.objectType.varStubs.$setindex(stub.get$name(), stub);
15022 }
15023 }
15024 VarMethodSet.prototype.generate = function(code) {
15025
15026 }
15027 // ********** Code for JsNames **************
15028 function JsNames() {}
15029 JsNames.get$reserved = function() {
15030 if (null == $globals.JsNames__reserved) {
15031 $globals.JsNames__reserved = new HashSetImplementation_dart_core_String();
15032 $globals.JsNames__reserved.addAll(const$0010);
15033 $globals.JsNames__reserved.addAll(const$0011);
15034 $globals.JsNames__reserved.addAll(const$0012);
15035 }
15036 return $globals.JsNames__reserved;
15037 }
15038 JsNames.getValid = function(name) {
15039 if (JsNames.get$reserved().contains(name)) {
15040 name = ("" + name + "$");
15041 }
15042 else if (name.contains("$")) {
15043 name = name.replaceAll("$", "$$");
15044 }
15045 return name;
15046 }
15047 // ********** Code for top level **************
15048 function _otherOperator(jsname, op) {
15049 return ("function " + jsname + "$complex$(x, y) {\n if (typeof(x) == 'number' ) {\n $throw(new IllegalArgumentException(y));\n } else if (typeof(x) == 'ob ject') {\n return x." + jsname + "(y);\n } else {\n $throw(new NoSuchMeth odException(x, \"operator " + op + "\", [y]));\n }\n}\nfunction " + jsname + "$ (x, y) {\n if (typeof(x) == 'number' && typeof(y) == 'number') return x " + op + " y;\n return " + jsname + "$complex$(x, y);\n}");
15050 }
15051 function map(source, mapper) {
15052 var result = new Array();
15053 if (!!(source && source.is$List())) {
15054 var list = source;
15055 result.set$length(list.get$length());
15056 for (var i = (0);
15057 i < list.get$length(); i++) {
15058 result.$setindex(i, mapper(list.$index(i)));
15059 }
15060 }
15061 else {
15062 for (var $$i = source.iterator(); $$i.hasNext(); ) {
15063 var item = $$i.next();
15064 result.add(mapper(item));
15065 }
15066 }
15067 return result;
15068 }
15069 function reduce(source, callback, initialValue) {
15070 var i = source.iterator();
15071 var current = initialValue;
15072 if ($eq$(current) && i.hasNext()) {
15073 current = i.next();
15074 }
15075 while (i.hasNext()) {
15076 current = callback.call$2(current, i.next());
15077 }
15078 return current;
15079 }
15080 function orderValuesByKeys(map) {
15081 var keys = map.getKeys();
15082 keys.sort((function (x, y) {
15083 return x.compareTo(y);
15084 })
15085 );
15086 var values = [];
15087 for (var $$i = keys.iterator(); $$i.hasNext(); ) {
15088 var k = $$i.next();
15089 values.add(map.$index(k));
15090 }
15091 return values;
15092 }
15093 var world;
15094 var experimentalAwaitPhase;
15095 var legCompile;
15096 function initializeWorld(files) {
15097 $globals.world = new World(files);
15098 if (!$globals.options.legOnly) $globals.world.init();
15099 }
15100 function compile(homedir, args, files) {
15101 parseOptions(homedir, args, files);
15102 initializeWorld(files);
15103 return $globals.world.compileAndSave();
15104 }
15105 var options;
15106 function parseOptions(homedir, args, files) {
15107 $globals.options = new FrogOptions(homedir, args, files);
15108 }
15109 function _getCallStubName(name, args) {
15110 var nameBuilder = new StringBufferImpl(("" + name + "$" + args.get$bareCount() ));
15111 for (var i = args.get$bareCount();
15112 i < args.get$length(); i++) {
15113 var argName = args.getName(i);
15114 nameBuilder.add("$");
15115 if (argName.contains$1("$")) {
15116 nameBuilder.add(("" + argName.get$length()));
15117 }
15118 nameBuilder.add(argName);
15119 }
15120 return nameBuilder.toString$0();
15121 }
15122 // ********** Library minfrog **************
15123 // ********** Code for top level **************
15124 function main() {
15125 var homedir = path.dirname(fs.realpathSync(get$$process().get$argv().$index((1 ))));
15126 var argv = [];
15127 for (var i = (0);
15128 i < get$$process().get$argv().get$length(); i++) {
15129 argv.add(get$$process().get$argv().$index(i));
15130 if (i == (1)) {
15131 var terminal = get$$process().get$env().$index("TERM");
15132 if ($eq$(terminal) || !terminal.startsWith("xterm")) {
15133 argv.add("--no_colors");
15134 }
15135 }
15136 }
15137 if (compile(homedir, argv, new NodeFileSystem())) {
15138 var code = $globals.world.getGeneratedCode();
15139 if ($globals.options.compileOnly) {
15140 if ($globals.options.outfile != null) {
15141 print$(("Compilation succeded. Code generated in: " + $globals.options.o utfile));
15142 }
15143 else {
15144 print$("Compilation succeded.");
15145 }
15146 }
15147 else {
15148 get$$process().set$argv([argv.$index((0)), argv.$index((1))]);
15149 get$$process().get$argv().addAll($globals.options.childArgs);
15150 vm.runInNewContext(code, createSandbox());
15151 }
15152 }
15153 else {
15154 get$$process().exit((1));
15155 }
15156 }
15157 // 1 dynamic types.
15158 // 1 types
15159 // 0 !leaf
15160 // ********** Globals **************
15161 function $static_init(){
15162 $globals._GREEN_COLOR = "\x1b[32m";
15163 $globals._MAGENTA_COLOR = "\x1b[35m";
15164 $globals._NO_COLOR = "\x1b[0m";
15165 $globals._RED_COLOR = "\x1b[31m";
15166 }
15167 var const$0000 = Object.create(_DeletedKeySentinel.prototype, {});
15168 var const$0001 = Object.create(NoMoreElementsException.prototype, {});
15169 var const$0002 = Object.create(EmptyQueueException.prototype, {});
15170 var const$0006 = Object.create(IllegalAccessException.prototype, {});
15171 var const$0007 = ImmutableList.ImmutableList$from$factory([]);
15172 var const$0009 = new JSSyntaxRegExp("^[a-zA-Z]:/");
15173 var const$0010 = ImmutableList.ImmutableList$from$factory(["__PROTO__", "prototy pe", "constructor"]);
15174 var const$0011 = ImmutableList.ImmutableList$from$factory(["NaN", "Infinity", "u ndefined", "eval", "parseInt", "parseFloat", "isNan", "isFinite", "decodeURI", " decodeURIComponent", "encodeURI", "encodeURIComponent", "Object", "Function", "A rray", "String", "Boolean", "Number", "Date", "RegExp", "Error", "EvalError", "R angeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "Math", "a rguments", "escape", "unescape", "applicationCache", "closed", "Components", "co ntent", "controllers", "crypto", "defaultStatus", "dialogArguments", "directorie s", "document", "frameElement", "frames", "fullScreen", "globalStorage", "histor y", "innerHeight", "innerWidth", "length", "location", "locationbar", "localStor age", "menubar", "mozInnerScreenX", "mozInnerScreenY", "mozScreenPixelsPerCssPix el", "name", "navigator", "opener", "outerHeight", "outerWidth", "pageXOffset", "pageYOffset", "parent", "personalbar", "pkcs11", "returnValue", "screen", "scro llbars", "scrollMaxX", "scrollMaxY", "self", "sessionStorage", "sidebar", "statu s", "statusbar", "toolbar", "top", "window", "alert", "addEventListener", "atob" , "back", "blur", "btoa", "captureEvents", "clearInterval", "clearTimeout", "clo se", "confirm", "disableExternalCapture", "dispatchEvent", "dump", "enableExtern alCapture", "escape", "find", "focus", "forward", "GeckoActiveXObject", "getAtte ntion", "getAttentionWithCycleCount", "getComputedStyle", "getSelection", "home" , "maximize", "minimize", "moveBy", "moveTo", "open", "openDialog", "postMessage ", "print", "prompt", "QueryInterface", "releaseEvents", "removeEventListener", "resizeBy", "resizeTo", "restore", "routeEvent", "scroll", "scrollBy", "scrollBy Lines", "scrollByPages", "scrollTo", "setInterval", "setResizeable", "setTimeout ", "showModalDialog", "sizeToContent", "stop", "uuescape", "updateCommands", "XP CNativeWrapper", "XPCSafeJSOjbectWrapper", "onabort", "onbeforeunload", "onchang e", "onclick", "onclose", "oncontextmenu", "ondragdrop", "onerror", "onfocus", " onhashchange", "onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown", "o nmousemove", "onmouseout", "onmouseover", "onmouseup", "onmozorientation", "onpa int", "onreset", "onresize", "onscroll", "onselect", "onsubmit", "onunload", "on touchcancel", "ontouchend", "ontouchmove", "ontouchstart", "ongesturestart", "on gesturechange", "ongestureend", "uneval", "getPrototypeOf", "let", "yield", "abs tract", "int", "short", "boolean", "interface", "static", "byte", "long", "char" , "final", "native", "synchronized", "float", "package", "throws", "goto", "priv ate", "transient", "implements", "protected", "volatile", "double", "public", "a ttachEvent", "clientInformation", "clipboardData", "createPopup", "dialogHeight" , "dialogLeft", "dialogTop", "dialogWidth", "onafterprint", "onbeforedeactivate" , "onbeforeprint", "oncontrolselect", "ondeactivate", "onhelp", "onresizeend", " event", "external", "Debug", "Enumerator", "Global", "Image", "ActiveXObject", " VBArray", "Components", "toString", "getClass", "constructor", "prototype", "val ueOf", "Anchor", "Applet", "Attr", "Canvas", "CanvasGradient", "CanvasPattern", "CanvasRenderingContext2D", "CDATASection", "CharacterData", "Comment", "CSS2Pro perties", "CSSRule", "CSSStyleSheet", "Document", "DocumentFragment", "DocumentT ype", "DOMException", "DOMImplementation", "DOMParser", "Element", "Event", "Ext ernalInterface", "FlashPlayer", "Form", "Frame", "History", "HTMLCollection", "H TMLDocument", "HTMLElement", "IFrame", "Image", "Input", "JSObject", "KeyEvent", "Link", "Location", "MimeType", "MouseEvent", "Navigator", "Node", "NodeList", "Option", "Plugin", "ProcessingInstruction", "Range", "RangeException", "Screen" , "Select", "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextAre a", "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer", "XPathException", "X PathResult", "XSLTProcessor", "java", "Packages", "netscape", "sun", "JavaObject ", "JavaClass", "JavaArray", "JavaMember", "$wnd", "$doc", "$entry", "$moduleNam e", "$moduleBase", "$gwt_version", "$sessionId", "$stack", "$stackDepth", "$loca tion", "call"]);
15175 var const$0012 = ImmutableList.ImmutableList$from$factory(["break", "delete", "f unction", "return", "typeof", "case", "do", "if", "switch", "var", "catch", "els e", "in", "this", "void", "continue", "false", "instanceof", "throw", "while", " debugger", "finally", "new", "true", "with", "default", "for", "null", "try", "a bstract", "double", "goto", "native", "static", "boolean", "enum", "implements", "package", "super", "byte", "export", "import", "private", "synchronized", "cha r", "extends", "int", "protected", "throws", "class", "final", "interface", "pub lic", "transient", "const", "float", "long", "short", "volatile"]);
15176 var const$0013 = new JSSyntaxRegExp("^[a-zA-Z][a-zA-Z_$0-9]*$");
15177 var $globals = {};
15178 $static_init();
15179 if (typeof window != 'undefined' && typeof document != 'undefined' &&
15180 window.addEventListener && document.readyState == 'loading') {
15181 window.addEventListener('DOMContentLoaded', function(e) {
15182 main();
15183 });
15184 } else {
15185 main();
15186 }
OLDNEW
« no previous file with comments | « dart/frog/lib/node/node.dart ('k') | dart/frog/minfrog.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698