OLD | NEW |
(Empty) | |
| 1 // ********** Library dart:core ************** |
| 2 // ********** Natives dart:core ************** |
| 3 /** |
| 4 * Generates a dynamic call stub for a function. |
| 5 * Our goal is to create a stub method like this on-the-fly: |
| 6 * function($0, $1, capture) { return this($0, $1, true, capture); } |
| 7 * |
| 8 * This stub then replaces the dynamic one on Function, with one that is |
| 9 * specialized for that particular function, taking into account its default |
| 10 * arguments. |
| 11 */ |
| 12 Function.prototype.$genStub = function(argsLength, names) { |
| 13 // Fast path: if no named arguments and arg count matches |
| 14 if (this.length == argsLength && !names) { |
| 15 return this; |
| 16 } |
| 17 |
| 18 function $throwArgMismatch() { |
| 19 // TODO(jmesserly): better error message |
| 20 $throw(new ClosureArgumentMismatchException()); |
| 21 } |
| 22 |
| 23 var paramsNamed = this.$optional ? (this.$optional.length / 2) : 0; |
| 24 var paramsBare = this.length - paramsNamed; |
| 25 var argsNamed = names ? names.length : 0; |
| 26 var argsBare = argsLength - argsNamed; |
| 27 |
| 28 // Check we got the right number of arguments |
| 29 if (argsBare < paramsBare || argsLength > this.length || |
| 30 argsNamed > paramsNamed) { |
| 31 return $throwArgMismatch; |
| 32 } |
| 33 |
| 34 // First, fill in all of the default values |
| 35 var p = new Array(paramsBare); |
| 36 if (paramsNamed) { |
| 37 p = p.concat(this.$optional.slice(paramsNamed)); |
| 38 } |
| 39 // Fill in positional args |
| 40 var a = new Array(argsLength); |
| 41 for (var i = 0; i < argsBare; i++) { |
| 42 p[i] = a[i] = '$' + i; |
| 43 } |
| 44 // Then overwrite with supplied values for optional args |
| 45 var lastParameterIndex; |
| 46 var namesInOrder = true; |
| 47 for (var i = 0; i < argsNamed; i++) { |
| 48 var name = names[i]; |
| 49 a[i + argsBare] = name; |
| 50 var j = this.$optional.indexOf(name); |
| 51 if (j < 0 || j >= paramsNamed) { |
| 52 return $throwArgMismatch; |
| 53 } else if (lastParameterIndex && lastParameterIndex > j) { |
| 54 namesInOrder = false; |
| 55 } |
| 56 p[j + paramsBare] = name; |
| 57 lastParameterIndex = j; |
| 58 } |
| 59 |
| 60 if (this.length == argsLength && namesInOrder) { |
| 61 // Fast path #2: named arguments, but they're in order. |
| 62 return this; |
| 63 } |
| 64 |
| 65 // Note: using Function instead of 'eval' to get a clean scope. |
| 66 // TODO(jmesserly): evaluate the performance of these stubs. |
| 67 var f = 'function(' + a.join(',') + '){return $f(' + p.join(',') + ');}'; |
| 68 return new Function('$f', 'return ' + f + '').call(null, this); |
| 69 } |
| 70 function $throw(e) { |
| 71 // If e is not a value, we can use V8's captureStackTrace utility method. |
| 72 // TODO(jmesserly): capture the stack trace on other JS engines. |
| 73 if (e && (typeof e == 'object') && Error.captureStackTrace) { |
| 74 // TODO(jmesserly): this will clobber the e.stack property |
| 75 Error.captureStackTrace(e, $throw); |
| 76 } |
| 77 throw e; |
| 78 } |
| 79 Object.prototype.$index = function(i) { |
| 80 var proto = Object.getPrototypeOf(this); |
| 81 if (proto !== Object) { |
| 82 proto.$index = function(i) { return this[i]; } |
| 83 } |
| 84 return this[i]; |
| 85 } |
| 86 Array.prototype.$index = function(i) { return this[i]; } |
| 87 String.prototype.$index = function(i) { return this[i]; } |
| 88 Object.prototype.$setindex = function(i, value) { |
| 89 var proto = Object.getPrototypeOf(this); |
| 90 if (proto !== Object) { |
| 91 proto.$setindex = function(i, value) { return this[i] = value; } |
| 92 } |
| 93 return this[i] = value; |
| 94 } |
| 95 Array.prototype.$setindex = function(i, value) { return this[i] = value; } |
| 96 function $wrap_call$0(fn) { return fn; } |
| 97 function $wrap_call$1(fn) { return fn; } |
| 98 function $eq(x, y) { |
| 99 if (x == null) return y == null; |
| 100 return (typeof(x) == 'number' && typeof(y) == 'number') || |
| 101 (typeof(x) == 'boolean' && typeof(y) == 'boolean') || |
| 102 (typeof(x) == 'string' && typeof(y) == 'string') |
| 103 ? x == y : x.$eq(y); |
| 104 } |
| 105 // TODO(jimhug): Should this or should it not match equals? |
| 106 Object.prototype.$eq = function(other) { return this === other; } |
| 107 function $mod(x, y) { |
| 108 if (typeof(x) == 'number' && typeof(y) == 'number') { |
| 109 var result = x % y; |
| 110 if (result == 0) { |
| 111 return 0; // Make sure we don't return -0.0. |
| 112 } else if (result < 0) { |
| 113 if (y < 0) { |
| 114 return result - y; |
| 115 } else { |
| 116 return result + y; |
| 117 } |
| 118 } |
| 119 return result; |
| 120 } else { |
| 121 return x.$mod(y); |
| 122 } |
| 123 } |
| 124 function $ne(x, y) { |
| 125 if (x == null) return y != null; |
| 126 return (typeof(x) == 'number' && typeof(y) == 'number') || |
| 127 (typeof(x) == 'boolean' && typeof(y) == 'boolean') || |
| 128 (typeof(x) == 'string' && typeof(y) == 'string') |
| 129 ? x != y : !x.$eq(y); |
| 130 } |
| 131 function $truncdiv(x, y) { |
| 132 if (typeof(x) == 'number' && typeof(y) == 'number') { |
| 133 if (y == 0) $throw(new IntegerDivisionByZeroException()); |
| 134 var tmp = x / y; |
| 135 return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp); |
| 136 } else { |
| 137 return x.$truncdiv(y); |
| 138 } |
| 139 } |
| 140 // ********** Code for Object ************** |
| 141 Object.prototype.get$dynamic = function() { |
| 142 return this; |
| 143 } |
| 144 Object.prototype.noSuchMethod = function(name, args) { |
| 145 $throw(new NoSuchMethodException(this, name, args)); |
| 146 } |
| 147 Object.prototype._checkExtends$0 = function() { |
| 148 return this.noSuchMethod("_checkExtends", []); |
| 149 }; |
| 150 Object.prototype._checkNonStatic$1 = function($0) { |
| 151 return this.noSuchMethod("_checkNonStatic", [$0]); |
| 152 }; |
| 153 Object.prototype._get$3 = function($0, $1, $2) { |
| 154 return this.noSuchMethod("_get", [$0, $1, $2]); |
| 155 }; |
| 156 Object.prototype._get$3$isDynamic = function($0, $1, $2, isDynamic) { |
| 157 return this.noSuchMethod("_get", [$0, $1, $2, isDynamic]); |
| 158 }; |
| 159 Object.prototype._get$4 = function($0, $1, $2, $3) { |
| 160 return this.noSuchMethod("_get", [$0, $1, $2, $3]); |
| 161 }; |
| 162 Object.prototype._redraw$0 = function() { |
| 163 return this.noSuchMethod("_redraw", []); |
| 164 }; |
| 165 Object.prototype._set$4 = function($0, $1, $2, $3) { |
| 166 return this.noSuchMethod("_set", [$0, $1, $2, $3]); |
| 167 }; |
| 168 Object.prototype._set$4$isDynamic = function($0, $1, $2, $3, isDynamic) { |
| 169 return this.noSuchMethod("_set", [$0, $1, $2, $3, isDynamic]); |
| 170 }; |
| 171 Object.prototype._set$5 = function($0, $1, $2, $3, $4) { |
| 172 return this.noSuchMethod("_set", [$0, $1, $2, $3, $4]); |
| 173 }; |
| 174 Object.prototype._wrapDomCallback$2 = function($0, $1) { |
| 175 return this.noSuchMethod("_wrapDomCallback", [$0, $1]); |
| 176 }; |
| 177 Object.prototype.add$1 = function($0) { |
| 178 return this.noSuchMethod("add", [$0]); |
| 179 }; |
| 180 Object.prototype.addAll$1 = function($0) { |
| 181 return this.noSuchMethod("addAll", [$0]); |
| 182 }; |
| 183 Object.prototype.addDirectSubtype$1 = function($0) { |
| 184 return this.noSuchMethod("addDirectSubtype", [$0]); |
| 185 }; |
| 186 Object.prototype.addEventListener$3 = function($0, $1, $2) { |
| 187 return this.noSuchMethod("addEventListener", [$0, $1, $2]); |
| 188 }; |
| 189 Object.prototype.addMessage$1 = function($0) { |
| 190 return this.noSuchMethod("addMessage", [$0]); |
| 191 }; |
| 192 Object.prototype.addMethod$2 = function($0, $1) { |
| 193 return this.noSuchMethod("addMethod", [$0, $1]); |
| 194 }; |
| 195 Object.prototype.addSource$1 = function($0) { |
| 196 return this.noSuchMethod("addSource", [$0]); |
| 197 }; |
| 198 Object.prototype.appendChild$1 = function($0) { |
| 199 return this.noSuchMethod("appendChild", [$0]); |
| 200 }; |
| 201 Object.prototype.block$0 = function() { |
| 202 return this.noSuchMethod("block", []); |
| 203 }; |
| 204 Object.prototype.canInvoke$2 = function($0, $1) { |
| 205 return this.noSuchMethod("canInvoke", [$0, $1]); |
| 206 }; |
| 207 Object.prototype.checkFirstClass$1 = function($0) { |
| 208 return this.noSuchMethod("checkFirstClass", [$0]); |
| 209 }; |
| 210 Object.prototype.clear$0 = function() { |
| 211 return this.noSuchMethod("clear", []); |
| 212 }; |
| 213 Object.prototype.compareTo$1 = function($0) { |
| 214 return this.noSuchMethod("compareTo", [$0]); |
| 215 }; |
| 216 Object.prototype.compilationUnit$0 = function() { |
| 217 return this.noSuchMethod("compilationUnit", []); |
| 218 }; |
| 219 Object.prototype.computeValue$0 = function() { |
| 220 return this.noSuchMethod("computeValue", []); |
| 221 }; |
| 222 Object.prototype.contains$1 = function($0) { |
| 223 return this.noSuchMethod("contains", [$0]); |
| 224 }; |
| 225 Object.prototype.containsKey$1 = function($0) { |
| 226 return this.noSuchMethod("containsKey", [$0]); |
| 227 }; |
| 228 Object.prototype.convertTo$3 = function($0, $1, $2) { |
| 229 return this.noSuchMethod("convertTo", [$0, $1, $2]); |
| 230 }; |
| 231 Object.prototype.convertTo$4 = function($0, $1, $2, $3) { |
| 232 return this.noSuchMethod("convertTo", [$0, $1, $2, $3]); |
| 233 }; |
| 234 Object.prototype.copyWithNewType$2 = function($0, $1) { |
| 235 return this.noSuchMethod("copyWithNewType", [$0, $1]); |
| 236 }; |
| 237 Object.prototype.delete$2 = function($0, $1) { |
| 238 return this.noSuchMethod("delete", [$0, $1]); |
| 239 }; |
| 240 Object.prototype.end$0 = function() { |
| 241 return this.noSuchMethod("end", []); |
| 242 }; |
| 243 Object.prototype.endsWith$1 = function($0) { |
| 244 return this.noSuchMethod("endsWith", [$0]); |
| 245 }; |
| 246 Object.prototype.ensureSubtypeOf$3 = function($0, $1, $2) { |
| 247 return this.noSuchMethod("ensureSubtypeOf", [$0, $1, $2]); |
| 248 }; |
| 249 Object.prototype.every$1 = function($0) { |
| 250 return this.noSuchMethod("every", [$0]); |
| 251 }; |
| 252 Object.prototype.filter$1 = function($0) { |
| 253 return this.noSuchMethod("filter", [$0]); |
| 254 }; |
| 255 Object.prototype.findTypeByName$1 = function($0) { |
| 256 return this.noSuchMethod("findTypeByName", [$0]); |
| 257 }; |
| 258 Object.prototype.focus$0 = function() { |
| 259 return this.noSuchMethod("focus", []); |
| 260 }; |
| 261 Object.prototype.forEach$1 = function($0) { |
| 262 return this.noSuchMethod("forEach", [$0]); |
| 263 }; |
| 264 Object.prototype.genValue$2 = function($0, $1) { |
| 265 return this.noSuchMethod("genValue", [$0, $1]); |
| 266 }; |
| 267 Object.prototype.generate$1 = function($0) { |
| 268 return this.noSuchMethod("generate", [$0]); |
| 269 }; |
| 270 Object.prototype.getBoundingClientRect$0 = function() { |
| 271 return this.noSuchMethod("getBoundingClientRect", []); |
| 272 }; |
| 273 Object.prototype.getColumn$2 = function($0, $1) { |
| 274 return this.noSuchMethod("getColumn", [$0, $1]); |
| 275 }; |
| 276 Object.prototype.getConstructor$1 = function($0) { |
| 277 return this.noSuchMethod("getConstructor", [$0]); |
| 278 }; |
| 279 Object.prototype.getFactory$2 = function($0, $1) { |
| 280 return this.noSuchMethod("getFactory", [$0, $1]); |
| 281 }; |
| 282 Object.prototype.getKeys$0 = function() { |
| 283 return this.noSuchMethod("getKeys", []); |
| 284 }; |
| 285 Object.prototype.getLine$1 = function($0) { |
| 286 return this.noSuchMethod("getLine", [$0]); |
| 287 }; |
| 288 Object.prototype.getLineColumn$1 = function($0) { |
| 289 return this.noSuchMethod("getLineColumn", [$0]); |
| 290 }; |
| 291 Object.prototype.getMember$1 = function($0) { |
| 292 return this.noSuchMethod("getMember", [$0]); |
| 293 }; |
| 294 Object.prototype.getOrMakeConcreteType$1 = function($0) { |
| 295 return this.noSuchMethod("getOrMakeConcreteType", [$0]); |
| 296 }; |
| 297 Object.prototype.getPosition$2 = function($0, $1) { |
| 298 return this.noSuchMethod("getPosition", [$0, $1]); |
| 299 }; |
| 300 Object.prototype.getValues$0 = function() { |
| 301 return this.noSuchMethod("getValues", []); |
| 302 }; |
| 303 Object.prototype.get_$3 = function($0, $1, $2) { |
| 304 return this.noSuchMethod("get_", [$0, $1, $2]); |
| 305 }; |
| 306 Object.prototype.hasNext$0 = function() { |
| 307 return this.noSuchMethod("hasNext", []); |
| 308 }; |
| 309 Object.prototype.hashCode$0 = function() { |
| 310 return this.noSuchMethod("hashCode", []); |
| 311 }; |
| 312 Object.prototype.indexOf$1 = function($0) { |
| 313 return this.noSuchMethod("indexOf", [$0]); |
| 314 }; |
| 315 Object.prototype.insertBefore$2 = function($0, $1) { |
| 316 return this.noSuchMethod("insertBefore", [$0, $1]); |
| 317 }; |
| 318 Object.prototype.insertText$2 = function($0, $1) { |
| 319 return this.noSuchMethod("insertText", [$0, $1]); |
| 320 }; |
| 321 Object.prototype.instanceOf$3$isTrue$forceCheck = function($0, $1, $2, isTrue, f
orceCheck) { |
| 322 return this.noSuchMethod("instanceOf", [$0, $1, $2, isTrue, forceCheck]); |
| 323 }; |
| 324 Object.prototype.instanceOf$4 = function($0, $1, $2, $3) { |
| 325 return this.noSuchMethod("instanceOf", [$0, $1, $2, $3]); |
| 326 }; |
| 327 Object.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 328 return this.noSuchMethod("invoke", [$0, $1, $2, $3]); |
| 329 }; |
| 330 Object.prototype.invoke$4$isDynamic = function($0, $1, $2, $3, isDynamic) { |
| 331 return this.noSuchMethod("invoke", [$0, $1, $2, $3, isDynamic]); |
| 332 }; |
| 333 Object.prototype.invoke$5 = function($0, $1, $2, $3, $4) { |
| 334 return this.noSuchMethod("invoke", [$0, $1, $2, $3, $4]); |
| 335 }; |
| 336 Object.prototype.is$List = function() { |
| 337 return false; |
| 338 }; |
| 339 Object.prototype.is$RegExp = function() { |
| 340 return false; |
| 341 }; |
| 342 Object.prototype.isAssignable$1 = function($0) { |
| 343 return this.noSuchMethod("isAssignable", [$0]); |
| 344 }; |
| 345 Object.prototype.isEmpty$0 = function() { |
| 346 return this.noSuchMethod("isEmpty", []); |
| 347 }; |
| 348 Object.prototype.isSubtypeOf$1 = function($0) { |
| 349 return this.noSuchMethod("isSubtypeOf", [$0]); |
| 350 }; |
| 351 Object.prototype.iterator$0 = function() { |
| 352 return this.noSuchMethod("iterator", []); |
| 353 }; |
| 354 Object.prototype.last$0 = function() { |
| 355 return this.noSuchMethod("last", []); |
| 356 }; |
| 357 Object.prototype.markUsed$0 = function() { |
| 358 return this.noSuchMethod("markUsed", []); |
| 359 }; |
| 360 Object.prototype.moveToOffset$1 = function($0) { |
| 361 return this.noSuchMethod("moveToOffset", [$0]); |
| 362 }; |
| 363 Object.prototype.namesInOrder$1 = function($0) { |
| 364 return this.noSuchMethod("namesInOrder", [$0]); |
| 365 }; |
| 366 Object.prototype.needsConversion$1 = function($0) { |
| 367 return this.noSuchMethod("needsConversion", [$0]); |
| 368 }; |
| 369 Object.prototype.next$0 = function() { |
| 370 return this.noSuchMethod("next", []); |
| 371 }; |
| 372 Object.prototype.offsetToPoint$1 = function($0) { |
| 373 return this.noSuchMethod("offsetToPoint", [$0]); |
| 374 }; |
| 375 Object.prototype.positionFromPoint$2 = function($0, $1) { |
| 376 return this.noSuchMethod("positionFromPoint", [$0, $1]); |
| 377 }; |
| 378 Object.prototype.provideFieldSyntax$0 = function() { |
| 379 return this.noSuchMethod("provideFieldSyntax", []); |
| 380 }; |
| 381 Object.prototype.providePropertySyntax$0 = function() { |
| 382 return this.noSuchMethod("providePropertySyntax", []); |
| 383 }; |
| 384 Object.prototype.removeChild$1 = function($0) { |
| 385 return this.noSuchMethod("removeChild", [$0]); |
| 386 }; |
| 387 Object.prototype.removeLast$0 = function() { |
| 388 return this.noSuchMethod("removeLast", []); |
| 389 }; |
| 390 Object.prototype.replaceAll$2 = function($0, $1) { |
| 391 return this.noSuchMethod("replaceAll", [$0, $1]); |
| 392 }; |
| 393 Object.prototype.replaceFirst$2 = function($0, $1) { |
| 394 return this.noSuchMethod("replaceFirst", [$0, $1]); |
| 395 }; |
| 396 Object.prototype.resolve$0 = function() { |
| 397 return this.noSuchMethod("resolve", []); |
| 398 }; |
| 399 Object.prototype.resolveTypeParams$1 = function($0) { |
| 400 return this.noSuchMethod("resolveTypeParams", [$0]); |
| 401 }; |
| 402 Object.prototype.select$0 = function() { |
| 403 return this.noSuchMethod("select", []); |
| 404 }; |
| 405 Object.prototype.setDefinition$1 = function($0) { |
| 406 return this.noSuchMethod("setDefinition", [$0]); |
| 407 }; |
| 408 Object.prototype.setProperty$2 = function($0, $1) { |
| 409 return this.noSuchMethod("setProperty", [$0, $1]); |
| 410 }; |
| 411 Object.prototype.set_$4 = function($0, $1, $2, $3) { |
| 412 return this.noSuchMethod("set_", [$0, $1, $2, $3]); |
| 413 }; |
| 414 Object.prototype.some$1 = function($0) { |
| 415 return this.noSuchMethod("some", [$0]); |
| 416 }; |
| 417 Object.prototype.sort$1 = function($0) { |
| 418 return this.noSuchMethod("sort", [$0]); |
| 419 }; |
| 420 Object.prototype.start$0 = function() { |
| 421 return this.noSuchMethod("start", []); |
| 422 }; |
| 423 Object.prototype.startsWith$1 = function($0) { |
| 424 return this.noSuchMethod("startsWith", [$0]); |
| 425 }; |
| 426 Object.prototype.substring$1 = function($0) { |
| 427 return this.noSuchMethod("substring", [$0]); |
| 428 }; |
| 429 Object.prototype.substring$2 = function($0, $1) { |
| 430 return this.noSuchMethod("substring", [$0, $1]); |
| 431 }; |
| 432 Object.prototype.toLeaf$0 = function() { |
| 433 return this.noSuchMethod("toLeaf", []); |
| 434 }; |
| 435 Object.prototype.toRoot$0 = function() { |
| 436 return this.noSuchMethod("toRoot", []); |
| 437 }; |
| 438 Object.prototype.toString$0 = function() { |
| 439 return this.toString(); |
| 440 }; |
| 441 Object.prototype.tokenizeInto$2 = function($0, $1) { |
| 442 return this.noSuchMethod("tokenizeInto", [$0, $1]); |
| 443 }; |
| 444 Object.prototype.visit$1 = function($0) { |
| 445 return this.noSuchMethod("visit", [$0]); |
| 446 }; |
| 447 Object.prototype.visitBinaryExpression$1 = function($0) { |
| 448 return this.noSuchMethod("visitBinaryExpression", [$0]); |
| 449 }; |
| 450 Object.prototype.visitPostfixExpression$1 = function($0) { |
| 451 return this.noSuchMethod("visitPostfixExpression", [$0]); |
| 452 }; |
| 453 Object.prototype.visitSources$0 = function() { |
| 454 return this.noSuchMethod("visitSources", []); |
| 455 }; |
| 456 Object.prototype.writeDefinition$2 = function($0, $1) { |
| 457 return this.noSuchMethod("writeDefinition", [$0, $1]); |
| 458 }; |
| 459 // ********** Code for Clock ************** |
| 460 function Clock() {} |
| 461 Clock.now = function() { |
| 462 return new Date().getTime(); |
| 463 } |
| 464 Clock.frequency = function() { |
| 465 return 1000; |
| 466 } |
| 467 // ********** Code for IllegalAccessException ************** |
| 468 function IllegalAccessException() { |
| 469 // Initializers done |
| 470 } |
| 471 IllegalAccessException.prototype.toString = function() { |
| 472 return "Attempt to modify an immutable object"; |
| 473 } |
| 474 IllegalAccessException.prototype.toString$0 = IllegalAccessException.prototype.t
oString; |
| 475 // ********** Code for NoSuchMethodException ************** |
| 476 function NoSuchMethodException(_receiver, _functionName, _arguments) { |
| 477 this._receiver = _receiver; |
| 478 this._functionName = _functionName; |
| 479 this._arguments = _arguments; |
| 480 // Initializers done |
| 481 } |
| 482 NoSuchMethodException.prototype.toString = function() { |
| 483 var sb = new StringBufferImpl(""); |
| 484 for (var i = 0; |
| 485 i < this._arguments.length; i++) { |
| 486 if (i > 0) { |
| 487 sb.add(", "); |
| 488 } |
| 489 sb.add(this._arguments.$index(i)); |
| 490 } |
| 491 sb.add("]"); |
| 492 return ("NoSuchMethodException - receiver: '" + this._receiver + "' ") + ("fun
ction name: '" + this._functionName + "' arguments: [" + sb + "]"); |
| 493 } |
| 494 NoSuchMethodException.prototype.toString$0 = NoSuchMethodException.prototype.toS
tring; |
| 495 // ********** Code for ObjectNotClosureException ************** |
| 496 function ObjectNotClosureException() { |
| 497 // Initializers done |
| 498 } |
| 499 ObjectNotClosureException.prototype.toString = function() { |
| 500 return "Object is not closure"; |
| 501 } |
| 502 ObjectNotClosureException.prototype.toString$0 = ObjectNotClosureException.proto
type.toString; |
| 503 // ********** Code for StackOverflowException ************** |
| 504 function StackOverflowException() { |
| 505 // Initializers done |
| 506 } |
| 507 StackOverflowException.prototype.toString = function() { |
| 508 return "Stack Overflow"; |
| 509 } |
| 510 StackOverflowException.prototype.toString$0 = StackOverflowException.prototype.t
oString; |
| 511 // ********** Code for BadNumberFormatException ************** |
| 512 function BadNumberFormatException() {} |
| 513 BadNumberFormatException.prototype.toString = function() { |
| 514 return ("BadNumberFormatException: '" + this._s + "'"); |
| 515 } |
| 516 BadNumberFormatException.prototype.toString$0 = BadNumberFormatException.prototy
pe.toString; |
| 517 // ********** Code for NullPointerException ************** |
| 518 function NullPointerException() { |
| 519 // Initializers done |
| 520 } |
| 521 NullPointerException.prototype.toString = function() { |
| 522 return "NullPointerException"; |
| 523 } |
| 524 NullPointerException.prototype.toString$0 = NullPointerException.prototype.toStr
ing; |
| 525 // ********** Code for NoMoreElementsException ************** |
| 526 function NoMoreElementsException() { |
| 527 // Initializers done |
| 528 } |
| 529 NoMoreElementsException.prototype.toString = function() { |
| 530 return "NoMoreElementsException"; |
| 531 } |
| 532 NoMoreElementsException.prototype.toString$0 = NoMoreElementsException.prototype
.toString; |
| 533 // ********** Code for EmptyQueueException ************** |
| 534 function EmptyQueueException() { |
| 535 // Initializers done |
| 536 } |
| 537 EmptyQueueException.prototype.toString = function() { |
| 538 return "EmptyQueueException"; |
| 539 } |
| 540 EmptyQueueException.prototype.toString$0 = EmptyQueueException.prototype.toStrin
g; |
| 541 // ********** Code for UnsupportedOperationException ************** |
| 542 function UnsupportedOperationException(_message) { |
| 543 this._dart_core_message = _message; |
| 544 // Initializers done |
| 545 } |
| 546 UnsupportedOperationException.prototype.toString = function() { |
| 547 return ("UnsupportedOperationException: " + this._dart_core_message); |
| 548 } |
| 549 UnsupportedOperationException.prototype.toString$0 = UnsupportedOperationExcepti
on.prototype.toString; |
| 550 // ********** Code for Function ************** |
| 551 Function.prototype.to$call$0 = function() { |
| 552 this.call$0 = this.$genStub(0); |
| 553 this.to$call$0 = function() { return this.call$0; }; |
| 554 return this.call$0; |
| 555 }; |
| 556 Function.prototype.call$0 = function() { |
| 557 return this.to$call$0()(); |
| 558 }; |
| 559 function to$call$0(f) { return f && f.to$call$0(); } |
| 560 Function.prototype.to$call$1 = function() { |
| 561 this.call$1 = this.$genStub(1); |
| 562 this.to$call$1 = function() { return this.call$1; }; |
| 563 return this.call$1; |
| 564 }; |
| 565 Function.prototype.call$1 = function($0) { |
| 566 return this.to$call$1()($0); |
| 567 }; |
| 568 function to$call$1(f) { return f && f.to$call$1(); } |
| 569 Function.prototype.to$call$2 = function() { |
| 570 this.call$2 = this.$genStub(2); |
| 571 this.to$call$2 = function() { return this.call$2; }; |
| 572 return this.call$2; |
| 573 }; |
| 574 Function.prototype.call$2 = function($0, $1) { |
| 575 return this.to$call$2()($0, $1); |
| 576 }; |
| 577 function to$call$2(f) { return f && f.to$call$2(); } |
| 578 // ********** Code for Math ************** |
| 579 Math.parseInt = function(str) { |
| 580 var ret = parseInt(str); |
| 581 if (isNaN(ret)) $throw(new BadNumberFormatException(str)); |
| 582 return ret; |
| 583 } |
| 584 Math.parseDouble = function(str) { |
| 585 var ret = parseFloat(str); |
| 586 if (isNaN(ret) && str != 'NaN') $throw(new BadNumberFormatException(str)); |
| 587 return ret; |
| 588 } |
| 589 Math.min = function(a, b) { |
| 590 if (a == b) return a; |
| 591 if (a < b) { |
| 592 if (isNaN(b)) return b; |
| 593 else return a; |
| 594 } |
| 595 if (isNaN(a)) return a; |
| 596 else return b; |
| 597 } |
| 598 Math.max = function(a, b) { |
| 599 return (a >= b) ? a : b; |
| 600 } |
| 601 // ********** Code for Strings ************** |
| 602 function Strings() {} |
| 603 Strings.String$fromCharCodes$factory = function(charCodes) { |
| 604 return StringBase.createFromCharCodes(charCodes); |
| 605 } |
| 606 Strings.join = function(strings, separator) { |
| 607 return StringBase.join(strings, separator); |
| 608 } |
| 609 // ********** Code for top level ************** |
| 610 function print(obj) { |
| 611 return _print(obj); |
| 612 } |
| 613 function _print(obj) { |
| 614 if (typeof console == 'object') { |
| 615 if (obj) obj = obj.toString(); |
| 616 console.log(obj); |
| 617 } else { |
| 618 write(obj); |
| 619 write('\n'); |
| 620 } |
| 621 } |
| 622 function _map(itemsAndKeys) { |
| 623 var ret = new LinkedHashMapImplementation(); |
| 624 for (var i = 0; |
| 625 i < itemsAndKeys.length; ) { |
| 626 ret.$setindex(itemsAndKeys.$index(i++), itemsAndKeys.$index(i++)); |
| 627 } |
| 628 return ret; |
| 629 } |
| 630 function _constMap(itemsAndKeys) { |
| 631 return new ImmutableMap(itemsAndKeys); |
| 632 } |
| 633 function _toDartException(e) { |
| 634 function attachStack(dartEx) { |
| 635 // TODO(jmesserly): setting the stack property is not a long term solution. |
| 636 var stack = e.stack; |
| 637 // The stack contains the error message, and the stack is all that is |
| 638 // printed (the exception's toString() is never called). Make the Dart |
| 639 // exception's toString() be the dominant message. |
| 640 if (typeof stack == 'string') { |
| 641 var message = dartEx.toString(); |
| 642 if (/^(Type|Range)Error:/.test(stack)) { |
| 643 // Indent JS message (it can be helpful) so new message stands out. |
| 644 stack = ' (' + stack.substring(0, stack.indexOf('\n')) + ')\n' + |
| 645 stack.substring(stack.indexOf('\n') + 1); |
| 646 } |
| 647 stack = message + '\n' + stack; |
| 648 } |
| 649 dartEx.stack = stack; |
| 650 return dartEx; |
| 651 } |
| 652 |
| 653 if (e instanceof TypeError) { |
| 654 switch(e.type) { |
| 655 case 'property_not_function': |
| 656 case 'called_non_callable': |
| 657 if (e.arguments[0] == null) { |
| 658 return attachStack(new NullPointerException()); |
| 659 } else { |
| 660 return attachStack(new ObjectNotClosureException()); |
| 661 } |
| 662 break; |
| 663 case 'non_object_property_call': |
| 664 case 'non_object_property_load': |
| 665 return attachStack(new NullPointerException()); |
| 666 break; |
| 667 case 'undefined_method': |
| 668 var mname = e.arguments[0]; |
| 669 if (typeof(mname) == 'string' && (mname.indexOf('call$') == 0 |
| 670 || mname == 'call' || mname == 'apply')) { |
| 671 return attachStack(new ObjectNotClosureException()); |
| 672 } else { |
| 673 // TODO(jmesserly): fix noSuchMethod on operators so we don't hit this |
| 674 return attachStack(new NoSuchMethodException('', e.arguments[0], [])); |
| 675 } |
| 676 break; |
| 677 } |
| 678 } else if (e instanceof RangeError) { |
| 679 if (e.message.indexOf('call stack') >= 0) { |
| 680 return attachStack(new StackOverflowException()); |
| 681 } |
| 682 } |
| 683 return e; |
| 684 } |
| 685 // ********** Library dart:coreimpl ************** |
| 686 // ********** Code for ListFactory ************** |
| 687 ListFactory = Array; |
| 688 ListFactory.prototype.is$List = function(){return true}; |
| 689 ListFactory.ListFactory$from$factory = function(other) { |
| 690 var list = []; |
| 691 for (var $$i = other.iterator(); $$i.hasNext$0(); ) { |
| 692 var e = $$i.next$0(); |
| 693 list.add(e); |
| 694 } |
| 695 return list; |
| 696 } |
| 697 ListFactory.prototype.add = function(value) { |
| 698 this.push(value); |
| 699 } |
| 700 ListFactory.prototype.addLast = function(value) { |
| 701 this.push(value); |
| 702 } |
| 703 ListFactory.prototype.addAll = function(collection) { |
| 704 for (var $$i = collection.iterator(); $$i.hasNext$0(); ) { |
| 705 var item = $$i.next$0(); |
| 706 this.add(item); |
| 707 } |
| 708 } |
| 709 ListFactory.prototype.clear = function() { |
| 710 this.length = 0; |
| 711 } |
| 712 ListFactory.prototype.removeLast = function() { |
| 713 return this.pop(); |
| 714 } |
| 715 ListFactory.prototype.last = function() { |
| 716 return this[this.length - 1]; |
| 717 } |
| 718 ListFactory.prototype.getRange = function(start, length) { |
| 719 return this.slice(start, start + length); |
| 720 } |
| 721 ListFactory.prototype.isEmpty = function() { |
| 722 return this.length == 0; |
| 723 } |
| 724 ListFactory.prototype.iterator = function() { |
| 725 return new ListIterator(this); |
| 726 } |
| 727 ListFactory.prototype.add$1 = ListFactory.prototype.add; |
| 728 ListFactory.prototype.addAll$1 = ListFactory.prototype.addAll; |
| 729 ListFactory.prototype.clear$0 = ListFactory.prototype.clear; |
| 730 ListFactory.prototype.every$1 = function($0) { |
| 731 return this.every(to$call$1($0)); |
| 732 }; |
| 733 ListFactory.prototype.filter$1 = function($0) { |
| 734 return this.filter(to$call$1($0)); |
| 735 }; |
| 736 ListFactory.prototype.forEach$1 = function($0) { |
| 737 return this.forEach(to$call$1($0)); |
| 738 }; |
| 739 ListFactory.prototype.indexOf$1 = ListFactory.prototype.indexOf; |
| 740 ListFactory.prototype.isEmpty$0 = ListFactory.prototype.isEmpty; |
| 741 ListFactory.prototype.iterator$0 = ListFactory.prototype.iterator; |
| 742 ListFactory.prototype.last$0 = ListFactory.prototype.last; |
| 743 ListFactory.prototype.removeLast$0 = ListFactory.prototype.removeLast; |
| 744 ListFactory.prototype.some$1 = function($0) { |
| 745 return this.some(to$call$1($0)); |
| 746 }; |
| 747 ListFactory.prototype.sort$1 = function($0) { |
| 748 return this.sort(to$call$2($0)); |
| 749 }; |
| 750 ListFactory_E = ListFactory; |
| 751 ListFactory_K = ListFactory; |
| 752 ListFactory_String = ListFactory; |
| 753 ListFactory_V = ListFactory; |
| 754 ListFactory_int = ListFactory; |
| 755 // ********** Code for ListIterator ************** |
| 756 function ListIterator(array) { |
| 757 this._array = array; |
| 758 this._dart_coreimpl_pos = 0; |
| 759 // Initializers done |
| 760 } |
| 761 ListIterator.prototype.hasNext = function() { |
| 762 return this._array.length > this._dart_coreimpl_pos; |
| 763 } |
| 764 ListIterator.prototype.next = function() { |
| 765 if (!this.hasNext()) { |
| 766 $throw(const$1/*const NoMoreElementsException()*/); |
| 767 } |
| 768 return this._array.$index(this._dart_coreimpl_pos++); |
| 769 } |
| 770 ListIterator.prototype.hasNext$0 = ListIterator.prototype.hasNext; |
| 771 ListIterator.prototype.next$0 = ListIterator.prototype.next; |
| 772 // ********** Code for ImmutableList ************** |
| 773 /** Implements extends for Dart classes on JavaScript prototypes. */ |
| 774 function $inherits(child, parent) { |
| 775 if (child.prototype.__proto__) { |
| 776 child.prototype.__proto__ = parent.prototype; |
| 777 } else { |
| 778 function tmp() {}; |
| 779 tmp.prototype = parent.prototype; |
| 780 child.prototype = new tmp(); |
| 781 child.prototype.constructor = child; |
| 782 } |
| 783 } |
| 784 $inherits(ImmutableList, ListFactory_E); |
| 785 function ImmutableList(length) { |
| 786 this._length = length; |
| 787 // Initializers done |
| 788 ListFactory_E.call(this, length); |
| 789 } |
| 790 ImmutableList.ImmutableList$from$factory = function(other) { |
| 791 var list = new ImmutableList(other.length); |
| 792 for (var i = 0; |
| 793 i < other.length; i++) { |
| 794 list._setindex(i, other.$index(i)); |
| 795 } |
| 796 return list; |
| 797 } |
| 798 ImmutableList.prototype.get$length = function() { |
| 799 return this._length; |
| 800 } |
| 801 ImmutableList.prototype.set$length = function(length) { |
| 802 $throw(const$143/*const IllegalAccessException()*/); |
| 803 } |
| 804 Object.defineProperty(ImmutableList.prototype, "length", { |
| 805 get: ImmutableList.prototype.get$length, |
| 806 set: ImmutableList.prototype.set$length |
| 807 }); |
| 808 ImmutableList.prototype._setindex = function(index, value) { |
| 809 return this[index] = value; |
| 810 } |
| 811 ImmutableList.prototype.$setindex = function(index, value) { |
| 812 $throw(const$143/*const IllegalAccessException()*/); |
| 813 } |
| 814 ImmutableList.prototype.sort = function(compare) { |
| 815 $throw(const$143/*const IllegalAccessException()*/); |
| 816 } |
| 817 ImmutableList.prototype.add = function(element) { |
| 818 $throw(const$143/*const IllegalAccessException()*/); |
| 819 } |
| 820 ImmutableList.prototype.addLast = function(element) { |
| 821 $throw(const$143/*const IllegalAccessException()*/); |
| 822 } |
| 823 ImmutableList.prototype.addAll = function(elements) { |
| 824 $throw(const$143/*const IllegalAccessException()*/); |
| 825 } |
| 826 ImmutableList.prototype.clear = function() { |
| 827 $throw(const$143/*const IllegalAccessException()*/); |
| 828 } |
| 829 ImmutableList.prototype.removeLast = function() { |
| 830 $throw(const$143/*const IllegalAccessException()*/); |
| 831 } |
| 832 ImmutableList.prototype.toString = function() { |
| 833 return ListFactory.ListFactory$from$factory(this).toString(); |
| 834 } |
| 835 ImmutableList.prototype.add$1 = ImmutableList.prototype.add; |
| 836 ImmutableList.prototype.addAll$1 = ImmutableList.prototype.addAll; |
| 837 ImmutableList.prototype.clear$0 = ImmutableList.prototype.clear; |
| 838 ImmutableList.prototype.removeLast$0 = ImmutableList.prototype.removeLast; |
| 839 ImmutableList.prototype.sort$1 = function($0) { |
| 840 return this.sort(to$call$2($0)); |
| 841 }; |
| 842 ImmutableList.prototype.toString$0 = ImmutableList.prototype.toString; |
| 843 // ********** Code for ImmutableMap ************** |
| 844 function ImmutableMap(keyValuePairs) { |
| 845 this._internal = _map(keyValuePairs); |
| 846 // Initializers done |
| 847 } |
| 848 ImmutableMap.prototype.$index = function(key) { |
| 849 return this._internal.$index(key); |
| 850 } |
| 851 ImmutableMap.prototype.isEmpty = function() { |
| 852 return this._internal.isEmpty(); |
| 853 } |
| 854 ImmutableMap.prototype.get$length = function() { |
| 855 return this._internal.get$length(); |
| 856 } |
| 857 Object.defineProperty(ImmutableMap.prototype, "length", { |
| 858 get: ImmutableMap.prototype.get$length |
| 859 }); |
| 860 ImmutableMap.prototype.forEach = function(f) { |
| 861 this._internal.forEach(f); |
| 862 } |
| 863 ImmutableMap.prototype.getKeys = function() { |
| 864 return this._internal.getKeys(); |
| 865 } |
| 866 ImmutableMap.prototype.getValues = function() { |
| 867 return this._internal.getValues(); |
| 868 } |
| 869 ImmutableMap.prototype.containsKey = function(key) { |
| 870 return this._internal.containsKey(key); |
| 871 } |
| 872 ImmutableMap.prototype.$setindex = function(key, value) { |
| 873 $throw(const$143/*const IllegalAccessException()*/); |
| 874 } |
| 875 ImmutableMap.prototype.clear = function() { |
| 876 $throw(const$143/*const IllegalAccessException()*/); |
| 877 } |
| 878 ImmutableMap.prototype.clear$0 = ImmutableMap.prototype.clear; |
| 879 ImmutableMap.prototype.containsKey$1 = ImmutableMap.prototype.containsKey; |
| 880 ImmutableMap.prototype.forEach$1 = function($0) { |
| 881 return this.forEach(to$call$2($0)); |
| 882 }; |
| 883 ImmutableMap.prototype.getKeys$0 = ImmutableMap.prototype.getKeys; |
| 884 ImmutableMap.prototype.getValues$0 = ImmutableMap.prototype.getValues; |
| 885 ImmutableMap.prototype.isEmpty$0 = ImmutableMap.prototype.isEmpty; |
| 886 // ********** Code for NumImplementation ************** |
| 887 NumImplementation = Number; |
| 888 NumImplementation.prototype.isNaN = function() { |
| 889 return isNaN(this); |
| 890 } |
| 891 NumImplementation.prototype.isNegative = function() { |
| 892 return this == 0 ? (1 / this) < 0 : this < 0; |
| 893 } |
| 894 NumImplementation.prototype.round = function() { |
| 895 return Math.round(this); |
| 896 } |
| 897 NumImplementation.prototype.floor = function() { |
| 898 return Math.floor(this); |
| 899 } |
| 900 NumImplementation.prototype.hashCode = function() { |
| 901 return this & 0xFFFFFFF; |
| 902 } |
| 903 NumImplementation.prototype.toInt = function() { |
| 904 if (isNaN(this)) throw new BadNumberFormatException("NaN"); |
| 905 if ((this == Infinity) || (this == -Infinity)) { |
| 906 throw new BadNumberFormatException("Infinity"); |
| 907 } |
| 908 var truncated = (this < 0) ? Math.ceil(this) : Math.floor(this); |
| 909 |
| 910 if (truncated == -0.0) return 0; |
| 911 return truncated; |
| 912 } |
| 913 NumImplementation.prototype.toDouble = function() { |
| 914 return this + 0; |
| 915 } |
| 916 NumImplementation.prototype.compareTo = function(other) { |
| 917 var thisValue = this.toDouble(); |
| 918 if (thisValue < other) { |
| 919 return -1; |
| 920 } |
| 921 else if (thisValue > other) { |
| 922 return 1; |
| 923 } |
| 924 else if (thisValue == other) { |
| 925 if (thisValue == 0) { |
| 926 var thisIsNegative = this.isNegative(); |
| 927 var otherIsNegative = other.isNegative(); |
| 928 if ($eq(thisIsNegative, otherIsNegative)) return 0; |
| 929 if (thisIsNegative) return -1; |
| 930 return 1; |
| 931 } |
| 932 return 0; |
| 933 } |
| 934 else if (this.isNaN()) { |
| 935 if (other.isNaN()) { |
| 936 return 0; |
| 937 } |
| 938 return 1; |
| 939 } |
| 940 else { |
| 941 return -1; |
| 942 } |
| 943 } |
| 944 NumImplementation.prototype.compareTo$1 = NumImplementation.prototype.compareTo; |
| 945 NumImplementation.prototype.hashCode$0 = NumImplementation.prototype.hashCode; |
| 946 // ********** Code for HashMapImplementation ************** |
| 947 function HashMapImplementation() { |
| 948 // Initializers done |
| 949 this._numberOfEntries = 0; |
| 950 this._numberOfDeleted = 0; |
| 951 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 952 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 953 this._values = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 954 } |
| 955 HashMapImplementation.HashMapImplementation$from$factory = function(other) { |
| 956 var result = new HashMapImplementation(); |
| 957 other.forEach((function (key, value) { |
| 958 result.$setindex(key, value); |
| 959 }) |
| 960 ); |
| 961 return result; |
| 962 } |
| 963 HashMapImplementation._computeLoadLimit = function(capacity) { |
| 964 return $truncdiv((capacity * 3), 4); |
| 965 } |
| 966 HashMapImplementation._firstProbe = function(hashCode, length) { |
| 967 return hashCode & (length - 1); |
| 968 } |
| 969 HashMapImplementation._nextProbe = function(currentProbe, numberOfProbes, length
) { |
| 970 return (currentProbe + numberOfProbes) & (length - 1); |
| 971 } |
| 972 HashMapImplementation.prototype._probeForAdding = function(key) { |
| 973 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 974 var numberOfProbes = 1; |
| 975 var initialHash = hash; |
| 976 var insertionIndex = -1; |
| 977 while (true) { |
| 978 var existingKey = this._keys.$index(hash); |
| 979 if (existingKey == null) { |
| 980 if (insertionIndex < 0) return hash; |
| 981 return insertionIndex; |
| 982 } |
| 983 else if ($eq(existingKey, key)) { |
| 984 return hash; |
| 985 } |
| 986 else if ((insertionIndex < 0) && (const$3/*HashMapImplementation._DELETED_KE
Y*/ === existingKey)) { |
| 987 insertionIndex = hash; |
| 988 } |
| 989 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 990 } |
| 991 } |
| 992 HashMapImplementation.prototype._probeForLookup = function(key) { |
| 993 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 994 var numberOfProbes = 1; |
| 995 var initialHash = hash; |
| 996 while (true) { |
| 997 var existingKey = this._keys.$index(hash); |
| 998 if (existingKey == null) return -1; |
| 999 if ($eq(existingKey, key)) return hash; |
| 1000 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 1001 } |
| 1002 } |
| 1003 HashMapImplementation.prototype._ensureCapacity = function() { |
| 1004 var newNumberOfEntries = this._numberOfEntries + 1; |
| 1005 if (newNumberOfEntries >= this._loadLimit) { |
| 1006 this._grow(this._keys.length * 2); |
| 1007 return; |
| 1008 } |
| 1009 var capacity = this._keys.length; |
| 1010 var numberOfFreeOrDeleted = capacity - newNumberOfEntries; |
| 1011 var numberOfFree = numberOfFreeOrDeleted - this._numberOfDeleted; |
| 1012 if (this._numberOfDeleted > numberOfFree) { |
| 1013 this._grow(this._keys.length); |
| 1014 } |
| 1015 } |
| 1016 HashMapImplementation._isPowerOfTwo = function(x) { |
| 1017 return ((x & (x - 1)) == 0); |
| 1018 } |
| 1019 HashMapImplementation.prototype._grow = function(newCapacity) { |
| 1020 var capacity = this._keys.length; |
| 1021 this._loadLimit = HashMapImplementation._computeLoadLimit(newCapacity); |
| 1022 var oldKeys = this._keys; |
| 1023 var oldValues = this._values; |
| 1024 this._keys = new ListFactory(newCapacity); |
| 1025 this._values = new ListFactory(newCapacity); |
| 1026 for (var i = 0; |
| 1027 i < capacity; i++) { |
| 1028 var key = oldKeys.$index(i); |
| 1029 if (key == null || key === const$3/*HashMapImplementation._DELETED_KEY*/) { |
| 1030 continue; |
| 1031 } |
| 1032 var value = oldValues.$index(i); |
| 1033 var newIndex = this._probeForAdding(key); |
| 1034 this._keys.$setindex(newIndex, key); |
| 1035 this._values.$setindex(newIndex, value); |
| 1036 } |
| 1037 this._numberOfDeleted = 0; |
| 1038 } |
| 1039 HashMapImplementation.prototype.clear = function() { |
| 1040 this._numberOfEntries = 0; |
| 1041 this._numberOfDeleted = 0; |
| 1042 var length = this._keys.length; |
| 1043 for (var i = 0; |
| 1044 i < length; i++) { |
| 1045 this._keys.$setindex(i); |
| 1046 this._values.$setindex(i); |
| 1047 } |
| 1048 } |
| 1049 HashMapImplementation.prototype.$setindex = function(key, value) { |
| 1050 this._ensureCapacity(); |
| 1051 var index = this._probeForAdding(key); |
| 1052 if ((this._keys.$index(index) == null) || (this._keys.$index(index) === const$
3/*HashMapImplementation._DELETED_KEY*/)) { |
| 1053 this._numberOfEntries++; |
| 1054 } |
| 1055 this._keys.$setindex(index, key); |
| 1056 this._values.$setindex(index, value); |
| 1057 } |
| 1058 HashMapImplementation.prototype.$index = function(key) { |
| 1059 var index = this._probeForLookup(key); |
| 1060 if (index < 0) return null; |
| 1061 return this._values.$index(index); |
| 1062 } |
| 1063 HashMapImplementation.prototype.remove = function(key) { |
| 1064 var index = this._probeForLookup(key); |
| 1065 if (index >= 0) { |
| 1066 this._numberOfEntries--; |
| 1067 var value = this._values.$index(index); |
| 1068 this._values.$setindex(index); |
| 1069 this._keys.$setindex(index, const$3/*HashMapImplementation._DELETED_KEY*/); |
| 1070 this._numberOfDeleted++; |
| 1071 return value; |
| 1072 } |
| 1073 return null; |
| 1074 } |
| 1075 HashMapImplementation.prototype.isEmpty = function() { |
| 1076 return this._numberOfEntries == 0; |
| 1077 } |
| 1078 HashMapImplementation.prototype.get$length = function() { |
| 1079 return this._numberOfEntries; |
| 1080 } |
| 1081 Object.defineProperty(HashMapImplementation.prototype, "length", { |
| 1082 get: HashMapImplementation.prototype.get$length |
| 1083 }); |
| 1084 HashMapImplementation.prototype.forEach = function(f) { |
| 1085 var length = this._keys.length; |
| 1086 for (var i = 0; |
| 1087 i < length; i++) { |
| 1088 if ((this._keys.$index(i) != null) && (this._keys.$index(i) !== const$3/*Has
hMapImplementation._DELETED_KEY*/)) { |
| 1089 f(this._keys.$index(i), this._values.$index(i)); |
| 1090 } |
| 1091 } |
| 1092 } |
| 1093 HashMapImplementation.prototype.getKeys = function() { |
| 1094 var list = new ListFactory(this.get$length()); |
| 1095 var i = 0; |
| 1096 this.forEach(function _(key, value) { |
| 1097 list.$setindex(i++, key); |
| 1098 } |
| 1099 ); |
| 1100 return list; |
| 1101 } |
| 1102 HashMapImplementation.prototype.getValues = function() { |
| 1103 var list = new ListFactory(this.get$length()); |
| 1104 var i = 0; |
| 1105 this.forEach(function _(key, value) { |
| 1106 list.$setindex(i++, value); |
| 1107 } |
| 1108 ); |
| 1109 return list; |
| 1110 } |
| 1111 HashMapImplementation.prototype.containsKey = function(key) { |
| 1112 return (this._probeForLookup(key) != -1); |
| 1113 } |
| 1114 HashMapImplementation.prototype.clear$0 = HashMapImplementation.prototype.clear; |
| 1115 HashMapImplementation.prototype.containsKey$1 = HashMapImplementation.prototype.
containsKey; |
| 1116 HashMapImplementation.prototype.forEach$1 = function($0) { |
| 1117 return this.forEach(to$call$2($0)); |
| 1118 }; |
| 1119 HashMapImplementation.prototype.getKeys$0 = HashMapImplementation.prototype.getK
eys; |
| 1120 HashMapImplementation.prototype.getValues$0 = HashMapImplementation.prototype.ge
tValues; |
| 1121 HashMapImplementation.prototype.isEmpty$0 = HashMapImplementation.prototype.isEm
pty; |
| 1122 // ********** Code for HashMapImplementation_E$E ************** |
| 1123 $inherits(HashMapImplementation_E$E, HashMapImplementation); |
| 1124 function HashMapImplementation_E$E() { |
| 1125 // Initializers done |
| 1126 this._numberOfEntries = 0; |
| 1127 this._numberOfDeleted = 0; |
| 1128 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 1129 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1130 this._values = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1131 } |
| 1132 HashMapImplementation_E$E._computeLoadLimit = function(capacity) { |
| 1133 return $truncdiv((capacity * 3), 4); |
| 1134 } |
| 1135 HashMapImplementation_E$E._firstProbe = function(hashCode, length) { |
| 1136 return hashCode & (length - 1); |
| 1137 } |
| 1138 HashMapImplementation_E$E._nextProbe = function(currentProbe, numberOfProbes, le
ngth) { |
| 1139 return (currentProbe + numberOfProbes) & (length - 1); |
| 1140 } |
| 1141 HashMapImplementation_E$E.prototype._probeForAdding = function(key) { |
| 1142 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 1143 var numberOfProbes = 1; |
| 1144 var initialHash = hash; |
| 1145 var insertionIndex = -1; |
| 1146 while (true) { |
| 1147 var existingKey = this._keys.$index(hash); |
| 1148 if (existingKey == null) { |
| 1149 if (insertionIndex < 0) return hash; |
| 1150 return insertionIndex; |
| 1151 } |
| 1152 else if ($eq(existingKey, key)) { |
| 1153 return hash; |
| 1154 } |
| 1155 else if ((insertionIndex < 0) && (const$3/*HashMapImplementation._DELETED_KE
Y*/ === existingKey)) { |
| 1156 insertionIndex = hash; |
| 1157 } |
| 1158 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 1159 } |
| 1160 } |
| 1161 HashMapImplementation_E$E.prototype._probeForLookup = function(key) { |
| 1162 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 1163 var numberOfProbes = 1; |
| 1164 var initialHash = hash; |
| 1165 while (true) { |
| 1166 var existingKey = this._keys.$index(hash); |
| 1167 if (existingKey == null) return -1; |
| 1168 if ($eq(existingKey, key)) return hash; |
| 1169 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 1170 } |
| 1171 } |
| 1172 HashMapImplementation_E$E.prototype._ensureCapacity = function() { |
| 1173 var newNumberOfEntries = this._numberOfEntries + 1; |
| 1174 if (newNumberOfEntries >= this._loadLimit) { |
| 1175 this._grow(this._keys.length * 2); |
| 1176 return; |
| 1177 } |
| 1178 var capacity = this._keys.length; |
| 1179 var numberOfFreeOrDeleted = capacity - newNumberOfEntries; |
| 1180 var numberOfFree = numberOfFreeOrDeleted - this._numberOfDeleted; |
| 1181 if (this._numberOfDeleted > numberOfFree) { |
| 1182 this._grow(this._keys.length); |
| 1183 } |
| 1184 } |
| 1185 HashMapImplementation_E$E._isPowerOfTwo = function(x) { |
| 1186 return ((x & (x - 1)) == 0); |
| 1187 } |
| 1188 HashMapImplementation_E$E.prototype._grow = function(newCapacity) { |
| 1189 var capacity = this._keys.length; |
| 1190 this._loadLimit = HashMapImplementation._computeLoadLimit(newCapacity); |
| 1191 var oldKeys = this._keys; |
| 1192 var oldValues = this._values; |
| 1193 this._keys = new ListFactory(newCapacity); |
| 1194 this._values = new ListFactory(newCapacity); |
| 1195 for (var i = 0; |
| 1196 i < capacity; i++) { |
| 1197 var key = oldKeys.$index(i); |
| 1198 if (key == null || key === const$3/*HashMapImplementation._DELETED_KEY*/) { |
| 1199 continue; |
| 1200 } |
| 1201 var value = oldValues.$index(i); |
| 1202 var newIndex = this._probeForAdding(key); |
| 1203 this._keys.$setindex(newIndex, key); |
| 1204 this._values.$setindex(newIndex, value); |
| 1205 } |
| 1206 this._numberOfDeleted = 0; |
| 1207 } |
| 1208 HashMapImplementation_E$E.prototype.clear = function() { |
| 1209 this._numberOfEntries = 0; |
| 1210 this._numberOfDeleted = 0; |
| 1211 var length = this._keys.length; |
| 1212 for (var i = 0; |
| 1213 i < length; i++) { |
| 1214 this._keys.$setindex(i); |
| 1215 this._values.$setindex(i); |
| 1216 } |
| 1217 } |
| 1218 HashMapImplementation_E$E.prototype.$setindex = function(key, value) { |
| 1219 this._ensureCapacity(); |
| 1220 var index = this._probeForAdding(key); |
| 1221 if ((this._keys.$index(index) == null) || (this._keys.$index(index) === const$
3/*HashMapImplementation._DELETED_KEY*/)) { |
| 1222 this._numberOfEntries++; |
| 1223 } |
| 1224 this._keys.$setindex(index, key); |
| 1225 this._values.$setindex(index, value); |
| 1226 } |
| 1227 HashMapImplementation_E$E.prototype.remove = function(key) { |
| 1228 var index = this._probeForLookup(key); |
| 1229 if (index >= 0) { |
| 1230 this._numberOfEntries--; |
| 1231 var value = this._values.$index(index); |
| 1232 this._values.$setindex(index); |
| 1233 this._keys.$setindex(index, const$3/*HashMapImplementation._DELETED_KEY*/); |
| 1234 this._numberOfDeleted++; |
| 1235 return value; |
| 1236 } |
| 1237 return null; |
| 1238 } |
| 1239 HashMapImplementation_E$E.prototype.isEmpty = function() { |
| 1240 return this._numberOfEntries == 0; |
| 1241 } |
| 1242 HashMapImplementation_E$E.prototype.forEach = function(f) { |
| 1243 var length = this._keys.length; |
| 1244 for (var i = 0; |
| 1245 i < length; i++) { |
| 1246 if ((this._keys.$index(i) != null) && (this._keys.$index(i) !== const$3/*Has
hMapImplementation._DELETED_KEY*/)) { |
| 1247 f(this._keys.$index(i), this._values.$index(i)); |
| 1248 } |
| 1249 } |
| 1250 } |
| 1251 HashMapImplementation_E$E.prototype.getKeys = function() { |
| 1252 var list = new ListFactory(this.get$length()); |
| 1253 var i = 0; |
| 1254 this.forEach(function _(key, value) { |
| 1255 list.$setindex(i++, key); |
| 1256 } |
| 1257 ); |
| 1258 return list; |
| 1259 } |
| 1260 HashMapImplementation_E$E.prototype.containsKey = function(key) { |
| 1261 return (this._probeForLookup(key) != -1); |
| 1262 } |
| 1263 // ********** Code for HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePa
ir_K$V ************** |
| 1264 $inherits(HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePair_K$V, HashM
apImplementation); |
| 1265 function HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePair_K$V() {} |
| 1266 // ********** Code for HashMapImplementation_String$EvaluatedValue *************
* |
| 1267 $inherits(HashMapImplementation_String$EvaluatedValue, HashMapImplementation); |
| 1268 function HashMapImplementation_String$EvaluatedValue() {} |
| 1269 // ********** Code for HashSetImplementation ************** |
| 1270 function HashSetImplementation() { |
| 1271 // Initializers done |
| 1272 this._backingMap = new HashMapImplementation_E$E(); |
| 1273 } |
| 1274 HashSetImplementation.HashSetImplementation$from$factory = function(other) { |
| 1275 var set = new HashSetImplementation(); |
| 1276 for (var $$i = other.iterator(); $$i.hasNext$0(); ) { |
| 1277 var e = $$i.next$0(); |
| 1278 set.add(e); |
| 1279 } |
| 1280 return set; |
| 1281 } |
| 1282 HashSetImplementation.prototype.clear = function() { |
| 1283 this._backingMap.clear(); |
| 1284 } |
| 1285 HashSetImplementation.prototype.add = function(value) { |
| 1286 this._backingMap.$setindex(value, value); |
| 1287 } |
| 1288 HashSetImplementation.prototype.contains = function(value) { |
| 1289 return this._backingMap.containsKey(value); |
| 1290 } |
| 1291 HashSetImplementation.prototype.remove = function(value) { |
| 1292 if (!this._backingMap.containsKey(value)) return false; |
| 1293 this._backingMap.remove(value); |
| 1294 return true; |
| 1295 } |
| 1296 HashSetImplementation.prototype.addAll = function(collection) { |
| 1297 var $this = this; // closure support |
| 1298 collection.forEach(function _(value) { |
| 1299 $this.add(value); |
| 1300 } |
| 1301 ); |
| 1302 } |
| 1303 HashSetImplementation.prototype.forEach = function(f) { |
| 1304 this._backingMap.forEach(function _(key, value) { |
| 1305 f(key); |
| 1306 } |
| 1307 ); |
| 1308 } |
| 1309 HashSetImplementation.prototype.filter = function(f) { |
| 1310 var result = new HashSetImplementation(); |
| 1311 this._backingMap.forEach(function _(key, value) { |
| 1312 if (f(key)) result.add(key); |
| 1313 } |
| 1314 ); |
| 1315 return result; |
| 1316 } |
| 1317 HashSetImplementation.prototype.every = function(f) { |
| 1318 var keys = this._backingMap.getKeys(); |
| 1319 return keys.every(f); |
| 1320 } |
| 1321 HashSetImplementation.prototype.some = function(f) { |
| 1322 var keys = this._backingMap.getKeys(); |
| 1323 return keys.some(f); |
| 1324 } |
| 1325 HashSetImplementation.prototype.isEmpty = function() { |
| 1326 return this._backingMap.isEmpty(); |
| 1327 } |
| 1328 HashSetImplementation.prototype.get$length = function() { |
| 1329 return this._backingMap.get$length(); |
| 1330 } |
| 1331 Object.defineProperty(HashSetImplementation.prototype, "length", { |
| 1332 get: HashSetImplementation.prototype.get$length |
| 1333 }); |
| 1334 HashSetImplementation.prototype.iterator = function() { |
| 1335 return new HashSetIterator_E(this); |
| 1336 } |
| 1337 HashSetImplementation.prototype.add$1 = HashSetImplementation.prototype.add; |
| 1338 HashSetImplementation.prototype.addAll$1 = HashSetImplementation.prototype.addAl
l; |
| 1339 HashSetImplementation.prototype.clear$0 = HashSetImplementation.prototype.clear; |
| 1340 HashSetImplementation.prototype.contains$1 = HashSetImplementation.prototype.con
tains; |
| 1341 HashSetImplementation.prototype.every$1 = function($0) { |
| 1342 return this.every(to$call$1($0)); |
| 1343 }; |
| 1344 HashSetImplementation.prototype.filter$1 = function($0) { |
| 1345 return this.filter(to$call$1($0)); |
| 1346 }; |
| 1347 HashSetImplementation.prototype.forEach$1 = function($0) { |
| 1348 return this.forEach(to$call$1($0)); |
| 1349 }; |
| 1350 HashSetImplementation.prototype.isEmpty$0 = HashSetImplementation.prototype.isEm
pty; |
| 1351 HashSetImplementation.prototype.iterator$0 = HashSetImplementation.prototype.ite
rator; |
| 1352 HashSetImplementation.prototype.some$1 = function($0) { |
| 1353 return this.some(to$call$1($0)); |
| 1354 }; |
| 1355 // ********** Code for HashSetImplementation_E ************** |
| 1356 $inherits(HashSetImplementation_E, HashSetImplementation); |
| 1357 function HashSetImplementation_E() {} |
| 1358 // ********** Code for HashSetImplementation_String ************** |
| 1359 $inherits(HashSetImplementation_String, HashSetImplementation); |
| 1360 function HashSetImplementation_String() {} |
| 1361 // ********** Code for HashSetImplementation_Type ************** |
| 1362 $inherits(HashSetImplementation_Type, HashSetImplementation); |
| 1363 function HashSetImplementation_Type() {} |
| 1364 // ********** Code for HashSetIterator ************** |
| 1365 function HashSetIterator(set_) { |
| 1366 this._nextValidIndex = -1; |
| 1367 this._entries = set_._backingMap._keys; |
| 1368 // Initializers done |
| 1369 this._advance(); |
| 1370 } |
| 1371 HashSetIterator.prototype.hasNext = function() { |
| 1372 if (this._nextValidIndex >= this._entries.length) return false; |
| 1373 if (this._entries.$index(this._nextValidIndex) === const$3/*HashMapImplementat
ion._DELETED_KEY*/) { |
| 1374 this._advance(); |
| 1375 } |
| 1376 return this._nextValidIndex < this._entries.length; |
| 1377 } |
| 1378 HashSetIterator.prototype.next = function() { |
| 1379 if (!this.hasNext()) { |
| 1380 $throw(const$1/*const NoMoreElementsException()*/); |
| 1381 } |
| 1382 var res = this._entries.$index(this._nextValidIndex); |
| 1383 this._advance(); |
| 1384 return res; |
| 1385 } |
| 1386 HashSetIterator.prototype._advance = function() { |
| 1387 var length = this._entries.length; |
| 1388 var entry; |
| 1389 var deletedKey = const$3/*HashMapImplementation._DELETED_KEY*/; |
| 1390 do { |
| 1391 if (++this._nextValidIndex >= length) break; |
| 1392 entry = this._entries.$index(this._nextValidIndex); |
| 1393 } |
| 1394 while ((entry == null) || (entry === deletedKey)) |
| 1395 } |
| 1396 HashSetIterator.prototype.hasNext$0 = HashSetIterator.prototype.hasNext; |
| 1397 HashSetIterator.prototype.next$0 = HashSetIterator.prototype.next; |
| 1398 // ********** Code for HashSetIterator_E ************** |
| 1399 $inherits(HashSetIterator_E, HashSetIterator); |
| 1400 function HashSetIterator_E(set_) { |
| 1401 this._nextValidIndex = -1; |
| 1402 this._entries = set_._backingMap._keys; |
| 1403 // Initializers done |
| 1404 this._advance(); |
| 1405 } |
| 1406 HashSetIterator_E.prototype._advance = function() { |
| 1407 var length = this._entries.length; |
| 1408 var entry; |
| 1409 var deletedKey = const$3/*HashMapImplementation._DELETED_KEY*/; |
| 1410 do { |
| 1411 if (++this._nextValidIndex >= length) break; |
| 1412 entry = this._entries.$index(this._nextValidIndex); |
| 1413 } |
| 1414 while ((entry == null) || (entry === deletedKey)) |
| 1415 } |
| 1416 // ********** Code for _DeletedKeySentinel ************** |
| 1417 function _DeletedKeySentinel() { |
| 1418 // Initializers done |
| 1419 } |
| 1420 // ********** Code for KeyValuePair ************** |
| 1421 function KeyValuePair(key, value) { |
| 1422 this.key = key; |
| 1423 this.value = value; |
| 1424 // Initializers done |
| 1425 } |
| 1426 // ********** Code for KeyValuePair_K$V ************** |
| 1427 $inherits(KeyValuePair_K$V, KeyValuePair); |
| 1428 function KeyValuePair_K$V(key, value) { |
| 1429 this.key = key; |
| 1430 this.value = value; |
| 1431 // Initializers done |
| 1432 } |
| 1433 // ********** Code for LinkedHashMapImplementation ************** |
| 1434 function LinkedHashMapImplementation() { |
| 1435 // Initializers done |
| 1436 this._map = new HashMapImplementation(); |
| 1437 this._list = new DoubleLinkedQueue_KeyValuePair_K$V(); |
| 1438 } |
| 1439 LinkedHashMapImplementation.prototype.$setindex = function(key, value) { |
| 1440 if (this._map.containsKey(key)) { |
| 1441 this._map.$index(key).get$element().value = value; |
| 1442 } |
| 1443 else { |
| 1444 this._list.addLast(new KeyValuePair_K$V(key, value)); |
| 1445 this._map.$setindex(key, this._list.lastEntry()); |
| 1446 } |
| 1447 } |
| 1448 LinkedHashMapImplementation.prototype.$index = function(key) { |
| 1449 var entry = this._map.$index(key); |
| 1450 if (entry == null) return null; |
| 1451 return entry.get$element().value; |
| 1452 } |
| 1453 LinkedHashMapImplementation.prototype.getKeys = function() { |
| 1454 var list = new ListFactory(this.get$length()); |
| 1455 var index = 0; |
| 1456 this._list.forEach(function _(entry) { |
| 1457 list.$setindex(index++, entry.key); |
| 1458 } |
| 1459 ); |
| 1460 return list; |
| 1461 } |
| 1462 LinkedHashMapImplementation.prototype.getValues = function() { |
| 1463 var list = new ListFactory(this.get$length()); |
| 1464 var index = 0; |
| 1465 this._list.forEach(function _(entry) { |
| 1466 list.$setindex(index++, entry.value); |
| 1467 } |
| 1468 ); |
| 1469 return list; |
| 1470 } |
| 1471 LinkedHashMapImplementation.prototype.forEach = function(f) { |
| 1472 this._list.forEach(function _(entry) { |
| 1473 f(entry.key, entry.value); |
| 1474 } |
| 1475 ); |
| 1476 } |
| 1477 LinkedHashMapImplementation.prototype.containsKey = function(key) { |
| 1478 return this._map.containsKey(key); |
| 1479 } |
| 1480 LinkedHashMapImplementation.prototype.get$length = function() { |
| 1481 return this._map.get$length(); |
| 1482 } |
| 1483 Object.defineProperty(LinkedHashMapImplementation.prototype, "length", { |
| 1484 get: LinkedHashMapImplementation.prototype.get$length |
| 1485 }); |
| 1486 LinkedHashMapImplementation.prototype.isEmpty = function() { |
| 1487 return this.get$length() == 0; |
| 1488 } |
| 1489 LinkedHashMapImplementation.prototype.clear = function() { |
| 1490 this._map.clear(); |
| 1491 this._list.clear(); |
| 1492 } |
| 1493 LinkedHashMapImplementation.prototype.clear$0 = LinkedHashMapImplementation.prot
otype.clear; |
| 1494 LinkedHashMapImplementation.prototype.containsKey$1 = LinkedHashMapImplementatio
n.prototype.containsKey; |
| 1495 LinkedHashMapImplementation.prototype.forEach$1 = function($0) { |
| 1496 return this.forEach(to$call$2($0)); |
| 1497 }; |
| 1498 LinkedHashMapImplementation.prototype.getKeys$0 = LinkedHashMapImplementation.pr
ototype.getKeys; |
| 1499 LinkedHashMapImplementation.prototype.getValues$0 = LinkedHashMapImplementation.
prototype.getValues; |
| 1500 LinkedHashMapImplementation.prototype.isEmpty$0 = LinkedHashMapImplementation.pr
ototype.isEmpty; |
| 1501 // ********** Code for DoubleLinkedQueueEntry ************** |
| 1502 function DoubleLinkedQueueEntry(e) { |
| 1503 // Initializers done |
| 1504 this._element = e; |
| 1505 } |
| 1506 DoubleLinkedQueueEntry.prototype._link = function(p, n) { |
| 1507 this._next = n; |
| 1508 this._previous = p; |
| 1509 p._next = this; |
| 1510 n._previous = this; |
| 1511 } |
| 1512 DoubleLinkedQueueEntry.prototype.prepend = function(e) { |
| 1513 new DoubleLinkedQueueEntry_E(e)._link(this._previous, this); |
| 1514 } |
| 1515 DoubleLinkedQueueEntry.prototype.remove = function() { |
| 1516 this._previous._next = this._next; |
| 1517 this._next._previous = this._previous; |
| 1518 this._next = null; |
| 1519 this._previous = null; |
| 1520 return this._element; |
| 1521 } |
| 1522 DoubleLinkedQueueEntry.prototype._asNonSentinelEntry = function() { |
| 1523 return this; |
| 1524 } |
| 1525 DoubleLinkedQueueEntry.prototype.previousEntry = function() { |
| 1526 return this._previous._asNonSentinelEntry(); |
| 1527 } |
| 1528 DoubleLinkedQueueEntry.prototype.get$element = function() { |
| 1529 return this._element; |
| 1530 } |
| 1531 // ********** Code for DoubleLinkedQueueEntry_E ************** |
| 1532 $inherits(DoubleLinkedQueueEntry_E, DoubleLinkedQueueEntry); |
| 1533 function DoubleLinkedQueueEntry_E(e) { |
| 1534 // Initializers done |
| 1535 this._element = e; |
| 1536 } |
| 1537 DoubleLinkedQueueEntry_E.prototype._link = function(p, n) { |
| 1538 this._next = n; |
| 1539 this._previous = p; |
| 1540 p._next = this; |
| 1541 n._previous = this; |
| 1542 } |
| 1543 DoubleLinkedQueueEntry_E.prototype.prepend = function(e) { |
| 1544 new DoubleLinkedQueueEntry_E(e)._link(this._previous, this); |
| 1545 } |
| 1546 DoubleLinkedQueueEntry_E.prototype.remove = function() { |
| 1547 this._previous._next = this._next; |
| 1548 this._next._previous = this._previous; |
| 1549 this._next = null; |
| 1550 this._previous = null; |
| 1551 return this._element; |
| 1552 } |
| 1553 DoubleLinkedQueueEntry_E.prototype._asNonSentinelEntry = function() { |
| 1554 return this; |
| 1555 } |
| 1556 // ********** Code for DoubleLinkedQueueEntry_KeyValuePair_K$V ************** |
| 1557 $inherits(DoubleLinkedQueueEntry_KeyValuePair_K$V, DoubleLinkedQueueEntry); |
| 1558 function DoubleLinkedQueueEntry_KeyValuePair_K$V(e) { |
| 1559 // Initializers done |
| 1560 this._element = e; |
| 1561 } |
| 1562 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype._link = function(p, n) { |
| 1563 this._next = n; |
| 1564 this._previous = p; |
| 1565 p._next = this; |
| 1566 n._previous = this; |
| 1567 } |
| 1568 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype.prepend = function(e) { |
| 1569 new DoubleLinkedQueueEntry_KeyValuePair_K$V(e)._link(this._previous, this); |
| 1570 } |
| 1571 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype._asNonSentinelEntry = function
() { |
| 1572 return this; |
| 1573 } |
| 1574 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype.previousEntry = function() { |
| 1575 return this._previous._asNonSentinelEntry(); |
| 1576 } |
| 1577 // ********** Code for _DoubleLinkedQueueEntrySentinel ************** |
| 1578 $inherits(_DoubleLinkedQueueEntrySentinel, DoubleLinkedQueueEntry_E); |
| 1579 function _DoubleLinkedQueueEntrySentinel() { |
| 1580 // Initializers done |
| 1581 DoubleLinkedQueueEntry_E.call(this, null); |
| 1582 this._link(this, this); |
| 1583 } |
| 1584 _DoubleLinkedQueueEntrySentinel.prototype.remove = function() { |
| 1585 $throw(const$5/*const EmptyQueueException()*/); |
| 1586 } |
| 1587 _DoubleLinkedQueueEntrySentinel.prototype._asNonSentinelEntry = function() { |
| 1588 return null; |
| 1589 } |
| 1590 _DoubleLinkedQueueEntrySentinel.prototype.get$element = function() { |
| 1591 $throw(const$5/*const EmptyQueueException()*/); |
| 1592 } |
| 1593 // ********** Code for _DoubleLinkedQueueEntrySentinel_E ************** |
| 1594 $inherits(_DoubleLinkedQueueEntrySentinel_E, _DoubleLinkedQueueEntrySentinel); |
| 1595 function _DoubleLinkedQueueEntrySentinel_E() { |
| 1596 // Initializers done |
| 1597 DoubleLinkedQueueEntry_E.call(this, null); |
| 1598 this._link(this, this); |
| 1599 } |
| 1600 // ********** Code for _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V ********
****** |
| 1601 $inherits(_DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V, _DoubleLinkedQueueEn
trySentinel); |
| 1602 function _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V() { |
| 1603 // Initializers done |
| 1604 DoubleLinkedQueueEntry_KeyValuePair_K$V.call(this, null); |
| 1605 this._link(this, this); |
| 1606 } |
| 1607 // ********** Code for DoubleLinkedQueue ************** |
| 1608 function DoubleLinkedQueue() { |
| 1609 // Initializers done |
| 1610 this._sentinel = new _DoubleLinkedQueueEntrySentinel_E(); |
| 1611 } |
| 1612 DoubleLinkedQueue.prototype.addLast = function(value) { |
| 1613 this._sentinel.prepend(value); |
| 1614 } |
| 1615 DoubleLinkedQueue.prototype.add = function(value) { |
| 1616 this.addLast(value); |
| 1617 } |
| 1618 DoubleLinkedQueue.prototype.addAll = function(collection) { |
| 1619 for (var $$i = collection.iterator(); $$i.hasNext$0(); ) { |
| 1620 var e = $$i.next$0(); |
| 1621 this.add(e); |
| 1622 } |
| 1623 } |
| 1624 DoubleLinkedQueue.prototype.removeLast = function() { |
| 1625 return this._sentinel._previous.remove(); |
| 1626 } |
| 1627 DoubleLinkedQueue.prototype.last = function() { |
| 1628 return this._sentinel._previous.get$element(); |
| 1629 } |
| 1630 DoubleLinkedQueue.prototype.get$length = function() { |
| 1631 var counter = 0; |
| 1632 this.forEach(function _(element) { |
| 1633 counter++; |
| 1634 } |
| 1635 ); |
| 1636 return counter; |
| 1637 } |
| 1638 Object.defineProperty(DoubleLinkedQueue.prototype, "length", { |
| 1639 get: DoubleLinkedQueue.prototype.get$length |
| 1640 }); |
| 1641 DoubleLinkedQueue.prototype.isEmpty = function() { |
| 1642 return (this._sentinel._next === this._sentinel); |
| 1643 } |
| 1644 DoubleLinkedQueue.prototype.clear = function() { |
| 1645 this._sentinel._next = this._sentinel; |
| 1646 this._sentinel._previous = this._sentinel; |
| 1647 } |
| 1648 DoubleLinkedQueue.prototype.forEach = function(f) { |
| 1649 var entry = this._sentinel._next; |
| 1650 while (entry !== this._sentinel) { |
| 1651 var nextEntry = entry._next; |
| 1652 f(entry._element); |
| 1653 entry = nextEntry; |
| 1654 } |
| 1655 } |
| 1656 DoubleLinkedQueue.prototype.every = function(f) { |
| 1657 var entry = this._sentinel._next; |
| 1658 while (entry !== this._sentinel) { |
| 1659 var nextEntry = entry._next; |
| 1660 if (!f(entry._element)) return false; |
| 1661 entry = nextEntry; |
| 1662 } |
| 1663 return true; |
| 1664 } |
| 1665 DoubleLinkedQueue.prototype.some = function(f) { |
| 1666 var entry = this._sentinel._next; |
| 1667 while (entry !== this._sentinel) { |
| 1668 var nextEntry = entry._next; |
| 1669 if (f(entry._element)) return true; |
| 1670 entry = nextEntry; |
| 1671 } |
| 1672 return false; |
| 1673 } |
| 1674 DoubleLinkedQueue.prototype.filter = function(f) { |
| 1675 var other = new DoubleLinkedQueue(); |
| 1676 var entry = this._sentinel._next; |
| 1677 while (entry !== this._sentinel) { |
| 1678 var nextEntry = entry._next; |
| 1679 if (f(entry._element)) other.addLast(entry._element); |
| 1680 entry = nextEntry; |
| 1681 } |
| 1682 return other; |
| 1683 } |
| 1684 DoubleLinkedQueue.prototype.iterator = function() { |
| 1685 return new _DoubleLinkedQueueIterator_E(this._sentinel); |
| 1686 } |
| 1687 DoubleLinkedQueue.prototype.add$1 = DoubleLinkedQueue.prototype.add; |
| 1688 DoubleLinkedQueue.prototype.addAll$1 = DoubleLinkedQueue.prototype.addAll; |
| 1689 DoubleLinkedQueue.prototype.clear$0 = DoubleLinkedQueue.prototype.clear; |
| 1690 DoubleLinkedQueue.prototype.every$1 = function($0) { |
| 1691 return this.every(to$call$1($0)); |
| 1692 }; |
| 1693 DoubleLinkedQueue.prototype.filter$1 = function($0) { |
| 1694 return this.filter(to$call$1($0)); |
| 1695 }; |
| 1696 DoubleLinkedQueue.prototype.forEach$1 = function($0) { |
| 1697 return this.forEach(to$call$1($0)); |
| 1698 }; |
| 1699 DoubleLinkedQueue.prototype.isEmpty$0 = DoubleLinkedQueue.prototype.isEmpty; |
| 1700 DoubleLinkedQueue.prototype.iterator$0 = DoubleLinkedQueue.prototype.iterator; |
| 1701 DoubleLinkedQueue.prototype.last$0 = DoubleLinkedQueue.prototype.last; |
| 1702 DoubleLinkedQueue.prototype.removeLast$0 = DoubleLinkedQueue.prototype.removeLas
t; |
| 1703 DoubleLinkedQueue.prototype.some$1 = function($0) { |
| 1704 return this.some(to$call$1($0)); |
| 1705 }; |
| 1706 // ********** Code for DoubleLinkedQueue_E ************** |
| 1707 $inherits(DoubleLinkedQueue_E, DoubleLinkedQueue); |
| 1708 function DoubleLinkedQueue_E() {} |
| 1709 // ********** Code for DoubleLinkedQueue_KeyValuePair_K$V ************** |
| 1710 $inherits(DoubleLinkedQueue_KeyValuePair_K$V, DoubleLinkedQueue); |
| 1711 function DoubleLinkedQueue_KeyValuePair_K$V() { |
| 1712 // Initializers done |
| 1713 this._sentinel = new _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V(); |
| 1714 } |
| 1715 DoubleLinkedQueue_KeyValuePair_K$V.prototype.addLast = function(value) { |
| 1716 this._sentinel.prepend(value); |
| 1717 } |
| 1718 DoubleLinkedQueue_KeyValuePair_K$V.prototype.lastEntry = function() { |
| 1719 return this._sentinel.previousEntry(); |
| 1720 } |
| 1721 DoubleLinkedQueue_KeyValuePair_K$V.prototype.clear = function() { |
| 1722 this._sentinel._next = this._sentinel; |
| 1723 this._sentinel._previous = this._sentinel; |
| 1724 } |
| 1725 DoubleLinkedQueue_KeyValuePair_K$V.prototype.forEach = function(f) { |
| 1726 var entry = this._sentinel._next; |
| 1727 while (entry !== this._sentinel) { |
| 1728 var nextEntry = entry._next; |
| 1729 f(entry._element); |
| 1730 entry = nextEntry; |
| 1731 } |
| 1732 } |
| 1733 // ********** Code for _DoubleLinkedQueueIterator ************** |
| 1734 function _DoubleLinkedQueueIterator(_sentinel) { |
| 1735 this._sentinel = _sentinel; |
| 1736 // Initializers done |
| 1737 this._currentEntry = this._sentinel; |
| 1738 } |
| 1739 _DoubleLinkedQueueIterator.prototype.hasNext = function() { |
| 1740 return this._currentEntry._next !== this._sentinel; |
| 1741 } |
| 1742 _DoubleLinkedQueueIterator.prototype.next = function() { |
| 1743 if (!this.hasNext()) { |
| 1744 $throw(const$1/*const NoMoreElementsException()*/); |
| 1745 } |
| 1746 this._currentEntry = this._currentEntry._next; |
| 1747 return this._currentEntry.get$element(); |
| 1748 } |
| 1749 _DoubleLinkedQueueIterator.prototype.hasNext$0 = _DoubleLinkedQueueIterator.prot
otype.hasNext; |
| 1750 _DoubleLinkedQueueIterator.prototype.next$0 = _DoubleLinkedQueueIterator.prototy
pe.next; |
| 1751 // ********** Code for _DoubleLinkedQueueIterator_E ************** |
| 1752 $inherits(_DoubleLinkedQueueIterator_E, _DoubleLinkedQueueIterator); |
| 1753 function _DoubleLinkedQueueIterator_E(_sentinel) { |
| 1754 this._sentinel = _sentinel; |
| 1755 // Initializers done |
| 1756 this._currentEntry = this._sentinel; |
| 1757 } |
| 1758 // ********** Code for StopwatchImplementation ************** |
| 1759 function StopwatchImplementation() { |
| 1760 this._start = null; |
| 1761 this._stop = null; |
| 1762 // Initializers done |
| 1763 } |
| 1764 StopwatchImplementation.prototype.start = function() { |
| 1765 if (this._start == null) { |
| 1766 this._start = Clock.now(); |
| 1767 } |
| 1768 else { |
| 1769 if (this._stop == null) { |
| 1770 return; |
| 1771 } |
| 1772 this._start = Clock.now() - (this._stop - this._start); |
| 1773 } |
| 1774 } |
| 1775 StopwatchImplementation.prototype.stop = function() { |
| 1776 if (this._start == null) { |
| 1777 return; |
| 1778 } |
| 1779 this._stop = Clock.now(); |
| 1780 } |
| 1781 StopwatchImplementation.prototype.elapsed = function() { |
| 1782 if (this._start == null) { |
| 1783 return 0; |
| 1784 } |
| 1785 return (this._stop == null) ? (Clock.now() - this._start) : (this._stop - this
._start); |
| 1786 } |
| 1787 StopwatchImplementation.prototype.elapsedInMs = function() { |
| 1788 return $truncdiv((this.elapsed() * 1000), this.frequency()); |
| 1789 } |
| 1790 StopwatchImplementation.prototype.frequency = function() { |
| 1791 return Clock.frequency(); |
| 1792 } |
| 1793 StopwatchImplementation.prototype.start$0 = StopwatchImplementation.prototype.st
art; |
| 1794 // ********** Code for StringBufferImpl ************** |
| 1795 function StringBufferImpl(content) { |
| 1796 // Initializers done |
| 1797 this.clear(); |
| 1798 this.add(content); |
| 1799 } |
| 1800 StringBufferImpl.prototype.get$length = function() { |
| 1801 return this._length; |
| 1802 } |
| 1803 Object.defineProperty(StringBufferImpl.prototype, "length", { |
| 1804 get: StringBufferImpl.prototype.get$length |
| 1805 }); |
| 1806 StringBufferImpl.prototype.isEmpty = function() { |
| 1807 return this._length == 0; |
| 1808 } |
| 1809 StringBufferImpl.prototype.add = function(obj) { |
| 1810 var str = obj.toString(); |
| 1811 if (str == null || str.isEmpty()) return this; |
| 1812 this._buffer.add(str); |
| 1813 this._length += str.length; |
| 1814 return this; |
| 1815 } |
| 1816 StringBufferImpl.prototype.addAll = function(objects) { |
| 1817 for (var $$i = objects.iterator(); $$i.hasNext$0(); ) { |
| 1818 var obj = $$i.next$0(); |
| 1819 this.add(obj); |
| 1820 } |
| 1821 return this; |
| 1822 } |
| 1823 StringBufferImpl.prototype.clear = function() { |
| 1824 this._buffer = new ListFactory(); |
| 1825 this._length = 0; |
| 1826 return this; |
| 1827 } |
| 1828 StringBufferImpl.prototype.toString = function() { |
| 1829 if (this._buffer.length == 0) return ""; |
| 1830 if (this._buffer.length == 1) return this._buffer.$index(0); |
| 1831 var result = StringBase.concatAll(this._buffer); |
| 1832 this._buffer.clear(); |
| 1833 this._buffer.add(result); |
| 1834 return result; |
| 1835 } |
| 1836 StringBufferImpl.prototype.add$1 = StringBufferImpl.prototype.add; |
| 1837 StringBufferImpl.prototype.addAll$1 = StringBufferImpl.prototype.addAll; |
| 1838 StringBufferImpl.prototype.clear$0 = StringBufferImpl.prototype.clear; |
| 1839 StringBufferImpl.prototype.isEmpty$0 = StringBufferImpl.prototype.isEmpty; |
| 1840 StringBufferImpl.prototype.toString$0 = StringBufferImpl.prototype.toString; |
| 1841 // ********** Code for StringBase ************** |
| 1842 function StringBase() {} |
| 1843 StringBase.createFromCharCodes = function(charCodes) { |
| 1844 if (Object.getPrototypeOf(charCodes) !== Array.prototype) { |
| 1845 charCodes = new ListFactory.ListFactory$from$factory(charCodes); |
| 1846 } |
| 1847 return String.fromCharCode.apply(null, charCodes); |
| 1848 } |
| 1849 StringBase.join = function(strings, separator) { |
| 1850 if (strings.length == 0) return ''; |
| 1851 var s = strings.$index(0); |
| 1852 for (var i = 1; |
| 1853 i < strings.length; i++) { |
| 1854 s = s + separator + strings.$index(i); |
| 1855 } |
| 1856 return s; |
| 1857 } |
| 1858 StringBase.concatAll = function(strings) { |
| 1859 return StringBase.join(strings, ""); |
| 1860 } |
| 1861 // ********** Code for StringImplementation ************** |
| 1862 StringImplementation = String; |
| 1863 StringImplementation.prototype.endsWith = function(other) { |
| 1864 if (other.length > this.length) return false; |
| 1865 return other == this.substring(this.length - other.length); |
| 1866 } |
| 1867 StringImplementation.prototype.startsWith = function(other) { |
| 1868 if (other.length > this.length) return false; |
| 1869 return other == this.substring(0, other.length); |
| 1870 } |
| 1871 StringImplementation.prototype.isEmpty = function() { |
| 1872 return this.length == 0; |
| 1873 } |
| 1874 StringImplementation.prototype.contains = function(pattern, startIndex) { |
| 1875 return this.indexOf(pattern, startIndex) >= 0; |
| 1876 } |
| 1877 StringImplementation.prototype._replaceFirst = function(from, to) { |
| 1878 return this.replace(from, to); |
| 1879 } |
| 1880 StringImplementation.prototype._replaceFirstRegExp = function(from, to) { |
| 1881 return this.replace(from.re, to); |
| 1882 } |
| 1883 StringImplementation.prototype.replaceFirst = function(from, to) { |
| 1884 if ((typeof(from) == 'string')) return this._replaceFirst(from, to); |
| 1885 if (!!(from && from.is$RegExp())) return this._replaceFirstRegExp(from, to); |
| 1886 var $$list = from.allMatches(this); |
| 1887 for (var $$i = from.allMatches(this).iterator(); $$i.hasNext$0(); ) { |
| 1888 var match = $$i.next$0(); |
| 1889 return this.substring(0, match.start$0()) + to + this.substring(match.end$0(
)); |
| 1890 } |
| 1891 } |
| 1892 StringImplementation.prototype.replaceAll = function(from, to) { |
| 1893 if (typeof(from) == 'string' || from instanceof String) { |
| 1894 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); |
| 1895 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun! |
| 1896 } |
| 1897 return this.replace(from, to); |
| 1898 } |
| 1899 StringImplementation.prototype.hashCode = function() { |
| 1900 if (this.hash_ === undefined) { |
| 1901 for (var i = 0; i < this.length; i++) { |
| 1902 var ch = this.charCodeAt(i); |
| 1903 this.hash_ += ch; |
| 1904 this.hash_ += this.hash_ << 10; |
| 1905 this.hash_ ^= this.hash_ >> 6; |
| 1906 } |
| 1907 |
| 1908 this.hash_ += this.hash_ << 3; |
| 1909 this.hash_ ^= this.hash_ >> 11; |
| 1910 this.hash_ += this.hash_ << 15; |
| 1911 this.hash_ = this.hash_ & ((1 << 29) - 1); |
| 1912 } |
| 1913 return this.hash_; |
| 1914 } |
| 1915 StringImplementation.prototype.compareTo = function(other) { |
| 1916 return this == other ? 0 : this < other ? -1 : 1; |
| 1917 } |
| 1918 StringImplementation.prototype.compareTo$1 = StringImplementation.prototype.comp
areTo; |
| 1919 StringImplementation.prototype.contains$1 = StringImplementation.prototype.conta
ins; |
| 1920 StringImplementation.prototype.endsWith$1 = StringImplementation.prototype.endsW
ith; |
| 1921 StringImplementation.prototype.hashCode$0 = StringImplementation.prototype.hashC
ode; |
| 1922 StringImplementation.prototype.indexOf$1 = StringImplementation.prototype.indexO
f; |
| 1923 StringImplementation.prototype.isEmpty$0 = StringImplementation.prototype.isEmpt
y; |
| 1924 StringImplementation.prototype.replaceAll$2 = StringImplementation.prototype.rep
laceAll; |
| 1925 StringImplementation.prototype.replaceFirst$2 = StringImplementation.prototype.r
eplaceFirst; |
| 1926 StringImplementation.prototype.startsWith$1 = StringImplementation.prototype.sta
rtsWith; |
| 1927 StringImplementation.prototype.substring$1 = StringImplementation.prototype.subs
tring; |
| 1928 StringImplementation.prototype.substring$2 = StringImplementation.prototype.subs
tring; |
| 1929 // ********** Code for Collections ************** |
| 1930 function Collections() {} |
| 1931 Collections.forEach = function(iterable, f) { |
| 1932 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1933 var e = $$i.next$0(); |
| 1934 f(e); |
| 1935 } |
| 1936 } |
| 1937 Collections.some = function(iterable, f) { |
| 1938 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1939 var e = $$i.next$0(); |
| 1940 if (f(e)) return true; |
| 1941 } |
| 1942 return false; |
| 1943 } |
| 1944 Collections.every = function(iterable, f) { |
| 1945 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1946 var e = $$i.next$0(); |
| 1947 if (!f(e)) return false; |
| 1948 } |
| 1949 return true; |
| 1950 } |
| 1951 Collections.filter = function(source, destination, f) { |
| 1952 for (var $$i = source.iterator(); $$i.hasNext$0(); ) { |
| 1953 var e = $$i.next$0(); |
| 1954 if (f(e)) destination.add(e); |
| 1955 } |
| 1956 return destination; |
| 1957 } |
| 1958 // ********** Code for top level ************** |
| 1959 // ********** Library dom ************** |
| 1960 // ********** Natives frog_dom.js ************** |
| 1961 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 1962 // for details. All rights reserved. Use of this source code is governed by a |
| 1963 // BSD-style license that can be found in the LICENSE file. |
| 1964 |
| 1965 // TODO(jmesserly): we need to find a way to avoid conflicts with other |
| 1966 // generated "typeName" fields. Ideally we wouldn't be patching 'Object' here. |
| 1967 Object.prototype.get$typeName = Object.prototype.$typeNameOf; |
| 1968 // ********** Code for Window ************** |
| 1969 // ********** Code for AbstractWorker ************** |
| 1970 Object.prototype.$typeNameOf = function() { |
| 1971 if ((typeof(window) != 'undefined' && window.constructor.name == 'DOMWindow') |
| 1972 || typeof(process) != 'undefined') { // fast-path for Chrome and Node |
| 1973 return this.constructor.name; |
| 1974 } |
| 1975 var str = Object.prototype.toString.call(this); |
| 1976 str = str.substring(8, str.length - 1); |
| 1977 if (str == 'Window') str = 'DOMWindow'; |
| 1978 return str; |
| 1979 } |
| 1980 function $dynamic(name) { |
| 1981 var f = Object.prototype[name]; |
| 1982 if (f && f.methods) return f.methods; |
| 1983 |
| 1984 var methods = {}; |
| 1985 if (f) methods.Object = f; |
| 1986 function $dynamicBind() { |
| 1987 // Find the target method |
| 1988 var method; |
| 1989 var proto = Object.getPrototypeOf(this); |
| 1990 var obj = this; |
| 1991 do { |
| 1992 method = methods[obj.$typeNameOf()]; |
| 1993 if (method) break; |
| 1994 obj = Object.getPrototypeOf(obj); |
| 1995 } while (obj); |
| 1996 |
| 1997 // Patch the prototype, but don't overwrite an existing stub, like |
| 1998 // the one on Object.prototype. |
| 1999 if (!proto.hasOwnProperty(name)) proto[name] = method || methods.Object; |
| 2000 |
| 2001 return method.apply(this, Array.prototype.slice.call(arguments)); |
| 2002 }; |
| 2003 $dynamicBind.methods = methods; |
| 2004 Object.prototype[name] = $dynamicBind; |
| 2005 return methods; |
| 2006 } |
| 2007 $dynamic("addEventListener$3").AbstractWorker = function($0, $1, $2) { |
| 2008 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2009 }; |
| 2010 // ********** Code for ArrayBuffer ************** |
| 2011 // ********** Code for ArrayBufferView ************** |
| 2012 // ********** Code for Attr ************** |
| 2013 // ********** Code for AudioBuffer ************** |
| 2014 // ********** Code for AudioBufferSourceNode ************** |
| 2015 // ********** Code for AudioChannelMerger ************** |
| 2016 // ********** Code for AudioChannelSplitter ************** |
| 2017 // ********** Code for AudioContext ************** |
| 2018 // ********** Code for AudioDestinationNode ************** |
| 2019 // ********** Code for AudioGain ************** |
| 2020 // ********** Code for AudioGainNode ************** |
| 2021 // ********** Code for AudioListener ************** |
| 2022 // ********** Code for AudioNode ************** |
| 2023 // ********** Code for AudioPannerNode ************** |
| 2024 // ********** Code for AudioParam ************** |
| 2025 // ********** Code for AudioProcessingEvent ************** |
| 2026 // ********** Code for AudioSourceNode ************** |
| 2027 // ********** Code for BarInfo ************** |
| 2028 // ********** Code for BeforeLoadEvent ************** |
| 2029 // ********** Code for BiquadFilterNode ************** |
| 2030 // ********** Code for Blob ************** |
| 2031 // ********** Code for CDATASection ************** |
| 2032 // ********** Code for CSSCharsetRule ************** |
| 2033 // ********** Code for CSSFontFaceRule ************** |
| 2034 // ********** Code for CSSImportRule ************** |
| 2035 // ********** Code for CSSMediaRule ************** |
| 2036 // ********** Code for CSSPageRule ************** |
| 2037 // ********** Code for CSSPrimitiveValue ************** |
| 2038 // ********** Code for CSSRule ************** |
| 2039 // ********** Code for CSSRuleList ************** |
| 2040 // ********** Code for CSSStyleDeclaration ************** |
| 2041 $dynamic("setProperty$2").CSSStyleDeclaration = function($0, $1) { |
| 2042 return this.setProperty($0, $1); |
| 2043 }; |
| 2044 // ********** Code for CSSStyleRule ************** |
| 2045 // ********** Code for CSSStyleSheet ************** |
| 2046 // ********** Code for CSSUnknownRule ************** |
| 2047 // ********** Code for CSSValue ************** |
| 2048 // ********** Code for CSSValueList ************** |
| 2049 // ********** Code for CanvasGradient ************** |
| 2050 // ********** Code for CanvasPattern ************** |
| 2051 // ********** Code for CanvasPixelArray ************** |
| 2052 // ********** Code for CanvasRenderingContext ************** |
| 2053 // ********** Code for CanvasRenderingContext2D ************** |
| 2054 // ********** Code for CharacterData ************** |
| 2055 // ********** Code for ClientRect ************** |
| 2056 // ********** Code for ClientRectList ************** |
| 2057 // ********** Code for Clipboard ************** |
| 2058 // ********** Code for CloseEvent ************** |
| 2059 // ********** Code for Comment ************** |
| 2060 // ********** Code for CompositionEvent ************** |
| 2061 // ********** Code for Console ************** |
| 2062 Console = (typeof console == 'undefined' ? {} : console); |
| 2063 // ********** Code for ConvolverNode ************** |
| 2064 // ********** Code for Coordinates ************** |
| 2065 // ********** Code for Counter ************** |
| 2066 // ********** Code for Crypto ************** |
| 2067 // ********** Code for CustomEvent ************** |
| 2068 // ********** Code for DOMApplicationCache ************** |
| 2069 $dynamic("addEventListener$3").DOMApplicationCache = function($0, $1, $2) { |
| 2070 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2071 }; |
| 2072 // ********** Code for DOMException ************** |
| 2073 $dynamic("toString$0").DOMException = function() { |
| 2074 return this.toString(); |
| 2075 }; |
| 2076 // ********** Code for DOMFileSystem ************** |
| 2077 // ********** Code for DOMFileSystemSync ************** |
| 2078 // ********** Code for DOMFormData ************** |
| 2079 // ********** Code for DOMImplementation ************** |
| 2080 // ********** Code for DOMMimeType ************** |
| 2081 // ********** Code for DOMMimeTypeArray ************** |
| 2082 // ********** Code for DOMParser ************** |
| 2083 // ********** Code for DOMPlugin ************** |
| 2084 // ********** Code for DOMPluginArray ************** |
| 2085 // ********** Code for DOMSelection ************** |
| 2086 $dynamic("toString$0").DOMSelection = function() { |
| 2087 return this.toString(); |
| 2088 }; |
| 2089 // ********** Code for DOMSettableTokenList ************** |
| 2090 // ********** Code for DOMTokenList ************** |
| 2091 $dynamic("add$1").DOMTokenList = function($0) { |
| 2092 return this.add($0); |
| 2093 }; |
| 2094 $dynamic("contains$1").DOMTokenList = function($0) { |
| 2095 return this.contains($0); |
| 2096 }; |
| 2097 $dynamic("toString$0").DOMTokenList = function() { |
| 2098 return this.toString(); |
| 2099 }; |
| 2100 // ********** Code for DOMURL ************** |
| 2101 // ********** Code for DOMWindow ************** |
| 2102 $dynamic("addEventListener$3").DOMWindow = function($0, $1, $2) { |
| 2103 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2104 }; |
| 2105 $dynamic("focus$0").DOMWindow = function() { |
| 2106 return this.focus(); |
| 2107 }; |
| 2108 // ********** Code for DataTransferItem ************** |
| 2109 // ********** Code for DataTransferItemList ************** |
| 2110 $dynamic("clear$0").DataTransferItemList = function() { |
| 2111 return this.clear(); |
| 2112 }; |
| 2113 // ********** Code for DataView ************** |
| 2114 // ********** Code for Database ************** |
| 2115 // ********** Code for DatabaseSync ************** |
| 2116 // ********** Code for DedicatedWorkerContext ************** |
| 2117 // ********** Code for DelayNode ************** |
| 2118 // ********** Code for DeviceMotionEvent ************** |
| 2119 // ********** Code for DeviceOrientationEvent ************** |
| 2120 // ********** Code for DirectoryEntry ************** |
| 2121 // ********** Code for DirectoryEntrySync ************** |
| 2122 // ********** Code for DirectoryReader ************** |
| 2123 // ********** Code for DirectoryReaderSync ************** |
| 2124 // ********** Code for Document ************** |
| 2125 // ********** Code for DocumentFragment ************** |
| 2126 // ********** Code for DocumentType ************** |
| 2127 // ********** Code for DynamicsCompressorNode ************** |
| 2128 // ********** Code for Element ************** |
| 2129 Element.prototype.focus$0 = function() { |
| 2130 return this.focus(); |
| 2131 }; |
| 2132 Element.prototype.getBoundingClientRect$0 = function() { |
| 2133 return this.getBoundingClientRect(); |
| 2134 }; |
| 2135 // ********** Code for ElementTimeControl ************** |
| 2136 // ********** Code for ElementTraversal ************** |
| 2137 // ********** Code for Entity ************** |
| 2138 // ********** Code for EntityReference ************** |
| 2139 // ********** Code for Entry ************** |
| 2140 // ********** Code for EntryArray ************** |
| 2141 // ********** Code for EntryArraySync ************** |
| 2142 // ********** Code for EntrySync ************** |
| 2143 // ********** Code for ErrorEvent ************** |
| 2144 // ********** Code for Event ************** |
| 2145 // ********** Code for EventException ************** |
| 2146 $dynamic("toString$0").EventException = function() { |
| 2147 return this.toString(); |
| 2148 }; |
| 2149 // ********** Code for EventSource ************** |
| 2150 $dynamic("addEventListener$3").EventSource = function($0, $1, $2) { |
| 2151 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2152 }; |
| 2153 // ********** Code for EventTarget ************** |
| 2154 $dynamic("addEventListener$3").EventTarget = function($0, $1, $2) { |
| 2155 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2156 }; |
| 2157 // ********** Code for File ************** |
| 2158 // ********** Code for FileEntry ************** |
| 2159 // ********** Code for FileEntrySync ************** |
| 2160 // ********** Code for FileError ************** |
| 2161 // ********** Code for FileException ************** |
| 2162 $dynamic("toString$0").FileException = function() { |
| 2163 return this.toString(); |
| 2164 }; |
| 2165 // ********** Code for FileList ************** |
| 2166 // ********** Code for FileReader ************** |
| 2167 // ********** Code for FileReaderSync ************** |
| 2168 // ********** Code for FileWriter ************** |
| 2169 // ********** Code for FileWriterSync ************** |
| 2170 // ********** Code for Float32Array ************** |
| 2171 Float32Array.prototype.is$List = function(){return true}; |
| 2172 // ********** Code for Float64Array ************** |
| 2173 Float64Array.prototype.is$List = function(){return true}; |
| 2174 // ********** Code for Geolocation ************** |
| 2175 // ********** Code for Geoposition ************** |
| 2176 // ********** Code for HTMLAllCollection ************** |
| 2177 // ********** Code for HTMLAnchorElement ************** |
| 2178 $dynamic("toString$0").HTMLAnchorElement = function() { |
| 2179 return this.toString(); |
| 2180 }; |
| 2181 // ********** Code for HTMLAppletElement ************** |
| 2182 // ********** Code for HTMLAreaElement ************** |
| 2183 // ********** Code for HTMLAudioElement ************** |
| 2184 // ********** Code for HTMLBRElement ************** |
| 2185 $dynamic("clear$0").HTMLBRElement = function() { |
| 2186 return this.clear(); |
| 2187 }; |
| 2188 // ********** Code for HTMLBaseElement ************** |
| 2189 // ********** Code for HTMLBaseFontElement ************** |
| 2190 // ********** Code for HTMLBodyElement ************** |
| 2191 // ********** Code for HTMLButtonElement ************** |
| 2192 // ********** Code for HTMLCanvasElement ************** |
| 2193 // ********** Code for HTMLCollection ************** |
| 2194 HTMLCollection.prototype.$setindex = function(index, value) { |
| 2195 $throw(new UnsupportedOperationException("Cannot assign element of immutable L
ist.")); |
| 2196 } |
| 2197 // ********** Code for HTMLDListElement ************** |
| 2198 // ********** Code for HTMLDataListElement ************** |
| 2199 // ********** Code for HTMLDetailsElement ************** |
| 2200 // ********** Code for HTMLDirectoryElement ************** |
| 2201 // ********** Code for HTMLDivElement ************** |
| 2202 // ********** Code for HTMLDocument ************** |
| 2203 $dynamic("clear$0").HTMLDocument = function() { |
| 2204 return this.clear(); |
| 2205 }; |
| 2206 // ********** Code for HTMLElement ************** |
| 2207 // ********** Code for HTMLEmbedElement ************** |
| 2208 // ********** Code for HTMLFieldSetElement ************** |
| 2209 // ********** Code for HTMLFontElement ************** |
| 2210 // ********** Code for HTMLFormElement ************** |
| 2211 // ********** Code for HTMLFrameElement ************** |
| 2212 // ********** Code for HTMLFrameSetElement ************** |
| 2213 // ********** Code for HTMLHRElement ************** |
| 2214 // ********** Code for HTMLHeadElement ************** |
| 2215 // ********** Code for HTMLHeadingElement ************** |
| 2216 // ********** Code for HTMLHtmlElement ************** |
| 2217 // ********** Code for HTMLIFrameElement ************** |
| 2218 // ********** Code for HTMLImageElement ************** |
| 2219 // ********** Code for HTMLInputElement ************** |
| 2220 HTMLInputElement.prototype.select$0 = function() { |
| 2221 return this.select(); |
| 2222 }; |
| 2223 // ********** Code for HTMLIsIndexElement ************** |
| 2224 // ********** Code for HTMLKeygenElement ************** |
| 2225 // ********** Code for HTMLLIElement ************** |
| 2226 // ********** Code for HTMLLabelElement ************** |
| 2227 // ********** Code for HTMLLegendElement ************** |
| 2228 // ********** Code for HTMLLinkElement ************** |
| 2229 // ********** Code for HTMLMapElement ************** |
| 2230 // ********** Code for HTMLMarqueeElement ************** |
| 2231 $dynamic("start$0").HTMLMarqueeElement = function() { |
| 2232 return this.start(); |
| 2233 }; |
| 2234 // ********** Code for HTMLMediaElement ************** |
| 2235 // ********** Code for HTMLMenuElement ************** |
| 2236 // ********** Code for HTMLMetaElement ************** |
| 2237 // ********** Code for HTMLMeterElement ************** |
| 2238 // ********** Code for HTMLModElement ************** |
| 2239 // ********** Code for HTMLOListElement ************** |
| 2240 $dynamic("start$0").HTMLOListElement = function() { |
| 2241 return this.start(); |
| 2242 }; |
| 2243 // ********** Code for HTMLObjectElement ************** |
| 2244 // ********** Code for HTMLOptGroupElement ************** |
| 2245 // ********** Code for HTMLOptionElement ************** |
| 2246 // ********** Code for HTMLOptionsCollection ************** |
| 2247 // ********** Code for HTMLOutputElement ************** |
| 2248 // ********** Code for HTMLParagraphElement ************** |
| 2249 // ********** Code for HTMLParamElement ************** |
| 2250 // ********** Code for HTMLPreElement ************** |
| 2251 // ********** Code for HTMLProgressElement ************** |
| 2252 // ********** Code for HTMLQuoteElement ************** |
| 2253 // ********** Code for HTMLScriptElement ************** |
| 2254 // ********** Code for HTMLSelectElement ************** |
| 2255 // ********** Code for HTMLSourceElement ************** |
| 2256 // ********** Code for HTMLSpanElement ************** |
| 2257 // ********** Code for HTMLStyleElement ************** |
| 2258 // ********** Code for HTMLTableCaptionElement ************** |
| 2259 // ********** Code for HTMLTableCellElement ************** |
| 2260 // ********** Code for HTMLTableColElement ************** |
| 2261 // ********** Code for HTMLTableElement ************** |
| 2262 // ********** Code for HTMLTableRowElement ************** |
| 2263 // ********** Code for HTMLTableSectionElement ************** |
| 2264 // ********** Code for HTMLTextAreaElement ************** |
| 2265 $dynamic("select$0").HTMLTextAreaElement = function() { |
| 2266 return this.select(); |
| 2267 }; |
| 2268 // ********** Code for HTMLTitleElement ************** |
| 2269 // ********** Code for HTMLTrackElement ************** |
| 2270 // ********** Code for HTMLUListElement ************** |
| 2271 // ********** Code for HTMLUnknownElement ************** |
| 2272 // ********** Code for HTMLVideoElement ************** |
| 2273 // ********** Code for HashChangeEvent ************** |
| 2274 // ********** Code for HighPass2FilterNode ************** |
| 2275 // ********** Code for History ************** |
| 2276 // ********** Code for IDBAny ************** |
| 2277 // ********** Code for IDBCursor ************** |
| 2278 // ********** Code for IDBCursorWithValue ************** |
| 2279 // ********** Code for IDBDatabase ************** |
| 2280 $dynamic("addEventListener$3").IDBDatabase = function($0, $1, $2) { |
| 2281 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2282 }; |
| 2283 // ********** Code for IDBDatabaseError ************** |
| 2284 // ********** Code for IDBDatabaseException ************** |
| 2285 $dynamic("toString$0").IDBDatabaseException = function() { |
| 2286 return this.toString(); |
| 2287 }; |
| 2288 // ********** Code for IDBFactory ************** |
| 2289 // ********** Code for IDBIndex ************** |
| 2290 // ********** Code for IDBKey ************** |
| 2291 // ********** Code for IDBKeyRange ************** |
| 2292 // ********** Code for IDBObjectStore ************** |
| 2293 $dynamic("add$1").IDBObjectStore = function($0) { |
| 2294 return this.add($0); |
| 2295 }; |
| 2296 $dynamic("clear$0").IDBObjectStore = function() { |
| 2297 return this.clear(); |
| 2298 }; |
| 2299 // ********** Code for IDBRequest ************** |
| 2300 $dynamic("addEventListener$3").IDBRequest = function($0, $1, $2) { |
| 2301 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2302 }; |
| 2303 // ********** Code for IDBTransaction ************** |
| 2304 $dynamic("addEventListener$3").IDBTransaction = function($0, $1, $2) { |
| 2305 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2306 }; |
| 2307 // ********** Code for IDBVersionChangeEvent ************** |
| 2308 // ********** Code for IDBVersionChangeRequest ************** |
| 2309 // ********** Code for ImageData ************** |
| 2310 // ********** Code for InjectedScriptHost ************** |
| 2311 // ********** Code for InspectorFrontendHost ************** |
| 2312 // ********** Code for Int16Array ************** |
| 2313 Int16Array.prototype.is$List = function(){return true}; |
| 2314 // ********** Code for Int32Array ************** |
| 2315 Int32Array.prototype.is$List = function(){return true}; |
| 2316 // ********** Code for Int8Array ************** |
| 2317 Int8Array.prototype.is$List = function(){return true}; |
| 2318 // ********** Code for JavaScriptAudioNode ************** |
| 2319 // ********** Code for JavaScriptCallFrame ************** |
| 2320 // ********** Code for KeyboardEvent ************** |
| 2321 // ********** Code for Location ************** |
| 2322 $dynamic("toString$0").Location = function() { |
| 2323 return this.toString(); |
| 2324 }; |
| 2325 // ********** Code for LowPass2FilterNode ************** |
| 2326 // ********** Code for MediaElementAudioSourceNode ************** |
| 2327 // ********** Code for MediaError ************** |
| 2328 // ********** Code for MediaList ************** |
| 2329 // ********** Code for MediaQueryList ************** |
| 2330 // ********** Code for MediaQueryListListener ************** |
| 2331 // ********** Code for MemoryInfo ************** |
| 2332 // ********** Code for MessageChannel ************** |
| 2333 // ********** Code for MessageEvent ************** |
| 2334 // ********** Code for MessagePort ************** |
| 2335 $dynamic("addEventListener$3").MessagePort = function($0, $1, $2) { |
| 2336 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2337 }; |
| 2338 $dynamic("start$0").MessagePort = function() { |
| 2339 return this.start(); |
| 2340 }; |
| 2341 // ********** Code for Metadata ************** |
| 2342 // ********** Code for MouseEvent ************** |
| 2343 // ********** Code for MutationCallback ************** |
| 2344 // ********** Code for MutationEvent ************** |
| 2345 // ********** Code for MutationRecord ************** |
| 2346 // ********** Code for NamedNodeMap ************** |
| 2347 // ********** Code for Navigator ************** |
| 2348 // ********** Code for NavigatorUserMediaError ************** |
| 2349 // ********** Code for NavigatorUserMediaSuccessCallback ************** |
| 2350 // ********** Code for Node ************** |
| 2351 Node.prototype.addEventListener$3 = function($0, $1, $2) { |
| 2352 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2353 }; |
| 2354 Node.prototype.appendChild$1 = function($0) { |
| 2355 return this.appendChild($0); |
| 2356 }; |
| 2357 Node.prototype.contains$1 = function($0) { |
| 2358 return this.contains($0); |
| 2359 }; |
| 2360 Node.prototype.insertBefore$2 = function($0, $1) { |
| 2361 return this.insertBefore($0, $1); |
| 2362 }; |
| 2363 Node.prototype.removeChild$1 = function($0) { |
| 2364 return this.removeChild($0); |
| 2365 }; |
| 2366 // ********** Code for NodeFilter ************** |
| 2367 // ********** Code for NodeIterator ************** |
| 2368 $dynamic("filter$1").NodeIterator = function($0) { |
| 2369 return this.filter($0); |
| 2370 }; |
| 2371 // ********** Code for NodeList ************** |
| 2372 // ********** Code for NodeSelector ************** |
| 2373 // ********** Code for Notation ************** |
| 2374 // ********** Code for Notification ************** |
| 2375 $dynamic("addEventListener$3").Notification = function($0, $1, $2) { |
| 2376 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2377 }; |
| 2378 // ********** Code for NotificationCenter ************** |
| 2379 // ********** Code for OESStandardDerivatives ************** |
| 2380 // ********** Code for OESTextureFloat ************** |
| 2381 // ********** Code for OESVertexArrayObject ************** |
| 2382 // ********** Code for OfflineAudioCompletionEvent ************** |
| 2383 // ********** Code for OperationNotAllowedException ************** |
| 2384 $dynamic("toString$0").OperationNotAllowedException = function() { |
| 2385 return this.toString(); |
| 2386 }; |
| 2387 // ********** Code for OverflowEvent ************** |
| 2388 // ********** Code for PageTransitionEvent ************** |
| 2389 // ********** Code for Performance ************** |
| 2390 // ********** Code for PerformanceNavigation ************** |
| 2391 // ********** Code for PerformanceTiming ************** |
| 2392 // ********** Code for PopStateEvent ************** |
| 2393 // ********** Code for PositionError ************** |
| 2394 // ********** Code for ProcessingInstruction ************** |
| 2395 // ********** Code for ProgressEvent ************** |
| 2396 // ********** Code for RGBColor ************** |
| 2397 // ********** Code for Range ************** |
| 2398 $dynamic("getBoundingClientRect$0").Range = function() { |
| 2399 return this.getBoundingClientRect(); |
| 2400 }; |
| 2401 $dynamic("toString$0").Range = function() { |
| 2402 return this.toString(); |
| 2403 }; |
| 2404 // ********** Code for RangeException ************** |
| 2405 $dynamic("toString$0").RangeException = function() { |
| 2406 return this.toString(); |
| 2407 }; |
| 2408 // ********** Code for RealtimeAnalyserNode ************** |
| 2409 // ********** Code for Rect ************** |
| 2410 // ********** Code for SQLError ************** |
| 2411 // ********** Code for SQLException ************** |
| 2412 // ********** Code for SQLResultSet ************** |
| 2413 // ********** Code for SQLResultSetRowList ************** |
| 2414 // ********** Code for SQLTransaction ************** |
| 2415 // ********** Code for SQLTransactionSync ************** |
| 2416 // ********** Code for SVGAElement ************** |
| 2417 // ********** Code for SVGAltGlyphDefElement ************** |
| 2418 // ********** Code for SVGAltGlyphElement ************** |
| 2419 // ********** Code for SVGAltGlyphItemElement ************** |
| 2420 // ********** Code for SVGAngle ************** |
| 2421 // ********** Code for SVGAnimateColorElement ************** |
| 2422 // ********** Code for SVGAnimateElement ************** |
| 2423 // ********** Code for SVGAnimateMotionElement ************** |
| 2424 // ********** Code for SVGAnimateTransformElement ************** |
| 2425 // ********** Code for SVGAnimatedAngle ************** |
| 2426 // ********** Code for SVGAnimatedBoolean ************** |
| 2427 // ********** Code for SVGAnimatedEnumeration ************** |
| 2428 // ********** Code for SVGAnimatedInteger ************** |
| 2429 // ********** Code for SVGAnimatedLength ************** |
| 2430 // ********** Code for SVGAnimatedLengthList ************** |
| 2431 // ********** Code for SVGAnimatedNumber ************** |
| 2432 // ********** Code for SVGAnimatedNumberList ************** |
| 2433 // ********** Code for SVGAnimatedPreserveAspectRatio ************** |
| 2434 // ********** Code for SVGAnimatedRect ************** |
| 2435 // ********** Code for SVGAnimatedString ************** |
| 2436 // ********** Code for SVGAnimatedTransformList ************** |
| 2437 // ********** Code for SVGAnimationElement ************** |
| 2438 // ********** Code for SVGCircleElement ************** |
| 2439 // ********** Code for SVGClipPathElement ************** |
| 2440 // ********** Code for SVGColor ************** |
| 2441 // ********** Code for SVGComponentTransferFunctionElement ************** |
| 2442 // ********** Code for SVGCursorElement ************** |
| 2443 // ********** Code for SVGDefsElement ************** |
| 2444 // ********** Code for SVGDescElement ************** |
| 2445 // ********** Code for SVGDocument ************** |
| 2446 // ********** Code for SVGElement ************** |
| 2447 // ********** Code for SVGElementInstance ************** |
| 2448 $dynamic("addEventListener$3").SVGElementInstance = function($0, $1, $2) { |
| 2449 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2450 }; |
| 2451 // ********** Code for SVGElementInstanceList ************** |
| 2452 // ********** Code for SVGEllipseElement ************** |
| 2453 // ********** Code for SVGException ************** |
| 2454 $dynamic("toString$0").SVGException = function() { |
| 2455 return this.toString(); |
| 2456 }; |
| 2457 // ********** Code for SVGExternalResourcesRequired ************** |
| 2458 // ********** Code for SVGFEBlendElement ************** |
| 2459 // ********** Code for SVGFEColorMatrixElement ************** |
| 2460 // ********** Code for SVGFEComponentTransferElement ************** |
| 2461 // ********** Code for SVGFECompositeElement ************** |
| 2462 // ********** Code for SVGFEConvolveMatrixElement ************** |
| 2463 // ********** Code for SVGFEDiffuseLightingElement ************** |
| 2464 // ********** Code for SVGFEDisplacementMapElement ************** |
| 2465 // ********** Code for SVGFEDistantLightElement ************** |
| 2466 // ********** Code for SVGFEDropShadowElement ************** |
| 2467 // ********** Code for SVGFEFloodElement ************** |
| 2468 // ********** Code for SVGFEFuncAElement ************** |
| 2469 // ********** Code for SVGFEFuncBElement ************** |
| 2470 // ********** Code for SVGFEFuncGElement ************** |
| 2471 // ********** Code for SVGFEFuncRElement ************** |
| 2472 // ********** Code for SVGFEGaussianBlurElement ************** |
| 2473 // ********** Code for SVGFEImageElement ************** |
| 2474 // ********** Code for SVGFEMergeElement ************** |
| 2475 // ********** Code for SVGFEMergeNodeElement ************** |
| 2476 // ********** Code for SVGFEMorphologyElement ************** |
| 2477 // ********** Code for SVGFEOffsetElement ************** |
| 2478 // ********** Code for SVGFEPointLightElement ************** |
| 2479 // ********** Code for SVGFESpecularLightingElement ************** |
| 2480 // ********** Code for SVGFESpotLightElement ************** |
| 2481 // ********** Code for SVGFETileElement ************** |
| 2482 // ********** Code for SVGFETurbulenceElement ************** |
| 2483 // ********** Code for SVGFilterElement ************** |
| 2484 // ********** Code for SVGFilterPrimitiveStandardAttributes ************** |
| 2485 // ********** Code for SVGFitToViewBox ************** |
| 2486 // ********** Code for SVGFontElement ************** |
| 2487 // ********** Code for SVGFontFaceElement ************** |
| 2488 // ********** Code for SVGFontFaceFormatElement ************** |
| 2489 // ********** Code for SVGFontFaceNameElement ************** |
| 2490 // ********** Code for SVGFontFaceSrcElement ************** |
| 2491 // ********** Code for SVGFontFaceUriElement ************** |
| 2492 // ********** Code for SVGForeignObjectElement ************** |
| 2493 // ********** Code for SVGGElement ************** |
| 2494 // ********** Code for SVGGlyphElement ************** |
| 2495 // ********** Code for SVGGlyphRefElement ************** |
| 2496 // ********** Code for SVGGradientElement ************** |
| 2497 // ********** Code for SVGHKernElement ************** |
| 2498 // ********** Code for SVGImageElement ************** |
| 2499 // ********** Code for SVGLangSpace ************** |
| 2500 // ********** Code for SVGLength ************** |
| 2501 // ********** Code for SVGLengthList ************** |
| 2502 $dynamic("clear$0").SVGLengthList = function() { |
| 2503 return this.clear(); |
| 2504 }; |
| 2505 // ********** Code for SVGLineElement ************** |
| 2506 // ********** Code for SVGLinearGradientElement ************** |
| 2507 // ********** Code for SVGLocatable ************** |
| 2508 // ********** Code for SVGMPathElement ************** |
| 2509 // ********** Code for SVGMarkerElement ************** |
| 2510 // ********** Code for SVGMaskElement ************** |
| 2511 // ********** Code for SVGMatrix ************** |
| 2512 // ********** Code for SVGMetadataElement ************** |
| 2513 // ********** Code for SVGMissingGlyphElement ************** |
| 2514 // ********** Code for SVGNumber ************** |
| 2515 // ********** Code for SVGNumberList ************** |
| 2516 $dynamic("clear$0").SVGNumberList = function() { |
| 2517 return this.clear(); |
| 2518 }; |
| 2519 // ********** Code for SVGPaint ************** |
| 2520 // ********** Code for SVGPathElement ************** |
| 2521 // ********** Code for SVGPathSeg ************** |
| 2522 // ********** Code for SVGPathSegArcAbs ************** |
| 2523 // ********** Code for SVGPathSegArcRel ************** |
| 2524 // ********** Code for SVGPathSegClosePath ************** |
| 2525 // ********** Code for SVGPathSegCurvetoCubicAbs ************** |
| 2526 // ********** Code for SVGPathSegCurvetoCubicRel ************** |
| 2527 // ********** Code for SVGPathSegCurvetoCubicSmoothAbs ************** |
| 2528 // ********** Code for SVGPathSegCurvetoCubicSmoothRel ************** |
| 2529 // ********** Code for SVGPathSegCurvetoQuadraticAbs ************** |
| 2530 // ********** Code for SVGPathSegCurvetoQuadraticRel ************** |
| 2531 // ********** Code for SVGPathSegCurvetoQuadraticSmoothAbs ************** |
| 2532 // ********** Code for SVGPathSegCurvetoQuadraticSmoothRel ************** |
| 2533 // ********** Code for SVGPathSegLinetoAbs ************** |
| 2534 // ********** Code for SVGPathSegLinetoHorizontalAbs ************** |
| 2535 // ********** Code for SVGPathSegLinetoHorizontalRel ************** |
| 2536 // ********** Code for SVGPathSegLinetoRel ************** |
| 2537 // ********** Code for SVGPathSegLinetoVerticalAbs ************** |
| 2538 // ********** Code for SVGPathSegLinetoVerticalRel ************** |
| 2539 // ********** Code for SVGPathSegList ************** |
| 2540 $dynamic("clear$0").SVGPathSegList = function() { |
| 2541 return this.clear(); |
| 2542 }; |
| 2543 // ********** Code for SVGPathSegMovetoAbs ************** |
| 2544 // ********** Code for SVGPathSegMovetoRel ************** |
| 2545 // ********** Code for SVGPatternElement ************** |
| 2546 // ********** Code for SVGPoint ************** |
| 2547 // ********** Code for SVGPointList ************** |
| 2548 $dynamic("clear$0").SVGPointList = function() { |
| 2549 return this.clear(); |
| 2550 }; |
| 2551 // ********** Code for SVGPolygonElement ************** |
| 2552 // ********** Code for SVGPolylineElement ************** |
| 2553 // ********** Code for SVGPreserveAspectRatio ************** |
| 2554 // ********** Code for SVGRadialGradientElement ************** |
| 2555 // ********** Code for SVGRect ************** |
| 2556 // ********** Code for SVGRectElement ************** |
| 2557 // ********** Code for SVGRenderingIntent ************** |
| 2558 // ********** Code for SVGSVGElement ************** |
| 2559 // ********** Code for SVGScriptElement ************** |
| 2560 // ********** Code for SVGSetElement ************** |
| 2561 // ********** Code for SVGStopElement ************** |
| 2562 // ********** Code for SVGStringList ************** |
| 2563 $dynamic("clear$0").SVGStringList = function() { |
| 2564 return this.clear(); |
| 2565 }; |
| 2566 // ********** Code for SVGStylable ************** |
| 2567 // ********** Code for SVGStyleElement ************** |
| 2568 // ********** Code for SVGSwitchElement ************** |
| 2569 // ********** Code for SVGSymbolElement ************** |
| 2570 // ********** Code for SVGTRefElement ************** |
| 2571 // ********** Code for SVGTSpanElement ************** |
| 2572 // ********** Code for SVGTests ************** |
| 2573 // ********** Code for SVGTextContentElement ************** |
| 2574 // ********** Code for SVGTextElement ************** |
| 2575 // ********** Code for SVGTextPathElement ************** |
| 2576 // ********** Code for SVGTextPositioningElement ************** |
| 2577 // ********** Code for SVGTitleElement ************** |
| 2578 // ********** Code for SVGTransform ************** |
| 2579 // ********** Code for SVGTransformList ************** |
| 2580 $dynamic("clear$0").SVGTransformList = function() { |
| 2581 return this.clear(); |
| 2582 }; |
| 2583 // ********** Code for SVGTransformable ************** |
| 2584 // ********** Code for SVGURIReference ************** |
| 2585 // ********** Code for SVGUnitTypes ************** |
| 2586 // ********** Code for SVGUseElement ************** |
| 2587 // ********** Code for SVGVKernElement ************** |
| 2588 // ********** Code for SVGViewElement ************** |
| 2589 // ********** Code for SVGViewSpec ************** |
| 2590 // ********** Code for SVGZoomAndPan ************** |
| 2591 // ********** Code for SVGZoomEvent ************** |
| 2592 // ********** Code for Screen ************** |
| 2593 // ********** Code for ScriptProfile ************** |
| 2594 // ********** Code for ScriptProfileNode ************** |
| 2595 // ********** Code for SharedWorker ************** |
| 2596 // ********** Code for SharedWorkercontext ************** |
| 2597 // ********** Code for SpeechInputEvent ************** |
| 2598 // ********** Code for SpeechInputResult ************** |
| 2599 // ********** Code for SpeechInputResultList ************** |
| 2600 // ********** Code for Storage ************** |
| 2601 $dynamic("clear$0").Storage = function() { |
| 2602 return this.clear(); |
| 2603 }; |
| 2604 // ********** Code for StorageEvent ************** |
| 2605 // ********** Code for StorageInfo ************** |
| 2606 // ********** Code for StyleMedia ************** |
| 2607 // ********** Code for StyleSheet ************** |
| 2608 // ********** Code for StyleSheetList ************** |
| 2609 // ********** Code for Text ************** |
| 2610 // ********** Code for TextEvent ************** |
| 2611 // ********** Code for TextMetrics ************** |
| 2612 // ********** Code for TextTrack ************** |
| 2613 // ********** Code for TextTrackCue ************** |
| 2614 // ********** Code for TextTrackCueList ************** |
| 2615 // ********** Code for TimeRanges ************** |
| 2616 // ********** Code for Touch ************** |
| 2617 // ********** Code for TouchEvent ************** |
| 2618 // ********** Code for TouchList ************** |
| 2619 // ********** Code for TreeWalker ************** |
| 2620 $dynamic("filter$1").TreeWalker = function($0) { |
| 2621 return this.filter($0); |
| 2622 }; |
| 2623 // ********** Code for UIEvent ************** |
| 2624 // ********** Code for Uint16Array ************** |
| 2625 Uint16Array.prototype.is$List = function(){return true}; |
| 2626 // ********** Code for Uint32Array ************** |
| 2627 Uint32Array.prototype.is$List = function(){return true}; |
| 2628 // ********** Code for Uint8Array ************** |
| 2629 Uint8Array.prototype.is$List = function(){return true}; |
| 2630 // ********** Code for ValidityState ************** |
| 2631 // ********** Code for VoidCallback ************** |
| 2632 // ********** Code for WaveShaperNode ************** |
| 2633 // ********** Code for WebGLActiveInfo ************** |
| 2634 // ********** Code for WebGLBuffer ************** |
| 2635 // ********** Code for WebGLContextAttributes ************** |
| 2636 // ********** Code for WebGLContextEvent ************** |
| 2637 // ********** Code for WebGLDebugRendererInfo ************** |
| 2638 // ********** Code for WebGLDebugShaders ************** |
| 2639 // ********** Code for WebGLFramebuffer ************** |
| 2640 // ********** Code for WebGLProgram ************** |
| 2641 // ********** Code for WebGLRenderbuffer ************** |
| 2642 // ********** Code for WebGLRenderingContext ************** |
| 2643 // ********** Code for WebGLShader ************** |
| 2644 // ********** Code for WebGLTexture ************** |
| 2645 // ********** Code for WebGLUniformLocation ************** |
| 2646 // ********** Code for WebGLVertexArrayObjectOES ************** |
| 2647 // ********** Code for WebKitAnimation ************** |
| 2648 // ********** Code for WebKitAnimationEvent ************** |
| 2649 // ********** Code for WebKitAnimationList ************** |
| 2650 // ********** Code for WebKitBlobBuilder ************** |
| 2651 // ********** Code for WebKitCSSFilterValue ************** |
| 2652 // ********** Code for WebKitCSSKeyframeRule ************** |
| 2653 // ********** Code for WebKitCSSKeyframesRule ************** |
| 2654 // ********** Code for WebKitCSSMatrix ************** |
| 2655 $dynamic("toString$0").WebKitCSSMatrix = function() { |
| 2656 return this.toString(); |
| 2657 }; |
| 2658 // ********** Code for WebKitCSSTransformValue ************** |
| 2659 // ********** Code for WebKitFlags ************** |
| 2660 // ********** Code for WebKitLoseContext ************** |
| 2661 // ********** Code for WebKitMutationObserver ************** |
| 2662 // ********** Code for WebKitPoint ************** |
| 2663 // ********** Code for WebKitTransitionEvent ************** |
| 2664 // ********** Code for WebSocket ************** |
| 2665 $dynamic("addEventListener$3").WebSocket = function($0, $1, $2) { |
| 2666 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2667 }; |
| 2668 // ********** Code for WheelEvent ************** |
| 2669 // ********** Code for Worker ************** |
| 2670 // ********** Code for WorkerContext ************** |
| 2671 $dynamic("addEventListener$3").WorkerContext = function($0, $1, $2) { |
| 2672 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2673 }; |
| 2674 // ********** Code for WorkerLocation ************** |
| 2675 $dynamic("toString$0").WorkerLocation = function() { |
| 2676 return this.toString(); |
| 2677 }; |
| 2678 // ********** Code for WorkerNavigator ************** |
| 2679 // ********** Code for XMLHttpRequest ************** |
| 2680 $dynamic("addEventListener$3").XMLHttpRequest = function($0, $1, $2) { |
| 2681 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2682 }; |
| 2683 // ********** Code for XMLHttpRequestException ************** |
| 2684 $dynamic("toString$0").XMLHttpRequestException = function() { |
| 2685 return this.toString(); |
| 2686 }; |
| 2687 // ********** Code for XMLHttpRequestProgressEvent ************** |
| 2688 // ********** Code for XMLHttpRequestUpload ************** |
| 2689 $dynamic("addEventListener$3").XMLHttpRequestUpload = function($0, $1, $2) { |
| 2690 return this.addEventListener($0, $wrap_call$1(to$call$1($1)), $2); |
| 2691 }; |
| 2692 // ********** Code for XMLSerializer ************** |
| 2693 // ********** Code for XPathEvaluator ************** |
| 2694 // ********** Code for XPathException ************** |
| 2695 $dynamic("toString$0").XPathException = function() { |
| 2696 return this.toString(); |
| 2697 }; |
| 2698 // ********** Code for XPathExpression ************** |
| 2699 // ********** Code for XPathNSResolver ************** |
| 2700 // ********** Code for XPathResult ************** |
| 2701 // ********** Code for XSLTProcessor ************** |
| 2702 // ********** Code for _Collections ************** |
| 2703 function _Collections() {} |
| 2704 // ********** Code for _VariableSizeListIterator_T ************** |
| 2705 $inherits(_VariableSizeListIterator_T, _VariableSizeListIterator); |
| 2706 function _VariableSizeListIterator_T() {} |
| 2707 // ********** Code for _FixedSizeListIterator ************** |
| 2708 $inherits(_FixedSizeListIterator, _VariableSizeListIterator_T); |
| 2709 function _FixedSizeListIterator() {} |
| 2710 _FixedSizeListIterator.prototype.hasNext$0 = _FixedSizeListIterator.prototype.ha
sNext; |
| 2711 // ********** Code for _VariableSizeListIterator ************** |
| 2712 function _VariableSizeListIterator() {} |
| 2713 _VariableSizeListIterator.prototype.hasNext$0 = _VariableSizeListIterator.protot
ype.hasNext; |
| 2714 _VariableSizeListIterator.prototype.next$0 = _VariableSizeListIterator.prototype
.next; |
| 2715 // ********** Code for _Lists ************** |
| 2716 function _Lists() {} |
| 2717 // ********** Code for top level ************** |
| 2718 function get$window() { |
| 2719 return window; |
| 2720 } |
| 2721 function get$document() { |
| 2722 return window.document; |
| 2723 } |
| 2724 // ********** Library file_system ************** |
| 2725 // ********** Code for top level ************** |
| 2726 function joinPaths(path1, path2) { |
| 2727 var pieces = path1.split('/'); |
| 2728 var $$list = path2.split('/'); |
| 2729 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2730 var piece = $$list.$index($$i); |
| 2731 if ($eq(piece, '..') && pieces.length > 0 && $ne(pieces.last$0(), '.') && $n
e(pieces.last$0(), '..')) { |
| 2732 pieces.removeLast$0(); |
| 2733 } |
| 2734 else if ($ne(piece, '')) { |
| 2735 if (pieces.length > 0 && $eq(pieces.last$0(), '.')) { |
| 2736 pieces.removeLast$0(); |
| 2737 } |
| 2738 pieces.add$1(piece); |
| 2739 } |
| 2740 } |
| 2741 return Strings.join(pieces, '/'); |
| 2742 } |
| 2743 function dirname(path) { |
| 2744 var lastSlash = path.lastIndexOf('/', path.length); |
| 2745 if (lastSlash == -1) { |
| 2746 return '.'; |
| 2747 } |
| 2748 else { |
| 2749 return path.substring(0, lastSlash); |
| 2750 } |
| 2751 } |
| 2752 function basename(path) { |
| 2753 var lastSlash = path.lastIndexOf('/', path.length); |
| 2754 if (lastSlash == -1) { |
| 2755 return path; |
| 2756 } |
| 2757 else { |
| 2758 return path.substring(lastSlash + 1); |
| 2759 } |
| 2760 } |
| 2761 // ********** Library lang ************** |
| 2762 // ********** Code for CodeWriter ************** |
| 2763 function CodeWriter() { |
| 2764 this._indentation = 0 |
| 2765 this._pendingIndent = false |
| 2766 this.writeComments = true |
| 2767 this._buf = new StringBufferImpl(""); |
| 2768 // Initializers done |
| 2769 } |
| 2770 CodeWriter.prototype.get$text = function() { |
| 2771 return this._buf.toString(); |
| 2772 } |
| 2773 Object.defineProperty(CodeWriter.prototype, "text", { |
| 2774 get: CodeWriter.prototype.get$text |
| 2775 }); |
| 2776 CodeWriter.prototype._indent = function() { |
| 2777 this._pendingIndent = false; |
| 2778 for (var i = 0; |
| 2779 i < this._indentation; i++) { |
| 2780 this._buf.add(' '/*CodeWriter.INDENTATION*/); |
| 2781 } |
| 2782 } |
| 2783 CodeWriter.prototype.comment = function(text) { |
| 2784 if (this.writeComments) { |
| 2785 this.writeln(text); |
| 2786 } |
| 2787 } |
| 2788 CodeWriter.prototype.write = function(text) { |
| 2789 if (text.length == 0) return; |
| 2790 if (this._pendingIndent) this._indent(); |
| 2791 if (text.indexOf('\n') != -1) { |
| 2792 var lines = text.split('\n'); |
| 2793 for (var i = 0; |
| 2794 i < lines.length - 1; i++) { |
| 2795 this.writeln(lines.$index(i)); |
| 2796 } |
| 2797 this.write(lines.$index(lines.length - 1)); |
| 2798 } |
| 2799 else { |
| 2800 this._buf.add(text); |
| 2801 } |
| 2802 } |
| 2803 CodeWriter.prototype.writeln = function(text) { |
| 2804 if (text != null) { |
| 2805 this.write(text); |
| 2806 } |
| 2807 if (!text.endsWith('\n')) this._buf.add('\n'/*CodeWriter.NEWLINE*/); |
| 2808 this._pendingIndent = true; |
| 2809 } |
| 2810 CodeWriter.prototype.enterBlock = function(text) { |
| 2811 this.writeln(text); |
| 2812 this._indentation++; |
| 2813 } |
| 2814 CodeWriter.prototype.exitBlock = function(text) { |
| 2815 this._indentation--; |
| 2816 this.writeln(text); |
| 2817 } |
| 2818 CodeWriter.prototype.nextBlock = function(text) { |
| 2819 this._indentation--; |
| 2820 this.writeln(text); |
| 2821 this._indentation++; |
| 2822 } |
| 2823 // ********** Code for CoreJs ************** |
| 2824 function CoreJs() { |
| 2825 this.useStackTraceOf = false |
| 2826 this.useThrow = false |
| 2827 this.useGenStub = false |
| 2828 this.useAssert = false |
| 2829 this.useNotNullBool = false |
| 2830 this.useIndex = false |
| 2831 this.useSetIndex = false |
| 2832 this.useWrap0 = false |
| 2833 this.useWrap1 = false |
| 2834 this.useIsolates = false |
| 2835 this.useToString = false |
| 2836 this._generatedTypeNameOf = false |
| 2837 this._generatedDynamicProto = false |
| 2838 this._generatedInherits = false |
| 2839 this._usedOperators = new HashMapImplementation(); |
| 2840 this.writer = new CodeWriter(); |
| 2841 // Initializers done |
| 2842 } |
| 2843 CoreJs.prototype.useOperator = function(name) { |
| 2844 if (this._usedOperators.$index(name) != null) return; |
| 2845 var code; |
| 2846 switch (name) { |
| 2847 case ':ne': |
| 2848 |
| 2849 code = "function $ne(x, y) {\n if (x == null) return y != null;\n return
(typeof(x) == 'number' && typeof(y) == 'number') ||\n (typeof(x) == 'bo
olean' && typeof(y) == 'boolean') ||\n (typeof(x) == 'string' && typeof(
y) == 'string')\n ? x != y : !x.$eq(y);\n}"; |
| 2850 break; |
| 2851 |
| 2852 case ':eq': |
| 2853 |
| 2854 code = "function $eq(x, y) {\n if (x == null) return y == null;\n return
(typeof(x) == 'number' && typeof(y) == 'number') ||\n (typeof(x) == 'bo
olean' && typeof(y) == 'boolean') ||\n (typeof(x) == 'string' && typeof(
y) == 'string')\n ? x == y : x.$eq(y);\n}\n// TODO(jimhug): Should this or sh
ould it not match equals?\nObject.prototype.$eq = function(other) { return this
=== other; }"; |
| 2855 break; |
| 2856 |
| 2857 case ':bit_not': |
| 2858 |
| 2859 code = "function $bit_not(x) {\n return (typeof(x) == 'number') ? ~x : x.
$bit_not();\n}"; |
| 2860 break; |
| 2861 |
| 2862 case ':negate': |
| 2863 |
| 2864 code = "function $negate(x) {\n return (typeof(x) == 'number') ? -x : x.$
negate();\n}"; |
| 2865 break; |
| 2866 |
| 2867 case ':add': |
| 2868 |
| 2869 code = "function $add(x, y) {\n return ((typeof(x) == 'number' && typeof(
y) == 'number') ||\n (typeof(x) == 'string'))\n ? x + y : x.$add(y);
\n}"; |
| 2870 break; |
| 2871 |
| 2872 case ':truncdiv': |
| 2873 |
| 2874 this.useThrow = true; |
| 2875 code = "function $truncdiv(x, y) {\n if (typeof(x) == 'number' && typeof(
y) == 'number') {\n if (y == 0) $throw(new IntegerDivisionByZeroException());
\n var tmp = x / y;\n return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp);
\n } else {\n return x.$truncdiv(y);\n }\n}"; |
| 2876 break; |
| 2877 |
| 2878 case ':mod': |
| 2879 |
| 2880 code = "function $mod(x, y) {\n if (typeof(x) == 'number' && typeof(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 return x.$mod(y);\n }\n}"; |
| 2881 break; |
| 2882 |
| 2883 default: |
| 2884 |
| 2885 var op = TokenKind.rawOperatorFromMethod(name); |
| 2886 var jsname = $globals.world.toJsIdentifier(name); |
| 2887 code = ("function " + jsname + "(x, y) {\n return (typeof(x) == 'number'
&& typeof(y) == 'number')\n ? x " + op + " y : x." + jsname + "(y);\n}"); |
| 2888 break; |
| 2889 |
| 2890 } |
| 2891 this._usedOperators.$setindex(name, code); |
| 2892 } |
| 2893 CoreJs.prototype.ensureDynamicProto = function() { |
| 2894 if (this._generatedDynamicProto) return; |
| 2895 this._generatedDynamicProto = true; |
| 2896 this.ensureTypeNameOf(); |
| 2897 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 method;\n var proto = Object.getPrototypeOf(this);\n var obj = this
;\n do {\n method = methods[obj.$typeNameOf()];\n if (method) break
;\n obj = Object.getPrototypeOf(obj);\n } while (obj);\n\n // Patch t
he prototype, but don't overwrite an existing stub, like\n // the one on Obje
ct.prototype.\n if (!proto.hasOwnProperty(name)) proto[name] = method || meth
ods.Object;\n\n return method.apply(this, Array.prototype.slice.call(argument
s));\n };\n $dynamicBind.methods = methods;\n Object.prototype[name] = $dynam
icBind;\n return methods;\n}"); |
| 2898 } |
| 2899 CoreJs.prototype.ensureTypeNameOf = function() { |
| 2900 if (this._generatedTypeNameOf) return; |
| 2901 this._generatedTypeNameOf = true; |
| 2902 this.writer.writeln("Object.prototype.$typeNameOf = function() {\n if ((typeo
f(window) != 'undefined' && window.constructor.name == 'DOMWindow')\n || ty
peof(process) != 'undefined') { // fast-path for Chrome and Node\n return thi
s.constructor.name;\n }\n var str = Object.prototype.toString.call(this);\n s
tr = str.substring(8, str.length - 1);\n if (str == 'Window') str = 'DOMWindow'
;\n return str;\n}"); |
| 2903 } |
| 2904 CoreJs.prototype.ensureInheritsHelper = function() { |
| 2905 if (this._generatedInherits) return; |
| 2906 this._generatedInherits = true; |
| 2907 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}"); |
| 2908 } |
| 2909 CoreJs.prototype.generate = function(w) { |
| 2910 w.write(this.writer.get$text()); |
| 2911 this.writer = w; |
| 2912 if (this.useGenStub) { |
| 2913 this.useThrow = true; |
| 2914 w.writeln("/**\n * Generates a dynamic call stub for a function.\n * Our goa
l is to create a stub method like this on-the-fly:\n * function($0, $1, captur
e) { return this($0, $1, true, capture); }\n *\n * This stub then replaces the d
ynamic one on Function, with one that is\n * specialized for that particular fun
ction, taking into account its default\n * arguments.\n */\nFunction.prototype.$
genStub = function(argsLength, names) {\n // Fast path: if no named arguments a
nd arg count matches\n if (this.length == argsLength && !names) {\n return t
his;\n }\n\n function $throwArgMismatch() {\n // TODO(jmesserly): better er
ror message\n $throw(new ClosureArgumentMismatchException());\n }\n\n var p
aramsNamed = this.$optional ? (this.$optional.length / 2) : 0;\n var paramsBare
= this.length - paramsNamed;\n var argsNamed = names ? names.length : 0;\n va
r argsBare = argsLength - argsNamed;\n\n // Check we got the right number of ar
guments\n if (argsBare < paramsBare || argsLength > this.length ||\n argsN
amed > paramsNamed) {\n return $throwArgMismatch;\n }\n\n // First, fill in
all of the default values\n var p = new Array(paramsBare);\n if (paramsNamed)
{\n p = p.concat(this.$optional.slice(paramsNamed));\n }\n // Fill in posi
tional args\n var a = new Array(argsLength);\n for (var i = 0; i < argsBare; i
++) {\n p[i] = a[i] = '$' + i;\n }\n // Then overwrite with supplied values
for optional args\n var lastParameterIndex;\n var namesInOrder = true;\n for
(var i = 0; i < argsNamed; i++) {\n var name = names[i];\n a[i + argsBare
] = name;\n var j = this.$optional.indexOf(name);\n if (j < 0 || j >= para
msNamed) {\n return $throwArgMismatch;\n } else if (lastParameterIndex &
& lastParameterIndex > j) {\n namesInOrder = false;\n }\n p[j + param
sBare] = name;\n lastParameterIndex = j;\n }\n\n if (this.length == argsLen
gth && namesInOrder) {\n // Fast path #2: named arguments, but they're in ord
er.\n return this;\n }\n\n // Note: using Function instead of 'eval' to get
a clean scope.\n // TODO(jmesserly): evaluate the performance of these stubs.\
n var f = 'function(' + a.join(',') + '){return $f(' + p.join(',') + ');}';\n
return new Function('$f', 'return ' + f + '').call(null, this);\n}"); |
| 2915 } |
| 2916 if (this.useStackTraceOf) { |
| 2917 w.writeln("function $stackTraceOf(e) {\n // TODO(jmesserly): we shouldn't b
e relying on the e.stack property.\n // Need to mangle it.\n return (e && e.s
tack) ? e.stack : null;\n}"); |
| 2918 } |
| 2919 if (this.useNotNullBool) { |
| 2920 this.useThrow = true; |
| 2921 w.writeln("function $notnull_bool(test) {\n if (test === true || test === f
alse) return test;\n $throw(new TypeError(test, 'bool'));\n}"); |
| 2922 } |
| 2923 if (this.useThrow) { |
| 2924 w.writeln("function $throw(e) {\n // If e is not a value, we can use V8's c
aptureStackTrace utility method.\n // TODO(jmesserly): capture the stack trace
on other JS engines.\n if (e && (typeof e == 'object') && Error.captureStackTra
ce) {\n // TODO(jmesserly): this will clobber the e.stack property\n Error
.captureStackTrace(e, $throw);\n }\n throw e;\n}"); |
| 2925 } |
| 2926 if (this.useToString) { |
| 2927 w.writeln("function $toString(o) {\n if (o == null) return 'null';\n var t
= typeof(o);\n if (t == 'object') { return o.toString(); }\n else if (t == 's
tring') { return o; }\n else if (t == 'bool') { return ''+o; }\n else if (t ==
'number') { return ''+o; }\n else return o.toString();\n}"); |
| 2928 } |
| 2929 if (this.useIndex) { |
| 2930 w.writeln("Object.prototype.$index = function(i) {\n var proto = Object.get
PrototypeOf(this);\n if (proto !== Object) {\n proto.$index = function(i) {
return this[i]; }\n }\n return this[i];\n}\nArray.prototype.$index = function(
i) { return this[i]; }\nString.prototype.$index = function(i) { return this[i];
}"); |
| 2931 } |
| 2932 if (this.useSetIndex) { |
| 2933 w.writeln("Object.prototype.$setindex = function(i, value) {\n var proto =
Object.getPrototypeOf(this);\n if (proto !== Object) {\n proto.$setindex = f
unction(i, value) { return this[i] = value; }\n }\n return this[i] = value;\n}
\nArray.prototype.$setindex = function(i, value) { return this[i] = value; }"); |
| 2934 } |
| 2935 if (this.useIsolates) { |
| 2936 if (this.useWrap0) { |
| 2937 w.writeln("// Wrap a 0-arg dom-callback to bind it with the current isolat
e:\nfunction $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }\nFunction.proto
type.wrap$call$0 = function() {\n var isolateContext = $globalState.currentCont
ext;\n var self = this;\n this.wrap$0 = function() {\n isolateContext.eval(
self);\n $globalState.topEventLoop.run();\n };\n this.wrap$call$0 = functio
n() { return this.wrap$0; };\n return this.wrap$0;\n}"); |
| 2938 } |
| 2939 if (this.useWrap1) { |
| 2940 w.writeln("// Wrap a 1-arg dom-callback to bind it with the current isolat
e:\nfunction $wrap_call$1(fn) { return fn && fn.wrap$call$1(); }\nFunction.proto
type.wrap$call$1 = function() {\n var isolateContext = $globalState.currentCont
ext;\n var self = this;\n this.wrap$1 = function(arg) {\n isolateContext.ev
al(function() { self(arg); });\n $globalState.topEventLoop.run();\n };\n th
is.wrap$call$1 = function() { return this.wrap$1; };\n return this.wrap$1;\n}")
; |
| 2941 } |
| 2942 w.writeln("var $globalThis = this;\nvar $globals = null;\nvar $globalState =
null;"); |
| 2943 } |
| 2944 else { |
| 2945 if (this.useWrap0) { |
| 2946 w.writeln("function $wrap_call$0(fn) { return fn; }"); |
| 2947 } |
| 2948 if (this.useWrap1) { |
| 2949 w.writeln("function $wrap_call$1(fn) { return fn; }"); |
| 2950 } |
| 2951 } |
| 2952 var $$list = orderValuesByKeys(this._usedOperators); |
| 2953 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2954 var opImpl = $$list.$index($$i); |
| 2955 w.writeln(opImpl); |
| 2956 } |
| 2957 } |
| 2958 CoreJs.prototype.generate$1 = CoreJs.prototype.generate; |
| 2959 // ********** Code for lang_Element ************** |
| 2960 function lang_Element(name, _enclosingElement) { |
| 2961 this.name = name; |
| 2962 this._enclosingElement = _enclosingElement; |
| 2963 // Initializers done |
| 2964 this._jsname = $globals.world.toJsIdentifier(this.name); |
| 2965 } |
| 2966 lang_Element.prototype.get$_jsname = function() { return this._jsname; }; |
| 2967 lang_Element.prototype.set$_jsname = function(value) { return this._jsname = val
ue; }; |
| 2968 lang_Element.prototype.get$library = function() { |
| 2969 return null; |
| 2970 } |
| 2971 lang_Element.prototype.get$span = function() { |
| 2972 return null; |
| 2973 } |
| 2974 Object.defineProperty(lang_Element.prototype, "span", { |
| 2975 get: lang_Element.prototype.get$span |
| 2976 }); |
| 2977 lang_Element.prototype.get$isNative = function() { |
| 2978 return false; |
| 2979 } |
| 2980 lang_Element.prototype.hashCode = function() { |
| 2981 return this.name.hashCode(); |
| 2982 } |
| 2983 lang_Element.prototype.get$jsname = function() { |
| 2984 return this._jsname; |
| 2985 } |
| 2986 lang_Element.prototype.resolve = function() { |
| 2987 |
| 2988 } |
| 2989 lang_Element.prototype.get$typeParameters = function() { |
| 2990 return null; |
| 2991 } |
| 2992 lang_Element.prototype.get$enclosingElement = function() { |
| 2993 return this._enclosingElement == null ? this.get$library() : this._enclosingEl
ement; |
| 2994 } |
| 2995 lang_Element.prototype.set$enclosingElement = function(e) { |
| 2996 return this._enclosingElement = e; |
| 2997 } |
| 2998 lang_Element.prototype.resolveType = function(node, typeErrors) { |
| 2999 if (node == null) return $globals.world.varType; |
| 3000 if (node.type != null) return node.type; |
| 3001 if ((node instanceof NameTypeReference)) { |
| 3002 var typeRef = node; |
| 3003 var name; |
| 3004 if (typeRef.names != null) { |
| 3005 name = typeRef.names.last().name; |
| 3006 } |
| 3007 else { |
| 3008 name = typeRef.name.name; |
| 3009 } |
| 3010 if (this.get$typeParameters() != null) { |
| 3011 var $$list = this.get$typeParameters(); |
| 3012 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3013 var tp = $$list.$index($$i); |
| 3014 if ($eq(tp.name, name)) { |
| 3015 typeRef.type = tp; |
| 3016 } |
| 3017 } |
| 3018 } |
| 3019 if (typeRef.type != null) { |
| 3020 return typeRef.type; |
| 3021 } |
| 3022 return this.get$enclosingElement().resolveType(node, typeErrors); |
| 3023 } |
| 3024 else if ((node instanceof GenericTypeReference)) { |
| 3025 var typeRef = node; |
| 3026 var baseType = this.resolveType(typeRef.baseType, typeErrors); |
| 3027 if (!baseType.get$isGeneric()) { |
| 3028 $globals.world.error(('' + baseType.name + ' is not generic'), typeRef.spa
n); |
| 3029 return null; |
| 3030 } |
| 3031 if (typeRef.typeArguments.length != baseType.get$typeParameters().length) { |
| 3032 $globals.world.error('wrong number of type arguments', typeRef.span); |
| 3033 return null; |
| 3034 } |
| 3035 var typeArgs = []; |
| 3036 for (var i = 0; |
| 3037 i < typeRef.typeArguments.length; i++) { |
| 3038 typeArgs.add$1(this.resolveType(typeRef.typeArguments.$index(i), typeError
s)); |
| 3039 } |
| 3040 typeRef.type = baseType.getOrMakeConcreteType$1(typeArgs); |
| 3041 } |
| 3042 else if ((node instanceof FunctionTypeReference)) { |
| 3043 var typeRef = node; |
| 3044 var name = ''; |
| 3045 if (typeRef.func.name != null) { |
| 3046 name = typeRef.func.name.name; |
| 3047 } |
| 3048 typeRef.type = this.get$library().getOrAddFunctionType(this, name, typeRef.f
unc); |
| 3049 } |
| 3050 else { |
| 3051 $globals.world.internalError('unknown type reference', node.span); |
| 3052 } |
| 3053 return node.type; |
| 3054 } |
| 3055 lang_Element.prototype.hashCode$0 = lang_Element.prototype.hashCode; |
| 3056 lang_Element.prototype.resolve$0 = lang_Element.prototype.resolve; |
| 3057 // ********** Code for WorldGenerator ************** |
| 3058 function WorldGenerator(main, writer) { |
| 3059 this.hasStatics = false |
| 3060 this.main = main; |
| 3061 this.writer = writer; |
| 3062 this.globals = new HashMapImplementation(); |
| 3063 this.corejs = new CoreJs(); |
| 3064 // Initializers done |
| 3065 } |
| 3066 WorldGenerator.prototype.run = function() { |
| 3067 var metaGen = new MethodGenerator(this.main, null); |
| 3068 var mainTarget = new Value.type$ctor(this.main.declaringType, this.main.get$sp
an()); |
| 3069 var mainCall = this.main.invoke(metaGen, null, mainTarget, Arguments.get$EMPTY
(), false); |
| 3070 this.main.declaringType.markUsed(); |
| 3071 if ($globals.options.compileAll) { |
| 3072 this.markLibraryUsed($globals.world.corelib); |
| 3073 this.markLibraryUsed(this.main.declaringType.get$library()); |
| 3074 } |
| 3075 else { |
| 3076 $globals.world.corelib.types.$index('BadNumberFormatException').markUsed$0()
; |
| 3077 $globals.world.get$coreimpl().types.$index('NumImplementation').markUsed$0()
; |
| 3078 $globals.world.get$coreimpl().types.$index('StringImplementation').markUsed$
0(); |
| 3079 this.genMethod($globals.world.get$coreimpl().types.$index('StringImplementat
ion').getMember$1('contains')); |
| 3080 } |
| 3081 if ($globals.world.corelib.types.$index('Isolate').get$isUsed() || $globals.wo
rld.get$coreimpl().types.$index('ReceivePortImpl').get$isUsed()) { |
| 3082 if (this.corejs.useWrap0 || this.corejs.useWrap1) { |
| 3083 this.genMethod($globals.world.get$coreimpl().types.$index('IsolateContext'
).getMember$1('eval')); |
| 3084 this.genMethod($globals.world.get$coreimpl().types.$index('EventLoop').get
Member$1('run')); |
| 3085 } |
| 3086 this.corejs.useIsolates = true; |
| 3087 var isolateMain = $globals.world.get$coreimpl().topType.resolveMember('start
RootIsolate').members.$index(0); |
| 3088 var isolateMainTarget = new Value.type$ctor($globals.world.get$coreimpl().to
pType, this.main.get$span()); |
| 3089 mainCall = isolateMain.invoke(metaGen, null, isolateMainTarget, new Argument
s(null, [this.main._get(metaGen, this.main.definition, null, false)]), false); |
| 3090 } |
| 3091 this.writeTypes($globals.world.get$coreimpl()); |
| 3092 this.writeTypes($globals.world.corelib); |
| 3093 this.writeTypes(this.main.declaringType.get$library()); |
| 3094 if (this._mixins != null) this.writer.write(this._mixins.get$text()); |
| 3095 this.writeGlobals(); |
| 3096 this.writer.writeln(('' + mainCall.code + ';')); |
| 3097 } |
| 3098 WorldGenerator.prototype.markLibraryUsed = function(l) { |
| 3099 var $this = this; // closure support |
| 3100 if (l.isMarked) return; |
| 3101 l.isMarked = true; |
| 3102 l.imports.forEach((function (i) { |
| 3103 return $this.markLibraryUsed(i.get$library()); |
| 3104 }) |
| 3105 ); |
| 3106 var $$list = l.types.getValues(); |
| 3107 for (var $$i = l.types.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 3108 var type = $$i.next$0(); |
| 3109 if (!type.get$isClass()) continue; |
| 3110 type.markUsed$0(); |
| 3111 type.set$isTested(!type.get$isTop() && !(type.get$isNative() && type.get$mem
bers().getValues$0().every$1((function (m) { |
| 3112 return m.get$isStatic() && !m.get$isFactory(); |
| 3113 }) |
| 3114 ))); |
| 3115 var $list0 = type.get$members().getValues$0(); |
| 3116 for (var $i0 = type.get$members().getValues$0().iterator$0(); $i0.hasNext$0(
); ) { |
| 3117 var member = $i0.next$0(); |
| 3118 if ((member instanceof PropertyMember)) { |
| 3119 if (member.get$getter() != null) this.genMethod(member.get$getter()); |
| 3120 if (member.get$setter() != null) this.genMethod(member.get$setter()); |
| 3121 } |
| 3122 if (member.get$isMethod()) this.genMethod(member); |
| 3123 } |
| 3124 } |
| 3125 } |
| 3126 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe
ndencies) { |
| 3127 this.hasStatics = true; |
| 3128 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname
()); |
| 3129 if (!this.globals.containsKey(fullname)) { |
| 3130 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory(
field, fieldValue, dependencies)); |
| 3131 } |
| 3132 return this.globals.$index(fullname); |
| 3133 } |
| 3134 WorldGenerator.prototype.globalForConst = function(exp, dependencies) { |
| 3135 var key = exp.get$type().get$jsname() + ':' + exp.canonicalCode; |
| 3136 if (!this.globals.containsKey(key)) { |
| 3137 this.globals.$setindex(key, GlobalValue.GlobalValue$fromConst$factory(this.g
lobals.get$length(), exp, dependencies)); |
| 3138 } |
| 3139 return this.globals.$index(key); |
| 3140 } |
| 3141 WorldGenerator.prototype.writeTypes = function(lib) { |
| 3142 if (lib.isWritten) return; |
| 3143 lib.isWritten = true; |
| 3144 var $$list = lib.imports; |
| 3145 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3146 var import_ = $$list.$index($$i); |
| 3147 this.writeTypes(import_.get$library()); |
| 3148 } |
| 3149 for (var i = 0; |
| 3150 i < lib.sources.length; i++) { |
| 3151 lib.sources.$index(i).set$orderInLibrary(i); |
| 3152 } |
| 3153 this.writer.comment(('// ********** Library ' + lib.name + ' **************')
); |
| 3154 if (lib.get$isCore()) { |
| 3155 this.writer.comment('// ********** Natives dart:core **************'); |
| 3156 this.corejs.generate(this.writer); |
| 3157 } |
| 3158 var $$list = lib.natives; |
| 3159 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3160 var file = $$list.$index($$i); |
| 3161 var filename = basename(file.filename); |
| 3162 this.writer.comment(('// ********** Natives ' + filename + ' **************
')); |
| 3163 this.writer.writeln(file.text); |
| 3164 } |
| 3165 lib.topType.markUsed(); |
| 3166 var $$list = this._orderValues(lib.types); |
| 3167 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3168 var type = $$list.$index($$i); |
| 3169 if ((type.get$isUsed() || $eq(type.get$library(), $globals.world.get$dom())
|| type.get$isHiddenNativeType()) && type.get$isClass()) { |
| 3170 this.writeType(type); |
| 3171 if (type.get$isGeneric()) { |
| 3172 var $list0 = this._orderValues(type.get$_concreteTypes()); |
| 3173 for (var $i0 = 0;$i0 < $list0.length; $i0++) { |
| 3174 var ct = $list0.$index($i0); |
| 3175 this.writeType(ct); |
| 3176 } |
| 3177 } |
| 3178 } |
| 3179 else if (type.get$isFunction() && type.get$varStubs().length > 0) { |
| 3180 this.writer.comment(('// ********** Code for ' + type.get$jsname() + ' ***
***********')); |
| 3181 this._writeDynamicStubs(type); |
| 3182 } |
| 3183 if (type.get$typeCheckCode() != null) { |
| 3184 this.writer.writeln(type.get$typeCheckCode()); |
| 3185 } |
| 3186 } |
| 3187 } |
| 3188 WorldGenerator.prototype.genMethod = function(meth, enclosingMethod) { |
| 3189 if (!meth.isGenerated && !meth.get$isAbstract() && meth.get$definition() != nu
ll) { |
| 3190 new MethodGenerator(meth, enclosingMethod).run(); |
| 3191 } |
| 3192 } |
| 3193 WorldGenerator.prototype._prototypeOf = function(type, name) { |
| 3194 if (type.get$isSingletonNative()) { |
| 3195 return ('' + type.get$jsname() + '.' + name); |
| 3196 } |
| 3197 else if (type.get$isHiddenNativeType()) { |
| 3198 this.corejs.ensureDynamicProto(); |
| 3199 return ('\$dynamic("' + name + '").' + type.get$jsname()); |
| 3200 } |
| 3201 else { |
| 3202 return ('' + type.get$jsname() + '.prototype.' + name); |
| 3203 } |
| 3204 } |
| 3205 WorldGenerator.prototype._maybeIsTest = function(onType, checkType) { |
| 3206 var isSubtype = onType.isSubtypeOf(checkType); |
| 3207 if (checkType.isTested) { |
| 3208 this.writer.writeln(this._prototypeOf(onType, ('is\$' + checkType.get$jsname
())) + (' = function(){return ' + isSubtype + '};')); |
| 3209 } |
| 3210 if (checkType.isChecked) { |
| 3211 var body = 'return this'; |
| 3212 var checkName = ('assert\$' + checkType.get$jsname()); |
| 3213 if (!isSubtype) { |
| 3214 body = $globals.world.objectType.varStubs.$index(checkName).body; |
| 3215 } |
| 3216 else if (onType.name == 'StringImplementation' || onType.name == 'NumImpleme
ntation') { |
| 3217 body = ('return ' + onType.get$nativeType().name + '(this)'); |
| 3218 } |
| 3219 this.writer.writeln(this._prototypeOf(onType, checkName) + (' = function(){'
+ body + '};')); |
| 3220 } |
| 3221 } |
| 3222 WorldGenerator.prototype.writeType = function(type) { |
| 3223 if (type.isWritten) return; |
| 3224 type.isWritten = true; |
| 3225 if (type.get$parent() != null && !type.get$isNative()) { |
| 3226 this.writeType(type.get$parent()); |
| 3227 } |
| 3228 if (type.name != null && (type instanceof ConcreteType) && $eq(type.get$librar
y(), $globals.world.get$coreimpl()) && type.name.startsWith('ListFactory')) { |
| 3229 this.writer.writeln(('' + type.get$jsname() + ' = ' + type.get$genericType()
.get$jsname() + ';')); |
| 3230 return; |
| 3231 } |
| 3232 var typeName = type.get$jsname() != null ? type.get$jsname() : 'top level'; |
| 3233 this.writer.comment(('// ********** Code for ' + typeName + ' **************')
); |
| 3234 if (type.get$isNative() && !type.get$isTop()) { |
| 3235 var nativeName = type.get$definition().get$nativeType().name; |
| 3236 if ($eq(nativeName, '')) { |
| 3237 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 3238 } |
| 3239 else if (type.get$jsname() != nativeName) { |
| 3240 this.writer.writeln(('' + type.get$jsname() + ' = ' + nativeName + ';')); |
| 3241 } |
| 3242 } |
| 3243 if (!type.get$isTop()) { |
| 3244 if ((type instanceof ConcreteType)) { |
| 3245 var c = type; |
| 3246 this.corejs.ensureInheritsHelper(); |
| 3247 this.writer.writeln(('\$inherits(' + c.get$jsname() + ', ' + c.genericType
.get$jsname() + ');')); |
| 3248 for (var p = c._lang_parent; |
| 3249 (p instanceof ConcreteType); p = p.get$_lang_parent()) { |
| 3250 this._ensureInheritMembersHelper(); |
| 3251 this._mixins.writeln(('\$inheritsMembers(' + c.get$jsname() + ', ' + p.g
et$jsname() + ');')); |
| 3252 } |
| 3253 } |
| 3254 else if (!type.get$isNative()) { |
| 3255 if (type.get$parent() != null && !type.get$parent().get$isObject()) { |
| 3256 this.corejs.ensureInheritsHelper(); |
| 3257 this.writer.writeln(('\$inherits(' + type.get$jsname() + ', ' + type.get
$parent().get$jsname() + ');')); |
| 3258 } |
| 3259 } |
| 3260 } |
| 3261 if (type.get$isTop()) { |
| 3262 } |
| 3263 else if (type.get$constructors().get$length() == 0) { |
| 3264 if (!type.get$isNative()) { |
| 3265 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 3266 } |
| 3267 } |
| 3268 else { |
| 3269 var standardConstructor = type.get$constructors().$index(''); |
| 3270 if (standardConstructor == null || standardConstructor.generator == null) { |
| 3271 if (!type.get$isNative()) { |
| 3272 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 3273 } |
| 3274 } |
| 3275 else { |
| 3276 standardConstructor.generator.writeDefinition(this.writer, null); |
| 3277 } |
| 3278 var $$list = type.get$constructors().getValues(); |
| 3279 for (var $$i = type.get$constructors().getValues().iterator$0(); $$i.hasNext
$0(); ) { |
| 3280 var c = $$i.next$0(); |
| 3281 if (c.get$generator() != null && $ne(c, standardConstructor)) { |
| 3282 c.get$generator().writeDefinition$2(this.writer); |
| 3283 } |
| 3284 } |
| 3285 } |
| 3286 if (!(type instanceof ConcreteType)) { |
| 3287 this._maybeIsTest(type, type); |
| 3288 } |
| 3289 if (type.get$genericType()._concreteTypes != null) { |
| 3290 var $$list = this._orderValues(type.get$genericType()._concreteTypes); |
| 3291 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3292 var ct = $$list.$index($$i); |
| 3293 this._maybeIsTest(type, ct); |
| 3294 } |
| 3295 } |
| 3296 if (type.get$interfaces() != null) { |
| 3297 var seen = new HashSetImplementation(); |
| 3298 var worklist = []; |
| 3299 worklist.addAll(type.get$interfaces()); |
| 3300 seen.addAll(type.get$interfaces()); |
| 3301 while (!worklist.isEmpty()) { |
| 3302 var interface_ = worklist.removeLast(); |
| 3303 this._maybeIsTest(type, interface_.get$genericType()); |
| 3304 if (interface_.get$genericType().get$_concreteTypes() != null) { |
| 3305 var $$list = this._orderValues(interface_.get$genericType().get$_concret
eTypes()); |
| 3306 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3307 var ct = $$list.$index($$i); |
| 3308 this._maybeIsTest(type, ct); |
| 3309 } |
| 3310 } |
| 3311 var $$list = interface_.get$interfaces(); |
| 3312 for (var $$i = interface_.get$interfaces().iterator$0(); $$i.hasNext$0();
) { |
| 3313 var other = $$i.next$0(); |
| 3314 if (!seen.contains(other)) { |
| 3315 worklist.addLast(other); |
| 3316 seen.add(other); |
| 3317 } |
| 3318 } |
| 3319 } |
| 3320 } |
| 3321 type.get$factories().forEach(this.get$_writeMethod()); |
| 3322 var $$list = this._orderValues(type.get$members()); |
| 3323 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3324 var member = $$list.$index($$i); |
| 3325 if ((member instanceof FieldMember)) { |
| 3326 this._writeField(member); |
| 3327 } |
| 3328 if ((member instanceof PropertyMember)) { |
| 3329 this._writeProperty(member); |
| 3330 } |
| 3331 if (member.get$isMethod()) { |
| 3332 this._writeMethod(member); |
| 3333 } |
| 3334 } |
| 3335 this._writeDynamicStubs(type); |
| 3336 } |
| 3337 WorldGenerator.prototype._ensureInheritMembersHelper = function() { |
| 3338 if (this._mixins != null) return; |
| 3339 this._mixins = new CodeWriter(); |
| 3340 this._mixins.comment('// ********** Generic Type Inheritance **************'); |
| 3341 this._mixins.writeln("/** Implements extends for generic types. */\nfunction $
inheritsMembers(child, parent) {\n child = child.prototype;\n parent = parent.
prototype;\n Object.getOwnPropertyNames(parent).forEach(function(name) {\n i
f (typeof(child[name]) == 'undefined') child[name] = parent[name];\n });\n}"); |
| 3342 } |
| 3343 WorldGenerator.prototype._writeDynamicStubs = function(type) { |
| 3344 var $$list = orderValuesByKeys(type.varStubs); |
| 3345 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3346 var stub = $$list.$index($$i); |
| 3347 stub.generate$1(this.writer); |
| 3348 } |
| 3349 } |
| 3350 WorldGenerator.prototype._writeStaticField = function(field) { |
| 3351 if (field.isFinal) return; |
| 3352 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname
()); |
| 3353 if (this.globals.containsKey(fullname)) { |
| 3354 var value = this.globals.$index(fullname); |
| 3355 if (field.declaringType.get$isTop() && !field.isNative) { |
| 3356 this.writer.writeln(('\$globals.' + field.get$jsname() + ' = ' + value.get
$exp().code + ';')); |
| 3357 } |
| 3358 else { |
| 3359 this.writer.writeln(('\$globals.' + field.declaringType.get$jsname() + '_'
+ field.get$jsname()) + (' = ' + value.get$exp().code + ';')); |
| 3360 } |
| 3361 } |
| 3362 } |
| 3363 WorldGenerator.prototype._writeField = function(field) { |
| 3364 if (field.declaringType.get$isTop() && !field.isNative && field.value == null)
{ |
| 3365 this.writer.writeln(('var ' + field.get$jsname() + ';')); |
| 3366 } |
| 3367 if (field._providePropertySyntax) { |
| 3368 this.writer.writeln(this._prototypeOf(field.declaringType, ('get\$' + field.
get$jsname())) + (' = function() { return this.' + field.get$jsname() + '; };'))
; |
| 3369 if (!field.isFinal) { |
| 3370 this.writer.writeln(this._prototypeOf(field.declaringType, ('set\$' + fiel
d.get$jsname())) + (' = function(value) { return this.' + field.get$jsname() + '
= value; };')); |
| 3371 } |
| 3372 } |
| 3373 } |
| 3374 WorldGenerator.prototype._writeProperty = function(property) { |
| 3375 if (property.getter != null) this._writeMethod(property.getter); |
| 3376 if (property.setter != null) this._writeMethod(property.setter); |
| 3377 if (property._provideFieldSyntax) { |
| 3378 this.writer.enterBlock('Object.defineProperty(' + ('' + property.declaringTy
pe.get$jsname() + '.prototype, "' + property.get$jsname() + '", {')); |
| 3379 if (property.getter != null) { |
| 3380 this.writer.write(('get: ' + property.declaringType.get$jsname() + '.proto
type.' + property.getter.get$jsname())); |
| 3381 this.writer.writeln(property.setter == null ? '' : ','); |
| 3382 } |
| 3383 if (property.setter != null) { |
| 3384 this.writer.writeln(('set: ' + property.declaringType.get$jsname() + '.pro
totype.' + property.setter.get$jsname())); |
| 3385 } |
| 3386 this.writer.exitBlock('});'); |
| 3387 } |
| 3388 } |
| 3389 WorldGenerator.prototype._writeMethod = function(method) { |
| 3390 if (method.generator != null) { |
| 3391 method.generator.writeDefinition(this.writer, null); |
| 3392 } |
| 3393 } |
| 3394 WorldGenerator.prototype.get$_writeMethod = function() { |
| 3395 return WorldGenerator.prototype._writeMethod.bind(this); |
| 3396 } |
| 3397 WorldGenerator.prototype.writeGlobals = function() { |
| 3398 if (this.globals.get$length() > 0) { |
| 3399 this.writer.comment('// ********** Globals **************'); |
| 3400 var list = this.globals.getValues(); |
| 3401 list.sort$1((function (a, b) { |
| 3402 return a.compareTo$1(b); |
| 3403 }) |
| 3404 ); |
| 3405 this.writer.enterBlock('function \$static_init(){'); |
| 3406 for (var $$i = list.iterator$0(); $$i.hasNext$0(); ) { |
| 3407 var global = $$i.next$0(); |
| 3408 if (global.get$field() != null) { |
| 3409 this._writeStaticField(global.get$field()); |
| 3410 } |
| 3411 } |
| 3412 this.writer.exitBlock('}'); |
| 3413 for (var $$i = list.iterator$0(); $$i.hasNext$0(); ) { |
| 3414 var global0 = $$i.next$0(); |
| 3415 if (global0.get$field() == null) { |
| 3416 this.writer.writeln(('var ' + global0.name + ' = ' + global0.get$exp().c
ode + ';')); |
| 3417 } |
| 3418 } |
| 3419 } |
| 3420 if (!this.corejs.useIsolates) { |
| 3421 if (this.hasStatics) { |
| 3422 this.writer.writeln('var \$globals = {};'); |
| 3423 } |
| 3424 if (this.globals.get$length() > 0) { |
| 3425 this.writer.writeln('\$static_init();'); |
| 3426 } |
| 3427 } |
| 3428 } |
| 3429 WorldGenerator.prototype._orderValues = function(map) { |
| 3430 var values = map.getValues(); |
| 3431 values.sort(this.get$_compareMembers()); |
| 3432 return values; |
| 3433 } |
| 3434 WorldGenerator.prototype._compareMembers = function(x, y) { |
| 3435 if (x.span != null && y.span != null) { |
| 3436 var spans = x.span.compareTo$1(y.span); |
| 3437 if (spans != 0) return spans; |
| 3438 } |
| 3439 if (x.span == null) return 1; |
| 3440 if (y.span == null) return -1; |
| 3441 return x.name.compareTo$1(y.name); |
| 3442 } |
| 3443 WorldGenerator.prototype.get$_compareMembers = function() { |
| 3444 return WorldGenerator.prototype._compareMembers.bind(this); |
| 3445 } |
| 3446 // ********** Code for BlockScope ************** |
| 3447 function BlockScope(enclosingMethod, parent, reentrant) { |
| 3448 this.enclosingMethod = enclosingMethod; |
| 3449 this.parent = parent; |
| 3450 this.reentrant = reentrant; |
| 3451 this._vars = new HashMapImplementation(); |
| 3452 this._jsNames = new HashSetImplementation(); |
| 3453 // Initializers done |
| 3454 if (this.get$isMethodScope()) { |
| 3455 this._closedOver = new HashSetImplementation(); |
| 3456 } |
| 3457 else { |
| 3458 this.reentrant = reentrant || this.parent.reentrant; |
| 3459 } |
| 3460 } |
| 3461 BlockScope.prototype.get$enclosingMethod = function() { return this.enclosingMet
hod; }; |
| 3462 BlockScope.prototype.set$enclosingMethod = function(value) { return this.enclosi
ngMethod = value; }; |
| 3463 BlockScope.prototype.get$_vars = function() { return this._vars; }; |
| 3464 BlockScope.prototype.set$_vars = function(value) { return this._vars = value; }; |
| 3465 BlockScope.prototype.get$_jsNames = function() { return this._jsNames; }; |
| 3466 BlockScope.prototype.set$_jsNames = function(value) { return this._jsNames = val
ue; }; |
| 3467 BlockScope.prototype.get$_closedOver = function() { return this._closedOver; }; |
| 3468 BlockScope.prototype.set$_closedOver = function(value) { return this._closedOver
= value; }; |
| 3469 BlockScope.prototype.get$rethrow = function() { return this.rethrow; }; |
| 3470 BlockScope.prototype.set$rethrow = function(value) { return this.rethrow = value
; }; |
| 3471 BlockScope.prototype.get$reentrant = function() { return this.reentrant; }; |
| 3472 BlockScope.prototype.set$reentrant = function(value) { return this.reentrant = v
alue; }; |
| 3473 BlockScope.prototype.get$isMethodScope = function() { |
| 3474 return this.parent == null || $ne(this.parent.enclosingMethod, this.enclosingM
ethod); |
| 3475 } |
| 3476 BlockScope.prototype.get$methodScope = function() { |
| 3477 var s = this; |
| 3478 while (!s.get$isMethodScope()) s = s.parent; |
| 3479 return s; |
| 3480 } |
| 3481 BlockScope.prototype.lookup = function(name) { |
| 3482 var ret = this._vars.$index(name); |
| 3483 if (ret != null) return ret; |
| 3484 for (var s = this.parent; |
| 3485 s != null; s = s.parent) { |
| 3486 ret = s.get$_vars().$index(name); |
| 3487 if (ret != null) { |
| 3488 if ($ne(s.get$enclosingMethod(), this.enclosingMethod)) { |
| 3489 s.get$methodScope().get$_closedOver().add$1(ret.code); |
| 3490 if (this.enclosingMethod.captures != null && s.get$reentrant()) { |
| 3491 this.enclosingMethod.captures.add(ret.code); |
| 3492 } |
| 3493 } |
| 3494 return ret; |
| 3495 } |
| 3496 } |
| 3497 } |
| 3498 BlockScope.prototype._isDefinedInParent = function(name) { |
| 3499 if (this.get$isMethodScope() && this._closedOver.contains(name)) return true; |
| 3500 for (var s = this.parent; |
| 3501 s != null; s = s.parent) { |
| 3502 if (s.get$_vars().containsKey$1(name)) return true; |
| 3503 if (s.get$_jsNames().contains$1(name)) return true; |
| 3504 if (s.get$isMethodScope() && s.get$_closedOver().contains$1(name)) return tr
ue; |
| 3505 } |
| 3506 var type = this.enclosingMethod.method.declaringType; |
| 3507 if (type.get$library().lookup(name, null) != null) return true; |
| 3508 return false; |
| 3509 } |
| 3510 BlockScope.prototype.create = function(name, type, span, isFinal, isParameter) { |
| 3511 var jsName = $globals.world.toJsIdentifier(name); |
| 3512 if (this._vars.containsKey(name)) { |
| 3513 $globals.world.error(('duplicate name "' + name + '"'), span); |
| 3514 } |
| 3515 if (!isParameter) { |
| 3516 var index = 0; |
| 3517 while (this._isDefinedInParent(jsName)) { |
| 3518 jsName = ('' + name + (index++)); |
| 3519 } |
| 3520 } |
| 3521 var ret = new Value(type, jsName, span, false); |
| 3522 ret.set$isFinal(isFinal); |
| 3523 this._vars.$setindex(name, ret); |
| 3524 if (name != jsName) this._jsNames.add(jsName); |
| 3525 return ret; |
| 3526 } |
| 3527 BlockScope.prototype.declareParameter = function(p) { |
| 3528 return this.create(p.name, p.type, p.definition.span, false, true); |
| 3529 } |
| 3530 BlockScope.prototype.declare = function(id) { |
| 3531 var type = this.enclosingMethod.method.resolveType(id.type, false); |
| 3532 return this.create(id.name.name, type, id.span, false, false); |
| 3533 } |
| 3534 BlockScope.prototype.getRethrow = function() { |
| 3535 var scope = this; |
| 3536 while (scope.get$rethrow() == null && scope.parent != null) { |
| 3537 scope = scope.parent; |
| 3538 } |
| 3539 return scope.get$rethrow(); |
| 3540 } |
| 3541 // ********** Code for MethodGenerator ************** |
| 3542 function MethodGenerator(method, enclosingMethod) { |
| 3543 this.method = method; |
| 3544 this.enclosingMethod = enclosingMethod; |
| 3545 this.writer = new CodeWriter(); |
| 3546 this.needsThis = false; |
| 3547 // Initializers done |
| 3548 if (this.enclosingMethod != null) { |
| 3549 this._scope = new BlockScope(this, this.enclosingMethod._scope, false); |
| 3550 this.captures = new HashSetImplementation(); |
| 3551 } |
| 3552 else { |
| 3553 this._scope = new BlockScope(this, null, false); |
| 3554 } |
| 3555 this._usedTemps = new HashSetImplementation(); |
| 3556 this._freeTemps = []; |
| 3557 } |
| 3558 MethodGenerator.prototype.get$enclosingMethod = function() { return this.enclosi
ngMethod; }; |
| 3559 MethodGenerator.prototype.set$enclosingMethod = function(value) { return this.en
closingMethod = value; }; |
| 3560 MethodGenerator.prototype.get$needsThis = function() { return this.needsThis; }; |
| 3561 MethodGenerator.prototype.set$needsThis = function(value) { return this.needsThi
s = value; }; |
| 3562 MethodGenerator.prototype.get$library = function() { |
| 3563 return this.method.get$library(); |
| 3564 } |
| 3565 MethodGenerator.prototype.findMembers = function(name) { |
| 3566 return this.get$library()._findMembers(name); |
| 3567 } |
| 3568 MethodGenerator.prototype.get$isClosure = function() { |
| 3569 return (this.enclosingMethod != null); |
| 3570 } |
| 3571 MethodGenerator.prototype.get$isStatic = function() { |
| 3572 return this.method.get$isStatic(); |
| 3573 } |
| 3574 MethodGenerator.prototype.getTemp = function(value) { |
| 3575 return value.needsTemp ? this.forceTemp(value) : value; |
| 3576 } |
| 3577 MethodGenerator.prototype.forceTemp = function(value) { |
| 3578 var name; |
| 3579 if (this._freeTemps.length > 0) { |
| 3580 name = this._freeTemps.removeLast(); |
| 3581 } |
| 3582 else { |
| 3583 name = '\$' + this._usedTemps.get$length(); |
| 3584 } |
| 3585 this._usedTemps.add(name); |
| 3586 return new Value(value.get$type(), name, value.span, false); |
| 3587 } |
| 3588 MethodGenerator.prototype.assignTemp = function(tmp, v) { |
| 3589 if ($eq(tmp, v)) { |
| 3590 return v; |
| 3591 } |
| 3592 else { |
| 3593 return new Value(v.get$type(), ('(' + tmp.code + ' = ' + v.code + ')'), v.sp
an, true); |
| 3594 } |
| 3595 } |
| 3596 MethodGenerator.prototype.freeTemp = function(value) { |
| 3597 if (this._usedTemps.remove(value.code)) { |
| 3598 this._freeTemps.add(value.code); |
| 3599 } |
| 3600 else { |
| 3601 $globals.world.internalError(('tried to free unused value or non-temp "' + v
alue.code + '"')); |
| 3602 } |
| 3603 } |
| 3604 MethodGenerator.prototype.run = function() { |
| 3605 if (this.method.isGenerated) return; |
| 3606 this.method.isGenerated = true; |
| 3607 this.method.generator = this; |
| 3608 this.writeBody(); |
| 3609 if (this.method.get$definition().get$nativeBody() != null) { |
| 3610 this.writer = new CodeWriter(); |
| 3611 if ($eq(this.method.get$definition().get$nativeBody(), '')) { |
| 3612 this.method.generator = null; |
| 3613 } |
| 3614 else { |
| 3615 this._paramCode = map(this.method.get$parameters(), (function (p) { |
| 3616 return p.name; |
| 3617 }) |
| 3618 ); |
| 3619 this.writer.write(this.method.get$definition().get$nativeBody()); |
| 3620 } |
| 3621 } |
| 3622 } |
| 3623 MethodGenerator.prototype.writeDefinition = function(defWriter, lambda) { |
| 3624 var paramCode = this._paramCode; |
| 3625 var names = null; |
| 3626 if (this.captures != null && this.captures.get$length() > 0) { |
| 3627 names = ListFactory.ListFactory$from$factory(this.captures); |
| 3628 names.sort$1((function (x, y) { |
| 3629 return x.compareTo$1(y); |
| 3630 }) |
| 3631 ); |
| 3632 paramCode = ListFactory.ListFactory$from$factory(names); |
| 3633 paramCode.addAll$1(this._paramCode); |
| 3634 } |
| 3635 var _params = ('(' + Strings.join(this._paramCode, ", ") + ')'); |
| 3636 var params = ('(' + Strings.join(paramCode, ", ") + ')'); |
| 3637 if (this.method.declaringType.get$isTop() && !this.get$isClosure()) { |
| 3638 defWriter.enterBlock(('function ' + this.method.get$jsname() + params + ' {'
)); |
| 3639 } |
| 3640 else if (this.get$isClosure()) { |
| 3641 if (this.method.name == '') { |
| 3642 defWriter.enterBlock(('(function ' + params + ' {')); |
| 3643 } |
| 3644 else if (names != null) { |
| 3645 if (lambda == null) { |
| 3646 defWriter.enterBlock(('var ' + this.method.get$jsname() + ' = (function'
+ params + ' {')); |
| 3647 } |
| 3648 else { |
| 3649 defWriter.enterBlock(('(function ' + this.method.get$jsname() + params +
' {')); |
| 3650 } |
| 3651 } |
| 3652 else { |
| 3653 defWriter.enterBlock(('function ' + this.method.get$jsname() + params + '
{')); |
| 3654 } |
| 3655 } |
| 3656 else if (this.method.get$isConstructor()) { |
| 3657 if (this.method.get$constructorName() == '') { |
| 3658 defWriter.enterBlock(('function ' + this.method.declaringType.get$jsname()
+ params + ' {')); |
| 3659 } |
| 3660 else { |
| 3661 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' +
this.method.get$constructorName() + '\$ctor = function' + params + ' {')); |
| 3662 } |
| 3663 } |
| 3664 else if (this.method.get$isFactory()) { |
| 3665 defWriter.enterBlock(('' + this.method.get$generatedFactoryName() + ' = func
tion' + _params + ' {')); |
| 3666 } |
| 3667 else if (this.method.get$isStatic()) { |
| 3668 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' + th
is.method.get$jsname() + ' = function' + _params + ' {')); |
| 3669 } |
| 3670 else { |
| 3671 defWriter.enterBlock($globals.world.gen._prototypeOf(this.method.declaringTy
pe, this.method.get$jsname()) + (' = function' + _params + ' {')); |
| 3672 } |
| 3673 if (this.needsThis) { |
| 3674 defWriter.writeln('var \$this = this; // closure support'); |
| 3675 } |
| 3676 if (this._usedTemps.get$length() > 0 || this._freeTemps.length > 0) { |
| 3677 this._freeTemps.addAll(this._usedTemps); |
| 3678 this._freeTemps.sort((function (x, y) { |
| 3679 return x.compareTo$1(y); |
| 3680 }) |
| 3681 ); |
| 3682 defWriter.writeln(('var ' + Strings.join(this._freeTemps, ", ") + ';')); |
| 3683 } |
| 3684 defWriter.writeln(this.writer.get$text()); |
| 3685 if (names != null) { |
| 3686 defWriter.exitBlock(('}).bind(null, ' + Strings.join(names, ", ") + ')')); |
| 3687 } |
| 3688 else if (this.get$isClosure() && this.method.name == '') { |
| 3689 defWriter.exitBlock('})'); |
| 3690 } |
| 3691 else { |
| 3692 defWriter.exitBlock('}'); |
| 3693 } |
| 3694 if (this.method.get$isConstructor() && this.method.get$constructorName() != ''
) { |
| 3695 defWriter.writeln(('' + this.method.declaringType.get$jsname() + '.' + this.
method.get$constructorName() + '\$ctor.prototype = ') + ('' + this.method.declar
ingType.get$jsname() + '.prototype;')); |
| 3696 } |
| 3697 this._provideOptionalParamInfo(defWriter); |
| 3698 if ((this.method instanceof MethodMember)) { |
| 3699 var m = this.method; |
| 3700 if (m._providePropertySyntax) { |
| 3701 defWriter.enterBlock(('' + m.declaringType.get$jsname() + '.prototype') +
('.get\$' + m.get$jsname() + ' = function() {')); |
| 3702 defWriter.writeln(('return ' + m.declaringType.get$jsname() + '.prototype.
') + ('' + m.get$jsname() + '.bind(this);')); |
| 3703 defWriter.exitBlock('}'); |
| 3704 if (m._provideFieldSyntax) { |
| 3705 $globals.world.internalError('bound m accessed with field syntax'); |
| 3706 } |
| 3707 } |
| 3708 } |
| 3709 } |
| 3710 MethodGenerator.prototype._provideOptionalParamInfo = function(defWriter) { |
| 3711 if ((this.method instanceof MethodMember)) { |
| 3712 var meth = this.method; |
| 3713 if (meth._provideOptionalParamInfo) { |
| 3714 var optNames = []; |
| 3715 var optValues = []; |
| 3716 meth.genParameterValues(); |
| 3717 var $$list = meth.parameters; |
| 3718 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3719 var param = $$list.$index($$i); |
| 3720 if (param.get$isOptional()) { |
| 3721 optNames.add$1(param.name); |
| 3722 optValues.add$1(MethodGenerator._escapeString(param.value.code)); |
| 3723 } |
| 3724 } |
| 3725 if (optNames.length > 0) { |
| 3726 var start = ''; |
| 3727 if (meth.isStatic) { |
| 3728 if (!meth.declaringType.get$isTop()) { |
| 3729 start = meth.declaringType.get$jsname() + '.'; |
| 3730 } |
| 3731 } |
| 3732 else { |
| 3733 start = meth.declaringType.get$jsname() + '.prototype.'; |
| 3734 } |
| 3735 optNames.addAll$1(optValues); |
| 3736 var optional = "['" + Strings.join(optNames, "', '") + "']"; |
| 3737 defWriter.writeln(('' + start + meth.get$jsname() + '.\$optional = ' + o
ptional)); |
| 3738 } |
| 3739 } |
| 3740 } |
| 3741 } |
| 3742 MethodGenerator.prototype.writeBody = function() { |
| 3743 var initializers = null; |
| 3744 var initializedFields = null; |
| 3745 var allMembers = null; |
| 3746 if (this.method.get$isConstructor()) { |
| 3747 initializers = []; |
| 3748 initializedFields = new HashSetImplementation(); |
| 3749 allMembers = $globals.world.gen._orderValues(this.method.declaringType.getAl
lMembers()); |
| 3750 for (var $$i = allMembers.iterator$0(); $$i.hasNext$0(); ) { |
| 3751 var f = $$i.next$0(); |
| 3752 if (f.get$isField() && !f.get$isStatic()) { |
| 3753 var cv = f.computeValue$0(); |
| 3754 if (cv != null) { |
| 3755 initializers.add$1(('this.' + f.get$jsname() + ' = ' + cv.code)); |
| 3756 initializedFields.add$1(f.name); |
| 3757 } |
| 3758 } |
| 3759 } |
| 3760 } |
| 3761 this._paramCode = []; |
| 3762 var $$list = this.method.get$parameters(); |
| 3763 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3764 var p = $$list.$index($$i); |
| 3765 if (initializers != null && p.get$isInitializer()) { |
| 3766 var field = this.method.declaringType.getMember(p.name); |
| 3767 if (field == null) { |
| 3768 $globals.world.error('bad this parameter - no matching field', p.get$def
inition().span); |
| 3769 } |
| 3770 if (!field.get$isField()) { |
| 3771 $globals.world.error(('"this.' + p.name + '" does not refer to a field')
, p.get$definition().span); |
| 3772 } |
| 3773 var paramValue = new Value(field.get$returnType(), p.name, p.get$definitio
n().span, false); |
| 3774 this._paramCode.add(paramValue.code); |
| 3775 initializers.add$1(('this.' + field.get$jsname() + ' = ' + paramValue.code
+ ';')); |
| 3776 initializedFields.add$1(p.name); |
| 3777 } |
| 3778 else { |
| 3779 var paramValue = this._scope.declareParameter(p); |
| 3780 this._paramCode.add(paramValue.code); |
| 3781 } |
| 3782 } |
| 3783 var body = this.method.get$definition().body; |
| 3784 if (body == null && !this.method.get$isConstructor() && !this.method.get$isNat
ive()) { |
| 3785 $globals.world.error(('unexpected empty body for ' + this.method.name), this
.method.get$definition().span); |
| 3786 } |
| 3787 var initializerCall = null; |
| 3788 var declaredInitializers = this.method.get$definition().get$initializers(); |
| 3789 if (initializers != null) { |
| 3790 for (var $$i = initializers.iterator$0(); $$i.hasNext$0(); ) { |
| 3791 var i = $$i.next$0(); |
| 3792 this.writer.writeln(i); |
| 3793 } |
| 3794 if (declaredInitializers != null) { |
| 3795 for (var $$i = declaredInitializers.iterator$0(); $$i.hasNext$0(); ) { |
| 3796 var init = $$i.next$0(); |
| 3797 if ((init instanceof CallExpression)) { |
| 3798 if (initializerCall != null) { |
| 3799 $globals.world.error('only one initializer redirecting call is allow
ed', init.span); |
| 3800 } |
| 3801 initializerCall = init; |
| 3802 } |
| 3803 else if ((init instanceof BinaryExpression) && TokenKind.kindFromAssign(
init.get$op().kind) == 0) { |
| 3804 var left = init.x; |
| 3805 if (!((left instanceof DotExpression) && (left.self instanceof ThisExp
ression) || (left instanceof VarExpression))) { |
| 3806 $globals.world.error('invalid left side of initializer', left.span); |
| 3807 continue; |
| 3808 } |
| 3809 var f = this.method.declaringType.getMember(left.name.name); |
| 3810 if (f == null) { |
| 3811 $globals.world.error('bad initializer - no matching field', left.spa
n); |
| 3812 continue; |
| 3813 } |
| 3814 else if (!f.get$isField()) { |
| 3815 $globals.world.error(('"' + left.name.name + '" does not refer to a
field'), left.span); |
| 3816 continue; |
| 3817 } |
| 3818 initializedFields.add$1(f.name); |
| 3819 this.writer.writeln(('this.' + f.get$jsname() + ' = ' + this.visitValu
e(init.y).code + ';')); |
| 3820 } |
| 3821 else { |
| 3822 $globals.world.error('invalid initializer', init.span); |
| 3823 } |
| 3824 } |
| 3825 } |
| 3826 this.writer.comment('// Initializers done'); |
| 3827 } |
| 3828 if (this.method.get$isConstructor() && initializerCall == null && !this.method
.get$isNative()) { |
| 3829 var parentType = this.method.declaringType.get$parent(); |
| 3830 if (parentType != null && !parentType.get$isObject()) { |
| 3831 initializerCall = new CallExpression(new SuperExpression(this.method.get$s
pan()), [], this.method.get$span()); |
| 3832 } |
| 3833 } |
| 3834 if (initializerCall != null) { |
| 3835 var target = this._writeInitializerCall(initializerCall); |
| 3836 if (!target.get$isSuper()) { |
| 3837 if (initializers.length > 0) { |
| 3838 var $$list = this.method.get$parameters(); |
| 3839 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3840 var p = $$list.$index($$i); |
| 3841 if (p.get$isInitializer()) { |
| 3842 $globals.world.error('no initialization allowed on redirecting const
ructors', p.get$definition().span); |
| 3843 break; |
| 3844 } |
| 3845 } |
| 3846 } |
| 3847 if (declaredInitializers != null && declaredInitializers.length > 1) { |
| 3848 var init = $eq(declaredInitializers.$index(0), initializerCall) ? declar
edInitializers.$index(1) : declaredInitializers.$index(0); |
| 3849 $globals.world.error('no initialization allowed on redirecting construct
ors', init.span); |
| 3850 } |
| 3851 initializedFields = null; |
| 3852 } |
| 3853 } |
| 3854 if (initializedFields != null) { |
| 3855 for (var $$i = allMembers.iterator$0(); $$i.hasNext$0(); ) { |
| 3856 var member = $$i.next$0(); |
| 3857 if (member.get$isField() && member.get$isFinal() && !member.get$isStatic()
&& !this.method.get$isNative() && !initializedFields.contains$1(member.name)) { |
| 3858 $globals.world.error(('Field "' + member.name + '" is final and was not
initialized'), this.method.get$definition().span); |
| 3859 } |
| 3860 } |
| 3861 } |
| 3862 this.visitStatementsInBlock(body); |
| 3863 } |
| 3864 MethodGenerator.prototype._writeInitializerCall = function(node) { |
| 3865 var contructorName = ''; |
| 3866 var targetExp = node.target; |
| 3867 if ((targetExp instanceof DotExpression)) { |
| 3868 var dot = targetExp; |
| 3869 targetExp = dot.self; |
| 3870 contructorName = dot.name.name; |
| 3871 } |
| 3872 var target = null; |
| 3873 if ((targetExp instanceof SuperExpression)) { |
| 3874 target = this._makeSuperValue(targetExp); |
| 3875 } |
| 3876 else if ((targetExp instanceof ThisExpression)) { |
| 3877 target = this._makeThisValue(targetExp); |
| 3878 } |
| 3879 else { |
| 3880 $globals.world.error('bad call in initializers', node.span); |
| 3881 } |
| 3882 target.set$allowDynamic(false); |
| 3883 var m = target.type.getConstructor$1(contructorName); |
| 3884 this.method.set$initDelegate(m); |
| 3885 var other = m; |
| 3886 while (other != null) { |
| 3887 if ($eq(other, this.method)) { |
| 3888 $globals.world.error('initialization cycle', node.span); |
| 3889 break; |
| 3890 } |
| 3891 other = other.get$initDelegate(); |
| 3892 } |
| 3893 $globals.world.gen.genMethod(m); |
| 3894 var value = m.invoke$4(this, node, target, this._makeArgs(node.arguments)); |
| 3895 if ($ne(target.type, $globals.world.objectType)) { |
| 3896 this.writer.writeln(('' + value.code + ';')); |
| 3897 } |
| 3898 return target; |
| 3899 } |
| 3900 MethodGenerator.prototype._makeArgs = function(arguments) { |
| 3901 var args = []; |
| 3902 var seenLabel = false; |
| 3903 for (var $$i = 0;$$i < arguments.length; $$i++) { |
| 3904 var arg = arguments.$index($$i); |
| 3905 if (arg.label != null) { |
| 3906 seenLabel = true; |
| 3907 } |
| 3908 else if (seenLabel) { |
| 3909 $globals.world.error('bare argument can not follow named arguments', arg.s
pan); |
| 3910 } |
| 3911 args.add$1(this.visitValue(arg.value)); |
| 3912 } |
| 3913 return new Arguments(arguments, args); |
| 3914 } |
| 3915 MethodGenerator.prototype._invokeNative = function(name, arguments) { |
| 3916 var args = Arguments.get$EMPTY(); |
| 3917 if (arguments.length > 0) { |
| 3918 args = new Arguments(null, arguments); |
| 3919 } |
| 3920 var method = $globals.world.corelib.topType.members.$index(name); |
| 3921 return method.invoke$4(this, method.get$definition(), new Value($globals.world
.corelib.topType, null, null, true), args); |
| 3922 } |
| 3923 MethodGenerator._escapeString = function(text) { |
| 3924 return text.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '
\\n').replaceAll('\r', '\\r'); |
| 3925 } |
| 3926 MethodGenerator.prototype.visitStatementsInBlock = function(body) { |
| 3927 if ((body instanceof BlockStatement)) { |
| 3928 var block = body; |
| 3929 var $$list = block.body; |
| 3930 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3931 var stmt = $$list.$index($$i); |
| 3932 stmt.visit$1(this); |
| 3933 } |
| 3934 } |
| 3935 else { |
| 3936 if (body != null) body.visit(this); |
| 3937 } |
| 3938 return false; |
| 3939 } |
| 3940 MethodGenerator.prototype._pushBlock = function(reentrant) { |
| 3941 this._scope = new BlockScope(this, this._scope, reentrant); |
| 3942 } |
| 3943 MethodGenerator.prototype._popBlock = function() { |
| 3944 this._scope = this._scope.parent; |
| 3945 } |
| 3946 MethodGenerator.prototype._makeLambdaMethod = function(name, func) { |
| 3947 var meth = new MethodMember(name, this.method.declaringType, func); |
| 3948 meth.set$isLambda(true); |
| 3949 meth.set$enclosingElement(this.method); |
| 3950 meth.resolve$0(); |
| 3951 return meth; |
| 3952 } |
| 3953 MethodGenerator.prototype.visitBool = function(node) { |
| 3954 return this.visitValue(node).convertTo$3(this, $globals.world.nonNullBool, nod
e); |
| 3955 } |
| 3956 MethodGenerator.prototype.visitValue = function(node) { |
| 3957 if (node == null) return null; |
| 3958 var value = node.visit(this); |
| 3959 value.checkFirstClass$1(node.span); |
| 3960 return value; |
| 3961 } |
| 3962 MethodGenerator.prototype.visitTypedValue = function(node, expectedType) { |
| 3963 var val = this.visitValue(node); |
| 3964 return expectedType == null ? val : val.convertTo$3(this, expectedType, node); |
| 3965 } |
| 3966 MethodGenerator.prototype.visitVoid = function(node) { |
| 3967 if ((node instanceof PostfixExpression)) { |
| 3968 var value = this.visitPostfixExpression(node, true); |
| 3969 value.checkFirstClass$1(node.span); |
| 3970 return value; |
| 3971 } |
| 3972 else if ((node instanceof BinaryExpression)) { |
| 3973 var value = this.visitBinaryExpression(node, true); |
| 3974 value.checkFirstClass$1(node.span); |
| 3975 return value; |
| 3976 } |
| 3977 return this.visitValue(node); |
| 3978 } |
| 3979 MethodGenerator.prototype.visitDietStatement = function(node) { |
| 3980 var parser = new Parser(node.span.file, false, false, false, node.span.start); |
| 3981 this.visitStatementsInBlock(parser.block$0()); |
| 3982 return false; |
| 3983 } |
| 3984 MethodGenerator.prototype.visitVariableDefinition = function(node) { |
| 3985 var isFinal = false; |
| 3986 if (node.modifiers != null && $eq(node.modifiers.$index(0).kind, 98/*TokenKind
.FINAL*/)) { |
| 3987 isFinal = true; |
| 3988 } |
| 3989 this.writer.write('var '); |
| 3990 var type = this.method.resolveType(node.type, false); |
| 3991 for (var i = 0; |
| 3992 i < node.names.length; i++) { |
| 3993 var thisType = type; |
| 3994 if (i > 0) { |
| 3995 this.writer.write(', '); |
| 3996 } |
| 3997 var name = node.names.$index(i).name; |
| 3998 var value = this.visitValue(node.values.$index(i)); |
| 3999 if (isFinal) { |
| 4000 if (value == null) { |
| 4001 $globals.world.error('no value specified for final variable', node.span)
; |
| 4002 } |
| 4003 else { |
| 4004 if (thisType.get$isVar()) thisType = value.type; |
| 4005 } |
| 4006 } |
| 4007 var val = this._scope.create(name, thisType, node.names.$index(i).span, isFi
nal, false); |
| 4008 if (value == null) { |
| 4009 if (this._scope.reentrant) { |
| 4010 this.writer.write(('' + val.code + ' = null')); |
| 4011 } |
| 4012 else { |
| 4013 this.writer.write(('' + val.code)); |
| 4014 } |
| 4015 } |
| 4016 else { |
| 4017 value = value.convertTo$3(this, type, node.values.$index(i)); |
| 4018 this.writer.write(('' + val.code + ' = ' + value.code)); |
| 4019 } |
| 4020 } |
| 4021 this.writer.writeln(';'); |
| 4022 return false; |
| 4023 } |
| 4024 MethodGenerator.prototype.visitFunctionDefinition = function(node) { |
| 4025 var meth = this._makeLambdaMethod(node.name.name, node); |
| 4026 var funcValue = this._scope.create(meth.name, meth.get$functionType(), this.me
thod.get$definition().span, true, false); |
| 4027 $globals.world.gen.genMethod(meth, this); |
| 4028 meth.get$generator().writeDefinition$2(this.writer); |
| 4029 return false; |
| 4030 } |
| 4031 MethodGenerator.prototype.visitReturnStatement = function(node) { |
| 4032 if (node.value == null) { |
| 4033 this.writer.writeln('return;'); |
| 4034 } |
| 4035 else { |
| 4036 if (this.method.get$isConstructor()) { |
| 4037 $globals.world.error('return of value not allowed from constructor', node.
span); |
| 4038 } |
| 4039 var value = this.visitTypedValue(node.value, this.method.get$returnType()); |
| 4040 this.writer.writeln(('return ' + value.code + ';')); |
| 4041 } |
| 4042 return true; |
| 4043 } |
| 4044 MethodGenerator.prototype.visitThrowStatement = function(node) { |
| 4045 if (node.value != null) { |
| 4046 var value = this.visitValue(node.value); |
| 4047 value.invoke$4(this, 'toString', node, Arguments.get$EMPTY()); |
| 4048 this.writer.writeln(('\$throw(' + value.code + ');')); |
| 4049 $globals.world.gen.corejs.useThrow = true; |
| 4050 } |
| 4051 else { |
| 4052 var rethrow = this._scope.getRethrow(); |
| 4053 if (rethrow == null) { |
| 4054 $globals.world.error('rethrow outside of catch', node.span); |
| 4055 } |
| 4056 else { |
| 4057 this.writer.writeln(('throw ' + rethrow.code + ';')); |
| 4058 } |
| 4059 } |
| 4060 return true; |
| 4061 } |
| 4062 MethodGenerator.prototype.visitAssertStatement = function(node) { |
| 4063 var test = this.visitValue(node.test); |
| 4064 if ($globals.options.enableAsserts) { |
| 4065 var span = node.test.span; |
| 4066 var line = span.get$file().getLine$1(span.start) + 1; |
| 4067 var column = span.get$file().getColumn$2(line - 1, span.start) + 1; |
| 4068 var args = [test, EvaluatedValue.EvaluatedValue$factory($globals.world.strin
gType, MethodGenerator._escapeString(span.text), ('"' + MethodGenerator._escapeS
tring(span.text) + '"'), null), EvaluatedValue.EvaluatedValue$factory($globals.w
orld.stringType, MethodGenerator._escapeString(span.get$file().filename), ('"' +
MethodGenerator._escapeString(span.get$file().filename) + '"'), null), Evaluate
dValue.EvaluatedValue$factory($globals.world.intType, line, line.toString$0(), n
ull), EvaluatedValue.EvaluatedValue$factory($globals.world.intType, column, colu
mn.toString$0(), null)]; |
| 4069 var tp = $globals.world.corelib.topType; |
| 4070 var f = tp.getMember$1('_assert'); |
| 4071 var value = f.invoke(this, node, new Value.type$ctor(tp, null), new Argument
s(null, args), false); |
| 4072 this.writer.writeln(('' + value.code + ';')); |
| 4073 } |
| 4074 return false; |
| 4075 } |
| 4076 MethodGenerator.prototype.visitBreakStatement = function(node) { |
| 4077 if (node.label == null) { |
| 4078 this.writer.writeln('break;'); |
| 4079 } |
| 4080 else { |
| 4081 this.writer.writeln(('break ' + node.label.name + ';')); |
| 4082 } |
| 4083 return true; |
| 4084 } |
| 4085 MethodGenerator.prototype.visitContinueStatement = function(node) { |
| 4086 if (node.label == null) { |
| 4087 this.writer.writeln('continue;'); |
| 4088 } |
| 4089 else { |
| 4090 this.writer.writeln(('continue ' + node.label.name + ';')); |
| 4091 } |
| 4092 return true; |
| 4093 } |
| 4094 MethodGenerator.prototype.visitIfStatement = function(node) { |
| 4095 var test = this.visitBool(node.test); |
| 4096 this.writer.write(('if (' + test.code + ') ')); |
| 4097 var exit1 = node.trueBranch.visit(this); |
| 4098 if (node.falseBranch != null) { |
| 4099 this.writer.write('else '); |
| 4100 if (node.falseBranch.visit(this) && exit1) { |
| 4101 return true; |
| 4102 } |
| 4103 } |
| 4104 return false; |
| 4105 } |
| 4106 MethodGenerator.prototype.visitWhileStatement = function(node) { |
| 4107 var test = this.visitBool(node.test); |
| 4108 this.writer.write(('while (' + test.code + ') ')); |
| 4109 this._pushBlock(true); |
| 4110 node.body.visit(this); |
| 4111 this._popBlock(); |
| 4112 return false; |
| 4113 } |
| 4114 MethodGenerator.prototype.visitDoStatement = function(node) { |
| 4115 this.writer.write('do '); |
| 4116 this._pushBlock(true); |
| 4117 node.body.visit(this); |
| 4118 this._popBlock(); |
| 4119 var test = this.visitBool(node.test); |
| 4120 this.writer.writeln(('while (' + test.code + ')')); |
| 4121 return false; |
| 4122 } |
| 4123 MethodGenerator.prototype.visitForStatement = function(node) { |
| 4124 this._pushBlock(false); |
| 4125 this.writer.write('for ('); |
| 4126 if (node.init != null) node.init.visit(this); |
| 4127 else this.writer.write(';'); |
| 4128 if (node.test != null) { |
| 4129 var test = this.visitBool(node.test); |
| 4130 this.writer.write((' ' + test.code + '; ')); |
| 4131 } |
| 4132 else { |
| 4133 this.writer.write('; '); |
| 4134 } |
| 4135 var needsComma = false; |
| 4136 var $$list = node.step; |
| 4137 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4138 var s = $$list.$index($$i); |
| 4139 if (needsComma) this.writer.write(', '); |
| 4140 var sv = this.visitVoid(s); |
| 4141 this.writer.write(sv.code); |
| 4142 needsComma = true; |
| 4143 } |
| 4144 this.writer.write(') '); |
| 4145 this._pushBlock(true); |
| 4146 node.body.visit(this); |
| 4147 this._popBlock(); |
| 4148 this._popBlock(); |
| 4149 return false; |
| 4150 } |
| 4151 MethodGenerator.prototype._isFinal = function(typeRef) { |
| 4152 if ((typeRef instanceof GenericTypeReference)) { |
| 4153 typeRef = typeRef.get$baseType(); |
| 4154 } |
| 4155 return typeRef != null && typeRef.get$isFinal(); |
| 4156 } |
| 4157 MethodGenerator.prototype.visitForInStatement = function(node) { |
| 4158 var itemType = this.method.resolveType(node.item.type, false); |
| 4159 var itemName = node.item.name.name; |
| 4160 var list = node.list.visit(this); |
| 4161 this._pushBlock(true); |
| 4162 var isFinal = this._isFinal(node.item.type); |
| 4163 var item = this._scope.create(itemName, itemType, node.item.name.span, isFinal
, false); |
| 4164 var listVar = list; |
| 4165 if (list.get$needsTemp()) { |
| 4166 listVar = this._scope.create('\$list', list.type, null, false, false); |
| 4167 this.writer.writeln(('var ' + listVar.code + ' = ' + list.code + ';')); |
| 4168 } |
| 4169 if (list.type.get$isList()) { |
| 4170 var tmpi = this._scope.create('\$i', $globals.world.numType, null, false, fa
lse); |
| 4171 this.writer.enterBlock(('for (var ' + tmpi.code + ' = 0;') + ('' + tmpi.code
+ ' < ' + listVar.code + '.length; ' + tmpi.code + '++) {')); |
| 4172 var value = listVar.invoke(this, ':index', node.list, new Arguments(null, [t
mpi]), false); |
| 4173 this.writer.writeln(('var ' + item.code + ' = ' + value.code + ';')); |
| 4174 } |
| 4175 else { |
| 4176 this._pushBlock(false); |
| 4177 var iterator = list.invoke$4(this, 'iterator', node.list, Arguments.get$EMPT
Y()); |
| 4178 var tmpi = this._scope.create('\$i', iterator.type, null, false, false); |
| 4179 var hasNext = tmpi.invoke$4(this, 'hasNext', node.list, Arguments.get$EMPTY(
)); |
| 4180 var next = tmpi.invoke$4(this, 'next', node.list, Arguments.get$EMPTY()); |
| 4181 this.writer.enterBlock(('for (var ' + tmpi.code + ' = ' + iterator.code + ';
' + hasNext.code + '; ) {')); |
| 4182 this.writer.writeln(('var ' + item.code + ' = ' + next.code + ';')); |
| 4183 } |
| 4184 this.visitStatementsInBlock(node.body); |
| 4185 this.writer.exitBlock('}'); |
| 4186 this._popBlock(); |
| 4187 return false; |
| 4188 } |
| 4189 MethodGenerator.prototype._genToDartException = function(ex, node) { |
| 4190 var result = this._invokeNative("_toDartException", [ex]); |
| 4191 this.writer.writeln(('' + ex.code + ' = ' + result.code + ';')); |
| 4192 } |
| 4193 MethodGenerator.prototype.visitTryStatement = function(node) { |
| 4194 this.writer.enterBlock('try {'); |
| 4195 this._pushBlock(false); |
| 4196 this.visitStatementsInBlock(node.body); |
| 4197 this._popBlock(); |
| 4198 if (node.catches.length == 1) { |
| 4199 var catch_ = node.catches.$index(0); |
| 4200 this._pushBlock(false); |
| 4201 var exType = this.method.resolveType(catch_.get$exception().type, false); |
| 4202 var ex = this._scope.declare(catch_.get$exception()); |
| 4203 this._scope.rethrow = ex; |
| 4204 this.writer.nextBlock(('} catch (' + ex.code + ') {')); |
| 4205 if (catch_.get$trace() != null) { |
| 4206 var trace = this._scope.declare(catch_.get$trace()); |
| 4207 this.writer.writeln(('var ' + trace.code + ' = \$stackTraceOf(' + ex.code
+ ');')); |
| 4208 $globals.world.gen.corejs.useStackTraceOf = true; |
| 4209 } |
| 4210 this._genToDartException(ex, node); |
| 4211 if (!exType.get$isVarOrObject()) { |
| 4212 var test = ex.instanceOf$3$isTrue$forceCheck(this, exType, catch_.get$exce
ption().span, false, true); |
| 4213 this.writer.writeln(('if (' + test.code + ') throw ' + ex.code + ';')); |
| 4214 } |
| 4215 this.visitStatementsInBlock(node.catches.$index(0).body); |
| 4216 this._popBlock(); |
| 4217 } |
| 4218 else if (node.catches.length > 0) { |
| 4219 this._pushBlock(false); |
| 4220 var ex = this._scope.create('\$ex', $globals.world.varType, null, false, fal
se); |
| 4221 this._scope.rethrow = ex; |
| 4222 this.writer.nextBlock(('} catch (' + ex.code + ') {')); |
| 4223 var trace = null; |
| 4224 if (node.catches.some((function (c) { |
| 4225 return c.get$trace() != null; |
| 4226 }) |
| 4227 )) { |
| 4228 trace = this._scope.create('\$trace', $globals.world.varType, null, false,
false); |
| 4229 this.writer.writeln(('var ' + trace.code + ' = \$stackTraceOf(' + ex.code
+ ');')); |
| 4230 $globals.world.gen.corejs.useStackTraceOf = true; |
| 4231 } |
| 4232 this._genToDartException(ex, node); |
| 4233 var needsRethrow = true; |
| 4234 for (var i = 0; |
| 4235 i < node.catches.length; i++) { |
| 4236 var catch_ = node.catches.$index(i); |
| 4237 this._pushBlock(false); |
| 4238 var tmpType = this.method.resolveType(catch_.get$exception().type, false); |
| 4239 var tmp = this._scope.declare(catch_.get$exception()); |
| 4240 if (!tmpType.get$isVarOrObject()) { |
| 4241 var test = ex.instanceOf$3$isTrue$forceCheck(this, tmpType, catch_.get$e
xception().span, true, true); |
| 4242 if (i == 0) { |
| 4243 this.writer.enterBlock(('if (' + test.code + ') {')); |
| 4244 } |
| 4245 else { |
| 4246 this.writer.nextBlock(('} else if (' + test.code + ') {')); |
| 4247 } |
| 4248 } |
| 4249 else if (i > 0) { |
| 4250 this.writer.nextBlock('} else {'); |
| 4251 } |
| 4252 this.writer.writeln(('var ' + tmp.code + ' = ' + ex.code + ';')); |
| 4253 if (catch_.get$trace() != null) { |
| 4254 var tmptrace = this._scope.declare(catch_.get$trace()); |
| 4255 this.writer.writeln(('var ' + tmptrace.code + ' = ' + trace.code + ';'))
; |
| 4256 } |
| 4257 this.visitStatementsInBlock(catch_.body); |
| 4258 this._popBlock(); |
| 4259 if (tmpType.get$isVarOrObject()) { |
| 4260 if (i + 1 < node.catches.length) { |
| 4261 $globals.world.error('Unreachable catch clause', node.catches.$index(i
+ 1).span); |
| 4262 } |
| 4263 if (i > 0) { |
| 4264 this.writer.exitBlock('}'); |
| 4265 } |
| 4266 needsRethrow = false; |
| 4267 break; |
| 4268 } |
| 4269 } |
| 4270 if (needsRethrow) { |
| 4271 this.writer.nextBlock('} else {'); |
| 4272 this.writer.writeln(('throw ' + ex.code + ';')); |
| 4273 this.writer.exitBlock('}'); |
| 4274 } |
| 4275 this._popBlock(); |
| 4276 } |
| 4277 if (node.finallyBlock != null) { |
| 4278 this.writer.nextBlock('} finally {'); |
| 4279 this._pushBlock(false); |
| 4280 this.visitStatementsInBlock(node.finallyBlock); |
| 4281 this._popBlock(); |
| 4282 } |
| 4283 this.writer.exitBlock('}'); |
| 4284 return false; |
| 4285 } |
| 4286 MethodGenerator.prototype.visitSwitchStatement = function(node) { |
| 4287 var test = this.visitValue(node.test); |
| 4288 this.writer.enterBlock(('switch (' + test.code + ') {')); |
| 4289 var $$list = node.cases; |
| 4290 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4291 var case_ = $$list.$index($$i); |
| 4292 if (case_.label != null) { |
| 4293 $globals.world.error('unimplemented: labeled case statement', case_.span); |
| 4294 } |
| 4295 this._pushBlock(false); |
| 4296 for (var i = 0; |
| 4297 i < case_.get$cases().length; i++) { |
| 4298 var expr = case_.get$cases().$index(i); |
| 4299 if (expr == null) { |
| 4300 if (i < case_.get$cases().length - 1) { |
| 4301 $globals.world.error('default clause must be the last case', case_.spa
n); |
| 4302 } |
| 4303 this.writer.writeln('default:'); |
| 4304 } |
| 4305 else { |
| 4306 var value = this.visitValue(expr); |
| 4307 this.writer.writeln(('case ' + value.code + ':')); |
| 4308 } |
| 4309 } |
| 4310 this.writer.enterBlock(''); |
| 4311 var caseExits = this._visitAllStatements(case_.get$statements(), false); |
| 4312 if ($ne(case_, node.cases.$index(node.cases.length - 1)) && !caseExits) { |
| 4313 var span = case_.get$statements().$index(case_.get$statements().length - 1
).span; |
| 4314 this.writer.writeln('\$throw(new FallThroughError());'); |
| 4315 $globals.world.gen.corejs.useThrow = true; |
| 4316 } |
| 4317 this.writer.exitBlock(''); |
| 4318 this._popBlock(); |
| 4319 } |
| 4320 this.writer.exitBlock('}'); |
| 4321 return false; |
| 4322 } |
| 4323 MethodGenerator.prototype._visitAllStatements = function(statementList, exits) { |
| 4324 for (var i = 0; |
| 4325 i < statementList.length; i++) { |
| 4326 var stmt = statementList.$index(i); |
| 4327 exits = stmt.visit$1(this); |
| 4328 if ($ne(stmt, statementList.$index(statementList.length - 1)) && exits) { |
| 4329 $globals.world.warning('unreachable code', statementList.$index(i + 1).spa
n); |
| 4330 } |
| 4331 } |
| 4332 return exits; |
| 4333 } |
| 4334 MethodGenerator.prototype.visitBlockStatement = function(node) { |
| 4335 this._pushBlock(false); |
| 4336 this.writer.enterBlock('{'); |
| 4337 var exits = this._visitAllStatements(node.body, false); |
| 4338 this.writer.exitBlock('}'); |
| 4339 this._popBlock(); |
| 4340 return exits; |
| 4341 } |
| 4342 MethodGenerator.prototype.visitLabeledStatement = function(node) { |
| 4343 this.writer.writeln(('' + node.name.name + ':')); |
| 4344 node.body.visit(this); |
| 4345 return false; |
| 4346 } |
| 4347 MethodGenerator.prototype.visitExpressionStatement = function(node) { |
| 4348 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi
on)) { |
| 4349 $globals.world.warning('variable used as statement', node.span); |
| 4350 } |
| 4351 var value = this.visitVoid(node.body); |
| 4352 this.writer.writeln(('' + value.code + ';')); |
| 4353 return false; |
| 4354 } |
| 4355 MethodGenerator.prototype.visitEmptyStatement = function(node) { |
| 4356 this.writer.writeln(';'); |
| 4357 return false; |
| 4358 } |
| 4359 MethodGenerator.prototype._checkNonStatic = function(node) { |
| 4360 if (this.get$isStatic()) { |
| 4361 $globals.world.warning('not allowed in static method', node.span); |
| 4362 } |
| 4363 } |
| 4364 MethodGenerator.prototype._makeSuperValue = function(node) { |
| 4365 var parentType = this.method.declaringType.get$parent(); |
| 4366 this._checkNonStatic(node); |
| 4367 if (parentType == null) { |
| 4368 $globals.world.error('no super class', node.span); |
| 4369 } |
| 4370 var ret = new Value(parentType, 'this', node.span, false); |
| 4371 ret.set$isSuper(true); |
| 4372 return ret; |
| 4373 } |
| 4374 MethodGenerator.prototype._getOutermostMethod = function() { |
| 4375 var result = this; |
| 4376 while (result.get$enclosingMethod() != null) { |
| 4377 result = result.get$enclosingMethod(); |
| 4378 } |
| 4379 return result; |
| 4380 } |
| 4381 MethodGenerator.prototype._makeThisCode = function() { |
| 4382 if (this.enclosingMethod != null) { |
| 4383 this._getOutermostMethod().set$needsThis(true); |
| 4384 return '\$this'; |
| 4385 } |
| 4386 else { |
| 4387 return 'this'; |
| 4388 } |
| 4389 } |
| 4390 MethodGenerator.prototype._makeThisValue = function(node) { |
| 4391 if (this.enclosingMethod != null) { |
| 4392 var outermostMethod = this._getOutermostMethod(); |
| 4393 outermostMethod._checkNonStatic$1(node); |
| 4394 outermostMethod.set$needsThis(true); |
| 4395 return new Value(outermostMethod.method.get$declaringType(), '\$this', node
!= null ? node.span : null, false); |
| 4396 } |
| 4397 else { |
| 4398 this._checkNonStatic(node); |
| 4399 return new Value(this.method.declaringType, 'this', node != null ? node.span
: null, false); |
| 4400 } |
| 4401 } |
| 4402 MethodGenerator.prototype.visitLambdaExpression = function(node) { |
| 4403 var name = (node.func.name != null) ? node.func.name.name : ''; |
| 4404 var meth = this._makeLambdaMethod(name, node.func); |
| 4405 var lambdaGen = new MethodGenerator(meth, this); |
| 4406 if ($ne(name, '')) { |
| 4407 lambdaGen._scope.create(name, meth.get$functionType(), meth.definition.span,
true, false); |
| 4408 lambdaGen._pushBlock(false); |
| 4409 } |
| 4410 lambdaGen.run(); |
| 4411 var w = new CodeWriter(); |
| 4412 meth.generator.writeDefinition(w, node); |
| 4413 return new Value(meth.get$functionType(), w.text, node.span, true); |
| 4414 } |
| 4415 MethodGenerator.prototype.visitCallExpression = function(node) { |
| 4416 var target; |
| 4417 var position = node.target; |
| 4418 var name = ':call'; |
| 4419 if ((node.target instanceof DotExpression)) { |
| 4420 var dot = node.target; |
| 4421 target = dot.self.visit(this); |
| 4422 name = dot.name.name; |
| 4423 position = dot.name; |
| 4424 } |
| 4425 else if ((node.target instanceof VarExpression)) { |
| 4426 var varExpr = node.target; |
| 4427 name = varExpr.name.name; |
| 4428 target = this._scope.lookup(name); |
| 4429 if (target != null) { |
| 4430 return target.invoke$4(this, ':call', node, this._makeArgs(node.arguments)
); |
| 4431 } |
| 4432 target = this._makeThisOrType(varExpr.span); |
| 4433 return target.invoke$4(this, name, node, this._makeArgs(node.arguments)); |
| 4434 } |
| 4435 else { |
| 4436 target = node.target.visit(this); |
| 4437 } |
| 4438 return target.invoke$4(this, name, position, this._makeArgs(node.arguments)); |
| 4439 } |
| 4440 MethodGenerator.prototype.visitIndexExpression = function(node) { |
| 4441 var target = this.visitValue(node.target); |
| 4442 var index = this.visitValue(node.index); |
| 4443 return target.invoke$4(this, ':index', node, new Arguments(null, [index])); |
| 4444 } |
| 4445 MethodGenerator.prototype.visitBinaryExpression = function(node, isVoid) { |
| 4446 var kind = node.op.kind; |
| 4447 if (kind == 35/*TokenKind.AND*/ || kind == 34/*TokenKind.OR*/) { |
| 4448 var x = this.visitTypedValue(node.x, $globals.world.nonNullBool); |
| 4449 var y = this.visitTypedValue(node.y, $globals.world.nonNullBool); |
| 4450 var code = ('' + x.code + ' ' + node.op + ' ' + y.code); |
| 4451 if (x.get$isConst() && y.get$isConst()) { |
| 4452 var value = (kind == 35/*TokenKind.AND*/) ? x.get$actualValue() && y.get$a
ctualValue() : x.get$actualValue() || y.get$actualValue(); |
| 4453 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v
alue, ('' + value), node.span); |
| 4454 } |
| 4455 return new Value($globals.world.nonNullBool, code, node.span, true); |
| 4456 } |
| 4457 else if (kind == 50/*TokenKind.EQ_STRICT*/ || kind == 51/*TokenKind.NE_STRICT*
/) { |
| 4458 var x = this.visitValue(node.x); |
| 4459 var y = this.visitValue(node.y); |
| 4460 if (x.get$isConst() && y.get$isConst()) { |
| 4461 var xVal = x.get$actualValue(); |
| 4462 var yVal = y.get$actualValue(); |
| 4463 if (x.type.get$isString() && y.type.get$isString() && $ne(xVal.$index(0),
yVal.$index(0))) { |
| 4464 if ($eq(xVal.$index(0), '"')) { |
| 4465 xVal = xVal.substring$2(1, xVal.length - 1); |
| 4466 yVal = toDoubleQuote(yVal.substring$2(1, yVal.length - 1)); |
| 4467 } |
| 4468 else { |
| 4469 xVal = toDoubleQuote(xVal.substring$2(1, xVal.length - 1)); |
| 4470 yVal = yVal.substring$2(1, yVal.length - 1); |
| 4471 } |
| 4472 } |
| 4473 var value = kind == 50/*TokenKind.EQ_STRICT*/ ? $eq(xVal, yVal) : $ne(xVal
, yVal); |
| 4474 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v
alue, ("" + value), node.span); |
| 4475 } |
| 4476 if ($eq(x.code, 'null') || $eq(y.code, 'null')) { |
| 4477 var op = node.op.toString().substring(0, 2); |
| 4478 return new Value($globals.world.nonNullBool, ('' + x.code + ' ' + op + ' '
+ y.code), node.span, true); |
| 4479 } |
| 4480 else { |
| 4481 return new Value($globals.world.nonNullBool, ('' + x.code + ' ' + node.op
+ ' ' + y.code), node.span, true); |
| 4482 } |
| 4483 } |
| 4484 var assignKind = TokenKind.kindFromAssign(node.op.kind); |
| 4485 if (assignKind == -1) { |
| 4486 var x = this.visitValue(node.x); |
| 4487 var y = this.visitValue(node.y); |
| 4488 var name = TokenKind.binaryMethodName(node.op.kind); |
| 4489 if (node.op.kind == 49/*TokenKind.NE*/) { |
| 4490 name = ':ne'; |
| 4491 } |
| 4492 if (name == null) { |
| 4493 $globals.world.internalError(('unimplemented binary op ' + node.op), node.
span); |
| 4494 return; |
| 4495 } |
| 4496 return x.invoke$4(this, name, node, new Arguments(null, [y])); |
| 4497 } |
| 4498 else { |
| 4499 return this._visitAssign(assignKind, node.x, node.y, node, to$call$1(null),
isVoid); |
| 4500 } |
| 4501 } |
| 4502 MethodGenerator.prototype._visitAssign = function(kind, xn, yn, position, captur
eOriginal, isVoid) { |
| 4503 if (captureOriginal == null) { |
| 4504 captureOriginal = (function (x) { |
| 4505 return x; |
| 4506 }) |
| 4507 ; |
| 4508 } |
| 4509 if ((xn instanceof VarExpression)) { |
| 4510 return this._visitVarAssign(kind, xn, yn, position, captureOriginal); |
| 4511 } |
| 4512 else if ((xn instanceof IndexExpression)) { |
| 4513 return this._visitIndexAssign(kind, xn, yn, position, captureOriginal, isVoi
d); |
| 4514 } |
| 4515 else if ((xn instanceof DotExpression)) { |
| 4516 return this._visitDotAssign(kind, xn, yn, position, captureOriginal); |
| 4517 } |
| 4518 else { |
| 4519 $globals.world.error('illegal lhs', xn.span); |
| 4520 } |
| 4521 } |
| 4522 MethodGenerator.prototype._visitVarAssign = function(kind, xn, yn, position, cap
tureOriginal) { |
| 4523 var name = xn.name.name; |
| 4524 var x = this._scope.lookup(name); |
| 4525 var y = this.visitValue(yn); |
| 4526 if (x == null) { |
| 4527 var members = this.method.declaringType.resolveMember(name); |
| 4528 x = this._makeThisOrType(position.span); |
| 4529 if (members != null) { |
| 4530 if ($globals.options.forceDynamic && !members.get$isStatic()) { |
| 4531 members = this.findMembers(xn.name.name); |
| 4532 } |
| 4533 if (kind == 0) { |
| 4534 return x.set_$4(this, name, position, y); |
| 4535 } |
| 4536 else if (!members.get$treatAsField() || members.get$containsMethods()) { |
| 4537 var right = x.get_$3(this, name, position); |
| 4538 right = captureOriginal(right); |
| 4539 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new
Arguments(null, [y])); |
| 4540 return x.set_$4(this, name, position, y); |
| 4541 } |
| 4542 else { |
| 4543 x = x.get_$3(this, name, position); |
| 4544 } |
| 4545 } |
| 4546 else { |
| 4547 var member = this.get$library().lookup(name, xn.name.span); |
| 4548 if (member == null) { |
| 4549 $globals.world.warning(('can not resolve ' + name), xn.span); |
| 4550 return this._makeMissingValue(name); |
| 4551 } |
| 4552 members = new MemberSet(member, false); |
| 4553 if (!members.get$treatAsField() || members.get$containsMethods()) { |
| 4554 if (kind != 0) { |
| 4555 var right = members._get$3(this, position, x); |
| 4556 right = captureOriginal(right); |
| 4557 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, n
ew Arguments(null, [y])); |
| 4558 } |
| 4559 return members._set$4(this, position, x, y); |
| 4560 } |
| 4561 else { |
| 4562 x = members._get$3(this, position, x); |
| 4563 } |
| 4564 } |
| 4565 } |
| 4566 if (x.get$isFinal()) { |
| 4567 $globals.world.error(('final variable "' + x.code + '" is not assignable'),
position.span); |
| 4568 } |
| 4569 y = y.convertTo$3(this, x.type, yn); |
| 4570 if (kind == 0) { |
| 4571 x = captureOriginal(x); |
| 4572 return new Value(y.type, ('' + x.code + ' = ' + y.code), position.span, true
); |
| 4573 } |
| 4574 else if (x.type.get$isNum() && y.type.get$isNum() && (kind != 46/*TokenKind.TR
UNCDIV*/)) { |
| 4575 x = captureOriginal(x); |
| 4576 var op = TokenKind.kindToString(kind); |
| 4577 return new Value(y.type, ('' + x.code + ' ' + op + '= ' + y.code), position.
span, true); |
| 4578 } |
| 4579 else { |
| 4580 var right = x; |
| 4581 right = captureOriginal(right); |
| 4582 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 4583 return new Value(y.type, ('' + x.code + ' = ' + y.code), position.span, true
); |
| 4584 } |
| 4585 } |
| 4586 MethodGenerator.prototype._visitIndexAssign = function(kind, xn, yn, position, c
aptureOriginal, isVoid) { |
| 4587 var target = this.visitValue(xn.target); |
| 4588 var index = this.visitValue(xn.index); |
| 4589 var y = this.visitValue(yn); |
| 4590 var tmptarget = target; |
| 4591 var tmpindex = index; |
| 4592 if (kind != 0) { |
| 4593 tmptarget = this.getTemp(target); |
| 4594 tmpindex = this.getTemp(index); |
| 4595 index = this.assignTemp(tmpindex, index); |
| 4596 var right = tmptarget.invoke$4(this, ':index', position, new Arguments(null,
[tmpindex])); |
| 4597 right = captureOriginal(right); |
| 4598 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 4599 } |
| 4600 var tmpy = null; |
| 4601 if (!isVoid) { |
| 4602 tmpy = this.getTemp(y); |
| 4603 y = this.assignTemp(tmpy, y); |
| 4604 } |
| 4605 var ret = this.assignTemp(tmptarget, target).invoke(this, ':setindex', positio
n, new Arguments(null, [index, y]), false); |
| 4606 if (tmpy != null) { |
| 4607 ret = new Value(ret.type, ('(' + ret.code + ', ' + tmpy.code + ')'), ret.spa
n, true); |
| 4608 if ($ne(tmpy, y)) this.freeTemp(tmpy); |
| 4609 } |
| 4610 if ($ne(tmptarget, target)) this.freeTemp(tmptarget); |
| 4611 if ($ne(tmpindex, index)) this.freeTemp(tmpindex); |
| 4612 return ret; |
| 4613 } |
| 4614 MethodGenerator.prototype._visitDotAssign = function(kind, xn, yn, position, cap
tureOriginal) { |
| 4615 var target = xn.self.visit(this); |
| 4616 var y = this.visitValue(yn); |
| 4617 var tmptarget = target; |
| 4618 if (kind != 0) { |
| 4619 tmptarget = this.getTemp(target); |
| 4620 var right = tmptarget.get_$3(this, xn.name.name, xn.name); |
| 4621 right = captureOriginal(right); |
| 4622 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 4623 } |
| 4624 var ret = this.assignTemp(tmptarget, target).set_(this, xn.name.name, xn.name,
y, false); |
| 4625 if ($ne(tmptarget, target)) this.freeTemp(tmptarget); |
| 4626 return ret; |
| 4627 } |
| 4628 MethodGenerator.prototype.visitUnaryExpression = function(node) { |
| 4629 var value = this.visitValue(node.self); |
| 4630 switch (node.op.kind) { |
| 4631 case 16/*TokenKind.INCR*/: |
| 4632 case 17/*TokenKind.DECR*/: |
| 4633 |
| 4634 if (value.type.get$isNum()) { |
| 4635 return new Value(value.type, ('' + node.op + value.code), node.span, tru
e); |
| 4636 } |
| 4637 else { |
| 4638 var kind = (16/*TokenKind.INCR*/ == node.op.kind ? 42/*TokenKind.ADD*/ :
43/*TokenKind.SUB*/); |
| 4639 var operand = new LiteralExpression(1, new TypeReference(node.span, $glo
bals.world.numType), '1', node.span); |
| 4640 var assignValue = this._visitAssign(kind, node.self, operand, node, to$c
all$1(null), false); |
| 4641 return new Value(assignValue.type, ('(' + assignValue.code + ')'), node.
span, true); |
| 4642 } |
| 4643 |
| 4644 case 19/*TokenKind.NOT*/: |
| 4645 |
| 4646 if (value.type.get$isBool() && value.get$isConst()) { |
| 4647 var newVal = !value.get$actualValue(); |
| 4648 return EvaluatedValue.EvaluatedValue$factory(value.type, newVal, ('' + n
ewVal), node.span); |
| 4649 } |
| 4650 else { |
| 4651 var newVal = value.convertTo$3(this, $globals.world.nonNullBool, node); |
| 4652 return new Value(newVal.type, ('!' + newVal.code), node.span, true); |
| 4653 } |
| 4654 |
| 4655 case 42/*TokenKind.ADD*/: |
| 4656 |
| 4657 return value.convertTo$3(this, $globals.world.numType, node); |
| 4658 |
| 4659 case 43/*TokenKind.SUB*/: |
| 4660 case 18/*TokenKind.BIT_NOT*/: |
| 4661 |
| 4662 if (node.op.kind == 18/*TokenKind.BIT_NOT*/) { |
| 4663 return value.invoke$4(this, ':bit_not', node, Arguments.get$EMPTY()); |
| 4664 } |
| 4665 else if (node.op.kind == 43/*TokenKind.SUB*/) { |
| 4666 return value.invoke$4(this, ':negate', node, Arguments.get$EMPTY()); |
| 4667 } |
| 4668 else { |
| 4669 $globals.world.internalError(('unimplemented: unary ' + node.op), node.s
pan); |
| 4670 } |
| 4671 $throw(new FallThroughError()); |
| 4672 |
| 4673 default: |
| 4674 |
| 4675 $globals.world.internalError(('unimplemented: ' + node.op), node.span); |
| 4676 |
| 4677 } |
| 4678 } |
| 4679 MethodGenerator.prototype.visitAwaitExpression = function(node) { |
| 4680 $globals.world.internalError('Await expressions should have been eliminated be
fore code generation', node.span); |
| 4681 } |
| 4682 MethodGenerator.prototype.visitPostfixExpression = function(node, isVoid) { |
| 4683 var $this = this; // closure support |
| 4684 var value = this.visitValue(node.body); |
| 4685 if (value.type.get$isNum() && !value.get$isFinal()) { |
| 4686 return new Value(value.type, ('' + value.code + node.op), node.span, true); |
| 4687 } |
| 4688 var kind = (16/*TokenKind.INCR*/ == node.op.kind) ? 42/*TokenKind.ADD*/ : 43/*
TokenKind.SUB*/; |
| 4689 var operand = new LiteralExpression(1, new TypeReference(node.span, $globals.w
orld.numType), '1', node.span); |
| 4690 var tmpleft = null, left = null; |
| 4691 var ret = this._visitAssign(kind, node.body, operand, node, (function (l) { |
| 4692 if (isVoid) { |
| 4693 return l; |
| 4694 } |
| 4695 else { |
| 4696 left = l; |
| 4697 tmpleft = $this.forceTemp(l); |
| 4698 return $this.assignTemp(tmpleft, left); |
| 4699 } |
| 4700 }) |
| 4701 , false); |
| 4702 if (tmpleft != null) { |
| 4703 ret = new Value(ret.type, ("(" + ret.code + ", " + tmpleft.code + ")"), node
.span, true); |
| 4704 } |
| 4705 if ($ne(tmpleft, left)) { |
| 4706 this.freeTemp(tmpleft); |
| 4707 } |
| 4708 return ret; |
| 4709 } |
| 4710 MethodGenerator.prototype.visitNewExpression = function(node) { |
| 4711 var typeRef = node.type; |
| 4712 var constructorName = ''; |
| 4713 if (node.name != null) { |
| 4714 constructorName = node.name.name; |
| 4715 } |
| 4716 if ($eq(constructorName, '') && !(typeRef instanceof GenericTypeReference) &&
typeRef.get$names() != null) { |
| 4717 var names = ListFactory.ListFactory$from$factory(typeRef.get$names()); |
| 4718 constructorName = names.removeLast$0().name; |
| 4719 if ($eq(names.length, 0)) names = null; |
| 4720 typeRef = new NameTypeReference(typeRef.get$isFinal(), typeRef.name, names,
typeRef.span); |
| 4721 } |
| 4722 var type = this.method.resolveType(typeRef, true); |
| 4723 if (type.get$isTop()) { |
| 4724 type = type.get$library().findTypeByName$1(constructorName); |
| 4725 constructorName = ''; |
| 4726 } |
| 4727 if ((type instanceof ParameterType)) { |
| 4728 $globals.world.error('cannot instantiate a type parameter', node.span); |
| 4729 return this._makeMissingValue(constructorName); |
| 4730 } |
| 4731 var m = type.getConstructor$1(constructorName); |
| 4732 if (m == null) { |
| 4733 var name = type.get$jsname(); |
| 4734 if (type.get$isVar()) { |
| 4735 name = typeRef.name.name; |
| 4736 } |
| 4737 $globals.world.error(('no matching constructor for ' + name), node.span); |
| 4738 return this._makeMissingValue(name); |
| 4739 } |
| 4740 if (node.isConst) { |
| 4741 if (!m.get$isConst()) { |
| 4742 $globals.world.error('can\'t use const on a non-const constructor', node.s
pan); |
| 4743 } |
| 4744 var $$list = node.arguments; |
| 4745 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4746 var arg = $$list.$index($$i); |
| 4747 if (!this.visitValue(arg.value).get$isConst()) { |
| 4748 $globals.world.error('const constructor expects const arguments', arg.sp
an); |
| 4749 } |
| 4750 } |
| 4751 } |
| 4752 var target = new Value.type$ctor(type, typeRef.span); |
| 4753 return m.invoke$4(this, node, target, this._makeArgs(node.arguments)); |
| 4754 } |
| 4755 MethodGenerator.prototype.visitListExpression = function(node) { |
| 4756 var argsCode = []; |
| 4757 var argValues = []; |
| 4758 var type = null; |
| 4759 if (node.type != null) { |
| 4760 type = this.method.resolveType(node.type, true).get$typeArgsInOrder().$index
(0); |
| 4761 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara
ms())) { |
| 4762 $globals.world.error('type parameter cannot be used in const list literals
'); |
| 4763 } |
| 4764 } |
| 4765 var $$list = node.values; |
| 4766 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4767 var item = $$list.$index($$i); |
| 4768 var arg = this.visitTypedValue(item, type); |
| 4769 argValues.add$1(arg); |
| 4770 if (node.isConst) { |
| 4771 if (!arg.get$isConst()) { |
| 4772 $globals.world.error('const list can only contain const values', item.sp
an); |
| 4773 argsCode.add$1(arg.code); |
| 4774 } |
| 4775 else { |
| 4776 argsCode.add$1(arg.get$canonicalCode()); |
| 4777 } |
| 4778 } |
| 4779 else { |
| 4780 argsCode.add$1(arg.code); |
| 4781 } |
| 4782 } |
| 4783 $globals.world.get$coreimpl().types.$index('ListFactory').markUsed$0(); |
| 4784 var code = ('[' + Strings.join(argsCode, ", ") + ']'); |
| 4785 var value = new Value($globals.world.listType, code, node.span, true); |
| 4786 if (node.isConst) { |
| 4787 var immutableList = $globals.world.get$coreimpl().types.$index('ImmutableLis
t'); |
| 4788 var immutableListCtor = immutableList.getConstructor$1('from'); |
| 4789 var result = immutableListCtor.invoke$4(this, node, new Value.type$ctor(valu
e.type, node.span), new Arguments(null, [value])); |
| 4790 value = $globals.world.gen.globalForConst(ConstListValue.ConstListValue$fact
ory(immutableList, argValues, ('const ' + code), result.code, node.span), argVal
ues); |
| 4791 } |
| 4792 return value; |
| 4793 } |
| 4794 MethodGenerator.prototype.visitMapExpression = function(node) { |
| 4795 if (node.items.length == 0 && !node.isConst) { |
| 4796 return $globals.world.mapType.getConstructor('').invoke$4(this, node, new Va
lue.type$ctor($globals.world.mapType, node.span), Arguments.get$EMPTY()); |
| 4797 } |
| 4798 var argValues = []; |
| 4799 var argsCode = []; |
| 4800 var type = null; |
| 4801 if (node.type != null) { |
| 4802 type = this.method.resolveType(node.type, true).get$typeArgsInOrder().$index
(1); |
| 4803 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara
ms())) { |
| 4804 $globals.world.error('type parameter cannot be used in const map literals'
); |
| 4805 } |
| 4806 } |
| 4807 for (var i = 0; |
| 4808 i < node.items.length; i += 2) { |
| 4809 var key = this.visitTypedValue(node.items.$index(i), $globals.world.stringTy
pe); |
| 4810 var valueItem = node.items.$index(i + 1); |
| 4811 var value = this.visitTypedValue(valueItem, type); |
| 4812 argValues.add$1(key); |
| 4813 argValues.add$1(value); |
| 4814 if (node.isConst) { |
| 4815 if (!key.get$isConst() || !value.get$isConst()) { |
| 4816 $globals.world.error('const map can only contain const values', valueIte
m.span); |
| 4817 argsCode.add$1(key.code); |
| 4818 argsCode.add$1(value.code); |
| 4819 } |
| 4820 else { |
| 4821 argsCode.add$1(key.get$canonicalCode()); |
| 4822 argsCode.add$1(value.get$canonicalCode()); |
| 4823 } |
| 4824 } |
| 4825 else { |
| 4826 argsCode.add$1(key.code); |
| 4827 argsCode.add$1(value.code); |
| 4828 } |
| 4829 } |
| 4830 var argList = ('[' + Strings.join(argsCode, ", ") + ']'); |
| 4831 var items = new Value($globals.world.listType, argList, node.span, true); |
| 4832 var tp = $globals.world.corelib.topType; |
| 4833 var f = node.isConst ? tp.getMember$1('_constMap') : tp.getMember$1('_map'); |
| 4834 var value = f.invoke(this, node, new Value.type$ctor(tp, null), new Arguments(
null, [items]), false); |
| 4835 if (node.isConst) { |
| 4836 value = ConstMapValue.ConstMapValue$factory(value.type, argValues, value.cod
e, value.code, value.span); |
| 4837 return $globals.world.gen.globalForConst(value, argValues); |
| 4838 } |
| 4839 else { |
| 4840 return value; |
| 4841 } |
| 4842 } |
| 4843 MethodGenerator.prototype.visitConditionalExpression = function(node) { |
| 4844 var test = this.visitBool(node.test); |
| 4845 var trueBranch = this.visitValue(node.trueBranch); |
| 4846 var falseBranch = this.visitValue(node.falseBranch); |
| 4847 var code = ('' + test.code + ' ? ' + trueBranch.code + ' : ' + falseBranch.cod
e); |
| 4848 return new Value(Type.union(trueBranch.type, falseBranch.type), code, node.spa
n, true); |
| 4849 } |
| 4850 MethodGenerator.prototype.visitIsExpression = function(node) { |
| 4851 var value = this.visitValue(node.x); |
| 4852 var type = this.method.resolveType(node.type, false); |
| 4853 return value.instanceOf$4(this, type, node.span, node.isTrue); |
| 4854 } |
| 4855 MethodGenerator.prototype.visitParenExpression = function(node) { |
| 4856 var body = this.visitValue(node.body); |
| 4857 if (body.get$isConst()) { |
| 4858 return EvaluatedValue.EvaluatedValue$factory(body.type, body.get$actualValue
(), ('(' + body.get$canonicalCode() + ')'), node.span); |
| 4859 } |
| 4860 return new Value(body.type, ('(' + body.code + ')'), node.span, true); |
| 4861 } |
| 4862 MethodGenerator.prototype.visitDotExpression = function(node) { |
| 4863 var target = node.self.visit(this); |
| 4864 return target.get_$3(this, node.name.name, node.name); |
| 4865 } |
| 4866 MethodGenerator.prototype.visitVarExpression = function(node) { |
| 4867 var name = node.name.name; |
| 4868 var ret = this._scope.lookup(name); |
| 4869 if (ret != null) return ret; |
| 4870 return this._makeThisOrType(node.span).get_$3(this, name, node); |
| 4871 } |
| 4872 MethodGenerator.prototype._makeMissingValue = function(name) { |
| 4873 return new Value($globals.world.varType, ('' + name + '()/*NotFound*/'), null,
true); |
| 4874 } |
| 4875 MethodGenerator.prototype._makeThisOrType = function(span) { |
| 4876 return new BareValue(this, this._getOutermostMethod(), span); |
| 4877 } |
| 4878 MethodGenerator.prototype.visitThisExpression = function(node) { |
| 4879 return this._makeThisValue(node); |
| 4880 } |
| 4881 MethodGenerator.prototype.visitSuperExpression = function(node) { |
| 4882 return this._makeSuperValue(node); |
| 4883 } |
| 4884 MethodGenerator.prototype.visitNullExpression = function(node) { |
| 4885 return EvaluatedValue.EvaluatedValue$factory($globals.world.varType, null, 'nu
ll', null); |
| 4886 } |
| 4887 MethodGenerator.prototype._isUnaryIncrement = function(item) { |
| 4888 if ((item instanceof UnaryExpression)) { |
| 4889 var u = item; |
| 4890 return u.op.kind == 16/*TokenKind.INCR*/ || u.op.kind == 17/*TokenKind.DECR*
/; |
| 4891 } |
| 4892 else { |
| 4893 return false; |
| 4894 } |
| 4895 } |
| 4896 MethodGenerator.prototype.visitLiteralExpression = function(node) { |
| 4897 var $0; |
| 4898 var type = node.type.type; |
| 4899 if (!!(($0 = node.value) && $0.is$List())) { |
| 4900 var items = []; |
| 4901 var $$list = node.value; |
| 4902 for (var $$i = node.value.iterator$0(); $$i.hasNext$0(); ) { |
| 4903 var item = $$i.next$0(); |
| 4904 var val = this.visitValue(item); |
| 4905 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY()); |
| 4906 var code = val.code; |
| 4907 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr
ession) || (item instanceof PostfixExpression) || this._isUnaryIncrement(item))
{ |
| 4908 code = ('(' + code + ')'); |
| 4909 } |
| 4910 if ($eq(items.length, 0) || ($ne(code, "''") && $ne(code, '""'))) { |
| 4911 items.add$1(code); |
| 4912 } |
| 4913 } |
| 4914 return new Value(type, ('(' + Strings.join(items, " + ") + ')'), node.span,
true); |
| 4915 } |
| 4916 var text = node.text; |
| 4917 if (type.get$isString()) { |
| 4918 if (text.startsWith$1('@')) { |
| 4919 text = MethodGenerator._escapeString(parseStringLiteral(text)); |
| 4920 text = ('"' + text + '"'); |
| 4921 } |
| 4922 else if (isMultilineString(text)) { |
| 4923 text = parseStringLiteral(text); |
| 4924 text = text.replaceAll$2('\n', '\\n'); |
| 4925 text = toDoubleQuote(text); |
| 4926 text = ('"' + text + '"'); |
| 4927 } |
| 4928 if (text !== node.text) { |
| 4929 node.value = text; |
| 4930 node.text = text; |
| 4931 } |
| 4932 } |
| 4933 return EvaluatedValue.EvaluatedValue$factory(type, node.value, node.text, null
); |
| 4934 } |
| 4935 MethodGenerator.prototype._checkNonStatic$1 = MethodGenerator.prototype._checkNo
nStatic; |
| 4936 MethodGenerator.prototype.visitBinaryExpression$1 = function($0) { |
| 4937 return this.visitBinaryExpression($0, false); |
| 4938 }; |
| 4939 MethodGenerator.prototype.visitPostfixExpression$1 = function($0) { |
| 4940 return this.visitPostfixExpression($0, false); |
| 4941 }; |
| 4942 MethodGenerator.prototype.writeDefinition$2 = MethodGenerator.prototype.writeDef
inition; |
| 4943 // ********** Code for Arguments ************** |
| 4944 function Arguments(nodes, values) { |
| 4945 this.nodes = nodes; |
| 4946 this.values = values; |
| 4947 // Initializers done |
| 4948 } |
| 4949 Arguments.Arguments$bare$factory = function(arity) { |
| 4950 var values = []; |
| 4951 for (var i = 0; |
| 4952 i < arity; i++) { |
| 4953 values.add$1(new Value($globals.world.varType, ('\$' + i), null, false)); |
| 4954 } |
| 4955 return new Arguments(null, values); |
| 4956 } |
| 4957 Arguments.get$EMPTY = function() { |
| 4958 if ($globals.Arguments__empty == null) { |
| 4959 $globals.Arguments__empty = new Arguments(null, []); |
| 4960 } |
| 4961 return $globals.Arguments__empty; |
| 4962 } |
| 4963 Arguments.prototype.get$nameCount = function() { |
| 4964 return this.get$length() - this.get$bareCount(); |
| 4965 } |
| 4966 Arguments.prototype.get$hasNames = function() { |
| 4967 return this.get$bareCount() < this.get$length(); |
| 4968 } |
| 4969 Arguments.prototype.get$length = function() { |
| 4970 return this.values.length; |
| 4971 } |
| 4972 Object.defineProperty(Arguments.prototype, "length", { |
| 4973 get: Arguments.prototype.get$length |
| 4974 }); |
| 4975 Arguments.prototype.getName = function(i) { |
| 4976 return this.nodes.$index(i).label.name; |
| 4977 } |
| 4978 Arguments.prototype.getIndexOfName = function(name) { |
| 4979 for (var i = this.get$bareCount(); |
| 4980 i < this.get$length(); i++) { |
| 4981 if (this.getName(i) == name) { |
| 4982 return i; |
| 4983 } |
| 4984 } |
| 4985 return -1; |
| 4986 } |
| 4987 Arguments.prototype.getValue = function(name) { |
| 4988 var i = this.getIndexOfName(name); |
| 4989 return i >= 0 ? this.values.$index(i) : null; |
| 4990 } |
| 4991 Arguments.prototype.get$bareCount = function() { |
| 4992 if (this._bareCount == null) { |
| 4993 this._bareCount = this.get$length(); |
| 4994 if (this.nodes != null) { |
| 4995 for (var i = 0; |
| 4996 i < this.nodes.length; i++) { |
| 4997 if (this.nodes.$index(i).label != null) { |
| 4998 this._bareCount = i; |
| 4999 break; |
| 5000 } |
| 5001 } |
| 5002 } |
| 5003 } |
| 5004 return this._bareCount; |
| 5005 } |
| 5006 Arguments.prototype.getCode = function() { |
| 5007 var argsCode = []; |
| 5008 for (var i = 0; |
| 5009 i < this.get$length(); i++) { |
| 5010 argsCode.add$1(this.values.$index(i).code); |
| 5011 } |
| 5012 Arguments.removeTrailingNulls(argsCode); |
| 5013 return Strings.join(argsCode, ", "); |
| 5014 } |
| 5015 Arguments.removeTrailingNulls = function(argsCode) { |
| 5016 while (argsCode.length > 0 && $eq(argsCode.last(), 'null')) { |
| 5017 argsCode.removeLast(); |
| 5018 } |
| 5019 } |
| 5020 Arguments.prototype.getNames = function() { |
| 5021 var names = []; |
| 5022 for (var i = this.get$bareCount(); |
| 5023 i < this.get$length(); i++) { |
| 5024 names.add$1(this.getName(i)); |
| 5025 } |
| 5026 return names; |
| 5027 } |
| 5028 Arguments.prototype.toCallStubArgs = function() { |
| 5029 var result = []; |
| 5030 for (var i = 0; |
| 5031 i < this.get$bareCount(); i++) { |
| 5032 result.add$1(new Value($globals.world.varType, ('\$' + i), null, false)); |
| 5033 } |
| 5034 for (var i = this.get$bareCount(); |
| 5035 i < this.get$length(); i++) { |
| 5036 var name = this.getName(i); |
| 5037 if (name == null) name = ('\$' + i); |
| 5038 result.add$1(new Value($globals.world.varType, name, null, false)); |
| 5039 } |
| 5040 return new Arguments(this.nodes, result); |
| 5041 } |
| 5042 // ********** Code for LibraryImport ************** |
| 5043 function LibraryImport(library, prefix) { |
| 5044 this.library = library; |
| 5045 this.prefix = prefix; |
| 5046 // Initializers done |
| 5047 } |
| 5048 LibraryImport.prototype.get$library = function() { return this.library; }; |
| 5049 LibraryImport.prototype.set$library = function(value) { return this.library = va
lue; }; |
| 5050 // ********** Code for Library ************** |
| 5051 $inherits(Library, lang_Element); |
| 5052 function Library(baseSource) { |
| 5053 this.isWritten = false |
| 5054 this.isMarked = false |
| 5055 this.baseSource = baseSource; |
| 5056 // Initializers done |
| 5057 lang_Element.call(this, null, null); |
| 5058 this.sourceDir = dirname(this.baseSource.filename); |
| 5059 this.topType = new DefinedType(null, this, null, true); |
| 5060 this.types = _map(['', this.topType]); |
| 5061 this.imports = []; |
| 5062 this.natives = []; |
| 5063 this.sources = []; |
| 5064 this._privateMembers = new HashMapImplementation(); |
| 5065 } |
| 5066 Library.prototype.get$baseSource = function() { return this.baseSource; }; |
| 5067 Library.prototype.get$_privateMembers = function() { return this._privateMembers
; }; |
| 5068 Library.prototype.set$_privateMembers = function(value) { return this._privateMe
mbers = value; }; |
| 5069 Library.prototype.get$topType = function() { return this.topType; }; |
| 5070 Library.prototype.set$topType = function(value) { return this.topType = value; }
; |
| 5071 Library.prototype.get$enclosingElement = function() { |
| 5072 return null; |
| 5073 } |
| 5074 Library.prototype.get$library = function() { |
| 5075 return this; |
| 5076 } |
| 5077 Library.prototype.get$isNative = function() { |
| 5078 return this.topType.isNative; |
| 5079 } |
| 5080 Library.prototype.get$isCore = function() { |
| 5081 return $eq(this, $globals.world.corelib); |
| 5082 } |
| 5083 Library.prototype.get$isCoreImpl = function() { |
| 5084 return $eq(this, $globals.world.get$coreimpl()); |
| 5085 } |
| 5086 Library.prototype.get$span = function() { |
| 5087 return new SourceSpan(this.baseSource, 0, 0); |
| 5088 } |
| 5089 Object.defineProperty(Library.prototype, "span", { |
| 5090 get: Library.prototype.get$span |
| 5091 }); |
| 5092 Library.prototype.makeFullPath = function(filename) { |
| 5093 if (filename.startsWith('dart:')) return filename; |
| 5094 if (filename.startsWith('/')) return filename; |
| 5095 if (filename.startsWith('file:///')) return filename; |
| 5096 if (filename.startsWith('http://')) return filename; |
| 5097 return joinPaths(this.sourceDir, filename); |
| 5098 } |
| 5099 Library.prototype.addImport = function(fullname, prefix) { |
| 5100 var newLib = $globals.world.getOrAddLibrary(fullname); |
| 5101 this.imports.add(new LibraryImport(newLib, prefix)); |
| 5102 return newLib; |
| 5103 } |
| 5104 Library.prototype.addNative = function(fullname) { |
| 5105 this.natives.add($globals.world.reader.readFile(fullname)); |
| 5106 } |
| 5107 Library.prototype._findMembers = function(name) { |
| 5108 if (name.startsWith('_')) { |
| 5109 return this._privateMembers.$index(name); |
| 5110 } |
| 5111 else { |
| 5112 return $globals.world._members.$index(name); |
| 5113 } |
| 5114 } |
| 5115 Library.prototype._addMember = function(member) { |
| 5116 if (member.get$isPrivate()) { |
| 5117 if (member.get$isStatic()) { |
| 5118 if (member.declaringType.get$isTop()) { |
| 5119 $globals.world._addTopName(member); |
| 5120 } |
| 5121 return; |
| 5122 } |
| 5123 var mset = this._privateMembers.$index(member.name); |
| 5124 if (mset == null) { |
| 5125 var $$list = $globals.world.libraries.getValues(); |
| 5126 for (var $$i = $globals.world.libraries.getValues().iterator$0(); $$i.hasN
ext$0(); ) { |
| 5127 var lib = $$i.next$0(); |
| 5128 if (lib.get$_privateMembers().containsKey$1(member.get$jsname())) { |
| 5129 member._jsname = ('_' + this.get$jsname() + member.get$jsname()); |
| 5130 break; |
| 5131 } |
| 5132 } |
| 5133 mset = new MemberSet(member, true); |
| 5134 this._privateMembers.$setindex(member.name, mset); |
| 5135 } |
| 5136 else { |
| 5137 mset.get$members().add$1(member); |
| 5138 } |
| 5139 } |
| 5140 else { |
| 5141 $globals.world._addMember(member); |
| 5142 } |
| 5143 } |
| 5144 Library.prototype.getOrAddFunctionType = function(enclosingElement, name, func)
{ |
| 5145 var def = new FunctionTypeDefinition(func, null, func.span); |
| 5146 var type = new DefinedType(name, this, def, false); |
| 5147 type.addMethod(':call', func); |
| 5148 var m = type.members.$index(':call'); |
| 5149 m.set$enclosingElement(enclosingElement); |
| 5150 m.resolve$0(); |
| 5151 type.interfaces = [$globals.world.functionType]; |
| 5152 return type; |
| 5153 } |
| 5154 Library.prototype.addType = function(name, definition, isClass) { |
| 5155 if (this.types.containsKey(name)) { |
| 5156 var existingType = this.types.$index(name); |
| 5157 if (this.get$isCore() && existingType.get$definition() == null) { |
| 5158 existingType.setDefinition$1(definition); |
| 5159 } |
| 5160 else { |
| 5161 $globals.world.warning(('duplicate definition of ' + name), definition.spa
n, existingType.span); |
| 5162 } |
| 5163 } |
| 5164 else { |
| 5165 this.types.$setindex(name, new DefinedType(name, this, definition, isClass))
; |
| 5166 } |
| 5167 return this.types.$index(name); |
| 5168 } |
| 5169 Library.prototype.findType = function(type) { |
| 5170 var result = this.findTypeByName(type.name.name); |
| 5171 if (result == null) return null; |
| 5172 if (type.names != null) { |
| 5173 if (type.names.length > 1) { |
| 5174 return null; |
| 5175 } |
| 5176 if (!result.get$isTop()) { |
| 5177 return null; |
| 5178 } |
| 5179 return result.get$library().findTypeByName(type.names.$index(0).name); |
| 5180 } |
| 5181 return result; |
| 5182 } |
| 5183 Library.prototype.findTypeByName = function(name) { |
| 5184 var ret = this.types.$index(name); |
| 5185 var $$list = this.imports; |
| 5186 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5187 var imported = $$list.$index($$i); |
| 5188 var newRet = null; |
| 5189 if (imported.prefix == null) { |
| 5190 newRet = imported.get$library().types.$index(name); |
| 5191 } |
| 5192 else if ($eq(imported.prefix, name)) { |
| 5193 newRet = imported.get$library().get$topType(); |
| 5194 } |
| 5195 if (newRet != null) { |
| 5196 if (ret != null && $ne(ret, newRet)) { |
| 5197 $globals.world.error(('conflicting types for "' + name + '"'), ret.span,
newRet.span); |
| 5198 } |
| 5199 else { |
| 5200 ret = newRet; |
| 5201 } |
| 5202 } |
| 5203 } |
| 5204 return ret; |
| 5205 } |
| 5206 Library.prototype.resolveType = function(node, typeErrors) { |
| 5207 if (node == null) return $globals.world.varType; |
| 5208 if (node.type != null) return node.type; |
| 5209 node.type = this.findType(node); |
| 5210 if (node.type == null) { |
| 5211 var message = ('cannot find type ' + Library._getDottedName(node)); |
| 5212 if (typeErrors) { |
| 5213 $globals.world.error(message, node.span); |
| 5214 node.type = $globals.world.objectType; |
| 5215 } |
| 5216 else { |
| 5217 $globals.world.warning(message, node.span); |
| 5218 node.type = $globals.world.varType; |
| 5219 } |
| 5220 } |
| 5221 return node.type; |
| 5222 } |
| 5223 Library._getDottedName = function(type) { |
| 5224 if (type.names != null) { |
| 5225 var names = map(type.names, (function (n) { |
| 5226 return n.name; |
| 5227 }) |
| 5228 ); |
| 5229 return type.name.name + '.' + Strings.join(names, '.'); |
| 5230 } |
| 5231 else { |
| 5232 return type.name.name; |
| 5233 } |
| 5234 } |
| 5235 Library.prototype.lookup = function(name, span) { |
| 5236 var retType = this.findTypeByName(name); |
| 5237 var ret = null; |
| 5238 if (retType != null) { |
| 5239 ret = retType.get$typeMember(); |
| 5240 } |
| 5241 var newRet = this.topType.getMember(name); |
| 5242 if (newRet != null) { |
| 5243 if (ret != null && $ne(ret, newRet)) { |
| 5244 $globals.world.error(('conflicting members for "' + name + '"'), span, ret
.span, newRet.span); |
| 5245 } |
| 5246 else { |
| 5247 ret = newRet; |
| 5248 } |
| 5249 } |
| 5250 var $$list = this.imports; |
| 5251 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5252 var imported = $$list.$index($$i); |
| 5253 if (imported.prefix == null) { |
| 5254 newRet = imported.get$library().get$topType().getMember$1(name); |
| 5255 if (newRet != null) { |
| 5256 if (ret != null && $ne(ret, newRet)) { |
| 5257 $globals.world.error(('conflicting members for "' + name + '"'), span,
ret.span, newRet.span); |
| 5258 } |
| 5259 else { |
| 5260 ret = newRet; |
| 5261 } |
| 5262 } |
| 5263 } |
| 5264 } |
| 5265 return ret; |
| 5266 } |
| 5267 Library.prototype.resolve = function() { |
| 5268 if (this.name == null) { |
| 5269 this.name = this.baseSource.filename; |
| 5270 var index = this.name.lastIndexOf('/', this.name.length); |
| 5271 if (index >= 0) { |
| 5272 this.name = this.name.substring(index + 1); |
| 5273 } |
| 5274 index = this.name.indexOf('.'); |
| 5275 if (index > 0) { |
| 5276 this.name = this.name.substring(0, index); |
| 5277 } |
| 5278 } |
| 5279 this._jsname = this.name.replaceAll('.', '_').replaceAll(':', '_').replaceAll(
' ', '_'); |
| 5280 var $$list = this.types.getValues(); |
| 5281 for (var $$i = this.types.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 5282 var type = $$i.next$0(); |
| 5283 type.resolve$0(); |
| 5284 } |
| 5285 } |
| 5286 Library.prototype.visitSources = function() { |
| 5287 var visitor = new _LibraryVisitor(this); |
| 5288 visitor.addSource$1(this.baseSource); |
| 5289 } |
| 5290 Library.prototype.toString = function() { |
| 5291 return this.baseSource.filename; |
| 5292 } |
| 5293 Library.prototype.hashCode = function() { |
| 5294 return this.baseSource.filename.hashCode(); |
| 5295 } |
| 5296 Library.prototype.$eq = function(other) { |
| 5297 return (other instanceof Library) && $eq(other.get$baseSource().filename, this
.baseSource.filename); |
| 5298 } |
| 5299 Library.prototype.findTypeByName$1 = Library.prototype.findTypeByName; |
| 5300 Library.prototype.hashCode$0 = Library.prototype.hashCode; |
| 5301 Library.prototype.resolve$0 = Library.prototype.resolve; |
| 5302 Library.prototype.toString$0 = Library.prototype.toString; |
| 5303 Library.prototype.visitSources$0 = Library.prototype.visitSources; |
| 5304 // ********** Code for _LibraryVisitor ************** |
| 5305 function _LibraryVisitor(library) { |
| 5306 this.seenImport = false |
| 5307 this.seenSource = false |
| 5308 this.seenResource = false |
| 5309 this.isTop = true |
| 5310 this.library = library; |
| 5311 // Initializers done |
| 5312 this.currentType = this.library.topType; |
| 5313 this.sources = []; |
| 5314 } |
| 5315 _LibraryVisitor.prototype.get$library = function() { return this.library; }; |
| 5316 _LibraryVisitor.prototype.get$isTop = function() { return this.isTop; }; |
| 5317 _LibraryVisitor.prototype.set$isTop = function(value) { return this.isTop = valu
e; }; |
| 5318 _LibraryVisitor.prototype.addSourceFromName = function(name, span) { |
| 5319 var filename = this.library.makeFullPath(name); |
| 5320 if ($eq(filename, this.library.baseSource.filename)) { |
| 5321 $globals.world.error('library can not source itself', span); |
| 5322 return; |
| 5323 } |
| 5324 else if (this.sources.some((function (s) { |
| 5325 return $eq(s.filename, filename); |
| 5326 }) |
| 5327 )) { |
| 5328 $globals.world.error(('file "' + filename + '" has already been sourced'), s
pan); |
| 5329 return; |
| 5330 } |
| 5331 var source = $globals.world.readFile(this.library.makeFullPath(name)); |
| 5332 this.sources.add(source); |
| 5333 } |
| 5334 _LibraryVisitor.prototype.addSource = function(source) { |
| 5335 var $this = this; // closure support |
| 5336 if (this.library.sources.some((function (s) { |
| 5337 return $eq(s.filename, source.filename); |
| 5338 }) |
| 5339 )) { |
| 5340 $globals.world.error(('duplicate source file "' + source.filename + '"')); |
| 5341 return; |
| 5342 } |
| 5343 this.library.sources.add(source); |
| 5344 var parser = new Parser(source, $globals.options.dietParse, false, false, 0); |
| 5345 var unit = parser.compilationUnit(); |
| 5346 unit.forEach((function (def) { |
| 5347 return def.visit$1($this); |
| 5348 }) |
| 5349 ); |
| 5350 this.isTop = false; |
| 5351 var newSources = this.sources; |
| 5352 this.sources = []; |
| 5353 for (var $$i = newSources.iterator$0(); $$i.hasNext$0(); ) { |
| 5354 var source0 = $$i.next$0(); |
| 5355 this.addSource(source0); |
| 5356 } |
| 5357 } |
| 5358 _LibraryVisitor.prototype.visitDirectiveDefinition = function(node) { |
| 5359 if (!this.isTop) { |
| 5360 $globals.world.error('directives not allowed in sourced file', node.span); |
| 5361 return; |
| 5362 } |
| 5363 var name; |
| 5364 switch (node.name.name) { |
| 5365 case "library": |
| 5366 |
| 5367 name = this.getSingleStringArg(node); |
| 5368 if (this.library.name == null) { |
| 5369 this.library.name = name; |
| 5370 if ($eq(name, 'node') || $eq(name, 'dom')) { |
| 5371 this.library.topType.isNative = true; |
| 5372 } |
| 5373 if (this.seenImport || this.seenSource || this.seenResource) { |
| 5374 $globals.world.error('#library must be first directive in file', node.
span); |
| 5375 } |
| 5376 } |
| 5377 else { |
| 5378 $globals.world.error('already specified library name', node.span); |
| 5379 } |
| 5380 break; |
| 5381 |
| 5382 case "import": |
| 5383 |
| 5384 this.seenImport = true; |
| 5385 name = this.getFirstStringArg(node); |
| 5386 var prefix = this.tryGetNamedStringArg(node, 'prefix'); |
| 5387 if (node.arguments.length > 2 || node.arguments.length == 2 && prefix == n
ull) { |
| 5388 $globals.world.error('expected at most one "name" argument and one optio
nal "prefix"' + (' but found ' + node.arguments.length), node.span); |
| 5389 } |
| 5390 else if (prefix != null && prefix.indexOf$1('.') >= 0) { |
| 5391 $globals.world.error('library prefix canot contain "."', node.span); |
| 5392 } |
| 5393 else if (this.seenSource || this.seenResource) { |
| 5394 $globals.world.error('#imports must come before any #source or #resource
', node.span); |
| 5395 } |
| 5396 if ($eq(prefix, '')) prefix = null; |
| 5397 var filename = this.library.makeFullPath(name); |
| 5398 if (this.library.imports.some((function (li) { |
| 5399 return $eq(li.get$library().get$baseSource(), filename); |
| 5400 }) |
| 5401 )) { |
| 5402 $globals.world.error(('duplicate import of "' + name + '"'), node.span); |
| 5403 return; |
| 5404 } |
| 5405 var newLib = this.library.addImport(filename, prefix); |
| 5406 break; |
| 5407 |
| 5408 case "source": |
| 5409 |
| 5410 this.seenSource = true; |
| 5411 name = this.getSingleStringArg(node); |
| 5412 this.addSourceFromName(name, node.span); |
| 5413 if (this.seenResource) { |
| 5414 $globals.world.error('#sources must come before any #resource', node.spa
n); |
| 5415 } |
| 5416 break; |
| 5417 |
| 5418 case "native": |
| 5419 |
| 5420 name = this.getSingleStringArg(node); |
| 5421 this.library.addNative(this.library.makeFullPath(name)); |
| 5422 break; |
| 5423 |
| 5424 case "resource": |
| 5425 |
| 5426 this.seenResource = true; |
| 5427 this.getFirstStringArg(node); |
| 5428 break; |
| 5429 |
| 5430 default: |
| 5431 |
| 5432 $globals.world.error(('unknown directive: ' + node.name.name), node.span); |
| 5433 |
| 5434 } |
| 5435 } |
| 5436 _LibraryVisitor.prototype.getSingleStringArg = function(node) { |
| 5437 if (node.arguments.length != 1) { |
| 5438 $globals.world.error(('expected exactly one argument but found ' + node.argu
ments.length), node.span); |
| 5439 } |
| 5440 return this.getFirstStringArg(node); |
| 5441 } |
| 5442 _LibraryVisitor.prototype.getFirstStringArg = function(node) { |
| 5443 if (node.arguments.length < 1) { |
| 5444 $globals.world.error(('expected at least one argument but found ' + node.arg
uments.length), node.span); |
| 5445 } |
| 5446 var arg = node.arguments.$index(0); |
| 5447 if (arg.label != null) { |
| 5448 $globals.world.error('label not allowed for directive', node.span); |
| 5449 } |
| 5450 return this._parseStringArgument(arg); |
| 5451 } |
| 5452 _LibraryVisitor.prototype.tryGetNamedStringArg = function(node, argName) { |
| 5453 var args = node.arguments.filter((function (a) { |
| 5454 return a.label != null && $eq(a.label.name, argName); |
| 5455 }) |
| 5456 ); |
| 5457 if ($eq(args.length, 0)) { |
| 5458 return null; |
| 5459 } |
| 5460 if (args.length > 1) { |
| 5461 $globals.world.error(('expected at most one "' + argName + '" argument but f
ound ') + node.arguments.length, node.span); |
| 5462 } |
| 5463 for (var $$i = args.iterator$0(); $$i.hasNext$0(); ) { |
| 5464 var arg = $$i.next$0(); |
| 5465 return this._parseStringArgument(arg); |
| 5466 } |
| 5467 } |
| 5468 _LibraryVisitor.prototype._parseStringArgument = function(arg) { |
| 5469 var expr = arg.value; |
| 5470 if (!(expr instanceof LiteralExpression) || !expr.type.type.get$isString()) { |
| 5471 $globals.world.error('expected string', expr.span); |
| 5472 } |
| 5473 return parseStringLiteral(expr.value); |
| 5474 } |
| 5475 _LibraryVisitor.prototype.visitTypeDefinition = function(node) { |
| 5476 var oldType = this.currentType; |
| 5477 this.currentType = this.library.addType(node.name.name, node, node.isClass); |
| 5478 var $$list = node.body; |
| 5479 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5480 var member = $$list.$index($$i); |
| 5481 member.visit$1(this); |
| 5482 } |
| 5483 this.currentType = oldType; |
| 5484 } |
| 5485 _LibraryVisitor.prototype.visitVariableDefinition = function(node) { |
| 5486 this.currentType.addField(node); |
| 5487 } |
| 5488 _LibraryVisitor.prototype.visitFunctionDefinition = function(node) { |
| 5489 this.currentType.addMethod(node.name.name, node); |
| 5490 } |
| 5491 _LibraryVisitor.prototype.visitFunctionTypeDefinition = function(node) { |
| 5492 var type = this.library.addType(node.func.name.name, node, false); |
| 5493 type.addMethod$2(':call', node.func); |
| 5494 } |
| 5495 _LibraryVisitor.prototype.addSource$1 = _LibraryVisitor.prototype.addSource; |
| 5496 // ********** Code for Parameter ************** |
| 5497 function Parameter(definition, method) { |
| 5498 this.isInitializer = false |
| 5499 this.definition = definition; |
| 5500 this.method = method; |
| 5501 // Initializers done |
| 5502 } |
| 5503 Parameter.prototype.get$definition = function() { return this.definition; }; |
| 5504 Parameter.prototype.set$definition = function(value) { return this.definition =
value; }; |
| 5505 Parameter.prototype.get$isInitializer = function() { return this.isInitializer;
}; |
| 5506 Parameter.prototype.set$isInitializer = function(value) { return this.isInitiali
zer = value; }; |
| 5507 Parameter.prototype.resolve = function() { |
| 5508 this.name = this.definition.name.name; |
| 5509 if (this.name.startsWith('this.')) { |
| 5510 this.name = this.name.substring(5); |
| 5511 this.isInitializer = true; |
| 5512 } |
| 5513 this.type = this.method.resolveType(this.definition.type, false); |
| 5514 if (this.definition.value != null) { |
| 5515 if (!this.get$hasDefaultValue()) return; |
| 5516 if (this.method.name == ':call') { |
| 5517 if (this.method.get$definition().body == null) { |
| 5518 $globals.world.error('default value not allowed on function type', this.
definition.span); |
| 5519 } |
| 5520 } |
| 5521 else if (this.method.get$isAbstract()) { |
| 5522 $globals.world.error('default value not allowed on abstract methods', this
.definition.span); |
| 5523 } |
| 5524 } |
| 5525 else if (this.isInitializer && !this.method.get$isConstructor()) { |
| 5526 $globals.world.error('initializer parameters only allowed on constructors',
this.definition.span); |
| 5527 } |
| 5528 } |
| 5529 Parameter.prototype.genValue = function(method, context) { |
| 5530 if (this.definition.value == null || this.value != null) return; |
| 5531 if (context == null) { |
| 5532 context = new MethodGenerator(method, null); |
| 5533 } |
| 5534 this.value = this.definition.value.visit(context); |
| 5535 if (!this.value.get$isConst()) { |
| 5536 $globals.world.error('default parameter values must be constant', this.value
.span); |
| 5537 } |
| 5538 this.value = this.value.convertTo(context, this.type, this.definition.value, f
alse); |
| 5539 } |
| 5540 Parameter.prototype.copyWithNewType = function(newMethod, newType) { |
| 5541 var ret = new Parameter(this.definition, newMethod); |
| 5542 ret.type = newType; |
| 5543 ret.name = this.name; |
| 5544 ret.set$isInitializer(this.isInitializer); |
| 5545 return ret; |
| 5546 } |
| 5547 Parameter.prototype.get$isOptional = function() { |
| 5548 return this.definition != null && this.definition.value != null; |
| 5549 } |
| 5550 Parameter.prototype.get$hasDefaultValue = function() { |
| 5551 return !(this.definition.value instanceof NullExpression) || (this.definition.
value.span.start != this.definition.span.start); |
| 5552 } |
| 5553 Parameter.prototype.copyWithNewType$2 = Parameter.prototype.copyWithNewType; |
| 5554 Parameter.prototype.genValue$2 = Parameter.prototype.genValue; |
| 5555 Parameter.prototype.resolve$0 = Parameter.prototype.resolve; |
| 5556 // ********** Code for Member ************** |
| 5557 $inherits(Member, lang_Element); |
| 5558 function Member(name, declaringType) { |
| 5559 this.isGenerated = false; |
| 5560 this.declaringType = declaringType; |
| 5561 // Initializers done |
| 5562 lang_Element.call(this, name, declaringType); |
| 5563 } |
| 5564 Member.prototype.get$declaringType = function() { return this.declaringType; }; |
| 5565 Member.prototype.get$generator = function() { return this.generator; }; |
| 5566 Member.prototype.set$generator = function(value) { return this.generator = value
; }; |
| 5567 Member.prototype.get$library = function() { |
| 5568 return this.declaringType.get$library(); |
| 5569 } |
| 5570 Member.prototype.get$isPrivate = function() { |
| 5571 return this.name.startsWith('_'); |
| 5572 } |
| 5573 Member.prototype.get$isConstructor = function() { |
| 5574 return false; |
| 5575 } |
| 5576 Member.prototype.get$isField = function() { |
| 5577 return false; |
| 5578 } |
| 5579 Member.prototype.get$isMethod = function() { |
| 5580 return false; |
| 5581 } |
| 5582 Member.prototype.get$isProperty = function() { |
| 5583 return false; |
| 5584 } |
| 5585 Member.prototype.get$isAbstract = function() { |
| 5586 return false; |
| 5587 } |
| 5588 Member.prototype.get$isFinal = function() { |
| 5589 return false; |
| 5590 } |
| 5591 Member.prototype.get$isConst = function() { |
| 5592 return false; |
| 5593 } |
| 5594 Member.prototype.get$isFactory = function() { |
| 5595 return false; |
| 5596 } |
| 5597 Member.prototype.get$isOperator = function() { |
| 5598 return this.name.startsWith(':'); |
| 5599 } |
| 5600 Member.prototype.get$isCallMethod = function() { |
| 5601 return this.name == ':call'; |
| 5602 } |
| 5603 Member.prototype.get$prefersPropertySyntax = function() { |
| 5604 return true; |
| 5605 } |
| 5606 Member.prototype.get$requiresFieldSyntax = function() { |
| 5607 return false; |
| 5608 } |
| 5609 Member.prototype.get$isNative = function() { |
| 5610 return false; |
| 5611 } |
| 5612 Member.prototype.get$constructorName = function() { |
| 5613 $globals.world.internalError('can not be a constructor', this.get$span()); |
| 5614 } |
| 5615 Member.prototype.provideFieldSyntax = function() { |
| 5616 |
| 5617 } |
| 5618 Member.prototype.providePropertySyntax = function() { |
| 5619 |
| 5620 } |
| 5621 Member.prototype.get$initDelegate = function() { |
| 5622 $globals.world.internalError('cannot have initializers', this.get$span()); |
| 5623 } |
| 5624 Member.prototype.set$initDelegate = function(ctor) { |
| 5625 $globals.world.internalError('cannot have initializers', this.get$span()); |
| 5626 } |
| 5627 Member.prototype.computeValue = function() { |
| 5628 $globals.world.internalError('cannot have value', this.get$span()); |
| 5629 } |
| 5630 Member.prototype.get$inferredResult = function() { |
| 5631 var t = this.get$returnType(); |
| 5632 if (t.get$isBool() && (this.get$library().get$isCore() || this.get$library().g
et$isCoreImpl())) { |
| 5633 return $globals.world.nonNullBool; |
| 5634 } |
| 5635 return t; |
| 5636 } |
| 5637 Member.prototype.get$definition = function() { |
| 5638 return null; |
| 5639 } |
| 5640 Member.prototype.get$parameters = function() { |
| 5641 return []; |
| 5642 } |
| 5643 Member.prototype.canInvoke = function(context, args) { |
| 5644 return this.get$canGet() && new Value(this.get$returnType(), null, null, true)
.canInvoke(context, ':call', args); |
| 5645 } |
| 5646 Member.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 5647 var newTarget = this._get(context, node, target, isDynamic); |
| 5648 return newTarget.invoke$5(context, ':call', node, args, isDynamic); |
| 5649 } |
| 5650 Member.prototype.override = function(other) { |
| 5651 if (this.get$isStatic()) { |
| 5652 $globals.world.error('static members can not hide parent members', this.get$
span(), other.get$span()); |
| 5653 return false; |
| 5654 } |
| 5655 else if (other.get$isStatic()) { |
| 5656 $globals.world.error('can not override static member', this.get$span(), othe
r.get$span()); |
| 5657 return false; |
| 5658 } |
| 5659 return true; |
| 5660 } |
| 5661 Member.prototype.get$generatedFactoryName = function() { |
| 5662 var prefix = ('' + this.declaringType.get$jsname() + '.' + this.get$constructo
rName() + '\$'); |
| 5663 if (this.name == '') { |
| 5664 return ('' + prefix + 'factory'); |
| 5665 } |
| 5666 else { |
| 5667 return ('' + prefix + this.name + '\$factory'); |
| 5668 } |
| 5669 } |
| 5670 Member.prototype.hashCode = function() { |
| 5671 var typeCode = this.declaringType == null ? 1 : this.declaringType.hashCode(); |
| 5672 var nameCode = this.get$isConstructor() ? this.get$constructorName().hashCode(
) : this.name.hashCode(); |
| 5673 return (typeCode << 4) ^ nameCode; |
| 5674 } |
| 5675 Member.prototype.$eq = function(other) { |
| 5676 return (other instanceof Member) && $eq(this.get$isConstructor(), other.get$is
Constructor()) && $eq(this.declaringType, other.get$declaringType()) && (this.ge
t$isConstructor() ? this.get$constructorName() == other.get$constructorName() :
this.name == other.name); |
| 5677 } |
| 5678 Member.prototype._get$3 = Member.prototype._get; |
| 5679 Member.prototype._get$3$isDynamic = Member.prototype._get; |
| 5680 Member.prototype._get$4 = Member.prototype._get; |
| 5681 Member.prototype._set$4 = Member.prototype._set; |
| 5682 Member.prototype._set$4$isDynamic = Member.prototype._set; |
| 5683 Member.prototype._set$5 = Member.prototype._set; |
| 5684 Member.prototype.canInvoke$2 = Member.prototype.canInvoke; |
| 5685 Member.prototype.computeValue$0 = Member.prototype.computeValue; |
| 5686 Member.prototype.hashCode$0 = Member.prototype.hashCode; |
| 5687 Member.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 5688 return this.invoke($0, $1, $2, $3, false); |
| 5689 }; |
| 5690 Member.prototype.invoke$4$isDynamic = Member.prototype.invoke; |
| 5691 Member.prototype.invoke$5 = Member.prototype.invoke; |
| 5692 Member.prototype.provideFieldSyntax$0 = Member.prototype.provideFieldSyntax; |
| 5693 Member.prototype.providePropertySyntax$0 = Member.prototype.providePropertySynta
x; |
| 5694 // ********** Code for TypeMember ************** |
| 5695 $inherits(TypeMember, Member); |
| 5696 function TypeMember(type) { |
| 5697 this.type = type; |
| 5698 // Initializers done |
| 5699 Member.call(this, type.name, type.library.topType); |
| 5700 } |
| 5701 TypeMember.prototype.get$span = function() { |
| 5702 return this.type.definition.span; |
| 5703 } |
| 5704 Object.defineProperty(TypeMember.prototype, "span", { |
| 5705 get: TypeMember.prototype.get$span |
| 5706 }); |
| 5707 TypeMember.prototype.get$isStatic = function() { |
| 5708 return true; |
| 5709 } |
| 5710 TypeMember.prototype.get$returnType = function() { |
| 5711 return $globals.world.varType; |
| 5712 } |
| 5713 TypeMember.prototype.canInvoke = function(context, args) { |
| 5714 return false; |
| 5715 } |
| 5716 TypeMember.prototype.get$canGet = function() { |
| 5717 return true; |
| 5718 } |
| 5719 TypeMember.prototype.get$canSet = function() { |
| 5720 return false; |
| 5721 } |
| 5722 TypeMember.prototype.get$requiresFieldSyntax = function() { |
| 5723 return true; |
| 5724 } |
| 5725 TypeMember.prototype._get = function(context, node, target, isDynamic) { |
| 5726 return new Value.type$ctor(this.type, node.span); |
| 5727 } |
| 5728 TypeMember.prototype._set = function(context, node, target, value, isDynamic) { |
| 5729 $globals.world.error('cannot set type', node.span); |
| 5730 } |
| 5731 TypeMember.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 5732 $globals.world.error('cannot invoke type', node.span); |
| 5733 } |
| 5734 TypeMember.prototype._get$3 = function($0, $1, $2) { |
| 5735 return this._get($0, $1, $2, false); |
| 5736 }; |
| 5737 TypeMember.prototype._get$3$isDynamic = TypeMember.prototype._get; |
| 5738 TypeMember.prototype._get$4 = TypeMember.prototype._get; |
| 5739 TypeMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 5740 return this._set($0, $1, $2, $3, false); |
| 5741 }; |
| 5742 TypeMember.prototype._set$4$isDynamic = TypeMember.prototype._set; |
| 5743 TypeMember.prototype._set$5 = TypeMember.prototype._set; |
| 5744 TypeMember.prototype.canInvoke$2 = TypeMember.prototype.canInvoke; |
| 5745 TypeMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 5746 return this.invoke($0, $1, $2, $3, false); |
| 5747 }; |
| 5748 TypeMember.prototype.invoke$4$isDynamic = TypeMember.prototype.invoke; |
| 5749 TypeMember.prototype.invoke$5 = TypeMember.prototype.invoke; |
| 5750 // ********** Code for FieldMember ************** |
| 5751 $inherits(FieldMember, Member); |
| 5752 function FieldMember(name, declaringType, definition, value) { |
| 5753 this._providePropertySyntax = false |
| 5754 this._computing = false |
| 5755 this.definition = definition; |
| 5756 this.value = value; |
| 5757 this.isNative = false; |
| 5758 // Initializers done |
| 5759 Member.call(this, name, declaringType); |
| 5760 } |
| 5761 FieldMember.prototype.get$definition = function() { return this.definition; }; |
| 5762 FieldMember.prototype.get$isStatic = function() { return this.isStatic; }; |
| 5763 FieldMember.prototype.set$isStatic = function(value) { return this.isStatic = va
lue; }; |
| 5764 FieldMember.prototype.get$isFinal = function() { return this.isFinal; }; |
| 5765 FieldMember.prototype.set$isFinal = function(value) { return this.isFinal = valu
e; }; |
| 5766 FieldMember.prototype.get$isNative = function() { return this.isNative; }; |
| 5767 FieldMember.prototype.set$isNative = function(value) { return this.isNative = va
lue; }; |
| 5768 FieldMember.prototype.override = function(other) { |
| 5769 if (!Member.prototype.override.call(this, other)) return false; |
| 5770 if (other.get$isProperty()) { |
| 5771 return true; |
| 5772 } |
| 5773 else { |
| 5774 $globals.world.error('field can not override anything but property', this.ge
t$span(), other.get$span()); |
| 5775 return false; |
| 5776 } |
| 5777 } |
| 5778 FieldMember.prototype.get$prefersPropertySyntax = function() { |
| 5779 return false; |
| 5780 } |
| 5781 FieldMember.prototype.get$requiresFieldSyntax = function() { |
| 5782 return this.isNative; |
| 5783 } |
| 5784 FieldMember.prototype.provideFieldSyntax = function() { |
| 5785 |
| 5786 } |
| 5787 FieldMember.prototype.providePropertySyntax = function() { |
| 5788 this._providePropertySyntax = true; |
| 5789 } |
| 5790 FieldMember.prototype.get$span = function() { |
| 5791 return this.definition == null ? null : this.definition.span; |
| 5792 } |
| 5793 Object.defineProperty(FieldMember.prototype, "span", { |
| 5794 get: FieldMember.prototype.get$span |
| 5795 }); |
| 5796 FieldMember.prototype.get$returnType = function() { |
| 5797 return this.type; |
| 5798 } |
| 5799 FieldMember.prototype.get$canGet = function() { |
| 5800 return true; |
| 5801 } |
| 5802 FieldMember.prototype.get$canSet = function() { |
| 5803 return !this.isFinal; |
| 5804 } |
| 5805 FieldMember.prototype.get$isField = function() { |
| 5806 return true; |
| 5807 } |
| 5808 FieldMember.prototype.resolve = function() { |
| 5809 this.isStatic = this.declaringType.get$isTop(); |
| 5810 this.isFinal = false; |
| 5811 if (this.definition.modifiers != null) { |
| 5812 var $$list = this.definition.modifiers; |
| 5813 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5814 var mod = $$list.$index($$i); |
| 5815 if ($eq(mod.kind, 86/*TokenKind.STATIC*/)) { |
| 5816 if (this.isStatic) { |
| 5817 $globals.world.error('duplicate static modifier', mod.span); |
| 5818 } |
| 5819 this.isStatic = true; |
| 5820 } |
| 5821 else if ($eq(mod.kind, 98/*TokenKind.FINAL*/)) { |
| 5822 if (this.isFinal) { |
| 5823 $globals.world.error('duplicate final modifier', mod.span); |
| 5824 } |
| 5825 this.isFinal = true; |
| 5826 } |
| 5827 else { |
| 5828 $globals.world.error(('' + mod + ' modifier not allowed on field'), mod.
span); |
| 5829 } |
| 5830 } |
| 5831 } |
| 5832 this.type = this.resolveType(this.definition.type, false); |
| 5833 if (this.isStatic && this.type.get$hasTypeParams()) { |
| 5834 $globals.world.error('using type parameter in static context', this.definiti
on.type.span); |
| 5835 } |
| 5836 if (this.isStatic && this.isFinal && this.value == null) { |
| 5837 $globals.world.error('static final field is missing initializer', this.get$s
pan()); |
| 5838 } |
| 5839 this.get$library()._addMember(this); |
| 5840 } |
| 5841 FieldMember.prototype.computeValue = function() { |
| 5842 if (this.value == null) return null; |
| 5843 if (this._computedValue == null) { |
| 5844 if (this._computing) { |
| 5845 $globals.world.error('circular reference', this.value.span); |
| 5846 return null; |
| 5847 } |
| 5848 this._computing = true; |
| 5849 var finalMethod = new MethodMember('final_context', this.declaringType, null
); |
| 5850 finalMethod.set$isStatic(true); |
| 5851 var finalGen = new MethodGenerator(finalMethod, null); |
| 5852 this._computedValue = this.value.visit(finalGen); |
| 5853 if (!this._computedValue.get$isConst()) { |
| 5854 if (this.isStatic) { |
| 5855 $globals.world.error('non constant static field must be initialized in f
unctions', this.value.span); |
| 5856 } |
| 5857 else { |
| 5858 $globals.world.error('non constant field must be initialized in construc
tor', this.value.span); |
| 5859 } |
| 5860 } |
| 5861 if (this.isStatic) { |
| 5862 this._computedValue = $globals.world.gen.globalForStaticField(this, this._
computedValue, [this._computedValue]); |
| 5863 } |
| 5864 this._computing = false; |
| 5865 } |
| 5866 return this._computedValue; |
| 5867 } |
| 5868 FieldMember.prototype._get = function(context, node, target, isDynamic) { |
| 5869 if (this.isNative && this.get$returnType() != null) { |
| 5870 this.get$returnType().markUsed(); |
| 5871 if ((this.get$returnType() instanceof DefinedType)) { |
| 5872 var factory_ = this.get$returnType().get$genericType().factory_; |
| 5873 if (factory_ != null && factory_.get$isNative()) { |
| 5874 factory_.markUsed$0(); |
| 5875 } |
| 5876 } |
| 5877 } |
| 5878 if (this.isStatic) { |
| 5879 this.declaringType.markUsed(); |
| 5880 var cv = this.computeValue(); |
| 5881 if (this.isFinal) { |
| 5882 return cv; |
| 5883 } |
| 5884 $globals.world.gen.hasStatics = true; |
| 5885 if (this.declaringType.get$isTop()) { |
| 5886 if ($eq(this.declaringType.get$library(), $globals.world.get$dom())) { |
| 5887 return new Value(this.type, ('' + this.get$jsname()), node.span, true); |
| 5888 } |
| 5889 else { |
| 5890 return new Value(this.type, ('\$globals.' + this.get$jsname()), node.spa
n, true); |
| 5891 } |
| 5892 } |
| 5893 else if (this.declaringType.get$isNative()) { |
| 5894 if (this.declaringType.get$isHiddenNativeType()) { |
| 5895 $globals.world.error('static field of hidden native type is inaccessible
', node.span); |
| 5896 } |
| 5897 return new Value(this.type, ('' + this.declaringType.get$jsname() + '.' +
this.get$jsname()), node.span, true); |
| 5898 } |
| 5899 else { |
| 5900 return new Value(this.type, ('\$globals.' + this.declaringType.get$jsname(
) + '_' + this.get$jsname()), node.span, true); |
| 5901 } |
| 5902 } |
| 5903 else if (target.get$isConst() && this.isFinal) { |
| 5904 var constTarget = (target instanceof GlobalValue) ? target.get$dynamic().get
$exp() : target; |
| 5905 if ((constTarget instanceof ConstObjectValue)) { |
| 5906 return constTarget.get$fields().$index(this.name); |
| 5907 } |
| 5908 else if ($eq(constTarget.type, $globals.world.stringType) && this.name == 'l
ength') { |
| 5909 return new Value(this.type, ('' + constTarget.get$actualValue().length), n
ode.span, true); |
| 5910 } |
| 5911 } |
| 5912 return new Value(this.type, ('' + target.code + '.' + this.get$jsname()), node
.span, true); |
| 5913 } |
| 5914 FieldMember.prototype._set = function(context, node, target, value, isDynamic) { |
| 5915 var lhs = this._get(context, node, target, isDynamic); |
| 5916 value = value.convertTo(context, this.type, node, isDynamic); |
| 5917 return new Value(this.type, ('' + lhs.code + ' = ' + value.code), node.span, t
rue); |
| 5918 } |
| 5919 FieldMember.prototype._get$3 = function($0, $1, $2) { |
| 5920 return this._get($0, $1, $2, false); |
| 5921 }; |
| 5922 FieldMember.prototype._get$3$isDynamic = FieldMember.prototype._get; |
| 5923 FieldMember.prototype._get$4 = FieldMember.prototype._get; |
| 5924 FieldMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 5925 return this._set($0, $1, $2, $3, false); |
| 5926 }; |
| 5927 FieldMember.prototype._set$4$isDynamic = FieldMember.prototype._set; |
| 5928 FieldMember.prototype._set$5 = FieldMember.prototype._set; |
| 5929 FieldMember.prototype.computeValue$0 = FieldMember.prototype.computeValue; |
| 5930 FieldMember.prototype.provideFieldSyntax$0 = FieldMember.prototype.provideFieldS
yntax; |
| 5931 FieldMember.prototype.providePropertySyntax$0 = FieldMember.prototype.providePro
pertySyntax; |
| 5932 FieldMember.prototype.resolve$0 = FieldMember.prototype.resolve; |
| 5933 // ********** Code for PropertyMember ************** |
| 5934 $inherits(PropertyMember, Member); |
| 5935 function PropertyMember(name, declaringType) { |
| 5936 this._provideFieldSyntax = false |
| 5937 // Initializers done |
| 5938 Member.call(this, name, declaringType); |
| 5939 } |
| 5940 PropertyMember.prototype.get$getter = function() { return this.getter; }; |
| 5941 PropertyMember.prototype.set$getter = function(value) { return this.getter = val
ue; }; |
| 5942 PropertyMember.prototype.get$setter = function() { return this.setter; }; |
| 5943 PropertyMember.prototype.set$setter = function(value) { return this.setter = val
ue; }; |
| 5944 PropertyMember.prototype.get$span = function() { |
| 5945 return this.getter != null ? this.getter.get$span() : null; |
| 5946 } |
| 5947 Object.defineProperty(PropertyMember.prototype, "span", { |
| 5948 get: PropertyMember.prototype.get$span |
| 5949 }); |
| 5950 PropertyMember.prototype.get$canGet = function() { |
| 5951 return this.getter != null; |
| 5952 } |
| 5953 PropertyMember.prototype.get$canSet = function() { |
| 5954 return this.setter != null; |
| 5955 } |
| 5956 PropertyMember.prototype.get$prefersPropertySyntax = function() { |
| 5957 return true; |
| 5958 } |
| 5959 PropertyMember.prototype.get$requiresFieldSyntax = function() { |
| 5960 return false; |
| 5961 } |
| 5962 PropertyMember.prototype.provideFieldSyntax = function() { |
| 5963 this._provideFieldSyntax = true; |
| 5964 } |
| 5965 PropertyMember.prototype.providePropertySyntax = function() { |
| 5966 |
| 5967 } |
| 5968 PropertyMember.prototype.get$isStatic = function() { |
| 5969 return this.getter == null ? this.setter.isStatic : this.getter.isStatic; |
| 5970 } |
| 5971 PropertyMember.prototype.get$isProperty = function() { |
| 5972 return true; |
| 5973 } |
| 5974 PropertyMember.prototype.get$returnType = function() { |
| 5975 return this.getter == null ? this.setter.returnType : this.getter.returnType; |
| 5976 } |
| 5977 PropertyMember.prototype.override = function(other) { |
| 5978 if (!Member.prototype.override.call(this, other)) return false; |
| 5979 if (other.get$isProperty() || other.get$isField()) { |
| 5980 if (other.get$isProperty()) this.addFromParent(other); |
| 5981 else this._overriddenField = other; |
| 5982 return true; |
| 5983 } |
| 5984 else { |
| 5985 $globals.world.error('property can only override field or property', this.ge
t$span(), other.get$span()); |
| 5986 return false; |
| 5987 } |
| 5988 } |
| 5989 PropertyMember.prototype._get = function(context, node, target, isDynamic) { |
| 5990 if (this.getter == null) { |
| 5991 if (this._overriddenField != null) { |
| 5992 return this._overriddenField._get(context, node, target, isDynamic); |
| 5993 } |
| 5994 return target.invokeNoSuchMethod(context, ('get:' + this.name), node); |
| 5995 } |
| 5996 return this.getter.invoke(context, node, target, Arguments.get$EMPTY(), false)
; |
| 5997 } |
| 5998 PropertyMember.prototype._set = function(context, node, target, value, isDynamic
) { |
| 5999 if (this.setter == null) { |
| 6000 if (this._overriddenField != null) { |
| 6001 return this._overriddenField._set(context, node, target, value, isDynamic)
; |
| 6002 } |
| 6003 return target.invokeNoSuchMethod(context, ('set:' + this.name), node, new Ar
guments(null, [value])); |
| 6004 } |
| 6005 return this.setter.invoke(context, node, target, new Arguments(null, [value]),
isDynamic); |
| 6006 } |
| 6007 PropertyMember.prototype.addFromParent = function(parentMember) { |
| 6008 var parent; |
| 6009 if ((parentMember instanceof ConcreteMember)) { |
| 6010 var c = parentMember; |
| 6011 parent = c.baseMember; |
| 6012 } |
| 6013 else { |
| 6014 parent = parentMember; |
| 6015 } |
| 6016 if (this.getter == null) this.getter = parent.getter; |
| 6017 if (this.setter == null) this.setter = parent.setter; |
| 6018 } |
| 6019 PropertyMember.prototype.resolve = function() { |
| 6020 if (this.getter != null) { |
| 6021 this.getter.resolve(); |
| 6022 if (this.getter.parameters.length != 0) { |
| 6023 $globals.world.error('getter methods should take no arguments', this.gette
r.definition.span); |
| 6024 } |
| 6025 if (this.getter.returnType.get$isVoid()) { |
| 6026 $globals.world.warning('getter methods should not be void', this.getter.de
finition.returnType.span); |
| 6027 } |
| 6028 } |
| 6029 if (this.setter != null) { |
| 6030 this.setter.resolve(); |
| 6031 if (this.setter.parameters.length != 1) { |
| 6032 $globals.world.error('setter methods should take a single argument', this.
setter.definition.span); |
| 6033 } |
| 6034 if (!this.setter.returnType.get$isVoid() && this.setter.definition.returnTyp
e != null) { |
| 6035 $globals.world.warning('setter methods should be void', this.setter.defini
tion.returnType.span); |
| 6036 } |
| 6037 } |
| 6038 this.get$library()._addMember(this); |
| 6039 } |
| 6040 PropertyMember.prototype._get$3 = function($0, $1, $2) { |
| 6041 return this._get($0, $1, $2, false); |
| 6042 }; |
| 6043 PropertyMember.prototype._get$3$isDynamic = PropertyMember.prototype._get; |
| 6044 PropertyMember.prototype._get$4 = PropertyMember.prototype._get; |
| 6045 PropertyMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 6046 return this._set($0, $1, $2, $3, false); |
| 6047 }; |
| 6048 PropertyMember.prototype._set$4$isDynamic = PropertyMember.prototype._set; |
| 6049 PropertyMember.prototype._set$5 = PropertyMember.prototype._set; |
| 6050 PropertyMember.prototype.provideFieldSyntax$0 = PropertyMember.prototype.provide
FieldSyntax; |
| 6051 PropertyMember.prototype.providePropertySyntax$0 = PropertyMember.prototype.prov
idePropertySyntax; |
| 6052 PropertyMember.prototype.resolve$0 = PropertyMember.prototype.resolve; |
| 6053 // ********** Code for ConcreteMember ************** |
| 6054 $inherits(ConcreteMember, Member); |
| 6055 function ConcreteMember(name, declaringType, baseMember) { |
| 6056 this.baseMember = baseMember; |
| 6057 // Initializers done |
| 6058 Member.call(this, name, declaringType); |
| 6059 this.parameters = []; |
| 6060 this.returnType = this.baseMember.get$returnType().resolveTypeParams(declaring
Type); |
| 6061 var $$list = this.baseMember.get$parameters(); |
| 6062 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6063 var p = $$list.$index($$i); |
| 6064 var newType = p.type.resolveTypeParams$1(declaringType); |
| 6065 if ($ne(newType, p.type)) { |
| 6066 this.parameters.add(p.copyWithNewType$2(this, newType)); |
| 6067 } |
| 6068 else { |
| 6069 this.parameters.add(p); |
| 6070 } |
| 6071 } |
| 6072 } |
| 6073 ConcreteMember.prototype.get$returnType = function() { return this.returnType; }
; |
| 6074 ConcreteMember.prototype.set$returnType = function(value) { return this.returnTy
pe = value; }; |
| 6075 ConcreteMember.prototype.get$parameters = function() { return this.parameters; }
; |
| 6076 ConcreteMember.prototype.set$parameters = function(value) { return this.paramete
rs = value; }; |
| 6077 ConcreteMember.prototype.get$span = function() { |
| 6078 return this.baseMember.get$span(); |
| 6079 } |
| 6080 Object.defineProperty(ConcreteMember.prototype, "span", { |
| 6081 get: ConcreteMember.prototype.get$span |
| 6082 }); |
| 6083 ConcreteMember.prototype.get$isStatic = function() { |
| 6084 return this.baseMember.get$isStatic(); |
| 6085 } |
| 6086 ConcreteMember.prototype.get$isAbstract = function() { |
| 6087 return this.baseMember.get$isAbstract(); |
| 6088 } |
| 6089 ConcreteMember.prototype.get$isConst = function() { |
| 6090 return this.baseMember.get$isConst(); |
| 6091 } |
| 6092 ConcreteMember.prototype.get$isFactory = function() { |
| 6093 return this.baseMember.get$isFactory(); |
| 6094 } |
| 6095 ConcreteMember.prototype.get$isFinal = function() { |
| 6096 return this.baseMember.get$isFinal(); |
| 6097 } |
| 6098 ConcreteMember.prototype.get$isNative = function() { |
| 6099 return this.baseMember.get$isNative(); |
| 6100 } |
| 6101 ConcreteMember.prototype.get$jsname = function() { |
| 6102 return this.baseMember.get$jsname(); |
| 6103 } |
| 6104 ConcreteMember.prototype.get$canGet = function() { |
| 6105 return this.baseMember.get$canGet(); |
| 6106 } |
| 6107 ConcreteMember.prototype.get$canSet = function() { |
| 6108 return this.baseMember.get$canSet(); |
| 6109 } |
| 6110 ConcreteMember.prototype.canInvoke = function(context, args) { |
| 6111 return this.baseMember.canInvoke(context, args); |
| 6112 } |
| 6113 ConcreteMember.prototype.get$isField = function() { |
| 6114 return this.baseMember.get$isField(); |
| 6115 } |
| 6116 ConcreteMember.prototype.get$isMethod = function() { |
| 6117 return this.baseMember.get$isMethod(); |
| 6118 } |
| 6119 ConcreteMember.prototype.get$isProperty = function() { |
| 6120 return this.baseMember.get$isProperty(); |
| 6121 } |
| 6122 ConcreteMember.prototype.get$prefersPropertySyntax = function() { |
| 6123 return this.baseMember.get$prefersPropertySyntax(); |
| 6124 } |
| 6125 ConcreteMember.prototype.get$requiresFieldSyntax = function() { |
| 6126 return this.baseMember.get$requiresFieldSyntax(); |
| 6127 } |
| 6128 ConcreteMember.prototype.provideFieldSyntax = function() { |
| 6129 return this.baseMember.provideFieldSyntax(); |
| 6130 } |
| 6131 ConcreteMember.prototype.providePropertySyntax = function() { |
| 6132 return this.baseMember.providePropertySyntax(); |
| 6133 } |
| 6134 ConcreteMember.prototype.get$isConstructor = function() { |
| 6135 return this.name == this.declaringType.name; |
| 6136 } |
| 6137 ConcreteMember.prototype.get$constructorName = function() { |
| 6138 return this.baseMember.get$constructorName(); |
| 6139 } |
| 6140 ConcreteMember.prototype.get$definition = function() { |
| 6141 return this.baseMember.get$definition(); |
| 6142 } |
| 6143 ConcreteMember.prototype.get$initDelegate = function() { |
| 6144 return this.baseMember.get$initDelegate(); |
| 6145 } |
| 6146 ConcreteMember.prototype.set$initDelegate = function(ctor) { |
| 6147 this.baseMember.set$initDelegate(ctor); |
| 6148 } |
| 6149 ConcreteMember.prototype.resolveType = function(node, isRequired) { |
| 6150 var type = this.baseMember.resolveType(node, isRequired); |
| 6151 return type.resolveTypeParams$1(this.declaringType); |
| 6152 } |
| 6153 ConcreteMember.prototype.computeValue = function() { |
| 6154 return this.baseMember.computeValue(); |
| 6155 } |
| 6156 ConcreteMember.prototype.override = function(other) { |
| 6157 return this.baseMember.override(other); |
| 6158 } |
| 6159 ConcreteMember.prototype._get = function(context, node, target, isDynamic) { |
| 6160 var ret = this.baseMember._get(context, node, target, isDynamic); |
| 6161 return new Value(this.get$inferredResult(), ret.code, node.span, true); |
| 6162 } |
| 6163 ConcreteMember.prototype._set = function(context, node, target, value, isDynamic
) { |
| 6164 var ret = this.baseMember._set(context, node, target, value, isDynamic); |
| 6165 return new Value(this.returnType, ret.code, node.span, true); |
| 6166 } |
| 6167 ConcreteMember.prototype.invoke = function(context, node, target, args, isDynami
c) { |
| 6168 var ret = this.baseMember.invoke(context, node, target, args, isDynamic); |
| 6169 var code = ret.code; |
| 6170 if (this.get$isConstructor()) { |
| 6171 code = code.replaceFirst$2(this.declaringType.get$genericType().get$jsname()
, this.declaringType.get$jsname()); |
| 6172 } |
| 6173 if ((this.baseMember instanceof MethodMember)) { |
| 6174 this.declaringType.genMethod(this); |
| 6175 } |
| 6176 return new Value(this.get$inferredResult(), code, node.span, true); |
| 6177 } |
| 6178 ConcreteMember.prototype._get$3 = function($0, $1, $2) { |
| 6179 return this._get($0, $1, $2, false); |
| 6180 }; |
| 6181 ConcreteMember.prototype._get$3$isDynamic = ConcreteMember.prototype._get; |
| 6182 ConcreteMember.prototype._get$4 = ConcreteMember.prototype._get; |
| 6183 ConcreteMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 6184 return this._set($0, $1, $2, $3, false); |
| 6185 }; |
| 6186 ConcreteMember.prototype._set$4$isDynamic = ConcreteMember.prototype._set; |
| 6187 ConcreteMember.prototype._set$5 = ConcreteMember.prototype._set; |
| 6188 ConcreteMember.prototype.canInvoke$2 = ConcreteMember.prototype.canInvoke; |
| 6189 ConcreteMember.prototype.computeValue$0 = ConcreteMember.prototype.computeValue; |
| 6190 ConcreteMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 6191 return this.invoke($0, $1, $2, $3, false); |
| 6192 }; |
| 6193 ConcreteMember.prototype.invoke$4$isDynamic = ConcreteMember.prototype.invoke; |
| 6194 ConcreteMember.prototype.invoke$5 = ConcreteMember.prototype.invoke; |
| 6195 ConcreteMember.prototype.provideFieldSyntax$0 = ConcreteMember.prototype.provide
FieldSyntax; |
| 6196 ConcreteMember.prototype.providePropertySyntax$0 = ConcreteMember.prototype.prov
idePropertySyntax; |
| 6197 // ********** Code for MethodMember ************** |
| 6198 $inherits(MethodMember, Member); |
| 6199 function MethodMember(name, declaringType, definition) { |
| 6200 this.isStatic = false |
| 6201 this.isAbstract = false |
| 6202 this.isConst = false |
| 6203 this.isFactory = false |
| 6204 this.isLambda = false |
| 6205 this._providePropertySyntax = false |
| 6206 this._provideFieldSyntax = false |
| 6207 this._provideOptionalParamInfo = false |
| 6208 this.definition = definition; |
| 6209 // Initializers done |
| 6210 Member.call(this, name, declaringType); |
| 6211 } |
| 6212 MethodMember.prototype.get$definition = function() { return this.definition; }; |
| 6213 MethodMember.prototype.set$definition = function(value) { return this.definition
= value; }; |
| 6214 MethodMember.prototype.get$returnType = function() { return this.returnType; }; |
| 6215 MethodMember.prototype.set$returnType = function(value) { return this.returnType
= value; }; |
| 6216 MethodMember.prototype.get$parameters = function() { return this.parameters; }; |
| 6217 MethodMember.prototype.set$parameters = function(value) { return this.parameters
= value; }; |
| 6218 MethodMember.prototype.get$typeParameters = function() { return this.typeParamet
ers; }; |
| 6219 MethodMember.prototype.set$typeParameters = function(value) { return this.typePa
rameters = value; }; |
| 6220 MethodMember.prototype.get$isStatic = function() { return this.isStatic; }; |
| 6221 MethodMember.prototype.set$isStatic = function(value) { return this.isStatic = v
alue; }; |
| 6222 MethodMember.prototype.get$isAbstract = function() { return this.isAbstract; }; |
| 6223 MethodMember.prototype.set$isAbstract = function(value) { return this.isAbstract
= value; }; |
| 6224 MethodMember.prototype.get$isConst = function() { return this.isConst; }; |
| 6225 MethodMember.prototype.set$isConst = function(value) { return this.isConst = val
ue; }; |
| 6226 MethodMember.prototype.get$isFactory = function() { return this.isFactory; }; |
| 6227 MethodMember.prototype.set$isFactory = function(value) { return this.isFactory =
value; }; |
| 6228 MethodMember.prototype.get$isLambda = function() { return this.isLambda; }; |
| 6229 MethodMember.prototype.set$isLambda = function(value) { return this.isLambda = v
alue; }; |
| 6230 MethodMember.prototype.get$initDelegate = function() { return this.initDelegate;
}; |
| 6231 MethodMember.prototype.set$initDelegate = function(value) { return this.initDele
gate = value; }; |
| 6232 MethodMember.prototype.get$isConstructor = function() { |
| 6233 return this.name == this.declaringType.name; |
| 6234 } |
| 6235 MethodMember.prototype.get$isMethod = function() { |
| 6236 return !this.get$isConstructor(); |
| 6237 } |
| 6238 MethodMember.prototype.get$isNative = function() { |
| 6239 return this.definition.nativeBody != null; |
| 6240 } |
| 6241 MethodMember.prototype.get$canGet = function() { |
| 6242 return false; |
| 6243 } |
| 6244 MethodMember.prototype.get$canSet = function() { |
| 6245 return false; |
| 6246 } |
| 6247 MethodMember.prototype.get$span = function() { |
| 6248 return this.definition == null ? null : this.definition.span; |
| 6249 } |
| 6250 Object.defineProperty(MethodMember.prototype, "span", { |
| 6251 get: MethodMember.prototype.get$span |
| 6252 }); |
| 6253 MethodMember.prototype.get$constructorName = function() { |
| 6254 var returnType = this.definition.returnType; |
| 6255 if (returnType == null) return ''; |
| 6256 if ((returnType instanceof GenericTypeReference)) { |
| 6257 return ''; |
| 6258 } |
| 6259 if (returnType.get$names() != null) { |
| 6260 return returnType.get$names().$index(0).name; |
| 6261 } |
| 6262 else if (returnType.name != null) { |
| 6263 return returnType.name.name; |
| 6264 } |
| 6265 $globals.world.internalError('no valid constructor name', this.definition.span
); |
| 6266 } |
| 6267 MethodMember.prototype.get$functionType = function() { |
| 6268 if (this._functionType == null) { |
| 6269 this._functionType = this.get$library().getOrAddFunctionType(this.declaringT
ype, this.name, this.definition); |
| 6270 if (this.parameters == null) { |
| 6271 this.resolve(); |
| 6272 } |
| 6273 } |
| 6274 return this._functionType; |
| 6275 } |
| 6276 MethodMember.prototype.override = function(other) { |
| 6277 if (!Member.prototype.override.call(this, other)) return false; |
| 6278 if (other.get$isMethod()) { |
| 6279 return true; |
| 6280 } |
| 6281 else { |
| 6282 $globals.world.error('method can only override methods', this.get$span(), ot
her.get$span()); |
| 6283 return false; |
| 6284 } |
| 6285 } |
| 6286 MethodMember.prototype.canInvoke = function(context, args) { |
| 6287 var bareCount = args.get$bareCount(); |
| 6288 if (bareCount > this.parameters.length) return false; |
| 6289 if (bareCount == this.parameters.length) { |
| 6290 if (bareCount != args.get$length()) return false; |
| 6291 } |
| 6292 else { |
| 6293 if (!this.parameters.$index(bareCount).get$isOptional()) return false; |
| 6294 for (var i = bareCount; |
| 6295 i < args.get$length(); i++) { |
| 6296 if (this.indexOfParameter(args.getName(i)) < 0) { |
| 6297 return false; |
| 6298 } |
| 6299 } |
| 6300 } |
| 6301 return true; |
| 6302 } |
| 6303 MethodMember.prototype.indexOfParameter = function(name) { |
| 6304 for (var i = 0; |
| 6305 i < this.parameters.length; i++) { |
| 6306 var p = this.parameters.$index(i); |
| 6307 if (p.get$isOptional() && $eq(p.name, name)) { |
| 6308 return i; |
| 6309 } |
| 6310 } |
| 6311 return -1; |
| 6312 } |
| 6313 MethodMember.prototype.get$prefersPropertySyntax = function() { |
| 6314 return true; |
| 6315 } |
| 6316 MethodMember.prototype.get$requiresFieldSyntax = function() { |
| 6317 return false; |
| 6318 } |
| 6319 MethodMember.prototype.provideFieldSyntax = function() { |
| 6320 this._provideFieldSyntax = true; |
| 6321 } |
| 6322 MethodMember.prototype.providePropertySyntax = function() { |
| 6323 this._providePropertySyntax = true; |
| 6324 } |
| 6325 MethodMember.prototype._set = function(context, node, target, value, isDynamic)
{ |
| 6326 $globals.world.error('cannot set method', node.span); |
| 6327 } |
| 6328 MethodMember.prototype._get = function(context, node, target, isDynamic) { |
| 6329 this.declaringType.genMethod(this); |
| 6330 this._provideOptionalParamInfo = true; |
| 6331 if (this.isStatic) { |
| 6332 this.declaringType.markUsed(); |
| 6333 var type = this.declaringType.get$isTop() ? '' : ('' + this.declaringType.ge
t$jsname() + '.'); |
| 6334 return new Value(this.get$functionType(), ('' + type + this.get$jsname()), n
ode.span, true); |
| 6335 } |
| 6336 this._providePropertySyntax = true; |
| 6337 return new Value(this.get$functionType(), ('' + target.code + '.get\$' + this.
get$jsname() + '()'), node.span, true); |
| 6338 } |
| 6339 MethodMember.prototype.namesInOrder = function(args) { |
| 6340 if (!args.get$hasNames()) return true; |
| 6341 var lastParameter = null; |
| 6342 for (var i = args.get$bareCount(); |
| 6343 i < this.parameters.length; i++) { |
| 6344 var p = args.getIndexOfName(this.parameters.$index(i).name); |
| 6345 if (p >= 0 && args.values.$index(p).get$needsTemp()) { |
| 6346 if (lastParameter != null && lastParameter > p) { |
| 6347 return false; |
| 6348 } |
| 6349 lastParameter = p; |
| 6350 } |
| 6351 } |
| 6352 return true; |
| 6353 } |
| 6354 MethodMember.prototype.needsArgumentConversion = function(args) { |
| 6355 var bareCount = args.get$bareCount(); |
| 6356 for (var i = 0; |
| 6357 i < bareCount; i++) { |
| 6358 var arg = args.values.$index(i); |
| 6359 if (arg.needsConversion$1(this.parameters.$index(i).type)) { |
| 6360 return true; |
| 6361 } |
| 6362 } |
| 6363 if (bareCount < this.parameters.length) { |
| 6364 this.genParameterValues(); |
| 6365 for (var i = bareCount; |
| 6366 i < this.parameters.length; i++) { |
| 6367 var arg = args.getValue(this.parameters.$index(i).name); |
| 6368 if (arg != null && arg.needsConversion$1(this.parameters.$index(i).type))
{ |
| 6369 return true; |
| 6370 } |
| 6371 } |
| 6372 } |
| 6373 return false; |
| 6374 } |
| 6375 MethodMember._argCountMsg = function(actual, expected, atLeast) { |
| 6376 return 'wrong number of positional arguments, expected ' + ('' + (atLeast ? "a
t least " : "") + expected + ' but found ' + actual); |
| 6377 } |
| 6378 MethodMember.prototype._argError = function(context, node, target, args, msg, sp
an) { |
| 6379 if (this.isStatic || this.get$isConstructor()) { |
| 6380 $globals.world.error(msg, span); |
| 6381 } |
| 6382 else { |
| 6383 $globals.world.warning(msg, span); |
| 6384 } |
| 6385 return target.invokeNoSuchMethod(context, this.name, node, args); |
| 6386 } |
| 6387 MethodMember.prototype.genParameterValues = function() { |
| 6388 var $$list = this.parameters; |
| 6389 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6390 var p = $$list.$index($$i); |
| 6391 p.genValue$2(this, this.generator); |
| 6392 } |
| 6393 } |
| 6394 MethodMember.prototype.invoke = function(context, node, target, args, isDynamic)
{ |
| 6395 if (this.parameters == null) { |
| 6396 $globals.world.info(('surprised to need to resolve: ' + this.declaringType.n
ame + '.' + this.name)); |
| 6397 this.resolve(); |
| 6398 } |
| 6399 this.declaringType.genMethod(this); |
| 6400 if (this.isStatic || this.isFactory) { |
| 6401 this.declaringType.markUsed(); |
| 6402 } |
| 6403 if (this.get$isNative() && this.returnType != null) this.returnType.markUsed()
; |
| 6404 if (!this.namesInOrder(args)) { |
| 6405 return context.findMembers(this.name).invokeOnVar(context, node, target, arg
s); |
| 6406 } |
| 6407 var argsCode = []; |
| 6408 if (!target.isType && (this.get$isConstructor() || target.isSuper)) { |
| 6409 argsCode.add$1('this'); |
| 6410 } |
| 6411 var bareCount = args.get$bareCount(); |
| 6412 for (var i = 0; |
| 6413 i < bareCount; i++) { |
| 6414 var arg = args.values.$index(i); |
| 6415 if (i >= this.parameters.length) { |
| 6416 var msg = MethodMember._argCountMsg(args.get$length(), this.parameters.len
gth, false); |
| 6417 return this._argError(context, node, target, args, msg, args.nodes.$index(
i).span); |
| 6418 } |
| 6419 arg = arg.convertTo$4(context, this.parameters.$index(i).type, node, isDynam
ic); |
| 6420 if (this.isConst && arg.get$isConst()) { |
| 6421 argsCode.add$1(arg.get$canonicalCode()); |
| 6422 } |
| 6423 else { |
| 6424 argsCode.add$1(arg.code); |
| 6425 } |
| 6426 } |
| 6427 var namedArgsUsed = 0; |
| 6428 if (bareCount < this.parameters.length) { |
| 6429 this.genParameterValues(); |
| 6430 for (var i = bareCount; |
| 6431 i < this.parameters.length; i++) { |
| 6432 var arg = args.getValue(this.parameters.$index(i).name); |
| 6433 if (arg == null) { |
| 6434 arg = this.parameters.$index(i).value; |
| 6435 } |
| 6436 else { |
| 6437 arg = arg.convertTo$4(context, this.parameters.$index(i).type, node, isD
ynamic); |
| 6438 namedArgsUsed++; |
| 6439 } |
| 6440 if (arg == null || !this.parameters.$index(i).get$isOptional()) { |
| 6441 var msg = MethodMember._argCountMsg(Math.min(i, args.get$length()), i +
1, true); |
| 6442 return this._argError(context, node, target, args, msg, args.nodes.$inde
x(i).span); |
| 6443 } |
| 6444 else { |
| 6445 argsCode.add$1(this.isConst && arg.get$isConst() ? arg.get$canonicalCode
() : arg.code); |
| 6446 } |
| 6447 } |
| 6448 Arguments.removeTrailingNulls(argsCode); |
| 6449 } |
| 6450 if (namedArgsUsed < args.get$nameCount()) { |
| 6451 var seen = new HashSetImplementation(); |
| 6452 for (var i = bareCount; |
| 6453 i < args.get$length(); i++) { |
| 6454 var name = args.getName(i); |
| 6455 if (seen.contains$1(name)) { |
| 6456 return this._argError(context, node, target, args, ('duplicate argument
"' + name + '"'), args.nodes.$index(i).span); |
| 6457 } |
| 6458 seen.add$1(name); |
| 6459 var p = this.indexOfParameter(name); |
| 6460 if (p < 0) { |
| 6461 return this._argError(context, node, target, args, ('method does not hav
e optional parameter "' + name + '"'), args.nodes.$index(i).span); |
| 6462 } |
| 6463 else if (p < bareCount) { |
| 6464 return this._argError(context, node, target, args, ('argument "' + name
+ '" passed as positional and named'), args.nodes.$index(p).span); |
| 6465 } |
| 6466 } |
| 6467 $globals.world.internalError(('wrong named arguments calling ' + this.name),
node.span); |
| 6468 } |
| 6469 var argsString = Strings.join(argsCode, ', '); |
| 6470 if (this.get$isConstructor()) { |
| 6471 return this._invokeConstructor(context, node, target, args, argsString); |
| 6472 } |
| 6473 if (target.isSuper) { |
| 6474 return new Value(this.get$inferredResult(), ('' + this.declaringType.get$jsn
ame() + '.prototype.' + this.get$jsname() + '.call(' + argsString + ')'), node.s
pan, true); |
| 6475 } |
| 6476 if (this.get$isOperator()) { |
| 6477 return this._invokeBuiltin(context, node, target, args, argsCode, isDynamic)
; |
| 6478 } |
| 6479 if (this.isFactory) { |
| 6480 return new Value(target.get$type(), ('' + this.get$generatedFactoryName() +
'(' + argsString + ')'), node.span, true); |
| 6481 } |
| 6482 if (this.isStatic) { |
| 6483 if (this.declaringType.get$isTop()) { |
| 6484 return new Value(this.get$inferredResult(), ('' + this.get$jsname() + '('
+ argsString + ')'), node != null ? node.span : node, true); |
| 6485 } |
| 6486 return new Value(this.get$inferredResult(), ('' + this.declaringType.get$jsn
ame() + '.' + this.get$jsname() + '(' + argsString + ')'), node.span, true); |
| 6487 } |
| 6488 var code = ('' + target.code + '.' + this.get$jsname() + '(' + argsString + ')
'); |
| 6489 if (target.get$isConst()) { |
| 6490 if ((target instanceof GlobalValue)) { |
| 6491 target = target.get$dynamic().get$exp(); |
| 6492 } |
| 6493 if (this.name == 'get:length') { |
| 6494 if ((target instanceof ConstListValue) || (target instanceof ConstMapValue
)) { |
| 6495 code = ('' + target.get$dynamic().values.length); |
| 6496 } |
| 6497 } |
| 6498 else if (this.name == 'isEmpty') { |
| 6499 if ((target instanceof ConstListValue) || (target instanceof ConstMapValue
)) { |
| 6500 code = ('' + target.get$dynamic().values.isEmpty$0()); |
| 6501 } |
| 6502 } |
| 6503 } |
| 6504 if (this.name == 'get:typeName' && $eq(this.declaringType.get$library(), $glob
als.world.get$dom())) { |
| 6505 $globals.world.gen.corejs.ensureTypeNameOf(); |
| 6506 } |
| 6507 return new Value(this.get$inferredResult(), code, node.span, true); |
| 6508 } |
| 6509 MethodMember.prototype._invokeConstructor = function(context, node, target, args
, argsString) { |
| 6510 this.declaringType.markUsed(); |
| 6511 if (!target.isType) { |
| 6512 var code = (this.get$constructorName() != '') ? ('' + this.declaringType.get
$jsname() + '.' + this.get$constructorName() + '\$ctor.call(' + argsString + ')'
) : ('' + this.declaringType.get$jsname() + '.call(' + argsString + ')'); |
| 6513 return new Value(target.get$type(), code, node.span, true); |
| 6514 } |
| 6515 else { |
| 6516 var code = (this.get$constructorName() != '') ? ('new ' + this.declaringType
.get$jsname() + '.' + this.get$constructorName() + '\$ctor(' + argsString + ')')
: ('new ' + this.declaringType.get$jsname() + '(' + argsString + ')'); |
| 6517 if (this.isConst && (node instanceof NewExpression) && node.get$dynamic().ge
t$isConst()) { |
| 6518 return this._invokeConstConstructor(node, code, target, args); |
| 6519 } |
| 6520 else { |
| 6521 return new Value(target.get$type(), code, node.span, true); |
| 6522 } |
| 6523 } |
| 6524 } |
| 6525 MethodMember.prototype._invokeConstConstructor = function(node, code, target, ar
gs) { |
| 6526 var fields = new HashMapImplementation(); |
| 6527 for (var i = 0; |
| 6528 i < this.parameters.length; i++) { |
| 6529 var param = this.parameters.$index(i); |
| 6530 if (param.get$isInitializer()) { |
| 6531 var value = null; |
| 6532 if (i < args.get$length()) { |
| 6533 value = args.values.$index(i); |
| 6534 } |
| 6535 else { |
| 6536 value = args.getValue(param.name); |
| 6537 if (value == null) { |
| 6538 value = param.value; |
| 6539 } |
| 6540 } |
| 6541 fields.$setindex(param.name, value); |
| 6542 } |
| 6543 } |
| 6544 if (this.definition.initializers != null) { |
| 6545 this.generator._pushBlock(false); |
| 6546 for (var j = 0; |
| 6547 j < this.definition.formals.length; j++) { |
| 6548 var name = this.definition.formals.$index(j).name.name; |
| 6549 var value = null; |
| 6550 if (j < args.get$length()) { |
| 6551 value = args.values.$index(j); |
| 6552 } |
| 6553 else { |
| 6554 value = args.getValue(this.parameters.$index(j).name); |
| 6555 if (value == null) { |
| 6556 value = this.parameters.$index(j).value; |
| 6557 } |
| 6558 } |
| 6559 this.generator._scope._vars.$setindex(name, value); |
| 6560 } |
| 6561 var $$list = this.definition.initializers; |
| 6562 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6563 var init = $$list.$index($$i); |
| 6564 if ((init instanceof CallExpression)) { |
| 6565 var delegateArgs = this.generator._makeArgs(init.get$arguments()); |
| 6566 var value = this.initDelegate.invoke(this.generator, node, target, deleg
ateArgs, false); |
| 6567 if ((init.target instanceof ThisExpression)) { |
| 6568 return value; |
| 6569 } |
| 6570 else { |
| 6571 if ((value instanceof GlobalValue)) { |
| 6572 value = value.get$exp(); |
| 6573 } |
| 6574 var $list0 = value.get$fields().getKeys$0(); |
| 6575 for (var $i0 = value.get$fields().getKeys$0().iterator$0(); $i0.hasNex
t$0(); ) { |
| 6576 var fname = $i0.next$0(); |
| 6577 fields.$setindex(fname, value.get$fields().$index(fname)); |
| 6578 } |
| 6579 } |
| 6580 } |
| 6581 else { |
| 6582 var assign = init; |
| 6583 var x = assign.x; |
| 6584 var fname = x.name.name; |
| 6585 var val = this.generator.visitValue(assign.y); |
| 6586 if (!val.get$isConst()) { |
| 6587 $globals.world.error('invalid non-const initializer in const construct
or', assign.y.span); |
| 6588 } |
| 6589 fields.$setindex(fname, val); |
| 6590 } |
| 6591 } |
| 6592 this.generator._popBlock(); |
| 6593 } |
| 6594 var $$list = this.declaringType.get$members().getValues(); |
| 6595 for (var $$i = this.declaringType.get$members().getValues().iterator$0(); $$i.
hasNext$0(); ) { |
| 6596 var f = $$i.next$0(); |
| 6597 if ((f instanceof FieldMember) && !f.get$isStatic() && !fields.containsKey(f
.name)) { |
| 6598 if (!f.get$isFinal()) { |
| 6599 $globals.world.error(('const class "' + this.declaringType.name + '" has
non-final ') + ('field "' + f.name + '"'), f.span); |
| 6600 } |
| 6601 if (f.value != null) { |
| 6602 fields.$setindex(f.name, f.computeValue$0()); |
| 6603 } |
| 6604 } |
| 6605 } |
| 6606 return $globals.world.gen.globalForConst(ConstObjectValue.ConstObjectValue$fac
tory(target.get$type(), fields, code, node.span), args.values); |
| 6607 } |
| 6608 MethodMember.prototype._invokeBuiltin = function(context, node, target, args, ar
gsCode, isDynamic) { |
| 6609 var allConst = target.get$isConst() && args.values.every((function (arg) { |
| 6610 return arg.get$isConst(); |
| 6611 }) |
| 6612 ); |
| 6613 if (this.declaringType.get$isNum()) { |
| 6614 if (!allConst) { |
| 6615 var code; |
| 6616 if (this.name == ':negate') { |
| 6617 code = ('-' + target.code); |
| 6618 } |
| 6619 else if (this.name == ':bit_not') { |
| 6620 code = ('~' + target.code); |
| 6621 } |
| 6622 else if (this.name == ':truncdiv' || this.name == ':mod') { |
| 6623 $globals.world.gen.corejs.useOperator(this.name); |
| 6624 code = ('' + this.get$jsname() + '(' + target.code + ', ' + argsCode.$in
dex(0) + ')'); |
| 6625 } |
| 6626 else { |
| 6627 var op = TokenKind.rawOperatorFromMethod(this.name); |
| 6628 code = ('' + target.code + ' ' + op + ' ' + argsCode.$index(0)); |
| 6629 } |
| 6630 return new Value(this.get$inferredResult(), code, node.span, true); |
| 6631 } |
| 6632 else { |
| 6633 var value; |
| 6634 var val0, val1, ival0, ival1; |
| 6635 val0 = target.get$dynamic().get$actualValue(); |
| 6636 ival0 = val0.toInt(); |
| 6637 if (args.values.length > 0) { |
| 6638 val1 = args.values.$index(0).get$dynamic().get$actualValue(); |
| 6639 ival1 = val1.toInt(); |
| 6640 } |
| 6641 switch (this.name) { |
| 6642 case ':negate': |
| 6643 |
| 6644 value = -val0; |
| 6645 break; |
| 6646 |
| 6647 case ':add': |
| 6648 |
| 6649 value = val0 + val1; |
| 6650 break; |
| 6651 |
| 6652 case ':sub': |
| 6653 |
| 6654 value = val0 - val1; |
| 6655 break; |
| 6656 |
| 6657 case ':mul': |
| 6658 |
| 6659 value = val0 * val1; |
| 6660 break; |
| 6661 |
| 6662 case ':div': |
| 6663 |
| 6664 value = val0 / val1; |
| 6665 break; |
| 6666 |
| 6667 case ':truncdiv': |
| 6668 |
| 6669 value = $truncdiv(val0, val1); |
| 6670 break; |
| 6671 |
| 6672 case ':mod': |
| 6673 |
| 6674 value = $mod(val0, val1); |
| 6675 break; |
| 6676 |
| 6677 case ':eq': |
| 6678 |
| 6679 value = val0 == val1; |
| 6680 break; |
| 6681 |
| 6682 case ':lt': |
| 6683 |
| 6684 value = val0 < val1; |
| 6685 break; |
| 6686 |
| 6687 case ':gt': |
| 6688 |
| 6689 value = val0 > val1; |
| 6690 break; |
| 6691 |
| 6692 case ':lte': |
| 6693 |
| 6694 value = val0 <= val1; |
| 6695 break; |
| 6696 |
| 6697 case ':gte': |
| 6698 |
| 6699 value = val0 >= val1; |
| 6700 break; |
| 6701 |
| 6702 case ':ne': |
| 6703 |
| 6704 value = val0 != val1; |
| 6705 break; |
| 6706 |
| 6707 case ':bit_not': |
| 6708 |
| 6709 value = (~ival0).toDouble(); |
| 6710 break; |
| 6711 |
| 6712 case ':bit_or': |
| 6713 |
| 6714 value = (ival0 | ival1).toDouble(); |
| 6715 break; |
| 6716 |
| 6717 case ':bit_xor': |
| 6718 |
| 6719 value = (ival0 ^ ival1).toDouble(); |
| 6720 break; |
| 6721 |
| 6722 case ':bit_and': |
| 6723 |
| 6724 value = (ival0 & ival1).toDouble(); |
| 6725 break; |
| 6726 |
| 6727 case ':shl': |
| 6728 |
| 6729 value = (ival0 << ival1).toDouble(); |
| 6730 break; |
| 6731 |
| 6732 case ':sar': |
| 6733 |
| 6734 value = (ival0 >> ival1).toDouble(); |
| 6735 break; |
| 6736 |
| 6737 case ':shr': |
| 6738 |
| 6739 value = (ival0 >>> ival1).toDouble(); |
| 6740 break; |
| 6741 |
| 6742 } |
| 6743 return EvaluatedValue.EvaluatedValue$factory(this.get$inferredResult(), va
lue, ("" + value), node.span); |
| 6744 } |
| 6745 } |
| 6746 else if (this.declaringType.get$isString()) { |
| 6747 if (this.name == ':index') { |
| 6748 return new Value(this.declaringType, ('' + target.code + '[' + argsCode.$i
ndex(0) + ']'), node.span, true); |
| 6749 } |
| 6750 else if (this.name == ':add') { |
| 6751 if (allConst) { |
| 6752 var value = this._normConcat(target, args.values.$index(0)); |
| 6753 return EvaluatedValue.EvaluatedValue$factory($globals.world.stringType,
value, value, node.span); |
| 6754 } |
| 6755 return new Value(this.declaringType, ('' + target.code + ' + ' + argsCode.
$index(0)), node.span, true); |
| 6756 } |
| 6757 } |
| 6758 else if (this.declaringType.get$isNative()) { |
| 6759 if (this.name == ':index') { |
| 6760 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde
x(0) + ']'), node.span, true); |
| 6761 } |
| 6762 else if (this.name == ':setindex') { |
| 6763 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde
x(0) + '] = ' + argsCode.$index(1)), node.span, true); |
| 6764 } |
| 6765 } |
| 6766 if (this.name == ':eq' || this.name == ':ne') { |
| 6767 var op = this.name == ':eq' ? '==' : '!='; |
| 6768 if (this.name == ':ne') { |
| 6769 target.invoke(context, ':eq', node, args, isDynamic); |
| 6770 } |
| 6771 if (allConst) { |
| 6772 var val0 = target.get$dynamic().get$actualValue(); |
| 6773 var val1 = args.values.$index(0).get$dynamic().get$actualValue(); |
| 6774 var newVal = this.name == ':eq' ? $eq(val0, val1) : $ne(val0, val1); |
| 6775 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, n
ewVal, ("" + newVal), node.span); |
| 6776 } |
| 6777 if ($eq(argsCode.$index(0), 'null')) { |
| 6778 return new Value(this.get$inferredResult(), ('' + target.code + ' ' + op +
' null'), node.span, true); |
| 6779 } |
| 6780 else if (target.get$type().get$isNum() || target.get$type().get$isString())
{ |
| 6781 return new Value(this.get$inferredResult(), ('' + target.code + ' ' + op +
' ' + argsCode.$index(0)), node.span, true); |
| 6782 } |
| 6783 $globals.world.gen.corejs.useOperator(this.name); |
| 6784 return new Value(this.get$inferredResult(), ('' + this.get$jsname() + '(' +
target.code + ', ' + argsCode.$index(0) + ')'), node.span, true); |
| 6785 } |
| 6786 if (this.get$isCallMethod()) { |
| 6787 this.declaringType.markUsed(); |
| 6788 return new Value(this.get$inferredResult(), ('' + target.code + '(' + String
s.join(argsCode, ", ") + ')'), node.span, true); |
| 6789 } |
| 6790 if (this.name == ':index') { |
| 6791 $globals.world.gen.corejs.useIndex = true; |
| 6792 } |
| 6793 else if (this.name == ':setindex') { |
| 6794 $globals.world.gen.corejs.useSetIndex = true; |
| 6795 } |
| 6796 var argsString = Strings.join(argsCode, ', '); |
| 6797 return new Value(this.get$inferredResult(), ('' + target.code + '.' + this.get
$jsname() + '(' + argsString + ')'), node.span, true); |
| 6798 } |
| 6799 MethodMember.prototype._normConcat = function(a, b) { |
| 6800 var val0 = a.get$dynamic().get$actualValue(); |
| 6801 var quote0 = val0.$index(0); |
| 6802 val0 = val0.substring$2(1, val0.length - 1); |
| 6803 var val1 = b.get$dynamic().get$actualValue(); |
| 6804 var quote1 = null; |
| 6805 if (b.get$type().get$isString()) { |
| 6806 quote1 = val1.$index(0); |
| 6807 val1 = val1.substring$2(1, val1.length - 1); |
| 6808 } |
| 6809 var value; |
| 6810 if ($eq(quote0, quote1) || quote1 == null) { |
| 6811 value = ('' + quote0 + val0 + val1 + quote0); |
| 6812 } |
| 6813 else if ($eq(quote0, '"')) { |
| 6814 value = ('' + quote0 + val0 + toDoubleQuote(val1) + quote0); |
| 6815 } |
| 6816 else { |
| 6817 value = ('' + quote1 + toDoubleQuote(val0) + val1 + quote1); |
| 6818 } |
| 6819 return value; |
| 6820 } |
| 6821 MethodMember.prototype.resolve = function() { |
| 6822 this.isStatic = this.declaringType.get$isTop(); |
| 6823 this.isConst = false; |
| 6824 this.isFactory = false; |
| 6825 this.isAbstract = !this.declaringType.get$isClass(); |
| 6826 if (this.definition.modifiers != null) { |
| 6827 var $$list = this.definition.modifiers; |
| 6828 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6829 var mod = $$list.$index($$i); |
| 6830 if ($eq(mod.kind, 86/*TokenKind.STATIC*/)) { |
| 6831 if (this.isStatic) { |
| 6832 $globals.world.error('duplicate static modifier', mod.span); |
| 6833 } |
| 6834 this.isStatic = true; |
| 6835 } |
| 6836 else if (this.get$isConstructor() && $eq(mod.kind, 92/*TokenKind.CONST*/))
{ |
| 6837 if (this.isConst) { |
| 6838 $globals.world.error('duplicate const modifier', mod.span); |
| 6839 } |
| 6840 this.isConst = true; |
| 6841 } |
| 6842 else if ($eq(mod.kind, 75/*TokenKind.FACTORY*/)) { |
| 6843 if (this.isFactory) { |
| 6844 $globals.world.error('duplicate factory modifier', mod.span); |
| 6845 } |
| 6846 this.isFactory = true; |
| 6847 } |
| 6848 else if ($eq(mod.kind, 71/*TokenKind.ABSTRACT*/)) { |
| 6849 if (this.isAbstract) { |
| 6850 if (this.declaringType.get$isClass()) { |
| 6851 $globals.world.error('duplicate abstract modifier', mod.span); |
| 6852 } |
| 6853 else { |
| 6854 $globals.world.error('abstract modifier not allowed on interface mem
bers', mod.span); |
| 6855 } |
| 6856 } |
| 6857 this.isAbstract = true; |
| 6858 } |
| 6859 else { |
| 6860 $globals.world.error(('' + mod + ' modifier not allowed on method'), mod
.span); |
| 6861 } |
| 6862 } |
| 6863 } |
| 6864 if (this.isFactory) { |
| 6865 this.isStatic = true; |
| 6866 } |
| 6867 if (this.definition.typeParameters != null) { |
| 6868 if (!this.isFactory) { |
| 6869 $globals.world.error('Only factories are allowed to have explicit type par
ameters', this.definition.typeParameters.$index(0).span); |
| 6870 } |
| 6871 else { |
| 6872 this.typeParameters = this.definition.typeParameters; |
| 6873 var $$list = this.definition.typeParameters; |
| 6874 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6875 var tp = $$list.$index($$i); |
| 6876 tp.set$enclosingElement(this); |
| 6877 tp.resolve$0(); |
| 6878 } |
| 6879 } |
| 6880 } |
| 6881 if (this.get$isOperator() && this.isStatic && !this.get$isCallMethod()) { |
| 6882 $globals.world.error(('operator method may not be static "' + this.name + '"
'), this.get$span()); |
| 6883 } |
| 6884 if (this.isAbstract) { |
| 6885 if (this.definition.body != null && !(this.declaringType.get$definition() in
stanceof FunctionTypeDefinition)) { |
| 6886 $globals.world.error('abstract method can not have a body', this.get$span(
)); |
| 6887 } |
| 6888 if (this.isStatic && !(this.declaringType.get$definition() instanceof Functi
onTypeDefinition)) { |
| 6889 $globals.world.error('static method can not be abstract', this.get$span())
; |
| 6890 } |
| 6891 } |
| 6892 else { |
| 6893 if (this.definition.body == null && !this.get$isConstructor() && !this.get$i
sNative()) { |
| 6894 $globals.world.error('method needs a body', this.get$span()); |
| 6895 } |
| 6896 } |
| 6897 if (this.get$isConstructor() && !this.isFactory) { |
| 6898 this.returnType = this.declaringType; |
| 6899 } |
| 6900 else { |
| 6901 this.returnType = this.resolveType(this.definition.returnType, false); |
| 6902 } |
| 6903 this.parameters = []; |
| 6904 var $$list = this.definition.formals; |
| 6905 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6906 var formal = $$list.$index($$i); |
| 6907 var param = new Parameter(formal, this); |
| 6908 param.resolve$0(); |
| 6909 this.parameters.add(param); |
| 6910 } |
| 6911 if (!this.isLambda) { |
| 6912 this.get$library()._addMember(this); |
| 6913 } |
| 6914 } |
| 6915 MethodMember.prototype.resolveType = function(node, typeErrors) { |
| 6916 var t = lang_Element.prototype.resolveType.call(this, node, typeErrors); |
| 6917 if (this.isStatic && (t instanceof ParameterType) && (this.typeParameters == n
ull || !this.typeParameters.some((function (p) { |
| 6918 return p === t; |
| 6919 }) |
| 6920 ))) { |
| 6921 $globals.world.error('using type parameter in static context.', node.span); |
| 6922 } |
| 6923 return t; |
| 6924 } |
| 6925 MethodMember.prototype._get$3 = function($0, $1, $2) { |
| 6926 return this._get($0, $1, $2, false); |
| 6927 }; |
| 6928 MethodMember.prototype._get$3$isDynamic = MethodMember.prototype._get; |
| 6929 MethodMember.prototype._get$4 = MethodMember.prototype._get; |
| 6930 MethodMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 6931 return this._set($0, $1, $2, $3, false); |
| 6932 }; |
| 6933 MethodMember.prototype._set$4$isDynamic = MethodMember.prototype._set; |
| 6934 MethodMember.prototype._set$5 = MethodMember.prototype._set; |
| 6935 MethodMember.prototype.canInvoke$2 = MethodMember.prototype.canInvoke; |
| 6936 MethodMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 6937 return this.invoke($0, $1, $2, $3, false); |
| 6938 }; |
| 6939 MethodMember.prototype.invoke$4$isDynamic = MethodMember.prototype.invoke; |
| 6940 MethodMember.prototype.invoke$5 = MethodMember.prototype.invoke; |
| 6941 MethodMember.prototype.namesInOrder$1 = MethodMember.prototype.namesInOrder; |
| 6942 MethodMember.prototype.provideFieldSyntax$0 = MethodMember.prototype.provideFiel
dSyntax; |
| 6943 MethodMember.prototype.providePropertySyntax$0 = MethodMember.prototype.provideP
ropertySyntax; |
| 6944 MethodMember.prototype.resolve$0 = MethodMember.prototype.resolve; |
| 6945 // ********** Code for MemberSet ************** |
| 6946 function MemberSet(member, isVar) { |
| 6947 this.name = member.name; |
| 6948 this.members = [member]; |
| 6949 this.jsname = member.get$jsname(); |
| 6950 this.isVar = isVar; |
| 6951 // Initializers done |
| 6952 } |
| 6953 MemberSet.prototype.get$members = function() { return this.members; }; |
| 6954 MemberSet.prototype.get$jsname = function() { return this.jsname; }; |
| 6955 MemberSet.prototype.get$isVar = function() { return this.isVar; }; |
| 6956 MemberSet.prototype.toString = function() { |
| 6957 return ('' + this.name + ':' + this.members.length); |
| 6958 } |
| 6959 MemberSet.prototype.get$containsMethods = function() { |
| 6960 return this.members.some((function (m) { |
| 6961 return (m instanceof MethodMember); |
| 6962 }) |
| 6963 ); |
| 6964 } |
| 6965 MemberSet.prototype.add = function(member) { |
| 6966 return this.members.add(member); |
| 6967 } |
| 6968 MemberSet.prototype.get$isStatic = function() { |
| 6969 return this.members.length == 1 && this.members.$index(0).get$isStatic(); |
| 6970 } |
| 6971 MemberSet.prototype.get$isOperator = function() { |
| 6972 return this.members.$index(0).get$isOperator(); |
| 6973 } |
| 6974 MemberSet.prototype.canInvoke = function(context, args) { |
| 6975 return this.members.some((function (m) { |
| 6976 return m.canInvoke$2(context, args); |
| 6977 }) |
| 6978 ); |
| 6979 } |
| 6980 MemberSet.prototype._makeError = function(node, target, action) { |
| 6981 if (!target.get$type().get$isVar()) { |
| 6982 $globals.world.warning(('could not find applicable ' + action + ' for "' + t
his.name + '"'), node.span); |
| 6983 } |
| 6984 return new Value($globals.world.varType, ('' + target.code + '.' + this.jsname
+ '() /*no applicable ' + action + '*/'), node.span, true); |
| 6985 } |
| 6986 MemberSet.prototype.get$treatAsField = function() { |
| 6987 if (this._treatAsField == null) { |
| 6988 this._treatAsField = !this.isVar; |
| 6989 var $$list = this.members; |
| 6990 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6991 var member = $$list.$index($$i); |
| 6992 if (member.get$requiresFieldSyntax()) { |
| 6993 this._treatAsField = true; |
| 6994 break; |
| 6995 } |
| 6996 if (member.get$prefersPropertySyntax()) { |
| 6997 this._treatAsField = false; |
| 6998 } |
| 6999 } |
| 7000 var $$list = this.members; |
| 7001 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 7002 var member = $$list.$index($$i); |
| 7003 if (this._treatAsField) { |
| 7004 member.provideFieldSyntax$0(); |
| 7005 } |
| 7006 else { |
| 7007 member.providePropertySyntax$0(); |
| 7008 } |
| 7009 } |
| 7010 } |
| 7011 return this._treatAsField; |
| 7012 } |
| 7013 MemberSet.prototype._get = function(context, node, target, isDynamic) { |
| 7014 var returnValue; |
| 7015 var targets = this.members.filter((function (m) { |
| 7016 return m.get$canGet(); |
| 7017 }) |
| 7018 ); |
| 7019 if (this.isVar) { |
| 7020 targets.forEach$1((function (m) { |
| 7021 return m._get$3$isDynamic(context, node, target, true); |
| 7022 }) |
| 7023 ); |
| 7024 returnValue = new Value(this._foldTypes(targets), null, node.span, true); |
| 7025 } |
| 7026 else { |
| 7027 if (this.members.length == 1) { |
| 7028 return this.members.$index(0)._get$4(context, node, target, isDynamic); |
| 7029 } |
| 7030 else if ($eq(targets.length, 1)) { |
| 7031 return targets.$index(0)._get$4(context, node, target, isDynamic); |
| 7032 } |
| 7033 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 7034 var member = $$i.next$0(); |
| 7035 var value = member._get$3$isDynamic(context, node, target, true); |
| 7036 returnValue = this._tryUnion(returnValue, value, node); |
| 7037 } |
| 7038 if (returnValue == null) { |
| 7039 return this._makeError(node, target, 'getter'); |
| 7040 } |
| 7041 } |
| 7042 if (returnValue.code == null) { |
| 7043 if (this.get$treatAsField()) { |
| 7044 return new Value(returnValue.get$type(), ('' + target.code + '.' + this.js
name), node.span, true); |
| 7045 } |
| 7046 else { |
| 7047 return new Value(returnValue.get$type(), ('' + target.code + '.get\$' + th
is.jsname + '()'), node.span, true); |
| 7048 } |
| 7049 } |
| 7050 return returnValue; |
| 7051 } |
| 7052 MemberSet.prototype._set = function(context, node, target, value, isDynamic) { |
| 7053 var returnValue; |
| 7054 var targets = this.members.filter((function (m) { |
| 7055 return m.get$canSet(); |
| 7056 }) |
| 7057 ); |
| 7058 if (this.isVar) { |
| 7059 targets.forEach$1((function (m) { |
| 7060 return m._set$4$isDynamic(context, node, target, value, true); |
| 7061 }) |
| 7062 ); |
| 7063 returnValue = new Value(this._foldTypes(targets), null, node.span, true); |
| 7064 } |
| 7065 else { |
| 7066 if (this.members.length == 1) { |
| 7067 return this.members.$index(0)._set$5(context, node, target, value, isDynam
ic); |
| 7068 } |
| 7069 else if ($eq(targets.length, 1)) { |
| 7070 return targets.$index(0)._set$5(context, node, target, value, isDynamic); |
| 7071 } |
| 7072 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 7073 var member = $$i.next$0(); |
| 7074 var res = member._set$4$isDynamic(context, node, target, value, true); |
| 7075 returnValue = this._tryUnion(returnValue, res, node); |
| 7076 } |
| 7077 if (returnValue == null) { |
| 7078 return this._makeError(node, target, 'setter'); |
| 7079 } |
| 7080 } |
| 7081 if (returnValue.code == null) { |
| 7082 if (this.get$treatAsField()) { |
| 7083 return new Value(returnValue.get$type(), ('' + target.code + '.' + this.js
name + ' = ' + value.code), node.span, true); |
| 7084 } |
| 7085 else { |
| 7086 return new Value(returnValue.get$type(), ('' + target.code + '.set\$' + th
is.jsname + '(' + value.code + ')'), node.span, true); |
| 7087 } |
| 7088 } |
| 7089 return returnValue; |
| 7090 } |
| 7091 MemberSet.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 7092 if (this.isVar && !this.get$isOperator()) { |
| 7093 return this.invokeOnVar(context, node, target, args); |
| 7094 } |
| 7095 if (this.members.length == 1) { |
| 7096 return this.members.$index(0).invoke$5(context, node, target, args, isDynami
c); |
| 7097 } |
| 7098 var targets = this.members.filter((function (m) { |
| 7099 return m.canInvoke$2(context, args); |
| 7100 }) |
| 7101 ); |
| 7102 if ($eq(targets.length, 1)) { |
| 7103 return targets.$index(0).invoke$5(context, node, target, args, isDynamic); |
| 7104 } |
| 7105 var returnValue = null; |
| 7106 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 7107 var member = $$i.next$0(); |
| 7108 var res = member.invoke$4$isDynamic(context, node, target, args, true); |
| 7109 returnValue = this._tryUnion(returnValue, res, node); |
| 7110 } |
| 7111 if (returnValue == null) { |
| 7112 return this._makeError(node, target, 'method'); |
| 7113 } |
| 7114 if (returnValue.code == null) { |
| 7115 if (this.name == ':call') { |
| 7116 return target._varCall(context, args); |
| 7117 } |
| 7118 else if (this.get$isOperator()) { |
| 7119 return this.invokeSpecial(target, args, returnValue.get$type()); |
| 7120 } |
| 7121 else { |
| 7122 return this.invokeOnVar(context, node, target, args); |
| 7123 } |
| 7124 } |
| 7125 return returnValue; |
| 7126 } |
| 7127 MemberSet.prototype.invokeSpecial = function(target, args, returnType) { |
| 7128 var argsString = args.getCode(); |
| 7129 if (this.name == ':index' || this.name == ':setindex') { |
| 7130 return new Value(returnType, ('' + target.code + '.' + this.jsname + '(' + a
rgsString + ')'), target.span, true); |
| 7131 } |
| 7132 else { |
| 7133 if (argsString.length > 0) argsString = (', ' + argsString); |
| 7134 $globals.world.gen.corejs.useOperator(this.name); |
| 7135 return new Value(returnType, ('' + this.jsname + '(' + target.code + argsStr
ing + ')'), target.span, true); |
| 7136 } |
| 7137 } |
| 7138 MemberSet.prototype.invokeOnVar = function(context, node, target, args) { |
| 7139 var member = this.getVarMember(context, node, args); |
| 7140 return member.invoke$4(context, node, target, args); |
| 7141 } |
| 7142 MemberSet.prototype._tryUnion = function(x, y, node) { |
| 7143 if (x == null) return y; |
| 7144 var type = Type.union(x.get$type(), y.get$type()); |
| 7145 if (x.code == y.code) { |
| 7146 if ($eq(type, x.get$type())) { |
| 7147 return x; |
| 7148 } |
| 7149 else if (x.get$isConst() || y.get$isConst()) { |
| 7150 $globals.world.internalError("unexpected: union of const values "); |
| 7151 } |
| 7152 else { |
| 7153 var ret = new Value(type, x.code, node.span, true); |
| 7154 ret.set$isSuper(x.isSuper && y.isSuper); |
| 7155 ret.set$needsTemp(x.needsTemp || y.needsTemp); |
| 7156 ret.set$isType(x.isType && y.isType); |
| 7157 return ret; |
| 7158 } |
| 7159 } |
| 7160 else { |
| 7161 return new Value(type, null, node.span, true); |
| 7162 } |
| 7163 } |
| 7164 MemberSet.prototype.getVarMember = function(context, node, args) { |
| 7165 if ($globals.world.objectType.varStubs == null) { |
| 7166 $globals.world.objectType.varStubs = new HashMapImplementation(); |
| 7167 } |
| 7168 var stubName = _getCallStubName(this.name, args); |
| 7169 var stub = $globals.world.objectType.varStubs.$index(stubName); |
| 7170 if (stub == null) { |
| 7171 var mset = context.findMembers(this.name).members; |
| 7172 var targets = mset.filter((function (m) { |
| 7173 return m.canInvoke$2(context, args); |
| 7174 }) |
| 7175 ); |
| 7176 stub = new VarMethodSet(this.name, stubName, targets, args, this._foldTypes(
targets)); |
| 7177 $globals.world.objectType.varStubs.$setindex(stubName, stub); |
| 7178 } |
| 7179 return stub; |
| 7180 } |
| 7181 MemberSet.prototype._foldTypes = function(targets) { |
| 7182 return reduce(map(targets, (function (t) { |
| 7183 return t.get$returnType(); |
| 7184 }) |
| 7185 ), Type.union, $globals.world.varType); |
| 7186 } |
| 7187 MemberSet.prototype._get$3 = function($0, $1, $2) { |
| 7188 return this._get($0, $1, $2, false); |
| 7189 }; |
| 7190 MemberSet.prototype._get$3$isDynamic = MemberSet.prototype._get; |
| 7191 MemberSet.prototype._get$4 = MemberSet.prototype._get; |
| 7192 MemberSet.prototype._set$4 = function($0, $1, $2, $3) { |
| 7193 return this._set($0, $1, $2, $3, false); |
| 7194 }; |
| 7195 MemberSet.prototype._set$4$isDynamic = MemberSet.prototype._set; |
| 7196 MemberSet.prototype._set$5 = MemberSet.prototype._set; |
| 7197 MemberSet.prototype.add$1 = MemberSet.prototype.add; |
| 7198 MemberSet.prototype.canInvoke$2 = MemberSet.prototype.canInvoke; |
| 7199 MemberSet.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 7200 return this.invoke($0, $1, $2, $3, false); |
| 7201 }; |
| 7202 MemberSet.prototype.invoke$4$isDynamic = MemberSet.prototype.invoke; |
| 7203 MemberSet.prototype.invoke$5 = MemberSet.prototype.invoke; |
| 7204 MemberSet.prototype.toString$0 = MemberSet.prototype.toString; |
| 7205 // ********** Code for FactoryMap ************** |
| 7206 function FactoryMap() { |
| 7207 this.factories = new HashMapImplementation(); |
| 7208 // Initializers done |
| 7209 } |
| 7210 FactoryMap.prototype.getFactoriesFor = function(typeName) { |
| 7211 var ret = this.factories.$index(typeName); |
| 7212 if (ret == null) { |
| 7213 ret = new HashMapImplementation(); |
| 7214 this.factories.$setindex(typeName, ret); |
| 7215 } |
| 7216 return ret; |
| 7217 } |
| 7218 FactoryMap.prototype.addFactory = function(typeName, name, member) { |
| 7219 this.getFactoriesFor(typeName).$setindex(name, member); |
| 7220 } |
| 7221 FactoryMap.prototype.getFactory = function(typeName, name) { |
| 7222 return this.getFactoriesFor(typeName).$index(name); |
| 7223 } |
| 7224 FactoryMap.prototype.forEach = function(f) { |
| 7225 this.factories.forEach((function (_, constructors) { |
| 7226 constructors.forEach((function (_, member) { |
| 7227 f(member); |
| 7228 }) |
| 7229 ); |
| 7230 }) |
| 7231 ); |
| 7232 } |
| 7233 FactoryMap.prototype.forEach$1 = function($0) { |
| 7234 return this.forEach(to$call$1($0)); |
| 7235 }; |
| 7236 FactoryMap.prototype.getFactory$2 = FactoryMap.prototype.getFactory; |
| 7237 // ********** Code for Token ************** |
| 7238 function Token(kind, source, start, end) { |
| 7239 this.kind = kind; |
| 7240 this.source = source; |
| 7241 this.start = start; |
| 7242 this.end = end; |
| 7243 // Initializers done |
| 7244 } |
| 7245 Token.prototype.get$end = function() { return this.end; }; |
| 7246 Token.prototype.get$text = function() { |
| 7247 return this.source.get$text().substring(this.start, this.end); |
| 7248 } |
| 7249 Object.defineProperty(Token.prototype, "text", { |
| 7250 get: Token.prototype.get$text |
| 7251 }); |
| 7252 Token.prototype.toString = function() { |
| 7253 var kindText = TokenKind.kindToString(this.kind); |
| 7254 var actualText = this.get$text(); |
| 7255 if ($ne(kindText, actualText)) { |
| 7256 if (actualText.length > 10) { |
| 7257 actualText = actualText.substring$2(0, 8) + '...'; |
| 7258 } |
| 7259 return ('' + kindText + '(' + actualText + ')'); |
| 7260 } |
| 7261 else { |
| 7262 return kindText; |
| 7263 } |
| 7264 } |
| 7265 Token.prototype.get$span = function() { |
| 7266 return new SourceSpan(this.source, this.start, this.end); |
| 7267 } |
| 7268 Object.defineProperty(Token.prototype, "span", { |
| 7269 get: Token.prototype.get$span |
| 7270 }); |
| 7271 Token.prototype.end$0 = function() { |
| 7272 return this.end(); |
| 7273 }; |
| 7274 Token.prototype.start$0 = function() { |
| 7275 return this.start(); |
| 7276 }; |
| 7277 Token.prototype.toString$0 = Token.prototype.toString; |
| 7278 // ********** Code for ErrorToken ************** |
| 7279 $inherits(ErrorToken, Token); |
| 7280 function ErrorToken(kind, source, start, end, message) { |
| 7281 this.message = message; |
| 7282 // Initializers done |
| 7283 Token.call(this, kind, source, start, end); |
| 7284 } |
| 7285 // ********** Code for SourceFile ************** |
| 7286 function SourceFile(filename, _text) { |
| 7287 this.filename = filename; |
| 7288 this._lang_text = _text; |
| 7289 // Initializers done |
| 7290 } |
| 7291 SourceFile.prototype.get$orderInLibrary = function() { return this.orderInLibrar
y; }; |
| 7292 SourceFile.prototype.set$orderInLibrary = function(value) { return this.orderInL
ibrary = value; }; |
| 7293 SourceFile.prototype.get$text = function() { |
| 7294 return this._lang_text; |
| 7295 } |
| 7296 Object.defineProperty(SourceFile.prototype, "text", { |
| 7297 get: SourceFile.prototype.get$text, |
| 7298 set: SourceFile.prototype.set$text |
| 7299 }); |
| 7300 SourceFile.prototype.get$lineStarts = function() { |
| 7301 if (this._lang_lineStarts == null) { |
| 7302 var starts = [0]; |
| 7303 var index = 0; |
| 7304 while (index < this.get$text().length) { |
| 7305 index = this.get$text().indexOf('\n', index) + 1; |
| 7306 if (index <= 0) break; |
| 7307 starts.add$1(index); |
| 7308 } |
| 7309 starts.add$1(this.get$text().length + 1); |
| 7310 this._lang_lineStarts = starts; |
| 7311 } |
| 7312 return this._lang_lineStarts; |
| 7313 } |
| 7314 SourceFile.prototype.getLine = function(position) { |
| 7315 var starts = this.get$lineStarts(); |
| 7316 for (var i = 0; |
| 7317 i < starts.length; i++) { |
| 7318 if (starts.$index(i) > position) return i - 1; |
| 7319 } |
| 7320 $globals.world.internalError('bad position'); |
| 7321 } |
| 7322 SourceFile.prototype.getColumn = function(line, position) { |
| 7323 return position - this.get$lineStarts().$index(line); |
| 7324 } |
| 7325 SourceFile.prototype.getLocationMessage = function(message, start, end, includeT
ext) { |
| 7326 var line = this.getLine(start); |
| 7327 var column = this.getColumn(line, start); |
| 7328 var buf = new StringBufferImpl(('' + this.filename + ':' + (line + 1) + ':' +
(column + 1) + ': ' + message)); |
| 7329 if (includeText) { |
| 7330 buf.add$1('\n'); |
| 7331 var textLine; |
| 7332 if ((line + 2) < this._lang_lineStarts.length) { |
| 7333 textLine = this.get$text().substring(this._lang_lineStarts.$index(line), t
his._lang_lineStarts.$index(line + 1)); |
| 7334 } |
| 7335 else { |
| 7336 textLine = this.get$text().substring(this._lang_lineStarts.$index(line)) +
'\n'; |
| 7337 } |
| 7338 var toColumn = Math.min(column + (end - start), textLine.length); |
| 7339 if ($globals.options.useColors) { |
| 7340 buf.add$1(textLine.substring$2(0, column)); |
| 7341 buf.add$1($globals._RED_COLOR); |
| 7342 buf.add$1(textLine.substring$2(column, toColumn)); |
| 7343 buf.add$1($globals._NO_COLOR); |
| 7344 buf.add$1(textLine.substring$1(toColumn)); |
| 7345 } |
| 7346 else { |
| 7347 buf.add$1(textLine); |
| 7348 } |
| 7349 var i = 0; |
| 7350 for (; i < column; i++) { |
| 7351 buf.add$1(' '); |
| 7352 } |
| 7353 if ($globals.options.useColors) buf.add$1($globals._RED_COLOR); |
| 7354 for (; i < toColumn; i++) { |
| 7355 buf.add$1('^'); |
| 7356 } |
| 7357 if ($globals.options.useColors) buf.add$1($globals._NO_COLOR); |
| 7358 } |
| 7359 return buf.toString$0(); |
| 7360 } |
| 7361 SourceFile.prototype.compareTo = function(other) { |
| 7362 if (this.orderInLibrary != null && other.orderInLibrary != null) { |
| 7363 return this.orderInLibrary - other.orderInLibrary; |
| 7364 } |
| 7365 else { |
| 7366 return this.filename.compareTo(other.filename); |
| 7367 } |
| 7368 } |
| 7369 SourceFile.prototype.compareTo$1 = SourceFile.prototype.compareTo; |
| 7370 SourceFile.prototype.getColumn$2 = SourceFile.prototype.getColumn; |
| 7371 SourceFile.prototype.getLine$1 = SourceFile.prototype.getLine; |
| 7372 // ********** Code for SourceSpan ************** |
| 7373 function SourceSpan(file, start, end) { |
| 7374 this.file = file; |
| 7375 this.start = start; |
| 7376 this.end = end; |
| 7377 // Initializers done |
| 7378 } |
| 7379 SourceSpan.prototype.get$file = function() { return this.file; }; |
| 7380 SourceSpan.prototype.get$end = function() { return this.end; }; |
| 7381 SourceSpan.prototype.get$text = function() { |
| 7382 return this.file.get$text().substring(this.start, this.end); |
| 7383 } |
| 7384 Object.defineProperty(SourceSpan.prototype, "text", { |
| 7385 get: SourceSpan.prototype.get$text |
| 7386 }); |
| 7387 SourceSpan.prototype.toMessageString = function(message) { |
| 7388 return this.file.getLocationMessage(message, this.start, this.end, true); |
| 7389 } |
| 7390 SourceSpan.prototype.get$locationText = function() { |
| 7391 var line = this.file.getLine(this.start); |
| 7392 var column = this.file.getColumn(line, this.start); |
| 7393 return ('' + this.file.filename + ':' + (line + 1) + ':' + (column + 1)); |
| 7394 } |
| 7395 SourceSpan.prototype.compareTo = function(other) { |
| 7396 if ($eq(this.file, other.file)) { |
| 7397 var d = this.start - other.start; |
| 7398 return d == 0 ? (this.end - other.end) : d; |
| 7399 } |
| 7400 return this.file.compareTo(other.file); |
| 7401 } |
| 7402 SourceSpan.prototype.compareTo$1 = SourceSpan.prototype.compareTo; |
| 7403 SourceSpan.prototype.end$0 = function() { |
| 7404 return this.end(); |
| 7405 }; |
| 7406 SourceSpan.prototype.start$0 = function() { |
| 7407 return this.start(); |
| 7408 }; |
| 7409 // ********** Code for InterpStack ************** |
| 7410 function InterpStack(previous, quote, isMultiline) { |
| 7411 this.previous = previous; |
| 7412 this.quote = quote; |
| 7413 this.isMultiline = isMultiline; |
| 7414 this.depth = -1; |
| 7415 // Initializers done |
| 7416 } |
| 7417 InterpStack.prototype.get$previous = function() { return this.previous; }; |
| 7418 InterpStack.prototype.set$previous = function(value) { return this.previous = va
lue; }; |
| 7419 InterpStack.prototype.get$quote = function() { return this.quote; }; |
| 7420 InterpStack.prototype.get$isMultiline = function() { return this.isMultiline; }; |
| 7421 InterpStack.prototype.pop = function() { |
| 7422 return this.previous; |
| 7423 } |
| 7424 InterpStack.push = function(stack, quote, isMultiline) { |
| 7425 var newStack = new InterpStack(stack, quote, isMultiline); |
| 7426 if (stack != null) newStack.set$previous(stack); |
| 7427 return newStack; |
| 7428 } |
| 7429 InterpStack.prototype.next$0 = function() { |
| 7430 return this.next(); |
| 7431 }; |
| 7432 // ********** Code for TokenizerHelpers ************** |
| 7433 function TokenizerHelpers() { |
| 7434 // Initializers done |
| 7435 } |
| 7436 TokenizerHelpers.isIdentifierStart = function(c) { |
| 7437 return ((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c == 95); |
| 7438 } |
| 7439 TokenizerHelpers.isDigit = function(c) { |
| 7440 return (c >= 48 && c <= 57); |
| 7441 } |
| 7442 TokenizerHelpers.isHexDigit = function(c) { |
| 7443 return (TokenizerHelpers.isDigit(c) || (c >= 97 && c <= 102) || (c >= 65 && c
<= 70)); |
| 7444 } |
| 7445 TokenizerHelpers.isIdentifierPart = function(c) { |
| 7446 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c) |
| c == 36); |
| 7447 } |
| 7448 TokenizerHelpers.isInterpIdentifierPart = function(c) { |
| 7449 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c)); |
| 7450 } |
| 7451 // ********** Code for TokenizerBase ************** |
| 7452 $inherits(TokenizerBase, TokenizerHelpers); |
| 7453 function TokenizerBase(_source, _skipWhitespace, index) { |
| 7454 this._source = _source; |
| 7455 this._skipWhitespace = _skipWhitespace; |
| 7456 this._index = index; |
| 7457 // Initializers done |
| 7458 TokenizerHelpers.call(this); |
| 7459 this._text = this._source.get$text(); |
| 7460 } |
| 7461 TokenizerBase.prototype._nextChar = function() { |
| 7462 if (this._index < this._text.length) { |
| 7463 return this._text.charCodeAt(this._index++); |
| 7464 } |
| 7465 else { |
| 7466 return 0; |
| 7467 } |
| 7468 } |
| 7469 TokenizerBase.prototype._peekChar = function() { |
| 7470 if (this._index < this._text.length) { |
| 7471 return this._text.charCodeAt(this._index); |
| 7472 } |
| 7473 else { |
| 7474 return 0; |
| 7475 } |
| 7476 } |
| 7477 TokenizerBase.prototype._maybeEatChar = function(ch) { |
| 7478 if (this._index < this._text.length) { |
| 7479 if (this._text.charCodeAt(this._index) == ch) { |
| 7480 this._index++; |
| 7481 return true; |
| 7482 } |
| 7483 else { |
| 7484 return false; |
| 7485 } |
| 7486 } |
| 7487 else { |
| 7488 return false; |
| 7489 } |
| 7490 } |
| 7491 TokenizerBase.prototype._finishToken = function(kind) { |
| 7492 return new Token(kind, this._source, this._startIndex, this._index); |
| 7493 } |
| 7494 TokenizerBase.prototype._errorToken = function(message) { |
| 7495 return new ErrorToken(65/*TokenKind.ERROR*/, this._source, this._startIndex, t
his._index, message); |
| 7496 } |
| 7497 TokenizerBase.prototype.finishWhitespace = function() { |
| 7498 this._index--; |
| 7499 while (this._index < this._text.length) { |
| 7500 var ch = this._text.charCodeAt(this._index++); |
| 7501 if (ch == 32 || ch == 9 || ch == 13) { |
| 7502 } |
| 7503 else if (ch == 10) { |
| 7504 if (!this._skipWhitespace) { |
| 7505 return this._finishToken(63/*TokenKind.WHITESPACE*/); |
| 7506 } |
| 7507 } |
| 7508 else { |
| 7509 this._index--; |
| 7510 if (this._skipWhitespace) { |
| 7511 return this.next(); |
| 7512 } |
| 7513 else { |
| 7514 return this._finishToken(63/*TokenKind.WHITESPACE*/); |
| 7515 } |
| 7516 } |
| 7517 } |
| 7518 return this._finishToken(1/*TokenKind.END_OF_FILE*/); |
| 7519 } |
| 7520 TokenizerBase.prototype.finishHashBang = function() { |
| 7521 while (true) { |
| 7522 var ch = this._nextChar(); |
| 7523 if (ch == 0 || ch == 10 || ch == 13) { |
| 7524 return this._finishToken(13/*TokenKind.HASHBANG*/); |
| 7525 } |
| 7526 } |
| 7527 } |
| 7528 TokenizerBase.prototype.finishSingleLineComment = function() { |
| 7529 while (true) { |
| 7530 var ch = this._nextChar(); |
| 7531 if (ch == 0 || ch == 10 || ch == 13) { |
| 7532 if (this._skipWhitespace) { |
| 7533 return this.next(); |
| 7534 } |
| 7535 else { |
| 7536 return this._finishToken(64/*TokenKind.COMMENT*/); |
| 7537 } |
| 7538 } |
| 7539 } |
| 7540 } |
| 7541 TokenizerBase.prototype.finishMultiLineComment = function() { |
| 7542 while (true) { |
| 7543 var ch = this._nextChar(); |
| 7544 if (ch == 0) { |
| 7545 return this._finishToken(67/*TokenKind.INCOMPLETE_COMMENT*/); |
| 7546 } |
| 7547 else if (ch == 42) { |
| 7548 if (this._maybeEatChar(47)) { |
| 7549 if (this._skipWhitespace) { |
| 7550 return this.next(); |
| 7551 } |
| 7552 else { |
| 7553 return this._finishToken(64/*TokenKind.COMMENT*/); |
| 7554 } |
| 7555 } |
| 7556 } |
| 7557 } |
| 7558 return this._errorToken(); |
| 7559 } |
| 7560 TokenizerBase.prototype.eatDigits = function() { |
| 7561 while (this._index < this._text.length) { |
| 7562 if (TokenizerHelpers.isDigit(this._text.charCodeAt(this._index))) { |
| 7563 this._index++; |
| 7564 } |
| 7565 else { |
| 7566 return; |
| 7567 } |
| 7568 } |
| 7569 } |
| 7570 TokenizerBase.prototype.eatHexDigits = function() { |
| 7571 while (this._index < this._text.length) { |
| 7572 if (TokenizerHelpers.isHexDigit(this._text.charCodeAt(this._index))) { |
| 7573 this._index++; |
| 7574 } |
| 7575 else { |
| 7576 return; |
| 7577 } |
| 7578 } |
| 7579 } |
| 7580 TokenizerBase.prototype.maybeEatHexDigit = function() { |
| 7581 if (this._index < this._text.length && TokenizerHelpers.isHexDigit(this._text.
charCodeAt(this._index))) { |
| 7582 this._index++; |
| 7583 return true; |
| 7584 } |
| 7585 return false; |
| 7586 } |
| 7587 TokenizerBase.prototype.finishHex = function() { |
| 7588 this.eatHexDigits(); |
| 7589 return this._finishToken(61/*TokenKind.HEX_INTEGER*/); |
| 7590 } |
| 7591 TokenizerBase.prototype.finishNumber = function() { |
| 7592 this.eatDigits(); |
| 7593 if (this._peekChar() == 46) { |
| 7594 this._nextChar(); |
| 7595 if (TokenizerHelpers.isDigit(this._peekChar())) { |
| 7596 this.eatDigits(); |
| 7597 return this.finishNumberExtra(62/*TokenKind.DOUBLE*/); |
| 7598 } |
| 7599 else { |
| 7600 this._index--; |
| 7601 } |
| 7602 } |
| 7603 return this.finishNumberExtra(60/*TokenKind.INTEGER*/); |
| 7604 } |
| 7605 TokenizerBase.prototype.finishNumberExtra = function(kind) { |
| 7606 if (this._maybeEatChar(101) || this._maybeEatChar(69)) { |
| 7607 kind = 62/*TokenKind.DOUBLE*/; |
| 7608 this._maybeEatChar(45); |
| 7609 this._maybeEatChar(43); |
| 7610 this.eatDigits(); |
| 7611 } |
| 7612 if (this._peekChar() != 0 && TokenizerHelpers.isIdentifierStart(this._peekChar
())) { |
| 7613 this._nextChar(); |
| 7614 return this._errorToken("illegal character in number"); |
| 7615 } |
| 7616 return this._finishToken(kind); |
| 7617 } |
| 7618 TokenizerBase.prototype.finishMultilineString = function(quote) { |
| 7619 while (true) { |
| 7620 var ch = this._nextChar(); |
| 7621 if (ch == 0) { |
| 7622 var kind = quote == 34 ? 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/ :
69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/; |
| 7623 return this._finishToken(kind); |
| 7624 } |
| 7625 else if (ch == quote) { |
| 7626 if (this._maybeEatChar(quote)) { |
| 7627 if (this._maybeEatChar(quote)) { |
| 7628 return this._finishToken(58/*TokenKind.STRING*/); |
| 7629 } |
| 7630 } |
| 7631 } |
| 7632 else if (ch == 36) { |
| 7633 this._interpStack = InterpStack.push(this._interpStack, quote, true); |
| 7634 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 7635 } |
| 7636 else if (ch == 92) { |
| 7637 if (!this.eatEscapeSequence()) { |
| 7638 return this._errorToken("invalid hex escape sequence"); |
| 7639 } |
| 7640 } |
| 7641 } |
| 7642 } |
| 7643 TokenizerBase.prototype._finishOpenBrace = function() { |
| 7644 var $0; |
| 7645 if (this._interpStack != null) { |
| 7646 if (this._interpStack.depth == -1) { |
| 7647 this._interpStack.depth = 1; |
| 7648 } |
| 7649 else { |
| 7650 ($0 = this._interpStack).depth = $0.depth + 1; |
| 7651 } |
| 7652 } |
| 7653 return this._finishToken(6/*TokenKind.LBRACE*/); |
| 7654 } |
| 7655 TokenizerBase.prototype._finishCloseBrace = function() { |
| 7656 var $0; |
| 7657 if (this._interpStack != null) { |
| 7658 ($0 = this._interpStack).depth = $0.depth - 1; |
| 7659 } |
| 7660 return this._finishToken(7/*TokenKind.RBRACE*/); |
| 7661 } |
| 7662 TokenizerBase.prototype.finishString = function(quote) { |
| 7663 if (this._maybeEatChar(quote)) { |
| 7664 if (this._maybeEatChar(quote)) { |
| 7665 return this.finishMultilineString(quote); |
| 7666 } |
| 7667 else { |
| 7668 return this._finishToken(58/*TokenKind.STRING*/); |
| 7669 } |
| 7670 } |
| 7671 return this.finishStringBody(quote); |
| 7672 } |
| 7673 TokenizerBase.prototype.finishRawString = function(quote) { |
| 7674 if (this._maybeEatChar(quote)) { |
| 7675 if (this._maybeEatChar(quote)) { |
| 7676 return this.finishMultilineRawString(quote); |
| 7677 } |
| 7678 else { |
| 7679 return this._finishToken(58/*TokenKind.STRING*/); |
| 7680 } |
| 7681 } |
| 7682 while (true) { |
| 7683 var ch = this._nextChar(); |
| 7684 if (ch == quote) { |
| 7685 return this._finishToken(58/*TokenKind.STRING*/); |
| 7686 } |
| 7687 else if (ch == 0) { |
| 7688 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 7689 } |
| 7690 } |
| 7691 } |
| 7692 TokenizerBase.prototype.finishMultilineRawString = function(quote) { |
| 7693 while (true) { |
| 7694 var ch = this._nextChar(); |
| 7695 if (ch == 0) { |
| 7696 var kind = quote == 34 ? 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/ :
69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/; |
| 7697 return this._finishToken(kind); |
| 7698 } |
| 7699 else if (ch == quote && this._maybeEatChar(quote) && this._maybeEatChar(quot
e)) { |
| 7700 return this._finishToken(58/*TokenKind.STRING*/); |
| 7701 } |
| 7702 } |
| 7703 } |
| 7704 TokenizerBase.prototype.finishStringBody = function(quote) { |
| 7705 while (true) { |
| 7706 var ch = this._nextChar(); |
| 7707 if (ch == quote) { |
| 7708 return this._finishToken(58/*TokenKind.STRING*/); |
| 7709 } |
| 7710 else if (ch == 36) { |
| 7711 this._interpStack = InterpStack.push(this._interpStack, quote, false); |
| 7712 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 7713 } |
| 7714 else if (ch == 0) { |
| 7715 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 7716 } |
| 7717 else if (ch == 92) { |
| 7718 if (!this.eatEscapeSequence()) { |
| 7719 return this._errorToken("invalid hex escape sequence"); |
| 7720 } |
| 7721 } |
| 7722 } |
| 7723 } |
| 7724 TokenizerBase.prototype.eatEscapeSequence = function() { |
| 7725 var hex; |
| 7726 switch (this._nextChar()) { |
| 7727 case 120: |
| 7728 |
| 7729 return this.maybeEatHexDigit() && this.maybeEatHexDigit(); |
| 7730 |
| 7731 case 117: |
| 7732 |
| 7733 if (this._maybeEatChar(123)) { |
| 7734 var start = this._index; |
| 7735 this.eatHexDigits(); |
| 7736 var chars = this._index - start; |
| 7737 if (chars > 0 && chars <= 6 && this._maybeEatChar(125)) { |
| 7738 hex = this._text.substring(start, start + chars); |
| 7739 break; |
| 7740 } |
| 7741 else { |
| 7742 return false; |
| 7743 } |
| 7744 } |
| 7745 else { |
| 7746 if (this.maybeEatHexDigit() && this.maybeEatHexDigit() && this.maybeEatH
exDigit() && this.maybeEatHexDigit()) { |
| 7747 hex = this._text.substring(this._index - 4, this._index); |
| 7748 break; |
| 7749 } |
| 7750 else { |
| 7751 return false; |
| 7752 } |
| 7753 } |
| 7754 |
| 7755 default: |
| 7756 |
| 7757 return true; |
| 7758 |
| 7759 } |
| 7760 var n = Parser.parseHex(hex); |
| 7761 return n < 0xD800 || n > 0xDFFF && n <= 0x10FFFF; |
| 7762 } |
| 7763 TokenizerBase.prototype.finishDot = function() { |
| 7764 if (TokenizerHelpers.isDigit(this._peekChar())) { |
| 7765 this.eatDigits(); |
| 7766 return this.finishNumberExtra(62/*TokenKind.DOUBLE*/); |
| 7767 } |
| 7768 else { |
| 7769 return this._finishToken(14/*TokenKind.DOT*/); |
| 7770 } |
| 7771 } |
| 7772 TokenizerBase.prototype.finishIdentifier = function(ch) { |
| 7773 if (this._interpStack != null && this._interpStack.depth == -1) { |
| 7774 this._interpStack.depth = 0; |
| 7775 if (ch == 36) { |
| 7776 return this._errorToken("illegal character after $ in string interpolation
"); |
| 7777 } |
| 7778 while (this._index < this._text.length) { |
| 7779 if (!TokenizerHelpers.isInterpIdentifierPart(this._text.charCodeAt(this._i
ndex++))) { |
| 7780 this._index--; |
| 7781 break; |
| 7782 } |
| 7783 } |
| 7784 } |
| 7785 else { |
| 7786 while (this._index < this._text.length) { |
| 7787 if (!TokenizerHelpers.isIdentifierPart(this._text.charCodeAt(this._index++
))) { |
| 7788 this._index--; |
| 7789 break; |
| 7790 } |
| 7791 } |
| 7792 } |
| 7793 var kind = this.getIdentifierKind(); |
| 7794 if (kind == 70/*TokenKind.IDENTIFIER*/) { |
| 7795 return this._finishToken(70/*TokenKind.IDENTIFIER*/); |
| 7796 } |
| 7797 else { |
| 7798 return this._finishToken(kind); |
| 7799 } |
| 7800 } |
| 7801 TokenizerBase.prototype.next$0 = TokenizerBase.prototype.next; |
| 7802 // ********** Code for Tokenizer ************** |
| 7803 $inherits(Tokenizer, TokenizerBase); |
| 7804 function Tokenizer(source, skipWhitespace, index) { |
| 7805 // Initializers done |
| 7806 TokenizerBase.call(this, source, skipWhitespace, index); |
| 7807 } |
| 7808 Tokenizer.prototype.next = function() { |
| 7809 this._startIndex = this._index; |
| 7810 if (this._interpStack != null && this._interpStack.depth == 0) { |
| 7811 var istack = this._interpStack; |
| 7812 this._interpStack = this._interpStack.pop(); |
| 7813 if (istack.get$isMultiline()) { |
| 7814 return this.finishMultilineString(istack.get$quote()); |
| 7815 } |
| 7816 else { |
| 7817 return this.finishStringBody(istack.get$quote()); |
| 7818 } |
| 7819 } |
| 7820 var ch; |
| 7821 ch = this._nextChar(); |
| 7822 switch (ch) { |
| 7823 case 0: |
| 7824 |
| 7825 return this._finishToken(1/*TokenKind.END_OF_FILE*/); |
| 7826 |
| 7827 case 32: |
| 7828 case 9: |
| 7829 case 10: |
| 7830 case 13: |
| 7831 |
| 7832 return this.finishWhitespace(); |
| 7833 |
| 7834 case 33: |
| 7835 |
| 7836 if (this._maybeEatChar(61)) { |
| 7837 if (this._maybeEatChar(61)) { |
| 7838 return this._finishToken(51/*TokenKind.NE_STRICT*/); |
| 7839 } |
| 7840 else { |
| 7841 return this._finishToken(49/*TokenKind.NE*/); |
| 7842 } |
| 7843 } |
| 7844 else { |
| 7845 return this._finishToken(19/*TokenKind.NOT*/); |
| 7846 } |
| 7847 |
| 7848 case 34: |
| 7849 |
| 7850 return this.finishString(34); |
| 7851 |
| 7852 case 35: |
| 7853 |
| 7854 if (this._maybeEatChar(33)) { |
| 7855 return this.finishHashBang(); |
| 7856 } |
| 7857 else { |
| 7858 return this._finishToken(12/*TokenKind.HASH*/); |
| 7859 } |
| 7860 |
| 7861 case 36: |
| 7862 |
| 7863 if (this._maybeEatChar(34)) { |
| 7864 return this.finishString(34); |
| 7865 } |
| 7866 else if (this._maybeEatChar(39)) { |
| 7867 return this.finishString(39); |
| 7868 } |
| 7869 else { |
| 7870 return this.finishIdentifier(36); |
| 7871 } |
| 7872 |
| 7873 case 37: |
| 7874 |
| 7875 if (this._maybeEatChar(61)) { |
| 7876 return this._finishToken(32/*TokenKind.ASSIGN_MOD*/); |
| 7877 } |
| 7878 else { |
| 7879 return this._finishToken(47/*TokenKind.MOD*/); |
| 7880 } |
| 7881 |
| 7882 case 38: |
| 7883 |
| 7884 if (this._maybeEatChar(38)) { |
| 7885 return this._finishToken(35/*TokenKind.AND*/); |
| 7886 } |
| 7887 else if (this._maybeEatChar(61)) { |
| 7888 return this._finishToken(23/*TokenKind.ASSIGN_AND*/); |
| 7889 } |
| 7890 else { |
| 7891 return this._finishToken(38/*TokenKind.BIT_AND*/); |
| 7892 } |
| 7893 |
| 7894 case 39: |
| 7895 |
| 7896 return this.finishString(39); |
| 7897 |
| 7898 case 40: |
| 7899 |
| 7900 return this._finishToken(2/*TokenKind.LPAREN*/); |
| 7901 |
| 7902 case 41: |
| 7903 |
| 7904 return this._finishToken(3/*TokenKind.RPAREN*/); |
| 7905 |
| 7906 case 42: |
| 7907 |
| 7908 if (this._maybeEatChar(61)) { |
| 7909 return this._finishToken(29/*TokenKind.ASSIGN_MUL*/); |
| 7910 } |
| 7911 else { |
| 7912 return this._finishToken(44/*TokenKind.MUL*/); |
| 7913 } |
| 7914 |
| 7915 case 43: |
| 7916 |
| 7917 if (this._maybeEatChar(43)) { |
| 7918 return this._finishToken(16/*TokenKind.INCR*/); |
| 7919 } |
| 7920 else if (this._maybeEatChar(61)) { |
| 7921 return this._finishToken(27/*TokenKind.ASSIGN_ADD*/); |
| 7922 } |
| 7923 else { |
| 7924 return this._finishToken(42/*TokenKind.ADD*/); |
| 7925 } |
| 7926 |
| 7927 case 44: |
| 7928 |
| 7929 return this._finishToken(11/*TokenKind.COMMA*/); |
| 7930 |
| 7931 case 45: |
| 7932 |
| 7933 if (this._maybeEatChar(45)) { |
| 7934 return this._finishToken(17/*TokenKind.DECR*/); |
| 7935 } |
| 7936 else if (this._maybeEatChar(61)) { |
| 7937 return this._finishToken(28/*TokenKind.ASSIGN_SUB*/); |
| 7938 } |
| 7939 else { |
| 7940 return this._finishToken(43/*TokenKind.SUB*/); |
| 7941 } |
| 7942 |
| 7943 case 46: |
| 7944 |
| 7945 if (this._maybeEatChar(46)) { |
| 7946 if (this._maybeEatChar(46)) { |
| 7947 return this._finishToken(15/*TokenKind.ELLIPSIS*/); |
| 7948 } |
| 7949 else { |
| 7950 return this._errorToken(); |
| 7951 } |
| 7952 } |
| 7953 else { |
| 7954 return this.finishDot(); |
| 7955 } |
| 7956 |
| 7957 case 47: |
| 7958 |
| 7959 if (this._maybeEatChar(42)) { |
| 7960 return this.finishMultiLineComment(); |
| 7961 } |
| 7962 else if (this._maybeEatChar(47)) { |
| 7963 return this.finishSingleLineComment(); |
| 7964 } |
| 7965 else if (this._maybeEatChar(61)) { |
| 7966 return this._finishToken(30/*TokenKind.ASSIGN_DIV*/); |
| 7967 } |
| 7968 else { |
| 7969 return this._finishToken(45/*TokenKind.DIV*/); |
| 7970 } |
| 7971 |
| 7972 case 48: |
| 7973 |
| 7974 if (this._maybeEatChar(88)) { |
| 7975 return this.finishHex(); |
| 7976 } |
| 7977 else if (this._maybeEatChar(120)) { |
| 7978 return this.finishHex(); |
| 7979 } |
| 7980 else { |
| 7981 return this.finishNumber(); |
| 7982 } |
| 7983 |
| 7984 case 58: |
| 7985 |
| 7986 return this._finishToken(8/*TokenKind.COLON*/); |
| 7987 |
| 7988 case 59: |
| 7989 |
| 7990 return this._finishToken(10/*TokenKind.SEMICOLON*/); |
| 7991 |
| 7992 case 60: |
| 7993 |
| 7994 if (this._maybeEatChar(60)) { |
| 7995 if (this._maybeEatChar(61)) { |
| 7996 return this._finishToken(24/*TokenKind.ASSIGN_SHL*/); |
| 7997 } |
| 7998 else { |
| 7999 return this._finishToken(39/*TokenKind.SHL*/); |
| 8000 } |
| 8001 } |
| 8002 else if (this._maybeEatChar(61)) { |
| 8003 return this._finishToken(54/*TokenKind.LTE*/); |
| 8004 } |
| 8005 else { |
| 8006 return this._finishToken(52/*TokenKind.LT*/); |
| 8007 } |
| 8008 |
| 8009 case 61: |
| 8010 |
| 8011 if (this._maybeEatChar(61)) { |
| 8012 if (this._maybeEatChar(61)) { |
| 8013 return this._finishToken(50/*TokenKind.EQ_STRICT*/); |
| 8014 } |
| 8015 else { |
| 8016 return this._finishToken(48/*TokenKind.EQ*/); |
| 8017 } |
| 8018 } |
| 8019 else if (this._maybeEatChar(62)) { |
| 8020 return this._finishToken(9/*TokenKind.ARROW*/); |
| 8021 } |
| 8022 else { |
| 8023 return this._finishToken(20/*TokenKind.ASSIGN*/); |
| 8024 } |
| 8025 |
| 8026 case 62: |
| 8027 |
| 8028 if (this._maybeEatChar(61)) { |
| 8029 return this._finishToken(55/*TokenKind.GTE*/); |
| 8030 } |
| 8031 else if (this._maybeEatChar(62)) { |
| 8032 if (this._maybeEatChar(61)) { |
| 8033 return this._finishToken(25/*TokenKind.ASSIGN_SAR*/); |
| 8034 } |
| 8035 else if (this._maybeEatChar(62)) { |
| 8036 if (this._maybeEatChar(61)) { |
| 8037 return this._finishToken(26/*TokenKind.ASSIGN_SHR*/); |
| 8038 } |
| 8039 else { |
| 8040 return this._finishToken(41/*TokenKind.SHR*/); |
| 8041 } |
| 8042 } |
| 8043 else { |
| 8044 return this._finishToken(40/*TokenKind.SAR*/); |
| 8045 } |
| 8046 } |
| 8047 else { |
| 8048 return this._finishToken(53/*TokenKind.GT*/); |
| 8049 } |
| 8050 |
| 8051 case 63: |
| 8052 |
| 8053 return this._finishToken(33/*TokenKind.CONDITIONAL*/); |
| 8054 |
| 8055 case 64: |
| 8056 |
| 8057 if (this._maybeEatChar(34)) { |
| 8058 return this.finishRawString(34); |
| 8059 } |
| 8060 else if (this._maybeEatChar(39)) { |
| 8061 return this.finishRawString(39); |
| 8062 } |
| 8063 else { |
| 8064 return this._errorToken(); |
| 8065 } |
| 8066 |
| 8067 case 91: |
| 8068 |
| 8069 if (this._maybeEatChar(93)) { |
| 8070 if (this._maybeEatChar(61)) { |
| 8071 return this._finishToken(57/*TokenKind.SETINDEX*/); |
| 8072 } |
| 8073 else { |
| 8074 return this._finishToken(56/*TokenKind.INDEX*/); |
| 8075 } |
| 8076 } |
| 8077 else { |
| 8078 return this._finishToken(4/*TokenKind.LBRACK*/); |
| 8079 } |
| 8080 |
| 8081 case 93: |
| 8082 |
| 8083 return this._finishToken(5/*TokenKind.RBRACK*/); |
| 8084 |
| 8085 case 94: |
| 8086 |
| 8087 if (this._maybeEatChar(61)) { |
| 8088 return this._finishToken(22/*TokenKind.ASSIGN_XOR*/); |
| 8089 } |
| 8090 else { |
| 8091 return this._finishToken(37/*TokenKind.BIT_XOR*/); |
| 8092 } |
| 8093 |
| 8094 case 123: |
| 8095 |
| 8096 return this._finishOpenBrace(); |
| 8097 |
| 8098 case 124: |
| 8099 |
| 8100 if (this._maybeEatChar(61)) { |
| 8101 return this._finishToken(21/*TokenKind.ASSIGN_OR*/); |
| 8102 } |
| 8103 else if (this._maybeEatChar(124)) { |
| 8104 return this._finishToken(34/*TokenKind.OR*/); |
| 8105 } |
| 8106 else { |
| 8107 return this._finishToken(36/*TokenKind.BIT_OR*/); |
| 8108 } |
| 8109 |
| 8110 case 125: |
| 8111 |
| 8112 return this._finishCloseBrace(); |
| 8113 |
| 8114 case 126: |
| 8115 |
| 8116 if (this._maybeEatChar(47)) { |
| 8117 if (this._maybeEatChar(61)) { |
| 8118 return this._finishToken(31/*TokenKind.ASSIGN_TRUNCDIV*/); |
| 8119 } |
| 8120 else { |
| 8121 return this._finishToken(46/*TokenKind.TRUNCDIV*/); |
| 8122 } |
| 8123 } |
| 8124 else { |
| 8125 return this._finishToken(18/*TokenKind.BIT_NOT*/); |
| 8126 } |
| 8127 |
| 8128 default: |
| 8129 |
| 8130 if (TokenizerHelpers.isIdentifierStart(ch)) { |
| 8131 return this.finishIdentifier(ch); |
| 8132 } |
| 8133 else if (TokenizerHelpers.isDigit(ch)) { |
| 8134 return this.finishNumber(); |
| 8135 } |
| 8136 else { |
| 8137 return this._errorToken(); |
| 8138 } |
| 8139 |
| 8140 } |
| 8141 } |
| 8142 Tokenizer.prototype.getIdentifierKind = function() { |
| 8143 var i0 = this._startIndex; |
| 8144 switch (this._index - i0) { |
| 8145 case 2: |
| 8146 |
| 8147 if (this._text.charCodeAt(i0) == 100) { |
| 8148 if (this._text.charCodeAt(i0 + 1) == 111) return 95/*TokenKind.DO*/; |
| 8149 } |
| 8150 else if (this._text.charCodeAt(i0) == 105) { |
| 8151 if (this._text.charCodeAt(i0 + 1) == 102) { |
| 8152 return 101/*TokenKind.IF*/; |
| 8153 } |
| 8154 else if (this._text.charCodeAt(i0 + 1) == 110) { |
| 8155 return 102/*TokenKind.IN*/; |
| 8156 } |
| 8157 else if (this._text.charCodeAt(i0 + 1) == 115) { |
| 8158 return 103/*TokenKind.IS*/; |
| 8159 } |
| 8160 } |
| 8161 return 70/*TokenKind.IDENTIFIER*/; |
| 8162 |
| 8163 case 3: |
| 8164 |
| 8165 if (this._text.charCodeAt(i0) == 102) { |
| 8166 if (this._text.charCodeAt(i0 + 1) == 111 && this._text.charCodeAt(i0 + 2
) == 114) return 100/*TokenKind.FOR*/; |
| 8167 } |
| 8168 else if (this._text.charCodeAt(i0) == 103) { |
| 8169 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 116) return 76/*TokenKind.GET*/; |
| 8170 } |
| 8171 else if (this._text.charCodeAt(i0) == 110) { |
| 8172 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 119) return 104/*TokenKind.NEW*/; |
| 8173 } |
| 8174 else if (this._text.charCodeAt(i0) == 115) { |
| 8175 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 116) return 84/*TokenKind.SET*/; |
| 8176 } |
| 8177 else if (this._text.charCodeAt(i0) == 116) { |
| 8178 if (this._text.charCodeAt(i0 + 1) == 114 && this._text.charCodeAt(i0 + 2
) == 121) return 112/*TokenKind.TRY*/; |
| 8179 } |
| 8180 else if (this._text.charCodeAt(i0) == 118) { |
| 8181 if (this._text.charCodeAt(i0 + 1) == 97 && this._text.charCodeAt(i0 + 2)
== 114) return 113/*TokenKind.VAR*/; |
| 8182 } |
| 8183 return 70/*TokenKind.IDENTIFIER*/; |
| 8184 |
| 8185 case 4: |
| 8186 |
| 8187 if (this._text.charCodeAt(i0) == 99) { |
| 8188 if (this._text.charCodeAt(i0 + 1) == 97 && this._text.charCodeAt(i0 + 2)
== 115 && this._text.charCodeAt(i0 + 3) == 101) return 90/*TokenKind.CASE*/; |
| 8189 } |
| 8190 else if (this._text.charCodeAt(i0) == 101) { |
| 8191 if (this._text.charCodeAt(i0 + 1) == 108 && this._text.charCodeAt(i0 + 2
) == 115 && this._text.charCodeAt(i0 + 3) == 101) return 96/*TokenKind.ELSE*/; |
| 8192 } |
| 8193 else if (this._text.charCodeAt(i0) == 110) { |
| 8194 if (this._text.charCodeAt(i0 + 1) == 117 && this._text.charCodeAt(i0 + 2
) == 108 && this._text.charCodeAt(i0 + 3) == 108) return 105/*TokenKind.NULL*/; |
| 8195 } |
| 8196 else if (this._text.charCodeAt(i0) == 116) { |
| 8197 if (this._text.charCodeAt(i0 + 1) == 104) { |
| 8198 if (this._text.charCodeAt(i0 + 2) == 105 && this._text.charCodeAt(i0 +
3) == 115) return 109/*TokenKind.THIS*/; |
| 8199 } |
| 8200 else if (this._text.charCodeAt(i0 + 1) == 114) { |
| 8201 if (this._text.charCodeAt(i0 + 2) == 117 && this._text.charCodeAt(i0 +
3) == 101) return 111/*TokenKind.TRUE*/; |
| 8202 } |
| 8203 } |
| 8204 else if (this._text.charCodeAt(i0) == 118) { |
| 8205 if (this._text.charCodeAt(i0 + 1) == 111 && this._text.charCodeAt(i0 + 2
) == 105 && this._text.charCodeAt(i0 + 3) == 100) return 114/*TokenKind.VOID*/; |
| 8206 } |
| 8207 return 70/*TokenKind.IDENTIFIER*/; |
| 8208 |
| 8209 case 5: |
| 8210 |
| 8211 if (this._text.charCodeAt(i0) == 97) { |
| 8212 if (this._text.charCodeAt(i0 + 1) == 119 && this._text.charCodeAt(i0 + 2
) == 97 && this._text.charCodeAt(i0 + 3) == 105 && this._text.charCodeAt(i0 + 4)
== 116) return 88/*TokenKind.AWAIT*/; |
| 8213 } |
| 8214 else if (this._text.charCodeAt(i0) == 98) { |
| 8215 if (this._text.charCodeAt(i0 + 1) == 114 && this._text.charCodeAt(i0 + 2
) == 101 && this._text.charCodeAt(i0 + 3) == 97 && this._text.charCodeAt(i0 + 4)
== 107) return 89/*TokenKind.BREAK*/; |
| 8216 } |
| 8217 else if (this._text.charCodeAt(i0) == 99) { |
| 8218 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 8219 if (this._text.charCodeAt(i0 + 2) == 116 && this._text.charCodeAt(i0 +
3) == 99 && this._text.charCodeAt(i0 + 4) == 104) return 91/*TokenKind.CATCH*/; |
| 8220 } |
| 8221 else if (this._text.charCodeAt(i0 + 1) == 108) { |
| 8222 if (this._text.charCodeAt(i0 + 2) == 97 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 115) return 73/*TokenKind.CLASS*/; |
| 8223 } |
| 8224 else if (this._text.charCodeAt(i0 + 1) == 111) { |
| 8225 if (this._text.charCodeAt(i0 + 2) == 110 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 116) return 92/*TokenKind.CONST*/
; |
| 8226 } |
| 8227 } |
| 8228 else if (this._text.charCodeAt(i0) == 102) { |
| 8229 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 8230 if (this._text.charCodeAt(i0 + 2) == 108 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 101) return 97/*TokenKind.FALSE*/
; |
| 8231 } |
| 8232 else if (this._text.charCodeAt(i0 + 1) == 105) { |
| 8233 if (this._text.charCodeAt(i0 + 2) == 110 && this._text.charCodeAt(i0 +
3) == 97 && this._text.charCodeAt(i0 + 4) == 108) return 98/*TokenKind.FINAL*/; |
| 8234 } |
| 8235 } |
| 8236 else if (this._text.charCodeAt(i0) == 115) { |
| 8237 if (this._text.charCodeAt(i0 + 1) == 117 && this._text.charCodeAt(i0 + 2
) == 112 && this._text.charCodeAt(i0 + 3) == 101 && this._text.charCodeAt(i0 + 4
) == 114) return 107/*TokenKind.SUPER*/; |
| 8238 } |
| 8239 else if (this._text.charCodeAt(i0) == 116) { |
| 8240 if (this._text.charCodeAt(i0 + 1) == 104 && this._text.charCodeAt(i0 + 2
) == 114 && this._text.charCodeAt(i0 + 3) == 111 && this._text.charCodeAt(i0 + 4
) == 119) return 110/*TokenKind.THROW*/; |
| 8241 } |
| 8242 else if (this._text.charCodeAt(i0) == 119) { |
| 8243 if (this._text.charCodeAt(i0 + 1) == 104 && this._text.charCodeAt(i0 + 2
) == 105 && this._text.charCodeAt(i0 + 3) == 108 && this._text.charCodeAt(i0 + 4
) == 101) return 115/*TokenKind.WHILE*/; |
| 8244 } |
| 8245 return 70/*TokenKind.IDENTIFIER*/; |
| 8246 |
| 8247 case 6: |
| 8248 |
| 8249 if (this._text.charCodeAt(i0) == 97) { |
| 8250 if (this._text.charCodeAt(i0 + 1) == 115 && this._text.charCodeAt(i0 + 2
) == 115 && this._text.charCodeAt(i0 + 3) == 101 && this._text.charCodeAt(i0 + 4
) == 114 && this._text.charCodeAt(i0 + 5) == 116) return 72/*TokenKind.ASSERT*/; |
| 8251 } |
| 8252 else if (this._text.charCodeAt(i0) == 105) { |
| 8253 if (this._text.charCodeAt(i0 + 1) == 109 && this._text.charCodeAt(i0 + 2
) == 112 && this._text.charCodeAt(i0 + 3) == 111 && this._text.charCodeAt(i0 + 4
) == 114 && this._text.charCodeAt(i0 + 5) == 116) return 78/*TokenKind.IMPORT*/; |
| 8254 } |
| 8255 else if (this._text.charCodeAt(i0) == 110) { |
| 8256 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 8257 if (this._text.charCodeAt(i0 + 2) == 116 && this._text.charCodeAt(i0 +
3) == 105 && this._text.charCodeAt(i0 + 4) == 118 && this._text.charCodeAt(i0 +
5) == 101) return 81/*TokenKind.NATIVE*/; |
| 8258 } |
| 8259 else if (this._text.charCodeAt(i0 + 1) == 101) { |
| 8260 if (this._text.charCodeAt(i0 + 2) == 103 && this._text.charCodeAt(i0 +
3) == 97 && this._text.charCodeAt(i0 + 4) == 116 && this._text.charCodeAt(i0 +
5) == 101) return 82/*TokenKind.NEGATE*/; |
| 8261 } |
| 8262 } |
| 8263 else if (this._text.charCodeAt(i0) == 114) { |
| 8264 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 116 && this._text.charCodeAt(i0 + 3) == 117 && this._text.charCodeAt(i0 + 4
) == 114 && this._text.charCodeAt(i0 + 5) == 110) return 106/*TokenKind.RETURN*/
; |
| 8265 } |
| 8266 else if (this._text.charCodeAt(i0) == 115) { |
| 8267 if (this._text.charCodeAt(i0 + 1) == 111) { |
| 8268 if (this._text.charCodeAt(i0 + 2) == 117 && this._text.charCodeAt(i0 +
3) == 114 && this._text.charCodeAt(i0 + 4) == 99 && this._text.charCodeAt(i0 +
5) == 101) return 85/*TokenKind.SOURCE*/; |
| 8269 } |
| 8270 else if (this._text.charCodeAt(i0 + 1) == 116) { |
| 8271 if (this._text.charCodeAt(i0 + 2) == 97 && this._text.charCodeAt(i0 +
3) == 116 && this._text.charCodeAt(i0 + 4) == 105 && this._text.charCodeAt(i0 +
5) == 99) return 86/*TokenKind.STATIC*/; |
| 8272 } |
| 8273 else if (this._text.charCodeAt(i0 + 1) == 119) { |
| 8274 if (this._text.charCodeAt(i0 + 2) == 105 && this._text.charCodeAt(i0 +
3) == 116 && this._text.charCodeAt(i0 + 4) == 99 && this._text.charCodeAt(i0 +
5) == 104) return 108/*TokenKind.SWITCH*/; |
| 8275 } |
| 8276 } |
| 8277 return 70/*TokenKind.IDENTIFIER*/; |
| 8278 |
| 8279 case 7: |
| 8280 |
| 8281 if (this._text.charCodeAt(i0) == 100) { |
| 8282 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 102 && this._text.charCodeAt(i0 + 3) == 97 && this._text.charCodeAt(i0 + 4)
== 117 && this._text.charCodeAt(i0 + 5) == 108 && this._text.charCodeAt(i0 + 6)
== 116) return 94/*TokenKind.DEFAULT*/; |
| 8283 } |
| 8284 else if (this._text.charCodeAt(i0) == 101) { |
| 8285 if (this._text.charCodeAt(i0 + 1) == 120 && this._text.charCodeAt(i0 + 2
) == 116 && this._text.charCodeAt(i0 + 3) == 101 && this._text.charCodeAt(i0 + 4
) == 110 && this._text.charCodeAt(i0 + 5) == 100 && this._text.charCodeAt(i0 + 6
) == 115) return 74/*TokenKind.EXTENDS*/; |
| 8286 } |
| 8287 else if (this._text.charCodeAt(i0) == 102) { |
| 8288 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 8289 if (this._text.charCodeAt(i0 + 2) == 99 && this._text.charCodeAt(i0 +
3) == 116 && this._text.charCodeAt(i0 + 4) == 111 && this._text.charCodeAt(i0 +
5) == 114 && this._text.charCodeAt(i0 + 6) == 121) return 75/*TokenKind.FACTORY*
/; |
| 8290 } |
| 8291 else if (this._text.charCodeAt(i0 + 1) == 105) { |
| 8292 if (this._text.charCodeAt(i0 + 2) == 110 && this._text.charCodeAt(i0 +
3) == 97 && this._text.charCodeAt(i0 + 4) == 108 && this._text.charCodeAt(i0 +
5) == 108 && this._text.charCodeAt(i0 + 6) == 121) return 99/*TokenKind.FINALLY*
/; |
| 8293 } |
| 8294 } |
| 8295 else if (this._text.charCodeAt(i0) == 108) { |
| 8296 if (this._text.charCodeAt(i0 + 1) == 105 && this._text.charCodeAt(i0 + 2
) == 98 && this._text.charCodeAt(i0 + 3) == 114 && this._text.charCodeAt(i0 + 4)
== 97 && this._text.charCodeAt(i0 + 5) == 114 && this._text.charCodeAt(i0 + 6)
== 121) return 80/*TokenKind.LIBRARY*/; |
| 8297 } |
| 8298 else if (this._text.charCodeAt(i0) == 116) { |
| 8299 if (this._text.charCodeAt(i0 + 1) == 121 && this._text.charCodeAt(i0 + 2
) == 112 && this._text.charCodeAt(i0 + 3) == 101 && this._text.charCodeAt(i0 + 4
) == 100 && this._text.charCodeAt(i0 + 5) == 101 && this._text.charCodeAt(i0 + 6
) == 102) return 87/*TokenKind.TYPEDEF*/; |
| 8300 } |
| 8301 return 70/*TokenKind.IDENTIFIER*/; |
| 8302 |
| 8303 case 8: |
| 8304 |
| 8305 if (this._text.charCodeAt(i0) == 97) { |
| 8306 if (this._text.charCodeAt(i0 + 1) == 98 && this._text.charCodeAt(i0 + 2)
== 115 && this._text.charCodeAt(i0 + 3) == 116 && this._text.charCodeAt(i0 + 4)
== 114 && this._text.charCodeAt(i0 + 5) == 97 && this._text.charCodeAt(i0 + 6)
== 99 && this._text.charCodeAt(i0 + 7) == 116) return 71/*TokenKind.ABSTRACT*/; |
| 8307 } |
| 8308 else if (this._text.charCodeAt(i0) == 99) { |
| 8309 if (this._text.charCodeAt(i0 + 1) == 111 && this._text.charCodeAt(i0 + 2
) == 110 && this._text.charCodeAt(i0 + 3) == 116 && this._text.charCodeAt(i0 + 4
) == 105 && this._text.charCodeAt(i0 + 5) == 110 && this._text.charCodeAt(i0 + 6
) == 117 && this._text.charCodeAt(i0 + 7) == 101) return 93/*TokenKind.CONTINUE*
/; |
| 8310 } |
| 8311 else if (this._text.charCodeAt(i0) == 111) { |
| 8312 if (this._text.charCodeAt(i0 + 1) == 112 && this._text.charCodeAt(i0 + 2
) == 101 && this._text.charCodeAt(i0 + 3) == 114 && this._text.charCodeAt(i0 + 4
) == 97 && this._text.charCodeAt(i0 + 5) == 116 && this._text.charCodeAt(i0 + 6)
== 111 && this._text.charCodeAt(i0 + 7) == 114) return 83/*TokenKind.OPERATOR*/
; |
| 8313 } |
| 8314 return 70/*TokenKind.IDENTIFIER*/; |
| 8315 |
| 8316 case 9: |
| 8317 |
| 8318 if (this._text.charCodeAt(i0) == 105 && this._text.charCodeAt(i0 + 1) == 1
10 && this._text.charCodeAt(i0 + 2) == 116 && this._text.charCodeAt(i0 + 3) == 1
01 && this._text.charCodeAt(i0 + 4) == 114 && this._text.charCodeAt(i0 + 5) == 1
02 && this._text.charCodeAt(i0 + 6) == 97 && this._text.charCodeAt(i0 + 7) == 99
&& this._text.charCodeAt(i0 + 8) == 101) return 79/*TokenKind.INTERFACE*/; |
| 8319 return 70/*TokenKind.IDENTIFIER*/; |
| 8320 |
| 8321 case 10: |
| 8322 |
| 8323 if (this._text.charCodeAt(i0) == 105 && this._text.charCodeAt(i0 + 1) == 1
09 && this._text.charCodeAt(i0 + 2) == 112 && this._text.charCodeAt(i0 + 3) == 1
08 && this._text.charCodeAt(i0 + 4) == 101 && this._text.charCodeAt(i0 + 5) == 1
09 && this._text.charCodeAt(i0 + 6) == 101 && this._text.charCodeAt(i0 + 7) == 1
10 && this._text.charCodeAt(i0 + 8) == 116 && this._text.charCodeAt(i0 + 9) == 1
15) return 77/*TokenKind.IMPLEMENTS*/; |
| 8324 return 70/*TokenKind.IDENTIFIER*/; |
| 8325 |
| 8326 default: |
| 8327 |
| 8328 return 70/*TokenKind.IDENTIFIER*/; |
| 8329 |
| 8330 } |
| 8331 } |
| 8332 Tokenizer.prototype.next$0 = Tokenizer.prototype.next; |
| 8333 // ********** Code for TokenKind ************** |
| 8334 function TokenKind() {} |
| 8335 TokenKind.kindToString = function(kind) { |
| 8336 switch (kind) { |
| 8337 case 1/*TokenKind.END_OF_FILE*/: |
| 8338 |
| 8339 return "end of file"; |
| 8340 |
| 8341 case 2/*TokenKind.LPAREN*/: |
| 8342 |
| 8343 return "("; |
| 8344 |
| 8345 case 3/*TokenKind.RPAREN*/: |
| 8346 |
| 8347 return ")"; |
| 8348 |
| 8349 case 4/*TokenKind.LBRACK*/: |
| 8350 |
| 8351 return "["; |
| 8352 |
| 8353 case 5/*TokenKind.RBRACK*/: |
| 8354 |
| 8355 return "]"; |
| 8356 |
| 8357 case 6/*TokenKind.LBRACE*/: |
| 8358 |
| 8359 return "{"; |
| 8360 |
| 8361 case 7/*TokenKind.RBRACE*/: |
| 8362 |
| 8363 return "}"; |
| 8364 |
| 8365 case 8/*TokenKind.COLON*/: |
| 8366 |
| 8367 return ":"; |
| 8368 |
| 8369 case 9/*TokenKind.ARROW*/: |
| 8370 |
| 8371 return "=>"; |
| 8372 |
| 8373 case 10/*TokenKind.SEMICOLON*/: |
| 8374 |
| 8375 return ";"; |
| 8376 |
| 8377 case 11/*TokenKind.COMMA*/: |
| 8378 |
| 8379 return ","; |
| 8380 |
| 8381 case 12/*TokenKind.HASH*/: |
| 8382 |
| 8383 return "#"; |
| 8384 |
| 8385 case 13/*TokenKind.HASHBANG*/: |
| 8386 |
| 8387 return "#!"; |
| 8388 |
| 8389 case 14/*TokenKind.DOT*/: |
| 8390 |
| 8391 return "."; |
| 8392 |
| 8393 case 15/*TokenKind.ELLIPSIS*/: |
| 8394 |
| 8395 return "..."; |
| 8396 |
| 8397 case 16/*TokenKind.INCR*/: |
| 8398 |
| 8399 return "++"; |
| 8400 |
| 8401 case 17/*TokenKind.DECR*/: |
| 8402 |
| 8403 return "--"; |
| 8404 |
| 8405 case 18/*TokenKind.BIT_NOT*/: |
| 8406 |
| 8407 return "~"; |
| 8408 |
| 8409 case 19/*TokenKind.NOT*/: |
| 8410 |
| 8411 return "!"; |
| 8412 |
| 8413 case 20/*TokenKind.ASSIGN*/: |
| 8414 |
| 8415 return "="; |
| 8416 |
| 8417 case 21/*TokenKind.ASSIGN_OR*/: |
| 8418 |
| 8419 return "|="; |
| 8420 |
| 8421 case 22/*TokenKind.ASSIGN_XOR*/: |
| 8422 |
| 8423 return "^="; |
| 8424 |
| 8425 case 23/*TokenKind.ASSIGN_AND*/: |
| 8426 |
| 8427 return "&="; |
| 8428 |
| 8429 case 24/*TokenKind.ASSIGN_SHL*/: |
| 8430 |
| 8431 return "<<="; |
| 8432 |
| 8433 case 25/*TokenKind.ASSIGN_SAR*/: |
| 8434 |
| 8435 return ">>="; |
| 8436 |
| 8437 case 26/*TokenKind.ASSIGN_SHR*/: |
| 8438 |
| 8439 return ">>>="; |
| 8440 |
| 8441 case 27/*TokenKind.ASSIGN_ADD*/: |
| 8442 |
| 8443 return "+="; |
| 8444 |
| 8445 case 28/*TokenKind.ASSIGN_SUB*/: |
| 8446 |
| 8447 return "-="; |
| 8448 |
| 8449 case 29/*TokenKind.ASSIGN_MUL*/: |
| 8450 |
| 8451 return "*="; |
| 8452 |
| 8453 case 30/*TokenKind.ASSIGN_DIV*/: |
| 8454 |
| 8455 return "/="; |
| 8456 |
| 8457 case 31/*TokenKind.ASSIGN_TRUNCDIV*/: |
| 8458 |
| 8459 return "~/="; |
| 8460 |
| 8461 case 32/*TokenKind.ASSIGN_MOD*/: |
| 8462 |
| 8463 return "%="; |
| 8464 |
| 8465 case 33/*TokenKind.CONDITIONAL*/: |
| 8466 |
| 8467 return "?"; |
| 8468 |
| 8469 case 34/*TokenKind.OR*/: |
| 8470 |
| 8471 return "||"; |
| 8472 |
| 8473 case 35/*TokenKind.AND*/: |
| 8474 |
| 8475 return "&&"; |
| 8476 |
| 8477 case 36/*TokenKind.BIT_OR*/: |
| 8478 |
| 8479 return "|"; |
| 8480 |
| 8481 case 37/*TokenKind.BIT_XOR*/: |
| 8482 |
| 8483 return "^"; |
| 8484 |
| 8485 case 38/*TokenKind.BIT_AND*/: |
| 8486 |
| 8487 return "&"; |
| 8488 |
| 8489 case 39/*TokenKind.SHL*/: |
| 8490 |
| 8491 return "<<"; |
| 8492 |
| 8493 case 40/*TokenKind.SAR*/: |
| 8494 |
| 8495 return ">>"; |
| 8496 |
| 8497 case 41/*TokenKind.SHR*/: |
| 8498 |
| 8499 return ">>>"; |
| 8500 |
| 8501 case 42/*TokenKind.ADD*/: |
| 8502 |
| 8503 return "+"; |
| 8504 |
| 8505 case 43/*TokenKind.SUB*/: |
| 8506 |
| 8507 return "-"; |
| 8508 |
| 8509 case 44/*TokenKind.MUL*/: |
| 8510 |
| 8511 return "*"; |
| 8512 |
| 8513 case 45/*TokenKind.DIV*/: |
| 8514 |
| 8515 return "/"; |
| 8516 |
| 8517 case 46/*TokenKind.TRUNCDIV*/: |
| 8518 |
| 8519 return "~/"; |
| 8520 |
| 8521 case 47/*TokenKind.MOD*/: |
| 8522 |
| 8523 return "%"; |
| 8524 |
| 8525 case 48/*TokenKind.EQ*/: |
| 8526 |
| 8527 return "=="; |
| 8528 |
| 8529 case 49/*TokenKind.NE*/: |
| 8530 |
| 8531 return "!="; |
| 8532 |
| 8533 case 50/*TokenKind.EQ_STRICT*/: |
| 8534 |
| 8535 return "==="; |
| 8536 |
| 8537 case 51/*TokenKind.NE_STRICT*/: |
| 8538 |
| 8539 return "!=="; |
| 8540 |
| 8541 case 52/*TokenKind.LT*/: |
| 8542 |
| 8543 return "<"; |
| 8544 |
| 8545 case 53/*TokenKind.GT*/: |
| 8546 |
| 8547 return ">"; |
| 8548 |
| 8549 case 54/*TokenKind.LTE*/: |
| 8550 |
| 8551 return "<="; |
| 8552 |
| 8553 case 55/*TokenKind.GTE*/: |
| 8554 |
| 8555 return ">="; |
| 8556 |
| 8557 case 56/*TokenKind.INDEX*/: |
| 8558 |
| 8559 return "[]"; |
| 8560 |
| 8561 case 57/*TokenKind.SETINDEX*/: |
| 8562 |
| 8563 return "[]="; |
| 8564 |
| 8565 case 58/*TokenKind.STRING*/: |
| 8566 |
| 8567 return "string"; |
| 8568 |
| 8569 case 59/*TokenKind.STRING_PART*/: |
| 8570 |
| 8571 return "string part"; |
| 8572 |
| 8573 case 60/*TokenKind.INTEGER*/: |
| 8574 |
| 8575 return "integer"; |
| 8576 |
| 8577 case 61/*TokenKind.HEX_INTEGER*/: |
| 8578 |
| 8579 return "hex integer"; |
| 8580 |
| 8581 case 62/*TokenKind.DOUBLE*/: |
| 8582 |
| 8583 return "double"; |
| 8584 |
| 8585 case 63/*TokenKind.WHITESPACE*/: |
| 8586 |
| 8587 return "whitespace"; |
| 8588 |
| 8589 case 64/*TokenKind.COMMENT*/: |
| 8590 |
| 8591 return "comment"; |
| 8592 |
| 8593 case 65/*TokenKind.ERROR*/: |
| 8594 |
| 8595 return "error"; |
| 8596 |
| 8597 case 66/*TokenKind.INCOMPLETE_STRING*/: |
| 8598 |
| 8599 return "incomplete string"; |
| 8600 |
| 8601 case 67/*TokenKind.INCOMPLETE_COMMENT*/: |
| 8602 |
| 8603 return "incomplete comment"; |
| 8604 |
| 8605 case 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/: |
| 8606 |
| 8607 return "incomplete multiline string dq"; |
| 8608 |
| 8609 case 69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/: |
| 8610 |
| 8611 return "incomplete multiline string sq"; |
| 8612 |
| 8613 case 70/*TokenKind.IDENTIFIER*/: |
| 8614 |
| 8615 return "identifier"; |
| 8616 |
| 8617 case 71/*TokenKind.ABSTRACT*/: |
| 8618 |
| 8619 return "pseudo-keyword 'abstract'"; |
| 8620 |
| 8621 case 72/*TokenKind.ASSERT*/: |
| 8622 |
| 8623 return "pseudo-keyword 'assert'"; |
| 8624 |
| 8625 case 73/*TokenKind.CLASS*/: |
| 8626 |
| 8627 return "pseudo-keyword 'class'"; |
| 8628 |
| 8629 case 74/*TokenKind.EXTENDS*/: |
| 8630 |
| 8631 return "pseudo-keyword 'extends'"; |
| 8632 |
| 8633 case 75/*TokenKind.FACTORY*/: |
| 8634 |
| 8635 return "pseudo-keyword 'factory'"; |
| 8636 |
| 8637 case 76/*TokenKind.GET*/: |
| 8638 |
| 8639 return "pseudo-keyword 'get'"; |
| 8640 |
| 8641 case 77/*TokenKind.IMPLEMENTS*/: |
| 8642 |
| 8643 return "pseudo-keyword 'implements'"; |
| 8644 |
| 8645 case 78/*TokenKind.IMPORT*/: |
| 8646 |
| 8647 return "pseudo-keyword 'import'"; |
| 8648 |
| 8649 case 79/*TokenKind.INTERFACE*/: |
| 8650 |
| 8651 return "pseudo-keyword 'interface'"; |
| 8652 |
| 8653 case 80/*TokenKind.LIBRARY*/: |
| 8654 |
| 8655 return "pseudo-keyword 'library'"; |
| 8656 |
| 8657 case 81/*TokenKind.NATIVE*/: |
| 8658 |
| 8659 return "pseudo-keyword 'native'"; |
| 8660 |
| 8661 case 82/*TokenKind.NEGATE*/: |
| 8662 |
| 8663 return "pseudo-keyword 'negate'"; |
| 8664 |
| 8665 case 83/*TokenKind.OPERATOR*/: |
| 8666 |
| 8667 return "pseudo-keyword 'operator'"; |
| 8668 |
| 8669 case 84/*TokenKind.SET*/: |
| 8670 |
| 8671 return "pseudo-keyword 'set'"; |
| 8672 |
| 8673 case 85/*TokenKind.SOURCE*/: |
| 8674 |
| 8675 return "pseudo-keyword 'source'"; |
| 8676 |
| 8677 case 86/*TokenKind.STATIC*/: |
| 8678 |
| 8679 return "pseudo-keyword 'static'"; |
| 8680 |
| 8681 case 87/*TokenKind.TYPEDEF*/: |
| 8682 |
| 8683 return "pseudo-keyword 'typedef'"; |
| 8684 |
| 8685 case 88/*TokenKind.AWAIT*/: |
| 8686 |
| 8687 return "keyword 'await'"; |
| 8688 |
| 8689 case 89/*TokenKind.BREAK*/: |
| 8690 |
| 8691 return "keyword 'break'"; |
| 8692 |
| 8693 case 90/*TokenKind.CASE*/: |
| 8694 |
| 8695 return "keyword 'case'"; |
| 8696 |
| 8697 case 91/*TokenKind.CATCH*/: |
| 8698 |
| 8699 return "keyword 'catch'"; |
| 8700 |
| 8701 case 92/*TokenKind.CONST*/: |
| 8702 |
| 8703 return "keyword 'const'"; |
| 8704 |
| 8705 case 93/*TokenKind.CONTINUE*/: |
| 8706 |
| 8707 return "keyword 'continue'"; |
| 8708 |
| 8709 case 94/*TokenKind.DEFAULT*/: |
| 8710 |
| 8711 return "keyword 'default'"; |
| 8712 |
| 8713 case 95/*TokenKind.DO*/: |
| 8714 |
| 8715 return "keyword 'do'"; |
| 8716 |
| 8717 case 96/*TokenKind.ELSE*/: |
| 8718 |
| 8719 return "keyword 'else'"; |
| 8720 |
| 8721 case 97/*TokenKind.FALSE*/: |
| 8722 |
| 8723 return "keyword 'false'"; |
| 8724 |
| 8725 case 98/*TokenKind.FINAL*/: |
| 8726 |
| 8727 return "keyword 'final'"; |
| 8728 |
| 8729 case 99/*TokenKind.FINALLY*/: |
| 8730 |
| 8731 return "keyword 'finally'"; |
| 8732 |
| 8733 case 100/*TokenKind.FOR*/: |
| 8734 |
| 8735 return "keyword 'for'"; |
| 8736 |
| 8737 case 101/*TokenKind.IF*/: |
| 8738 |
| 8739 return "keyword 'if'"; |
| 8740 |
| 8741 case 102/*TokenKind.IN*/: |
| 8742 |
| 8743 return "keyword 'in'"; |
| 8744 |
| 8745 case 103/*TokenKind.IS*/: |
| 8746 |
| 8747 return "keyword 'is'"; |
| 8748 |
| 8749 case 104/*TokenKind.NEW*/: |
| 8750 |
| 8751 return "keyword 'new'"; |
| 8752 |
| 8753 case 105/*TokenKind.NULL*/: |
| 8754 |
| 8755 return "keyword 'null'"; |
| 8756 |
| 8757 case 106/*TokenKind.RETURN*/: |
| 8758 |
| 8759 return "keyword 'return'"; |
| 8760 |
| 8761 case 107/*TokenKind.SUPER*/: |
| 8762 |
| 8763 return "keyword 'super'"; |
| 8764 |
| 8765 case 108/*TokenKind.SWITCH*/: |
| 8766 |
| 8767 return "keyword 'switch'"; |
| 8768 |
| 8769 case 109/*TokenKind.THIS*/: |
| 8770 |
| 8771 return "keyword 'this'"; |
| 8772 |
| 8773 case 110/*TokenKind.THROW*/: |
| 8774 |
| 8775 return "keyword 'throw'"; |
| 8776 |
| 8777 case 111/*TokenKind.TRUE*/: |
| 8778 |
| 8779 return "keyword 'true'"; |
| 8780 |
| 8781 case 112/*TokenKind.TRY*/: |
| 8782 |
| 8783 return "keyword 'try'"; |
| 8784 |
| 8785 case 113/*TokenKind.VAR*/: |
| 8786 |
| 8787 return "keyword 'var'"; |
| 8788 |
| 8789 case 114/*TokenKind.VOID*/: |
| 8790 |
| 8791 return "keyword 'void'"; |
| 8792 |
| 8793 case 115/*TokenKind.WHILE*/: |
| 8794 |
| 8795 return "keyword 'while'"; |
| 8796 |
| 8797 default: |
| 8798 |
| 8799 return "TokenKind(" + kind.toString() + ")"; |
| 8800 |
| 8801 } |
| 8802 } |
| 8803 TokenKind.isIdentifier = function(kind) { |
| 8804 return kind >= 70/*TokenKind.IDENTIFIER*/ && kind < 88/*TokenKind.AWAIT*/; |
| 8805 } |
| 8806 TokenKind.infixPrecedence = function(kind) { |
| 8807 switch (kind) { |
| 8808 case 20/*TokenKind.ASSIGN*/: |
| 8809 |
| 8810 return 2; |
| 8811 |
| 8812 case 21/*TokenKind.ASSIGN_OR*/: |
| 8813 |
| 8814 return 2; |
| 8815 |
| 8816 case 22/*TokenKind.ASSIGN_XOR*/: |
| 8817 |
| 8818 return 2; |
| 8819 |
| 8820 case 23/*TokenKind.ASSIGN_AND*/: |
| 8821 |
| 8822 return 2; |
| 8823 |
| 8824 case 24/*TokenKind.ASSIGN_SHL*/: |
| 8825 |
| 8826 return 2; |
| 8827 |
| 8828 case 25/*TokenKind.ASSIGN_SAR*/: |
| 8829 |
| 8830 return 2; |
| 8831 |
| 8832 case 26/*TokenKind.ASSIGN_SHR*/: |
| 8833 |
| 8834 return 2; |
| 8835 |
| 8836 case 27/*TokenKind.ASSIGN_ADD*/: |
| 8837 |
| 8838 return 2; |
| 8839 |
| 8840 case 28/*TokenKind.ASSIGN_SUB*/: |
| 8841 |
| 8842 return 2; |
| 8843 |
| 8844 case 29/*TokenKind.ASSIGN_MUL*/: |
| 8845 |
| 8846 return 2; |
| 8847 |
| 8848 case 30/*TokenKind.ASSIGN_DIV*/: |
| 8849 |
| 8850 return 2; |
| 8851 |
| 8852 case 31/*TokenKind.ASSIGN_TRUNCDIV*/: |
| 8853 |
| 8854 return 2; |
| 8855 |
| 8856 case 32/*TokenKind.ASSIGN_MOD*/: |
| 8857 |
| 8858 return 2; |
| 8859 |
| 8860 case 33/*TokenKind.CONDITIONAL*/: |
| 8861 |
| 8862 return 3; |
| 8863 |
| 8864 case 34/*TokenKind.OR*/: |
| 8865 |
| 8866 return 4; |
| 8867 |
| 8868 case 35/*TokenKind.AND*/: |
| 8869 |
| 8870 return 5; |
| 8871 |
| 8872 case 36/*TokenKind.BIT_OR*/: |
| 8873 |
| 8874 return 6; |
| 8875 |
| 8876 case 37/*TokenKind.BIT_XOR*/: |
| 8877 |
| 8878 return 7; |
| 8879 |
| 8880 case 38/*TokenKind.BIT_AND*/: |
| 8881 |
| 8882 return 8; |
| 8883 |
| 8884 case 39/*TokenKind.SHL*/: |
| 8885 |
| 8886 return 11; |
| 8887 |
| 8888 case 40/*TokenKind.SAR*/: |
| 8889 |
| 8890 return 11; |
| 8891 |
| 8892 case 41/*TokenKind.SHR*/: |
| 8893 |
| 8894 return 11; |
| 8895 |
| 8896 case 42/*TokenKind.ADD*/: |
| 8897 |
| 8898 return 12; |
| 8899 |
| 8900 case 43/*TokenKind.SUB*/: |
| 8901 |
| 8902 return 12; |
| 8903 |
| 8904 case 44/*TokenKind.MUL*/: |
| 8905 |
| 8906 return 13; |
| 8907 |
| 8908 case 45/*TokenKind.DIV*/: |
| 8909 |
| 8910 return 13; |
| 8911 |
| 8912 case 46/*TokenKind.TRUNCDIV*/: |
| 8913 |
| 8914 return 13; |
| 8915 |
| 8916 case 47/*TokenKind.MOD*/: |
| 8917 |
| 8918 return 13; |
| 8919 |
| 8920 case 48/*TokenKind.EQ*/: |
| 8921 |
| 8922 return 9; |
| 8923 |
| 8924 case 49/*TokenKind.NE*/: |
| 8925 |
| 8926 return 9; |
| 8927 |
| 8928 case 50/*TokenKind.EQ_STRICT*/: |
| 8929 |
| 8930 return 9; |
| 8931 |
| 8932 case 51/*TokenKind.NE_STRICT*/: |
| 8933 |
| 8934 return 9; |
| 8935 |
| 8936 case 52/*TokenKind.LT*/: |
| 8937 |
| 8938 return 10; |
| 8939 |
| 8940 case 53/*TokenKind.GT*/: |
| 8941 |
| 8942 return 10; |
| 8943 |
| 8944 case 54/*TokenKind.LTE*/: |
| 8945 |
| 8946 return 10; |
| 8947 |
| 8948 case 55/*TokenKind.GTE*/: |
| 8949 |
| 8950 return 10; |
| 8951 |
| 8952 case 103/*TokenKind.IS*/: |
| 8953 |
| 8954 return 10; |
| 8955 |
| 8956 default: |
| 8957 |
| 8958 return -1; |
| 8959 |
| 8960 } |
| 8961 } |
| 8962 TokenKind.rawOperatorFromMethod = function(name) { |
| 8963 switch (name) { |
| 8964 case ':bit_not': |
| 8965 |
| 8966 return '~'; |
| 8967 |
| 8968 case ':bit_or': |
| 8969 |
| 8970 return '|'; |
| 8971 |
| 8972 case ':bit_xor': |
| 8973 |
| 8974 return '^'; |
| 8975 |
| 8976 case ':bit_and': |
| 8977 |
| 8978 return '&'; |
| 8979 |
| 8980 case ':shl': |
| 8981 |
| 8982 return '<<'; |
| 8983 |
| 8984 case ':sar': |
| 8985 |
| 8986 return '>>'; |
| 8987 |
| 8988 case ':shr': |
| 8989 |
| 8990 return '>>>'; |
| 8991 |
| 8992 case ':add': |
| 8993 |
| 8994 return '+'; |
| 8995 |
| 8996 case ':sub': |
| 8997 |
| 8998 return '-'; |
| 8999 |
| 9000 case ':mul': |
| 9001 |
| 9002 return '*'; |
| 9003 |
| 9004 case ':div': |
| 9005 |
| 9006 return '/'; |
| 9007 |
| 9008 case ':truncdiv': |
| 9009 |
| 9010 return '~/'; |
| 9011 |
| 9012 case ':mod': |
| 9013 |
| 9014 return '%'; |
| 9015 |
| 9016 case ':eq': |
| 9017 |
| 9018 return '=='; |
| 9019 |
| 9020 case ':lt': |
| 9021 |
| 9022 return '<'; |
| 9023 |
| 9024 case ':gt': |
| 9025 |
| 9026 return '>'; |
| 9027 |
| 9028 case ':lte': |
| 9029 |
| 9030 return '<='; |
| 9031 |
| 9032 case ':gte': |
| 9033 |
| 9034 return '>='; |
| 9035 |
| 9036 case ':index': |
| 9037 |
| 9038 return '[]'; |
| 9039 |
| 9040 case ':setindex': |
| 9041 |
| 9042 return '[]='; |
| 9043 |
| 9044 case ':ne': |
| 9045 |
| 9046 return '!='; |
| 9047 |
| 9048 } |
| 9049 } |
| 9050 TokenKind.binaryMethodName = function(kind) { |
| 9051 switch (kind) { |
| 9052 case 18/*TokenKind.BIT_NOT*/: |
| 9053 |
| 9054 return ':bit_not'; |
| 9055 |
| 9056 case 36/*TokenKind.BIT_OR*/: |
| 9057 |
| 9058 return ':bit_or'; |
| 9059 |
| 9060 case 37/*TokenKind.BIT_XOR*/: |
| 9061 |
| 9062 return ':bit_xor'; |
| 9063 |
| 9064 case 38/*TokenKind.BIT_AND*/: |
| 9065 |
| 9066 return ':bit_and'; |
| 9067 |
| 9068 case 39/*TokenKind.SHL*/: |
| 9069 |
| 9070 return ':shl'; |
| 9071 |
| 9072 case 40/*TokenKind.SAR*/: |
| 9073 |
| 9074 return ':sar'; |
| 9075 |
| 9076 case 41/*TokenKind.SHR*/: |
| 9077 |
| 9078 return ':shr'; |
| 9079 |
| 9080 case 42/*TokenKind.ADD*/: |
| 9081 |
| 9082 return ':add'; |
| 9083 |
| 9084 case 43/*TokenKind.SUB*/: |
| 9085 |
| 9086 return ':sub'; |
| 9087 |
| 9088 case 44/*TokenKind.MUL*/: |
| 9089 |
| 9090 return ':mul'; |
| 9091 |
| 9092 case 45/*TokenKind.DIV*/: |
| 9093 |
| 9094 return ':div'; |
| 9095 |
| 9096 case 46/*TokenKind.TRUNCDIV*/: |
| 9097 |
| 9098 return ':truncdiv'; |
| 9099 |
| 9100 case 47/*TokenKind.MOD*/: |
| 9101 |
| 9102 return ':mod'; |
| 9103 |
| 9104 case 48/*TokenKind.EQ*/: |
| 9105 |
| 9106 return ':eq'; |
| 9107 |
| 9108 case 52/*TokenKind.LT*/: |
| 9109 |
| 9110 return ':lt'; |
| 9111 |
| 9112 case 53/*TokenKind.GT*/: |
| 9113 |
| 9114 return ':gt'; |
| 9115 |
| 9116 case 54/*TokenKind.LTE*/: |
| 9117 |
| 9118 return ':lte'; |
| 9119 |
| 9120 case 55/*TokenKind.GTE*/: |
| 9121 |
| 9122 return ':gte'; |
| 9123 |
| 9124 case 56/*TokenKind.INDEX*/: |
| 9125 |
| 9126 return ':index'; |
| 9127 |
| 9128 case 57/*TokenKind.SETINDEX*/: |
| 9129 |
| 9130 return ':setindex'; |
| 9131 |
| 9132 } |
| 9133 } |
| 9134 TokenKind.kindFromAssign = function(kind) { |
| 9135 if (kind == 20/*TokenKind.ASSIGN*/) return 0; |
| 9136 if (kind > 20/*TokenKind.ASSIGN*/ && kind <= 32/*TokenKind.ASSIGN_MOD*/) { |
| 9137 return kind + (15)/*(ADD - ASSIGN_ADD)*/; |
| 9138 } |
| 9139 return -1; |
| 9140 } |
| 9141 // ********** Code for Parser ************** |
| 9142 function Parser(source, diet, throwOnIncomplete, optionalSemicolons, startOffset
) { |
| 9143 this._inhibitLambda = false |
| 9144 this._afterParensIndex = 0 |
| 9145 this._recover = false |
| 9146 this.source = source; |
| 9147 this.diet = diet; |
| 9148 this.throwOnIncomplete = throwOnIncomplete; |
| 9149 this.optionalSemicolons = optionalSemicolons; |
| 9150 // Initializers done |
| 9151 this.tokenizer = new Tokenizer(this.source, true, startOffset); |
| 9152 this._peekToken = this.tokenizer.next(); |
| 9153 this._afterParens = []; |
| 9154 } |
| 9155 Parser.prototype.get$enableAwait = function() { |
| 9156 return $globals.experimentalAwaitPhase != null; |
| 9157 } |
| 9158 Parser.prototype.isPrematureEndOfFile = function() { |
| 9159 if (this.throwOnIncomplete && this._maybeEat(1/*TokenKind.END_OF_FILE*/) || th
is._maybeEat(68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/) || this._maybeEat(6
9/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/)) { |
| 9160 $throw(new IncompleteSourceException(this._previousToken)); |
| 9161 } |
| 9162 else if (this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { |
| 9163 this._lang_error('unexpected end of file', this._peekToken.get$span()); |
| 9164 return true; |
| 9165 } |
| 9166 else { |
| 9167 return false; |
| 9168 } |
| 9169 } |
| 9170 Parser.prototype._recoverTo = function(kind1, kind2, kind3) { |
| 9171 while (!this.isPrematureEndOfFile()) { |
| 9172 var kind = this._peek(); |
| 9173 if (kind == kind1 || kind == kind2 || kind == kind3) { |
| 9174 this._recover = false; |
| 9175 return true; |
| 9176 } |
| 9177 this._lang_next(); |
| 9178 } |
| 9179 return false; |
| 9180 } |
| 9181 Parser.prototype._peek = function() { |
| 9182 return this._peekToken.kind; |
| 9183 } |
| 9184 Parser.prototype._lang_next = function() { |
| 9185 this._previousToken = this._peekToken; |
| 9186 this._peekToken = this.tokenizer.next(); |
| 9187 return this._previousToken; |
| 9188 } |
| 9189 Parser.prototype._peekKind = function(kind) { |
| 9190 return this._peekToken.kind == kind; |
| 9191 } |
| 9192 Parser.prototype._peekIdentifier = function() { |
| 9193 return this._isIdentifier(this._peekToken.kind); |
| 9194 } |
| 9195 Parser.prototype._isIdentifier = function(kind) { |
| 9196 return TokenKind.isIdentifier(kind) || (!this.get$enableAwait() && $eq(kind, 8
8/*TokenKind.AWAIT*/)); |
| 9197 } |
| 9198 Parser.prototype._maybeEat = function(kind) { |
| 9199 if (this._peekToken.kind == kind) { |
| 9200 this._previousToken = this._peekToken; |
| 9201 this._peekToken = this.tokenizer.next(); |
| 9202 return true; |
| 9203 } |
| 9204 else { |
| 9205 return false; |
| 9206 } |
| 9207 } |
| 9208 Parser.prototype._eat = function(kind) { |
| 9209 if (!this._maybeEat(kind)) { |
| 9210 this._errorExpected(TokenKind.kindToString(kind)); |
| 9211 } |
| 9212 } |
| 9213 Parser.prototype._eatSemicolon = function() { |
| 9214 if (this.optionalSemicolons && this._peekKind(1/*TokenKind.END_OF_FILE*/)) ret
urn; |
| 9215 this._eat(10/*TokenKind.SEMICOLON*/); |
| 9216 } |
| 9217 Parser.prototype._errorExpected = function(expected) { |
| 9218 if (this.throwOnIncomplete) this.isPrematureEndOfFile(); |
| 9219 var tok = this._lang_next(); |
| 9220 if ((tok instanceof ErrorToken) && tok.message != null) { |
| 9221 this._lang_error(tok.message, tok.span); |
| 9222 } |
| 9223 else { |
| 9224 this._lang_error(('expected ' + expected + ', but found ' + tok), tok.span); |
| 9225 } |
| 9226 } |
| 9227 Parser.prototype._lang_error = function(message, location) { |
| 9228 if (this._recover) return; |
| 9229 if (location == null) { |
| 9230 location = this._peekToken.get$span(); |
| 9231 } |
| 9232 $globals.world.fatal(message, location); |
| 9233 this._recover = true; |
| 9234 } |
| 9235 Parser.prototype._skipBlock = function() { |
| 9236 var depth = 1; |
| 9237 this._eat(6/*TokenKind.LBRACE*/); |
| 9238 while (true) { |
| 9239 var tok = this._lang_next(); |
| 9240 if ($eq(tok.kind, 6/*TokenKind.LBRACE*/)) { |
| 9241 depth += 1; |
| 9242 } |
| 9243 else if ($eq(tok.kind, 7/*TokenKind.RBRACE*/)) { |
| 9244 depth -= 1; |
| 9245 if (depth == 0) return; |
| 9246 } |
| 9247 else if ($eq(tok.kind, 1/*TokenKind.END_OF_FILE*/)) { |
| 9248 this._lang_error('unexpected end of file during diet parse', tok.span); |
| 9249 return; |
| 9250 } |
| 9251 } |
| 9252 } |
| 9253 Parser.prototype._makeSpan = function(start) { |
| 9254 return new SourceSpan(this.source, start, this._previousToken.end); |
| 9255 } |
| 9256 Parser.prototype.compilationUnit = function() { |
| 9257 var ret = []; |
| 9258 this._maybeEat(13/*TokenKind.HASHBANG*/); |
| 9259 while (this._peekKind(12/*TokenKind.HASH*/)) { |
| 9260 ret.add$1(this.directive()); |
| 9261 } |
| 9262 this._recover = false; |
| 9263 while (!this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { |
| 9264 ret.add$1(this.topLevelDefinition()); |
| 9265 } |
| 9266 this._recover = false; |
| 9267 return ret; |
| 9268 } |
| 9269 Parser.prototype.directive = function() { |
| 9270 var start = this._peekToken.start; |
| 9271 this._eat(12/*TokenKind.HASH*/); |
| 9272 var name = this.identifier(); |
| 9273 var args = this.arguments(); |
| 9274 this._eatSemicolon(); |
| 9275 return new DirectiveDefinition(name, args, this._makeSpan(start)); |
| 9276 } |
| 9277 Parser.prototype.topLevelDefinition = function() { |
| 9278 switch (this._peek()) { |
| 9279 case 73/*TokenKind.CLASS*/: |
| 9280 |
| 9281 return this.classDefinition(73/*TokenKind.CLASS*/); |
| 9282 |
| 9283 case 79/*TokenKind.INTERFACE*/: |
| 9284 |
| 9285 return this.classDefinition(79/*TokenKind.INTERFACE*/); |
| 9286 |
| 9287 case 87/*TokenKind.TYPEDEF*/: |
| 9288 |
| 9289 return this.functionTypeAlias(); |
| 9290 |
| 9291 default: |
| 9292 |
| 9293 return this.declaration(true); |
| 9294 |
| 9295 } |
| 9296 } |
| 9297 Parser.prototype.classDefinition = function(kind) { |
| 9298 var start = this._peekToken.start; |
| 9299 this._eat(kind); |
| 9300 var name = this.identifier(); |
| 9301 var typeParams = null; |
| 9302 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9303 typeParams = this.typeParameters(); |
| 9304 } |
| 9305 var _extends = null; |
| 9306 if (this._maybeEat(74/*TokenKind.EXTENDS*/)) { |
| 9307 _extends = this.typeList(); |
| 9308 } |
| 9309 var _implements = null; |
| 9310 if (this._maybeEat(77/*TokenKind.IMPLEMENTS*/)) { |
| 9311 _implements = this.typeList(); |
| 9312 } |
| 9313 var _native = null; |
| 9314 if (this._maybeEat(81/*TokenKind.NATIVE*/)) { |
| 9315 _native = this.maybeStringLiteral(); |
| 9316 if (_native != null) _native = new NativeType(_native); |
| 9317 } |
| 9318 var _factory = null; |
| 9319 if (this._maybeEat(75/*TokenKind.FACTORY*/)) { |
| 9320 _factory = this.nameTypeReference(); |
| 9321 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9322 this.typeParameters(); |
| 9323 } |
| 9324 } |
| 9325 var body = []; |
| 9326 if (this._maybeEat(6/*TokenKind.LBRACE*/)) { |
| 9327 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 9328 body.add$1(this.declaration(true)); |
| 9329 if (this._recover) { |
| 9330 if (!this._recoverTo(7/*TokenKind.RBRACE*/, 10/*TokenKind.SEMICOLON*/))
break; |
| 9331 this._maybeEat(10/*TokenKind.SEMICOLON*/); |
| 9332 } |
| 9333 } |
| 9334 } |
| 9335 else { |
| 9336 this._errorExpected('block starting with "{" or ";"'); |
| 9337 } |
| 9338 return new TypeDefinition(kind == 73/*TokenKind.CLASS*/, name, typeParams, _ex
tends, _implements, _native, _factory, body, this._makeSpan(start)); |
| 9339 } |
| 9340 Parser.prototype.functionTypeAlias = function() { |
| 9341 var start = this._peekToken.start; |
| 9342 this._eat(87/*TokenKind.TYPEDEF*/); |
| 9343 var di = this.declaredIdentifier(false); |
| 9344 var typeParams = null; |
| 9345 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9346 typeParams = this.typeParameters(); |
| 9347 } |
| 9348 var formals = this.formalParameterList(); |
| 9349 this._eatSemicolon(); |
| 9350 var func = new FunctionDefinition(null, di.type, di.name, formals, null, null,
null, null, this._makeSpan(start)); |
| 9351 return new FunctionTypeDefinition(func, typeParams, this._makeSpan(start)); |
| 9352 } |
| 9353 Parser.prototype.initializers = function() { |
| 9354 this._inhibitLambda = true; |
| 9355 var ret = []; |
| 9356 do { |
| 9357 ret.add$1(this.expression()); |
| 9358 } |
| 9359 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9360 this._inhibitLambda = false; |
| 9361 return ret; |
| 9362 } |
| 9363 Parser.prototype.get$initializers = function() { |
| 9364 return Parser.prototype.initializers.bind(this); |
| 9365 } |
| 9366 Parser.prototype.functionBody = function(inExpression) { |
| 9367 var start = this._peekToken.start; |
| 9368 if (this._maybeEat(9/*TokenKind.ARROW*/)) { |
| 9369 var expr = this.expression(); |
| 9370 if (!inExpression) { |
| 9371 this._eatSemicolon(); |
| 9372 } |
| 9373 return new ReturnStatement(expr, this._makeSpan(start)); |
| 9374 } |
| 9375 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 9376 if (this.diet) { |
| 9377 this._skipBlock(); |
| 9378 return new DietStatement(this._makeSpan(start)); |
| 9379 } |
| 9380 else { |
| 9381 return this.block(); |
| 9382 } |
| 9383 } |
| 9384 else if (!inExpression) { |
| 9385 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 9386 return null; |
| 9387 } |
| 9388 } |
| 9389 this._lang_error('Expected function body (neither { nor => found)'); |
| 9390 } |
| 9391 Parser.prototype.finishField = function(start, modifiers, typeParams, type, name
, value) { |
| 9392 if (typeParams != null) { |
| 9393 $globals.world.internalError('trying to create a generic field', this._makeS
pan(start)); |
| 9394 } |
| 9395 var names = [name]; |
| 9396 var values = [value]; |
| 9397 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9398 names.add$1(this.identifier()); |
| 9399 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 9400 values.add$1(this.expression()); |
| 9401 } |
| 9402 else { |
| 9403 values.add$1(); |
| 9404 } |
| 9405 } |
| 9406 this._eatSemicolon(); |
| 9407 return new VariableDefinition(modifiers, type, names, values, this._makeSpan(s
tart)); |
| 9408 } |
| 9409 Parser.prototype.finishDefinition = function(start, modifiers, di, typeParams) { |
| 9410 switch (this._peek()) { |
| 9411 case 2/*TokenKind.LPAREN*/: |
| 9412 |
| 9413 var formals = this.formalParameterList(); |
| 9414 var inits = null, native_ = null; |
| 9415 if (this._maybeEat(8/*TokenKind.COLON*/)) { |
| 9416 inits = this.initializers(); |
| 9417 } |
| 9418 if (this._maybeEat(81/*TokenKind.NATIVE*/)) { |
| 9419 native_ = this.maybeStringLiteral(); |
| 9420 if (native_ == null) native_ = ''; |
| 9421 } |
| 9422 var body = this.functionBody(false); |
| 9423 if (di.name == null) { |
| 9424 di.name = di.type.name; |
| 9425 } |
| 9426 return new FunctionDefinition(modifiers, di.type, di.name, formals, typePa
rams, inits, native_, body, this._makeSpan(start)); |
| 9427 |
| 9428 case 20/*TokenKind.ASSIGN*/: |
| 9429 |
| 9430 this._eat(20/*TokenKind.ASSIGN*/); |
| 9431 var value = this.expression(); |
| 9432 return this.finishField(start, modifiers, typeParams, di.type, di.name, va
lue); |
| 9433 |
| 9434 case 11/*TokenKind.COMMA*/: |
| 9435 case 10/*TokenKind.SEMICOLON*/: |
| 9436 |
| 9437 return this.finishField(start, modifiers, typeParams, di.type, di.name, nu
ll); |
| 9438 |
| 9439 default: |
| 9440 |
| 9441 this._errorExpected('declaration'); |
| 9442 return null; |
| 9443 |
| 9444 } |
| 9445 } |
| 9446 Parser.prototype.declaration = function(includeOperators) { |
| 9447 var start = this._peekToken.start; |
| 9448 if (this._peekKind(75/*TokenKind.FACTORY*/)) { |
| 9449 return this.factoryConstructorDeclaration(); |
| 9450 } |
| 9451 var modifiers = this._readModifiers(); |
| 9452 return this.finishDefinition(start, modifiers, this.declaredIdentifier(include
Operators), null); |
| 9453 } |
| 9454 Parser.prototype.factoryConstructorDeclaration = function() { |
| 9455 var start = this._peekToken.start; |
| 9456 var factoryToken = this._lang_next(); |
| 9457 var names = [this.identifier()]; |
| 9458 while (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 9459 names.add$1(this.identifier()); |
| 9460 } |
| 9461 var typeParams = null; |
| 9462 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9463 typeParams = this.typeParameters(); |
| 9464 } |
| 9465 var name = null; |
| 9466 var type = null; |
| 9467 if (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 9468 name = this.identifier(); |
| 9469 } |
| 9470 else if (typeParams == null) { |
| 9471 if (names.length > 1) { |
| 9472 name = names.removeLast$0(); |
| 9473 } |
| 9474 else { |
| 9475 name = new Identifier('', names.$index(0).span); |
| 9476 } |
| 9477 } |
| 9478 else { |
| 9479 name = new Identifier('', names.$index(0).span); |
| 9480 } |
| 9481 if (names.length > 1) { |
| 9482 this._lang_error('unsupported qualified name for factory', names.$index(0).s
pan); |
| 9483 } |
| 9484 type = new NameTypeReference(false, names.$index(0), null, names.$index(0).spa
n); |
| 9485 var di = new DeclaredIdentifier(type, name, this._makeSpan(start)); |
| 9486 return this.finishDefinition(start, [factoryToken], di, typeParams); |
| 9487 } |
| 9488 Parser.prototype.statement = function() { |
| 9489 switch (this._peek()) { |
| 9490 case 89/*TokenKind.BREAK*/: |
| 9491 |
| 9492 return this.breakStatement(); |
| 9493 |
| 9494 case 93/*TokenKind.CONTINUE*/: |
| 9495 |
| 9496 return this.continueStatement(); |
| 9497 |
| 9498 case 106/*TokenKind.RETURN*/: |
| 9499 |
| 9500 return this.returnStatement(); |
| 9501 |
| 9502 case 110/*TokenKind.THROW*/: |
| 9503 |
| 9504 return this.throwStatement(); |
| 9505 |
| 9506 case 72/*TokenKind.ASSERT*/: |
| 9507 |
| 9508 return this.assertStatement(); |
| 9509 |
| 9510 case 115/*TokenKind.WHILE*/: |
| 9511 |
| 9512 return this.whileStatement(); |
| 9513 |
| 9514 case 95/*TokenKind.DO*/: |
| 9515 |
| 9516 return this.doStatement(); |
| 9517 |
| 9518 case 100/*TokenKind.FOR*/: |
| 9519 |
| 9520 return this.forStatement(); |
| 9521 |
| 9522 case 101/*TokenKind.IF*/: |
| 9523 |
| 9524 return this.ifStatement(); |
| 9525 |
| 9526 case 108/*TokenKind.SWITCH*/: |
| 9527 |
| 9528 return this.switchStatement(); |
| 9529 |
| 9530 case 112/*TokenKind.TRY*/: |
| 9531 |
| 9532 return this.tryStatement(); |
| 9533 |
| 9534 case 6/*TokenKind.LBRACE*/: |
| 9535 |
| 9536 return this.block(); |
| 9537 |
| 9538 case 10/*TokenKind.SEMICOLON*/: |
| 9539 |
| 9540 return this.emptyStatement(); |
| 9541 |
| 9542 case 98/*TokenKind.FINAL*/: |
| 9543 |
| 9544 return this.declaration(false); |
| 9545 |
| 9546 case 113/*TokenKind.VAR*/: |
| 9547 |
| 9548 return this.declaration(false); |
| 9549 |
| 9550 default: |
| 9551 |
| 9552 return this.finishExpressionAsStatement(this.expression()); |
| 9553 |
| 9554 } |
| 9555 } |
| 9556 Parser.prototype.finishExpressionAsStatement = function(expr) { |
| 9557 var start = expr.span.start; |
| 9558 if (this._maybeEat(8/*TokenKind.COLON*/)) { |
| 9559 var label = this._makeLabel(expr); |
| 9560 return new LabeledStatement(label, this.statement(), this._makeSpan(start)); |
| 9561 } |
| 9562 if ((expr instanceof LambdaExpression)) { |
| 9563 if (!(expr.get$func().body instanceof BlockStatement)) { |
| 9564 this._eatSemicolon(); |
| 9565 expr.get$func().span = this._makeSpan(start); |
| 9566 } |
| 9567 return expr.get$func(); |
| 9568 } |
| 9569 else if ((expr instanceof DeclaredIdentifier)) { |
| 9570 var value = null; |
| 9571 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 9572 value = this.expression(); |
| 9573 } |
| 9574 return this.finishField(start, null, null, expr.type, expr.name, value); |
| 9575 } |
| 9576 else if (this._isBin(expr, 20/*TokenKind.ASSIGN*/) && ((expr.x instanceof Decl
aredIdentifier))) { |
| 9577 var di = expr.x; |
| 9578 return this.finishField(start, null, null, di.type, di.name, expr.y); |
| 9579 } |
| 9580 else if (this._isBin(expr, 52/*TokenKind.LT*/) && this._maybeEat(11/*TokenKind
.COMMA*/)) { |
| 9581 var baseType = this._makeType(expr.x); |
| 9582 var typeArgs = [this._makeType(expr.y)]; |
| 9583 var gt = this._finishTypeArguments(baseType, 0, typeArgs); |
| 9584 var name = this.identifier(); |
| 9585 var value = null; |
| 9586 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 9587 value = this.expression(); |
| 9588 } |
| 9589 return this.finishField(expr.span.start, null, null, gt, name, value); |
| 9590 } |
| 9591 else { |
| 9592 this._eatSemicolon(); |
| 9593 return new ExpressionStatement(expr, this._makeSpan(expr.span.start)); |
| 9594 } |
| 9595 } |
| 9596 Parser.prototype.testCondition = function() { |
| 9597 this._eatLeftParen(); |
| 9598 var ret = this.expression(); |
| 9599 this._eat(3/*TokenKind.RPAREN*/); |
| 9600 return ret; |
| 9601 } |
| 9602 Parser.prototype.block = function() { |
| 9603 var start = this._peekToken.start; |
| 9604 this._eat(6/*TokenKind.LBRACE*/); |
| 9605 var stmts = []; |
| 9606 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 9607 stmts.add$1(this.statement()); |
| 9608 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 10/*TokenKind.S
EMICOLON*/)) break; |
| 9609 } |
| 9610 this._recover = false; |
| 9611 return new BlockStatement(stmts, this._makeSpan(start)); |
| 9612 } |
| 9613 Parser.prototype.get$block = function() { |
| 9614 return Parser.prototype.block.bind(this); |
| 9615 } |
| 9616 Parser.prototype.emptyStatement = function() { |
| 9617 var start = this._peekToken.start; |
| 9618 this._eat(10/*TokenKind.SEMICOLON*/); |
| 9619 return new EmptyStatement(this._makeSpan(start)); |
| 9620 } |
| 9621 Parser.prototype.ifStatement = function() { |
| 9622 var start = this._peekToken.start; |
| 9623 this._eat(101/*TokenKind.IF*/); |
| 9624 var test = this.testCondition(); |
| 9625 var trueBranch = this.statement(); |
| 9626 var falseBranch = null; |
| 9627 if (this._maybeEat(96/*TokenKind.ELSE*/)) { |
| 9628 falseBranch = this.statement(); |
| 9629 } |
| 9630 return new IfStatement(test, trueBranch, falseBranch, this._makeSpan(start)); |
| 9631 } |
| 9632 Parser.prototype.whileStatement = function() { |
| 9633 var start = this._peekToken.start; |
| 9634 this._eat(115/*TokenKind.WHILE*/); |
| 9635 var test = this.testCondition(); |
| 9636 var body = this.statement(); |
| 9637 return new WhileStatement(test, body, this._makeSpan(start)); |
| 9638 } |
| 9639 Parser.prototype.doStatement = function() { |
| 9640 var start = this._peekToken.start; |
| 9641 this._eat(95/*TokenKind.DO*/); |
| 9642 var body = this.statement(); |
| 9643 this._eat(115/*TokenKind.WHILE*/); |
| 9644 var test = this.testCondition(); |
| 9645 this._eatSemicolon(); |
| 9646 return new DoStatement(body, test, this._makeSpan(start)); |
| 9647 } |
| 9648 Parser.prototype.forStatement = function() { |
| 9649 var start = this._peekToken.start; |
| 9650 this._eat(100/*TokenKind.FOR*/); |
| 9651 this._eatLeftParen(); |
| 9652 var init = this.forInitializerStatement(start); |
| 9653 if ((init instanceof ForInStatement)) { |
| 9654 return init; |
| 9655 } |
| 9656 var test = null; |
| 9657 if (!this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 9658 test = this.expression(); |
| 9659 this._eatSemicolon(); |
| 9660 } |
| 9661 var step = []; |
| 9662 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 9663 step.add$1(this.expression()); |
| 9664 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9665 step.add$1(this.expression()); |
| 9666 } |
| 9667 this._eat(3/*TokenKind.RPAREN*/); |
| 9668 } |
| 9669 var body = this.statement(); |
| 9670 return new ForStatement(init, test, step, body, this._makeSpan(start)); |
| 9671 } |
| 9672 Parser.prototype.forInitializerStatement = function(start) { |
| 9673 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 9674 return null; |
| 9675 } |
| 9676 else { |
| 9677 var init = this.expression(); |
| 9678 if (this._peekKind(11/*TokenKind.COMMA*/) && this._isBin(init, 52/*TokenKind
.LT*/)) { |
| 9679 this._eat(11/*TokenKind.COMMA*/); |
| 9680 var baseType = this._makeType(init.x); |
| 9681 var typeArgs = [this._makeType(init.y)]; |
| 9682 var gt = this._finishTypeArguments(baseType, 0, typeArgs); |
| 9683 var name = this.identifier(); |
| 9684 init = new DeclaredIdentifier(gt, name, this._makeSpan(init.span.start)); |
| 9685 } |
| 9686 if (this._maybeEat(102/*TokenKind.IN*/)) { |
| 9687 return this._finishForIn(start, this._makeDeclaredIdentifier(init)); |
| 9688 } |
| 9689 else { |
| 9690 return this.finishExpressionAsStatement(init); |
| 9691 } |
| 9692 } |
| 9693 } |
| 9694 Parser.prototype._finishForIn = function(start, di) { |
| 9695 var expr = this.expression(); |
| 9696 this._eat(3/*TokenKind.RPAREN*/); |
| 9697 var body = this.statement(); |
| 9698 return new ForInStatement(di, expr, body, this._makeSpan(start)); |
| 9699 } |
| 9700 Parser.prototype.tryStatement = function() { |
| 9701 var start = this._peekToken.start; |
| 9702 this._eat(112/*TokenKind.TRY*/); |
| 9703 var body = this.block(); |
| 9704 var catches = []; |
| 9705 while (this._peekKind(91/*TokenKind.CATCH*/)) { |
| 9706 catches.add$1(this.catchNode()); |
| 9707 } |
| 9708 var finallyBlock = null; |
| 9709 if (this._maybeEat(99/*TokenKind.FINALLY*/)) { |
| 9710 finallyBlock = this.block(); |
| 9711 } |
| 9712 return new TryStatement(body, catches, finallyBlock, this._makeSpan(start)); |
| 9713 } |
| 9714 Parser.prototype.catchNode = function() { |
| 9715 var start = this._peekToken.start; |
| 9716 this._eat(91/*TokenKind.CATCH*/); |
| 9717 this._eatLeftParen(); |
| 9718 var exc = this.declaredIdentifier(false); |
| 9719 var trace = null; |
| 9720 if (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9721 trace = this.declaredIdentifier(false); |
| 9722 } |
| 9723 this._eat(3/*TokenKind.RPAREN*/); |
| 9724 var body = this.block(); |
| 9725 return new CatchNode(exc, trace, body, this._makeSpan(start)); |
| 9726 } |
| 9727 Parser.prototype.switchStatement = function() { |
| 9728 var start = this._peekToken.start; |
| 9729 this._eat(108/*TokenKind.SWITCH*/); |
| 9730 var test = this.testCondition(); |
| 9731 var cases = []; |
| 9732 this._eat(6/*TokenKind.LBRACE*/); |
| 9733 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 9734 cases.add$1(this.caseNode()); |
| 9735 } |
| 9736 return new SwitchStatement(test, cases, this._makeSpan(start)); |
| 9737 } |
| 9738 Parser.prototype._peekCaseEnd = function() { |
| 9739 var kind = this._peek(); |
| 9740 return $eq(kind, 7/*TokenKind.RBRACE*/) || $eq(kind, 90/*TokenKind.CASE*/) ||
$eq(kind, 94/*TokenKind.DEFAULT*/); |
| 9741 } |
| 9742 Parser.prototype.caseNode = function() { |
| 9743 var start = this._peekToken.start; |
| 9744 var label = null; |
| 9745 if (this._peekIdentifier()) { |
| 9746 label = this.identifier(); |
| 9747 this._eat(8/*TokenKind.COLON*/); |
| 9748 } |
| 9749 var cases = []; |
| 9750 while (true) { |
| 9751 if (this._maybeEat(90/*TokenKind.CASE*/)) { |
| 9752 cases.add$1(this.expression()); |
| 9753 this._eat(8/*TokenKind.COLON*/); |
| 9754 } |
| 9755 else if (this._maybeEat(94/*TokenKind.DEFAULT*/)) { |
| 9756 cases.add$1(); |
| 9757 this._eat(8/*TokenKind.COLON*/); |
| 9758 } |
| 9759 else { |
| 9760 break; |
| 9761 } |
| 9762 } |
| 9763 if ($eq(cases.length, 0)) { |
| 9764 this._lang_error('case or default'); |
| 9765 } |
| 9766 var stmts = []; |
| 9767 while (!this._peekCaseEnd()) { |
| 9768 stmts.add$1(this.statement()); |
| 9769 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 90/*TokenKind.C
ASE*/, 94/*TokenKind.DEFAULT*/)) { |
| 9770 break; |
| 9771 } |
| 9772 } |
| 9773 return new CaseNode(label, cases, stmts, this._makeSpan(start)); |
| 9774 } |
| 9775 Parser.prototype.returnStatement = function() { |
| 9776 var start = this._peekToken.start; |
| 9777 this._eat(106/*TokenKind.RETURN*/); |
| 9778 var expr; |
| 9779 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 9780 expr = null; |
| 9781 } |
| 9782 else { |
| 9783 expr = this.expression(); |
| 9784 this._eatSemicolon(); |
| 9785 } |
| 9786 return new ReturnStatement(expr, this._makeSpan(start)); |
| 9787 } |
| 9788 Parser.prototype.throwStatement = function() { |
| 9789 var start = this._peekToken.start; |
| 9790 this._eat(110/*TokenKind.THROW*/); |
| 9791 var expr; |
| 9792 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 9793 expr = null; |
| 9794 } |
| 9795 else { |
| 9796 expr = this.expression(); |
| 9797 this._eatSemicolon(); |
| 9798 } |
| 9799 return new ThrowStatement(expr, this._makeSpan(start)); |
| 9800 } |
| 9801 Parser.prototype.assertStatement = function() { |
| 9802 var start = this._peekToken.start; |
| 9803 this._eat(72/*TokenKind.ASSERT*/); |
| 9804 this._eatLeftParen(); |
| 9805 var expr = this.expression(); |
| 9806 this._eat(3/*TokenKind.RPAREN*/); |
| 9807 this._eatSemicolon(); |
| 9808 return new AssertStatement(expr, this._makeSpan(start)); |
| 9809 } |
| 9810 Parser.prototype.breakStatement = function() { |
| 9811 var start = this._peekToken.start; |
| 9812 this._eat(89/*TokenKind.BREAK*/); |
| 9813 var name = null; |
| 9814 if (this._peekIdentifier()) { |
| 9815 name = this.identifier(); |
| 9816 } |
| 9817 this._eatSemicolon(); |
| 9818 return new BreakStatement(name, this._makeSpan(start)); |
| 9819 } |
| 9820 Parser.prototype.continueStatement = function() { |
| 9821 var start = this._peekToken.start; |
| 9822 this._eat(93/*TokenKind.CONTINUE*/); |
| 9823 var name = null; |
| 9824 if (this._peekIdentifier()) { |
| 9825 name = this.identifier(); |
| 9826 } |
| 9827 this._eatSemicolon(); |
| 9828 return new ContinueStatement(name, this._makeSpan(start)); |
| 9829 } |
| 9830 Parser.prototype.expression = function() { |
| 9831 return this.infixExpression(0); |
| 9832 } |
| 9833 Parser.prototype._makeType = function(expr) { |
| 9834 if ((expr instanceof VarExpression)) { |
| 9835 return new NameTypeReference(false, expr.name, null, expr.span); |
| 9836 } |
| 9837 else if ((expr instanceof DotExpression)) { |
| 9838 var type = this._makeType(expr.self); |
| 9839 if (type.get$names() == null) { |
| 9840 type.set$names([expr.name]); |
| 9841 } |
| 9842 else { |
| 9843 type.get$names().add$1(expr.name); |
| 9844 } |
| 9845 type.span = expr.span; |
| 9846 return type; |
| 9847 } |
| 9848 else { |
| 9849 this._lang_error('expected type reference'); |
| 9850 return null; |
| 9851 } |
| 9852 } |
| 9853 Parser.prototype.infixExpression = function(precedence) { |
| 9854 return this.finishInfixExpression(this.unaryExpression(), precedence); |
| 9855 } |
| 9856 Parser.prototype._finishDeclaredId = function(type) { |
| 9857 var name = this.identifier(); |
| 9858 return this.finishPostfixExpression(new DeclaredIdentifier(type, name, this._m
akeSpan(type.span.start))); |
| 9859 } |
| 9860 Parser.prototype._fixAsType = function(x) { |
| 9861 if (this._maybeEat(53/*TokenKind.GT*/)) { |
| 9862 var base = this._makeType(x.x); |
| 9863 var typeParam = this._makeType(x.y); |
| 9864 var type = new GenericTypeReference(base, [typeParam], 0, this._makeSpan(x.s
pan.start)); |
| 9865 return this._finishDeclaredId(type); |
| 9866 } |
| 9867 else { |
| 9868 var base = this._makeType(x.x); |
| 9869 var paramBase = this._makeType(x.y); |
| 9870 var firstParam = this.addTypeArguments(paramBase, 1); |
| 9871 var type; |
| 9872 if (firstParam.depth <= 0) { |
| 9873 type = new GenericTypeReference(base, [firstParam], 0, this._makeSpan(x.sp
an.start)); |
| 9874 } |
| 9875 else if (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9876 type = this._finishTypeArguments(base, 0, [firstParam]); |
| 9877 } |
| 9878 else { |
| 9879 this._eat(53/*TokenKind.GT*/); |
| 9880 type = new GenericTypeReference(base, [firstParam], 0, this._makeSpan(x.sp
an.start)); |
| 9881 } |
| 9882 return this._finishDeclaredId(type); |
| 9883 } |
| 9884 } |
| 9885 Parser.prototype.finishInfixExpression = function(x, precedence) { |
| 9886 while (true) { |
| 9887 var kind = this._peek(); |
| 9888 var prec = TokenKind.infixPrecedence(this._peek()); |
| 9889 if (prec >= precedence) { |
| 9890 if (kind == 52/*TokenKind.LT*/ || kind == 53/*TokenKind.GT*/) { |
| 9891 if (this._isBin(x, 52/*TokenKind.LT*/)) { |
| 9892 return this._fixAsType(x); |
| 9893 } |
| 9894 } |
| 9895 var op = this._lang_next(); |
| 9896 if ($eq(op.kind, 103/*TokenKind.IS*/)) { |
| 9897 var isTrue = !this._maybeEat(19/*TokenKind.NOT*/); |
| 9898 var typeRef = this.type(0); |
| 9899 x = new IsExpression(isTrue, x, typeRef, this._makeSpan(x.span.start)); |
| 9900 continue; |
| 9901 } |
| 9902 var y = this.infixExpression($eq(prec, 2) ? prec : prec + 1); |
| 9903 if ($eq(op.kind, 33/*TokenKind.CONDITIONAL*/)) { |
| 9904 this._eat(8/*TokenKind.COLON*/); |
| 9905 var z = this.infixExpression(prec); |
| 9906 x = new ConditionalExpression(x, y, z, this._makeSpan(x.span.start)); |
| 9907 } |
| 9908 else { |
| 9909 x = new BinaryExpression(op, x, y, this._makeSpan(x.span.start)); |
| 9910 } |
| 9911 } |
| 9912 else { |
| 9913 break; |
| 9914 } |
| 9915 } |
| 9916 return x; |
| 9917 } |
| 9918 Parser.prototype._isPrefixUnaryOperator = function(kind) { |
| 9919 switch (kind) { |
| 9920 case 42/*TokenKind.ADD*/: |
| 9921 case 43/*TokenKind.SUB*/: |
| 9922 case 19/*TokenKind.NOT*/: |
| 9923 case 18/*TokenKind.BIT_NOT*/: |
| 9924 case 16/*TokenKind.INCR*/: |
| 9925 case 17/*TokenKind.DECR*/: |
| 9926 |
| 9927 return true; |
| 9928 |
| 9929 default: |
| 9930 |
| 9931 return false; |
| 9932 |
| 9933 } |
| 9934 } |
| 9935 Parser.prototype.unaryExpression = function() { |
| 9936 var start = this._peekToken.start; |
| 9937 if (this._isPrefixUnaryOperator(this._peek())) { |
| 9938 var tok = this._lang_next(); |
| 9939 var expr = this.unaryExpression(); |
| 9940 return new UnaryExpression(tok, expr, this._makeSpan(start)); |
| 9941 } |
| 9942 else if (this.get$enableAwait() && this._maybeEat(88/*TokenKind.AWAIT*/)) { |
| 9943 var expr = this.unaryExpression(); |
| 9944 return new AwaitExpression(expr, this._makeSpan(start)); |
| 9945 } |
| 9946 return this.finishPostfixExpression(this.primary()); |
| 9947 } |
| 9948 Parser.prototype.argument = function() { |
| 9949 var start = this._peekToken.start; |
| 9950 var expr; |
| 9951 var label = null; |
| 9952 if (this._maybeEat(15/*TokenKind.ELLIPSIS*/)) { |
| 9953 label = new Identifier('...', this._makeSpan(start)); |
| 9954 } |
| 9955 expr = this.expression(); |
| 9956 if (label == null && this._maybeEat(8/*TokenKind.COLON*/)) { |
| 9957 label = this._makeLabel(expr); |
| 9958 expr = this.expression(); |
| 9959 } |
| 9960 return new ArgumentNode(label, expr, this._makeSpan(start)); |
| 9961 } |
| 9962 Parser.prototype.arguments = function() { |
| 9963 var args = []; |
| 9964 this._eatLeftParen(); |
| 9965 var saved = this._inhibitLambda; |
| 9966 this._inhibitLambda = false; |
| 9967 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 9968 do { |
| 9969 args.add$1(this.argument()); |
| 9970 } |
| 9971 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9972 this._eat(3/*TokenKind.RPAREN*/); |
| 9973 } |
| 9974 this._inhibitLambda = saved; |
| 9975 return args; |
| 9976 } |
| 9977 Parser.prototype.get$arguments = function() { |
| 9978 return Parser.prototype.arguments.bind(this); |
| 9979 } |
| 9980 Parser.prototype.finishPostfixExpression = function(expr) { |
| 9981 switch (this._peek()) { |
| 9982 case 2/*TokenKind.LPAREN*/: |
| 9983 |
| 9984 return this.finishCallOrLambdaExpression(expr); |
| 9985 |
| 9986 case 4/*TokenKind.LBRACK*/: |
| 9987 |
| 9988 this._eat(4/*TokenKind.LBRACK*/); |
| 9989 var index = this.expression(); |
| 9990 this._eat(5/*TokenKind.RBRACK*/); |
| 9991 return this.finishPostfixExpression(new IndexExpression(expr, index, this.
_makeSpan(expr.span.start))); |
| 9992 |
| 9993 case 14/*TokenKind.DOT*/: |
| 9994 |
| 9995 this._eat(14/*TokenKind.DOT*/); |
| 9996 var name = this.identifier(); |
| 9997 var ret = new DotExpression(expr, name, this._makeSpan(expr.span.start)); |
| 9998 return this.finishPostfixExpression(ret); |
| 9999 |
| 10000 case 16/*TokenKind.INCR*/: |
| 10001 case 17/*TokenKind.DECR*/: |
| 10002 |
| 10003 var tok = this._lang_next(); |
| 10004 return new PostfixExpression(expr, tok, this._makeSpan(expr.span.start)); |
| 10005 |
| 10006 case 9/*TokenKind.ARROW*/: |
| 10007 case 6/*TokenKind.LBRACE*/: |
| 10008 |
| 10009 return expr; |
| 10010 |
| 10011 default: |
| 10012 |
| 10013 if (this._peekIdentifier()) { |
| 10014 return this.finishPostfixExpression(new DeclaredIdentifier(this._makeTyp
e(expr), this.identifier(), this._makeSpan(expr.span.start))); |
| 10015 } |
| 10016 else { |
| 10017 return expr; |
| 10018 } |
| 10019 |
| 10020 } |
| 10021 } |
| 10022 Parser.prototype.finishCallOrLambdaExpression = function(expr) { |
| 10023 if (this._atClosureParameters()) { |
| 10024 var formals = this.formalParameterList(); |
| 10025 var body = this.functionBody(true); |
| 10026 return this._makeFunction(expr, formals, body); |
| 10027 } |
| 10028 else { |
| 10029 if ((expr instanceof DeclaredIdentifier)) { |
| 10030 this._lang_error('illegal target for call, did you mean to declare a funct
ion?', expr.span); |
| 10031 } |
| 10032 var args = this.arguments(); |
| 10033 return this.finishPostfixExpression(new CallExpression(expr, args, this._mak
eSpan(expr.span.start))); |
| 10034 } |
| 10035 } |
| 10036 Parser.prototype._isBin = function(expr, kind) { |
| 10037 return (expr instanceof BinaryExpression) && $eq(expr.get$op().kind, kind); |
| 10038 } |
| 10039 Parser.prototype._boolTypeRef = function(span) { |
| 10040 return new TypeReference(span, $globals.world.nonNullBool); |
| 10041 } |
| 10042 Parser.prototype._intTypeRef = function(span) { |
| 10043 return new TypeReference(span, $globals.world.intType); |
| 10044 } |
| 10045 Parser.prototype._doubleTypeRef = function(span) { |
| 10046 return new TypeReference(span, $globals.world.doubleType); |
| 10047 } |
| 10048 Parser.prototype._stringTypeRef = function(span) { |
| 10049 return new TypeReference(span, $globals.world.stringType); |
| 10050 } |
| 10051 Parser.prototype.primary = function() { |
| 10052 var start = this._peekToken.start; |
| 10053 switch (this._peek()) { |
| 10054 case 109/*TokenKind.THIS*/: |
| 10055 |
| 10056 this._eat(109/*TokenKind.THIS*/); |
| 10057 return new ThisExpression(this._makeSpan(start)); |
| 10058 |
| 10059 case 107/*TokenKind.SUPER*/: |
| 10060 |
| 10061 this._eat(107/*TokenKind.SUPER*/); |
| 10062 return new SuperExpression(this._makeSpan(start)); |
| 10063 |
| 10064 case 92/*TokenKind.CONST*/: |
| 10065 |
| 10066 this._eat(92/*TokenKind.CONST*/); |
| 10067 if (this._peekKind(4/*TokenKind.LBRACK*/) || this._peekKind(56/*TokenKind.
INDEX*/)) { |
| 10068 return this.finishListLiteral(start, true, null); |
| 10069 } |
| 10070 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 10071 return this.finishMapLiteral(start, true, null); |
| 10072 } |
| 10073 else if (this._peekKind(52/*TokenKind.LT*/)) { |
| 10074 return this.finishTypedLiteral(start, true); |
| 10075 } |
| 10076 else { |
| 10077 return this.finishNewExpression(start, true); |
| 10078 } |
| 10079 |
| 10080 case 104/*TokenKind.NEW*/: |
| 10081 |
| 10082 this._eat(104/*TokenKind.NEW*/); |
| 10083 return this.finishNewExpression(start, false); |
| 10084 |
| 10085 case 2/*TokenKind.LPAREN*/: |
| 10086 |
| 10087 return this._parenOrLambda(); |
| 10088 |
| 10089 case 4/*TokenKind.LBRACK*/: |
| 10090 case 56/*TokenKind.INDEX*/: |
| 10091 |
| 10092 return this.finishListLiteral(start, false, null); |
| 10093 |
| 10094 case 6/*TokenKind.LBRACE*/: |
| 10095 |
| 10096 return this.finishMapLiteral(start, false, null); |
| 10097 |
| 10098 case 105/*TokenKind.NULL*/: |
| 10099 |
| 10100 this._eat(105/*TokenKind.NULL*/); |
| 10101 return new NullExpression(this._makeSpan(start)); |
| 10102 |
| 10103 case 111/*TokenKind.TRUE*/: |
| 10104 |
| 10105 this._eat(111/*TokenKind.TRUE*/); |
| 10106 return new LiteralExpression(true, this._boolTypeRef(this._makeSpan(start)
), 'true', this._makeSpan(start)); |
| 10107 |
| 10108 case 97/*TokenKind.FALSE*/: |
| 10109 |
| 10110 this._eat(97/*TokenKind.FALSE*/); |
| 10111 return new LiteralExpression(false, this._boolTypeRef(this._makeSpan(start
)), 'false', this._makeSpan(start)); |
| 10112 |
| 10113 case 61/*TokenKind.HEX_INTEGER*/: |
| 10114 |
| 10115 var t = this._lang_next(); |
| 10116 return new LiteralExpression(Parser.parseHex(t.text.substring$1(2)), this.
_intTypeRef(this._makeSpan(start)), t.text, this._makeSpan(start)); |
| 10117 |
| 10118 case 60/*TokenKind.INTEGER*/: |
| 10119 |
| 10120 var t = this._lang_next(); |
| 10121 return new LiteralExpression(Math.parseInt(t.text), this._intTypeRef(this.
_makeSpan(start)), t.text, this._makeSpan(start)); |
| 10122 |
| 10123 case 62/*TokenKind.DOUBLE*/: |
| 10124 |
| 10125 var t = this._lang_next(); |
| 10126 return new LiteralExpression(Math.parseDouble(t.text), this._doubleTypeRef
(this._makeSpan(start)), t.text, this._makeSpan(start)); |
| 10127 |
| 10128 case 58/*TokenKind.STRING*/: |
| 10129 |
| 10130 return this.stringLiteralExpr(); |
| 10131 |
| 10132 case 66/*TokenKind.INCOMPLETE_STRING*/: |
| 10133 |
| 10134 return this.stringInterpolation(); |
| 10135 |
| 10136 case 52/*TokenKind.LT*/: |
| 10137 |
| 10138 return this.finishTypedLiteral(start, false); |
| 10139 |
| 10140 case 114/*TokenKind.VOID*/: |
| 10141 case 113/*TokenKind.VAR*/: |
| 10142 case 98/*TokenKind.FINAL*/: |
| 10143 |
| 10144 return this.declaredIdentifier(false); |
| 10145 |
| 10146 default: |
| 10147 |
| 10148 if (!this._peekIdentifier()) { |
| 10149 this._errorExpected('expression'); |
| 10150 } |
| 10151 return new VarExpression(this.identifier(), this._makeSpan(start)); |
| 10152 |
| 10153 } |
| 10154 } |
| 10155 Parser.prototype.stringInterpolation = function() { |
| 10156 var start = this._peekToken.start; |
| 10157 var lits = []; |
| 10158 var startQuote = null, endQuote = null; |
| 10159 while (this._peekKind(66/*TokenKind.INCOMPLETE_STRING*/)) { |
| 10160 var token = this._lang_next(); |
| 10161 var text = token.text; |
| 10162 if (startQuote == null) { |
| 10163 if (isMultilineString(text)) { |
| 10164 endQuote = text.substring$2(0, 3); |
| 10165 startQuote = endQuote + '\n'; |
| 10166 } |
| 10167 else { |
| 10168 startQuote = endQuote = text.$index(0); |
| 10169 } |
| 10170 text = text.substring$2(0, text.length - 1) + endQuote; |
| 10171 } |
| 10172 else { |
| 10173 text = startQuote + text.substring$2(0, text.length - 1) + endQuote; |
| 10174 } |
| 10175 lits.add$1(this.makeStringLiteral(text, token.span)); |
| 10176 if (this._maybeEat(6/*TokenKind.LBRACE*/)) { |
| 10177 lits.add$1(this.expression()); |
| 10178 this._eat(7/*TokenKind.RBRACE*/); |
| 10179 } |
| 10180 else if (this._maybeEat(109/*TokenKind.THIS*/)) { |
| 10181 lits.add$1(new ThisExpression(this._previousToken.get$span())); |
| 10182 } |
| 10183 else { |
| 10184 var id = this.identifier(); |
| 10185 lits.add$1(new VarExpression(id, id.span)); |
| 10186 } |
| 10187 } |
| 10188 var tok = this._lang_next(); |
| 10189 if ($ne(tok.kind, 58/*TokenKind.STRING*/)) { |
| 10190 this._errorExpected('interpolated string'); |
| 10191 } |
| 10192 var text = startQuote + tok.text; |
| 10193 lits.add$1(this.makeStringLiteral(text, tok.span)); |
| 10194 var span = this._makeSpan(start); |
| 10195 return new LiteralExpression(lits, this._stringTypeRef(span), '\$\$\$', span); |
| 10196 } |
| 10197 Parser.prototype.makeStringLiteral = function(text, span) { |
| 10198 return new LiteralExpression(text, this._stringTypeRef(span), text, span); |
| 10199 } |
| 10200 Parser.prototype.stringLiteralExpr = function() { |
| 10201 var token = this._lang_next(); |
| 10202 return this.makeStringLiteral(token.text, token.span); |
| 10203 } |
| 10204 Parser.prototype.maybeStringLiteral = function() { |
| 10205 var kind = this._peek(); |
| 10206 if ($eq(kind, 58/*TokenKind.STRING*/)) { |
| 10207 return parseStringLiteral(this._lang_next().get$text()); |
| 10208 } |
| 10209 else if ($eq(kind, 59/*TokenKind.STRING_PART*/)) { |
| 10210 this._lang_next(); |
| 10211 this._errorExpected('string literal, but found interpolated string start'); |
| 10212 } |
| 10213 else if ($eq(kind, 66/*TokenKind.INCOMPLETE_STRING*/)) { |
| 10214 this._lang_next(); |
| 10215 this._errorExpected('string literal, but found incomplete string'); |
| 10216 } |
| 10217 return null; |
| 10218 } |
| 10219 Parser.prototype._parenOrLambda = function() { |
| 10220 var start = this._peekToken.start; |
| 10221 if (this._atClosureParameters()) { |
| 10222 var formals = this.formalParameterList(); |
| 10223 var body = this.functionBody(true); |
| 10224 var func = new FunctionDefinition(null, null, null, formals, null, null, nul
l, body, this._makeSpan(start)); |
| 10225 return new LambdaExpression(func, func.span); |
| 10226 } |
| 10227 else { |
| 10228 this._eatLeftParen(); |
| 10229 var saved = this._inhibitLambda; |
| 10230 this._inhibitLambda = false; |
| 10231 var expr = this.expression(); |
| 10232 this._eat(3/*TokenKind.RPAREN*/); |
| 10233 this._inhibitLambda = saved; |
| 10234 return new ParenExpression(expr, this._makeSpan(start)); |
| 10235 } |
| 10236 } |
| 10237 Parser.prototype._atClosureParameters = function() { |
| 10238 if (this._inhibitLambda) return false; |
| 10239 var after = this._peekAfterCloseParen(); |
| 10240 return after.kind == 9/*TokenKind.ARROW*/ || after.kind == 6/*TokenKind.LBRACE
*/; |
| 10241 } |
| 10242 Parser.prototype._eatLeftParen = function() { |
| 10243 this._eat(2/*TokenKind.LPAREN*/); |
| 10244 this._afterParensIndex++; |
| 10245 } |
| 10246 Parser.prototype._peekAfterCloseParen = function() { |
| 10247 if (this._afterParensIndex < this._afterParens.length) { |
| 10248 return this._afterParens.$index(this._afterParensIndex); |
| 10249 } |
| 10250 this._afterParensIndex = 0; |
| 10251 this._afterParens.clear(); |
| 10252 var tokens = [this._lang_next()]; |
| 10253 this._lookaheadAfterParens(tokens); |
| 10254 var after = this._peekToken; |
| 10255 tokens.add$1(after); |
| 10256 this.tokenizer = new DivertedTokenSource(tokens, this, this.tokenizer); |
| 10257 this._lang_next(); |
| 10258 return after; |
| 10259 } |
| 10260 Parser.prototype._lookaheadAfterParens = function(tokens) { |
| 10261 var saved = this._afterParens.length; |
| 10262 this._afterParens.add(null); |
| 10263 while (true) { |
| 10264 var token = this._lang_next(); |
| 10265 tokens.add(token); |
| 10266 var kind = token.kind; |
| 10267 if (kind == 3/*TokenKind.RPAREN*/ || kind == 1/*TokenKind.END_OF_FILE*/) { |
| 10268 this._afterParens.$setindex(saved, this._peekToken); |
| 10269 return; |
| 10270 } |
| 10271 else if (kind == 2/*TokenKind.LPAREN*/) { |
| 10272 this._lookaheadAfterParens(tokens); |
| 10273 } |
| 10274 } |
| 10275 } |
| 10276 Parser.prototype._typeAsIdentifier = function(type) { |
| 10277 return type.name; |
| 10278 } |
| 10279 Parser.prototype._specialIdentifier = function(includeOperators) { |
| 10280 var start = this._peekToken.start; |
| 10281 var name; |
| 10282 switch (this._peek()) { |
| 10283 case 15/*TokenKind.ELLIPSIS*/: |
| 10284 |
| 10285 this._eat(15/*TokenKind.ELLIPSIS*/); |
| 10286 this._lang_error('rest no longer supported', this._previousToken.get$span(
)); |
| 10287 name = this.identifier().name; |
| 10288 break; |
| 10289 |
| 10290 case 109/*TokenKind.THIS*/: |
| 10291 |
| 10292 this._eat(109/*TokenKind.THIS*/); |
| 10293 this._eat(14/*TokenKind.DOT*/); |
| 10294 name = ('this.' + this.identifier().name); |
| 10295 break; |
| 10296 |
| 10297 case 76/*TokenKind.GET*/: |
| 10298 |
| 10299 if (!includeOperators) return null; |
| 10300 this._eat(76/*TokenKind.GET*/); |
| 10301 if (this._peekIdentifier()) { |
| 10302 name = ('get:' + this.identifier().name); |
| 10303 } |
| 10304 else { |
| 10305 name = 'get'; |
| 10306 } |
| 10307 break; |
| 10308 |
| 10309 case 84/*TokenKind.SET*/: |
| 10310 |
| 10311 if (!includeOperators) return null; |
| 10312 this._eat(84/*TokenKind.SET*/); |
| 10313 if (this._peekIdentifier()) { |
| 10314 name = ('set:' + this.identifier().name); |
| 10315 } |
| 10316 else { |
| 10317 name = 'set'; |
| 10318 } |
| 10319 break; |
| 10320 |
| 10321 case 83/*TokenKind.OPERATOR*/: |
| 10322 |
| 10323 if (!includeOperators) return null; |
| 10324 this._eat(83/*TokenKind.OPERATOR*/); |
| 10325 var kind = this._peek(); |
| 10326 if ($eq(kind, 82/*TokenKind.NEGATE*/)) { |
| 10327 name = ':negate'; |
| 10328 this._lang_next(); |
| 10329 } |
| 10330 else { |
| 10331 name = TokenKind.binaryMethodName(kind); |
| 10332 if (name == null) { |
| 10333 name = 'operator'; |
| 10334 } |
| 10335 else { |
| 10336 this._lang_next(); |
| 10337 } |
| 10338 } |
| 10339 break; |
| 10340 |
| 10341 default: |
| 10342 |
| 10343 return null; |
| 10344 |
| 10345 } |
| 10346 return new Identifier(name, this._makeSpan(start)); |
| 10347 } |
| 10348 Parser.prototype.declaredIdentifier = function(includeOperators) { |
| 10349 var start = this._peekToken.start; |
| 10350 var myType = null; |
| 10351 var name = this._specialIdentifier(includeOperators); |
| 10352 if (name == null) { |
| 10353 myType = this.type(0); |
| 10354 name = this._specialIdentifier(includeOperators); |
| 10355 if (name == null) { |
| 10356 if (this._peekIdentifier()) { |
| 10357 name = this.identifier(); |
| 10358 } |
| 10359 else if ((myType instanceof NameTypeReference) && myType.get$names() == nu
ll) { |
| 10360 name = this._typeAsIdentifier(myType); |
| 10361 myType = null; |
| 10362 } |
| 10363 else { |
| 10364 } |
| 10365 } |
| 10366 } |
| 10367 return new DeclaredIdentifier(myType, name, this._makeSpan(start)); |
| 10368 } |
| 10369 Parser._hexDigit = function(c) { |
| 10370 if (c >= 48 && c <= 57) { |
| 10371 return c - 48; |
| 10372 } |
| 10373 else if (c >= 97 && c <= 102) { |
| 10374 return c - 87; |
| 10375 } |
| 10376 else if (c >= 65 && c <= 70) { |
| 10377 return c - 55; |
| 10378 } |
| 10379 else { |
| 10380 return -1; |
| 10381 } |
| 10382 } |
| 10383 Parser.parseHex = function(hex) { |
| 10384 var result = 0; |
| 10385 for (var i = 0; |
| 10386 i < hex.length; i++) { |
| 10387 var digit = Parser._hexDigit(hex.charCodeAt(i)); |
| 10388 result = (result * 16) + digit; |
| 10389 } |
| 10390 return result; |
| 10391 } |
| 10392 Parser.prototype.finishNewExpression = function(start, isConst) { |
| 10393 var type = this.type(0); |
| 10394 var name = null; |
| 10395 if (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 10396 name = this.identifier(); |
| 10397 } |
| 10398 var args = this.arguments(); |
| 10399 return new NewExpression(isConst, type, name, args, this._makeSpan(start)); |
| 10400 } |
| 10401 Parser.prototype.finishListLiteral = function(start, isConst, type) { |
| 10402 if (this._maybeEat(56/*TokenKind.INDEX*/)) { |
| 10403 return new ListExpression(isConst, type, [], this._makeSpan(start)); |
| 10404 } |
| 10405 var values = []; |
| 10406 this._eat(4/*TokenKind.LBRACK*/); |
| 10407 while (!this._maybeEat(5/*TokenKind.RBRACK*/)) { |
| 10408 values.add$1(this.expression()); |
| 10409 if (this._recover && !this._recoverTo(5/*TokenKind.RBRACK*/, 11/*TokenKind.C
OMMA*/)) break; |
| 10410 if (!this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 10411 this._eat(5/*TokenKind.RBRACK*/); |
| 10412 break; |
| 10413 } |
| 10414 } |
| 10415 return new ListExpression(isConst, type, values, this._makeSpan(start)); |
| 10416 } |
| 10417 Parser.prototype.finishMapLiteral = function(start, isConst, type) { |
| 10418 var items = []; |
| 10419 this._eat(6/*TokenKind.LBRACE*/); |
| 10420 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 10421 items.add$1(this.expression()); |
| 10422 this._eat(8/*TokenKind.COLON*/); |
| 10423 items.add$1(this.expression()); |
| 10424 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 11/*TokenKind.C
OMMA*/)) break; |
| 10425 if (!this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 10426 this._eat(7/*TokenKind.RBRACE*/); |
| 10427 break; |
| 10428 } |
| 10429 } |
| 10430 return new MapExpression(isConst, type, items, this._makeSpan(start)); |
| 10431 } |
| 10432 Parser.prototype.finishTypedLiteral = function(start, isConst) { |
| 10433 var span = this._makeSpan(start); |
| 10434 var typeToBeNamedLater = new NameTypeReference(false, null, null, span); |
| 10435 var genericType = this.addTypeArguments(typeToBeNamedLater, 0); |
| 10436 if (this._peekKind(4/*TokenKind.LBRACK*/) || this._peekKind(56/*TokenKind.INDE
X*/)) { |
| 10437 genericType.set$baseType(new TypeReference(span, $globals.world.listType)); |
| 10438 return this.finishListLiteral(start, isConst, genericType); |
| 10439 } |
| 10440 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 10441 genericType.set$baseType(new TypeReference(span, $globals.world.mapType)); |
| 10442 var typeArgs = genericType.get$typeArguments(); |
| 10443 if ($eq(typeArgs.length, 1)) { |
| 10444 genericType.set$typeArguments([new TypeReference(span, $globals.world.stri
ngType), typeArgs.$index(0)]); |
| 10445 } |
| 10446 else if ($eq(typeArgs.length, 2)) { |
| 10447 var keyType = typeArgs.$index(0); |
| 10448 if (!(keyType instanceof NameTypeReference) || $ne(keyType.name.name, "Str
ing")) { |
| 10449 $globals.world.error('the key type of a map literal is implicitly "Strin
g"', keyType.span); |
| 10450 } |
| 10451 else { |
| 10452 $globals.world.warning('a map literal takes one type argument specifying
the value type', keyType.span); |
| 10453 } |
| 10454 } |
| 10455 return this.finishMapLiteral(start, isConst, genericType); |
| 10456 } |
| 10457 else { |
| 10458 this._errorExpected('array or map literal'); |
| 10459 } |
| 10460 } |
| 10461 Parser.prototype._readModifiers = function() { |
| 10462 var modifiers = null; |
| 10463 while (true) { |
| 10464 switch (this._peek()) { |
| 10465 case 86/*TokenKind.STATIC*/: |
| 10466 case 98/*TokenKind.FINAL*/: |
| 10467 case 92/*TokenKind.CONST*/: |
| 10468 case 71/*TokenKind.ABSTRACT*/: |
| 10469 case 75/*TokenKind.FACTORY*/: |
| 10470 |
| 10471 if (modifiers == null) modifiers = []; |
| 10472 modifiers.add$1(this._lang_next()); |
| 10473 break; |
| 10474 |
| 10475 default: |
| 10476 |
| 10477 return modifiers; |
| 10478 |
| 10479 } |
| 10480 } |
| 10481 return null; |
| 10482 } |
| 10483 Parser.prototype.typeParameter = function() { |
| 10484 var start = this._peekToken.start; |
| 10485 var name = this.identifier(); |
| 10486 var myType = null; |
| 10487 if (this._maybeEat(74/*TokenKind.EXTENDS*/)) { |
| 10488 myType = this.type(1); |
| 10489 } |
| 10490 var tp = new TypeParameter(name, myType, this._makeSpan(start)); |
| 10491 return new ParameterType(name.name, tp); |
| 10492 } |
| 10493 Parser.prototype.get$typeParameter = function() { |
| 10494 return Parser.prototype.typeParameter.bind(this); |
| 10495 } |
| 10496 Parser.prototype.typeParameters = function() { |
| 10497 this._eat(52/*TokenKind.LT*/); |
| 10498 var closed = false; |
| 10499 var ret = []; |
| 10500 do { |
| 10501 var tp = this.typeParameter(); |
| 10502 ret.add$1(tp); |
| 10503 if ((tp.get$typeParameter().get$extendsType() instanceof GenericTypeReferenc
e) && $eq(tp.get$typeParameter().get$extendsType().depth, 0)) { |
| 10504 closed = true; |
| 10505 break; |
| 10506 } |
| 10507 } |
| 10508 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 10509 if (!closed) { |
| 10510 this._eat(53/*TokenKind.GT*/); |
| 10511 } |
| 10512 return ret; |
| 10513 } |
| 10514 Parser.prototype.get$typeParameters = function() { |
| 10515 return Parser.prototype.typeParameters.bind(this); |
| 10516 } |
| 10517 Parser.prototype._eatClosingAngle = function(depth) { |
| 10518 if (this._maybeEat(53/*TokenKind.GT*/)) { |
| 10519 return depth; |
| 10520 } |
| 10521 else if (depth > 0 && this._maybeEat(40/*TokenKind.SAR*/)) { |
| 10522 return depth - 1; |
| 10523 } |
| 10524 else if (depth > 1 && this._maybeEat(41/*TokenKind.SHR*/)) { |
| 10525 return depth - 2; |
| 10526 } |
| 10527 else { |
| 10528 this._errorExpected('>'); |
| 10529 return depth; |
| 10530 } |
| 10531 } |
| 10532 Parser.prototype.addTypeArguments = function(baseType, depth) { |
| 10533 this._eat(52/*TokenKind.LT*/); |
| 10534 return this._finishTypeArguments(baseType, depth, []); |
| 10535 } |
| 10536 Parser.prototype._finishTypeArguments = function(baseType, depth, types) { |
| 10537 var delta = -1; |
| 10538 do { |
| 10539 var myType = this.type(depth + 1); |
| 10540 types.add$1(myType); |
| 10541 if ((myType instanceof GenericTypeReference) && myType.depth <= depth) { |
| 10542 delta = depth - myType.depth; |
| 10543 break; |
| 10544 } |
| 10545 } |
| 10546 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 10547 if (delta >= 0) { |
| 10548 depth = depth - delta; |
| 10549 } |
| 10550 else { |
| 10551 depth = this._eatClosingAngle(depth); |
| 10552 } |
| 10553 var span = this._makeSpan(baseType.span.start); |
| 10554 return new GenericTypeReference(baseType, types, depth, span); |
| 10555 } |
| 10556 Parser.prototype.typeList = function() { |
| 10557 var types = []; |
| 10558 do { |
| 10559 types.add$1(this.type(0)); |
| 10560 } |
| 10561 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 10562 return types; |
| 10563 } |
| 10564 Parser.prototype.nameTypeReference = function() { |
| 10565 var start = this._peekToken.start; |
| 10566 var name; |
| 10567 var names = null; |
| 10568 var typeArgs = null; |
| 10569 var isFinal = false; |
| 10570 switch (this._peek()) { |
| 10571 case 114/*TokenKind.VOID*/: |
| 10572 |
| 10573 return new TypeReference(this._lang_next().get$span(), $globals.world.void
Type); |
| 10574 |
| 10575 case 113/*TokenKind.VAR*/: |
| 10576 |
| 10577 return new TypeReference(this._lang_next().get$span(), $globals.world.varT
ype); |
| 10578 |
| 10579 case 98/*TokenKind.FINAL*/: |
| 10580 |
| 10581 this._eat(98/*TokenKind.FINAL*/); |
| 10582 isFinal = true; |
| 10583 name = this.identifier(); |
| 10584 break; |
| 10585 |
| 10586 default: |
| 10587 |
| 10588 name = this.identifier(); |
| 10589 break; |
| 10590 |
| 10591 } |
| 10592 while (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 10593 if (names == null) names = []; |
| 10594 names.add$1(this.identifier()); |
| 10595 } |
| 10596 return new NameTypeReference(isFinal, name, names, this._makeSpan(start)); |
| 10597 } |
| 10598 Parser.prototype.type = function(depth) { |
| 10599 var typeRef = this.nameTypeReference(); |
| 10600 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 10601 return this.addTypeArguments(typeRef, depth); |
| 10602 } |
| 10603 else { |
| 10604 return typeRef; |
| 10605 } |
| 10606 } |
| 10607 Parser.prototype.formalParameter = function(inOptionalBlock) { |
| 10608 var start = this._peekToken.start; |
| 10609 var isThis = false; |
| 10610 var isRest = false; |
| 10611 var di = this.declaredIdentifier(false); |
| 10612 var type = di.type; |
| 10613 var name = di.name; |
| 10614 var value = null; |
| 10615 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 10616 if (!inOptionalBlock) { |
| 10617 this._lang_error('default values only allowed inside [optional] section'); |
| 10618 } |
| 10619 value = this.expression(); |
| 10620 } |
| 10621 else if (this._peekKind(2/*TokenKind.LPAREN*/)) { |
| 10622 var formals = this.formalParameterList(); |
| 10623 var func = new FunctionDefinition(null, type, name, formals, null, null, nul
l, null, this._makeSpan(start)); |
| 10624 type = new FunctionTypeReference(false, func, func.span); |
| 10625 } |
| 10626 if (inOptionalBlock && value == null) { |
| 10627 value = new NullExpression(this._makeSpan(start)); |
| 10628 } |
| 10629 return new FormalNode(isThis, isRest, type, name, value, this._makeSpan(start)
); |
| 10630 } |
| 10631 Parser.prototype.formalParameterList = function() { |
| 10632 this._eatLeftParen(); |
| 10633 var formals = []; |
| 10634 var inOptionalBlock = false; |
| 10635 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 10636 if (this._maybeEat(4/*TokenKind.LBRACK*/)) { |
| 10637 inOptionalBlock = true; |
| 10638 } |
| 10639 formals.add$1(this.formalParameter(inOptionalBlock)); |
| 10640 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 10641 if (this._maybeEat(4/*TokenKind.LBRACK*/)) { |
| 10642 if (inOptionalBlock) { |
| 10643 this._lang_error('already inside an optional block', this._previousTok
en.get$span()); |
| 10644 } |
| 10645 inOptionalBlock = true; |
| 10646 } |
| 10647 formals.add$1(this.formalParameter(inOptionalBlock)); |
| 10648 } |
| 10649 if (inOptionalBlock) { |
| 10650 this._eat(5/*TokenKind.RBRACK*/); |
| 10651 } |
| 10652 this._eat(3/*TokenKind.RPAREN*/); |
| 10653 } |
| 10654 return formals; |
| 10655 } |
| 10656 Parser.prototype.identifier = function() { |
| 10657 var tok = this._lang_next(); |
| 10658 if (!this._isIdentifier(tok.kind)) { |
| 10659 this._lang_error(('expected identifier, but found ' + tok), tok.span); |
| 10660 } |
| 10661 return new Identifier(tok.text, this._makeSpan(tok.start)); |
| 10662 } |
| 10663 Parser.prototype._makeFunction = function(expr, formals, body) { |
| 10664 var name, type; |
| 10665 if ((expr instanceof VarExpression)) { |
| 10666 name = expr.name; |
| 10667 type = null; |
| 10668 } |
| 10669 else if ((expr instanceof DeclaredIdentifier)) { |
| 10670 name = expr.name; |
| 10671 type = expr.type; |
| 10672 } |
| 10673 else { |
| 10674 this._lang_error('bad function body', expr.span); |
| 10675 } |
| 10676 var span = new SourceSpan(expr.span.get$file(), expr.span.start, body.span.get
$end()); |
| 10677 var func = new FunctionDefinition(null, type, name, formals, null, null, null,
body, span); |
| 10678 return new LambdaExpression(func, func.span); |
| 10679 } |
| 10680 Parser.prototype._makeDeclaredIdentifier = function(e) { |
| 10681 if ((e instanceof VarExpression)) { |
| 10682 return new DeclaredIdentifier(null, e.name, e.span); |
| 10683 } |
| 10684 else if ((e instanceof DeclaredIdentifier)) { |
| 10685 return e; |
| 10686 } |
| 10687 else { |
| 10688 this._lang_error('expected declared identifier'); |
| 10689 return new DeclaredIdentifier(null, null, e.span); |
| 10690 } |
| 10691 } |
| 10692 Parser.prototype._makeLabel = function(expr) { |
| 10693 if ((expr instanceof VarExpression)) { |
| 10694 return expr.name; |
| 10695 } |
| 10696 else { |
| 10697 this._errorExpected('label'); |
| 10698 return null; |
| 10699 } |
| 10700 } |
| 10701 Parser.prototype.block$0 = Parser.prototype.block; |
| 10702 Parser.prototype.compilationUnit$0 = Parser.prototype.compilationUnit; |
| 10703 // ********** Code for IncompleteSourceException ************** |
| 10704 function IncompleteSourceException(token) { |
| 10705 this.token = token; |
| 10706 // Initializers done |
| 10707 } |
| 10708 IncompleteSourceException.prototype.toString = function() { |
| 10709 if (this.token.get$span() == null) return ('Unexpected ' + this.token); |
| 10710 return this.token.get$span().toMessageString(('Unexpected ' + this.token)); |
| 10711 } |
| 10712 IncompleteSourceException.prototype.toString$0 = IncompleteSourceException.proto
type.toString; |
| 10713 // ********** Code for DivertedTokenSource ************** |
| 10714 function DivertedTokenSource(tokens, parser, previousTokenizer) { |
| 10715 this._lang_pos = 0 |
| 10716 this.tokens = tokens; |
| 10717 this.parser = parser; |
| 10718 this.previousTokenizer = previousTokenizer; |
| 10719 // Initializers done |
| 10720 } |
| 10721 DivertedTokenSource.prototype.next = function() { |
| 10722 var token = this.tokens.$index(this._lang_pos); |
| 10723 ++this._lang_pos; |
| 10724 if (this._lang_pos == this.tokens.length) { |
| 10725 this.parser.tokenizer = this.previousTokenizer; |
| 10726 } |
| 10727 return token; |
| 10728 } |
| 10729 DivertedTokenSource.prototype.next$0 = DivertedTokenSource.prototype.next; |
| 10730 // ********** Code for lang_Node ************** |
| 10731 function lang_Node(span) { |
| 10732 this.span = span; |
| 10733 // Initializers done |
| 10734 } |
| 10735 lang_Node.prototype.visit$1 = lang_Node.prototype.visit; |
| 10736 // ********** Code for Statement ************** |
| 10737 $inherits(Statement, lang_Node); |
| 10738 function Statement(span) { |
| 10739 // Initializers done |
| 10740 lang_Node.call(this, span); |
| 10741 } |
| 10742 // ********** Code for Definition ************** |
| 10743 $inherits(Definition, Statement); |
| 10744 function Definition(span) { |
| 10745 // Initializers done |
| 10746 Statement.call(this, span); |
| 10747 } |
| 10748 Definition.prototype.get$typeParameters = function() { |
| 10749 return null; |
| 10750 } |
| 10751 Definition.prototype.get$nativeType = function() { |
| 10752 return null; |
| 10753 } |
| 10754 // ********** Code for Expression ************** |
| 10755 $inherits(Expression, lang_Node); |
| 10756 function Expression(span) { |
| 10757 // Initializers done |
| 10758 lang_Node.call(this, span); |
| 10759 } |
| 10760 // ********** Code for TypeReference ************** |
| 10761 $inherits(TypeReference, lang_Node); |
| 10762 function TypeReference(span, type) { |
| 10763 this.type = type; |
| 10764 // Initializers done |
| 10765 lang_Node.call(this, span); |
| 10766 } |
| 10767 TypeReference.prototype.visit = function(visitor) { |
| 10768 return visitor.visitTypeReference(this); |
| 10769 } |
| 10770 TypeReference.prototype.get$isFinal = function() { |
| 10771 return false; |
| 10772 } |
| 10773 TypeReference.prototype.visit$1 = TypeReference.prototype.visit; |
| 10774 // ********** Code for DirectiveDefinition ************** |
| 10775 $inherits(DirectiveDefinition, Definition); |
| 10776 function DirectiveDefinition(name, arguments, span) { |
| 10777 this.name = name; |
| 10778 this.arguments = arguments; |
| 10779 // Initializers done |
| 10780 Definition.call(this, span); |
| 10781 } |
| 10782 DirectiveDefinition.prototype.get$arguments = function() { return this.arguments
; }; |
| 10783 DirectiveDefinition.prototype.set$arguments = function(value) { return this.argu
ments = value; }; |
| 10784 DirectiveDefinition.prototype.visit = function(visitor) { |
| 10785 return visitor.visitDirectiveDefinition(this); |
| 10786 } |
| 10787 DirectiveDefinition.prototype.visit$1 = DirectiveDefinition.prototype.visit; |
| 10788 // ********** Code for TypeDefinition ************** |
| 10789 $inherits(TypeDefinition, Definition); |
| 10790 function TypeDefinition(isClass, name, typeParameters, extendsTypes, implementsT
ypes, nativeType, factoryType, body, span) { |
| 10791 this.isClass = isClass; |
| 10792 this.name = name; |
| 10793 this.typeParameters = typeParameters; |
| 10794 this.extendsTypes = extendsTypes; |
| 10795 this.implementsTypes = implementsTypes; |
| 10796 this.nativeType = nativeType; |
| 10797 this.factoryType = factoryType; |
| 10798 this.body = body; |
| 10799 // Initializers done |
| 10800 Definition.call(this, span); |
| 10801 } |
| 10802 TypeDefinition.prototype.get$isClass = function() { return this.isClass; }; |
| 10803 TypeDefinition.prototype.set$isClass = function(value) { return this.isClass = v
alue; }; |
| 10804 TypeDefinition.prototype.get$typeParameters = function() { return this.typeParam
eters; }; |
| 10805 TypeDefinition.prototype.set$typeParameters = function(value) { return this.type
Parameters = value; }; |
| 10806 TypeDefinition.prototype.get$nativeType = function() { return this.nativeType; }
; |
| 10807 TypeDefinition.prototype.set$nativeType = function(value) { return this.nativeTy
pe = value; }; |
| 10808 TypeDefinition.prototype.visit = function(visitor) { |
| 10809 return visitor.visitTypeDefinition(this); |
| 10810 } |
| 10811 TypeDefinition.prototype.visit$1 = TypeDefinition.prototype.visit; |
| 10812 // ********** Code for FunctionTypeDefinition ************** |
| 10813 $inherits(FunctionTypeDefinition, Definition); |
| 10814 function FunctionTypeDefinition(func, typeParameters, span) { |
| 10815 this.func = func; |
| 10816 this.typeParameters = typeParameters; |
| 10817 // Initializers done |
| 10818 Definition.call(this, span); |
| 10819 } |
| 10820 FunctionTypeDefinition.prototype.get$func = function() { return this.func; }; |
| 10821 FunctionTypeDefinition.prototype.set$func = function(value) { return this.func =
value; }; |
| 10822 FunctionTypeDefinition.prototype.get$typeParameters = function() { return this.t
ypeParameters; }; |
| 10823 FunctionTypeDefinition.prototype.set$typeParameters = function(value) { return t
his.typeParameters = value; }; |
| 10824 FunctionTypeDefinition.prototype.visit = function(visitor) { |
| 10825 return visitor.visitFunctionTypeDefinition(this); |
| 10826 } |
| 10827 FunctionTypeDefinition.prototype.visit$1 = FunctionTypeDefinition.prototype.visi
t; |
| 10828 // ********** Code for VariableDefinition ************** |
| 10829 $inherits(VariableDefinition, Definition); |
| 10830 function VariableDefinition(modifiers, type, names, values, span) { |
| 10831 this.modifiers = modifiers; |
| 10832 this.type = type; |
| 10833 this.names = names; |
| 10834 this.values = values; |
| 10835 // Initializers done |
| 10836 Definition.call(this, span); |
| 10837 } |
| 10838 VariableDefinition.prototype.get$names = function() { return this.names; }; |
| 10839 VariableDefinition.prototype.set$names = function(value) { return this.names = v
alue; }; |
| 10840 VariableDefinition.prototype.visit = function(visitor) { |
| 10841 return visitor.visitVariableDefinition(this); |
| 10842 } |
| 10843 VariableDefinition.prototype.visit$1 = VariableDefinition.prototype.visit; |
| 10844 // ********** Code for FunctionDefinition ************** |
| 10845 $inherits(FunctionDefinition, Definition); |
| 10846 function FunctionDefinition(modifiers, returnType, name, formals, typeParameters
, initializers, nativeBody, body, span) { |
| 10847 this.modifiers = modifiers; |
| 10848 this.returnType = returnType; |
| 10849 this.name = name; |
| 10850 this.formals = formals; |
| 10851 this.typeParameters = typeParameters; |
| 10852 this.initializers = initializers; |
| 10853 this.nativeBody = nativeBody; |
| 10854 this.body = body; |
| 10855 // Initializers done |
| 10856 Definition.call(this, span); |
| 10857 } |
| 10858 FunctionDefinition.prototype.get$returnType = function() { return this.returnTyp
e; }; |
| 10859 FunctionDefinition.prototype.set$returnType = function(value) { return this.retu
rnType = value; }; |
| 10860 FunctionDefinition.prototype.get$typeParameters = function() { return this.typeP
arameters; }; |
| 10861 FunctionDefinition.prototype.set$typeParameters = function(value) { return this.
typeParameters = value; }; |
| 10862 FunctionDefinition.prototype.get$initializers = function() { return this.initial
izers; }; |
| 10863 FunctionDefinition.prototype.set$initializers = function(value) { return this.in
itializers = value; }; |
| 10864 FunctionDefinition.prototype.get$nativeBody = function() { return this.nativeBod
y; }; |
| 10865 FunctionDefinition.prototype.set$nativeBody = function(value) { return this.nati
veBody = value; }; |
| 10866 FunctionDefinition.prototype.visit = function(visitor) { |
| 10867 return visitor.visitFunctionDefinition(this); |
| 10868 } |
| 10869 FunctionDefinition.prototype.visit$1 = FunctionDefinition.prototype.visit; |
| 10870 // ********** Code for ReturnStatement ************** |
| 10871 $inherits(ReturnStatement, Statement); |
| 10872 function ReturnStatement(value, span) { |
| 10873 this.value = value; |
| 10874 // Initializers done |
| 10875 Statement.call(this, span); |
| 10876 } |
| 10877 ReturnStatement.prototype.visit = function(visitor) { |
| 10878 return visitor.visitReturnStatement(this); |
| 10879 } |
| 10880 ReturnStatement.prototype.visit$1 = ReturnStatement.prototype.visit; |
| 10881 // ********** Code for ThrowStatement ************** |
| 10882 $inherits(ThrowStatement, Statement); |
| 10883 function ThrowStatement(value, span) { |
| 10884 this.value = value; |
| 10885 // Initializers done |
| 10886 Statement.call(this, span); |
| 10887 } |
| 10888 ThrowStatement.prototype.visit = function(visitor) { |
| 10889 return visitor.visitThrowStatement(this); |
| 10890 } |
| 10891 ThrowStatement.prototype.visit$1 = ThrowStatement.prototype.visit; |
| 10892 // ********** Code for AssertStatement ************** |
| 10893 $inherits(AssertStatement, Statement); |
| 10894 function AssertStatement(test, span) { |
| 10895 this.test = test; |
| 10896 // Initializers done |
| 10897 Statement.call(this, span); |
| 10898 } |
| 10899 AssertStatement.prototype.visit = function(visitor) { |
| 10900 return visitor.visitAssertStatement(this); |
| 10901 } |
| 10902 AssertStatement.prototype.visit$1 = AssertStatement.prototype.visit; |
| 10903 // ********** Code for BreakStatement ************** |
| 10904 $inherits(BreakStatement, Statement); |
| 10905 function BreakStatement(label, span) { |
| 10906 this.label = label; |
| 10907 // Initializers done |
| 10908 Statement.call(this, span); |
| 10909 } |
| 10910 BreakStatement.prototype.visit = function(visitor) { |
| 10911 return visitor.visitBreakStatement(this); |
| 10912 } |
| 10913 BreakStatement.prototype.visit$1 = BreakStatement.prototype.visit; |
| 10914 // ********** Code for ContinueStatement ************** |
| 10915 $inherits(ContinueStatement, Statement); |
| 10916 function ContinueStatement(label, span) { |
| 10917 this.label = label; |
| 10918 // Initializers done |
| 10919 Statement.call(this, span); |
| 10920 } |
| 10921 ContinueStatement.prototype.visit = function(visitor) { |
| 10922 return visitor.visitContinueStatement(this); |
| 10923 } |
| 10924 ContinueStatement.prototype.visit$1 = ContinueStatement.prototype.visit; |
| 10925 // ********** Code for IfStatement ************** |
| 10926 $inherits(IfStatement, Statement); |
| 10927 function IfStatement(test, trueBranch, falseBranch, span) { |
| 10928 this.test = test; |
| 10929 this.trueBranch = trueBranch; |
| 10930 this.falseBranch = falseBranch; |
| 10931 // Initializers done |
| 10932 Statement.call(this, span); |
| 10933 } |
| 10934 IfStatement.prototype.visit = function(visitor) { |
| 10935 return visitor.visitIfStatement(this); |
| 10936 } |
| 10937 IfStatement.prototype.visit$1 = IfStatement.prototype.visit; |
| 10938 // ********** Code for WhileStatement ************** |
| 10939 $inherits(WhileStatement, Statement); |
| 10940 function WhileStatement(test, body, span) { |
| 10941 this.test = test; |
| 10942 this.body = body; |
| 10943 // Initializers done |
| 10944 Statement.call(this, span); |
| 10945 } |
| 10946 WhileStatement.prototype.visit = function(visitor) { |
| 10947 return visitor.visitWhileStatement(this); |
| 10948 } |
| 10949 WhileStatement.prototype.visit$1 = WhileStatement.prototype.visit; |
| 10950 // ********** Code for DoStatement ************** |
| 10951 $inherits(DoStatement, Statement); |
| 10952 function DoStatement(body, test, span) { |
| 10953 this.body = body; |
| 10954 this.test = test; |
| 10955 // Initializers done |
| 10956 Statement.call(this, span); |
| 10957 } |
| 10958 DoStatement.prototype.visit = function(visitor) { |
| 10959 return visitor.visitDoStatement(this); |
| 10960 } |
| 10961 DoStatement.prototype.visit$1 = DoStatement.prototype.visit; |
| 10962 // ********** Code for ForStatement ************** |
| 10963 $inherits(ForStatement, Statement); |
| 10964 function ForStatement(init, test, step, body, span) { |
| 10965 this.init = init; |
| 10966 this.test = test; |
| 10967 this.step = step; |
| 10968 this.body = body; |
| 10969 // Initializers done |
| 10970 Statement.call(this, span); |
| 10971 } |
| 10972 ForStatement.prototype.visit = function(visitor) { |
| 10973 return visitor.visitForStatement(this); |
| 10974 } |
| 10975 ForStatement.prototype.visit$1 = ForStatement.prototype.visit; |
| 10976 // ********** Code for ForInStatement ************** |
| 10977 $inherits(ForInStatement, Statement); |
| 10978 function ForInStatement(item, list, body, span) { |
| 10979 this.item = item; |
| 10980 this.list = list; |
| 10981 this.body = body; |
| 10982 // Initializers done |
| 10983 Statement.call(this, span); |
| 10984 } |
| 10985 ForInStatement.prototype.visit = function(visitor) { |
| 10986 return visitor.visitForInStatement(this); |
| 10987 } |
| 10988 ForInStatement.prototype.visit$1 = ForInStatement.prototype.visit; |
| 10989 // ********** Code for TryStatement ************** |
| 10990 $inherits(TryStatement, Statement); |
| 10991 function TryStatement(body, catches, finallyBlock, span) { |
| 10992 this.body = body; |
| 10993 this.catches = catches; |
| 10994 this.finallyBlock = finallyBlock; |
| 10995 // Initializers done |
| 10996 Statement.call(this, span); |
| 10997 } |
| 10998 TryStatement.prototype.visit = function(visitor) { |
| 10999 return visitor.visitTryStatement(this); |
| 11000 } |
| 11001 TryStatement.prototype.visit$1 = TryStatement.prototype.visit; |
| 11002 // ********** Code for SwitchStatement ************** |
| 11003 $inherits(SwitchStatement, Statement); |
| 11004 function SwitchStatement(test, cases, span) { |
| 11005 this.test = test; |
| 11006 this.cases = cases; |
| 11007 // Initializers done |
| 11008 Statement.call(this, span); |
| 11009 } |
| 11010 SwitchStatement.prototype.get$cases = function() { return this.cases; }; |
| 11011 SwitchStatement.prototype.set$cases = function(value) { return this.cases = valu
e; }; |
| 11012 SwitchStatement.prototype.visit = function(visitor) { |
| 11013 return visitor.visitSwitchStatement(this); |
| 11014 } |
| 11015 SwitchStatement.prototype.visit$1 = SwitchStatement.prototype.visit; |
| 11016 // ********** Code for BlockStatement ************** |
| 11017 $inherits(BlockStatement, Statement); |
| 11018 function BlockStatement(body, span) { |
| 11019 this.body = body; |
| 11020 // Initializers done |
| 11021 Statement.call(this, span); |
| 11022 } |
| 11023 BlockStatement.prototype.visit = function(visitor) { |
| 11024 return visitor.visitBlockStatement(this); |
| 11025 } |
| 11026 BlockStatement.prototype.visit$1 = BlockStatement.prototype.visit; |
| 11027 // ********** Code for LabeledStatement ************** |
| 11028 $inherits(LabeledStatement, Statement); |
| 11029 function LabeledStatement(name, body, span) { |
| 11030 this.name = name; |
| 11031 this.body = body; |
| 11032 // Initializers done |
| 11033 Statement.call(this, span); |
| 11034 } |
| 11035 LabeledStatement.prototype.visit = function(visitor) { |
| 11036 return visitor.visitLabeledStatement(this); |
| 11037 } |
| 11038 LabeledStatement.prototype.visit$1 = LabeledStatement.prototype.visit; |
| 11039 // ********** Code for ExpressionStatement ************** |
| 11040 $inherits(ExpressionStatement, Statement); |
| 11041 function ExpressionStatement(body, span) { |
| 11042 this.body = body; |
| 11043 // Initializers done |
| 11044 Statement.call(this, span); |
| 11045 } |
| 11046 ExpressionStatement.prototype.visit = function(visitor) { |
| 11047 return visitor.visitExpressionStatement(this); |
| 11048 } |
| 11049 ExpressionStatement.prototype.visit$1 = ExpressionStatement.prototype.visit; |
| 11050 // ********** Code for EmptyStatement ************** |
| 11051 $inherits(EmptyStatement, Statement); |
| 11052 function EmptyStatement(span) { |
| 11053 // Initializers done |
| 11054 Statement.call(this, span); |
| 11055 } |
| 11056 EmptyStatement.prototype.visit = function(visitor) { |
| 11057 return visitor.visitEmptyStatement(this); |
| 11058 } |
| 11059 EmptyStatement.prototype.visit$1 = EmptyStatement.prototype.visit; |
| 11060 // ********** Code for DietStatement ************** |
| 11061 $inherits(DietStatement, Statement); |
| 11062 function DietStatement(span) { |
| 11063 // Initializers done |
| 11064 Statement.call(this, span); |
| 11065 } |
| 11066 DietStatement.prototype.visit = function(visitor) { |
| 11067 return visitor.visitDietStatement(this); |
| 11068 } |
| 11069 DietStatement.prototype.visit$1 = DietStatement.prototype.visit; |
| 11070 // ********** Code for LambdaExpression ************** |
| 11071 $inherits(LambdaExpression, Expression); |
| 11072 function LambdaExpression(func, span) { |
| 11073 this.func = func; |
| 11074 // Initializers done |
| 11075 Expression.call(this, span); |
| 11076 } |
| 11077 LambdaExpression.prototype.get$func = function() { return this.func; }; |
| 11078 LambdaExpression.prototype.set$func = function(value) { return this.func = value
; }; |
| 11079 LambdaExpression.prototype.visit = function(visitor) { |
| 11080 return visitor.visitLambdaExpression(this); |
| 11081 } |
| 11082 LambdaExpression.prototype.visit$1 = LambdaExpression.prototype.visit; |
| 11083 // ********** Code for CallExpression ************** |
| 11084 $inherits(CallExpression, Expression); |
| 11085 function CallExpression(target, arguments, span) { |
| 11086 this.target = target; |
| 11087 this.arguments = arguments; |
| 11088 // Initializers done |
| 11089 Expression.call(this, span); |
| 11090 } |
| 11091 CallExpression.prototype.get$arguments = function() { return this.arguments; }; |
| 11092 CallExpression.prototype.set$arguments = function(value) { return this.arguments
= value; }; |
| 11093 CallExpression.prototype.visit = function(visitor) { |
| 11094 return visitor.visitCallExpression(this); |
| 11095 } |
| 11096 CallExpression.prototype.visit$1 = CallExpression.prototype.visit; |
| 11097 // ********** Code for IndexExpression ************** |
| 11098 $inherits(IndexExpression, Expression); |
| 11099 function IndexExpression(target, index, span) { |
| 11100 this.target = target; |
| 11101 this.index = index; |
| 11102 // Initializers done |
| 11103 Expression.call(this, span); |
| 11104 } |
| 11105 IndexExpression.prototype.visit = function(visitor) { |
| 11106 return visitor.visitIndexExpression(this); |
| 11107 } |
| 11108 IndexExpression.prototype.visit$1 = IndexExpression.prototype.visit; |
| 11109 // ********** Code for BinaryExpression ************** |
| 11110 $inherits(BinaryExpression, Expression); |
| 11111 function BinaryExpression(op, x, y, span) { |
| 11112 this.op = op; |
| 11113 this.x = x; |
| 11114 this.y = y; |
| 11115 // Initializers done |
| 11116 Expression.call(this, span); |
| 11117 } |
| 11118 BinaryExpression.prototype.get$op = function() { return this.op; }; |
| 11119 BinaryExpression.prototype.set$op = function(value) { return this.op = value; }; |
| 11120 BinaryExpression.prototype.visit = function(visitor) { |
| 11121 return visitor.visitBinaryExpression$1(this); |
| 11122 } |
| 11123 BinaryExpression.prototype.visit$1 = BinaryExpression.prototype.visit; |
| 11124 // ********** Code for UnaryExpression ************** |
| 11125 $inherits(UnaryExpression, Expression); |
| 11126 function UnaryExpression(op, self, span) { |
| 11127 this.op = op; |
| 11128 this.self = self; |
| 11129 // Initializers done |
| 11130 Expression.call(this, span); |
| 11131 } |
| 11132 UnaryExpression.prototype.get$op = function() { return this.op; }; |
| 11133 UnaryExpression.prototype.set$op = function(value) { return this.op = value; }; |
| 11134 UnaryExpression.prototype.visit = function(visitor) { |
| 11135 return visitor.visitUnaryExpression(this); |
| 11136 } |
| 11137 UnaryExpression.prototype.visit$1 = UnaryExpression.prototype.visit; |
| 11138 // ********** Code for PostfixExpression ************** |
| 11139 $inherits(PostfixExpression, Expression); |
| 11140 function PostfixExpression(body, op, span) { |
| 11141 this.body = body; |
| 11142 this.op = op; |
| 11143 // Initializers done |
| 11144 Expression.call(this, span); |
| 11145 } |
| 11146 PostfixExpression.prototype.get$op = function() { return this.op; }; |
| 11147 PostfixExpression.prototype.set$op = function(value) { return this.op = value; }
; |
| 11148 PostfixExpression.prototype.visit = function(visitor) { |
| 11149 return visitor.visitPostfixExpression$1(this); |
| 11150 } |
| 11151 PostfixExpression.prototype.visit$1 = PostfixExpression.prototype.visit; |
| 11152 // ********** Code for NewExpression ************** |
| 11153 $inherits(NewExpression, Expression); |
| 11154 function NewExpression(isConst, type, name, arguments, span) { |
| 11155 this.isConst = isConst; |
| 11156 this.type = type; |
| 11157 this.name = name; |
| 11158 this.arguments = arguments; |
| 11159 // Initializers done |
| 11160 Expression.call(this, span); |
| 11161 } |
| 11162 NewExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 11163 NewExpression.prototype.set$isConst = function(value) { return this.isConst = va
lue; }; |
| 11164 NewExpression.prototype.get$arguments = function() { return this.arguments; }; |
| 11165 NewExpression.prototype.set$arguments = function(value) { return this.arguments
= value; }; |
| 11166 NewExpression.prototype.visit = function(visitor) { |
| 11167 return visitor.visitNewExpression(this); |
| 11168 } |
| 11169 NewExpression.prototype.visit$1 = NewExpression.prototype.visit; |
| 11170 // ********** Code for ListExpression ************** |
| 11171 $inherits(ListExpression, Expression); |
| 11172 function ListExpression(isConst, type, values, span) { |
| 11173 this.isConst = isConst; |
| 11174 this.type = type; |
| 11175 this.values = values; |
| 11176 // Initializers done |
| 11177 Expression.call(this, span); |
| 11178 } |
| 11179 ListExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 11180 ListExpression.prototype.set$isConst = function(value) { return this.isConst = v
alue; }; |
| 11181 ListExpression.prototype.visit = function(visitor) { |
| 11182 return visitor.visitListExpression(this); |
| 11183 } |
| 11184 ListExpression.prototype.visit$1 = ListExpression.prototype.visit; |
| 11185 // ********** Code for MapExpression ************** |
| 11186 $inherits(MapExpression, Expression); |
| 11187 function MapExpression(isConst, type, items, span) { |
| 11188 this.isConst = isConst; |
| 11189 this.type = type; |
| 11190 this.items = items; |
| 11191 // Initializers done |
| 11192 Expression.call(this, span); |
| 11193 } |
| 11194 MapExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 11195 MapExpression.prototype.set$isConst = function(value) { return this.isConst = va
lue; }; |
| 11196 MapExpression.prototype.visit = function(visitor) { |
| 11197 return visitor.visitMapExpression(this); |
| 11198 } |
| 11199 MapExpression.prototype.visit$1 = MapExpression.prototype.visit; |
| 11200 // ********** Code for ConditionalExpression ************** |
| 11201 $inherits(ConditionalExpression, Expression); |
| 11202 function ConditionalExpression(test, trueBranch, falseBranch, span) { |
| 11203 this.test = test; |
| 11204 this.trueBranch = trueBranch; |
| 11205 this.falseBranch = falseBranch; |
| 11206 // Initializers done |
| 11207 Expression.call(this, span); |
| 11208 } |
| 11209 ConditionalExpression.prototype.visit = function(visitor) { |
| 11210 return visitor.visitConditionalExpression(this); |
| 11211 } |
| 11212 ConditionalExpression.prototype.visit$1 = ConditionalExpression.prototype.visit; |
| 11213 // ********** Code for IsExpression ************** |
| 11214 $inherits(IsExpression, Expression); |
| 11215 function IsExpression(isTrue, x, type, span) { |
| 11216 this.isTrue = isTrue; |
| 11217 this.x = x; |
| 11218 this.type = type; |
| 11219 // Initializers done |
| 11220 Expression.call(this, span); |
| 11221 } |
| 11222 IsExpression.prototype.visit = function(visitor) { |
| 11223 return visitor.visitIsExpression(this); |
| 11224 } |
| 11225 IsExpression.prototype.visit$1 = IsExpression.prototype.visit; |
| 11226 // ********** Code for ParenExpression ************** |
| 11227 $inherits(ParenExpression, Expression); |
| 11228 function ParenExpression(body, span) { |
| 11229 this.body = body; |
| 11230 // Initializers done |
| 11231 Expression.call(this, span); |
| 11232 } |
| 11233 ParenExpression.prototype.visit = function(visitor) { |
| 11234 return visitor.visitParenExpression(this); |
| 11235 } |
| 11236 ParenExpression.prototype.visit$1 = ParenExpression.prototype.visit; |
| 11237 // ********** Code for AwaitExpression ************** |
| 11238 $inherits(AwaitExpression, Expression); |
| 11239 function AwaitExpression(body, span) { |
| 11240 this.body = body; |
| 11241 // Initializers done |
| 11242 Expression.call(this, span); |
| 11243 } |
| 11244 AwaitExpression.prototype.visit = function(visitor) { |
| 11245 return visitor.visitAwaitExpression(this); |
| 11246 } |
| 11247 AwaitExpression.prototype.visit$1 = AwaitExpression.prototype.visit; |
| 11248 // ********** Code for DotExpression ************** |
| 11249 $inherits(DotExpression, Expression); |
| 11250 function DotExpression(self, name, span) { |
| 11251 this.self = self; |
| 11252 this.name = name; |
| 11253 // Initializers done |
| 11254 Expression.call(this, span); |
| 11255 } |
| 11256 DotExpression.prototype.visit = function(visitor) { |
| 11257 return visitor.visitDotExpression(this); |
| 11258 } |
| 11259 DotExpression.prototype.visit$1 = DotExpression.prototype.visit; |
| 11260 // ********** Code for VarExpression ************** |
| 11261 $inherits(VarExpression, Expression); |
| 11262 function VarExpression(name, span) { |
| 11263 this.name = name; |
| 11264 // Initializers done |
| 11265 Expression.call(this, span); |
| 11266 } |
| 11267 VarExpression.prototype.visit = function(visitor) { |
| 11268 return visitor.visitVarExpression(this); |
| 11269 } |
| 11270 VarExpression.prototype.visit$1 = VarExpression.prototype.visit; |
| 11271 // ********** Code for ThisExpression ************** |
| 11272 $inherits(ThisExpression, Expression); |
| 11273 function ThisExpression(span) { |
| 11274 // Initializers done |
| 11275 Expression.call(this, span); |
| 11276 } |
| 11277 ThisExpression.prototype.visit = function(visitor) { |
| 11278 return visitor.visitThisExpression(this); |
| 11279 } |
| 11280 ThisExpression.prototype.visit$1 = ThisExpression.prototype.visit; |
| 11281 // ********** Code for SuperExpression ************** |
| 11282 $inherits(SuperExpression, Expression); |
| 11283 function SuperExpression(span) { |
| 11284 // Initializers done |
| 11285 Expression.call(this, span); |
| 11286 } |
| 11287 SuperExpression.prototype.visit = function(visitor) { |
| 11288 return visitor.visitSuperExpression(this); |
| 11289 } |
| 11290 SuperExpression.prototype.visit$1 = SuperExpression.prototype.visit; |
| 11291 // ********** Code for NullExpression ************** |
| 11292 $inherits(NullExpression, Expression); |
| 11293 function NullExpression(span) { |
| 11294 // Initializers done |
| 11295 Expression.call(this, span); |
| 11296 } |
| 11297 NullExpression.prototype.visit = function(visitor) { |
| 11298 return visitor.visitNullExpression(this); |
| 11299 } |
| 11300 NullExpression.prototype.visit$1 = NullExpression.prototype.visit; |
| 11301 // ********** Code for LiteralExpression ************** |
| 11302 $inherits(LiteralExpression, Expression); |
| 11303 function LiteralExpression(value, type, text, span) { |
| 11304 this.value = value; |
| 11305 this.type = type; |
| 11306 this.text = text; |
| 11307 // Initializers done |
| 11308 Expression.call(this, span); |
| 11309 } |
| 11310 LiteralExpression.prototype.visit = function(visitor) { |
| 11311 return visitor.visitLiteralExpression(this); |
| 11312 } |
| 11313 LiteralExpression.prototype.visit$1 = LiteralExpression.prototype.visit; |
| 11314 // ********** Code for NameTypeReference ************** |
| 11315 $inherits(NameTypeReference, TypeReference); |
| 11316 function NameTypeReference(isFinal, name, names, span) { |
| 11317 this.isFinal = isFinal; |
| 11318 this.name = name; |
| 11319 this.names = names; |
| 11320 // Initializers done |
| 11321 TypeReference.call(this, span); |
| 11322 } |
| 11323 NameTypeReference.prototype.get$isFinal = function() { return this.isFinal; }; |
| 11324 NameTypeReference.prototype.set$isFinal = function(value) { return this.isFinal
= value; }; |
| 11325 NameTypeReference.prototype.get$names = function() { return this.names; }; |
| 11326 NameTypeReference.prototype.set$names = function(value) { return this.names = va
lue; }; |
| 11327 NameTypeReference.prototype.visit = function(visitor) { |
| 11328 return visitor.visitNameTypeReference(this); |
| 11329 } |
| 11330 NameTypeReference.prototype.visit$1 = NameTypeReference.prototype.visit; |
| 11331 // ********** Code for GenericTypeReference ************** |
| 11332 $inherits(GenericTypeReference, TypeReference); |
| 11333 function GenericTypeReference(baseType, typeArguments, depth, span) { |
| 11334 this.baseType = baseType; |
| 11335 this.typeArguments = typeArguments; |
| 11336 this.depth = depth; |
| 11337 // Initializers done |
| 11338 TypeReference.call(this, span); |
| 11339 } |
| 11340 GenericTypeReference.prototype.get$baseType = function() { return this.baseType;
}; |
| 11341 GenericTypeReference.prototype.set$baseType = function(value) { return this.base
Type = value; }; |
| 11342 GenericTypeReference.prototype.get$typeArguments = function() { return this.type
Arguments; }; |
| 11343 GenericTypeReference.prototype.set$typeArguments = function(value) { return this
.typeArguments = value; }; |
| 11344 GenericTypeReference.prototype.visit = function(visitor) { |
| 11345 return visitor.visitGenericTypeReference(this); |
| 11346 } |
| 11347 GenericTypeReference.prototype.visit$1 = GenericTypeReference.prototype.visit; |
| 11348 // ********** Code for FunctionTypeReference ************** |
| 11349 $inherits(FunctionTypeReference, TypeReference); |
| 11350 function FunctionTypeReference(isFinal, func, span) { |
| 11351 this.isFinal = isFinal; |
| 11352 this.func = func; |
| 11353 // Initializers done |
| 11354 TypeReference.call(this, span); |
| 11355 } |
| 11356 FunctionTypeReference.prototype.get$isFinal = function() { return this.isFinal;
}; |
| 11357 FunctionTypeReference.prototype.set$isFinal = function(value) { return this.isFi
nal = value; }; |
| 11358 FunctionTypeReference.prototype.get$func = function() { return this.func; }; |
| 11359 FunctionTypeReference.prototype.set$func = function(value) { return this.func =
value; }; |
| 11360 FunctionTypeReference.prototype.visit = function(visitor) { |
| 11361 return visitor.visitFunctionTypeReference(this); |
| 11362 } |
| 11363 FunctionTypeReference.prototype.visit$1 = FunctionTypeReference.prototype.visit; |
| 11364 // ********** Code for ArgumentNode ************** |
| 11365 $inherits(ArgumentNode, lang_Node); |
| 11366 function ArgumentNode(label, value, span) { |
| 11367 this.label = label; |
| 11368 this.value = value; |
| 11369 // Initializers done |
| 11370 lang_Node.call(this, span); |
| 11371 } |
| 11372 ArgumentNode.prototype.visit = function(visitor) { |
| 11373 return visitor.visitArgumentNode(this); |
| 11374 } |
| 11375 ArgumentNode.prototype.visit$1 = ArgumentNode.prototype.visit; |
| 11376 // ********** Code for FormalNode ************** |
| 11377 $inherits(FormalNode, lang_Node); |
| 11378 function FormalNode(isThis, isRest, type, name, value, span) { |
| 11379 this.isThis = isThis; |
| 11380 this.isRest = isRest; |
| 11381 this.type = type; |
| 11382 this.name = name; |
| 11383 this.value = value; |
| 11384 // Initializers done |
| 11385 lang_Node.call(this, span); |
| 11386 } |
| 11387 FormalNode.prototype.visit = function(visitor) { |
| 11388 return visitor.visitFormalNode(this); |
| 11389 } |
| 11390 FormalNode.prototype.visit$1 = FormalNode.prototype.visit; |
| 11391 // ********** Code for CatchNode ************** |
| 11392 $inherits(CatchNode, lang_Node); |
| 11393 function CatchNode(exception, trace, body, span) { |
| 11394 this.exception = exception; |
| 11395 this.trace = trace; |
| 11396 this.body = body; |
| 11397 // Initializers done |
| 11398 lang_Node.call(this, span); |
| 11399 } |
| 11400 CatchNode.prototype.get$exception = function() { return this.exception; }; |
| 11401 CatchNode.prototype.set$exception = function(value) { return this.exception = va
lue; }; |
| 11402 CatchNode.prototype.get$trace = function() { return this.trace; }; |
| 11403 CatchNode.prototype.set$trace = function(value) { return this.trace = value; }; |
| 11404 CatchNode.prototype.visit = function(visitor) { |
| 11405 return visitor.visitCatchNode(this); |
| 11406 } |
| 11407 CatchNode.prototype.visit$1 = CatchNode.prototype.visit; |
| 11408 // ********** Code for CaseNode ************** |
| 11409 $inherits(CaseNode, lang_Node); |
| 11410 function CaseNode(label, cases, statements, span) { |
| 11411 this.label = label; |
| 11412 this.cases = cases; |
| 11413 this.statements = statements; |
| 11414 // Initializers done |
| 11415 lang_Node.call(this, span); |
| 11416 } |
| 11417 CaseNode.prototype.get$cases = function() { return this.cases; }; |
| 11418 CaseNode.prototype.set$cases = function(value) { return this.cases = value; }; |
| 11419 CaseNode.prototype.get$statements = function() { return this.statements; }; |
| 11420 CaseNode.prototype.set$statements = function(value) { return this.statements = v
alue; }; |
| 11421 CaseNode.prototype.visit = function(visitor) { |
| 11422 return visitor.visitCaseNode(this); |
| 11423 } |
| 11424 CaseNode.prototype.visit$1 = CaseNode.prototype.visit; |
| 11425 // ********** Code for TypeParameter ************** |
| 11426 $inherits(TypeParameter, lang_Node); |
| 11427 function TypeParameter(name, extendsType, span) { |
| 11428 this.name = name; |
| 11429 this.extendsType = extendsType; |
| 11430 // Initializers done |
| 11431 lang_Node.call(this, span); |
| 11432 } |
| 11433 TypeParameter.prototype.get$extendsType = function() { return this.extendsType;
}; |
| 11434 TypeParameter.prototype.set$extendsType = function(value) { return this.extendsT
ype = value; }; |
| 11435 TypeParameter.prototype.visit = function(visitor) { |
| 11436 return visitor.visitTypeParameter(this); |
| 11437 } |
| 11438 TypeParameter.prototype.visit$1 = TypeParameter.prototype.visit; |
| 11439 // ********** Code for Identifier ************** |
| 11440 $inherits(Identifier, lang_Node); |
| 11441 function Identifier(name, span) { |
| 11442 this.name = name; |
| 11443 // Initializers done |
| 11444 lang_Node.call(this, span); |
| 11445 } |
| 11446 Identifier.prototype.visit = function(visitor) { |
| 11447 return visitor.visitIdentifier(this); |
| 11448 } |
| 11449 Identifier.prototype.visit$1 = Identifier.prototype.visit; |
| 11450 // ********** Code for DeclaredIdentifier ************** |
| 11451 $inherits(DeclaredIdentifier, Expression); |
| 11452 function DeclaredIdentifier(type, name, span) { |
| 11453 this.type = type; |
| 11454 this.name = name; |
| 11455 // Initializers done |
| 11456 Expression.call(this, span); |
| 11457 } |
| 11458 DeclaredIdentifier.prototype.visit = function(visitor) { |
| 11459 return visitor.visitDeclaredIdentifier(this); |
| 11460 } |
| 11461 DeclaredIdentifier.prototype.visit$1 = DeclaredIdentifier.prototype.visit; |
| 11462 // ********** Code for Type ************** |
| 11463 $inherits(Type, lang_Element); |
| 11464 function Type(name) { |
| 11465 this.isTested = false |
| 11466 this.isChecked = false |
| 11467 this.isWritten = false |
| 11468 this._resolvedMembers = new HashMapImplementation(); |
| 11469 this.varStubs = new HashMapImplementation(); |
| 11470 // Initializers done |
| 11471 lang_Element.call(this, name, null); |
| 11472 } |
| 11473 Type.prototype.get$isTested = function() { return this.isTested; }; |
| 11474 Type.prototype.set$isTested = function(value) { return this.isTested = value; }; |
| 11475 Type.prototype.get$typeCheckCode = function() { return this.typeCheckCode; }; |
| 11476 Type.prototype.set$typeCheckCode = function(value) { return this.typeCheckCode =
value; }; |
| 11477 Type.prototype.get$varStubs = function() { return this.varStubs; }; |
| 11478 Type.prototype.set$varStubs = function(value) { return this.varStubs = value; }; |
| 11479 Type.prototype.markUsed = function() { |
| 11480 |
| 11481 } |
| 11482 Type.prototype.get$typeMember = function() { |
| 11483 if (this._typeMember == null) { |
| 11484 this._typeMember = new TypeMember(this); |
| 11485 } |
| 11486 return this._typeMember; |
| 11487 } |
| 11488 Type.prototype.getMember = function(name) { |
| 11489 return null; |
| 11490 } |
| 11491 Type.prototype.get$subtypes = function() { |
| 11492 return null; |
| 11493 } |
| 11494 Type.prototype.get$isVar = function() { |
| 11495 return false; |
| 11496 } |
| 11497 Type.prototype.get$isTop = function() { |
| 11498 return false; |
| 11499 } |
| 11500 Type.prototype.get$isObject = function() { |
| 11501 return false; |
| 11502 } |
| 11503 Type.prototype.get$isString = function() { |
| 11504 return false; |
| 11505 } |
| 11506 Type.prototype.get$isBool = function() { |
| 11507 return false; |
| 11508 } |
| 11509 Type.prototype.get$isFunction = function() { |
| 11510 return false; |
| 11511 } |
| 11512 Type.prototype.get$isList = function() { |
| 11513 return false; |
| 11514 } |
| 11515 Type.prototype.get$isNum = function() { |
| 11516 return false; |
| 11517 } |
| 11518 Type.prototype.get$isVoid = function() { |
| 11519 return false; |
| 11520 } |
| 11521 Type.prototype.get$isNullable = function() { |
| 11522 return true; |
| 11523 } |
| 11524 Type.prototype.get$isVarOrFunction = function() { |
| 11525 return this.get$isVar() || this.get$isFunction(); |
| 11526 } |
| 11527 Type.prototype.get$isVarOrObject = function() { |
| 11528 return this.get$isVar() || this.get$isObject(); |
| 11529 } |
| 11530 Type.prototype.getCallMethod = function() { |
| 11531 return null; |
| 11532 } |
| 11533 Type.prototype.get$isClosed = function() { |
| 11534 return this.get$isString() || this.get$isBool() || this.get$isNum() || this.ge
t$isFunction() || this.get$isVar(); |
| 11535 } |
| 11536 Type.prototype.get$isUsed = function() { |
| 11537 return false; |
| 11538 } |
| 11539 Type.prototype.get$isGeneric = function() { |
| 11540 return false; |
| 11541 } |
| 11542 Type.prototype.get$nativeType = function() { |
| 11543 return null; |
| 11544 } |
| 11545 Type.prototype.get$isHiddenNativeType = function() { |
| 11546 return (this.get$nativeType() != null && this.get$nativeType().isConstructorHi
dden); |
| 11547 } |
| 11548 Type.prototype.get$isSingletonNative = function() { |
| 11549 return (this.get$nativeType() != null && this.get$nativeType().isSingleton); |
| 11550 } |
| 11551 Type.prototype.get$isJsGlobalObject = function() { |
| 11552 return (this.get$nativeType() != null && this.get$nativeType().isJsGlobalObjec
t); |
| 11553 } |
| 11554 Type.prototype.get$hasTypeParams = function() { |
| 11555 return false; |
| 11556 } |
| 11557 Type.prototype.get$typeofName = function() { |
| 11558 return null; |
| 11559 } |
| 11560 Type.prototype.get$members = function() { |
| 11561 return null; |
| 11562 } |
| 11563 Type.prototype.get$definition = function() { |
| 11564 return null; |
| 11565 } |
| 11566 Type.prototype.get$factories = function() { |
| 11567 return null; |
| 11568 } |
| 11569 Type.prototype.get$typeArgsInOrder = function() { |
| 11570 return null; |
| 11571 } |
| 11572 Type.prototype.get$genericType = function() { |
| 11573 return this; |
| 11574 } |
| 11575 Type.prototype.get$interfaces = function() { |
| 11576 return null; |
| 11577 } |
| 11578 Type.prototype.get$parent = function() { |
| 11579 return null; |
| 11580 } |
| 11581 Object.defineProperty(Type.prototype, "parent", { |
| 11582 get: Type.prototype.get$parent |
| 11583 }); |
| 11584 Type.prototype.getAllMembers = function() { |
| 11585 return new HashMapImplementation(); |
| 11586 } |
| 11587 Type.prototype.get$hasNativeSubtypes = function() { |
| 11588 if (this._hasNativeSubtypes == null) { |
| 11589 this._hasNativeSubtypes = this.get$subtypes().some((function (t) { |
| 11590 return t.get$isNative(); |
| 11591 }) |
| 11592 ); |
| 11593 } |
| 11594 return this._hasNativeSubtypes; |
| 11595 } |
| 11596 Type.prototype._checkExtends = function() { |
| 11597 var typeParams = this.get$genericType().typeParameters; |
| 11598 if (typeParams != null && this.get$typeArgsInOrder() != null) { |
| 11599 var args = this.get$typeArgsInOrder().iterator$0(); |
| 11600 var params = typeParams.iterator$0(); |
| 11601 while (args.hasNext$0() && params.hasNext$0()) { |
| 11602 var typeParam = params.next$0(); |
| 11603 var typeArg = args.next$0(); |
| 11604 if (typeParam.get$extendsType() != null && typeArg != null) { |
| 11605 typeArg.ensureSubtypeOf$3(typeParam.get$extendsType(), typeParam.span, t
rue); |
| 11606 } |
| 11607 } |
| 11608 } |
| 11609 if (this.get$interfaces() != null) { |
| 11610 var $$list = this.get$interfaces(); |
| 11611 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11612 var i = $$list.$index($$i); |
| 11613 i._checkExtends$0(); |
| 11614 } |
| 11615 } |
| 11616 } |
| 11617 Type.prototype._checkOverride = function(member) { |
| 11618 var parentMember = this._getMemberInParents(member.name); |
| 11619 if (parentMember != null) { |
| 11620 if (!member.get$isPrivate() || $eq(member.get$library(), parentMember.get$li
brary())) { |
| 11621 member.override(parentMember); |
| 11622 } |
| 11623 } |
| 11624 } |
| 11625 Type.prototype._createNotEqualMember = function() { |
| 11626 var eq = this.get$members().$index(':eq'); |
| 11627 if (eq == null) { |
| 11628 return; |
| 11629 } |
| 11630 var ne = new MethodMember(':ne', this, eq.definition); |
| 11631 ne.isGenerated = true; |
| 11632 ne.returnType = eq.returnType; |
| 11633 ne.parameters = eq.parameters; |
| 11634 ne.isStatic = eq.isStatic; |
| 11635 ne.isAbstract = eq.isAbstract; |
| 11636 this.get$members().$setindex(':ne', ne); |
| 11637 } |
| 11638 Type.prototype._getMemberInParents = function(memberName) { |
| 11639 if (this.get$isClass()) { |
| 11640 if (this.get$parent() != null) { |
| 11641 return this.get$parent().getMember(memberName); |
| 11642 } |
| 11643 else { |
| 11644 return null; |
| 11645 } |
| 11646 } |
| 11647 else { |
| 11648 if (this.get$interfaces() != null && this.get$interfaces().length > 0) { |
| 11649 var $$list = this.get$interfaces(); |
| 11650 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11651 var i = $$list.$index($$i); |
| 11652 var ret = i.getMember$1(memberName); |
| 11653 if (ret != null) { |
| 11654 return ret; |
| 11655 } |
| 11656 } |
| 11657 } |
| 11658 return $globals.world.objectType.getMember(memberName); |
| 11659 } |
| 11660 } |
| 11661 Type.prototype.resolveMember = function(memberName) { |
| 11662 var ret = this._resolvedMembers.$index(memberName); |
| 11663 if (ret != null) return ret; |
| 11664 var member = this.getMember(memberName); |
| 11665 if (member == null) { |
| 11666 return null; |
| 11667 } |
| 11668 ret = new MemberSet(member, false); |
| 11669 this._resolvedMembers.$setindex(memberName, ret); |
| 11670 if (member.get$isStatic()) { |
| 11671 return ret; |
| 11672 } |
| 11673 else { |
| 11674 var $$list = this.get$subtypes(); |
| 11675 for (var $$i = this.get$subtypes().iterator(); $$i.hasNext$0(); ) { |
| 11676 var t = $$i.next$0(); |
| 11677 if (!this.get$isClass() && t.get$isClass()) { |
| 11678 var m = t.getMember$1(memberName); |
| 11679 if (m != null && ret.members.indexOf(m) == -1) { |
| 11680 ret.add(m); |
| 11681 } |
| 11682 } |
| 11683 else { |
| 11684 var m = t.get$members().$index(memberName); |
| 11685 if (m != null) ret.add(m); |
| 11686 } |
| 11687 } |
| 11688 return ret; |
| 11689 } |
| 11690 } |
| 11691 Type.prototype.ensureSubtypeOf = function(other, span, typeErrors) { |
| 11692 if (!this.isSubtypeOf(other)) { |
| 11693 var msg = ('type ' + this.name + ' is not a subtype of ' + other.name); |
| 11694 if (typeErrors) { |
| 11695 $globals.world.error(msg, span); |
| 11696 } |
| 11697 else { |
| 11698 $globals.world.warning(msg, span); |
| 11699 } |
| 11700 } |
| 11701 } |
| 11702 Type.prototype.needsVarCall = function(args) { |
| 11703 if (this.get$isVarOrFunction()) { |
| 11704 return true; |
| 11705 } |
| 11706 var call = this.getCallMethod(); |
| 11707 if (call != null) { |
| 11708 if (args.get$length() != call.get$parameters().length || !call.namesInOrder$
1(args)) { |
| 11709 return true; |
| 11710 } |
| 11711 } |
| 11712 return false; |
| 11713 } |
| 11714 Type.union = function(x, y) { |
| 11715 if ($eq(x, y)) return x; |
| 11716 if (x.get$isNum() && y.get$isNum()) return $globals.world.numType; |
| 11717 if (x.get$isString() && y.get$isString()) return $globals.world.stringType; |
| 11718 return $globals.world.varType; |
| 11719 } |
| 11720 Type.prototype.isAssignable = function(other) { |
| 11721 return this.isSubtypeOf(other) || other.isSubtypeOf(this); |
| 11722 } |
| 11723 Type.prototype._isDirectSupertypeOf = function(other) { |
| 11724 var $this = this; // closure support |
| 11725 if (other.get$isClass()) { |
| 11726 return $eq(other.get$parent(), this) || this.get$isObject() && other.get$par
ent() == null; |
| 11727 } |
| 11728 else { |
| 11729 if (other.get$interfaces() == null || other.get$interfaces().isEmpty()) { |
| 11730 return this.get$isObject(); |
| 11731 } |
| 11732 else { |
| 11733 return other.get$interfaces().some((function (i) { |
| 11734 return $eq(i, $this); |
| 11735 }) |
| 11736 ); |
| 11737 } |
| 11738 } |
| 11739 } |
| 11740 Type.prototype.isSubtypeOf = function(other) { |
| 11741 if ((other instanceof ParameterType)) { |
| 11742 return true; |
| 11743 } |
| 11744 if ($eq(this, other)) return true; |
| 11745 if (this.get$isVar()) return true; |
| 11746 if (other.get$isVar()) return true; |
| 11747 if (other._isDirectSupertypeOf(this)) return true; |
| 11748 var call = this.getCallMethod(); |
| 11749 var otherCall = other.getCallMethod(); |
| 11750 if (call != null && otherCall != null) { |
| 11751 return Type._isFunctionSubtypeOf(call, otherCall); |
| 11752 } |
| 11753 if ($eq(this.get$genericType(), other.get$genericType()) && this.get$typeArgsI
nOrder() != null && other.get$typeArgsInOrder() != null && $eq(this.get$typeArgs
InOrder().length, other.get$typeArgsInOrder().length)) { |
| 11754 var t = this.get$typeArgsInOrder().iterator$0(); |
| 11755 var s = other.get$typeArgsInOrder().iterator$0(); |
| 11756 while (t.hasNext$0()) { |
| 11757 if (!t.next$0().isSubtypeOf$1(s.next$0())) return false; |
| 11758 } |
| 11759 return true; |
| 11760 } |
| 11761 if (this.get$parent() != null && this.get$parent().isSubtypeOf(other)) { |
| 11762 return true; |
| 11763 } |
| 11764 if (this.get$interfaces() != null && this.get$interfaces().some((function (i)
{ |
| 11765 return i.isSubtypeOf$1(other); |
| 11766 }) |
| 11767 )) { |
| 11768 return true; |
| 11769 } |
| 11770 return false; |
| 11771 } |
| 11772 Type.prototype.hashCode = function() { |
| 11773 var libraryCode = this.get$library() == null ? 1 : this.get$library().hashCode
(); |
| 11774 var nameCode = this.name == null ? 1 : this.name.hashCode(); |
| 11775 return (libraryCode << 4) ^ nameCode; |
| 11776 } |
| 11777 Type.prototype.$eq = function(other) { |
| 11778 return (other instanceof Type) && $eq(other.name, this.name) && $eq(this.get$l
ibrary(), other.get$library()); |
| 11779 } |
| 11780 Type._isFunctionSubtypeOf = function(t, s) { |
| 11781 if (!s.returnType.get$isVoid() && !s.returnType.isAssignable(t.returnType)) { |
| 11782 return false; |
| 11783 } |
| 11784 var tp = t.parameters; |
| 11785 var sp = s.parameters; |
| 11786 if (tp.length < sp.length) return false; |
| 11787 for (var i = 0; |
| 11788 i < sp.length; i++) { |
| 11789 if ($ne(tp.$index(i).get$isOptional(), sp.$index(i).get$isOptional())) retur
n false; |
| 11790 if (tp.$index(i).get$isOptional() && $ne(tp.$index(i).name, sp.$index(i).nam
e)) return false; |
| 11791 if (!tp.$index(i).type.isAssignable$1(sp.$index(i).type)) return false; |
| 11792 } |
| 11793 if (tp.length > sp.length && !tp.$index(sp.length).get$isOptional()) return fa
lse; |
| 11794 return true; |
| 11795 } |
| 11796 Type.prototype._checkExtends$0 = Type.prototype._checkExtends; |
| 11797 Type.prototype.addDirectSubtype$1 = Type.prototype.addDirectSubtype; |
| 11798 Type.prototype.ensureSubtypeOf$3 = Type.prototype.ensureSubtypeOf; |
| 11799 Type.prototype.getConstructor$1 = Type.prototype.getConstructor; |
| 11800 Type.prototype.getFactory$2 = Type.prototype.getFactory; |
| 11801 Type.prototype.getMember$1 = Type.prototype.getMember; |
| 11802 Type.prototype.getOrMakeConcreteType$1 = Type.prototype.getOrMakeConcreteType; |
| 11803 Type.prototype.hashCode$0 = Type.prototype.hashCode; |
| 11804 Type.prototype.isAssignable$1 = Type.prototype.isAssignable; |
| 11805 Type.prototype.isSubtypeOf$1 = Type.prototype.isSubtypeOf; |
| 11806 Type.prototype.markUsed$0 = Type.prototype.markUsed; |
| 11807 Type.prototype.resolveTypeParams$1 = Type.prototype.resolveTypeParams; |
| 11808 // ********** Code for ParameterType ************** |
| 11809 $inherits(ParameterType, Type); |
| 11810 function ParameterType(name, typeParameter) { |
| 11811 this.typeParameter = typeParameter; |
| 11812 // Initializers done |
| 11813 Type.call(this, name); |
| 11814 } |
| 11815 ParameterType.prototype.get$typeParameter = function() { return this.typeParamet
er; }; |
| 11816 ParameterType.prototype.set$typeParameter = function(value) { return this.typePa
rameter = value; }; |
| 11817 ParameterType.prototype.get$extendsType = function() { return this.extendsType;
}; |
| 11818 ParameterType.prototype.set$extendsType = function(value) { return this.extendsT
ype = value; }; |
| 11819 ParameterType.prototype.get$isClass = function() { |
| 11820 return false; |
| 11821 } |
| 11822 ParameterType.prototype.get$library = function() { |
| 11823 return null; |
| 11824 } |
| 11825 ParameterType.prototype.get$span = function() { |
| 11826 return this.typeParameter.span; |
| 11827 } |
| 11828 Object.defineProperty(ParameterType.prototype, "span", { |
| 11829 get: ParameterType.prototype.get$span |
| 11830 }); |
| 11831 ParameterType.prototype.get$constructors = function() { |
| 11832 $globals.world.internalError('no constructors on type parameters yet'); |
| 11833 } |
| 11834 ParameterType.prototype.getCallMethod = function() { |
| 11835 return this.extendsType.getCallMethod(); |
| 11836 } |
| 11837 ParameterType.prototype.genMethod = function(method) { |
| 11838 this.extendsType.genMethod(method); |
| 11839 } |
| 11840 ParameterType.prototype.isSubtypeOf = function(other) { |
| 11841 return true; |
| 11842 } |
| 11843 ParameterType.prototype.resolveMember = function(memberName) { |
| 11844 return this.extendsType.resolveMember(memberName); |
| 11845 } |
| 11846 ParameterType.prototype.getConstructor = function(constructorName) { |
| 11847 $globals.world.internalError('no constructors on type parameters yet'); |
| 11848 } |
| 11849 ParameterType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11850 $globals.world.internalError('no concrete types of type parameters yet', this.
get$span()); |
| 11851 } |
| 11852 ParameterType.prototype.resolveTypeParams = function(inType) { |
| 11853 return inType.typeArguments.$index(this.name); |
| 11854 } |
| 11855 ParameterType.prototype.addDirectSubtype = function(type) { |
| 11856 $globals.world.internalError('no subtypes of type parameters yet', this.get$sp
an()); |
| 11857 } |
| 11858 ParameterType.prototype.resolve = function() { |
| 11859 if (this.typeParameter.extendsType != null) { |
| 11860 this.extendsType = this.get$enclosingElement().resolveType(this.typeParamete
r.extendsType, true); |
| 11861 } |
| 11862 else { |
| 11863 this.extendsType = $globals.world.objectType; |
| 11864 } |
| 11865 } |
| 11866 ParameterType.prototype.addDirectSubtype$1 = ParameterType.prototype.addDirectSu
btype; |
| 11867 ParameterType.prototype.getConstructor$1 = ParameterType.prototype.getConstructo
r; |
| 11868 ParameterType.prototype.getOrMakeConcreteType$1 = ParameterType.prototype.getOrM
akeConcreteType; |
| 11869 ParameterType.prototype.isSubtypeOf$1 = ParameterType.prototype.isSubtypeOf; |
| 11870 ParameterType.prototype.resolve$0 = ParameterType.prototype.resolve; |
| 11871 ParameterType.prototype.resolveTypeParams$1 = ParameterType.prototype.resolveTyp
eParams; |
| 11872 // ********** Code for NonNullableType ************** |
| 11873 $inherits(NonNullableType, Type); |
| 11874 function NonNullableType(type) { |
| 11875 this.type = type; |
| 11876 // Initializers done |
| 11877 Type.call(this, type.name); |
| 11878 } |
| 11879 NonNullableType.prototype.get$isNullable = function() { |
| 11880 return false; |
| 11881 } |
| 11882 NonNullableType.prototype.get$isBool = function() { |
| 11883 return this.type.get$isBool(); |
| 11884 } |
| 11885 NonNullableType.prototype.get$isUsed = function() { |
| 11886 return false; |
| 11887 } |
| 11888 NonNullableType.prototype.isSubtypeOf = function(other) { |
| 11889 return $eq(this, other) || $eq(this.type, other) || this.type.isSubtypeOf(othe
r); |
| 11890 } |
| 11891 NonNullableType.prototype.resolveType = function(node, isRequired) { |
| 11892 return this.type.resolveType(node, isRequired); |
| 11893 } |
| 11894 NonNullableType.prototype.resolveTypeParams = function(inType) { |
| 11895 return this.type.resolveTypeParams(inType); |
| 11896 } |
| 11897 NonNullableType.prototype.addDirectSubtype = function(subtype) { |
| 11898 this.type.addDirectSubtype(subtype); |
| 11899 } |
| 11900 NonNullableType.prototype.markUsed = function() { |
| 11901 this.type.markUsed(); |
| 11902 } |
| 11903 NonNullableType.prototype.genMethod = function(method) { |
| 11904 this.type.genMethod(method); |
| 11905 } |
| 11906 NonNullableType.prototype.get$span = function() { |
| 11907 return this.type.get$span(); |
| 11908 } |
| 11909 Object.defineProperty(NonNullableType.prototype, "span", { |
| 11910 get: NonNullableType.prototype.get$span |
| 11911 }); |
| 11912 NonNullableType.prototype.resolveMember = function(name) { |
| 11913 return this.type.resolveMember(name); |
| 11914 } |
| 11915 NonNullableType.prototype.getMember = function(name) { |
| 11916 return this.type.getMember(name); |
| 11917 } |
| 11918 NonNullableType.prototype.getConstructor = function(name) { |
| 11919 return this.type.getConstructor(name); |
| 11920 } |
| 11921 NonNullableType.prototype.getFactory = function(t, name) { |
| 11922 return this.type.getFactory(t, name); |
| 11923 } |
| 11924 NonNullableType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11925 return this.type.getOrMakeConcreteType(typeArgs); |
| 11926 } |
| 11927 NonNullableType.prototype.get$constructors = function() { |
| 11928 return this.type.get$constructors(); |
| 11929 } |
| 11930 NonNullableType.prototype.get$isClass = function() { |
| 11931 return this.type.get$isClass(); |
| 11932 } |
| 11933 NonNullableType.prototype.get$library = function() { |
| 11934 return this.type.get$library(); |
| 11935 } |
| 11936 NonNullableType.prototype.getCallMethod = function() { |
| 11937 return this.type.getCallMethod(); |
| 11938 } |
| 11939 NonNullableType.prototype.get$isGeneric = function() { |
| 11940 return this.type.get$isGeneric(); |
| 11941 } |
| 11942 NonNullableType.prototype.get$hasTypeParams = function() { |
| 11943 return this.type.get$hasTypeParams(); |
| 11944 } |
| 11945 NonNullableType.prototype.get$typeofName = function() { |
| 11946 return this.type.get$typeofName(); |
| 11947 } |
| 11948 NonNullableType.prototype.get$jsname = function() { |
| 11949 return this.type.get$jsname(); |
| 11950 } |
| 11951 NonNullableType.prototype.get$members = function() { |
| 11952 return this.type.get$members(); |
| 11953 } |
| 11954 NonNullableType.prototype.get$definition = function() { |
| 11955 return this.type.get$definition(); |
| 11956 } |
| 11957 NonNullableType.prototype.get$factories = function() { |
| 11958 return this.type.get$factories(); |
| 11959 } |
| 11960 NonNullableType.prototype.get$typeArgsInOrder = function() { |
| 11961 return this.type.get$typeArgsInOrder(); |
| 11962 } |
| 11963 NonNullableType.prototype.get$genericType = function() { |
| 11964 return this.type.get$genericType(); |
| 11965 } |
| 11966 NonNullableType.prototype.get$interfaces = function() { |
| 11967 return this.type.get$interfaces(); |
| 11968 } |
| 11969 NonNullableType.prototype.get$parent = function() { |
| 11970 return this.type.get$parent(); |
| 11971 } |
| 11972 Object.defineProperty(NonNullableType.prototype, "parent", { |
| 11973 get: NonNullableType.prototype.get$parent |
| 11974 }); |
| 11975 NonNullableType.prototype.getAllMembers = function() { |
| 11976 return this.type.getAllMembers(); |
| 11977 } |
| 11978 NonNullableType.prototype.get$isNative = function() { |
| 11979 return this.type.get$isNative(); |
| 11980 } |
| 11981 NonNullableType.prototype.addDirectSubtype$1 = NonNullableType.prototype.addDire
ctSubtype; |
| 11982 NonNullableType.prototype.getConstructor$1 = NonNullableType.prototype.getConstr
uctor; |
| 11983 NonNullableType.prototype.getFactory$2 = NonNullableType.prototype.getFactory; |
| 11984 NonNullableType.prototype.getMember$1 = NonNullableType.prototype.getMember; |
| 11985 NonNullableType.prototype.getOrMakeConcreteType$1 = NonNullableType.prototype.ge
tOrMakeConcreteType; |
| 11986 NonNullableType.prototype.isSubtypeOf$1 = NonNullableType.prototype.isSubtypeOf; |
| 11987 NonNullableType.prototype.markUsed$0 = NonNullableType.prototype.markUsed; |
| 11988 NonNullableType.prototype.resolveTypeParams$1 = NonNullableType.prototype.resolv
eTypeParams; |
| 11989 // ********** Code for ConcreteType ************** |
| 11990 $inherits(ConcreteType, Type); |
| 11991 function ConcreteType(name, genericType, typeArguments, typeArgsInOrder) { |
| 11992 this.isUsed = false |
| 11993 this.genericType = genericType; |
| 11994 this.typeArguments = typeArguments; |
| 11995 this.typeArgsInOrder = typeArgsInOrder; |
| 11996 this.constructors = new HashMapImplementation(); |
| 11997 this.members = new HashMapImplementation(); |
| 11998 this.factories = new FactoryMap(); |
| 11999 // Initializers done |
| 12000 Type.call(this, name); |
| 12001 } |
| 12002 ConcreteType.prototype.get$genericType = function() { return this.genericType; }
; |
| 12003 ConcreteType.prototype.get$typeArguments = function() { return this.typeArgument
s; }; |
| 12004 ConcreteType.prototype.set$typeArguments = function(value) { return this.typeArg
uments = value; }; |
| 12005 ConcreteType.prototype.get$_lang_parent = function() { return this._lang_parent;
}; |
| 12006 ConcreteType.prototype.set$_lang_parent = function(value) { return this._lang_pa
rent = value; }; |
| 12007 ConcreteType.prototype.get$typeArgsInOrder = function() { return this.typeArgsIn
Order; }; |
| 12008 ConcreteType.prototype.set$typeArgsInOrder = function(value) { return this.typeA
rgsInOrder = value; }; |
| 12009 ConcreteType.prototype.get$isList = function() { |
| 12010 return this.genericType.get$isList(); |
| 12011 } |
| 12012 ConcreteType.prototype.get$isClass = function() { |
| 12013 return this.genericType.isClass; |
| 12014 } |
| 12015 ConcreteType.prototype.get$library = function() { |
| 12016 return this.genericType.library; |
| 12017 } |
| 12018 ConcreteType.prototype.get$span = function() { |
| 12019 return this.genericType.get$span(); |
| 12020 } |
| 12021 Object.defineProperty(ConcreteType.prototype, "span", { |
| 12022 get: ConcreteType.prototype.get$span |
| 12023 }); |
| 12024 ConcreteType.prototype.get$hasTypeParams = function() { |
| 12025 return this.typeArguments.getValues().some$1((function (e) { |
| 12026 return (e instanceof ParameterType); |
| 12027 }) |
| 12028 ); |
| 12029 } |
| 12030 ConcreteType.prototype.get$isUsed = function() { return this.isUsed; }; |
| 12031 ConcreteType.prototype.set$isUsed = function(value) { return this.isUsed = value
; }; |
| 12032 ConcreteType.prototype.get$members = function() { return this.members; }; |
| 12033 ConcreteType.prototype.set$members = function(value) { return this.members = val
ue; }; |
| 12034 ConcreteType.prototype.get$constructors = function() { return this.constructors;
}; |
| 12035 ConcreteType.prototype.set$constructors = function(value) { return this.construc
tors = value; }; |
| 12036 ConcreteType.prototype.get$factories = function() { return this.factories; }; |
| 12037 ConcreteType.prototype.set$factories = function(value) { return this.factories =
value; }; |
| 12038 ConcreteType.prototype.resolveTypeParams = function(inType) { |
| 12039 var newTypeArgs = []; |
| 12040 var needsNewType = false; |
| 12041 var $$list = this.typeArgsInOrder; |
| 12042 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 12043 var t = $$list.$index($$i); |
| 12044 var newType = t.resolveTypeParams$1(inType); |
| 12045 if ($ne(newType, t)) needsNewType = true; |
| 12046 newTypeArgs.add$1(newType); |
| 12047 } |
| 12048 if (!needsNewType) return this; |
| 12049 return this.genericType.getOrMakeConcreteType(newTypeArgs); |
| 12050 } |
| 12051 ConcreteType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 12052 return this.genericType.getOrMakeConcreteType(typeArgs); |
| 12053 } |
| 12054 ConcreteType.prototype.get$parent = function() { |
| 12055 if (this._lang_parent == null && this.genericType.get$parent() != null) { |
| 12056 this._lang_parent = this.genericType.get$parent().resolveTypeParams(this); |
| 12057 } |
| 12058 return this._lang_parent; |
| 12059 } |
| 12060 Object.defineProperty(ConcreteType.prototype, "parent", { |
| 12061 get: ConcreteType.prototype.get$parent |
| 12062 }); |
| 12063 ConcreteType.prototype.get$interfaces = function() { |
| 12064 if (this._interfaces == null && this.genericType.interfaces != null) { |
| 12065 this._interfaces = []; |
| 12066 var $$list = this.genericType.interfaces; |
| 12067 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 12068 var i = $$list.$index($$i); |
| 12069 this._interfaces.add(i.resolveTypeParams$1(this)); |
| 12070 } |
| 12071 } |
| 12072 return this._interfaces; |
| 12073 } |
| 12074 ConcreteType.prototype.get$subtypes = function() { |
| 12075 if (this._subtypes == null) { |
| 12076 this._subtypes = new HashSetImplementation(); |
| 12077 var $$list = this.genericType.get$subtypes(); |
| 12078 for (var $$i = this.genericType.get$subtypes().iterator(); $$i.hasNext$0();
) { |
| 12079 var s = $$i.next$0(); |
| 12080 this._subtypes.add(s.resolveTypeParams$1(this)); |
| 12081 } |
| 12082 } |
| 12083 return this._subtypes; |
| 12084 } |
| 12085 ConcreteType.prototype.getCallMethod = function() { |
| 12086 return this.genericType.getCallMethod(); |
| 12087 } |
| 12088 ConcreteType.prototype.getAllMembers = function() { |
| 12089 var result = this.genericType.getAllMembers(); |
| 12090 var $$list = result.getKeys$0(); |
| 12091 for (var $$i = result.getKeys$0().iterator$0(); $$i.hasNext$0(); ) { |
| 12092 var memberName = $$i.next$0(); |
| 12093 var myMember = this.members.$index(memberName); |
| 12094 if (myMember != null) { |
| 12095 result.$setindex(memberName, myMember); |
| 12096 } |
| 12097 } |
| 12098 return result; |
| 12099 } |
| 12100 ConcreteType.prototype.markUsed = function() { |
| 12101 if (this.isUsed) return; |
| 12102 this.isUsed = true; |
| 12103 this._checkExtends(); |
| 12104 this.genericType.markUsed(); |
| 12105 } |
| 12106 ConcreteType.prototype.genMethod = function(method) { |
| 12107 return this.genericType.genMethod(method); |
| 12108 } |
| 12109 ConcreteType.prototype.getFactory = function(type, constructorName) { |
| 12110 return this.genericType.getFactory(type, constructorName); |
| 12111 } |
| 12112 ConcreteType.prototype.getConstructor = function(constructorName) { |
| 12113 var ret = this.constructors.$index(constructorName); |
| 12114 if (ret != null) return ret; |
| 12115 ret = this.factories.getFactory(this.name, constructorName); |
| 12116 if (ret != null) return ret; |
| 12117 var genericMember = this.genericType.getConstructor(constructorName); |
| 12118 if (genericMember == null) return null; |
| 12119 if ($ne(genericMember.get$declaringType(), this.genericType)) { |
| 12120 if (!genericMember.get$declaringType().get$isGeneric()) return genericMember
; |
| 12121 var newDeclaringType = genericMember.get$declaringType().getOrMakeConcreteTy
pe$1(this.typeArgsInOrder); |
| 12122 var factory = newDeclaringType.getFactory$2(this.genericType, constructorNam
e); |
| 12123 if (factory != null) return factory; |
| 12124 return newDeclaringType.getConstructor$1(constructorName); |
| 12125 } |
| 12126 if (genericMember.get$isFactory()) { |
| 12127 ret = new ConcreteMember(genericMember.name, this, genericMember); |
| 12128 this.factories.addFactory(this.name, constructorName, ret); |
| 12129 } |
| 12130 else { |
| 12131 ret = new ConcreteMember(this.name, this, genericMember); |
| 12132 this.constructors.$setindex(constructorName, ret); |
| 12133 } |
| 12134 return ret; |
| 12135 } |
| 12136 ConcreteType.prototype.getMember = function(memberName) { |
| 12137 var member = this.members.$index(memberName); |
| 12138 if (member != null) { |
| 12139 this._checkOverride(member); |
| 12140 return member; |
| 12141 } |
| 12142 var genericMember = this.genericType.members.$index(memberName); |
| 12143 if (genericMember != null) { |
| 12144 member = new ConcreteMember(genericMember.name, this, genericMember); |
| 12145 this.members.$setindex(memberName, member); |
| 12146 return member; |
| 12147 } |
| 12148 return this._getMemberInParents(memberName); |
| 12149 } |
| 12150 ConcreteType.prototype.resolveType = function(node, isRequired) { |
| 12151 var ret = this.genericType.resolveType(node, isRequired); |
| 12152 return ret; |
| 12153 } |
| 12154 ConcreteType.prototype.addDirectSubtype = function(type) { |
| 12155 this.genericType.addDirectSubtype(type); |
| 12156 } |
| 12157 ConcreteType.prototype.addDirectSubtype$1 = ConcreteType.prototype.addDirectSubt
ype; |
| 12158 ConcreteType.prototype.getConstructor$1 = ConcreteType.prototype.getConstructor; |
| 12159 ConcreteType.prototype.getFactory$2 = ConcreteType.prototype.getFactory; |
| 12160 ConcreteType.prototype.getMember$1 = ConcreteType.prototype.getMember; |
| 12161 ConcreteType.prototype.getOrMakeConcreteType$1 = ConcreteType.prototype.getOrMak
eConcreteType; |
| 12162 ConcreteType.prototype.markUsed$0 = ConcreteType.prototype.markUsed; |
| 12163 ConcreteType.prototype.resolveTypeParams$1 = ConcreteType.prototype.resolveTypeP
arams; |
| 12164 // ********** Code for DefinedType ************** |
| 12165 $inherits(DefinedType, Type); |
| 12166 function DefinedType(name, library, definition, isClass) { |
| 12167 this.isUsed = false |
| 12168 this.isNative = false |
| 12169 this.library = library; |
| 12170 this.isClass = isClass; |
| 12171 this.directSubtypes = new HashSetImplementation(); |
| 12172 this.constructors = new HashMapImplementation(); |
| 12173 this.members = new HashMapImplementation(); |
| 12174 this.factories = new FactoryMap(); |
| 12175 // Initializers done |
| 12176 Type.call(this, name); |
| 12177 this.setDefinition(definition); |
| 12178 } |
| 12179 DefinedType.prototype.get$definition = function() { return this.definition; }; |
| 12180 DefinedType.prototype.set$definition = function(value) { return this.definition
= value; }; |
| 12181 DefinedType.prototype.get$library = function() { return this.library; }; |
| 12182 DefinedType.prototype.get$isClass = function() { return this.isClass; }; |
| 12183 DefinedType.prototype.get$_parent = function() { return this._parent; }; |
| 12184 DefinedType.prototype.set$_parent = function(value) { return this._parent = valu
e; }; |
| 12185 DefinedType.prototype.get$parent = function() { |
| 12186 return this._parent; |
| 12187 } |
| 12188 DefinedType.prototype.set$parent = function(p) { |
| 12189 this._parent = p; |
| 12190 } |
| 12191 Object.defineProperty(DefinedType.prototype, "parent", { |
| 12192 get: DefinedType.prototype.get$parent, |
| 12193 set: DefinedType.prototype.set$parent |
| 12194 }); |
| 12195 DefinedType.prototype.get$interfaces = function() { return this.interfaces; }; |
| 12196 DefinedType.prototype.set$interfaces = function(value) { return this.interfaces
= value; }; |
| 12197 DefinedType.prototype.get$typeParameters = function() { return this.typeParamete
rs; }; |
| 12198 DefinedType.prototype.set$typeParameters = function(value) { return this.typePar
ameters = value; }; |
| 12199 DefinedType.prototype.get$constructors = function() { return this.constructors;
}; |
| 12200 DefinedType.prototype.set$constructors = function(value) { return this.construct
ors = value; }; |
| 12201 DefinedType.prototype.get$members = function() { return this.members; }; |
| 12202 DefinedType.prototype.set$members = function(value) { return this.members = valu
e; }; |
| 12203 DefinedType.prototype.get$factories = function() { return this.factories; }; |
| 12204 DefinedType.prototype.set$factories = function(value) { return this.factories =
value; }; |
| 12205 DefinedType.prototype.get$_concreteTypes = function() { return this._concreteTyp
es; }; |
| 12206 DefinedType.prototype.set$_concreteTypes = function(value) { return this._concre
teTypes = value; }; |
| 12207 DefinedType.prototype.get$isUsed = function() { return this.isUsed; }; |
| 12208 DefinedType.prototype.set$isUsed = function(value) { return this.isUsed = value;
}; |
| 12209 DefinedType.prototype.get$isNative = function() { return this.isNative; }; |
| 12210 DefinedType.prototype.set$isNative = function(value) { return this.isNative = va
lue; }; |
| 12211 DefinedType.prototype.setDefinition = function(def) { |
| 12212 this.definition = def; |
| 12213 if ((this.definition instanceof TypeDefinition) && this.definition.get$nativeT
ype() != null) { |
| 12214 this.isNative = true; |
| 12215 } |
| 12216 if (this.definition != null && this.definition.get$typeParameters() != null) { |
| 12217 this._concreteTypes = new HashMapImplementation(); |
| 12218 this.typeParameters = this.definition.get$typeParameters(); |
| 12219 } |
| 12220 } |
| 12221 DefinedType.prototype.get$nativeType = function() { |
| 12222 return (this.definition != null ? this.definition.get$nativeType() : null); |
| 12223 } |
| 12224 DefinedType.prototype.get$typeArgsInOrder = function() { |
| 12225 if (this.typeParameters == null) return null; |
| 12226 if (this._typeArgsInOrder == null) { |
| 12227 this._typeArgsInOrder = new FixedCollection_Type($globals.world.varType, thi
s.typeParameters.length); |
| 12228 } |
| 12229 return this._typeArgsInOrder; |
| 12230 } |
| 12231 DefinedType.prototype.get$isVar = function() { |
| 12232 return $eq(this, $globals.world.varType); |
| 12233 } |
| 12234 DefinedType.prototype.get$isVoid = function() { |
| 12235 return $eq(this, $globals.world.voidType); |
| 12236 } |
| 12237 DefinedType.prototype.get$isTop = function() { |
| 12238 return this.name == null; |
| 12239 } |
| 12240 DefinedType.prototype.get$isObject = function() { |
| 12241 return this.library.get$isCore() && this.name == 'Object'; |
| 12242 } |
| 12243 DefinedType.prototype.get$isString = function() { |
| 12244 return this.library.get$isCore() && this.name == 'String' || this.library.get$
isCoreImpl() && this.name == 'StringImplementation'; |
| 12245 } |
| 12246 DefinedType.prototype.get$isBool = function() { |
| 12247 return this.library.get$isCore() && this.name == 'bool'; |
| 12248 } |
| 12249 DefinedType.prototype.get$isFunction = function() { |
| 12250 return this.library.get$isCore() && this.name == 'Function'; |
| 12251 } |
| 12252 DefinedType.prototype.get$isList = function() { |
| 12253 return this.library.get$isCore() && this.name == 'List'; |
| 12254 } |
| 12255 DefinedType.prototype.get$isGeneric = function() { |
| 12256 return this.typeParameters != null; |
| 12257 } |
| 12258 DefinedType.prototype.get$span = function() { |
| 12259 return this.definition == null ? null : this.definition.span; |
| 12260 } |
| 12261 Object.defineProperty(DefinedType.prototype, "span", { |
| 12262 get: DefinedType.prototype.get$span |
| 12263 }); |
| 12264 DefinedType.prototype.get$typeofName = function() { |
| 12265 if (!this.library.get$isCore()) return null; |
| 12266 if (this.get$isBool()) return 'boolean'; |
| 12267 else if (this.get$isNum()) return 'number'; |
| 12268 else if (this.get$isString()) return 'string'; |
| 12269 else if (this.get$isFunction()) return 'function'; |
| 12270 else return null; |
| 12271 } |
| 12272 DefinedType.prototype.get$isNum = function() { |
| 12273 return this.library != null && this.library.get$isCore() && (this.name == 'num
' || this.name == 'int' || this.name == 'double'); |
| 12274 } |
| 12275 DefinedType.prototype.getCallMethod = function() { |
| 12276 return this.members.$index(':call'); |
| 12277 } |
| 12278 DefinedType.prototype.getAllMembers = function() { |
| 12279 return HashMapImplementation.HashMapImplementation$from$factory(this.members); |
| 12280 } |
| 12281 DefinedType.prototype.markUsed = function() { |
| 12282 if (this.isUsed) return; |
| 12283 this.isUsed = true; |
| 12284 this._checkExtends(); |
| 12285 if (this._lazyGenMethods != null) { |
| 12286 var $$list = orderValuesByKeys(this._lazyGenMethods); |
| 12287 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 12288 var method = $$list.$index($$i); |
| 12289 $globals.world.gen.genMethod(method); |
| 12290 } |
| 12291 this._lazyGenMethods = null; |
| 12292 } |
| 12293 if (this.get$parent() != null) this.get$parent().markUsed(); |
| 12294 } |
| 12295 DefinedType.prototype.genMethod = function(method) { |
| 12296 if (this.isUsed) { |
| 12297 $globals.world.gen.genMethod(method); |
| 12298 } |
| 12299 else if (this.isClass) { |
| 12300 if (this._lazyGenMethods == null) this._lazyGenMethods = new HashMapImplemen
tation(); |
| 12301 this._lazyGenMethods.$setindex(method.name, method); |
| 12302 } |
| 12303 } |
| 12304 DefinedType.prototype._resolveInterfaces = function(types) { |
| 12305 if (types == null) return []; |
| 12306 var interfaces = []; |
| 12307 for (var $$i = 0;$$i < types.length; $$i++) { |
| 12308 var type = types.$index($$i); |
| 12309 var resolvedInterface = this.resolveType(type, true); |
| 12310 if (resolvedInterface.get$isClosed() && !(this.library.get$isCore() || this.
library.get$isCoreImpl())) { |
| 12311 $globals.world.error(('can not implement "' + resolvedInterface.name + '":
') + 'only native implementation allowed', type.span); |
| 12312 } |
| 12313 resolvedInterface.addDirectSubtype$1(this); |
| 12314 interfaces.add$1(resolvedInterface); |
| 12315 } |
| 12316 return interfaces; |
| 12317 } |
| 12318 DefinedType.prototype.addDirectSubtype = function(type) { |
| 12319 this.directSubtypes.add(type); |
| 12320 } |
| 12321 DefinedType.prototype.get$subtypes = function() { |
| 12322 if (this._subtypes == null) { |
| 12323 this._subtypes = new HashSetImplementation(); |
| 12324 var $$list = this.directSubtypes; |
| 12325 for (var $$i = this.directSubtypes.iterator(); $$i.hasNext$0(); ) { |
| 12326 var st = $$i.next$0(); |
| 12327 this._subtypes.add(st); |
| 12328 this._subtypes.addAll(st.get$subtypes()); |
| 12329 } |
| 12330 } |
| 12331 return this._subtypes; |
| 12332 } |
| 12333 DefinedType.prototype._cycleInClassExtends = function() { |
| 12334 var seen = new HashSetImplementation(); |
| 12335 seen.add(this); |
| 12336 var ancestor = this.get$parent(); |
| 12337 while (ancestor != null) { |
| 12338 if (ancestor === this) { |
| 12339 return true; |
| 12340 } |
| 12341 if (seen.contains(ancestor)) { |
| 12342 return false; |
| 12343 } |
| 12344 seen.add(ancestor); |
| 12345 ancestor = ancestor.parent; |
| 12346 } |
| 12347 return false; |
| 12348 } |
| 12349 DefinedType.prototype._cycleInInterfaceExtends = function() { |
| 12350 var $this = this; // closure support |
| 12351 var seen = new HashSetImplementation(); |
| 12352 seen.add(this); |
| 12353 function _helper(ancestor) { |
| 12354 if (ancestor == null) return false; |
| 12355 if (ancestor === $this) return true; |
| 12356 if (seen.contains(ancestor)) { |
| 12357 return false; |
| 12358 } |
| 12359 seen.add(ancestor); |
| 12360 if (ancestor.get$interfaces() != null) { |
| 12361 var $$list = ancestor.get$interfaces(); |
| 12362 for (var $$i = ancestor.get$interfaces().iterator$0(); $$i.hasNext$0(); )
{ |
| 12363 var parent = $$i.next$0(); |
| 12364 if (_helper(parent)) return true; |
| 12365 } |
| 12366 } |
| 12367 return false; |
| 12368 } |
| 12369 for (var i = 0; |
| 12370 i < this.interfaces.length; i++) { |
| 12371 if (_helper(this.interfaces.$index(i))) return i; |
| 12372 } |
| 12373 return -1; |
| 12374 } |
| 12375 DefinedType.prototype.resolve = function() { |
| 12376 if ((this.definition instanceof TypeDefinition)) { |
| 12377 var typeDef = this.definition; |
| 12378 if (this.isClass) { |
| 12379 if (typeDef.extendsTypes != null && typeDef.extendsTypes.length > 0) { |
| 12380 if (typeDef.extendsTypes.length > 1) { |
| 12381 $globals.world.error('more than one base class', typeDef.extendsTypes.
$index(1).span); |
| 12382 } |
| 12383 var extendsTypeRef = typeDef.extendsTypes.$index(0); |
| 12384 if ((extendsTypeRef instanceof GenericTypeReference)) { |
| 12385 var g = extendsTypeRef; |
| 12386 this.set$parent(this.resolveType(g.baseType, true)); |
| 12387 } |
| 12388 this.set$parent(this.resolveType(extendsTypeRef, true)); |
| 12389 if (!this.get$parent().get$isClass()) { |
| 12390 $globals.world.error('class may not extend an interface - use implemen
ts', typeDef.extendsTypes.$index(0).span); |
| 12391 } |
| 12392 this.get$parent().addDirectSubtype(this); |
| 12393 if (this._cycleInClassExtends()) { |
| 12394 $globals.world.error(('class "' + this.name + '" has a cycle in its in
heritance chain'), extendsTypeRef.span); |
| 12395 } |
| 12396 } |
| 12397 else { |
| 12398 if (!this.get$isObject()) { |
| 12399 this.set$parent($globals.world.objectType); |
| 12400 this.get$parent().addDirectSubtype(this); |
| 12401 } |
| 12402 } |
| 12403 this.interfaces = this._resolveInterfaces(typeDef.implementsTypes); |
| 12404 if (typeDef.factoryType != null) { |
| 12405 $globals.world.error('factory not allowed on classes', typeDef.factoryTy
pe.span); |
| 12406 } |
| 12407 } |
| 12408 else { |
| 12409 if (typeDef.implementsTypes != null && typeDef.implementsTypes.length > 0)
{ |
| 12410 $globals.world.error('implements not allowed on interfaces (use extends)
', typeDef.implementsTypes.$index(0).span); |
| 12411 } |
| 12412 this.interfaces = this._resolveInterfaces(typeDef.extendsTypes); |
| 12413 var res = this._cycleInInterfaceExtends(); |
| 12414 if (res >= 0) { |
| 12415 $globals.world.error(('interface "' + this.name + '" has a cycle in its
inheritance chain'), typeDef.extendsTypes.$index(res).span); |
| 12416 } |
| 12417 if (typeDef.factoryType != null) { |
| 12418 this.factory_ = this.resolveType(typeDef.factoryType, true); |
| 12419 if (this.factory_ == null) { |
| 12420 $globals.world.warning('unresolved factory', typeDef.factoryType.span)
; |
| 12421 } |
| 12422 } |
| 12423 } |
| 12424 } |
| 12425 else if ((this.definition instanceof FunctionTypeDefinition)) { |
| 12426 this.interfaces = [$globals.world.functionType]; |
| 12427 } |
| 12428 if (this.typeParameters != null) { |
| 12429 var $$list = this.typeParameters; |
| 12430 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 12431 var tp = $$list.$index($$i); |
| 12432 tp.set$enclosingElement(this); |
| 12433 tp.resolve$0(); |
| 12434 } |
| 12435 } |
| 12436 if (this.get$isObject()) this._createNotEqualMember(); |
| 12437 $globals.world._addType(this); |
| 12438 var $$list = this.constructors.getValues(); |
| 12439 for (var $$i = this.constructors.getValues().iterator$0(); $$i.hasNext$0(); )
{ |
| 12440 var c = $$i.next$0(); |
| 12441 c.resolve$0(); |
| 12442 } |
| 12443 var $list0 = this.members.getValues(); |
| 12444 for (var $$i = this.members.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 12445 var m = $$i.next$0(); |
| 12446 m.resolve$0(); |
| 12447 } |
| 12448 this.factories.forEach((function (f) { |
| 12449 return f.resolve$0(); |
| 12450 }) |
| 12451 ); |
| 12452 if (this.get$isJsGlobalObject()) { |
| 12453 var $list1 = this.members.getValues(); |
| 12454 for (var $$i = this.members.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 12455 var m0 = $$i.next$0(); |
| 12456 if (!m0.get$isStatic()) $globals.world._addTopName(m0); |
| 12457 } |
| 12458 } |
| 12459 } |
| 12460 DefinedType.prototype.addMethod = function(methodName, definition) { |
| 12461 if (methodName == null) methodName = definition.name.name; |
| 12462 var method = new MethodMember(methodName, this, definition); |
| 12463 if (method.get$isConstructor()) { |
| 12464 if (this.constructors.containsKey(method.get$constructorName())) { |
| 12465 $globals.world.error(('duplicate constructor definition of ' + method.name
), definition.span); |
| 12466 return; |
| 12467 } |
| 12468 this.constructors.$setindex(method.get$constructorName(), method); |
| 12469 return; |
| 12470 } |
| 12471 if (definition.modifiers != null && definition.modifiers.length == 1 && $eq(de
finition.modifiers.$index(0).kind, 75/*TokenKind.FACTORY*/)) { |
| 12472 if (this.factories.getFactory(method.get$constructorName(), method.name) !=
null) { |
| 12473 $globals.world.error(('duplicate factory definition of "' + method.name +
'"'), definition.span); |
| 12474 return; |
| 12475 } |
| 12476 this.factories.addFactory(method.get$constructorName(), method.name, method)
; |
| 12477 return; |
| 12478 } |
| 12479 if (methodName.startsWith('get:') || methodName.startsWith('set:')) { |
| 12480 var propName = methodName.substring(4); |
| 12481 var prop = this.members.$index(propName); |
| 12482 if (prop == null) { |
| 12483 prop = new PropertyMember(propName, this); |
| 12484 this.members.$setindex(propName, prop); |
| 12485 } |
| 12486 if (!(prop instanceof PropertyMember)) { |
| 12487 $globals.world.error(('property conflicts with field "' + propName + '"'),
definition.span); |
| 12488 return; |
| 12489 } |
| 12490 if (methodName[0] == 'g') { |
| 12491 if (prop.get$getter() != null) { |
| 12492 $globals.world.error(('duplicate getter definition for "' + propName + '
"'), definition.span); |
| 12493 } |
| 12494 prop.set$getter(method); |
| 12495 } |
| 12496 else { |
| 12497 if (prop.get$setter() != null) { |
| 12498 $globals.world.error(('duplicate setter definition for "' + propName + '
"'), definition.span); |
| 12499 } |
| 12500 prop.set$setter(method); |
| 12501 } |
| 12502 return; |
| 12503 } |
| 12504 if (this.members.containsKey(methodName)) { |
| 12505 $globals.world.error(('duplicate method definition of "' + method.name + '"'
), definition.span); |
| 12506 return; |
| 12507 } |
| 12508 this.members.$setindex(methodName, method); |
| 12509 } |
| 12510 DefinedType.prototype.addField = function(definition) { |
| 12511 for (var i = 0; |
| 12512 i < definition.names.length; i++) { |
| 12513 var name = definition.names.$index(i).name; |
| 12514 if (this.members.containsKey(name)) { |
| 12515 $globals.world.error(('duplicate field definition of "' + name + '"'), def
inition.span); |
| 12516 return; |
| 12517 } |
| 12518 var value = null; |
| 12519 if (definition.values != null) { |
| 12520 value = definition.values.$index(i); |
| 12521 } |
| 12522 var field = new FieldMember(name, this, definition, value); |
| 12523 this.members.$setindex(name, field); |
| 12524 if (this.isNative) { |
| 12525 field.set$isNative(true); |
| 12526 } |
| 12527 } |
| 12528 } |
| 12529 DefinedType.prototype.getFactory = function(type, constructorName) { |
| 12530 var ret = this.factories.getFactory(type.name, constructorName); |
| 12531 if (ret != null) return ret; |
| 12532 ret = this.factories.getFactory(this.name, constructorName); |
| 12533 if (ret != null) return ret; |
| 12534 ret = this.constructors.$index(constructorName); |
| 12535 if (ret != null) return ret; |
| 12536 return this._tryCreateDefaultConstructor(constructorName); |
| 12537 } |
| 12538 DefinedType.prototype.getConstructor = function(constructorName) { |
| 12539 var ret = this.constructors.$index(constructorName); |
| 12540 if (ret != null) { |
| 12541 if (this.factory_ != null) { |
| 12542 return this.factory_.getFactory(this, constructorName); |
| 12543 } |
| 12544 return ret; |
| 12545 } |
| 12546 ret = this.factories.getFactory(this.name, constructorName); |
| 12547 if (ret != null) return ret; |
| 12548 return this._tryCreateDefaultConstructor(constructorName); |
| 12549 } |
| 12550 DefinedType.prototype._tryCreateDefaultConstructor = function(name) { |
| 12551 if (name == '' && this.definition != null && this.isClass && this.constructors
.get$length() == 0) { |
| 12552 var span = this.definition.span; |
| 12553 var inits = null, native_ = null, body = null; |
| 12554 if (this.isNative) { |
| 12555 native_ = ''; |
| 12556 inits = null; |
| 12557 } |
| 12558 else { |
| 12559 body = null; |
| 12560 inits = [new CallExpression(new SuperExpression(span), [], span)]; |
| 12561 } |
| 12562 var typeDef = this.definition; |
| 12563 var c = new FunctionDefinition(null, null, typeDef.name, [], null, inits, na
tive_, body, span); |
| 12564 this.addMethod(null, c); |
| 12565 this.constructors.$index('').resolve$0(); |
| 12566 return this.constructors.$index(''); |
| 12567 } |
| 12568 return null; |
| 12569 } |
| 12570 DefinedType.prototype.getMember = function(memberName) { |
| 12571 var member = this.members.$index(memberName); |
| 12572 if (member != null) { |
| 12573 this._checkOverride(member); |
| 12574 return member; |
| 12575 } |
| 12576 if (this.get$isTop()) { |
| 12577 var libType = this.library.findTypeByName(memberName); |
| 12578 if (libType != null) { |
| 12579 return libType.get$typeMember(); |
| 12580 } |
| 12581 } |
| 12582 return this._getMemberInParents(memberName); |
| 12583 } |
| 12584 DefinedType.prototype.resolveTypeParams = function(inType) { |
| 12585 return this; |
| 12586 } |
| 12587 DefinedType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 12588 var jsnames = []; |
| 12589 var names = []; |
| 12590 var typeMap = new HashMapImplementation(); |
| 12591 for (var i = 0; |
| 12592 i < typeArgs.length; i++) { |
| 12593 var paramName = this.typeParameters.$index(i).name; |
| 12594 typeMap.$setindex(paramName, typeArgs.$index(i)); |
| 12595 names.add$1(typeArgs.$index(i).name); |
| 12596 jsnames.add$1(typeArgs.$index(i).get$jsname()); |
| 12597 } |
| 12598 var jsname = ('' + this.get$jsname() + '_' + Strings.join(jsnames, '\$')); |
| 12599 var simpleName = ('' + this.name + '<' + Strings.join(names, ', ') + '>'); |
| 12600 var key = Strings.join(names, '\$'); |
| 12601 var ret = this._concreteTypes.$index(key); |
| 12602 if (ret == null) { |
| 12603 ret = new ConcreteType(simpleName, this, typeMap, typeArgs); |
| 12604 ret.set$_jsname(jsname); |
| 12605 this._concreteTypes.$setindex(key, ret); |
| 12606 } |
| 12607 return ret; |
| 12608 } |
| 12609 DefinedType.prototype.getCallStub = function(args) { |
| 12610 var name = _getCallStubName('call', args); |
| 12611 var stub = this.varStubs.$index(name); |
| 12612 if (stub == null) { |
| 12613 stub = new VarFunctionStub(name, args); |
| 12614 this.varStubs.$setindex(name, stub); |
| 12615 } |
| 12616 return stub; |
| 12617 } |
| 12618 DefinedType.prototype.addDirectSubtype$1 = DefinedType.prototype.addDirectSubtyp
e; |
| 12619 DefinedType.prototype.addMethod$2 = DefinedType.prototype.addMethod; |
| 12620 DefinedType.prototype.getConstructor$1 = DefinedType.prototype.getConstructor; |
| 12621 DefinedType.prototype.getFactory$2 = DefinedType.prototype.getFactory; |
| 12622 DefinedType.prototype.getMember$1 = DefinedType.prototype.getMember; |
| 12623 DefinedType.prototype.getOrMakeConcreteType$1 = DefinedType.prototype.getOrMakeC
oncreteType; |
| 12624 DefinedType.prototype.markUsed$0 = DefinedType.prototype.markUsed; |
| 12625 DefinedType.prototype.resolve$0 = DefinedType.prototype.resolve; |
| 12626 DefinedType.prototype.resolveTypeParams$1 = DefinedType.prototype.resolveTypePar
ams; |
| 12627 DefinedType.prototype.setDefinition$1 = DefinedType.prototype.setDefinition; |
| 12628 // ********** Code for NativeType ************** |
| 12629 function NativeType(name) { |
| 12630 this.isConstructorHidden = false |
| 12631 this.isJsGlobalObject = false |
| 12632 this.isSingleton = false |
| 12633 this.name = name; |
| 12634 // Initializers done |
| 12635 while (true) { |
| 12636 if (this.name.startsWith('@')) { |
| 12637 this.name = this.name.substring(1); |
| 12638 this.isJsGlobalObject = true; |
| 12639 } |
| 12640 else if (this.name.startsWith('*')) { |
| 12641 this.name = this.name.substring(1); |
| 12642 this.isConstructorHidden = true; |
| 12643 } |
| 12644 else { |
| 12645 break; |
| 12646 } |
| 12647 } |
| 12648 if (this.name.startsWith('=')) { |
| 12649 this.name = this.name.substring(1); |
| 12650 this.isSingleton = true; |
| 12651 } |
| 12652 } |
| 12653 // ********** Code for FixedCollection ************** |
| 12654 function FixedCollection(value, length) { |
| 12655 this.value = value; |
| 12656 this.length = length; |
| 12657 // Initializers done |
| 12658 } |
| 12659 FixedCollection.prototype.iterator = function() { |
| 12660 return new FixedIterator_E(this.value, this.length); |
| 12661 } |
| 12662 FixedCollection.prototype.forEach = function(f) { |
| 12663 Collections.forEach(this, f); |
| 12664 } |
| 12665 FixedCollection.prototype.filter = function(f) { |
| 12666 return Collections.filter(this, new ListFactory(), f); |
| 12667 } |
| 12668 FixedCollection.prototype.every = function(f) { |
| 12669 return Collections.every(this, f); |
| 12670 } |
| 12671 FixedCollection.prototype.some = function(f) { |
| 12672 return Collections.some(this, f); |
| 12673 } |
| 12674 FixedCollection.prototype.isEmpty = function() { |
| 12675 return this.length == 0; |
| 12676 } |
| 12677 FixedCollection.prototype.every$1 = function($0) { |
| 12678 return this.every(to$call$1($0)); |
| 12679 }; |
| 12680 FixedCollection.prototype.filter$1 = function($0) { |
| 12681 return this.filter(to$call$1($0)); |
| 12682 }; |
| 12683 FixedCollection.prototype.forEach$1 = function($0) { |
| 12684 return this.forEach(to$call$1($0)); |
| 12685 }; |
| 12686 FixedCollection.prototype.isEmpty$0 = FixedCollection.prototype.isEmpty; |
| 12687 FixedCollection.prototype.iterator$0 = FixedCollection.prototype.iterator; |
| 12688 FixedCollection.prototype.some$1 = function($0) { |
| 12689 return this.some(to$call$1($0)); |
| 12690 }; |
| 12691 // ********** Code for FixedCollection_Type ************** |
| 12692 $inherits(FixedCollection_Type, FixedCollection); |
| 12693 function FixedCollection_Type(value, length) { |
| 12694 this.value = value; |
| 12695 this.length = length; |
| 12696 // Initializers done |
| 12697 } |
| 12698 // ********** Code for FixedIterator ************** |
| 12699 function FixedIterator(value, length) { |
| 12700 this._index = 0 |
| 12701 this.value = value; |
| 12702 this.length = length; |
| 12703 // Initializers done |
| 12704 } |
| 12705 FixedIterator.prototype.hasNext = function() { |
| 12706 return this._index < this.length; |
| 12707 } |
| 12708 FixedIterator.prototype.next = function() { |
| 12709 this._index++; |
| 12710 return this.value; |
| 12711 } |
| 12712 FixedIterator.prototype.hasNext$0 = FixedIterator.prototype.hasNext; |
| 12713 FixedIterator.prototype.next$0 = FixedIterator.prototype.next; |
| 12714 // ********** Code for FixedIterator_E ************** |
| 12715 $inherits(FixedIterator_E, FixedIterator); |
| 12716 function FixedIterator_E(value, length) { |
| 12717 this._index = 0 |
| 12718 this.value = value; |
| 12719 this.length = length; |
| 12720 // Initializers done |
| 12721 } |
| 12722 // ********** Code for Value ************** |
| 12723 function Value(_type, code, span, needsTemp) { |
| 12724 this.isSuper = false |
| 12725 this.isType = false |
| 12726 this.isFinal = false |
| 12727 this.allowDynamic = true |
| 12728 this._type = _type; |
| 12729 this.code = code; |
| 12730 this.span = span; |
| 12731 this.needsTemp = needsTemp; |
| 12732 // Initializers done |
| 12733 if (this._type == null) $globals.world.internalError('type passed as null', th
is.span); |
| 12734 } |
| 12735 Value.type$ctor = function(_type, span) { |
| 12736 this.isSuper = false |
| 12737 this.isType = false |
| 12738 this.isFinal = false |
| 12739 this.allowDynamic = true |
| 12740 this._type = _type; |
| 12741 this.span = span; |
| 12742 this.code = null; |
| 12743 this.needsTemp = false; |
| 12744 this.isType = true; |
| 12745 // Initializers done |
| 12746 if (this._type == null) $globals.world.internalError('type passed as null', th
is.span); |
| 12747 } |
| 12748 Value.type$ctor.prototype = Value.prototype; |
| 12749 Value.prototype.get$isSuper = function() { return this.isSuper; }; |
| 12750 Value.prototype.set$isSuper = function(value) { return this.isSuper = value; }; |
| 12751 Value.prototype.get$isType = function() { return this.isType; }; |
| 12752 Value.prototype.set$isType = function(value) { return this.isType = value; }; |
| 12753 Value.prototype.get$isFinal = function() { return this.isFinal; }; |
| 12754 Value.prototype.set$isFinal = function(value) { return this.isFinal = value; }; |
| 12755 Value.prototype.get$allowDynamic = function() { return this.allowDynamic; }; |
| 12756 Value.prototype.set$allowDynamic = function(value) { return this.allowDynamic =
value; }; |
| 12757 Value.prototype.get$needsTemp = function() { return this.needsTemp; }; |
| 12758 Value.prototype.set$needsTemp = function(value) { return this.needsTemp = value;
}; |
| 12759 Value.prototype.get$_typeIsVarOrParameterType = function() { |
| 12760 return this.get$type().get$isVar() || (this.get$type() instanceof ParameterTyp
e); |
| 12761 } |
| 12762 Value.prototype.get$type = function() { |
| 12763 if (!$globals.options.forceDynamic || !this.allowDynamic || this.isType || thi
s.isSuper || this.get$isConst()) { |
| 12764 return this._type; |
| 12765 } |
| 12766 else { |
| 12767 return $globals.world.varType; |
| 12768 } |
| 12769 } |
| 12770 Object.defineProperty(Value.prototype, "type", { |
| 12771 get: Value.prototype.get$type |
| 12772 }); |
| 12773 Value.prototype.get$isConst = function() { |
| 12774 return false; |
| 12775 } |
| 12776 Value.prototype.get$canonicalCode = function() { |
| 12777 return null; |
| 12778 } |
| 12779 Value.prototype.get_ = function(context, name, node) { |
| 12780 var member = this._resolveMember(context, name, node, false); |
| 12781 if (member != null) { |
| 12782 return member._get$3(context, node, this); |
| 12783 } |
| 12784 else { |
| 12785 return this.invokeNoSuchMethod(context, ('get:' + name), node); |
| 12786 } |
| 12787 } |
| 12788 Value.prototype.set_ = function(context, name, node, value, isDynamic) { |
| 12789 var member = this._resolveMember(context, name, node, isDynamic); |
| 12790 if (member != null) { |
| 12791 return member._set$5(context, node, this, value, isDynamic); |
| 12792 } |
| 12793 else { |
| 12794 return this.invokeNoSuchMethod(context, ('set:' + name), node, new Arguments
(null, [value])); |
| 12795 } |
| 12796 } |
| 12797 Value.prototype.invoke = function(context, name, node, args, isDynamic) { |
| 12798 if (name == ':call') { |
| 12799 if (this.isType) { |
| 12800 $globals.world.error('must use "new" or "const" to construct a new instanc
e', node.span); |
| 12801 } |
| 12802 if (this.get$type().needsVarCall(args)) { |
| 12803 return this._varCall(context, args); |
| 12804 } |
| 12805 } |
| 12806 var member = this._resolveMember(context, name, node, isDynamic); |
| 12807 if (member == null) { |
| 12808 return this.invokeNoSuchMethod(context, name, node, args); |
| 12809 } |
| 12810 else { |
| 12811 return member.invoke$5(context, node, this, args, isDynamic); |
| 12812 } |
| 12813 } |
| 12814 Value.prototype.canInvoke = function(context, name, args) { |
| 12815 if (this.get$type().get$isVarOrFunction() && name == ':call') { |
| 12816 return true; |
| 12817 } |
| 12818 var member = this._resolveMember(context, name, null, true); |
| 12819 return member != null && member.canInvoke$2(context, args); |
| 12820 } |
| 12821 Value.prototype._hasOverriddenNoSuchMethod = function() { |
| 12822 if (this.isSuper) { |
| 12823 var m = this.get$type().getMember('noSuchMethod'); |
| 12824 return m != null && !m.get$declaringType().get$isObject(); |
| 12825 } |
| 12826 else { |
| 12827 var m = this.get$type().resolveMember('noSuchMethod'); |
| 12828 return m != null && m.get$members().length > 1; |
| 12829 } |
| 12830 } |
| 12831 Value.prototype._tryResolveMember = function(context, name) { |
| 12832 if (this.isSuper) { |
| 12833 return this.get$type().getMember(name); |
| 12834 } |
| 12835 else { |
| 12836 return this.get$type().resolveMember(name); |
| 12837 } |
| 12838 } |
| 12839 Value.prototype._resolveMember = function(context, name, node, isDynamic) { |
| 12840 var member; |
| 12841 if (!this.get$_typeIsVarOrParameterType()) { |
| 12842 member = this._tryResolveMember(context, name); |
| 12843 if (member != null && this.isType && !member.get$isStatic()) { |
| 12844 if (!isDynamic) { |
| 12845 $globals.world.error('can not refer to instance member as static', node.
span); |
| 12846 } |
| 12847 return null; |
| 12848 } |
| 12849 if (member == null && !isDynamic && !this._hasOverriddenNoSuchMethod()) { |
| 12850 var typeName = this.get$type().name == null ? this.get$type().get$library(
).name : this.get$type().name; |
| 12851 var message = ('can not resolve "' + name + '" on "' + typeName + '"'); |
| 12852 if (this.isType) { |
| 12853 $globals.world.error(message, node.span); |
| 12854 } |
| 12855 else { |
| 12856 $globals.world.warning(message, node.span); |
| 12857 } |
| 12858 } |
| 12859 } |
| 12860 if (member == null && !this.isSuper && !this.isType) { |
| 12861 member = context.findMembers(name); |
| 12862 if (member == null && !isDynamic) { |
| 12863 var where = 'the world'; |
| 12864 if (name.startsWith('_')) { |
| 12865 where = ('library "' + context.get$library().name + '"'); |
| 12866 } |
| 12867 $globals.world.warning(('' + name + ' is not defined anywhere in ' + where
+ '.'), node.span); |
| 12868 } |
| 12869 } |
| 12870 return member; |
| 12871 } |
| 12872 Value.prototype.checkFirstClass = function(span) { |
| 12873 if (this.isType) { |
| 12874 $globals.world.error('Types are not first class', span); |
| 12875 } |
| 12876 } |
| 12877 Value.prototype._varCall = function(context, args) { |
| 12878 var stub = $globals.world.functionType.getCallStub(args); |
| 12879 return new Value($globals.world.varType, ('' + this.code + '.' + stub.name + '
(' + args.getCode() + ')'), this.span, true); |
| 12880 } |
| 12881 Value.prototype.needsConversion = function(toType) { |
| 12882 var callMethod = toType.getCallMethod(); |
| 12883 if (callMethod != null) { |
| 12884 var arity = callMethod.get$parameters().length; |
| 12885 var myCall = this.get$type().getCallMethod(); |
| 12886 if (myCall == null || $ne(myCall.get$parameters().length, arity)) { |
| 12887 return true; |
| 12888 } |
| 12889 } |
| 12890 if ($globals.options.enableTypeChecks) { |
| 12891 var fromType = this.get$type(); |
| 12892 if (this.get$type().get$isVar() && (this.code != 'null' || !toType.get$isNul
lable())) { |
| 12893 fromType = $globals.world.objectType; |
| 12894 } |
| 12895 var bothNum = this.get$type().get$isNum() && toType.get$isNum(); |
| 12896 return !(fromType.isSubtypeOf(toType) || bothNum); |
| 12897 } |
| 12898 return false; |
| 12899 } |
| 12900 Value.prototype.convertTo = function(context, toType, node, isDynamic) { |
| 12901 var checked = !isDynamic; |
| 12902 var callMethod = toType.getCallMethod(); |
| 12903 if (callMethod != null) { |
| 12904 if (checked && !toType.isAssignable(this.get$type())) { |
| 12905 this.convertWarning(toType, node); |
| 12906 } |
| 12907 var arity = callMethod.get$parameters().length; |
| 12908 var myCall = this.get$type().getCallMethod(); |
| 12909 if (myCall == null || $ne(myCall.get$parameters().length, arity)) { |
| 12910 var stub = $globals.world.functionType.getCallStub(Arguments.Arguments$bar
e$factory(arity)); |
| 12911 var val = new Value(toType, ('to\$' + stub.name + '(' + this.code + ')'),
node.span, true); |
| 12912 return this._isDomCallback(toType) && !this._isDomCallback(this.get$type()
) ? val._wrapDomCallback$2(toType, arity) : val; |
| 12913 } |
| 12914 else if (this._isDomCallback(toType) && !this._isDomCallback(this.get$type()
)) { |
| 12915 return this._wrapDomCallback(toType, arity); |
| 12916 } |
| 12917 } |
| 12918 var fromType = this.get$type(); |
| 12919 if (this.get$type().get$isVar() && (this.code != 'null' || !toType.get$isNulla
ble())) { |
| 12920 fromType = $globals.world.objectType; |
| 12921 } |
| 12922 var bothNum = this.get$type().get$isNum() && toType.get$isNum(); |
| 12923 if (fromType.isSubtypeOf(toType) || bothNum) { |
| 12924 return this; |
| 12925 } |
| 12926 if (checked && !toType.isSubtypeOf(this.get$type())) { |
| 12927 this.convertWarning(toType, node); |
| 12928 } |
| 12929 if ($globals.options.enableTypeChecks) { |
| 12930 return this._typeAssert(context, toType, node, isDynamic); |
| 12931 } |
| 12932 else { |
| 12933 return this; |
| 12934 } |
| 12935 } |
| 12936 Value.prototype._isDomCallback = function(toType) { |
| 12937 return ((toType.get$definition() instanceof FunctionTypeDefinition) && $eq(toT
ype.get$library(), $globals.world.get$dom())); |
| 12938 } |
| 12939 Value.prototype._wrapDomCallback = function(toType, arity) { |
| 12940 if (arity == 0) { |
| 12941 $globals.world.gen.corejs.useWrap0 = true; |
| 12942 } |
| 12943 else { |
| 12944 $globals.world.gen.corejs.useWrap1 = true; |
| 12945 } |
| 12946 return new Value(toType, ('\$wrap_call\$' + arity + '(' + this.code + ')'), th
is.span, true); |
| 12947 } |
| 12948 Value.prototype._typeAssert = function(context, toType, node, isDynamic) { |
| 12949 if ((toType instanceof ParameterType)) { |
| 12950 var p = toType; |
| 12951 toType = p.extendsType; |
| 12952 } |
| 12953 if (toType.get$isObject() || toType.get$isVar()) { |
| 12954 $globals.world.internalError(('We thought ' + this.get$type().name + ' is no
t a subtype of ' + toType.name + '?')); |
| 12955 } |
| 12956 function throwTypeError(paramName) { |
| 12957 return $globals.world.withoutForceDynamic((function () { |
| 12958 var typeError = $globals.world.corelib.types.$index('TypeError'); |
| 12959 var typeErrorCtor = typeError.getConstructor$1('_internal'); |
| 12960 $globals.world.gen.corejs.ensureTypeNameOf(); |
| 12961 var result = typeErrorCtor.invoke$5(context, node, new Value.type$ctor(typ
eError, null), new Arguments(null, [new Value($globals.world.objectType, paramNa
me, null, true), new Value($globals.world.stringType, ('"' + toType.name + '"'),
null, true)]), isDynamic); |
| 12962 $globals.world.gen.corejs.useThrow = true; |
| 12963 return ('\$throw(' + result.code + ')'); |
| 12964 }) |
| 12965 ); |
| 12966 } |
| 12967 if (toType.get$isNum()) toType = $globals.world.numType; |
| 12968 var check; |
| 12969 if (toType.get$isVoid()) { |
| 12970 check = ('\$assert_void(' + this.code + ')'); |
| 12971 if (toType.typeCheckCode == null) { |
| 12972 toType.typeCheckCode = ("function $assert_void(x) {\n if (x == null) retu
rn null;\n " + throwTypeError("x") + "\n}"); |
| 12973 } |
| 12974 } |
| 12975 else if ($eq(toType, $globals.world.nonNullBool)) { |
| 12976 $globals.world.gen.corejs.useNotNullBool = true; |
| 12977 check = ('\$notnull_bool(' + this.code + ')'); |
| 12978 } |
| 12979 else if (toType.get$library().get$isCore() && toType.get$typeofName() != null)
{ |
| 12980 check = ('\$assert_' + toType.name + '(' + this.code + ')'); |
| 12981 if (toType.typeCheckCode == null) { |
| 12982 toType.typeCheckCode = ("function $assert_" + toType.name + "(x) {\n if (
x == null || typeof(x) == \"" + toType.get$typeofName() + "\") return x;\n " +
throwTypeError("x") + "\n}"); |
| 12983 } |
| 12984 } |
| 12985 else { |
| 12986 toType.isChecked = true; |
| 12987 var checkName = 'assert\$' + toType.get$jsname(); |
| 12988 var temp = context.getTemp(this); |
| 12989 check = ('(' + context.assignTemp(temp, this).code + ' == null ? null :'); |
| 12990 check = check + (' ' + temp.code + '.' + checkName + '())'); |
| 12991 if ($ne(this, temp)) context.freeTemp(temp); |
| 12992 if (!$globals.world.objectType.varStubs.containsKey(checkName)) { |
| 12993 $globals.world.objectType.varStubs.$setindex(checkName, new VarMethodStub(
checkName, null, Arguments.get$EMPTY(), throwTypeError('this'))); |
| 12994 } |
| 12995 } |
| 12996 return new Value(toType, check, this.span, true); |
| 12997 } |
| 12998 Value.prototype.instanceOf = function(context, toType, span, isTrue, forceCheck)
{ |
| 12999 if (toType.get$isVar()) { |
| 13000 $globals.world.error('can not resolve type', span); |
| 13001 } |
| 13002 var testCode = null; |
| 13003 if (toType.get$isVar() || toType.get$isObject() || (toType instanceof Paramete
rType)) { |
| 13004 if (this.needsTemp) { |
| 13005 return new Value($globals.world.nonNullBool, ('(' + this.code + ', true)')
, span, true); |
| 13006 } |
| 13007 else { |
| 13008 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, t
rue, 'true', null); |
| 13009 } |
| 13010 } |
| 13011 if (toType.get$library().get$isCore()) { |
| 13012 var typeofName = toType.get$typeofName(); |
| 13013 if (typeofName != null) { |
| 13014 testCode = ("(typeof(" + this.code + ") " + (isTrue ? '==' : '!=') + " '"
+ typeofName + "')"); |
| 13015 } |
| 13016 } |
| 13017 if (toType.get$isClass() && !(toType instanceof ConcreteType) && !toType.get$i
sHiddenNativeType()) { |
| 13018 toType.markUsed(); |
| 13019 testCode = ('(' + this.code + ' instanceof ' + toType.get$jsname() + ')'); |
| 13020 if (!isTrue) { |
| 13021 testCode = '!' + testCode; |
| 13022 } |
| 13023 } |
| 13024 if (testCode == null) { |
| 13025 toType.isTested = true; |
| 13026 var temp = context.getTemp(this); |
| 13027 var checkName = ('is\$' + toType.get$jsname()); |
| 13028 testCode = ('(' + context.assignTemp(temp, this).code + ' &&'); |
| 13029 testCode = testCode + (' ' + temp.code + '.' + checkName + '())'); |
| 13030 if (isTrue) { |
| 13031 testCode = '!!' + testCode; |
| 13032 } |
| 13033 else { |
| 13034 testCode = '!' + testCode; |
| 13035 } |
| 13036 if ($ne(this, temp)) context.freeTemp(temp); |
| 13037 if (!$globals.world.objectType.varStubs.containsKey(checkName)) { |
| 13038 $globals.world.objectType.varStubs.$setindex(checkName, new VarMethodStub(
checkName, null, Arguments.get$EMPTY(), 'return false')); |
| 13039 } |
| 13040 } |
| 13041 return new Value($globals.world.nonNullBool, testCode, span, true); |
| 13042 } |
| 13043 Value.prototype.convertWarning = function(toType, node) { |
| 13044 $globals.world.warning(('type "' + this.get$type().name + '" is not assignable
to "' + toType.name + '"'), node.span); |
| 13045 } |
| 13046 Value.prototype.invokeNoSuchMethod = function(context, name, node, args) { |
| 13047 var pos = ''; |
| 13048 if (args != null) { |
| 13049 var argsCode = []; |
| 13050 for (var i = 0; |
| 13051 i < args.get$length(); i++) { |
| 13052 argsCode.add$1(args.values.$index(i).code); |
| 13053 } |
| 13054 pos = Strings.join(argsCode, ", "); |
| 13055 } |
| 13056 var noSuchArgs = [new Value($globals.world.stringType, ('"' + name + '"'), nod
e.span, true), new Value($globals.world.listType, ('[' + pos + ']'), node.span,
true)]; |
| 13057 return this._resolveMember(context, 'noSuchMethod', node, false).invoke$4(cont
ext, node, this, new Arguments(null, noSuchArgs)); |
| 13058 } |
| 13059 Value.prototype._wrapDomCallback$2 = Value.prototype._wrapDomCallback; |
| 13060 Value.prototype.checkFirstClass$1 = Value.prototype.checkFirstClass; |
| 13061 Value.prototype.convertTo$3 = function($0, $1, $2) { |
| 13062 return this.convertTo($0, $1, $2, false); |
| 13063 }; |
| 13064 Value.prototype.convertTo$4 = Value.prototype.convertTo; |
| 13065 Value.prototype.get_$3 = Value.prototype.get_; |
| 13066 Value.prototype.instanceOf$3$isTrue$forceCheck = Value.prototype.instanceOf; |
| 13067 Value.prototype.instanceOf$4 = function($0, $1, $2, $3) { |
| 13068 return this.instanceOf($0, $1, $2, $3, false); |
| 13069 }; |
| 13070 Value.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 13071 return this.invoke($0, $1, $2, $3, false); |
| 13072 }; |
| 13073 Value.prototype.invoke$4$isDynamic = Value.prototype.invoke; |
| 13074 Value.prototype.invoke$5 = Value.prototype.invoke; |
| 13075 Value.prototype.needsConversion$1 = Value.prototype.needsConversion; |
| 13076 Value.prototype.set_$4 = function($0, $1, $2, $3) { |
| 13077 return this.set_($0, $1, $2, $3, false); |
| 13078 }; |
| 13079 // ********** Code for EvaluatedValue ************** |
| 13080 $inherits(EvaluatedValue, Value); |
| 13081 function EvaluatedValue() {} |
| 13082 EvaluatedValue._internal$ctor = function(type, actualValue, canonicalCode, span,
code) { |
| 13083 this.actualValue = actualValue; |
| 13084 this.canonicalCode = canonicalCode; |
| 13085 // Initializers done |
| 13086 Value.call(this, type, code, span, false); |
| 13087 } |
| 13088 EvaluatedValue._internal$ctor.prototype = EvaluatedValue.prototype; |
| 13089 EvaluatedValue.EvaluatedValue$factory = function(type, actualValue, canonicalCod
e, span) { |
| 13090 return new EvaluatedValue._internal$ctor(type, actualValue, canonicalCode, spa
n, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 13091 } |
| 13092 EvaluatedValue.prototype.get$actualValue = function() { return this.actualValue;
}; |
| 13093 EvaluatedValue.prototype.set$actualValue = function(value) { return this.actualV
alue = value; }; |
| 13094 EvaluatedValue.prototype.get$isConst = function() { |
| 13095 return true; |
| 13096 } |
| 13097 EvaluatedValue.prototype.get$canonicalCode = function() { return this.canonicalC
ode; }; |
| 13098 EvaluatedValue.prototype.set$canonicalCode = function(value) { return this.canon
icalCode = value; }; |
| 13099 EvaluatedValue.codeWithComments = function(canonicalCode, span) { |
| 13100 return (span != null && span.get$text() != canonicalCode) ? ('' + canonicalCod
e + '/*' + _escapeForComment(span.get$text()) + '*/') : canonicalCode; |
| 13101 } |
| 13102 // ********** Code for ConstListValue ************** |
| 13103 $inherits(ConstListValue, EvaluatedValue); |
| 13104 function ConstListValue() {} |
| 13105 ConstListValue._internal$ctor = function(type, values, actualValue, canonicalCod
e, span, code) { |
| 13106 this.values = values; |
| 13107 // Initializers done |
| 13108 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 13109 } |
| 13110 ConstListValue._internal$ctor.prototype = ConstListValue.prototype; |
| 13111 ConstListValue.ConstListValue$factory = function(type, values, actualValue, cano
nicalCode, span) { |
| 13112 return new ConstListValue._internal$ctor(type, values, actualValue, canonicalC
ode, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 13113 } |
| 13114 // ********** Code for ConstMapValue ************** |
| 13115 $inherits(ConstMapValue, EvaluatedValue); |
| 13116 function ConstMapValue() {} |
| 13117 ConstMapValue._internal$ctor = function(type, values, actualValue, canonicalCode
, span, code) { |
| 13118 this.values = values; |
| 13119 // Initializers done |
| 13120 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 13121 } |
| 13122 ConstMapValue._internal$ctor.prototype = ConstMapValue.prototype; |
| 13123 ConstMapValue.ConstMapValue$factory = function(type, keyValuePairs, actualValue,
canonicalCode, span) { |
| 13124 var values = new HashMapImplementation(); |
| 13125 for (var i = 0; |
| 13126 i < keyValuePairs.length; i += 2) { |
| 13127 values.$setindex(keyValuePairs.$index(i).get$actualValue(), keyValuePairs.$i
ndex(i + 1)); |
| 13128 } |
| 13129 return new ConstMapValue._internal$ctor(type, values, actualValue, canonicalCo
de, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 13130 } |
| 13131 // ********** Code for ConstObjectValue ************** |
| 13132 $inherits(ConstObjectValue, EvaluatedValue); |
| 13133 function ConstObjectValue() {} |
| 13134 ConstObjectValue._internal$ctor = function(type, fields, actualValue, canonicalC
ode, span, code) { |
| 13135 this.fields = fields; |
| 13136 // Initializers done |
| 13137 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 13138 } |
| 13139 ConstObjectValue._internal$ctor.prototype = ConstObjectValue.prototype; |
| 13140 ConstObjectValue.ConstObjectValue$factory = function(type, fields, canonicalCode
, span) { |
| 13141 var fieldValues = []; |
| 13142 var $$list = fields.getKeys(); |
| 13143 for (var $$i = fields.getKeys().iterator$0(); $$i.hasNext$0(); ) { |
| 13144 var f = $$i.next$0(); |
| 13145 fieldValues.add(('' + f + ' = ' + fields.$index(f).get$actualValue())); |
| 13146 } |
| 13147 fieldValues.sort((function (a, b) { |
| 13148 return a.compareTo$1(b); |
| 13149 }) |
| 13150 ); |
| 13151 var actualValue = ('const ' + type.get$jsname() + ' [') + Strings.join(fieldVa
lues, ',') + ']'; |
| 13152 return new ConstObjectValue._internal$ctor(type, fields, actualValue, canonica
lCode, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 13153 } |
| 13154 ConstObjectValue.prototype.get$fields = function() { return this.fields; }; |
| 13155 ConstObjectValue.prototype.set$fields = function(value) { return this.fields = v
alue; }; |
| 13156 // ********** Code for GlobalValue ************** |
| 13157 $inherits(GlobalValue, Value); |
| 13158 function GlobalValue(type, code, isConst, field, name, exp, canonicalCode, span,
_dependencies) { |
| 13159 this.field = field; |
| 13160 this.name = name; |
| 13161 this.exp = exp; |
| 13162 this.canonicalCode = canonicalCode; |
| 13163 this.dependencies = []; |
| 13164 // Initializers done |
| 13165 Value.call(this, type, code, span, !isConst); |
| 13166 for (var $$i = 0;$$i < _dependencies.length; $$i++) { |
| 13167 var dep = _dependencies.$index($$i); |
| 13168 this.dependencies.add(dep); |
| 13169 this.dependencies.addAll(dep.get$dependencies()); |
| 13170 } |
| 13171 } |
| 13172 GlobalValue.GlobalValue$fromStatic$factory = function(field, exp, dependencies)
{ |
| 13173 var code = (exp.get$isConst() ? exp.get$canonicalCode() : exp.code); |
| 13174 var codeWithComment = ('' + code + '/*' + field.get$declaringType().name + '.'
+ field.name + '*/'); |
| 13175 return new GlobalValue(exp.get$type(), codeWithComment, field.get$isFinal(), f
ield, null, exp, code, exp.span, dependencies.filter$1((function (d) { |
| 13176 return (d instanceof GlobalValue); |
| 13177 }) |
| 13178 )); |
| 13179 } |
| 13180 GlobalValue.GlobalValue$fromConst$factory = function(uniqueId, exp, dependencies
) { |
| 13181 var name = ("const\$" + uniqueId); |
| 13182 var codeWithComment = ("" + name + "/*" + _escapeForComment(exp.span.get$text(
)) + "*/"); |
| 13183 return new GlobalValue(exp.get$type(), codeWithComment, true, null, name, exp,
name, exp.span, dependencies.filter$1((function (d) { |
| 13184 return (d instanceof GlobalValue); |
| 13185 }) |
| 13186 )); |
| 13187 } |
| 13188 GlobalValue.prototype.get$field = function() { return this.field; }; |
| 13189 GlobalValue.prototype.set$field = function(value) { return this.field = value; }
; |
| 13190 GlobalValue.prototype.get$exp = function() { return this.exp; }; |
| 13191 GlobalValue.prototype.set$exp = function(value) { return this.exp = value; }; |
| 13192 GlobalValue.prototype.get$canonicalCode = function() { return this.canonicalCode
; }; |
| 13193 GlobalValue.prototype.set$canonicalCode = function(value) { return this.canonica
lCode = value; }; |
| 13194 GlobalValue.prototype.get$isConst = function() { |
| 13195 return this.exp.get$isConst() && (this.field == null || this.field.isFinal); |
| 13196 } |
| 13197 GlobalValue.prototype.get$actualValue = function() { |
| 13198 return this.exp.get$dynamic().get$actualValue(); |
| 13199 } |
| 13200 GlobalValue.prototype.get$dependencies = function() { return this.dependencies;
}; |
| 13201 GlobalValue.prototype.set$dependencies = function(value) { return this.dependenc
ies = value; }; |
| 13202 GlobalValue.prototype.compareTo = function(other) { |
| 13203 if ($eq(other, this)) { |
| 13204 return 0; |
| 13205 } |
| 13206 else if (this.dependencies.indexOf(other) >= 0) { |
| 13207 return 1; |
| 13208 } |
| 13209 else if (other.dependencies.indexOf(this) >= 0) { |
| 13210 return -1; |
| 13211 } |
| 13212 else if (this.dependencies.length > other.dependencies.length) { |
| 13213 return 1; |
| 13214 } |
| 13215 else if (this.dependencies.length < other.dependencies.length) { |
| 13216 return -1; |
| 13217 } |
| 13218 else if (this.name == null && other.name != null) { |
| 13219 return 1; |
| 13220 } |
| 13221 else if (this.name != null && other.name == null) { |
| 13222 return -1; |
| 13223 } |
| 13224 else if (this.name != null) { |
| 13225 return this.name.compareTo(other.name); |
| 13226 } |
| 13227 else { |
| 13228 return this.field.name.compareTo(other.field.name); |
| 13229 } |
| 13230 } |
| 13231 GlobalValue.prototype.compareTo$1 = GlobalValue.prototype.compareTo; |
| 13232 // ********** Code for BareValue ************** |
| 13233 $inherits(BareValue, Value); |
| 13234 function BareValue(home, outermost, span) { |
| 13235 this.home = home; |
| 13236 // Initializers done |
| 13237 Value.call(this, outermost.method.declaringType, null, span, false); |
| 13238 this.isType = outermost.get$isStatic(); |
| 13239 } |
| 13240 BareValue.prototype.get$type = function() { |
| 13241 return this._type; |
| 13242 } |
| 13243 Object.defineProperty(BareValue.prototype, "type", { |
| 13244 get: BareValue.prototype.get$type |
| 13245 }); |
| 13246 BareValue.prototype._ensureCode = function() { |
| 13247 if (this.code != null) return; |
| 13248 if (this.isType) { |
| 13249 this.code = this.get$type().get$jsname(); |
| 13250 } |
| 13251 else { |
| 13252 this.code = this.home._makeThisCode(); |
| 13253 } |
| 13254 } |
| 13255 BareValue.prototype._tryResolveMember = function(context, name) { |
| 13256 var member = this.get$type().resolveMember(name); |
| 13257 if (member != null) { |
| 13258 if ($globals.options.forceDynamic && !member.get$isStatic()) { |
| 13259 member = context.findMembers(name); |
| 13260 } |
| 13261 this._ensureCode(); |
| 13262 return member; |
| 13263 } |
| 13264 member = this.home.get$library().lookup(name, this.span); |
| 13265 if (member != null) { |
| 13266 return member; |
| 13267 } |
| 13268 this._ensureCode(); |
| 13269 return null; |
| 13270 } |
| 13271 // ********** Code for CompilerException ************** |
| 13272 function CompilerException(_message, _location) { |
| 13273 this._message = _message; |
| 13274 this._location = _location; |
| 13275 // Initializers done |
| 13276 } |
| 13277 CompilerException.prototype.toString = function() { |
| 13278 if (this._location != null) { |
| 13279 return ('CompilerException: ' + this._location.toMessageString(this._message
)); |
| 13280 } |
| 13281 else { |
| 13282 return ('CompilerException: ' + this._message); |
| 13283 } |
| 13284 } |
| 13285 CompilerException.prototype.toString$0 = CompilerException.prototype.toString; |
| 13286 // ********** Code for World ************** |
| 13287 function World(files) { |
| 13288 this.errors = 0 |
| 13289 this.warnings = 0 |
| 13290 this.dartBytesRead = 0 |
| 13291 this.jsBytesWritten = 0 |
| 13292 this.seenFatal = false |
| 13293 this.files = files; |
| 13294 this.libraries = new HashMapImplementation(); |
| 13295 this._todo = []; |
| 13296 this._members = new HashMapImplementation(); |
| 13297 this._topNames = new HashMapImplementation(); |
| 13298 this.reader = new LibraryReader(); |
| 13299 // Initializers done |
| 13300 } |
| 13301 World.prototype.get$coreimpl = function() { |
| 13302 return this.libraries.$index('dart:coreimpl'); |
| 13303 } |
| 13304 World.prototype.get$dom = function() { |
| 13305 return this.libraries.$index('dart:dom'); |
| 13306 } |
| 13307 World.prototype.get$functionType = function() { return this.functionType; }; |
| 13308 World.prototype.set$functionType = function(value) { return this.functionType =
value; }; |
| 13309 World.prototype.reset = function() { |
| 13310 this.libraries = new HashMapImplementation(); |
| 13311 this._todo = []; |
| 13312 this._members = new HashMapImplementation(); |
| 13313 this._topNames = new HashMapImplementation(); |
| 13314 this.errors = this.warnings = 0; |
| 13315 this.seenFatal = false; |
| 13316 this.init(); |
| 13317 } |
| 13318 World.prototype.init = function() { |
| 13319 this.corelib = new Library(this.readFile('dart:core')); |
| 13320 this.libraries.$setindex('dart:core', this.corelib); |
| 13321 this._todo.add(this.corelib); |
| 13322 this.voidType = this._addToCoreLib('void', false); |
| 13323 this.dynamicType = this._addToCoreLib('Dynamic', false); |
| 13324 this.varType = this.dynamicType; |
| 13325 this.objectType = this._addToCoreLib('Object', true); |
| 13326 this.numType = this._addToCoreLib('num', false); |
| 13327 this.intType = this._addToCoreLib('int', false); |
| 13328 this.doubleType = this._addToCoreLib('double', false); |
| 13329 this.boolType = this._addToCoreLib('bool', false); |
| 13330 this.stringType = this._addToCoreLib('String', false); |
| 13331 this.listType = this._addToCoreLib('List', false); |
| 13332 this.mapType = this._addToCoreLib('Map', false); |
| 13333 this.functionType = this._addToCoreLib('Function', false); |
| 13334 this.nonNullBool = new NonNullableType(this.boolType); |
| 13335 } |
| 13336 World.prototype._addMember = function(member) { |
| 13337 if (member.get$isStatic()) { |
| 13338 if (member.declaringType.get$isTop()) { |
| 13339 this._addTopName(member); |
| 13340 } |
| 13341 return; |
| 13342 } |
| 13343 var mset = this._members.$index(member.name); |
| 13344 if (mset == null) { |
| 13345 mset = new MemberSet(member, true); |
| 13346 this._members.$setindex(mset.name, mset); |
| 13347 } |
| 13348 else { |
| 13349 mset.get$members().add$1(member); |
| 13350 } |
| 13351 } |
| 13352 World.prototype._addTopName = function(named) { |
| 13353 var existing = this._topNames.$index(named.get$jsname()); |
| 13354 if (existing != null) { |
| 13355 this.info(('mangling matching top level name "' + named.get$jsname() + '" in
') + ('both "' + named.get$library().get$jsname() + '" and "' + existing.get$li
brary().get$jsname() + '"')); |
| 13356 if (named.get$isNative()) { |
| 13357 if (existing.get$isNative()) { |
| 13358 $globals.world.internalError(('conflicting native names "' + named.get$j
sname() + '" ') + ('(already defined in ' + existing.span.get$locationText() + '
)'), named.get$span()); |
| 13359 } |
| 13360 else { |
| 13361 this._topNames.$setindex(named.get$jsname(), named); |
| 13362 this._addJavascriptTopName(existing); |
| 13363 } |
| 13364 } |
| 13365 else if (named.get$library().get$isCore()) { |
| 13366 if (existing.get$library().get$isCore()) { |
| 13367 $globals.world.internalError(('conflicting top-level names in core "' +
named.get$jsname() + '" ') + ('(previously defined in ' + existing.span.get$loca
tionText() + ')'), named.get$span()); |
| 13368 } |
| 13369 else { |
| 13370 this._topNames.$setindex(named.get$jsname(), named); |
| 13371 this._addJavascriptTopName(existing); |
| 13372 } |
| 13373 } |
| 13374 else { |
| 13375 this._addJavascriptTopName(named); |
| 13376 } |
| 13377 } |
| 13378 else { |
| 13379 this._topNames.$setindex(named.get$jsname(), named); |
| 13380 } |
| 13381 } |
| 13382 World.prototype._addJavascriptTopName = function(named) { |
| 13383 named._jsname = ('' + named.get$library().get$jsname() + '_' + named.get$jsnam
e()); |
| 13384 var existing = this._topNames.$index(named.get$jsname()); |
| 13385 if (existing != null && $ne(existing, named)) { |
| 13386 $globals.world.internalError(('name mangling failed for "' + named.get$jsnam
e() + '" ') + ('("' + named.get$jsname() + '" defined also in ' + existing.span.
get$locationText() + ')'), named.get$span()); |
| 13387 } |
| 13388 this._topNames.$setindex(named.get$jsname(), named); |
| 13389 } |
| 13390 World.prototype._addType = function(type) { |
| 13391 if (!type.get$isTop()) this._addTopName(type); |
| 13392 } |
| 13393 World.prototype._addToCoreLib = function(name, isClass) { |
| 13394 var ret = new DefinedType(name, this.corelib, null, isClass); |
| 13395 this.corelib.types.$setindex(name, ret); |
| 13396 return ret; |
| 13397 } |
| 13398 World.prototype.toJsIdentifier = function(name) { |
| 13399 if (name == null) return null; |
| 13400 if (this._jsKeywords == null) { |
| 13401 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'])
; |
| 13402 } |
| 13403 if (this._jsKeywords.contains(name)) { |
| 13404 return name + '_'; |
| 13405 } |
| 13406 else { |
| 13407 return name.replaceAll("$", "$$").replaceAll(':', "$"); |
| 13408 } |
| 13409 } |
| 13410 World.prototype.compile = function() { |
| 13411 if ($globals.options.dartScript == null) { |
| 13412 this.fatal('no script provided to compile'); |
| 13413 return false; |
| 13414 } |
| 13415 try { |
| 13416 this.info(('compiling ' + $globals.options.dartScript + ' with corelib ' + t
his.corelib)); |
| 13417 if (!this.runLeg()) this.runCompilationPhases(); |
| 13418 } catch (exc) { |
| 13419 exc = _toDartException(exc); |
| 13420 if (this.get$hasErrors() && !$globals.options.throwOnErrors) { |
| 13421 } |
| 13422 else { |
| 13423 throw exc; |
| 13424 } |
| 13425 } |
| 13426 this.printStatus(); |
| 13427 return !this.get$hasErrors(); |
| 13428 } |
| 13429 World.prototype.runLeg = function() { |
| 13430 var $this = this; // closure support |
| 13431 if (!$globals.options.enableLeg) return false; |
| 13432 if ($globals.legCompile == null) { |
| 13433 this.fatal('requested leg enabled, but no leg compiler available'); |
| 13434 } |
| 13435 var res = this.withTiming('try leg compile', (function () { |
| 13436 return $globals.legCompile($this); |
| 13437 }) |
| 13438 ); |
| 13439 if (!res && $globals.options.legOnly) { |
| 13440 this.fatal(("Leg could not compile " + $globals.options.dartScript)); |
| 13441 return true; |
| 13442 } |
| 13443 return res; |
| 13444 } |
| 13445 World.prototype.runCompilationPhases = function() { |
| 13446 var $this = this; // closure support |
| 13447 var lib = this.withTiming('first pass', (function () { |
| 13448 return $this.processDartScript(); |
| 13449 }) |
| 13450 ); |
| 13451 this.withTiming('resolve top level', this.get$resolveAll()); |
| 13452 if ($globals.experimentalAwaitPhase != null) { |
| 13453 this.withTiming('await translation', to$call$0($globals.experimentalAwaitPha
se)); |
| 13454 } |
| 13455 this.withTiming('generate code', (function () { |
| 13456 $this.generateCode(lib); |
| 13457 }) |
| 13458 ); |
| 13459 } |
| 13460 World.prototype.getGeneratedCode = function() { |
| 13461 if (this.legCode != null) { |
| 13462 return this.legCode; |
| 13463 } |
| 13464 else { |
| 13465 return this.gen.writer.get$text(); |
| 13466 } |
| 13467 } |
| 13468 World.prototype.readFile = function(filename) { |
| 13469 try { |
| 13470 var sourceFile = this.reader.readFile(filename); |
| 13471 this.dartBytesRead += sourceFile.get$text().length; |
| 13472 return sourceFile; |
| 13473 } catch (e) { |
| 13474 e = _toDartException(e); |
| 13475 this.warning(('Error reading file: ' + filename)); |
| 13476 return new SourceFile(filename, ''); |
| 13477 } |
| 13478 } |
| 13479 World.prototype.getOrAddLibrary = function(filename) { |
| 13480 var library = this.libraries.$index(filename); |
| 13481 if (library == null) { |
| 13482 library = new Library(this.readFile(filename)); |
| 13483 this.info(('read library ' + filename)); |
| 13484 if (!library.get$isCore() && !library.imports.some((function (li) { |
| 13485 return li.get$library().get$isCore(); |
| 13486 }) |
| 13487 )) { |
| 13488 library.imports.add(new LibraryImport(this.corelib)); |
| 13489 } |
| 13490 this.libraries.$setindex(filename, library); |
| 13491 this._todo.add(library); |
| 13492 } |
| 13493 return library; |
| 13494 } |
| 13495 World.prototype.process = function() { |
| 13496 while (this._todo.length > 0) { |
| 13497 var todo = this._todo; |
| 13498 this._todo = []; |
| 13499 for (var $$i = 0;$$i < todo.length; $$i++) { |
| 13500 var lib = todo.$index($$i); |
| 13501 lib.visitSources$0(); |
| 13502 } |
| 13503 } |
| 13504 } |
| 13505 World.prototype.processDartScript = function(script) { |
| 13506 if (script == null) script = $globals.options.dartScript; |
| 13507 var library = this.getOrAddLibrary(script); |
| 13508 this.process(); |
| 13509 return library; |
| 13510 } |
| 13511 World.prototype.resolveAll = function() { |
| 13512 var $$list = this.libraries.getValues(); |
| 13513 for (var $$i = this.libraries.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 13514 var lib = $$i.next$0(); |
| 13515 lib.resolve$0(); |
| 13516 } |
| 13517 } |
| 13518 World.prototype.get$resolveAll = function() { |
| 13519 return World.prototype.resolveAll.bind(this); |
| 13520 } |
| 13521 World.prototype.generateCode = function(lib) { |
| 13522 var mainMembers = lib.topType.resolveMember('main'); |
| 13523 var main = null; |
| 13524 if (mainMembers == null || $eq(mainMembers.get$members().length, 0)) { |
| 13525 this.fatal('no main method specified'); |
| 13526 } |
| 13527 else if (mainMembers.get$members().length > 1) { |
| 13528 var $$list = mainMembers.get$members(); |
| 13529 for (var $$i = mainMembers.get$members().iterator$0(); $$i.hasNext$0(); ) { |
| 13530 var m = $$i.next$0(); |
| 13531 main = m; |
| 13532 this.error('more than one main member (using last?)', main.span); |
| 13533 } |
| 13534 } |
| 13535 else { |
| 13536 main = mainMembers.get$members().$index(0); |
| 13537 } |
| 13538 var codeWriter = new CodeWriter(); |
| 13539 this.gen = new WorldGenerator(main, codeWriter); |
| 13540 this.gen.run(); |
| 13541 this.jsBytesWritten = codeWriter.text.length; |
| 13542 } |
| 13543 World.prototype._message = function(color, prefix, message, span, span1, span2,
throwing) { |
| 13544 if (this.messageHandler != null) { |
| 13545 this.messageHandler(prefix, message, span); |
| 13546 if (span1 != null) { |
| 13547 this.messageHandler(prefix, message, span1); |
| 13548 } |
| 13549 if (span2 != null) { |
| 13550 this.messageHandler(prefix, message, span2); |
| 13551 } |
| 13552 } |
| 13553 var messageWithPrefix = $globals.options.useColors ? (color + prefix + $global
s._NO_COLOR + message) : (prefix + message); |
| 13554 var text = messageWithPrefix; |
| 13555 if (span != null) { |
| 13556 text = span.toMessageString(messageWithPrefix); |
| 13557 } |
| 13558 print(text); |
| 13559 if (span1 != null) { |
| 13560 print(span1.toMessageString(messageWithPrefix)); |
| 13561 } |
| 13562 if (span2 != null) { |
| 13563 print(span2.toMessageString(messageWithPrefix)); |
| 13564 } |
| 13565 if (throwing) { |
| 13566 $throw(new CompilerException(messageWithPrefix, span)); |
| 13567 } |
| 13568 } |
| 13569 World.prototype.error = function(message, span, span1, span2) { |
| 13570 this.errors++; |
| 13571 this._message($globals._RED_COLOR, 'error: ', message, span, span1, span2, $gl
obals.options.throwOnErrors); |
| 13572 } |
| 13573 World.prototype.warning = function(message, span, span1, span2) { |
| 13574 if ($globals.options.warningsAsErrors) { |
| 13575 this.error(message, span, span1, span2); |
| 13576 return; |
| 13577 } |
| 13578 this.warnings++; |
| 13579 if ($globals.options.showWarnings) { |
| 13580 this._message($globals._MAGENTA_COLOR, 'warning: ', message, span, span1, sp
an2, $globals.options.throwOnWarnings); |
| 13581 } |
| 13582 } |
| 13583 World.prototype.fatal = function(message, span, span1, span2) { |
| 13584 this.errors++; |
| 13585 this.seenFatal = true; |
| 13586 this._message($globals._RED_COLOR, 'fatal: ', message, span, span1, span2, $gl
obals.options.throwOnFatal || $globals.options.throwOnErrors); |
| 13587 } |
| 13588 World.prototype.internalError = function(message, span, span1, span2) { |
| 13589 this._message($globals._NO_COLOR, 'We are sorry, but...', message, span, span1
, span2, true); |
| 13590 } |
| 13591 World.prototype.info = function(message, span, span1, span2) { |
| 13592 if ($globals.options.showInfo) { |
| 13593 this._message($globals._GREEN_COLOR, 'info: ', message, span, span1, span2,
false); |
| 13594 } |
| 13595 } |
| 13596 World.prototype.withoutForceDynamic = function(fn) { |
| 13597 var oldForceDynamic = $globals.options.forceDynamic; |
| 13598 $globals.options.forceDynamic = false; |
| 13599 try { |
| 13600 return fn(); |
| 13601 } finally { |
| 13602 $globals.options.forceDynamic = oldForceDynamic; |
| 13603 } |
| 13604 } |
| 13605 World.prototype.get$hasErrors = function() { |
| 13606 return this.errors > 0; |
| 13607 } |
| 13608 World.prototype.printStatus = function() { |
| 13609 this.info(('compiled ' + this.dartBytesRead + ' bytes Dart -> ' + this.jsBytes
Written + ' bytes JS')); |
| 13610 if (this.get$hasErrors()) { |
| 13611 print(('compilation failed with ' + this.errors + ' errors')); |
| 13612 } |
| 13613 else { |
| 13614 if (this.warnings > 0) { |
| 13615 this.info(('compilation completed successfully with ' + this.warnings + '
warnings')); |
| 13616 } |
| 13617 else { |
| 13618 this.info('compilation completed sucessfully'); |
| 13619 } |
| 13620 } |
| 13621 } |
| 13622 World.prototype.withTiming = function(name, f) { |
| 13623 var sw = new StopwatchImplementation(); |
| 13624 sw.start(); |
| 13625 var result = f(); |
| 13626 sw.stop(); |
| 13627 this.info(('' + name + ' in ' + sw.elapsedInMs() + 'msec')); |
| 13628 return result; |
| 13629 } |
| 13630 // ********** Code for FrogOptions ************** |
| 13631 function FrogOptions(homedir, args, files) { |
| 13632 this.config = 'dev' |
| 13633 this.enableLeg = false |
| 13634 this.legOnly = false |
| 13635 this.enableAsserts = false |
| 13636 this.enableTypeChecks = false |
| 13637 this.warningsAsErrors = false |
| 13638 this.verifyImplements = false |
| 13639 this.compileAll = false |
| 13640 this.forceDynamic = false |
| 13641 this.dietParse = false |
| 13642 this.compileOnly = false |
| 13643 this.throwOnErrors = false |
| 13644 this.throwOnWarnings = false |
| 13645 this.throwOnFatal = false |
| 13646 this.showInfo = false |
| 13647 this.showWarnings = true |
| 13648 this.useColors = true |
| 13649 // Initializers done |
| 13650 if ($eq(this.config, 'dev')) { |
| 13651 this.libDir = joinPaths(homedir, '/lib'); |
| 13652 } |
| 13653 else if ($eq(this.config, 'sdk')) { |
| 13654 this.libDir = joinPaths(homedir, '/../lib'); |
| 13655 } |
| 13656 else { |
| 13657 $globals.world.error(('Invalid configuration ' + this.config)); |
| 13658 $throw(('Invalid configuration')); |
| 13659 } |
| 13660 var ignoreUnrecognizedFlags = false; |
| 13661 var passedLibDir = false; |
| 13662 this.childArgs = []; |
| 13663 loop: |
| 13664 for (var i = 2; |
| 13665 i < args.length; i++) { |
| 13666 var arg = args.$index(i); |
| 13667 switch (arg) { |
| 13668 case '--enable_leg': |
| 13669 |
| 13670 this.enableLeg = true; |
| 13671 break; |
| 13672 |
| 13673 case '--leg_only': |
| 13674 |
| 13675 this.enableLeg = true; |
| 13676 this.legOnly = true; |
| 13677 break; |
| 13678 |
| 13679 case '--enable_asserts': |
| 13680 |
| 13681 this.enableAsserts = true; |
| 13682 break; |
| 13683 |
| 13684 case '--enable_type_checks': |
| 13685 |
| 13686 this.enableTypeChecks = true; |
| 13687 this.enableAsserts = true; |
| 13688 break; |
| 13689 |
| 13690 case '--verify_implements': |
| 13691 |
| 13692 this.verifyImplements = true; |
| 13693 break; |
| 13694 |
| 13695 case '--compile_all': |
| 13696 |
| 13697 this.compileAll = true; |
| 13698 break; |
| 13699 |
| 13700 case '--diet-parse': |
| 13701 |
| 13702 this.dietParse = true; |
| 13703 break; |
| 13704 |
| 13705 case '--ignore-unrecognized-flags': |
| 13706 |
| 13707 ignoreUnrecognizedFlags = true; |
| 13708 break; |
| 13709 |
| 13710 case '--verbose': |
| 13711 |
| 13712 this.showInfo = true; |
| 13713 break; |
| 13714 |
| 13715 case '--suppress_warnings': |
| 13716 |
| 13717 this.showWarnings = false; |
| 13718 break; |
| 13719 |
| 13720 case '--warnings_as_errors': |
| 13721 |
| 13722 this.warningsAsErrors = true; |
| 13723 break; |
| 13724 |
| 13725 case '--throw_on_errors': |
| 13726 |
| 13727 this.throwOnErrors = true; |
| 13728 break; |
| 13729 |
| 13730 case '--throw_on_warnings': |
| 13731 |
| 13732 this.throwOnWarnings = true; |
| 13733 break; |
| 13734 |
| 13735 case '--compile-only': |
| 13736 |
| 13737 this.compileOnly = true; |
| 13738 break; |
| 13739 |
| 13740 case '--force_dynamic': |
| 13741 |
| 13742 this.forceDynamic = true; |
| 13743 break; |
| 13744 |
| 13745 case '--no_colors': |
| 13746 |
| 13747 this.useColors = false; |
| 13748 break; |
| 13749 |
| 13750 default: |
| 13751 |
| 13752 if (arg.endsWith$1('.dart')) { |
| 13753 this.dartScript = arg; |
| 13754 this.childArgs = args.getRange(i + 1, args.length - i - 1); |
| 13755 break loop; |
| 13756 } |
| 13757 else if (arg.startsWith$1('--out=')) { |
| 13758 this.outfile = arg.substring$1('--out='.length); |
| 13759 } |
| 13760 else if (arg.startsWith$1('--libdir=')) { |
| 13761 this.libDir = arg.substring$1('--libdir='.length); |
| 13762 passedLibDir = true; |
| 13763 } |
| 13764 else { |
| 13765 if (!ignoreUnrecognizedFlags) { |
| 13766 print(('unrecognized flag: "' + arg + '"')); |
| 13767 } |
| 13768 } |
| 13769 |
| 13770 } |
| 13771 } |
| 13772 if (!passedLibDir && $eq(this.config, 'dev') && !files.fileExists(this.libDir)
) { |
| 13773 var temp = 'frog/lib'; |
| 13774 if (files.fileExists(temp)) { |
| 13775 this.libDir = temp; |
| 13776 } |
| 13777 else { |
| 13778 this.libDir = 'lib'; |
| 13779 } |
| 13780 } |
| 13781 } |
| 13782 // ********** Code for LibraryReader ************** |
| 13783 function LibraryReader() { |
| 13784 // Initializers done |
| 13785 if ($eq($globals.options.config, 'dev')) { |
| 13786 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, '../../client/html/rele
ase/html.dart'), 'dart:htmlimpl', joinPaths($globals.options.libDir, '../../clie
nt/html/release/htmlimpl.dart'), 'dart:dom', joinPaths($globals.options.libDir,
'../../client/dom/frog/frog_dom.dart'), 'dart:json', joinPaths($globals.options.
libDir, 'json.dart')]); |
| 13787 } |
| 13788 else if ($eq($globals.options.config, 'sdk')) { |
| 13789 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.dart'), 'dart:htmlimpl', joinPaths($globals.options.libDir, 'htmlimpl/htmli
mpl.dart'), 'dart:dom', joinPaths($globals.options.libDir, 'dom/frog/frog_dom.da
rt'), 'dart:json', joinPaths($globals.options.libDir, 'json/json_frog.dart')]); |
| 13790 } |
| 13791 else { |
| 13792 $globals.world.error(('Invalid configuration ' + $globals.options.config)); |
| 13793 } |
| 13794 } |
| 13795 LibraryReader.prototype.readFile = function(fullname) { |
| 13796 var filename = this._specialLibs.$index(fullname); |
| 13797 if (filename == null) { |
| 13798 filename = fullname; |
| 13799 } |
| 13800 if ($globals.world.files.fileExists(filename)) { |
| 13801 return new SourceFile(filename, $globals.world.files.readAll(filename)); |
| 13802 } |
| 13803 else { |
| 13804 $globals.world.error(('File not found: ' + filename)); |
| 13805 return new SourceFile(filename, ''); |
| 13806 } |
| 13807 } |
| 13808 // ********** Code for VarMember ************** |
| 13809 function VarMember(name) { |
| 13810 this.name = name; |
| 13811 // Initializers done |
| 13812 } |
| 13813 VarMember.prototype.get$returnType = function() { |
| 13814 return $globals.world.varType; |
| 13815 } |
| 13816 VarMember.prototype.invoke = function(context, node, target, args) { |
| 13817 return new Value(this.get$returnType(), ('' + target.code + '.' + this.name +
'(' + args.getCode() + ')'), node.span, true); |
| 13818 } |
| 13819 VarMember.prototype.generate$1 = VarMember.prototype.generate; |
| 13820 VarMember.prototype.invoke$4 = VarMember.prototype.invoke; |
| 13821 // ********** Code for VarFunctionStub ************** |
| 13822 $inherits(VarFunctionStub, VarMember); |
| 13823 function VarFunctionStub(name, callArgs) { |
| 13824 this.args = callArgs.toCallStubArgs(); |
| 13825 // Initializers done |
| 13826 VarMember.call(this, name); |
| 13827 $globals.world.gen.corejs.useGenStub = true; |
| 13828 } |
| 13829 VarFunctionStub.prototype.generate = function(code) { |
| 13830 if (this.args.get$hasNames()) { |
| 13831 this.generateNamed(code); |
| 13832 } |
| 13833 else { |
| 13834 this.generatePositional(code); |
| 13835 } |
| 13836 } |
| 13837 VarFunctionStub.prototype.generatePositional = function(w) { |
| 13838 var arity = this.args.get$length(); |
| 13839 w.enterBlock(('Function.prototype.to\$' + this.name + ' = function() {')); |
| 13840 w.writeln(('this.' + this.name + ' = this.\$genStub(' + arity + ');')); |
| 13841 w.writeln(('this.to\$' + this.name + ' = function() { return this.' + this.nam
e + '; };')); |
| 13842 w.writeln(('return this.' + this.name + ';')); |
| 13843 w.exitBlock('};'); |
| 13844 var argsCode = this.args.getCode(); |
| 13845 w.enterBlock(('Function.prototype.' + this.name + ' = function(' + argsCode +
') {')); |
| 13846 w.writeln(('return this.to\$' + this.name + '()(' + argsCode + ');')); |
| 13847 w.exitBlock('};'); |
| 13848 w.writeln(('function to\$' + this.name + '(f) { return f && f.to\$' + this.nam
e + '(); }')); |
| 13849 } |
| 13850 VarFunctionStub.prototype.generateNamed = function(w) { |
| 13851 var named = Strings.join(this.args.getNames(), '", "'); |
| 13852 var argsCode = this.args.getCode(); |
| 13853 w.enterBlock(('Function.prototype.' + this.name + ' = function(' + argsCode +
') {')); |
| 13854 w.writeln(('this.' + this.name + ' = this.\$genStub(' + this.args.get$length()
+ ', ["' + named + '"]);')); |
| 13855 w.writeln(('return this.' + this.name + '(' + argsCode + ');')); |
| 13856 w.exitBlock('}'); |
| 13857 } |
| 13858 VarFunctionStub.prototype.generate$1 = VarFunctionStub.prototype.generate; |
| 13859 // ********** Code for VarMethodStub ************** |
| 13860 $inherits(VarMethodStub, VarMember); |
| 13861 function VarMethodStub(name, member, args, body) { |
| 13862 this.member = member; |
| 13863 this.args = args; |
| 13864 this.body = body; |
| 13865 // Initializers done |
| 13866 VarMember.call(this, name); |
| 13867 } |
| 13868 VarMethodStub.prototype.get$isHidden = function() { |
| 13869 return this.member != null ? this.member.declaringType.get$isHiddenNativeType(
) : false; |
| 13870 } |
| 13871 VarMethodStub.prototype.get$returnType = function() { |
| 13872 return this.member != null ? this.member.get$returnType() : $globals.world.var
Type; |
| 13873 } |
| 13874 VarMethodStub.prototype.get$declaringType = function() { |
| 13875 return this.member != null ? this.member.declaringType : $globals.world.object
Type; |
| 13876 } |
| 13877 VarMethodStub.prototype.generate = function(code) { |
| 13878 code.write($globals.world.gen._prototypeOf(this.get$declaringType(), this.name
) + ' = '); |
| 13879 if (!this.get$isHidden() && this._useDirectCall(this.args)) { |
| 13880 code.writeln($globals.world.gen._prototypeOf(this.get$declaringType(), this.
member.get$jsname()) + ';'); |
| 13881 } |
| 13882 else if (this._needsExactTypeCheck()) { |
| 13883 code.enterBlock(('function(' + this.args.getCode() + ') {')); |
| 13884 code.enterBlock(('if (Object.getPrototypeOf(this).hasOwnProperty("' + this.n
ame + '")) {')); |
| 13885 code.writeln(('' + this.body + ';')); |
| 13886 code.exitBlock('}'); |
| 13887 var argsCode = this.args.getCode(); |
| 13888 if (argsCode != '') argsCode = ', ' + argsCode; |
| 13889 code.writeln(('return Object.prototype.' + this.name + '.call(this' + argsCo
de + ');')); |
| 13890 code.exitBlock('};'); |
| 13891 } |
| 13892 else { |
| 13893 code.enterBlock(('function(' + this.args.getCode() + ') {')); |
| 13894 code.writeln(('' + this.body + ';')); |
| 13895 code.exitBlock('};'); |
| 13896 } |
| 13897 } |
| 13898 VarMethodStub.prototype._needsExactTypeCheck = function() { |
| 13899 var $this = this; // closure support |
| 13900 if (this.member == null || this.member.declaringType.get$isObject()) return fa
lse; |
| 13901 var members = this.member.declaringType.resolveMember(this.member.name).member
s; |
| 13902 return members.filter$1((function (m) { |
| 13903 return $ne(m, $this.member) && m.get$declaringType().get$isHiddenNativeType(
); |
| 13904 }) |
| 13905 ).length >= 1; |
| 13906 } |
| 13907 VarMethodStub.prototype._useDirectCall = function(args) { |
| 13908 if ((this.member instanceof MethodMember) && !this.member.declaringType.get$ha
sNativeSubtypes()) { |
| 13909 var method = this.member; |
| 13910 if (method.needsArgumentConversion(args)) { |
| 13911 return false; |
| 13912 } |
| 13913 for (var i = args.get$length(); |
| 13914 i < method.parameters.length; i++) { |
| 13915 if ($ne(method.parameters.$index(i).value.code, 'null')) { |
| 13916 return false; |
| 13917 } |
| 13918 } |
| 13919 return method.namesInOrder(args); |
| 13920 } |
| 13921 else { |
| 13922 return false; |
| 13923 } |
| 13924 } |
| 13925 VarMethodStub.prototype.generate$1 = VarMethodStub.prototype.generate; |
| 13926 // ********** Code for VarMethodSet ************** |
| 13927 $inherits(VarMethodSet, VarMember); |
| 13928 function VarMethodSet(baseName, name, members, callArgs, returnType) { |
| 13929 this.invoked = false |
| 13930 this.baseName = baseName; |
| 13931 this.members = members; |
| 13932 this.returnType = returnType; |
| 13933 this.args = callArgs.toCallStubArgs(); |
| 13934 // Initializers done |
| 13935 VarMember.call(this, name); |
| 13936 } |
| 13937 VarMethodSet.prototype.get$members = function() { return this.members; }; |
| 13938 VarMethodSet.prototype.get$returnType = function() { return this.returnType; }; |
| 13939 VarMethodSet.prototype.invoke = function(context, node, target, args) { |
| 13940 this._invokeMembers(context, node); |
| 13941 return VarMember.prototype.invoke.call(this, context, node, target, args); |
| 13942 } |
| 13943 VarMethodSet.prototype._invokeMembers = function(context, node) { |
| 13944 if (this.invoked) return; |
| 13945 this.invoked = true; |
| 13946 var hasObjectType = false; |
| 13947 var $$list = this.members; |
| 13948 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 13949 var member = $$list.$index($$i); |
| 13950 var type = member.get$declaringType(); |
| 13951 var target = new Value(type, 'this', node.span, true); |
| 13952 var result = member.invoke$4$isDynamic(context, node, target, this.args, tru
e); |
| 13953 var stub = new VarMethodStub(this.name, member, this.args, 'return ' + resul
t.code); |
| 13954 type.get$varStubs().$setindex(stub.name, stub); |
| 13955 if (type.get$isObject()) hasObjectType = true; |
| 13956 } |
| 13957 if (!hasObjectType) { |
| 13958 var target = new Value($globals.world.objectType, 'this', node.span, true); |
| 13959 var result = target.invokeNoSuchMethod(context, this.baseName, node, this.ar
gs); |
| 13960 var stub = new VarMethodStub(this.name, null, this.args, 'return ' + result.
code); |
| 13961 $globals.world.objectType.varStubs.$setindex(stub.name, stub); |
| 13962 } |
| 13963 } |
| 13964 VarMethodSet.prototype.generate = function(code) { |
| 13965 |
| 13966 } |
| 13967 VarMethodSet.prototype.generate$1 = VarMethodSet.prototype.generate; |
| 13968 VarMethodSet.prototype.invoke$4 = VarMethodSet.prototype.invoke; |
| 13969 // ********** Code for top level ************** |
| 13970 function map(source, mapper) { |
| 13971 var result = new ListFactory(); |
| 13972 if (!!(source && source.is$List())) { |
| 13973 var list = source; |
| 13974 result.length = list.length; |
| 13975 for (var i = 0; |
| 13976 i < list.length; i++) { |
| 13977 result.$setindex(i, mapper(list.$index(i))); |
| 13978 } |
| 13979 } |
| 13980 else { |
| 13981 for (var $$i = source.iterator(); $$i.hasNext$0(); ) { |
| 13982 var item = $$i.next$0(); |
| 13983 result.add(mapper(item)); |
| 13984 } |
| 13985 } |
| 13986 return result; |
| 13987 } |
| 13988 function reduce(source, callback, initialValue) { |
| 13989 var i = source.iterator(); |
| 13990 var current = initialValue; |
| 13991 if (current == null && i.hasNext$0()) { |
| 13992 current = i.next$0(); |
| 13993 } |
| 13994 while (i.hasNext$0()) { |
| 13995 current = callback.call$2(current, i.next$0()); |
| 13996 } |
| 13997 return current; |
| 13998 } |
| 13999 function orderValuesByKeys(map) { |
| 14000 var keys = map.getKeys(); |
| 14001 keys.sort((function (x, y) { |
| 14002 return x.compareTo$1(y); |
| 14003 }) |
| 14004 ); |
| 14005 var values = []; |
| 14006 for (var $$i = 0;$$i < keys.length; $$i++) { |
| 14007 var k = keys.$index($$i); |
| 14008 values.add(map.$index(k)); |
| 14009 } |
| 14010 return values; |
| 14011 } |
| 14012 function isMultilineString(text) { |
| 14013 return text.startsWith('"""') || text.startsWith("'''"); |
| 14014 } |
| 14015 function isRawMultilineString(text) { |
| 14016 return text.startsWith('@"""') || text.startsWith("@'''"); |
| 14017 } |
| 14018 function toDoubleQuote(s) { |
| 14019 return s.replaceAll('"', '\\"').replaceAll("\\'", "'"); |
| 14020 } |
| 14021 function parseStringLiteral(lit) { |
| 14022 if (lit.startsWith('@')) { |
| 14023 if (isRawMultilineString(lit)) { |
| 14024 return stripLeadingNewline(lit.substring(4, lit.length - 3)); |
| 14025 } |
| 14026 else { |
| 14027 return lit.substring(2, lit.length - 1); |
| 14028 } |
| 14029 } |
| 14030 else if (isMultilineString(lit)) { |
| 14031 lit = lit.substring(3, lit.length - 3).replaceAll('\\\$', '\$'); |
| 14032 return stripLeadingNewline(lit); |
| 14033 } |
| 14034 else { |
| 14035 return lit.substring(1, lit.length - 1).replaceAll('\\\$', '\$'); |
| 14036 } |
| 14037 } |
| 14038 function stripLeadingNewline(text) { |
| 14039 if (text.startsWith('\n')) { |
| 14040 return text.substring(1); |
| 14041 } |
| 14042 else if (text.startsWith('\r')) { |
| 14043 if (text.startsWith('\r\n')) { |
| 14044 return text.substring(2); |
| 14045 } |
| 14046 else { |
| 14047 return text.substring(1); |
| 14048 } |
| 14049 } |
| 14050 else { |
| 14051 return text; |
| 14052 } |
| 14053 } |
| 14054 function _escapeForComment(text) { |
| 14055 return text.replaceAll('/*', '/ *').replaceAll('*/', '* /'); |
| 14056 } |
| 14057 var world; |
| 14058 var experimentalAwaitPhase; |
| 14059 var legCompile; |
| 14060 function initializeWorld(files) { |
| 14061 $globals.world = new World(files); |
| 14062 $globals.world.init(); |
| 14063 } |
| 14064 var options; |
| 14065 function parseOptions(homedir, args, files) { |
| 14066 $globals.options = new FrogOptions(homedir, args, files); |
| 14067 } |
| 14068 function _getCallStubName(name, args) { |
| 14069 var nameBuilder = new StringBufferImpl(('' + name + '\$' + args.get$bareCount(
))); |
| 14070 for (var i = args.get$bareCount(); |
| 14071 i < args.get$length(); i++) { |
| 14072 nameBuilder.add('\$').add(args.getName(i)); |
| 14073 } |
| 14074 return nameBuilder.toString(); |
| 14075 } |
| 14076 // ********** Library file_system_dom ************** |
| 14077 // ********** Code for DomFileSystem ************** |
| 14078 function DomFileSystem(_path) { |
| 14079 this._path = _path; |
| 14080 this._fileCache = new HashMapImplementation(); |
| 14081 // Initializers done |
| 14082 } |
| 14083 DomFileSystem.prototype.absPath = function(filename) { |
| 14084 if (this._path != null && !filename.startsWith('/') && !filename.startsWith('f
ile:///') && !filename.startsWith('http://') && !filename.startsWith('dart:')) { |
| 14085 filename = joinPaths(this._path, filename); |
| 14086 } |
| 14087 return filename; |
| 14088 } |
| 14089 DomFileSystem.prototype.readAll = function(filename) { |
| 14090 filename = this.absPath(filename); |
| 14091 var result = this._fileCache.$index(filename); |
| 14092 if (result == null) { |
| 14093 var xhr = new XMLHttpRequest(); |
| 14094 xhr.open('GET', filename, false); |
| 14095 try { |
| 14096 xhr.send(null); |
| 14097 } catch (e) { |
| 14098 e = _toDartException(e); |
| 14099 return ("_directory(" + filename + ")_"); |
| 14100 } |
| 14101 if (xhr.status == 0 || xhr.status == 200) { |
| 14102 result = xhr.responseText; |
| 14103 if (result.isEmpty$0()) { |
| 14104 print(('Error: ' + filename + ' is not found or empty')); |
| 14105 return null; |
| 14106 } |
| 14107 } |
| 14108 else { |
| 14109 print(("Error: " + xhr.statusText)); |
| 14110 } |
| 14111 this._fileCache.$setindex(filename, result); |
| 14112 } |
| 14113 return result; |
| 14114 } |
| 14115 DomFileSystem.prototype.writeString = function(outfile, text) { |
| 14116 outfile = this.absPath(outfile); |
| 14117 this._fileCache.$setindex(outfile, text); |
| 14118 } |
| 14119 DomFileSystem.prototype.fileExists = function(filename) { |
| 14120 return this.readAll(filename) != null; |
| 14121 } |
| 14122 // ********** Code for top level ************** |
| 14123 // ********** Library tip ************** |
| 14124 // ********** Code for Message ************** |
| 14125 function Message(prefix, message, span) { |
| 14126 this.prefix = prefix; |
| 14127 this.message = message; |
| 14128 this.span = span; |
| 14129 // Initializers done |
| 14130 var col = this.prefix.indexOf(':'); |
| 14131 if ($ne(col, -1)) { |
| 14132 this.prefix = this.prefix.substring(0, col); |
| 14133 } |
| 14134 this._node = get$document().createElement('div'); |
| 14135 this._node.className = ('message ' + this.prefix); |
| 14136 this._node.innerText = ('' + this.message + ' at ' + this.span.get$locationTex
t()); |
| 14137 this._node.addEventListener$3('click', this.get$click(), false); |
| 14138 } |
| 14139 Message.prototype.get$_node = function() { return this._node; }; |
| 14140 Message.prototype.set$_node = function(value) { return this._node = value; }; |
| 14141 Message.prototype.click = function(event) { |
| 14142 $globals.shell.showSpan(this.span); |
| 14143 } |
| 14144 Message.prototype.get$click = function() { |
| 14145 return Message.prototype.click.bind(this); |
| 14146 } |
| 14147 // ********** Code for MessageWindow ************** |
| 14148 function MessageWindow() { |
| 14149 // Initializers done |
| 14150 this.messages = []; |
| 14151 this._node = get$document().createElement('div'); |
| 14152 this._node.className = 'errors'; |
| 14153 } |
| 14154 MessageWindow.prototype.get$_node = function() { return this._node; }; |
| 14155 MessageWindow.prototype.set$_node = function(value) { return this._node = value;
}; |
| 14156 MessageWindow.prototype.addMessage = function(message) { |
| 14157 this.messages.add(message); |
| 14158 this._node.appendChild$1(message._node); |
| 14159 } |
| 14160 MessageWindow.prototype.clear = function() { |
| 14161 this.messages.length = 0; |
| 14162 this._node.innerHTML = ''; |
| 14163 } |
| 14164 MessageWindow.prototype.addMessage$1 = MessageWindow.prototype.addMessage; |
| 14165 MessageWindow.prototype.clear$0 = MessageWindow.prototype.clear; |
| 14166 // ********** Code for Shell ************** |
| 14167 function Shell() { |
| 14168 var $this = this; // closure support |
| 14169 // Initializers done |
| 14170 this._node = get$document().createElement('div'); |
| 14171 this._node.className = 'shell'; |
| 14172 this._editor = new Editor(this); |
| 14173 this._editor._node.style.setProperty$2('height', '93%'); |
| 14174 this._node.appendChild$1(this._editor._node); |
| 14175 this._textInputArea = get$document().createElement('textarea'); |
| 14176 this._textInputArea.className = 'hiddenTextArea'; |
| 14177 this._node.appendChild$1(this._textInputArea); |
| 14178 var outDiv = get$document().createElement('div'); |
| 14179 outDiv.className = 'output'; |
| 14180 outDiv.style.setProperty$2('height', '83%'); |
| 14181 this._output = get$document().createElement('iframe'); |
| 14182 outDiv.appendChild$1(this._output); |
| 14183 this._node.appendChild$1(outDiv); |
| 14184 this._repl = get$document().createElement('div'); |
| 14185 this._repl.className = 'repl'; |
| 14186 this._repl.style.setProperty$2('height', '5%'); |
| 14187 this._repl.innerHTML = '<div>REPL Under Construction...</div>'; |
| 14188 this._node.appendChild$1(this._repl); |
| 14189 this._errors = new MessageWindow(); |
| 14190 this._errors.get$_node().style.setProperty$2('height', '15%'); |
| 14191 this._node.appendChild$1(this._errors.get$_node()); |
| 14192 get$window().setTimeout($wrap_call$0((function () { |
| 14193 $this._editor.focus(); |
| 14194 $this._output.contentDocument.head.innerHTML = " <style>body {\n
font-family: arial , sans-serif;\n }\n h3 {\n text-a
lign: center;\n }\n </style>"; |
| 14195 $this._output.contentDocument.body.innerHTML = '<h3>Output will go here</h3>
'; |
| 14196 }) |
| 14197 ), .5); |
| 14198 var bindings = _map(['Left', (function () { |
| 14199 $this.cursor.clearSelection(); |
| 14200 $this.cursor._pos = $this.cursor._pos.moveColumn(-1); |
| 14201 }) |
| 14202 , 'Shift-Left', (function () { |
| 14203 if ($this.cursor._toPos == null) { |
| 14204 $this.cursor._toPos = $this.cursor._pos; |
| 14205 } |
| 14206 $this.cursor._pos = $this.cursor._pos.moveColumn(-1); |
| 14207 }) |
| 14208 , 'Right', (function () { |
| 14209 $this.cursor.clearSelection(); |
| 14210 $this.cursor._pos = $this.cursor._pos.moveColumn(1); |
| 14211 }) |
| 14212 , 'Shift-Right', (function () { |
| 14213 if ($this.cursor._toPos == null) { |
| 14214 $this.cursor._toPos = $this.cursor._pos; |
| 14215 } |
| 14216 $this.cursor._pos = $this.cursor._pos.moveColumn(1); |
| 14217 }) |
| 14218 , 'Up', (function () { |
| 14219 $this.cursor.clearSelection(); |
| 14220 $this.cursor._pos = $this.cursor._pos.moveLine(-1); |
| 14221 }) |
| 14222 , 'Shift-Up', (function () { |
| 14223 if ($this.cursor._toPos == null) { |
| 14224 $this.cursor._toPos = $this.cursor._pos; |
| 14225 } |
| 14226 $this.cursor._pos = $this.cursor._pos.moveLine(-1); |
| 14227 }) |
| 14228 , 'Down', (function () { |
| 14229 $this.cursor.clearSelection(); |
| 14230 $this.cursor._pos = $this.cursor._pos.moveLine(1); |
| 14231 }) |
| 14232 , 'Shift-Down', (function () { |
| 14233 if ($this.cursor._toPos == null) { |
| 14234 $this.cursor._toPos = $this.cursor._pos; |
| 14235 } |
| 14236 $this.cursor._pos = $this.cursor._pos.moveLine(1); |
| 14237 }) |
| 14238 , 'Meta-Up', (function () { |
| 14239 $this.cursor.clearSelection(); |
| 14240 $this.cursor._pos = $this._editor._code.get$start(); |
| 14241 }) |
| 14242 , 'Meta-Shift-Up', (function () { |
| 14243 if ($this.cursor._toPos == null) { |
| 14244 $this.cursor._toPos = $this.cursor._pos; |
| 14245 } |
| 14246 $this.cursor._pos = $this._editor._code.get$start(); |
| 14247 }) |
| 14248 , 'Meta-Down', (function () { |
| 14249 $this.cursor.clearSelection(); |
| 14250 $this.cursor._pos = $this._editor._code.get$end(); |
| 14251 }) |
| 14252 , 'Meta-Shift-Down', (function () { |
| 14253 if ($this.cursor._toPos == null) { |
| 14254 $this.cursor._toPos = $this.cursor._pos; |
| 14255 } |
| 14256 $this.cursor._pos = $this._editor._code.get$end(); |
| 14257 }) |
| 14258 , 'Delete', (function () { |
| 14259 if ($this.cursor._toPos == null) { |
| 14260 $this.cursor._toPos = $this.cursor._pos.moveColumn(-1); |
| 14261 } |
| 14262 $this.cursor.deleteSelection(); |
| 14263 }) |
| 14264 , 'Control-D', (function () { |
| 14265 if ($this.cursor._toPos == null) { |
| 14266 $this.cursor._toPos = $this.cursor._pos.moveColumn(1); |
| 14267 } |
| 14268 $this.cursor.deleteSelection(); |
| 14269 }) |
| 14270 , 'Meta-A', (function () { |
| 14271 $this.cursor._pos = $this._editor._code.get$start(); |
| 14272 $this.cursor._toPos = $this._editor._code.get$end(); |
| 14273 }) |
| 14274 , '.', (function () { |
| 14275 $this.cursor.write('.'); |
| 14276 }) |
| 14277 , '}', (function () { |
| 14278 $this.cursor.write('}'); |
| 14279 }) |
| 14280 , 'Enter', (function () { |
| 14281 $this.cursor.write('\n'); |
| 14282 }) |
| 14283 , 'Tab', (function () { |
| 14284 $this.cursor.write(' '); |
| 14285 }) |
| 14286 , 'Space', (function () { |
| 14287 return $this.cursor.write(' '); |
| 14288 }) |
| 14289 , 'Shift-Space', (function () { |
| 14290 return $this.cursor.write(' '); |
| 14291 }) |
| 14292 , 'Meta-G', (function () { |
| 14293 return $this.cursor.write("#import(\"dart:dom\");\n\n// This is an interesti
ng field;\nfinal int y = 22;\nString name;\n\n/** This is my main method. */\nvo
id main() {\n var element = document.createElement('div');\n element.innerHTML
= \"Hello dom from Dart!\";\n document.body.appendChild(element);\n\n HTMLCan
vasElement canvas = document.createElement('canvas');\n document.body.appendChi
ld(canvas);\n\n var context = canvas.getContext('2d');\n context.setFillColor(
'purple');\n context.fillRect(10, 10, 30, 30);\n}\n\n/**\n * The usual method o
f computing factorial in the slowest possible way.\n */\nnum fact(n) {\n if (n
== 0) return 1;\n return n * fact(n - 1);\n}\n\nfinal x = 22;\n\n"/*null.CODE*/
); |
| 14294 }) |
| 14295 , 'Meta-H', (function () { |
| 14296 return $this.cursor.write("#import(\"dart:html\");\n\nvoid main() {\n var e
lement = document.createElement('div');\n element.innerHTML = \"Hello html from
Dart!\";\n document.body.nodes.add(element);\n\n CanvasElement canvas = docum
ent.createElement('canvas');\n canvas.width = 100;\n canvas.height = 100;\n d
ocument.body.nodes.add(canvas);\n\n var context = canvas.getContext('2d');\n c
ontext.setFillColor('blue');\n context.fillRect(10, 10, 30, 30);\n}\n"/*null.HC
ODE*/); |
| 14297 }) |
| 14298 , 'Meta-P', (function () { |
| 14299 return $this.cursor._pos.block.parse(); |
| 14300 }) |
| 14301 , 'Shift-Enter', this.get$run(), 'Meta-Enter', this.get$run()]); |
| 14302 this._bindings = new KeyBindings(this._textInputArea, bindings, (function (tex
t) { |
| 14303 $this.cursor.write(text); |
| 14304 }) |
| 14305 , (function (key) { |
| 14306 if (key == 'Meta-V') return false; |
| 14307 if (key == 'Control-V') return false; |
| 14308 if (key == 'Meta-X' || key == 'Control-X') { |
| 14309 get$window().setTimeout($wrap_call$0((function () { |
| 14310 $this.cursor.deleteSelection(); |
| 14311 $this._editor._redraw(); |
| 14312 }) |
| 14313 ), 0); |
| 14314 return false; |
| 14315 } |
| 14316 if (key == 'Meta-C') return false; |
| 14317 if (key == 'Control-C') return false; |
| 14318 if (key == 'Alt-Meta-I') return false; |
| 14319 if (key == 'Control-Shift-I') return false; |
| 14320 get$window().console.log(('Unbound key "' + key + '"')); |
| 14321 return true; |
| 14322 }) |
| 14323 ); |
| 14324 } |
| 14325 Shell.prototype.get$_node = function() { return this._node; }; |
| 14326 Shell.prototype.set$_node = function(value) { return this._node = value; }; |
| 14327 Shell.prototype.handleMessage = function(prefix, message, span) { |
| 14328 var m = new Message(prefix, message, span); |
| 14329 this._errors.addMessage$1(m); |
| 14330 } |
| 14331 Shell.prototype.get$handleMessage = function() { |
| 14332 return Shell.prototype.handleMessage.bind(this); |
| 14333 } |
| 14334 Shell.prototype.showSpan = function(span) { |
| 14335 var code = this._editor._code; |
| 14336 var p1 = new CodePosition(code, span.start); |
| 14337 var p2 = new CodePosition(code, span.end); |
| 14338 this._editor._cursor._pos = p1.toLeaf$0(); |
| 14339 this._editor._cursor._toPos = p2.toLeaf$0(); |
| 14340 this._editor._redraw(); |
| 14341 } |
| 14342 Shell.prototype.run = function() { |
| 14343 var $this = this; // closure support |
| 14344 this._output.contentDocument.body.innerHTML = '<h3 style="color:green">Compili
ng...</h3>'; |
| 14345 this._errors.clear$0(); |
| 14346 get$window().setTimeout($wrap_call$0((function () { |
| 14347 var sw = new StopwatchImplementation(); |
| 14348 sw.start(); |
| 14349 var code = $this._editor.getCode(); |
| 14350 $globals.world.files.writeString('input.dart'/*null.DART_FILENAME*/, code); |
| 14351 $globals.options.enableAsserts = true; |
| 14352 $globals.options.enableTypeChecks = true; |
| 14353 $globals.world.reset(); |
| 14354 var success = $globals.world.compile(); |
| 14355 sw.stop(); |
| 14356 if (success) { |
| 14357 $this._output.contentDocument.body.innerHTML = ''; |
| 14358 inject($globals.world.getGeneratedCode(), $this._output.contentWindow, 'ge
nerated.js'); |
| 14359 } |
| 14360 else { |
| 14361 $this._output.contentDocument.body.innerHTML = '<h3 style="color:red">Comp
ilation failed</h3>'; |
| 14362 } |
| 14363 print(('compiled in ' + sw.elapsedInMs() + 'msec')); |
| 14364 }) |
| 14365 ), 0); |
| 14366 } |
| 14367 Shell.prototype.get$run = function() { |
| 14368 return Shell.prototype.run.bind(this); |
| 14369 } |
| 14370 Shell.prototype.focusKeys = function(editor) { |
| 14371 this._editor = editor; |
| 14372 this.cursor = editor._cursor; |
| 14373 this._textInputArea.focus$0(); |
| 14374 } |
| 14375 // ********** Code for Editor ************** |
| 14376 function Editor(_shell) { |
| 14377 this._shell = _shell; |
| 14378 // Initializers done |
| 14379 this._node = get$document().createElement('div'); |
| 14380 this._node.className = 'editor'; |
| 14381 this._code = new BlockBlock(null, 0); |
| 14382 this._code.set$text("#import(\"dart:dom\");\n\n// This is an interesting field
;\nfinal int y = 22;\nString name;\n\n/** This is my main method. */\nvoid main(
) {\n var element = document.createElement('div');\n element.innerHTML = \"Hel
lo dom from Dart!\";\n document.body.appendChild(element);\n\n HTMLCanvasEleme
nt canvas = document.createElement('canvas');\n document.body.appendChild(canva
s);\n\n var context = canvas.getContext('2d');\n context.setFillColor('purple'
);\n context.fillRect(10, 10, 30, 30);\n}\n\n/**\n * The usual method of comput
ing factorial in the slowest possible way.\n */\nnum fact(n) {\n if (n == 0) re
turn 1;\n return n * fact(n - 1);\n}\n\nfinal x = 22;\n\n"/*null.CODE*/); |
| 14383 this._code.set$top(0); |
| 14384 this._node.appendChild$1(this._code._node); |
| 14385 this._cursor = new Cursor(this._code.get$start()); |
| 14386 this._node.appendChild$1(this._cursor._node); |
| 14387 this._node.addEventListener$3('mousedown', this.get$mousedown(), false); |
| 14388 this._node.addEventListener$3('mousemove', this.get$mousemove(), false); |
| 14389 this._node.addEventListener$3('mouseup', this.get$mouseup(), false); |
| 14390 } |
| 14391 Editor.prototype.get$_node = function() { return this._node; }; |
| 14392 Editor.prototype.set$_node = function(value) { return this._node = value; }; |
| 14393 Editor.prototype.getCode = function() { |
| 14394 return this._code.get$text(); |
| 14395 } |
| 14396 Editor.prototype.mousedown = function(e) { |
| 14397 if (e.shiftKey) { |
| 14398 this._cursor._toPos = this._cursor._pos; |
| 14399 } |
| 14400 else { |
| 14401 this._cursor.clearSelection(); |
| 14402 } |
| 14403 this._cursor._pos = this._code.positionFromMouse(e); |
| 14404 this.focus(); |
| 14405 e.preventDefault(); |
| 14406 this._isSelecting = true; |
| 14407 } |
| 14408 Editor.prototype.get$mousedown = function() { |
| 14409 return Editor.prototype.mousedown.bind(this); |
| 14410 } |
| 14411 Editor.prototype.mousemove = function(e) { |
| 14412 if (this._isSelecting) { |
| 14413 if (this._cursor._toPos == null) { |
| 14414 this._cursor._toPos = this._cursor._pos; |
| 14415 } |
| 14416 this._cursor._pos = this._code.positionFromMouse(e); |
| 14417 e.preventDefault(); |
| 14418 this._redraw(); |
| 14419 } |
| 14420 } |
| 14421 Editor.prototype.get$mousemove = function() { |
| 14422 return Editor.prototype.mousemove.bind(this); |
| 14423 } |
| 14424 Editor.prototype.mouseup = function(e) { |
| 14425 this._isSelecting = false; |
| 14426 if (this._cursor.get$emptySelection()) { |
| 14427 this._cursor.clearSelection(); |
| 14428 } |
| 14429 } |
| 14430 Editor.prototype.get$mouseup = function() { |
| 14431 return Editor.prototype.mouseup.bind(this); |
| 14432 } |
| 14433 Editor.prototype.scrollToVisible = function(pos) { |
| 14434 var top = this._node.scrollTop; |
| 14435 var height = this._node.getBoundingClientRect$0().height; |
| 14436 var pt = pos.getPoint(); |
| 14437 if (pt.y < top) { |
| 14438 this._node.scrollTop = pt.y; |
| 14439 } |
| 14440 else if (pt.y > top + height - 22/*null.LINE_HEIGHT*/) { |
| 14441 var H = 22/*null.LINE_HEIGHT*/ * (($truncdiv(height, 22/*null.LINE_HEIGHT*/)
) - 1); |
| 14442 this._node.scrollTop = Math.max(pt.y - H, 0); |
| 14443 } |
| 14444 } |
| 14445 Editor.prototype._redraw = function() { |
| 14446 this.scrollToVisible(this._cursor._pos); |
| 14447 this._code._redraw(); |
| 14448 this._cursor._redraw(); |
| 14449 } |
| 14450 Editor.prototype.focus = function() { |
| 14451 this._shell.focusKeys(this); |
| 14452 this._cursor._visible = true; |
| 14453 this._redraw(); |
| 14454 } |
| 14455 Editor.prototype._redraw$0 = Editor.prototype._redraw; |
| 14456 Editor.prototype.focus$0 = Editor.prototype.focus; |
| 14457 // ********** Code for Point ************** |
| 14458 function Point(x, y) { |
| 14459 this.x = x; |
| 14460 this.y = y; |
| 14461 // Initializers done |
| 14462 } |
| 14463 // ********** Code for LineColumn ************** |
| 14464 function LineColumn(line, column) { |
| 14465 this.line = line; |
| 14466 this.column = column; |
| 14467 // Initializers done |
| 14468 } |
| 14469 // ********** Code for Cursor ************** |
| 14470 function Cursor(_pos) { |
| 14471 this._visible = true |
| 14472 this._pos = _pos; |
| 14473 // Initializers done |
| 14474 this._node = get$document().createElement('div'); |
| 14475 this._node.className = 'cursorDiv'; |
| 14476 } |
| 14477 Cursor.prototype.get$_node = function() { return this._node; }; |
| 14478 Cursor.prototype.set$_node = function(value) { return this._node = value; }; |
| 14479 Cursor.prototype.get$emptySelection = function() { |
| 14480 return this._toPos == null || ($eq(this._toPos.block, this._pos.block) && this
._toPos.offset == this._pos.offset); |
| 14481 } |
| 14482 Cursor.prototype._redraw = function() { |
| 14483 var $this = this; // closure support |
| 14484 this._node.innerHTML = ''; |
| 14485 if (!this._visible) return; |
| 14486 this._cursorNode = get$document().createElement('div'); |
| 14487 this._cursorNode.className = 'cursor blink'; |
| 14488 this._cursorNode.style.setProperty$2('height', ('' + 22/*null.LINE_HEIGHT*/ +
'px')); |
| 14489 var p = this._pos.getPoint(); |
| 14490 this._cursorNode.style.setProperty$2('left', ('' + p.x + 'px')); |
| 14491 this._cursorNode.style.setProperty$2('top', ('' + p.y + 'px')); |
| 14492 this._node.appendChild$1(this._cursorNode); |
| 14493 if (this._toPos == null) return; |
| 14494 function addDiv(top, left, height, width) { |
| 14495 var child = get$document().createElement('div'); |
| 14496 child.className = 'selection'; |
| 14497 child.style.setProperty$2('left', ('' + left + 'px')); |
| 14498 child.style.setProperty$2('top', ('' + top + 'px')); |
| 14499 child.style.setProperty$2('height', ('' + height + 'px')); |
| 14500 if (width == null) { |
| 14501 child.style.setProperty$2('right', '0px'); |
| 14502 } |
| 14503 else { |
| 14504 child.style.setProperty$2('width', ('' + width + 'px')); |
| 14505 } |
| 14506 $this._node.appendChild$1(child); |
| 14507 } |
| 14508 var toP = this._toPos.getPoint(); |
| 14509 if ($eq(toP.y, p.y)) { |
| 14510 if (toP.x < p.x) { |
| 14511 addDiv(p.y, toP.x, 22/*null.LINE_HEIGHT*/, p.x - toP.x); |
| 14512 } |
| 14513 else { |
| 14514 addDiv(p.y, p.x, 22/*null.LINE_HEIGHT*/, toP.x - p.x); |
| 14515 } |
| 14516 } |
| 14517 else { |
| 14518 if (toP.y < p.y) { |
| 14519 var tmp = toP; |
| 14520 toP = p; |
| 14521 p = tmp; |
| 14522 } |
| 14523 addDiv(p.y, p.x, 22/*null.LINE_HEIGHT*/, null); |
| 14524 if (toP.y > p.y + 22/*null.LINE_HEIGHT*/) { |
| 14525 addDiv(p.y + 22/*null.LINE_HEIGHT*/, 0, toP.y - p.y - 22/*null.LINE_HEIGHT
*/, null); |
| 14526 } |
| 14527 addDiv(toP.y, 0, 22/*null.LINE_HEIGHT*/, toP.x); |
| 14528 } |
| 14529 var p0 = this._pos.toRoot(); |
| 14530 var p1 = this._toPos.toRoot(); |
| 14531 var i0 = p0.offset; |
| 14532 var i1 = p1.offset; |
| 14533 if (i1 < i0) { |
| 14534 var tmp = i1; |
| 14535 i1 = i0; |
| 14536 i0 = tmp; |
| 14537 } |
| 14538 var text = p0.get$block().text.substring$2(i0, i1); |
| 14539 $globals.shell._textInputArea.value = text; |
| 14540 $globals.shell._textInputArea.select$0(); |
| 14541 } |
| 14542 Cursor.prototype.clearSelection = function() { |
| 14543 this._toPos = null; |
| 14544 } |
| 14545 Cursor.prototype.deleteSelection = function() { |
| 14546 if (this._toPos == null) return; |
| 14547 var p0 = this._pos; |
| 14548 var p1 = this._toPos; |
| 14549 if ($ne(p0.get$block(), p1.get$block())) { |
| 14550 p0 = p0.toRoot$0(); |
| 14551 p1 = p1.toRoot$0(); |
| 14552 } |
| 14553 if (p1.offset < p0.offset) { |
| 14554 var tmp = p0; |
| 14555 p0 = p1; |
| 14556 p1 = tmp; |
| 14557 } |
| 14558 p0.get$block().delete$2(p0.offset, p1.offset); |
| 14559 this._pos = p0.toLeaf$0(); |
| 14560 this._toPos = null; |
| 14561 } |
| 14562 Cursor.prototype.write = function(text) { |
| 14563 this.deleteSelection(); |
| 14564 this._pos.block.insertText(this._pos.offset, text); |
| 14565 this._pos.block._redraw(); |
| 14566 this._pos = this._pos.moveColumn(text.length); |
| 14567 } |
| 14568 Cursor.prototype._redraw$0 = Cursor.prototype._redraw; |
| 14569 // ********** Code for CodePosition ************** |
| 14570 function CodePosition(block, offset) { |
| 14571 this.block = block; |
| 14572 this.offset = offset; |
| 14573 // Initializers done |
| 14574 } |
| 14575 CodePosition.prototype.get$block = function() { return this.block; }; |
| 14576 CodePosition.prototype.moveLine = function(delta) { |
| 14577 if (delta == 0) return this; |
| 14578 var lineCol = this.getLineColumn(); |
| 14579 return this.block.getPosition(lineCol.line + delta, lineCol.column); |
| 14580 } |
| 14581 CodePosition.prototype.moveColumn = function(delta) { |
| 14582 return this.block.moveToOffset(this.offset + delta); |
| 14583 } |
| 14584 CodePosition.prototype.getPoint = function() { |
| 14585 return this.block.offsetToPoint(this.offset); |
| 14586 } |
| 14587 CodePosition.prototype.getLineColumn = function() { |
| 14588 return this.block.getLineColumn(this.offset); |
| 14589 } |
| 14590 CodePosition.prototype.toRoot = function() { |
| 14591 if (this.block._parent == null) return this; |
| 14592 var ret = new CodePosition(this.block._parent, this.block._parent.getOffset(th
is.block) + this.offset); |
| 14593 return ret.toRoot$0(); |
| 14594 } |
| 14595 CodePosition.prototype.toLeaf = function() { |
| 14596 return this.block.moveToOffset(this.offset); |
| 14597 } |
| 14598 CodePosition.prototype.block$0 = function() { |
| 14599 return this.block(); |
| 14600 }; |
| 14601 CodePosition.prototype.toLeaf$0 = CodePosition.prototype.toLeaf; |
| 14602 CodePosition.prototype.toRoot$0 = CodePosition.prototype.toRoot; |
| 14603 // ********** Code for BlockChildren ************** |
| 14604 function BlockChildren(_parent) { |
| 14605 this._parent = _parent; |
| 14606 // Initializers done |
| 14607 } |
| 14608 BlockChildren.prototype.iterator = function() { |
| 14609 return new BlockChildrenIterator(this._parent._firstChild); |
| 14610 } |
| 14611 BlockChildren.prototype.iterator$0 = BlockChildren.prototype.iterator; |
| 14612 // ********** Code for BlockChildrenIterator ************** |
| 14613 function BlockChildrenIterator(_child) { |
| 14614 this._child = _child; |
| 14615 // Initializers done |
| 14616 } |
| 14617 BlockChildrenIterator.prototype.next = function() { |
| 14618 var ret = this._child; |
| 14619 this._child = this._child._nextSibling; |
| 14620 return ret; |
| 14621 } |
| 14622 BlockChildrenIterator.prototype.hasNext = function() { |
| 14623 return this._child != null; |
| 14624 } |
| 14625 BlockChildrenIterator.prototype.hasNext$0 = BlockChildrenIterator.prototype.hasN
ext; |
| 14626 BlockChildrenIterator.prototype.next$0 = BlockChildrenIterator.prototype.next; |
| 14627 // ********** Code for CodeBlock ************** |
| 14628 function CodeBlock(_parent, _depth) { |
| 14629 this._depth = 0 |
| 14630 this._dirty = true |
| 14631 this._parent = _parent; |
| 14632 this._depth = _depth; |
| 14633 // Initializers done |
| 14634 this._node = get$document().createElement('div'); |
| 14635 this._node.className = 'code'; |
| 14636 } |
| 14637 CodeBlock.prototype.get$_nextSibling = function() { return this._nextSibling; }; |
| 14638 CodeBlock.prototype.set$_nextSibling = function(value) { return this._nextSiblin
g = value; }; |
| 14639 CodeBlock.prototype.get$_node = function() { return this._node; }; |
| 14640 CodeBlock.prototype.set$_node = function(value) { return this._node = value; }; |
| 14641 Object.defineProperty(CodeBlock.prototype, "text", { |
| 14642 get: CodeBlock.prototype.get$text, |
| 14643 set: CodeBlock.prototype.set$text |
| 14644 }); |
| 14645 CodeBlock.prototype.get$start = function() { |
| 14646 return new CodePosition(this, 0); |
| 14647 } |
| 14648 Object.defineProperty(CodeBlock.prototype, "start", { |
| 14649 get: CodeBlock.prototype.get$start |
| 14650 }); |
| 14651 CodeBlock.prototype.get$end = function() { |
| 14652 return new CodePosition(this, this.get$size()); |
| 14653 } |
| 14654 CodeBlock.prototype.getOffset = function(forChild) { |
| 14655 $throw("child missing"); |
| 14656 } |
| 14657 CodeBlock.prototype.getLine = function(forChild) { |
| 14658 $throw("child missing"); |
| 14659 } |
| 14660 CodeBlock.prototype._removeChild = function(child) { |
| 14661 $throw("child missing"); |
| 14662 } |
| 14663 CodeBlock.prototype.parse = function() { |
| 14664 var source = new SourceFile('fake.dart', this.get$text()); |
| 14665 var p = new Parser(source, false, false, false, 0); |
| 14666 var cu = p.compilationUnit$0(); |
| 14667 } |
| 14668 CodeBlock.prototype.markDirty = function() { |
| 14669 if (!this._dirty) { |
| 14670 this._dirty = true; |
| 14671 if (this._parent != null) { |
| 14672 this._parent._dirty = true; |
| 14673 } |
| 14674 } |
| 14675 } |
| 14676 CodeBlock.prototype.get$top = function() { |
| 14677 return this._top; |
| 14678 } |
| 14679 CodeBlock.prototype.set$top = function(newTop) { |
| 14680 if (newTop != this._top) { |
| 14681 this._top = newTop; |
| 14682 this._node.style.setProperty$2('top', ('' + this._top + 'px')); |
| 14683 } |
| 14684 } |
| 14685 Object.defineProperty(CodeBlock.prototype, "top", { |
| 14686 get: CodeBlock.prototype.get$top, |
| 14687 set: CodeBlock.prototype.set$top |
| 14688 }); |
| 14689 CodeBlock.prototype.get$height = function() { |
| 14690 return this._height; |
| 14691 } |
| 14692 CodeBlock.prototype.set$height = function(newHeight) { |
| 14693 if (newHeight != this._height) { |
| 14694 this._height = newHeight; |
| 14695 this._node.style.setProperty$2('height', ('' + this._height + 'px')); |
| 14696 } |
| 14697 } |
| 14698 Object.defineProperty(CodeBlock.prototype, "height", { |
| 14699 get: CodeBlock.prototype.get$height, |
| 14700 set: CodeBlock.prototype.set$height |
| 14701 }); |
| 14702 CodeBlock.prototype.positionFromMouse = function(p) { |
| 14703 var box = this._node.getBoundingClientRect$0(); |
| 14704 var y = p.clientY - box.top; |
| 14705 var x = p.clientX - box.left; |
| 14706 return this.positionFromPoint(x, y); |
| 14707 } |
| 14708 CodeBlock.prototype._redraw$0 = CodeBlock.prototype._redraw; |
| 14709 CodeBlock.prototype.delete$2 = CodeBlock.prototype.delete_; |
| 14710 CodeBlock.prototype.end$0 = function() { |
| 14711 return this.get$end()(); |
| 14712 }; |
| 14713 CodeBlock.prototype.getLine$1 = CodeBlock.prototype.getLine; |
| 14714 CodeBlock.prototype.getLineColumn$1 = CodeBlock.prototype.getLineColumn; |
| 14715 CodeBlock.prototype.getPosition$2 = CodeBlock.prototype.getPosition; |
| 14716 CodeBlock.prototype.insertText$2 = CodeBlock.prototype.insertText; |
| 14717 CodeBlock.prototype.moveToOffset$1 = CodeBlock.prototype.moveToOffset; |
| 14718 CodeBlock.prototype.offsetToPoint$1 = CodeBlock.prototype.offsetToPoint; |
| 14719 CodeBlock.prototype.positionFromPoint$2 = CodeBlock.prototype.positionFromPoint; |
| 14720 CodeBlock.prototype.start$0 = function() { |
| 14721 return this.get$start()(); |
| 14722 }; |
| 14723 // ********** Code for BlockBlock ************** |
| 14724 $inherits(BlockBlock, CodeBlock); |
| 14725 function BlockBlock(parent, depth) { |
| 14726 // Initializers done |
| 14727 CodeBlock.call(this, parent, depth); |
| 14728 this.set$text(''); |
| 14729 this.children = new BlockChildren(this); |
| 14730 } |
| 14731 BlockBlock.prototype.get$start = function() { |
| 14732 return this._firstChild.get$start(); |
| 14733 } |
| 14734 Object.defineProperty(BlockBlock.prototype, "start", { |
| 14735 get: BlockBlock.prototype.get$start |
| 14736 }); |
| 14737 BlockBlock.prototype.get$end = function() { |
| 14738 return this._lastChild.get$end(); |
| 14739 } |
| 14740 BlockBlock.prototype.get$size = function() { |
| 14741 var ret = 0; |
| 14742 var $$list = this.children; |
| 14743 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14744 var child = $$i.next$0(); |
| 14745 ret = ret + child.size; |
| 14746 } |
| 14747 return ret; |
| 14748 } |
| 14749 Object.defineProperty(BlockBlock.prototype, "size", { |
| 14750 get: BlockBlock.prototype.get$size |
| 14751 }); |
| 14752 BlockBlock.prototype.get$lineCount = function() { |
| 14753 var ret = 0; |
| 14754 var $$list = this.children; |
| 14755 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14756 var child = $$i.next$0(); |
| 14757 ret = ret + child.get$lineCount(); |
| 14758 } |
| 14759 return ret; |
| 14760 } |
| 14761 BlockBlock.prototype.get$text = function() { |
| 14762 var ret = new StringBufferImpl(""); |
| 14763 var $$list = this.children; |
| 14764 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14765 var child = $$i.next$0(); |
| 14766 ret.add$1(child.text); |
| 14767 } |
| 14768 return ret.toString$0(); |
| 14769 } |
| 14770 BlockBlock.prototype.set$text = function(newText) { |
| 14771 var sw = new StopwatchImplementation(); |
| 14772 sw.start(); |
| 14773 this._firstChild = this._lastChild = null; |
| 14774 var src = new SourceFile('fake.dart', newText); |
| 14775 var start = 0; |
| 14776 while (start != -1) { |
| 14777 var child = new TextBlock(this, null, this._depth + 1); |
| 14778 if (this._lastChild == null) { |
| 14779 this._firstChild = this._lastChild = child; |
| 14780 this._node.appendChild$1(child.get$_node()); |
| 14781 } |
| 14782 else { |
| 14783 this._addChildAfter(this._lastChild, child); |
| 14784 } |
| 14785 start = child.tokenizeInto$2(src, start); |
| 14786 } |
| 14787 sw.stop(); |
| 14788 print(('create structure in ' + sw.elapsedInMs() + 'msec')); |
| 14789 } |
| 14790 Object.defineProperty(BlockBlock.prototype, "text", { |
| 14791 get: BlockBlock.prototype.get$text, |
| 14792 set: BlockBlock.prototype.set$text |
| 14793 }); |
| 14794 BlockBlock.prototype.getOffset = function(forChild) { |
| 14795 var ret = 0; |
| 14796 var $$list = this.children; |
| 14797 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14798 var child = $$i.next$0(); |
| 14799 if ($eq(child, forChild)) return ret; |
| 14800 ret = ret + child.size; |
| 14801 } |
| 14802 $throw("child missing"); |
| 14803 } |
| 14804 BlockBlock.prototype.getLine = function(forChild) { |
| 14805 var ret = 0; |
| 14806 var $$list = this.children; |
| 14807 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14808 var child = $$i.next$0(); |
| 14809 if ($eq(child, forChild)) return ret; |
| 14810 ret = ret + child.get$lineCount(); |
| 14811 } |
| 14812 $throw("child missing"); |
| 14813 } |
| 14814 BlockBlock.prototype._addChildAfter = function(addAfterChild, child) { |
| 14815 this.markDirty(); |
| 14816 child._nextSibling = addAfterChild._nextSibling; |
| 14817 child._previousSibling = addAfterChild; |
| 14818 addAfterChild._nextSibling = child; |
| 14819 if (child._nextSibling == null) { |
| 14820 this._node.appendChild$1(child._node); |
| 14821 this._lastChild = child; |
| 14822 } |
| 14823 else { |
| 14824 this._node.insertBefore$2(child._node, child._nextSibling._node); |
| 14825 } |
| 14826 } |
| 14827 BlockBlock.prototype._removeChild = function(child) { |
| 14828 this.markDirty(); |
| 14829 if (child._previousSibling != null) { |
| 14830 child._previousSibling._nextSibling = child._nextSibling; |
| 14831 } |
| 14832 else { |
| 14833 this._firstChild = child._nextSibling; |
| 14834 } |
| 14835 if (child._nextSibling != null) { |
| 14836 child._nextSibling._previousSibling = child._previousSibling; |
| 14837 } |
| 14838 else { |
| 14839 this._lastChild = child._previousSibling; |
| 14840 } |
| 14841 this._node.removeChild$1(child._node); |
| 14842 } |
| 14843 BlockBlock.prototype.insertText = function(offset, newText) { |
| 14844 var index = 0; |
| 14845 var $$list = this.children; |
| 14846 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14847 var child = $$i.next$0(); |
| 14848 var childSize = child.size; |
| 14849 if (offset < childSize) { |
| 14850 child.insertText$2(offset, newText); |
| 14851 return; |
| 14852 } |
| 14853 else if (offset == childSize) { |
| 14854 var newChild = new TextBlock(this, newText, this._depth + 1); |
| 14855 this._addChildAfter(child, newChild); |
| 14856 return; |
| 14857 } |
| 14858 offset = offset - childSize; |
| 14859 index = index + 1; |
| 14860 } |
| 14861 $throw("help"); |
| 14862 } |
| 14863 BlockBlock.prototype.delete_ = function(from, to) { |
| 14864 var keepChild = null; |
| 14865 for (var child = this._firstChild; |
| 14866 child != null; child = child.get$_nextSibling()) { |
| 14867 var childSize = child.size; |
| 14868 if (keepChild != null) { |
| 14869 this._removeChild(child); |
| 14870 if (to <= childSize) { |
| 14871 keepChild.set$_text(keepChild.get$_text() + child.get$_text().substring$
1(to)); |
| 14872 return; |
| 14873 } |
| 14874 } |
| 14875 else if (from <= childSize) { |
| 14876 if (to < childSize) { |
| 14877 child.delete$2(from, to); |
| 14878 return; |
| 14879 } |
| 14880 else { |
| 14881 child.delete$2(from, childSize); |
| 14882 keepChild = child; |
| 14883 } |
| 14884 } |
| 14885 from = from - childSize; |
| 14886 to = to - childSize; |
| 14887 } |
| 14888 $throw("help"); |
| 14889 } |
| 14890 BlockBlock.prototype._redraw = function() { |
| 14891 if (!this._dirty) return; |
| 14892 this._dirty = false; |
| 14893 var childTop = 0; |
| 14894 for (var child = this._firstChild; |
| 14895 child != null; child = child.get$_nextSibling()) { |
| 14896 child.top = childTop; |
| 14897 child._redraw$0(); |
| 14898 childTop = childTop + child.height; |
| 14899 } |
| 14900 this.set$height(childTop); |
| 14901 } |
| 14902 BlockBlock.prototype.moveToOffset = function(offset) { |
| 14903 var $$list = this.children; |
| 14904 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14905 var child = $$i.next$0(); |
| 14906 var childSize = child.size; |
| 14907 if (offset < childSize) { |
| 14908 return child.moveToOffset$1(offset); |
| 14909 } |
| 14910 offset = offset - childSize; |
| 14911 } |
| 14912 return this.get$end(); |
| 14913 } |
| 14914 BlockBlock.prototype.positionFromPoint = function(x, y) { |
| 14915 if (y < this.get$top()) return this.get$start(); |
| 14916 var $$list = this.children; |
| 14917 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14918 var child = $$i.next$0(); |
| 14919 if (child.top <= y && (child.top + child.height) >= y) { |
| 14920 return child.positionFromPoint$2(x, y - child.top); |
| 14921 } |
| 14922 } |
| 14923 return this.get$end(); |
| 14924 } |
| 14925 BlockBlock.prototype.getPosition = function(line, column) { |
| 14926 if (line < 0) return this.get$start(); |
| 14927 var $$list = this.children; |
| 14928 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14929 var child = $$i.next$0(); |
| 14930 if (line < child.get$lineCount()) return child.getPosition$2(line, column); |
| 14931 line = line - child.get$lineCount(); |
| 14932 } |
| 14933 return this.get$end(); |
| 14934 } |
| 14935 BlockBlock.prototype.getLineColumn = function(offset) { |
| 14936 if (offset < 0) return new LineColumn(0, 0); |
| 14937 var childLine = 0; |
| 14938 var $$list = this.children; |
| 14939 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14940 var child = $$i.next$0(); |
| 14941 var childSize = child.size; |
| 14942 if (offset < childSize) { |
| 14943 var ret = child.getLineColumn$1(offset); |
| 14944 return new LineColumn(ret.line + childLine, ret.column); |
| 14945 } |
| 14946 offset = offset - childSize; |
| 14947 childLine = childLine + child.get$lineCount(); |
| 14948 } |
| 14949 return new LineColumn(this.get$lineCount(), 0); |
| 14950 } |
| 14951 BlockBlock.prototype.offsetToPoint = function(offset) { |
| 14952 if (offset < 0) return new Point(0, 0); |
| 14953 var $$list = this.children; |
| 14954 for (var $$i = this.children.iterator(); $$i.hasNext$0(); ) { |
| 14955 var child = $$i.next$0(); |
| 14956 var childSize = child.size; |
| 14957 if (offset < childSize) { |
| 14958 var ret = child.offsetToPoint$1(offset); |
| 14959 return new Point(ret.x, ret.y + child.top); |
| 14960 } |
| 14961 offset = offset - childSize; |
| 14962 } |
| 14963 return new Point(0, this.get$top() + this.get$height()); |
| 14964 } |
| 14965 BlockBlock.prototype._redraw$0 = BlockBlock.prototype._redraw; |
| 14966 BlockBlock.prototype.delete$2 = BlockBlock.prototype.delete_; |
| 14967 BlockBlock.prototype.end$0 = function() { |
| 14968 return this.get$end()(); |
| 14969 }; |
| 14970 BlockBlock.prototype.getLine$1 = BlockBlock.prototype.getLine; |
| 14971 BlockBlock.prototype.getLineColumn$1 = BlockBlock.prototype.getLineColumn; |
| 14972 BlockBlock.prototype.getPosition$2 = BlockBlock.prototype.getPosition; |
| 14973 BlockBlock.prototype.insertText$2 = BlockBlock.prototype.insertText; |
| 14974 BlockBlock.prototype.moveToOffset$1 = BlockBlock.prototype.moveToOffset; |
| 14975 BlockBlock.prototype.offsetToPoint$1 = BlockBlock.prototype.offsetToPoint; |
| 14976 BlockBlock.prototype.positionFromPoint$2 = BlockBlock.prototype.positionFromPoin
t; |
| 14977 BlockBlock.prototype.start$0 = function() { |
| 14978 return this.get$start()(); |
| 14979 }; |
| 14980 // ********** Code for TextBlock ************** |
| 14981 $inherits(TextBlock, CodeBlock); |
| 14982 function TextBlock(parent, _text, depth) { |
| 14983 this._text = _text; |
| 14984 // Initializers done |
| 14985 CodeBlock.call(this, parent, depth); |
| 14986 } |
| 14987 TextBlock.prototype.get$_text = function() { return this._text; }; |
| 14988 TextBlock.prototype.set$_text = function(value) { return this._text = value; }; |
| 14989 TextBlock.prototype.get$size = function() { |
| 14990 return this._text.length; |
| 14991 } |
| 14992 Object.defineProperty(TextBlock.prototype, "size", { |
| 14993 get: TextBlock.prototype.get$size |
| 14994 }); |
| 14995 TextBlock.prototype.get$lineCount = function() { |
| 14996 return this._lineStarts.length; |
| 14997 } |
| 14998 TextBlock.prototype.get$text = function() { |
| 14999 return this._text; |
| 15000 } |
| 15001 TextBlock.prototype.set$text = function(newText) { |
| 15002 this._text = newText; |
| 15003 this.markDirty(); |
| 15004 } |
| 15005 Object.defineProperty(TextBlock.prototype, "text", { |
| 15006 get: TextBlock.prototype.get$text, |
| 15007 set: TextBlock.prototype.set$text |
| 15008 }); |
| 15009 TextBlock.prototype.insertText = function(offset, newText) { |
| 15010 this._text = this._text.substring(0, offset) + newText + this._text.substring(
offset); |
| 15011 this.markDirty(); |
| 15012 } |
| 15013 TextBlock.prototype.delete_ = function(from, to) { |
| 15014 this.markDirty(); |
| 15015 if (to == this._text.length) { |
| 15016 if (from == 0) { |
| 15017 this._parent._removeChild(this); |
| 15018 } |
| 15019 else { |
| 15020 this._text = this._text.substring(0, from); |
| 15021 } |
| 15022 } |
| 15023 else { |
| 15024 this._text = this._text.substring(0, from) + this._text.substring(to); |
| 15025 } |
| 15026 } |
| 15027 TextBlock.prototype.tokenizeInto = function(src, start) { |
| 15028 var $this = this; // closure support |
| 15029 this._lineStarts = new ListFactory(); |
| 15030 this._lineStarts.add(start); |
| 15031 var html = new StringBufferImpl(""); |
| 15032 var tokenizer = new Tokenizer(src, false, start); |
| 15033 var depth = 0; |
| 15034 function addLineStarts(token) { |
| 15035 var text = src.get$text(); |
| 15036 for (var index = token.start; |
| 15037 index < token.end; index++) { |
| 15038 if (text.charCodeAt(index) == 10) { |
| 15039 $this._lineStarts.add(index - start + 1); |
| 15040 } |
| 15041 } |
| 15042 } |
| 15043 while (true) { |
| 15044 var token = tokenizer.next(); |
| 15045 if ($eq(token.kind, 1/*TokenKind.END_OF_FILE*/)) { |
| 15046 this._node.innerHTML = html.toString$0(); |
| 15047 if (start == 0) this._text = src.get$text(); |
| 15048 else this._text = src.get$text().substring(start); |
| 15049 this.set$height(this.get$lineCount() * 22/*null.LINE_HEIGHT*/); |
| 15050 return -1; |
| 15051 } |
| 15052 else if ($eq(token.kind, 63/*TokenKind.WHITESPACE*/)) { |
| 15053 if (src.get$text().charCodeAt(token.get$end() - 1) == 10) { |
| 15054 this._text = src.get$text().substring(start, token.get$end()); |
| 15055 this._node.innerHTML = html.toString$0(); |
| 15056 this.set$height(this.get$lineCount() * 22/*null.LINE_HEIGHT*/); |
| 15057 return token.get$end(); |
| 15058 } |
| 15059 } |
| 15060 else if ($eq(token.kind, 64/*TokenKind.COMMENT*/)) { |
| 15061 addLineStarts(token); |
| 15062 } |
| 15063 else if ($eq(token.kind, 58/*TokenKind.STRING*/)) { |
| 15064 addLineStarts(token); |
| 15065 } |
| 15066 else if ($eq(token.kind, 59/*TokenKind.STRING_PART*/)) { |
| 15067 addLineStarts(token); |
| 15068 } |
| 15069 var kind = classify(token); |
| 15070 var stringClass = ''; |
| 15071 var text = htmlEscape(token.text); |
| 15072 if (kind != null) { |
| 15073 html.add$1(('<span class="' + kind + ' ' + stringClass + '">' + text + '</
span>')); |
| 15074 } |
| 15075 else { |
| 15076 html.add$1(('<span>' + text + '</span>')); |
| 15077 } |
| 15078 } |
| 15079 } |
| 15080 TextBlock.prototype._redraw = function() { |
| 15081 if (!this._dirty) return; |
| 15082 this._dirty = false; |
| 15083 var initialText = this._text; |
| 15084 var end = this.tokenizeInto(new SourceFile('fake.dart', this._text), 0); |
| 15085 if (this._text.length < initialText.length) { |
| 15086 var extraText = initialText.substring$1(this._text.length); |
| 15087 this._parent.insertText(this._parent.getOffset(this) + this._text.length, ex
traText); |
| 15088 } |
| 15089 } |
| 15090 TextBlock.prototype.moveToOffset = function(offset) { |
| 15091 if (offset < 0 || offset >= this._text.length) { |
| 15092 return this._parent.moveToOffset(this._parent.getOffset(this) + offset); |
| 15093 } |
| 15094 return new CodePosition(this, offset); |
| 15095 } |
| 15096 TextBlock.prototype.positionFromPoint = function(x, y) { |
| 15097 return this.getPosition((y / 22/*null.LINE_HEIGHT*/).floor(), (x / 8/*null.CHA
R_WIDTH*/).round()); |
| 15098 } |
| 15099 TextBlock.prototype.getPosition = function(line, column) { |
| 15100 if (line < 0 || line >= this.get$lineCount()) { |
| 15101 return this._parent.getPosition(this._parent.getLine(this) + line, column); |
| 15102 } |
| 15103 var maxOffset; |
| 15104 if (line < this._lineStarts.length - 1) { |
| 15105 maxOffset = this._lineStarts.$index(line + 1) - 1; |
| 15106 } |
| 15107 else { |
| 15108 maxOffset = this._text.length - 1; |
| 15109 } |
| 15110 var offset = Math.min(this._lineStarts.$index(line) + column, maxOffset); |
| 15111 return new CodePosition(this, offset); |
| 15112 } |
| 15113 TextBlock.prototype.getLineColumn = function(offset) { |
| 15114 if (this._lineStarts == null) { |
| 15115 return new LineColumn(0, 0); |
| 15116 } |
| 15117 var previousStart = 0; |
| 15118 var line = 1; |
| 15119 for (; line < this._lineStarts.length; line++) { |
| 15120 var start = this._lineStarts.$index(line); |
| 15121 if (start > offset) { |
| 15122 break; |
| 15123 } |
| 15124 previousStart = start; |
| 15125 } |
| 15126 return new LineColumn(line - 1, offset - previousStart); |
| 15127 } |
| 15128 TextBlock.prototype.offsetToPoint = function(offset) { |
| 15129 var lc = this.getLineColumn(offset); |
| 15130 return new Point(lc.column * 8/*null.CHAR_WIDTH*/, this.get$top() + (lc.line *
22/*null.LINE_HEIGHT*/)); |
| 15131 } |
| 15132 TextBlock.prototype._redraw$0 = TextBlock.prototype._redraw; |
| 15133 TextBlock.prototype.delete$2 = TextBlock.prototype.delete_; |
| 15134 TextBlock.prototype.getLineColumn$1 = TextBlock.prototype.getLineColumn; |
| 15135 TextBlock.prototype.getPosition$2 = TextBlock.prototype.getPosition; |
| 15136 TextBlock.prototype.insertText$2 = TextBlock.prototype.insertText; |
| 15137 TextBlock.prototype.moveToOffset$1 = TextBlock.prototype.moveToOffset; |
| 15138 TextBlock.prototype.offsetToPoint$1 = TextBlock.prototype.offsetToPoint; |
| 15139 TextBlock.prototype.positionFromPoint$2 = TextBlock.prototype.positionFromPoint; |
| 15140 TextBlock.prototype.tokenizeInto$2 = TextBlock.prototype.tokenizeInto; |
| 15141 // ********** Code for KeyBindings ************** |
| 15142 function KeyBindings(node, bindings, handleText, handleUnknown) { |
| 15143 this.node = node; |
| 15144 this.bindings = bindings; |
| 15145 this.handleText = handleText; |
| 15146 this.handleUnknown = handleUnknown; |
| 15147 // Initializers done |
| 15148 this.node.addEventListener$3('textInput', this.get$onTextInput(), false); |
| 15149 this.node.addEventListener$3('keydown', this.get$onKeydown(), false); |
| 15150 } |
| 15151 KeyBindings._getModifiers = function(event) { |
| 15152 var ret = ''; |
| 15153 if (event.ctrlKey) { |
| 15154 ret = ret + 'Control-'; |
| 15155 } |
| 15156 if (event.altKey) { |
| 15157 ret = ret + 'Alt-'; |
| 15158 } |
| 15159 if (event.metaKey) { |
| 15160 ret = ret + 'Meta-'; |
| 15161 } |
| 15162 if (event.shiftKey) { |
| 15163 ret = ret + 'Shift-'; |
| 15164 } |
| 15165 return ret; |
| 15166 } |
| 15167 KeyBindings._hexDigit = function(c) { |
| 15168 if (c >= 48 && c <= 57) { |
| 15169 return c - 48; |
| 15170 } |
| 15171 else if (c >= 97 && c <= 102) { |
| 15172 return c - 87; |
| 15173 } |
| 15174 else if (c >= 65 && c <= 70) { |
| 15175 return c - 55; |
| 15176 } |
| 15177 else { |
| 15178 return -1; |
| 15179 } |
| 15180 } |
| 15181 KeyBindings.parseHex = function(hex) { |
| 15182 var result = 0; |
| 15183 for (var i = 0; |
| 15184 i < hex.length; i++) { |
| 15185 var digit = KeyBindings._hexDigit(hex.charCodeAt(i)); |
| 15186 result = (result << 4) + digit; |
| 15187 } |
| 15188 return result; |
| 15189 } |
| 15190 KeyBindings.translate = function(event) { |
| 15191 var ret = const$144/*KeyBindings._remap*/.$index(event.keyIdentifier); |
| 15192 if (ret == null) ret = event.keyIdentifier; |
| 15193 if ($eq(ret, '')) { |
| 15194 return null; |
| 15195 } |
| 15196 else if (ret.startsWith$1('U+')) { |
| 15197 if (event.ctrlKey || event.altKey || event.metaKey) { |
| 15198 return KeyBindings._getModifiers(event) + Strings.String$fromCharCodes$fac
tory([KeyBindings.parseHex(ret.substring$2(2, ret.length))]); |
| 15199 } |
| 15200 else { |
| 15201 return null; |
| 15202 } |
| 15203 } |
| 15204 else { |
| 15205 return KeyBindings._getModifiers(event) + ret; |
| 15206 } |
| 15207 } |
| 15208 KeyBindings.prototype.onTextInput = function(event) { |
| 15209 var text = event.data; |
| 15210 var ret; |
| 15211 if (this.bindings.$index(text) != null) { |
| 15212 ret = this.bindings.$index(text)(); |
| 15213 } |
| 15214 else { |
| 15215 ret = this.handleText.call$1(text); |
| 15216 } |
| 15217 $globals.shell._editor._redraw(); |
| 15218 return ret; |
| 15219 } |
| 15220 KeyBindings.prototype.get$onTextInput = function() { |
| 15221 return KeyBindings.prototype.onTextInput.bind(this); |
| 15222 } |
| 15223 KeyBindings.prototype.onKeydown = function(event) { |
| 15224 var key = KeyBindings.translate(event); |
| 15225 if (key != null) { |
| 15226 if (this.bindings.$index(key) != null) { |
| 15227 this.bindings.$index(key)(); |
| 15228 event.preventDefault(); |
| 15229 } |
| 15230 else { |
| 15231 if (this.handleUnknown.call$1(key)) { |
| 15232 event.preventDefault(); |
| 15233 } |
| 15234 else { |
| 15235 event.stopPropagation(); |
| 15236 } |
| 15237 } |
| 15238 } |
| 15239 else { |
| 15240 event.stopPropagation(); |
| 15241 } |
| 15242 $globals.shell._editor._redraw(); |
| 15243 return false; |
| 15244 } |
| 15245 KeyBindings.prototype.get$onKeydown = function() { |
| 15246 return KeyBindings.prototype.onKeydown.bind(this); |
| 15247 } |
| 15248 // ********** Code for Classification ************** |
| 15249 function Classification() {} |
| 15250 // ********** Code for top level ************** |
| 15251 function main() { |
| 15252 var systemPath = getRootPath(get$window()) + '/..'; |
| 15253 var userPath = getRootPath(get$window().parent); |
| 15254 if (get$window() !== get$window().parent) { |
| 15255 if (!get$document().implementation.hasFeature('dart', '')) { |
| 15256 initialize(systemPath, userPath, ['--suppress_warnings']); |
| 15257 get$window().addEventListener('DOMContentLoaded', $wrap_call$1((function (
e) { |
| 15258 return frogify(get$window().parent); |
| 15259 }) |
| 15260 ), false); |
| 15261 } |
| 15262 } |
| 15263 else { |
| 15264 $globals.shell = new Shell(); |
| 15265 get$document().body.appendChild($globals.shell._node); |
| 15266 initialize(systemPath, userPath, const$146/*const []*/); |
| 15267 $globals.world.messageHandler = $globals.shell.get$handleMessage(); |
| 15268 } |
| 15269 } |
| 15270 function getRootPath(window) { |
| 15271 var url = window.location.href; |
| 15272 var tail = url.lastIndexOf('/', url.length); |
| 15273 var dir = url.substring(0, tail); |
| 15274 return dir; |
| 15275 } |
| 15276 function inject(code, win, name) { |
| 15277 var doc = win.document; |
| 15278 var script = doc.createElement('script'); |
| 15279 script.innerHTML = code + ('\n//@ sourceURL=' + name); |
| 15280 script.type = 'application/javascript'; |
| 15281 doc.body.appendChild(script); |
| 15282 } |
| 15283 function frogify(win) { |
| 15284 var doc = win.document; |
| 15285 var n = doc.scripts.length; |
| 15286 for (var i = 0; |
| 15287 i < n; ++i) { |
| 15288 var script = doc.scripts.$index(i); |
| 15289 if ($eq(script.type, 'application/dart')) { |
| 15290 var src = script.src; |
| 15291 var input = null; |
| 15292 var name = null; |
| 15293 if ($eq(src, '')) { |
| 15294 input = script.innerHTML; |
| 15295 name = null; |
| 15296 } |
| 15297 else { |
| 15298 input = $globals.world.files.readAll(src); |
| 15299 name = ('' + src + '.js'); |
| 15300 } |
| 15301 $globals.world.files.writeString('input.dart'/*null.DART_FILENAME*/, input
); |
| 15302 $globals.world.reset(); |
| 15303 var success = $globals.world.compile(); |
| 15304 if (success) { |
| 15305 inject($globals.world.getGeneratedCode(), win, name); |
| 15306 } |
| 15307 else { |
| 15308 inject('window.alert("compilation failed");', win, name); |
| 15309 } |
| 15310 } |
| 15311 } |
| 15312 } |
| 15313 function initialize(systemPath, userPath, flags) { |
| 15314 var fs = new DomFileSystem(userPath); |
| 15315 var options0 = [null, null, ('--libdir=' + systemPath + '/lib')]; |
| 15316 options0.addAll(flags); |
| 15317 options0.add('input.dart'/*null.DART_FILENAME*/); |
| 15318 parseOptions(systemPath, options0, fs); |
| 15319 initializeWorld(fs); |
| 15320 } |
| 15321 var shell; |
| 15322 function htmlEscape(text) { |
| 15323 return text.replaceAll('&', '&').replaceAll('>', '>').replaceAll('<', '
<'); |
| 15324 } |
| 15325 function _looksLikeType(name) { |
| 15326 return _looksLikePublicType(name) || _looksLikePrivateType(name); |
| 15327 } |
| 15328 function _looksLikePublicType(name) { |
| 15329 return name.length >= 2 && isUpper(name[0]) && isLower(name[1]); |
| 15330 } |
| 15331 function _looksLikePrivateType(name) { |
| 15332 return (name.length >= 3 && name[0] == '_' && isUpper(name[1]) && isLower(name
[2])); |
| 15333 } |
| 15334 function isUpper(s) { |
| 15335 return s.toLowerCase() != s; |
| 15336 } |
| 15337 function isLower(s) { |
| 15338 return s.toUpperCase() != s; |
| 15339 } |
| 15340 function classify(token) { |
| 15341 switch (token.kind) { |
| 15342 case 65/*TokenKind.ERROR*/: |
| 15343 |
| 15344 return "e"/*Classification.ERROR*/; |
| 15345 |
| 15346 case 70/*TokenKind.IDENTIFIER*/: |
| 15347 |
| 15348 if (_looksLikeType(token.get$text()) || token.get$text() == 'num' || token
.get$text() == 'bool' || token.get$text() == 'int' || token.get$text() == 'doubl
e') { |
| 15349 return "t"/*Classification.TYPE_IDENTIFIER*/; |
| 15350 } |
| 15351 return "i"/*Classification.IDENTIFIER*/; |
| 15352 |
| 15353 case 114/*TokenKind.VOID*/: |
| 15354 |
| 15355 return "t"/*Classification.TYPE_IDENTIFIER*/; |
| 15356 |
| 15357 case 109/*TokenKind.THIS*/: |
| 15358 case 107/*TokenKind.SUPER*/: |
| 15359 |
| 15360 return "r"/*Classification.SPECIAL_IDENTIFIER*/; |
| 15361 |
| 15362 case 58/*TokenKind.STRING*/: |
| 15363 case 59/*TokenKind.STRING_PART*/: |
| 15364 case 66/*TokenKind.INCOMPLETE_STRING*/: |
| 15365 case 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/: |
| 15366 case 69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/: |
| 15367 |
| 15368 return "s"/*Classification.STRING*/; |
| 15369 |
| 15370 case 60/*TokenKind.INTEGER*/: |
| 15371 case 61/*TokenKind.HEX_INTEGER*/: |
| 15372 case 62/*TokenKind.DOUBLE*/: |
| 15373 |
| 15374 return "n"/*Classification.NUMBER*/; |
| 15375 |
| 15376 case 64/*TokenKind.COMMENT*/: |
| 15377 case 67/*TokenKind.INCOMPLETE_COMMENT*/: |
| 15378 |
| 15379 return "c"/*Classification.COMMENT*/; |
| 15380 |
| 15381 case 9/*TokenKind.ARROW*/: |
| 15382 |
| 15383 return "a"/*Classification.ARROW_OPERATOR*/; |
| 15384 |
| 15385 case 13/*TokenKind.HASHBANG*/: |
| 15386 case 2/*TokenKind.LPAREN*/: |
| 15387 case 3/*TokenKind.RPAREN*/: |
| 15388 case 4/*TokenKind.LBRACK*/: |
| 15389 case 5/*TokenKind.RBRACK*/: |
| 15390 case 6/*TokenKind.LBRACE*/: |
| 15391 case 7/*TokenKind.RBRACE*/: |
| 15392 case 8/*TokenKind.COLON*/: |
| 15393 case 10/*TokenKind.SEMICOLON*/: |
| 15394 case 11/*TokenKind.COMMA*/: |
| 15395 case 14/*TokenKind.DOT*/: |
| 15396 case 15/*TokenKind.ELLIPSIS*/: |
| 15397 |
| 15398 return "p"/*Classification.PUNCTUATION*/; |
| 15399 |
| 15400 case 16/*TokenKind.INCR*/: |
| 15401 case 17/*TokenKind.DECR*/: |
| 15402 case 18/*TokenKind.BIT_NOT*/: |
| 15403 case 19/*TokenKind.NOT*/: |
| 15404 case 20/*TokenKind.ASSIGN*/: |
| 15405 case 21/*TokenKind.ASSIGN_OR*/: |
| 15406 case 22/*TokenKind.ASSIGN_XOR*/: |
| 15407 case 23/*TokenKind.ASSIGN_AND*/: |
| 15408 case 24/*TokenKind.ASSIGN_SHL*/: |
| 15409 case 25/*TokenKind.ASSIGN_SAR*/: |
| 15410 case 26/*TokenKind.ASSIGN_SHR*/: |
| 15411 case 27/*TokenKind.ASSIGN_ADD*/: |
| 15412 case 28/*TokenKind.ASSIGN_SUB*/: |
| 15413 case 29/*TokenKind.ASSIGN_MUL*/: |
| 15414 case 30/*TokenKind.ASSIGN_DIV*/: |
| 15415 case 31/*TokenKind.ASSIGN_TRUNCDIV*/: |
| 15416 case 32/*TokenKind.ASSIGN_MOD*/: |
| 15417 case 33/*TokenKind.CONDITIONAL*/: |
| 15418 case 34/*TokenKind.OR*/: |
| 15419 case 35/*TokenKind.AND*/: |
| 15420 case 36/*TokenKind.BIT_OR*/: |
| 15421 case 37/*TokenKind.BIT_XOR*/: |
| 15422 case 38/*TokenKind.BIT_AND*/: |
| 15423 case 39/*TokenKind.SHL*/: |
| 15424 case 40/*TokenKind.SAR*/: |
| 15425 case 41/*TokenKind.SHR*/: |
| 15426 case 42/*TokenKind.ADD*/: |
| 15427 case 43/*TokenKind.SUB*/: |
| 15428 case 44/*TokenKind.MUL*/: |
| 15429 case 45/*TokenKind.DIV*/: |
| 15430 case 46/*TokenKind.TRUNCDIV*/: |
| 15431 case 47/*TokenKind.MOD*/: |
| 15432 case 48/*TokenKind.EQ*/: |
| 15433 case 49/*TokenKind.NE*/: |
| 15434 case 50/*TokenKind.EQ_STRICT*/: |
| 15435 case 51/*TokenKind.NE_STRICT*/: |
| 15436 case 52/*TokenKind.LT*/: |
| 15437 case 53/*TokenKind.GT*/: |
| 15438 case 54/*TokenKind.LTE*/: |
| 15439 case 55/*TokenKind.GTE*/: |
| 15440 case 56/*TokenKind.INDEX*/: |
| 15441 case 57/*TokenKind.SETINDEX*/: |
| 15442 |
| 15443 return "o"/*Classification.OPERATOR*/; |
| 15444 |
| 15445 case 12/*TokenKind.HASH*/: |
| 15446 case 71/*TokenKind.ABSTRACT*/: |
| 15447 case 72/*TokenKind.ASSERT*/: |
| 15448 case 73/*TokenKind.CLASS*/: |
| 15449 case 74/*TokenKind.EXTENDS*/: |
| 15450 case 75/*TokenKind.FACTORY*/: |
| 15451 case 76/*TokenKind.GET*/: |
| 15452 case 77/*TokenKind.IMPLEMENTS*/: |
| 15453 case 78/*TokenKind.IMPORT*/: |
| 15454 case 79/*TokenKind.INTERFACE*/: |
| 15455 case 80/*TokenKind.LIBRARY*/: |
| 15456 case 81/*TokenKind.NATIVE*/: |
| 15457 case 82/*TokenKind.NEGATE*/: |
| 15458 case 83/*TokenKind.OPERATOR*/: |
| 15459 case 84/*TokenKind.SET*/: |
| 15460 case 85/*TokenKind.SOURCE*/: |
| 15461 case 86/*TokenKind.STATIC*/: |
| 15462 case 87/*TokenKind.TYPEDEF*/: |
| 15463 case 89/*TokenKind.BREAK*/: |
| 15464 case 90/*TokenKind.CASE*/: |
| 15465 case 91/*TokenKind.CATCH*/: |
| 15466 case 92/*TokenKind.CONST*/: |
| 15467 case 93/*TokenKind.CONTINUE*/: |
| 15468 case 94/*TokenKind.DEFAULT*/: |
| 15469 case 95/*TokenKind.DO*/: |
| 15470 case 96/*TokenKind.ELSE*/: |
| 15471 case 97/*TokenKind.FALSE*/: |
| 15472 case 99/*TokenKind.FINALLY*/: |
| 15473 case 100/*TokenKind.FOR*/: |
| 15474 case 101/*TokenKind.IF*/: |
| 15475 case 102/*TokenKind.IN*/: |
| 15476 case 103/*TokenKind.IS*/: |
| 15477 case 104/*TokenKind.NEW*/: |
| 15478 case 105/*TokenKind.NULL*/: |
| 15479 case 106/*TokenKind.RETURN*/: |
| 15480 case 108/*TokenKind.SWITCH*/: |
| 15481 case 110/*TokenKind.THROW*/: |
| 15482 case 111/*TokenKind.TRUE*/: |
| 15483 case 112/*TokenKind.TRY*/: |
| 15484 case 115/*TokenKind.WHILE*/: |
| 15485 case 113/*TokenKind.VAR*/: |
| 15486 case 98/*TokenKind.FINAL*/: |
| 15487 |
| 15488 return "k"/*Classification.KEYWORD*/; |
| 15489 |
| 15490 case 63/*TokenKind.WHITESPACE*/: |
| 15491 case 1/*TokenKind.END_OF_FILE*/: |
| 15492 |
| 15493 return null/*Classification.NONE*/; |
| 15494 |
| 15495 default: |
| 15496 |
| 15497 return null/*Classification.NONE*/; |
| 15498 |
| 15499 } |
| 15500 } |
| 15501 // ********** Generic Type Inheritance ************** |
| 15502 /** Implements extends for generic types. */ |
| 15503 function $inheritsMembers(child, parent) { |
| 15504 child = child.prototype; |
| 15505 parent = parent.prototype; |
| 15506 Object.getOwnPropertyNames(parent).forEach(function(name) { |
| 15507 if (typeof(child[name]) == 'undefined') child[name] = parent[name]; |
| 15508 }); |
| 15509 } |
| 15510 $inheritsMembers(_DoubleLinkedQueueEntrySentinel_E, DoubleLinkedQueueEntry_E); |
| 15511 $inheritsMembers(_DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V, DoubleLinkedQ
ueueEntry_KeyValuePair_K$V); |
| 15512 // ********** Globals ************** |
| 15513 function $static_init(){ |
| 15514 $globals._GREEN_COLOR = '\u001b[32m'; |
| 15515 $globals._MAGENTA_COLOR = '\u001b[35m'; |
| 15516 $globals._NO_COLOR = '\u001b[0m'; |
| 15517 $globals._RED_COLOR = '\u001b[31m'; |
| 15518 } |
| 15519 var const$1 = new NoMoreElementsException()/*const NoMoreElementsException()*/; |
| 15520 var const$143 = new IllegalAccessException()/*const IllegalAccessException()*/; |
| 15521 var const$144 = _constMap(['U+001B', 'Esc', 'U+0008', 'Delete', 'U+0009', 'Tab',
'U+0020', 'Space', 'Shift', '', 'Control', '', 'Alt', '', 'Meta', ''])/*const { |
| 15522 'U+001B':'Esc', 'U+0008':'Delete', 'U+0009':'Tab', 'U+0020':'Space', |
| 15523 'Shift':'', 'Control':'', 'Alt':'', 'Meta':'' |
| 15524 }*/; |
| 15525 var const$146 = ImmutableList.ImmutableList$from$factory([])/*const []*/; |
| 15526 var const$3 = new _DeletedKeySentinel()/*const _DeletedKeySentinel()*/; |
| 15527 var const$5 = new EmptyQueueException()/*const EmptyQueueException()*/; |
| 15528 var $globals = {}; |
| 15529 $static_init(); |
| 15530 main(); |
OLD | NEW |