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 $eq(x, y) { |
| 97 if (x == null) return y == null; |
| 98 return (typeof(x) == 'number' && typeof(y) == 'number') || |
| 99 (typeof(x) == 'boolean' && typeof(y) == 'boolean') || |
| 100 (typeof(x) == 'string' && typeof(y) == 'string') |
| 101 ? x == y : x.$eq(y); |
| 102 } |
| 103 // TODO(jimhug): Should this or should it not match equals? |
| 104 Object.prototype.$eq = function(other) { return this === other; } |
| 105 function $mod(x, y) { |
| 106 if (typeof(x) == 'number' && typeof(y) == 'number') { |
| 107 var result = x % y; |
| 108 if (result == 0) { |
| 109 return 0; // Make sure we don't return -0.0. |
| 110 } else if (result < 0) { |
| 111 if (y < 0) { |
| 112 return result - y; |
| 113 } else { |
| 114 return result + y; |
| 115 } |
| 116 } |
| 117 return result; |
| 118 } else { |
| 119 return x.$mod(y); |
| 120 } |
| 121 } |
| 122 function $ne(x, y) { |
| 123 if (x == null) return y != null; |
| 124 return (typeof(x) == 'number' && typeof(y) == 'number') || |
| 125 (typeof(x) == 'boolean' && typeof(y) == 'boolean') || |
| 126 (typeof(x) == 'string' && typeof(y) == 'string') |
| 127 ? x != y : !x.$eq(y); |
| 128 } |
| 129 function $truncdiv(x, y) { |
| 130 if (typeof(x) == 'number' && typeof(y) == 'number') { |
| 131 if (y == 0) $throw(new IntegerDivisionByZeroException()); |
| 132 var tmp = x / y; |
| 133 return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp); |
| 134 } else { |
| 135 return x.$truncdiv(y); |
| 136 } |
| 137 } |
| 138 // ********** Code for Object ************** |
| 139 Object.prototype.get$dynamic = function() { |
| 140 return this; |
| 141 } |
| 142 Object.prototype.noSuchMethod = function(name, args) { |
| 143 $throw(new NoSuchMethodException(this, name, args)); |
| 144 } |
| 145 Object.prototype._checkExtends$0 = function() { |
| 146 return this.noSuchMethod("_checkExtends", []); |
| 147 }; |
| 148 Object.prototype._checkNonStatic$1 = function($0) { |
| 149 return this.noSuchMethod("_checkNonStatic", [$0]); |
| 150 }; |
| 151 Object.prototype._get$3 = function($0, $1, $2) { |
| 152 return this.noSuchMethod("_get", [$0, $1, $2]); |
| 153 }; |
| 154 Object.prototype._get$3$isDynamic = function($0, $1, $2, isDynamic) { |
| 155 return this.noSuchMethod("_get", [$0, $1, $2, isDynamic]); |
| 156 }; |
| 157 Object.prototype._get$4 = function($0, $1, $2, $3) { |
| 158 return this.noSuchMethod("_get", [$0, $1, $2, $3]); |
| 159 }; |
| 160 Object.prototype._set$4 = function($0, $1, $2, $3) { |
| 161 return this.noSuchMethod("_set", [$0, $1, $2, $3]); |
| 162 }; |
| 163 Object.prototype._set$4$isDynamic = function($0, $1, $2, $3, isDynamic) { |
| 164 return this.noSuchMethod("_set", [$0, $1, $2, $3, isDynamic]); |
| 165 }; |
| 166 Object.prototype._set$5 = function($0, $1, $2, $3, $4) { |
| 167 return this.noSuchMethod("_set", [$0, $1, $2, $3, $4]); |
| 168 }; |
| 169 Object.prototype._wrapDomCallback$2 = function($0, $1) { |
| 170 return this.noSuchMethod("_wrapDomCallback", [$0, $1]); |
| 171 }; |
| 172 Object.prototype.add$1 = function($0) { |
| 173 return this.noSuchMethod("add", [$0]); |
| 174 }; |
| 175 Object.prototype.addAll$1 = function($0) { |
| 176 return this.noSuchMethod("addAll", [$0]); |
| 177 }; |
| 178 Object.prototype.addDirectSubtype$1 = function($0) { |
| 179 return this.noSuchMethod("addDirectSubtype", [$0]); |
| 180 }; |
| 181 Object.prototype.addMethod$2 = function($0, $1) { |
| 182 return this.noSuchMethod("addMethod", [$0, $1]); |
| 183 }; |
| 184 Object.prototype.addSource$1 = function($0) { |
| 185 return this.noSuchMethod("addSource", [$0]); |
| 186 }; |
| 187 Object.prototype.block$0 = function() { |
| 188 return this.noSuchMethod("block", []); |
| 189 }; |
| 190 Object.prototype.canInvoke$2 = function($0, $1) { |
| 191 return this.noSuchMethod("canInvoke", [$0, $1]); |
| 192 }; |
| 193 Object.prototype.checkFirstClass$1 = function($0) { |
| 194 return this.noSuchMethod("checkFirstClass", [$0]); |
| 195 }; |
| 196 Object.prototype.compareTo$1 = function($0) { |
| 197 return this.noSuchMethod("compareTo", [$0]); |
| 198 }; |
| 199 Object.prototype.computeValue$0 = function() { |
| 200 return this.noSuchMethod("computeValue", []); |
| 201 }; |
| 202 Object.prototype.contains$1 = function($0) { |
| 203 return this.noSuchMethod("contains", [$0]); |
| 204 }; |
| 205 Object.prototype.containsKey$1 = function($0) { |
| 206 return this.noSuchMethod("containsKey", [$0]); |
| 207 }; |
| 208 Object.prototype.convertTo$3 = function($0, $1, $2) { |
| 209 return this.noSuchMethod("convertTo", [$0, $1, $2]); |
| 210 }; |
| 211 Object.prototype.convertTo$4 = function($0, $1, $2, $3) { |
| 212 return this.noSuchMethod("convertTo", [$0, $1, $2, $3]); |
| 213 }; |
| 214 Object.prototype.copyWithNewType$2 = function($0, $1) { |
| 215 return this.noSuchMethod("copyWithNewType", [$0, $1]); |
| 216 }; |
| 217 Object.prototype.end$0 = function() { |
| 218 return this.noSuchMethod("end", []); |
| 219 }; |
| 220 Object.prototype.endsWith$1 = function($0) { |
| 221 return this.noSuchMethod("endsWith", [$0]); |
| 222 }; |
| 223 Object.prototype.ensureSubtypeOf$3 = function($0, $1, $2) { |
| 224 return this.noSuchMethod("ensureSubtypeOf", [$0, $1, $2]); |
| 225 }; |
| 226 Object.prototype.every$1 = function($0) { |
| 227 return this.noSuchMethod("every", [$0]); |
| 228 }; |
| 229 Object.prototype.filter$1 = function($0) { |
| 230 return this.noSuchMethod("filter", [$0]); |
| 231 }; |
| 232 Object.prototype.findTypeByName$1 = function($0) { |
| 233 return this.noSuchMethod("findTypeByName", [$0]); |
| 234 }; |
| 235 Object.prototype.forEach$1 = function($0) { |
| 236 return this.noSuchMethod("forEach", [$0]); |
| 237 }; |
| 238 Object.prototype.genValue$2 = function($0, $1) { |
| 239 return this.noSuchMethod("genValue", [$0, $1]); |
| 240 }; |
| 241 Object.prototype.generate$1 = function($0) { |
| 242 return this.noSuchMethod("generate", [$0]); |
| 243 }; |
| 244 Object.prototype.getColumn$2 = function($0, $1) { |
| 245 return this.noSuchMethod("getColumn", [$0, $1]); |
| 246 }; |
| 247 Object.prototype.getConstructor$1 = function($0) { |
| 248 return this.noSuchMethod("getConstructor", [$0]); |
| 249 }; |
| 250 Object.prototype.getFactory$2 = function($0, $1) { |
| 251 return this.noSuchMethod("getFactory", [$0, $1]); |
| 252 }; |
| 253 Object.prototype.getKeys$0 = function() { |
| 254 return this.noSuchMethod("getKeys", []); |
| 255 }; |
| 256 Object.prototype.getLine$1 = function($0) { |
| 257 return this.noSuchMethod("getLine", [$0]); |
| 258 }; |
| 259 Object.prototype.getMember$1 = function($0) { |
| 260 return this.noSuchMethod("getMember", [$0]); |
| 261 }; |
| 262 Object.prototype.getOrMakeConcreteType$1 = function($0) { |
| 263 return this.noSuchMethod("getOrMakeConcreteType", [$0]); |
| 264 }; |
| 265 Object.prototype.getValues$0 = function() { |
| 266 return this.noSuchMethod("getValues", []); |
| 267 }; |
| 268 Object.prototype.get_$3 = function($0, $1, $2) { |
| 269 return this.noSuchMethod("get_", [$0, $1, $2]); |
| 270 }; |
| 271 Object.prototype.group$1 = function($0) { |
| 272 return this.noSuchMethod("group", [$0]); |
| 273 }; |
| 274 Object.prototype.hasNext$0 = function() { |
| 275 return this.noSuchMethod("hasNext", []); |
| 276 }; |
| 277 Object.prototype.hashCode$0 = function() { |
| 278 return this.noSuchMethod("hashCode", []); |
| 279 }; |
| 280 Object.prototype.indexOf$1 = function($0) { |
| 281 return this.noSuchMethod("indexOf", [$0]); |
| 282 }; |
| 283 Object.prototype.instanceOf$3$isTrue$forceCheck = function($0, $1, $2, isTrue, f
orceCheck) { |
| 284 return this.noSuchMethod("instanceOf", [$0, $1, $2, isTrue, forceCheck]); |
| 285 }; |
| 286 Object.prototype.instanceOf$4 = function($0, $1, $2, $3) { |
| 287 return this.noSuchMethod("instanceOf", [$0, $1, $2, $3]); |
| 288 }; |
| 289 Object.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 290 return this.noSuchMethod("invoke", [$0, $1, $2, $3]); |
| 291 }; |
| 292 Object.prototype.invoke$4$isDynamic = function($0, $1, $2, $3, isDynamic) { |
| 293 return this.noSuchMethod("invoke", [$0, $1, $2, $3, isDynamic]); |
| 294 }; |
| 295 Object.prototype.invoke$5 = function($0, $1, $2, $3, $4) { |
| 296 return this.noSuchMethod("invoke", [$0, $1, $2, $3, $4]); |
| 297 }; |
| 298 Object.prototype.is$List = function() { |
| 299 return false; |
| 300 }; |
| 301 Object.prototype.is$RegExp = function() { |
| 302 return false; |
| 303 }; |
| 304 Object.prototype.isAssignable$1 = function($0) { |
| 305 return this.noSuchMethod("isAssignable", [$0]); |
| 306 }; |
| 307 Object.prototype.isEmpty$0 = function() { |
| 308 return this.noSuchMethod("isEmpty", []); |
| 309 }; |
| 310 Object.prototype.isFile$0 = function() { |
| 311 return this.noSuchMethod("isFile", []); |
| 312 }; |
| 313 Object.prototype.isSubtypeOf$1 = function($0) { |
| 314 return this.noSuchMethod("isSubtypeOf", [$0]); |
| 315 }; |
| 316 Object.prototype.iterator$0 = function() { |
| 317 return this.noSuchMethod("iterator", []); |
| 318 }; |
| 319 Object.prototype.last$0 = function() { |
| 320 return this.noSuchMethod("last", []); |
| 321 }; |
| 322 Object.prototype.markUsed$0 = function() { |
| 323 return this.noSuchMethod("markUsed", []); |
| 324 }; |
| 325 Object.prototype.namesInOrder$1 = function($0) { |
| 326 return this.noSuchMethod("namesInOrder", [$0]); |
| 327 }; |
| 328 Object.prototype.needsConversion$1 = function($0) { |
| 329 return this.noSuchMethod("needsConversion", [$0]); |
| 330 }; |
| 331 Object.prototype.next$0 = function() { |
| 332 return this.noSuchMethod("next", []); |
| 333 }; |
| 334 Object.prototype.provideFieldSyntax$0 = function() { |
| 335 return this.noSuchMethod("provideFieldSyntax", []); |
| 336 }; |
| 337 Object.prototype.providePropertySyntax$0 = function() { |
| 338 return this.noSuchMethod("providePropertySyntax", []); |
| 339 }; |
| 340 Object.prototype.removeLast$0 = function() { |
| 341 return this.noSuchMethod("removeLast", []); |
| 342 }; |
| 343 Object.prototype.replaceAll$2 = function($0, $1) { |
| 344 return this.noSuchMethod("replaceAll", [$0, $1]); |
| 345 }; |
| 346 Object.prototype.replaceFirst$2 = function($0, $1) { |
| 347 return this.noSuchMethod("replaceFirst", [$0, $1]); |
| 348 }; |
| 349 Object.prototype.resolve$0 = function() { |
| 350 return this.noSuchMethod("resolve", []); |
| 351 }; |
| 352 Object.prototype.resolveTypeParams$1 = function($0) { |
| 353 return this.noSuchMethod("resolveTypeParams", [$0]); |
| 354 }; |
| 355 Object.prototype.setDefinition$1 = function($0) { |
| 356 return this.noSuchMethod("setDefinition", [$0]); |
| 357 }; |
| 358 Object.prototype.set_$4 = function($0, $1, $2, $3) { |
| 359 return this.noSuchMethod("set_", [$0, $1, $2, $3]); |
| 360 }; |
| 361 Object.prototype.some$1 = function($0) { |
| 362 return this.noSuchMethod("some", [$0]); |
| 363 }; |
| 364 Object.prototype.sort$1 = function($0) { |
| 365 return this.noSuchMethod("sort", [$0]); |
| 366 }; |
| 367 Object.prototype.start$0 = function() { |
| 368 return this.noSuchMethod("start", []); |
| 369 }; |
| 370 Object.prototype.startsWith$1 = function($0) { |
| 371 return this.noSuchMethod("startsWith", [$0]); |
| 372 }; |
| 373 Object.prototype.substring$1 = function($0) { |
| 374 return this.noSuchMethod("substring", [$0]); |
| 375 }; |
| 376 Object.prototype.substring$2 = function($0, $1) { |
| 377 return this.noSuchMethod("substring", [$0, $1]); |
| 378 }; |
| 379 Object.prototype.toString$0 = function() { |
| 380 return this.toString(); |
| 381 }; |
| 382 Object.prototype.visit$1 = function($0) { |
| 383 return this.noSuchMethod("visit", [$0]); |
| 384 }; |
| 385 Object.prototype.visitBinaryExpression$1 = function($0) { |
| 386 return this.noSuchMethod("visitBinaryExpression", [$0]); |
| 387 }; |
| 388 Object.prototype.visitPostfixExpression$1 = function($0) { |
| 389 return this.noSuchMethod("visitPostfixExpression", [$0]); |
| 390 }; |
| 391 Object.prototype.visitSources$0 = function() { |
| 392 return this.noSuchMethod("visitSources", []); |
| 393 }; |
| 394 Object.prototype.writeDefinition$2 = function($0, $1) { |
| 395 return this.noSuchMethod("writeDefinition", [$0, $1]); |
| 396 }; |
| 397 // ********** Code for Clock ************** |
| 398 function Clock() {} |
| 399 Clock.now = function() { |
| 400 return new Date().getTime(); |
| 401 } |
| 402 Clock.frequency = function() { |
| 403 return 1000; |
| 404 } |
| 405 // ********** Code for NoSuchMethodException ************** |
| 406 function NoSuchMethodException(_receiver, _functionName, _arguments) { |
| 407 this._receiver = _receiver; |
| 408 this._functionName = _functionName; |
| 409 this._arguments = _arguments; |
| 410 // Initializers done |
| 411 } |
| 412 NoSuchMethodException.prototype.toString = function() { |
| 413 var sb = new StringBufferImpl(""); |
| 414 for (var i = 0; |
| 415 i < this._arguments.length; i++) { |
| 416 if (i > 0) { |
| 417 sb.add(", "); |
| 418 } |
| 419 sb.add(this._arguments.$index(i)); |
| 420 } |
| 421 sb.add("]"); |
| 422 return ("NoSuchMethodException - receiver: '" + this._receiver + "' ") + ("fun
ction name: '" + this._functionName + "' arguments: [" + sb + "]"); |
| 423 } |
| 424 NoSuchMethodException.prototype.toString$0 = NoSuchMethodException.prototype.toS
tring; |
| 425 // ********** Code for ObjectNotClosureException ************** |
| 426 function ObjectNotClosureException() { |
| 427 // Initializers done |
| 428 } |
| 429 ObjectNotClosureException.prototype.toString = function() { |
| 430 return "Object is not closure"; |
| 431 } |
| 432 ObjectNotClosureException.prototype.toString$0 = ObjectNotClosureException.proto
type.toString; |
| 433 // ********** Code for StackOverflowException ************** |
| 434 function StackOverflowException() { |
| 435 // Initializers done |
| 436 } |
| 437 StackOverflowException.prototype.toString = function() { |
| 438 return "Stack Overflow"; |
| 439 } |
| 440 StackOverflowException.prototype.toString$0 = StackOverflowException.prototype.t
oString; |
| 441 // ********** Code for BadNumberFormatException ************** |
| 442 function BadNumberFormatException() {} |
| 443 BadNumberFormatException.prototype.toString = function() { |
| 444 return ("BadNumberFormatException: '" + this._s + "'"); |
| 445 } |
| 446 BadNumberFormatException.prototype.toString$0 = BadNumberFormatException.prototy
pe.toString; |
| 447 // ********** Code for NullPointerException ************** |
| 448 function NullPointerException() { |
| 449 // Initializers done |
| 450 } |
| 451 NullPointerException.prototype.toString = function() { |
| 452 return "NullPointerException"; |
| 453 } |
| 454 NullPointerException.prototype.toString$0 = NullPointerException.prototype.toStr
ing; |
| 455 // ********** Code for NoMoreElementsException ************** |
| 456 function NoMoreElementsException() { |
| 457 // Initializers done |
| 458 } |
| 459 NoMoreElementsException.prototype.toString = function() { |
| 460 return "NoMoreElementsException"; |
| 461 } |
| 462 NoMoreElementsException.prototype.toString$0 = NoMoreElementsException.prototype
.toString; |
| 463 // ********** Code for EmptyQueueException ************** |
| 464 function EmptyQueueException() { |
| 465 // Initializers done |
| 466 } |
| 467 EmptyQueueException.prototype.toString = function() { |
| 468 return "EmptyQueueException"; |
| 469 } |
| 470 EmptyQueueException.prototype.toString$0 = EmptyQueueException.prototype.toStrin
g; |
| 471 // ********** Code for Function ************** |
| 472 Function.prototype.to$call$0 = function() { |
| 473 this.call$0 = this.$genStub(0); |
| 474 this.to$call$0 = function() { return this.call$0; }; |
| 475 return this.call$0; |
| 476 }; |
| 477 Function.prototype.call$0 = function() { |
| 478 return this.to$call$0()(); |
| 479 }; |
| 480 function to$call$0(f) { return f && f.to$call$0(); } |
| 481 Function.prototype.to$call$1 = function() { |
| 482 this.call$1 = this.$genStub(1); |
| 483 this.to$call$1 = function() { return this.call$1; }; |
| 484 return this.call$1; |
| 485 }; |
| 486 Function.prototype.call$1 = function($0) { |
| 487 return this.to$call$1()($0); |
| 488 }; |
| 489 function to$call$1(f) { return f && f.to$call$1(); } |
| 490 Function.prototype.to$call$2 = function() { |
| 491 this.call$2 = this.$genStub(2); |
| 492 this.to$call$2 = function() { return this.call$2; }; |
| 493 return this.call$2; |
| 494 }; |
| 495 Function.prototype.call$2 = function($0, $1) { |
| 496 return this.to$call$2()($0, $1); |
| 497 }; |
| 498 function to$call$2(f) { return f && f.to$call$2(); } |
| 499 // ********** Code for Math ************** |
| 500 Math.parseInt = function(str) { |
| 501 var ret = parseInt(str); |
| 502 if (isNaN(ret)) $throw(new BadNumberFormatException(str)); |
| 503 return ret; |
| 504 } |
| 505 Math.parseDouble = function(str) { |
| 506 var ret = parseFloat(str); |
| 507 if (isNaN(ret) && str != 'NaN') $throw(new BadNumberFormatException(str)); |
| 508 return ret; |
| 509 } |
| 510 Math.min = function(a, b) { |
| 511 if (a == b) return a; |
| 512 if (a < b) { |
| 513 if (isNaN(b)) return b; |
| 514 else return a; |
| 515 } |
| 516 if (isNaN(a)) return a; |
| 517 else return b; |
| 518 } |
| 519 // ********** Code for Strings ************** |
| 520 function Strings() {} |
| 521 Strings.join = function(strings, separator) { |
| 522 return StringBase.join(strings, separator); |
| 523 } |
| 524 // ********** Code for top level ************** |
| 525 function print(obj) { |
| 526 return _print(obj); |
| 527 } |
| 528 function _print(obj) { |
| 529 if (typeof console == 'object') { |
| 530 if (obj) obj = obj.toString(); |
| 531 console.log(obj); |
| 532 } else { |
| 533 write(obj); |
| 534 write('\n'); |
| 535 } |
| 536 } |
| 537 function _map(itemsAndKeys) { |
| 538 var ret = new LinkedHashMapImplementation(); |
| 539 for (var i = 0; |
| 540 i < itemsAndKeys.length; ) { |
| 541 ret.$setindex(itemsAndKeys.$index(i++), itemsAndKeys.$index(i++)); |
| 542 } |
| 543 return ret; |
| 544 } |
| 545 function _toDartException(e) { |
| 546 function attachStack(dartEx) { |
| 547 // TODO(jmesserly): setting the stack property is not a long term solution. |
| 548 var stack = e.stack; |
| 549 // The stack contains the error message, and the stack is all that is |
| 550 // printed (the exception's toString() is never called). Make the Dart |
| 551 // exception's toString() be the dominant message. |
| 552 if (typeof stack == 'string') { |
| 553 var message = dartEx.toString(); |
| 554 if (/^(Type|Range)Error:/.test(stack)) { |
| 555 // Indent JS message (it can be helpful) so new message stands out. |
| 556 stack = ' (' + stack.substring(0, stack.indexOf('\n')) + ')\n' + |
| 557 stack.substring(stack.indexOf('\n') + 1); |
| 558 } |
| 559 stack = message + '\n' + stack; |
| 560 } |
| 561 dartEx.stack = stack; |
| 562 return dartEx; |
| 563 } |
| 564 |
| 565 if (e instanceof TypeError) { |
| 566 switch(e.type) { |
| 567 case 'property_not_function': |
| 568 case 'called_non_callable': |
| 569 if (e.arguments[0] == null) { |
| 570 return attachStack(new NullPointerException()); |
| 571 } else { |
| 572 return attachStack(new ObjectNotClosureException()); |
| 573 } |
| 574 break; |
| 575 case 'non_object_property_call': |
| 576 case 'non_object_property_load': |
| 577 return attachStack(new NullPointerException()); |
| 578 break; |
| 579 case 'undefined_method': |
| 580 var mname = e.arguments[0]; |
| 581 if (typeof(mname) == 'string' && (mname.indexOf('call$') == 0 |
| 582 || mname == 'call' || mname == 'apply')) { |
| 583 return attachStack(new ObjectNotClosureException()); |
| 584 } else { |
| 585 // TODO(jmesserly): fix noSuchMethod on operators so we don't hit this |
| 586 return attachStack(new NoSuchMethodException('', e.arguments[0], [])); |
| 587 } |
| 588 break; |
| 589 } |
| 590 } else if (e instanceof RangeError) { |
| 591 if (e.message.indexOf('call stack') >= 0) { |
| 592 return attachStack(new StackOverflowException()); |
| 593 } |
| 594 } |
| 595 return e; |
| 596 } |
| 597 // ********** Library dart:coreimpl ************** |
| 598 // ********** Code for ListFactory ************** |
| 599 ListFactory = Array; |
| 600 ListFactory.prototype.is$List = function(){return true}; |
| 601 ListFactory.ListFactory$from$factory = function(other) { |
| 602 var list = []; |
| 603 for (var $$i = other.iterator(); $$i.hasNext$0(); ) { |
| 604 var e = $$i.next$0(); |
| 605 list.add(e); |
| 606 } |
| 607 return list; |
| 608 } |
| 609 ListFactory.prototype.add = function(value) { |
| 610 this.push(value); |
| 611 } |
| 612 ListFactory.prototype.addLast = function(value) { |
| 613 this.push(value); |
| 614 } |
| 615 ListFactory.prototype.addAll = function(collection) { |
| 616 for (var $$i = collection.iterator(); $$i.hasNext$0(); ) { |
| 617 var item = $$i.next$0(); |
| 618 this.add(item); |
| 619 } |
| 620 } |
| 621 ListFactory.prototype.clear = function() { |
| 622 this.length = 0; |
| 623 } |
| 624 ListFactory.prototype.removeLast = function() { |
| 625 return this.pop(); |
| 626 } |
| 627 ListFactory.prototype.last = function() { |
| 628 return this[this.length - 1]; |
| 629 } |
| 630 ListFactory.prototype.getRange = function(start, length) { |
| 631 return this.slice(start, start + length); |
| 632 } |
| 633 ListFactory.prototype.isEmpty = function() { |
| 634 return this.length == 0; |
| 635 } |
| 636 ListFactory.prototype.iterator = function() { |
| 637 return new ListIterator(this); |
| 638 } |
| 639 ListFactory.prototype.add$1 = ListFactory.prototype.add; |
| 640 ListFactory.prototype.addAll$1 = ListFactory.prototype.addAll; |
| 641 ListFactory.prototype.every$1 = function($0) { |
| 642 return this.every(to$call$1($0)); |
| 643 }; |
| 644 ListFactory.prototype.filter$1 = function($0) { |
| 645 return this.filter(to$call$1($0)); |
| 646 }; |
| 647 ListFactory.prototype.forEach$1 = function($0) { |
| 648 return this.forEach(to$call$1($0)); |
| 649 }; |
| 650 ListFactory.prototype.indexOf$1 = ListFactory.prototype.indexOf; |
| 651 ListFactory.prototype.isEmpty$0 = ListFactory.prototype.isEmpty; |
| 652 ListFactory.prototype.iterator$0 = ListFactory.prototype.iterator; |
| 653 ListFactory.prototype.last$0 = ListFactory.prototype.last; |
| 654 ListFactory.prototype.removeLast$0 = ListFactory.prototype.removeLast; |
| 655 ListFactory.prototype.some$1 = function($0) { |
| 656 return this.some(to$call$1($0)); |
| 657 }; |
| 658 ListFactory.prototype.sort$1 = function($0) { |
| 659 return this.sort(to$call$2($0)); |
| 660 }; |
| 661 ListFactory_E = ListFactory; |
| 662 ListFactory_K = ListFactory; |
| 663 ListFactory_String = ListFactory; |
| 664 ListFactory_V = ListFactory; |
| 665 // ********** Code for ListIterator ************** |
| 666 function ListIterator(array) { |
| 667 this._array = array; |
| 668 this._pos = 0; |
| 669 // Initializers done |
| 670 } |
| 671 ListIterator.prototype.hasNext = function() { |
| 672 return this._array.length > this._pos; |
| 673 } |
| 674 ListIterator.prototype.next = function() { |
| 675 if (!this.hasNext()) { |
| 676 $throw(const$7/*const NoMoreElementsException()*/); |
| 677 } |
| 678 return this._array.$index(this._pos++); |
| 679 } |
| 680 ListIterator.prototype.hasNext$0 = ListIterator.prototype.hasNext; |
| 681 ListIterator.prototype.next$0 = ListIterator.prototype.next; |
| 682 // ********** Code for JSSyntaxRegExp ************** |
| 683 function JSSyntaxRegExp(pattern, multiLine, ignoreCase) { |
| 684 // Initializers done |
| 685 JSSyntaxRegExp._create$ctor.call(this, pattern, ($eq(multiLine, true) ? 'm' :
'') + ($eq(ignoreCase, true) ? 'i' : '')); |
| 686 } |
| 687 JSSyntaxRegExp._create$ctor = function(pattern, flags) { |
| 688 this.re = new RegExp(pattern, flags); |
| 689 this.pattern = pattern; |
| 690 this.multiLine = this.re.multiline; |
| 691 this.ignoreCase = this.re.ignoreCase; |
| 692 } |
| 693 JSSyntaxRegExp._create$ctor.prototype = JSSyntaxRegExp.prototype; |
| 694 JSSyntaxRegExp.prototype.is$RegExp = function(){return true}; |
| 695 JSSyntaxRegExp.prototype.firstMatch = function(str) { |
| 696 var m = this._exec(str); |
| 697 return m == null ? null : new MatchImplementation(this.pattern, str, this._mat
chStart(m), this.get$_lastIndex(), m); |
| 698 } |
| 699 JSSyntaxRegExp.prototype._exec = function(str) { |
| 700 return this.re.exec(str); |
| 701 } |
| 702 JSSyntaxRegExp.prototype._matchStart = function(m) { |
| 703 return m.index; |
| 704 } |
| 705 JSSyntaxRegExp.prototype.get$_lastIndex = function() { |
| 706 return this.re.lastIndex; |
| 707 } |
| 708 JSSyntaxRegExp.prototype.allMatches = function(str) { |
| 709 return new _AllMatchesIterable(this, str); |
| 710 } |
| 711 // ********** Code for MatchImplementation ************** |
| 712 function MatchImplementation(pattern, str, _start, _end, _groups) { |
| 713 this.pattern = pattern; |
| 714 this.str = str; |
| 715 this._start = _start; |
| 716 this._end = _end; |
| 717 this._groups = _groups; |
| 718 // Initializers done |
| 719 } |
| 720 MatchImplementation.prototype.start = function() { |
| 721 return this._start; |
| 722 } |
| 723 MatchImplementation.prototype.get$start = function() { |
| 724 return MatchImplementation.prototype.start.bind(this); |
| 725 } |
| 726 MatchImplementation.prototype.end = function() { |
| 727 return this._end; |
| 728 } |
| 729 MatchImplementation.prototype.get$end = function() { |
| 730 return MatchImplementation.prototype.end.bind(this); |
| 731 } |
| 732 MatchImplementation.prototype.group = function(group) { |
| 733 return this._groups.$index(group); |
| 734 } |
| 735 MatchImplementation.prototype.$index = function(group) { |
| 736 return this._groups.$index(group); |
| 737 } |
| 738 MatchImplementation.prototype.end$0 = MatchImplementation.prototype.end; |
| 739 MatchImplementation.prototype.group$1 = MatchImplementation.prototype.group; |
| 740 MatchImplementation.prototype.start$0 = MatchImplementation.prototype.start; |
| 741 // ********** Code for _AllMatchesIterable ************** |
| 742 function _AllMatchesIterable(_re, _str) { |
| 743 this._re = _re; |
| 744 this._str = _str; |
| 745 // Initializers done |
| 746 } |
| 747 _AllMatchesIterable.prototype.iterator = function() { |
| 748 return new _AllMatchesIterator(this._re, this._str); |
| 749 } |
| 750 _AllMatchesIterable.prototype.iterator$0 = _AllMatchesIterable.prototype.iterato
r; |
| 751 // ********** Code for _AllMatchesIterator ************** |
| 752 function _AllMatchesIterator(re, _str) { |
| 753 this._str = _str; |
| 754 this._done = false; |
| 755 this._re = new JSSyntaxRegExp._create$ctor(re.pattern, 'g' + (re.multiLine ? '
m' : '') + (re.ignoreCase ? 'i' : '')); |
| 756 // Initializers done |
| 757 } |
| 758 _AllMatchesIterator.prototype.next = function() { |
| 759 if (!this.hasNext()) { |
| 760 $throw(const$7/*const NoMoreElementsException()*/); |
| 761 } |
| 762 var next = this._next; |
| 763 this._next = null; |
| 764 return next; |
| 765 } |
| 766 _AllMatchesIterator.prototype.hasNext = function() { |
| 767 if (this._done) { |
| 768 return false; |
| 769 } |
| 770 else if (this._next != null) { |
| 771 return true; |
| 772 } |
| 773 this._next = this._re.firstMatch(this._str); |
| 774 if (this._next == null) { |
| 775 this._done = true; |
| 776 return false; |
| 777 } |
| 778 else { |
| 779 return true; |
| 780 } |
| 781 } |
| 782 _AllMatchesIterator.prototype.hasNext$0 = _AllMatchesIterator.prototype.hasNext; |
| 783 _AllMatchesIterator.prototype.next$0 = _AllMatchesIterator.prototype.next; |
| 784 // ********** Code for NumImplementation ************** |
| 785 NumImplementation = Number; |
| 786 NumImplementation.prototype.isNaN = function() { |
| 787 return isNaN(this); |
| 788 } |
| 789 NumImplementation.prototype.isNegative = function() { |
| 790 return this == 0 ? (1 / this) < 0 : this < 0; |
| 791 } |
| 792 NumImplementation.prototype.hashCode = function() { |
| 793 return this & 0xFFFFFFF; |
| 794 } |
| 795 NumImplementation.prototype.toInt = function() { |
| 796 if (isNaN(this)) throw new BadNumberFormatException("NaN"); |
| 797 if ((this == Infinity) || (this == -Infinity)) { |
| 798 throw new BadNumberFormatException("Infinity"); |
| 799 } |
| 800 var truncated = (this < 0) ? Math.ceil(this) : Math.floor(this); |
| 801 |
| 802 if (truncated == -0.0) return 0; |
| 803 return truncated; |
| 804 } |
| 805 NumImplementation.prototype.toDouble = function() { |
| 806 return this + 0; |
| 807 } |
| 808 NumImplementation.prototype.compareTo = function(other) { |
| 809 var thisValue = this.toDouble(); |
| 810 if (thisValue < other) { |
| 811 return -1; |
| 812 } |
| 813 else if (thisValue > other) { |
| 814 return 1; |
| 815 } |
| 816 else if (thisValue == other) { |
| 817 if (thisValue == 0) { |
| 818 var thisIsNegative = this.isNegative(); |
| 819 var otherIsNegative = other.isNegative(); |
| 820 if ($eq(thisIsNegative, otherIsNegative)) return 0; |
| 821 if (thisIsNegative) return -1; |
| 822 return 1; |
| 823 } |
| 824 return 0; |
| 825 } |
| 826 else if (this.isNaN()) { |
| 827 if (other.isNaN()) { |
| 828 return 0; |
| 829 } |
| 830 return 1; |
| 831 } |
| 832 else { |
| 833 return -1; |
| 834 } |
| 835 } |
| 836 NumImplementation.prototype.compareTo$1 = NumImplementation.prototype.compareTo; |
| 837 NumImplementation.prototype.hashCode$0 = NumImplementation.prototype.hashCode; |
| 838 // ********** Code for HashMapImplementation ************** |
| 839 function HashMapImplementation() { |
| 840 // Initializers done |
| 841 this._numberOfEntries = 0; |
| 842 this._numberOfDeleted = 0; |
| 843 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 844 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 845 this._values = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 846 } |
| 847 HashMapImplementation.HashMapImplementation$from$factory = function(other) { |
| 848 var result = new HashMapImplementation(); |
| 849 other.forEach((function (key, value) { |
| 850 result.$setindex(key, value); |
| 851 }) |
| 852 ); |
| 853 return result; |
| 854 } |
| 855 HashMapImplementation._computeLoadLimit = function(capacity) { |
| 856 return $truncdiv((capacity * 3), 4); |
| 857 } |
| 858 HashMapImplementation._firstProbe = function(hashCode, length) { |
| 859 return hashCode & (length - 1); |
| 860 } |
| 861 HashMapImplementation._nextProbe = function(currentProbe, numberOfProbes, length
) { |
| 862 return (currentProbe + numberOfProbes) & (length - 1); |
| 863 } |
| 864 HashMapImplementation.prototype._probeForAdding = function(key) { |
| 865 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 866 var numberOfProbes = 1; |
| 867 var initialHash = hash; |
| 868 var insertionIndex = -1; |
| 869 while (true) { |
| 870 var existingKey = this._keys.$index(hash); |
| 871 if (existingKey == null) { |
| 872 if (insertionIndex < 0) return hash; |
| 873 return insertionIndex; |
| 874 } |
| 875 else if ($eq(existingKey, key)) { |
| 876 return hash; |
| 877 } |
| 878 else if ((insertionIndex < 0) && (const$2/*HashMapImplementation._DELETED_KE
Y*/ === existingKey)) { |
| 879 insertionIndex = hash; |
| 880 } |
| 881 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 882 } |
| 883 } |
| 884 HashMapImplementation.prototype._probeForLookup = function(key) { |
| 885 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 886 var numberOfProbes = 1; |
| 887 var initialHash = hash; |
| 888 while (true) { |
| 889 var existingKey = this._keys.$index(hash); |
| 890 if (existingKey == null) return -1; |
| 891 if ($eq(existingKey, key)) return hash; |
| 892 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 893 } |
| 894 } |
| 895 HashMapImplementation.prototype._ensureCapacity = function() { |
| 896 var newNumberOfEntries = this._numberOfEntries + 1; |
| 897 if (newNumberOfEntries >= this._loadLimit) { |
| 898 this._grow(this._keys.length * 2); |
| 899 return; |
| 900 } |
| 901 var capacity = this._keys.length; |
| 902 var numberOfFreeOrDeleted = capacity - newNumberOfEntries; |
| 903 var numberOfFree = numberOfFreeOrDeleted - this._numberOfDeleted; |
| 904 if (this._numberOfDeleted > numberOfFree) { |
| 905 this._grow(this._keys.length); |
| 906 } |
| 907 } |
| 908 HashMapImplementation._isPowerOfTwo = function(x) { |
| 909 return ((x & (x - 1)) == 0); |
| 910 } |
| 911 HashMapImplementation.prototype._grow = function(newCapacity) { |
| 912 var capacity = this._keys.length; |
| 913 this._loadLimit = HashMapImplementation._computeLoadLimit(newCapacity); |
| 914 var oldKeys = this._keys; |
| 915 var oldValues = this._values; |
| 916 this._keys = new ListFactory(newCapacity); |
| 917 this._values = new ListFactory(newCapacity); |
| 918 for (var i = 0; |
| 919 i < capacity; i++) { |
| 920 var key = oldKeys.$index(i); |
| 921 if (key == null || key === const$2/*HashMapImplementation._DELETED_KEY*/) { |
| 922 continue; |
| 923 } |
| 924 var value = oldValues.$index(i); |
| 925 var newIndex = this._probeForAdding(key); |
| 926 this._keys.$setindex(newIndex, key); |
| 927 this._values.$setindex(newIndex, value); |
| 928 } |
| 929 this._numberOfDeleted = 0; |
| 930 } |
| 931 HashMapImplementation.prototype.$setindex = function(key, value) { |
| 932 this._ensureCapacity(); |
| 933 var index = this._probeForAdding(key); |
| 934 if ((this._keys.$index(index) == null) || (this._keys.$index(index) === const$
2/*HashMapImplementation._DELETED_KEY*/)) { |
| 935 this._numberOfEntries++; |
| 936 } |
| 937 this._keys.$setindex(index, key); |
| 938 this._values.$setindex(index, value); |
| 939 } |
| 940 HashMapImplementation.prototype.$index = function(key) { |
| 941 var index = this._probeForLookup(key); |
| 942 if (index < 0) return null; |
| 943 return this._values.$index(index); |
| 944 } |
| 945 HashMapImplementation.prototype.remove = function(key) { |
| 946 var index = this._probeForLookup(key); |
| 947 if (index >= 0) { |
| 948 this._numberOfEntries--; |
| 949 var value = this._values.$index(index); |
| 950 this._values.$setindex(index); |
| 951 this._keys.$setindex(index, const$2/*HashMapImplementation._DELETED_KEY*/); |
| 952 this._numberOfDeleted++; |
| 953 return value; |
| 954 } |
| 955 return null; |
| 956 } |
| 957 HashMapImplementation.prototype.isEmpty = function() { |
| 958 return this._numberOfEntries == 0; |
| 959 } |
| 960 HashMapImplementation.prototype.get$length = function() { |
| 961 return this._numberOfEntries; |
| 962 } |
| 963 Object.defineProperty(HashMapImplementation.prototype, "length", { |
| 964 get: HashMapImplementation.prototype.get$length |
| 965 }); |
| 966 HashMapImplementation.prototype.forEach = function(f) { |
| 967 var length = this._keys.length; |
| 968 for (var i = 0; |
| 969 i < length; i++) { |
| 970 if ((this._keys.$index(i) != null) && (this._keys.$index(i) !== const$2/*Has
hMapImplementation._DELETED_KEY*/)) { |
| 971 f(this._keys.$index(i), this._values.$index(i)); |
| 972 } |
| 973 } |
| 974 } |
| 975 HashMapImplementation.prototype.getKeys = function() { |
| 976 var list = new ListFactory(this.get$length()); |
| 977 var i = 0; |
| 978 this.forEach(function _(key, value) { |
| 979 list.$setindex(i++, key); |
| 980 } |
| 981 ); |
| 982 return list; |
| 983 } |
| 984 HashMapImplementation.prototype.getValues = function() { |
| 985 var list = new ListFactory(this.get$length()); |
| 986 var i = 0; |
| 987 this.forEach(function _(key, value) { |
| 988 list.$setindex(i++, value); |
| 989 } |
| 990 ); |
| 991 return list; |
| 992 } |
| 993 HashMapImplementation.prototype.containsKey = function(key) { |
| 994 return (this._probeForLookup(key) != -1); |
| 995 } |
| 996 HashMapImplementation.prototype.containsKey$1 = HashMapImplementation.prototype.
containsKey; |
| 997 HashMapImplementation.prototype.forEach$1 = function($0) { |
| 998 return this.forEach(to$call$2($0)); |
| 999 }; |
| 1000 HashMapImplementation.prototype.getKeys$0 = HashMapImplementation.prototype.getK
eys; |
| 1001 HashMapImplementation.prototype.getValues$0 = HashMapImplementation.prototype.ge
tValues; |
| 1002 HashMapImplementation.prototype.isEmpty$0 = HashMapImplementation.prototype.isEm
pty; |
| 1003 // ********** Code for HashMapImplementation_E$E ************** |
| 1004 /** Implements extends for Dart classes on JavaScript prototypes. */ |
| 1005 function $inherits(child, parent) { |
| 1006 if (child.prototype.__proto__) { |
| 1007 child.prototype.__proto__ = parent.prototype; |
| 1008 } else { |
| 1009 function tmp() {}; |
| 1010 tmp.prototype = parent.prototype; |
| 1011 child.prototype = new tmp(); |
| 1012 child.prototype.constructor = child; |
| 1013 } |
| 1014 } |
| 1015 $inherits(HashMapImplementation_E$E, HashMapImplementation); |
| 1016 function HashMapImplementation_E$E() { |
| 1017 // Initializers done |
| 1018 this._numberOfEntries = 0; |
| 1019 this._numberOfDeleted = 0; |
| 1020 this._loadLimit = HashMapImplementation._computeLoadLimit(8/*HashMapImplementa
tion._INITIAL_CAPACITY*/); |
| 1021 this._keys = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1022 this._values = new ListFactory(8/*HashMapImplementation._INITIAL_CAPACITY*/); |
| 1023 } |
| 1024 HashMapImplementation_E$E._computeLoadLimit = function(capacity) { |
| 1025 return $truncdiv((capacity * 3), 4); |
| 1026 } |
| 1027 HashMapImplementation_E$E._firstProbe = function(hashCode, length) { |
| 1028 return hashCode & (length - 1); |
| 1029 } |
| 1030 HashMapImplementation_E$E._nextProbe = function(currentProbe, numberOfProbes, le
ngth) { |
| 1031 return (currentProbe + numberOfProbes) & (length - 1); |
| 1032 } |
| 1033 HashMapImplementation_E$E.prototype._probeForAdding = function(key) { |
| 1034 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 1035 var numberOfProbes = 1; |
| 1036 var initialHash = hash; |
| 1037 var insertionIndex = -1; |
| 1038 while (true) { |
| 1039 var existingKey = this._keys.$index(hash); |
| 1040 if (existingKey == null) { |
| 1041 if (insertionIndex < 0) return hash; |
| 1042 return insertionIndex; |
| 1043 } |
| 1044 else if ($eq(existingKey, key)) { |
| 1045 return hash; |
| 1046 } |
| 1047 else if ((insertionIndex < 0) && (const$2/*HashMapImplementation._DELETED_KE
Y*/ === existingKey)) { |
| 1048 insertionIndex = hash; |
| 1049 } |
| 1050 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 1051 } |
| 1052 } |
| 1053 HashMapImplementation_E$E.prototype._probeForLookup = function(key) { |
| 1054 var hash = HashMapImplementation._firstProbe(key.hashCode$0(), this._keys.leng
th); |
| 1055 var numberOfProbes = 1; |
| 1056 var initialHash = hash; |
| 1057 while (true) { |
| 1058 var existingKey = this._keys.$index(hash); |
| 1059 if (existingKey == null) return -1; |
| 1060 if ($eq(existingKey, key)) return hash; |
| 1061 hash = HashMapImplementation._nextProbe(hash, numberOfProbes++, this._keys.l
ength); |
| 1062 } |
| 1063 } |
| 1064 HashMapImplementation_E$E.prototype._ensureCapacity = function() { |
| 1065 var newNumberOfEntries = this._numberOfEntries + 1; |
| 1066 if (newNumberOfEntries >= this._loadLimit) { |
| 1067 this._grow(this._keys.length * 2); |
| 1068 return; |
| 1069 } |
| 1070 var capacity = this._keys.length; |
| 1071 var numberOfFreeOrDeleted = capacity - newNumberOfEntries; |
| 1072 var numberOfFree = numberOfFreeOrDeleted - this._numberOfDeleted; |
| 1073 if (this._numberOfDeleted > numberOfFree) { |
| 1074 this._grow(this._keys.length); |
| 1075 } |
| 1076 } |
| 1077 HashMapImplementation_E$E._isPowerOfTwo = function(x) { |
| 1078 return ((x & (x - 1)) == 0); |
| 1079 } |
| 1080 HashMapImplementation_E$E.prototype._grow = function(newCapacity) { |
| 1081 var capacity = this._keys.length; |
| 1082 this._loadLimit = HashMapImplementation._computeLoadLimit(newCapacity); |
| 1083 var oldKeys = this._keys; |
| 1084 var oldValues = this._values; |
| 1085 this._keys = new ListFactory(newCapacity); |
| 1086 this._values = new ListFactory(newCapacity); |
| 1087 for (var i = 0; |
| 1088 i < capacity; i++) { |
| 1089 var key = oldKeys.$index(i); |
| 1090 if (key == null || key === const$2/*HashMapImplementation._DELETED_KEY*/) { |
| 1091 continue; |
| 1092 } |
| 1093 var value = oldValues.$index(i); |
| 1094 var newIndex = this._probeForAdding(key); |
| 1095 this._keys.$setindex(newIndex, key); |
| 1096 this._values.$setindex(newIndex, value); |
| 1097 } |
| 1098 this._numberOfDeleted = 0; |
| 1099 } |
| 1100 HashMapImplementation_E$E.prototype.$setindex = function(key, value) { |
| 1101 this._ensureCapacity(); |
| 1102 var index = this._probeForAdding(key); |
| 1103 if ((this._keys.$index(index) == null) || (this._keys.$index(index) === const$
2/*HashMapImplementation._DELETED_KEY*/)) { |
| 1104 this._numberOfEntries++; |
| 1105 } |
| 1106 this._keys.$setindex(index, key); |
| 1107 this._values.$setindex(index, value); |
| 1108 } |
| 1109 HashMapImplementation_E$E.prototype.remove = function(key) { |
| 1110 var index = this._probeForLookup(key); |
| 1111 if (index >= 0) { |
| 1112 this._numberOfEntries--; |
| 1113 var value = this._values.$index(index); |
| 1114 this._values.$setindex(index); |
| 1115 this._keys.$setindex(index, const$2/*HashMapImplementation._DELETED_KEY*/); |
| 1116 this._numberOfDeleted++; |
| 1117 return value; |
| 1118 } |
| 1119 return null; |
| 1120 } |
| 1121 HashMapImplementation_E$E.prototype.isEmpty = function() { |
| 1122 return this._numberOfEntries == 0; |
| 1123 } |
| 1124 HashMapImplementation_E$E.prototype.forEach = function(f) { |
| 1125 var length = this._keys.length; |
| 1126 for (var i = 0; |
| 1127 i < length; i++) { |
| 1128 if ((this._keys.$index(i) != null) && (this._keys.$index(i) !== const$2/*Has
hMapImplementation._DELETED_KEY*/)) { |
| 1129 f(this._keys.$index(i), this._values.$index(i)); |
| 1130 } |
| 1131 } |
| 1132 } |
| 1133 HashMapImplementation_E$E.prototype.getKeys = function() { |
| 1134 var list = new ListFactory(this.get$length()); |
| 1135 var i = 0; |
| 1136 this.forEach(function _(key, value) { |
| 1137 list.$setindex(i++, key); |
| 1138 } |
| 1139 ); |
| 1140 return list; |
| 1141 } |
| 1142 HashMapImplementation_E$E.prototype.containsKey = function(key) { |
| 1143 return (this._probeForLookup(key) != -1); |
| 1144 } |
| 1145 // ********** Code for HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePa
ir_K$V ************** |
| 1146 $inherits(HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePair_K$V, HashM
apImplementation); |
| 1147 function HashMapImplementation_K$DoubleLinkedQueueEntry_KeyValuePair_K$V() {} |
| 1148 // ********** Code for HashMapImplementation_String$EvaluatedValue *************
* |
| 1149 $inherits(HashMapImplementation_String$EvaluatedValue, HashMapImplementation); |
| 1150 function HashMapImplementation_String$EvaluatedValue() {} |
| 1151 // ********** Code for HashSetImplementation ************** |
| 1152 function HashSetImplementation() { |
| 1153 // Initializers done |
| 1154 this._backingMap = new HashMapImplementation_E$E(); |
| 1155 } |
| 1156 HashSetImplementation.HashSetImplementation$from$factory = function(other) { |
| 1157 var set = new HashSetImplementation(); |
| 1158 for (var $$i = other.iterator(); $$i.hasNext$0(); ) { |
| 1159 var e = $$i.next$0(); |
| 1160 set.add(e); |
| 1161 } |
| 1162 return set; |
| 1163 } |
| 1164 HashSetImplementation.prototype.add = function(value) { |
| 1165 this._backingMap.$setindex(value, value); |
| 1166 } |
| 1167 HashSetImplementation.prototype.contains = function(value) { |
| 1168 return this._backingMap.containsKey(value); |
| 1169 } |
| 1170 HashSetImplementation.prototype.remove = function(value) { |
| 1171 if (!this._backingMap.containsKey(value)) return false; |
| 1172 this._backingMap.remove(value); |
| 1173 return true; |
| 1174 } |
| 1175 HashSetImplementation.prototype.addAll = function(collection) { |
| 1176 var $this = this; // closure support |
| 1177 collection.forEach(function _(value) { |
| 1178 $this.add(value); |
| 1179 } |
| 1180 ); |
| 1181 } |
| 1182 HashSetImplementation.prototype.forEach = function(f) { |
| 1183 this._backingMap.forEach(function _(key, value) { |
| 1184 f(key); |
| 1185 } |
| 1186 ); |
| 1187 } |
| 1188 HashSetImplementation.prototype.filter = function(f) { |
| 1189 var result = new HashSetImplementation(); |
| 1190 this._backingMap.forEach(function _(key, value) { |
| 1191 if (f(key)) result.add(key); |
| 1192 } |
| 1193 ); |
| 1194 return result; |
| 1195 } |
| 1196 HashSetImplementation.prototype.every = function(f) { |
| 1197 var keys = this._backingMap.getKeys(); |
| 1198 return keys.every(f); |
| 1199 } |
| 1200 HashSetImplementation.prototype.some = function(f) { |
| 1201 var keys = this._backingMap.getKeys(); |
| 1202 return keys.some(f); |
| 1203 } |
| 1204 HashSetImplementation.prototype.isEmpty = function() { |
| 1205 return this._backingMap.isEmpty(); |
| 1206 } |
| 1207 HashSetImplementation.prototype.get$length = function() { |
| 1208 return this._backingMap.get$length(); |
| 1209 } |
| 1210 Object.defineProperty(HashSetImplementation.prototype, "length", { |
| 1211 get: HashSetImplementation.prototype.get$length |
| 1212 }); |
| 1213 HashSetImplementation.prototype.iterator = function() { |
| 1214 return new HashSetIterator_E(this); |
| 1215 } |
| 1216 HashSetImplementation.prototype.add$1 = HashSetImplementation.prototype.add; |
| 1217 HashSetImplementation.prototype.addAll$1 = HashSetImplementation.prototype.addAl
l; |
| 1218 HashSetImplementation.prototype.contains$1 = HashSetImplementation.prototype.con
tains; |
| 1219 HashSetImplementation.prototype.every$1 = function($0) { |
| 1220 return this.every(to$call$1($0)); |
| 1221 }; |
| 1222 HashSetImplementation.prototype.filter$1 = function($0) { |
| 1223 return this.filter(to$call$1($0)); |
| 1224 }; |
| 1225 HashSetImplementation.prototype.forEach$1 = function($0) { |
| 1226 return this.forEach(to$call$1($0)); |
| 1227 }; |
| 1228 HashSetImplementation.prototype.isEmpty$0 = HashSetImplementation.prototype.isEm
pty; |
| 1229 HashSetImplementation.prototype.iterator$0 = HashSetImplementation.prototype.ite
rator; |
| 1230 HashSetImplementation.prototype.some$1 = function($0) { |
| 1231 return this.some(to$call$1($0)); |
| 1232 }; |
| 1233 // ********** Code for HashSetImplementation_E ************** |
| 1234 $inherits(HashSetImplementation_E, HashSetImplementation); |
| 1235 function HashSetImplementation_E() {} |
| 1236 // ********** Code for HashSetImplementation_Library ************** |
| 1237 $inherits(HashSetImplementation_Library, HashSetImplementation); |
| 1238 function HashSetImplementation_Library() {} |
| 1239 // ********** Code for HashSetImplementation_String ************** |
| 1240 $inherits(HashSetImplementation_String, HashSetImplementation); |
| 1241 function HashSetImplementation_String() {} |
| 1242 // ********** Code for HashSetImplementation_Type ************** |
| 1243 $inherits(HashSetImplementation_Type, HashSetImplementation); |
| 1244 function HashSetImplementation_Type() {} |
| 1245 // ********** Code for HashSetIterator ************** |
| 1246 function HashSetIterator(set_) { |
| 1247 this._nextValidIndex = -1; |
| 1248 this._entries = set_._backingMap._keys; |
| 1249 // Initializers done |
| 1250 this._advance(); |
| 1251 } |
| 1252 HashSetIterator.prototype.hasNext = function() { |
| 1253 if (this._nextValidIndex >= this._entries.length) return false; |
| 1254 if (this._entries.$index(this._nextValidIndex) === const$2/*HashMapImplementat
ion._DELETED_KEY*/) { |
| 1255 this._advance(); |
| 1256 } |
| 1257 return this._nextValidIndex < this._entries.length; |
| 1258 } |
| 1259 HashSetIterator.prototype.next = function() { |
| 1260 if (!this.hasNext()) { |
| 1261 $throw(const$7/*const NoMoreElementsException()*/); |
| 1262 } |
| 1263 var res = this._entries.$index(this._nextValidIndex); |
| 1264 this._advance(); |
| 1265 return res; |
| 1266 } |
| 1267 HashSetIterator.prototype._advance = function() { |
| 1268 var length = this._entries.length; |
| 1269 var entry; |
| 1270 var deletedKey = const$2/*HashMapImplementation._DELETED_KEY*/; |
| 1271 do { |
| 1272 if (++this._nextValidIndex >= length) break; |
| 1273 entry = this._entries.$index(this._nextValidIndex); |
| 1274 } |
| 1275 while ((entry == null) || (entry === deletedKey)) |
| 1276 } |
| 1277 HashSetIterator.prototype.hasNext$0 = HashSetIterator.prototype.hasNext; |
| 1278 HashSetIterator.prototype.next$0 = HashSetIterator.prototype.next; |
| 1279 // ********** Code for HashSetIterator_E ************** |
| 1280 $inherits(HashSetIterator_E, HashSetIterator); |
| 1281 function HashSetIterator_E(set_) { |
| 1282 this._nextValidIndex = -1; |
| 1283 this._entries = set_._backingMap._keys; |
| 1284 // Initializers done |
| 1285 this._advance(); |
| 1286 } |
| 1287 HashSetIterator_E.prototype._advance = function() { |
| 1288 var length = this._entries.length; |
| 1289 var entry; |
| 1290 var deletedKey = const$2/*HashMapImplementation._DELETED_KEY*/; |
| 1291 do { |
| 1292 if (++this._nextValidIndex >= length) break; |
| 1293 entry = this._entries.$index(this._nextValidIndex); |
| 1294 } |
| 1295 while ((entry == null) || (entry === deletedKey)) |
| 1296 } |
| 1297 // ********** Code for _DeletedKeySentinel ************** |
| 1298 function _DeletedKeySentinel() { |
| 1299 // Initializers done |
| 1300 } |
| 1301 // ********** Code for KeyValuePair ************** |
| 1302 function KeyValuePair(key, value) { |
| 1303 this.key = key; |
| 1304 this.value = value; |
| 1305 // Initializers done |
| 1306 } |
| 1307 KeyValuePair.prototype.get$value = function() { return this.value; }; |
| 1308 KeyValuePair.prototype.set$value = function(value) { return this.value = value;
}; |
| 1309 // ********** Code for KeyValuePair_K$V ************** |
| 1310 $inherits(KeyValuePair_K$V, KeyValuePair); |
| 1311 function KeyValuePair_K$V(key, value) { |
| 1312 this.key = key; |
| 1313 this.value = value; |
| 1314 // Initializers done |
| 1315 } |
| 1316 // ********** Code for LinkedHashMapImplementation ************** |
| 1317 function LinkedHashMapImplementation() { |
| 1318 // Initializers done |
| 1319 this._map = new HashMapImplementation(); |
| 1320 this._list = new DoubleLinkedQueue_KeyValuePair_K$V(); |
| 1321 } |
| 1322 LinkedHashMapImplementation.prototype.$setindex = function(key, value) { |
| 1323 if (this._map.containsKey(key)) { |
| 1324 this._map.$index(key).get$element().set$value(value); |
| 1325 } |
| 1326 else { |
| 1327 this._list.addLast(new KeyValuePair_K$V(key, value)); |
| 1328 this._map.$setindex(key, this._list.lastEntry()); |
| 1329 } |
| 1330 } |
| 1331 LinkedHashMapImplementation.prototype.$index = function(key) { |
| 1332 var entry = this._map.$index(key); |
| 1333 if (entry == null) return null; |
| 1334 return entry.get$element().get$value(); |
| 1335 } |
| 1336 LinkedHashMapImplementation.prototype.getKeys = function() { |
| 1337 var list = new ListFactory(this.get$length()); |
| 1338 var index = 0; |
| 1339 this._list.forEach(function _(entry) { |
| 1340 list.$setindex(index++, entry.key); |
| 1341 } |
| 1342 ); |
| 1343 return list; |
| 1344 } |
| 1345 LinkedHashMapImplementation.prototype.getValues = function() { |
| 1346 var list = new ListFactory(this.get$length()); |
| 1347 var index = 0; |
| 1348 this._list.forEach(function _(entry) { |
| 1349 list.$setindex(index++, entry.value); |
| 1350 } |
| 1351 ); |
| 1352 return list; |
| 1353 } |
| 1354 LinkedHashMapImplementation.prototype.forEach = function(f) { |
| 1355 this._list.forEach(function _(entry) { |
| 1356 f(entry.key, entry.value); |
| 1357 } |
| 1358 ); |
| 1359 } |
| 1360 LinkedHashMapImplementation.prototype.containsKey = function(key) { |
| 1361 return this._map.containsKey(key); |
| 1362 } |
| 1363 LinkedHashMapImplementation.prototype.get$length = function() { |
| 1364 return this._map.get$length(); |
| 1365 } |
| 1366 Object.defineProperty(LinkedHashMapImplementation.prototype, "length", { |
| 1367 get: LinkedHashMapImplementation.prototype.get$length |
| 1368 }); |
| 1369 LinkedHashMapImplementation.prototype.isEmpty = function() { |
| 1370 return this.get$length() == 0; |
| 1371 } |
| 1372 LinkedHashMapImplementation.prototype.containsKey$1 = LinkedHashMapImplementatio
n.prototype.containsKey; |
| 1373 LinkedHashMapImplementation.prototype.forEach$1 = function($0) { |
| 1374 return this.forEach(to$call$2($0)); |
| 1375 }; |
| 1376 LinkedHashMapImplementation.prototype.getKeys$0 = LinkedHashMapImplementation.pr
ototype.getKeys; |
| 1377 LinkedHashMapImplementation.prototype.getValues$0 = LinkedHashMapImplementation.
prototype.getValues; |
| 1378 LinkedHashMapImplementation.prototype.isEmpty$0 = LinkedHashMapImplementation.pr
ototype.isEmpty; |
| 1379 // ********** Code for DoubleLinkedQueueEntry ************** |
| 1380 function DoubleLinkedQueueEntry(e) { |
| 1381 // Initializers done |
| 1382 this._element = e; |
| 1383 } |
| 1384 DoubleLinkedQueueEntry.prototype._link = function(p, n) { |
| 1385 this._next = n; |
| 1386 this._previous = p; |
| 1387 p._next = this; |
| 1388 n._previous = this; |
| 1389 } |
| 1390 DoubleLinkedQueueEntry.prototype.prepend = function(e) { |
| 1391 new DoubleLinkedQueueEntry_E(e)._link(this._previous, this); |
| 1392 } |
| 1393 DoubleLinkedQueueEntry.prototype.remove = function() { |
| 1394 this._previous._next = this._next; |
| 1395 this._next._previous = this._previous; |
| 1396 this._next = null; |
| 1397 this._previous = null; |
| 1398 return this._element; |
| 1399 } |
| 1400 DoubleLinkedQueueEntry.prototype._asNonSentinelEntry = function() { |
| 1401 return this; |
| 1402 } |
| 1403 DoubleLinkedQueueEntry.prototype.previousEntry = function() { |
| 1404 return this._previous._asNonSentinelEntry(); |
| 1405 } |
| 1406 DoubleLinkedQueueEntry.prototype.get$element = function() { |
| 1407 return this._element; |
| 1408 } |
| 1409 // ********** Code for DoubleLinkedQueueEntry_E ************** |
| 1410 $inherits(DoubleLinkedQueueEntry_E, DoubleLinkedQueueEntry); |
| 1411 function DoubleLinkedQueueEntry_E(e) { |
| 1412 // Initializers done |
| 1413 this._element = e; |
| 1414 } |
| 1415 DoubleLinkedQueueEntry_E.prototype._link = function(p, n) { |
| 1416 this._next = n; |
| 1417 this._previous = p; |
| 1418 p._next = this; |
| 1419 n._previous = this; |
| 1420 } |
| 1421 DoubleLinkedQueueEntry_E.prototype.prepend = function(e) { |
| 1422 new DoubleLinkedQueueEntry_E(e)._link(this._previous, this); |
| 1423 } |
| 1424 DoubleLinkedQueueEntry_E.prototype.remove = function() { |
| 1425 this._previous._next = this._next; |
| 1426 this._next._previous = this._previous; |
| 1427 this._next = null; |
| 1428 this._previous = null; |
| 1429 return this._element; |
| 1430 } |
| 1431 DoubleLinkedQueueEntry_E.prototype._asNonSentinelEntry = function() { |
| 1432 return this; |
| 1433 } |
| 1434 DoubleLinkedQueueEntry_E.prototype.previousEntry = function() { |
| 1435 return this._previous._asNonSentinelEntry(); |
| 1436 } |
| 1437 // ********** Code for DoubleLinkedQueueEntry_KeyValuePair_K$V ************** |
| 1438 $inherits(DoubleLinkedQueueEntry_KeyValuePair_K$V, DoubleLinkedQueueEntry); |
| 1439 function DoubleLinkedQueueEntry_KeyValuePair_K$V(e) { |
| 1440 // Initializers done |
| 1441 this._element = e; |
| 1442 } |
| 1443 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype._link = function(p, n) { |
| 1444 this._next = n; |
| 1445 this._previous = p; |
| 1446 p._next = this; |
| 1447 n._previous = this; |
| 1448 } |
| 1449 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype.prepend = function(e) { |
| 1450 new DoubleLinkedQueueEntry_KeyValuePair_K$V(e)._link(this._previous, this); |
| 1451 } |
| 1452 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype._asNonSentinelEntry = function
() { |
| 1453 return this; |
| 1454 } |
| 1455 DoubleLinkedQueueEntry_KeyValuePair_K$V.prototype.previousEntry = function() { |
| 1456 return this._previous._asNonSentinelEntry(); |
| 1457 } |
| 1458 // ********** Code for _DoubleLinkedQueueEntrySentinel ************** |
| 1459 $inherits(_DoubleLinkedQueueEntrySentinel, DoubleLinkedQueueEntry_E); |
| 1460 function _DoubleLinkedQueueEntrySentinel() { |
| 1461 // Initializers done |
| 1462 DoubleLinkedQueueEntry_E.call(this, null); |
| 1463 this._link(this, this); |
| 1464 } |
| 1465 _DoubleLinkedQueueEntrySentinel.prototype.remove = function() { |
| 1466 $throw(const$1/*const EmptyQueueException()*/); |
| 1467 } |
| 1468 _DoubleLinkedQueueEntrySentinel.prototype._asNonSentinelEntry = function() { |
| 1469 return null; |
| 1470 } |
| 1471 _DoubleLinkedQueueEntrySentinel.prototype.get$element = function() { |
| 1472 $throw(const$1/*const EmptyQueueException()*/); |
| 1473 } |
| 1474 // ********** Code for _DoubleLinkedQueueEntrySentinel_E ************** |
| 1475 $inherits(_DoubleLinkedQueueEntrySentinel_E, _DoubleLinkedQueueEntrySentinel); |
| 1476 function _DoubleLinkedQueueEntrySentinel_E() { |
| 1477 // Initializers done |
| 1478 DoubleLinkedQueueEntry_E.call(this, null); |
| 1479 this._link(this, this); |
| 1480 } |
| 1481 // ********** Code for _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V ********
****** |
| 1482 $inherits(_DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V, _DoubleLinkedQueueEn
trySentinel); |
| 1483 function _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V() { |
| 1484 // Initializers done |
| 1485 DoubleLinkedQueueEntry_KeyValuePair_K$V.call(this, null); |
| 1486 this._link(this, this); |
| 1487 } |
| 1488 // ********** Code for DoubleLinkedQueue ************** |
| 1489 function DoubleLinkedQueue() { |
| 1490 // Initializers done |
| 1491 this._sentinel = new _DoubleLinkedQueueEntrySentinel_E(); |
| 1492 } |
| 1493 DoubleLinkedQueue.DoubleLinkedQueue$from$factory = function(other) { |
| 1494 var list = new DoubleLinkedQueue(); |
| 1495 for (var $$i = other.iterator(); $$i.hasNext$0(); ) { |
| 1496 var e = $$i.next$0(); |
| 1497 list.addLast(e); |
| 1498 } |
| 1499 return list; |
| 1500 } |
| 1501 DoubleLinkedQueue.prototype.addLast = function(value) { |
| 1502 this._sentinel.prepend(value); |
| 1503 } |
| 1504 DoubleLinkedQueue.prototype.add = function(value) { |
| 1505 this.addLast(value); |
| 1506 } |
| 1507 DoubleLinkedQueue.prototype.addAll = function(collection) { |
| 1508 for (var $$i = collection.iterator(); $$i.hasNext$0(); ) { |
| 1509 var e = $$i.next$0(); |
| 1510 this.add(e); |
| 1511 } |
| 1512 } |
| 1513 DoubleLinkedQueue.prototype.removeLast = function() { |
| 1514 return this._sentinel._previous.remove(); |
| 1515 } |
| 1516 DoubleLinkedQueue.prototype.removeFirst = function() { |
| 1517 return this._sentinel._next.remove(); |
| 1518 } |
| 1519 DoubleLinkedQueue.prototype.last = function() { |
| 1520 return this._sentinel._previous.get$element(); |
| 1521 } |
| 1522 DoubleLinkedQueue.prototype.lastEntry = function() { |
| 1523 return this._sentinel.previousEntry(); |
| 1524 } |
| 1525 DoubleLinkedQueue.prototype.get$length = function() { |
| 1526 var counter = 0; |
| 1527 this.forEach(function _(element) { |
| 1528 counter++; |
| 1529 } |
| 1530 ); |
| 1531 return counter; |
| 1532 } |
| 1533 Object.defineProperty(DoubleLinkedQueue.prototype, "length", { |
| 1534 get: DoubleLinkedQueue.prototype.get$length |
| 1535 }); |
| 1536 DoubleLinkedQueue.prototype.isEmpty = function() { |
| 1537 return (this._sentinel._next === this._sentinel); |
| 1538 } |
| 1539 DoubleLinkedQueue.prototype.forEach = function(f) { |
| 1540 var entry = this._sentinel._next; |
| 1541 while (entry !== this._sentinel) { |
| 1542 var nextEntry = entry._next; |
| 1543 f(entry._element); |
| 1544 entry = nextEntry; |
| 1545 } |
| 1546 } |
| 1547 DoubleLinkedQueue.prototype.every = function(f) { |
| 1548 var entry = this._sentinel._next; |
| 1549 while (entry !== this._sentinel) { |
| 1550 var nextEntry = entry._next; |
| 1551 if (!f(entry._element)) return false; |
| 1552 entry = nextEntry; |
| 1553 } |
| 1554 return true; |
| 1555 } |
| 1556 DoubleLinkedQueue.prototype.some = function(f) { |
| 1557 var entry = this._sentinel._next; |
| 1558 while (entry !== this._sentinel) { |
| 1559 var nextEntry = entry._next; |
| 1560 if (f(entry._element)) return true; |
| 1561 entry = nextEntry; |
| 1562 } |
| 1563 return false; |
| 1564 } |
| 1565 DoubleLinkedQueue.prototype.filter = function(f) { |
| 1566 var other = new DoubleLinkedQueue(); |
| 1567 var entry = this._sentinel._next; |
| 1568 while (entry !== this._sentinel) { |
| 1569 var nextEntry = entry._next; |
| 1570 if (f(entry._element)) other.addLast(entry._element); |
| 1571 entry = nextEntry; |
| 1572 } |
| 1573 return other; |
| 1574 } |
| 1575 DoubleLinkedQueue.prototype.iterator = function() { |
| 1576 return new _DoubleLinkedQueueIterator_E(this._sentinel); |
| 1577 } |
| 1578 DoubleLinkedQueue.prototype.add$1 = DoubleLinkedQueue.prototype.add; |
| 1579 DoubleLinkedQueue.prototype.addAll$1 = DoubleLinkedQueue.prototype.addAll; |
| 1580 DoubleLinkedQueue.prototype.every$1 = function($0) { |
| 1581 return this.every(to$call$1($0)); |
| 1582 }; |
| 1583 DoubleLinkedQueue.prototype.filter$1 = function($0) { |
| 1584 return this.filter(to$call$1($0)); |
| 1585 }; |
| 1586 DoubleLinkedQueue.prototype.forEach$1 = function($0) { |
| 1587 return this.forEach(to$call$1($0)); |
| 1588 }; |
| 1589 DoubleLinkedQueue.prototype.isEmpty$0 = DoubleLinkedQueue.prototype.isEmpty; |
| 1590 DoubleLinkedQueue.prototype.iterator$0 = DoubleLinkedQueue.prototype.iterator; |
| 1591 DoubleLinkedQueue.prototype.last$0 = DoubleLinkedQueue.prototype.last; |
| 1592 DoubleLinkedQueue.prototype.removeLast$0 = DoubleLinkedQueue.prototype.removeLas
t; |
| 1593 DoubleLinkedQueue.prototype.some$1 = function($0) { |
| 1594 return this.some(to$call$1($0)); |
| 1595 }; |
| 1596 // ********** Code for DoubleLinkedQueue_E ************** |
| 1597 $inherits(DoubleLinkedQueue_E, DoubleLinkedQueue); |
| 1598 function DoubleLinkedQueue_E() {} |
| 1599 // ********** Code for DoubleLinkedQueue_KeyValuePair_K$V ************** |
| 1600 $inherits(DoubleLinkedQueue_KeyValuePair_K$V, DoubleLinkedQueue); |
| 1601 function DoubleLinkedQueue_KeyValuePair_K$V() { |
| 1602 // Initializers done |
| 1603 this._sentinel = new _DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V(); |
| 1604 } |
| 1605 DoubleLinkedQueue_KeyValuePair_K$V.prototype.addLast = function(value) { |
| 1606 this._sentinel.prepend(value); |
| 1607 } |
| 1608 DoubleLinkedQueue_KeyValuePair_K$V.prototype.lastEntry = function() { |
| 1609 return this._sentinel.previousEntry(); |
| 1610 } |
| 1611 DoubleLinkedQueue_KeyValuePair_K$V.prototype.forEach = function(f) { |
| 1612 var entry = this._sentinel._next; |
| 1613 while (entry !== this._sentinel) { |
| 1614 var nextEntry = entry._next; |
| 1615 f(entry._element); |
| 1616 entry = nextEntry; |
| 1617 } |
| 1618 } |
| 1619 // ********** Code for _DoubleLinkedQueueIterator ************** |
| 1620 function _DoubleLinkedQueueIterator(_sentinel) { |
| 1621 this._sentinel = _sentinel; |
| 1622 // Initializers done |
| 1623 this._currentEntry = this._sentinel; |
| 1624 } |
| 1625 _DoubleLinkedQueueIterator.prototype.hasNext = function() { |
| 1626 return this._currentEntry._next !== this._sentinel; |
| 1627 } |
| 1628 _DoubleLinkedQueueIterator.prototype.next = function() { |
| 1629 if (!this.hasNext()) { |
| 1630 $throw(const$7/*const NoMoreElementsException()*/); |
| 1631 } |
| 1632 this._currentEntry = this._currentEntry._next; |
| 1633 return this._currentEntry.get$element(); |
| 1634 } |
| 1635 _DoubleLinkedQueueIterator.prototype.hasNext$0 = _DoubleLinkedQueueIterator.prot
otype.hasNext; |
| 1636 _DoubleLinkedQueueIterator.prototype.next$0 = _DoubleLinkedQueueIterator.prototy
pe.next; |
| 1637 // ********** Code for _DoubleLinkedQueueIterator_E ************** |
| 1638 $inherits(_DoubleLinkedQueueIterator_E, _DoubleLinkedQueueIterator); |
| 1639 function _DoubleLinkedQueueIterator_E(_sentinel) { |
| 1640 this._sentinel = _sentinel; |
| 1641 // Initializers done |
| 1642 this._currentEntry = this._sentinel; |
| 1643 } |
| 1644 // ********** Code for StopwatchImplementation ************** |
| 1645 function StopwatchImplementation() { |
| 1646 this._start = null; |
| 1647 this._stop = null; |
| 1648 // Initializers done |
| 1649 } |
| 1650 StopwatchImplementation.prototype.start = function() { |
| 1651 if (this._start == null) { |
| 1652 this._start = Clock.now(); |
| 1653 } |
| 1654 else { |
| 1655 if (this._stop == null) { |
| 1656 return; |
| 1657 } |
| 1658 this._start = Clock.now() - (this._stop - this._start); |
| 1659 } |
| 1660 } |
| 1661 StopwatchImplementation.prototype.get$start = function() { |
| 1662 return StopwatchImplementation.prototype.start.bind(this); |
| 1663 } |
| 1664 StopwatchImplementation.prototype.stop = function() { |
| 1665 if (this._start == null) { |
| 1666 return; |
| 1667 } |
| 1668 this._stop = Clock.now(); |
| 1669 } |
| 1670 StopwatchImplementation.prototype.elapsed = function() { |
| 1671 if (this._start == null) { |
| 1672 return 0; |
| 1673 } |
| 1674 return (this._stop == null) ? (Clock.now() - this._start) : (this._stop - this
._start); |
| 1675 } |
| 1676 StopwatchImplementation.prototype.elapsedInMs = function() { |
| 1677 return $truncdiv((this.elapsed() * 1000), this.frequency()); |
| 1678 } |
| 1679 StopwatchImplementation.prototype.frequency = function() { |
| 1680 return Clock.frequency(); |
| 1681 } |
| 1682 StopwatchImplementation.prototype.start$0 = StopwatchImplementation.prototype.st
art; |
| 1683 // ********** Code for StringBufferImpl ************** |
| 1684 function StringBufferImpl(content) { |
| 1685 // Initializers done |
| 1686 this.clear(); |
| 1687 this.add(content); |
| 1688 } |
| 1689 StringBufferImpl.prototype.get$length = function() { |
| 1690 return this._length; |
| 1691 } |
| 1692 Object.defineProperty(StringBufferImpl.prototype, "length", { |
| 1693 get: StringBufferImpl.prototype.get$length |
| 1694 }); |
| 1695 StringBufferImpl.prototype.isEmpty = function() { |
| 1696 return this._length == 0; |
| 1697 } |
| 1698 StringBufferImpl.prototype.add = function(obj) { |
| 1699 var str = obj.toString(); |
| 1700 if (str == null || str.isEmpty()) return this; |
| 1701 this._buffer.add(str); |
| 1702 this._length += str.length; |
| 1703 return this; |
| 1704 } |
| 1705 StringBufferImpl.prototype.addAll = function(objects) { |
| 1706 for (var $$i = objects.iterator(); $$i.hasNext$0(); ) { |
| 1707 var obj = $$i.next$0(); |
| 1708 this.add(obj); |
| 1709 } |
| 1710 return this; |
| 1711 } |
| 1712 StringBufferImpl.prototype.clear = function() { |
| 1713 this._buffer = new ListFactory(); |
| 1714 this._length = 0; |
| 1715 return this; |
| 1716 } |
| 1717 StringBufferImpl.prototype.toString = function() { |
| 1718 if (this._buffer.length == 0) return ""; |
| 1719 if (this._buffer.length == 1) return this._buffer.$index(0); |
| 1720 var result = StringBase.concatAll(this._buffer); |
| 1721 this._buffer.clear(); |
| 1722 this._buffer.add(result); |
| 1723 return result; |
| 1724 } |
| 1725 StringBufferImpl.prototype.add$1 = StringBufferImpl.prototype.add; |
| 1726 StringBufferImpl.prototype.addAll$1 = StringBufferImpl.prototype.addAll; |
| 1727 StringBufferImpl.prototype.isEmpty$0 = StringBufferImpl.prototype.isEmpty; |
| 1728 StringBufferImpl.prototype.toString$0 = StringBufferImpl.prototype.toString; |
| 1729 // ********** Code for StringBase ************** |
| 1730 function StringBase() {} |
| 1731 StringBase.join = function(strings, separator) { |
| 1732 if (strings.length == 0) return ''; |
| 1733 var s = strings.$index(0); |
| 1734 for (var i = 1; |
| 1735 i < strings.length; i++) { |
| 1736 s = s + separator + strings.$index(i); |
| 1737 } |
| 1738 return s; |
| 1739 } |
| 1740 StringBase.concatAll = function(strings) { |
| 1741 return StringBase.join(strings, ""); |
| 1742 } |
| 1743 // ********** Code for StringImplementation ************** |
| 1744 StringImplementation = String; |
| 1745 StringImplementation.prototype.endsWith = function(other) { |
| 1746 if (other.length > this.length) return false; |
| 1747 return other == this.substring(this.length - other.length); |
| 1748 } |
| 1749 StringImplementation.prototype.startsWith = function(other) { |
| 1750 if (other.length > this.length) return false; |
| 1751 return other == this.substring(0, other.length); |
| 1752 } |
| 1753 StringImplementation.prototype.isEmpty = function() { |
| 1754 return this.length == 0; |
| 1755 } |
| 1756 StringImplementation.prototype.contains = function(pattern, startIndex) { |
| 1757 return this.indexOf(pattern, startIndex) >= 0; |
| 1758 } |
| 1759 StringImplementation.prototype._replaceFirst = function(from, to) { |
| 1760 return this.replace(from, to); |
| 1761 } |
| 1762 StringImplementation.prototype._replaceFirstRegExp = function(from, to) { |
| 1763 return this.replace(from.re, to); |
| 1764 } |
| 1765 StringImplementation.prototype.replaceFirst = function(from, to) { |
| 1766 if ((typeof(from) == 'string')) return this._replaceFirst(from, to); |
| 1767 if (!!(from && from.is$RegExp())) return this._replaceFirstRegExp(from, to); |
| 1768 var $$list = from.allMatches(this); |
| 1769 for (var $$i = from.allMatches(this).iterator(); $$i.hasNext$0(); ) { |
| 1770 var match = $$i.next$0(); |
| 1771 return this.substring(0, match.start$0()) + to + this.substring(match.end$0(
)); |
| 1772 } |
| 1773 } |
| 1774 StringImplementation.prototype.replaceAll = function(from, to) { |
| 1775 if (typeof(from) == 'string' || from instanceof String) { |
| 1776 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); |
| 1777 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun! |
| 1778 } |
| 1779 return this.replace(from, to); |
| 1780 } |
| 1781 StringImplementation.prototype.hashCode = function() { |
| 1782 if (this.hash_ === undefined) { |
| 1783 for (var i = 0; i < this.length; i++) { |
| 1784 var ch = this.charCodeAt(i); |
| 1785 this.hash_ += ch; |
| 1786 this.hash_ += this.hash_ << 10; |
| 1787 this.hash_ ^= this.hash_ >> 6; |
| 1788 } |
| 1789 |
| 1790 this.hash_ += this.hash_ << 3; |
| 1791 this.hash_ ^= this.hash_ >> 11; |
| 1792 this.hash_ += this.hash_ << 15; |
| 1793 this.hash_ = this.hash_ & ((1 << 29) - 1); |
| 1794 } |
| 1795 return this.hash_; |
| 1796 } |
| 1797 StringImplementation.prototype.compareTo = function(other) { |
| 1798 return this == other ? 0 : this < other ? -1 : 1; |
| 1799 } |
| 1800 StringImplementation.prototype.compareTo$1 = StringImplementation.prototype.comp
areTo; |
| 1801 StringImplementation.prototype.contains$1 = StringImplementation.prototype.conta
ins; |
| 1802 StringImplementation.prototype.endsWith$1 = StringImplementation.prototype.endsW
ith; |
| 1803 StringImplementation.prototype.hashCode$0 = StringImplementation.prototype.hashC
ode; |
| 1804 StringImplementation.prototype.indexOf$1 = StringImplementation.prototype.indexO
f; |
| 1805 StringImplementation.prototype.isEmpty$0 = StringImplementation.prototype.isEmpt
y; |
| 1806 StringImplementation.prototype.replaceAll$2 = StringImplementation.prototype.rep
laceAll; |
| 1807 StringImplementation.prototype.replaceFirst$2 = StringImplementation.prototype.r
eplaceFirst; |
| 1808 StringImplementation.prototype.startsWith$1 = StringImplementation.prototype.sta
rtsWith; |
| 1809 StringImplementation.prototype.substring$1 = StringImplementation.prototype.subs
tring; |
| 1810 StringImplementation.prototype.substring$2 = StringImplementation.prototype.subs
tring; |
| 1811 // ********** Code for Collections ************** |
| 1812 function Collections() {} |
| 1813 Collections.forEach = function(iterable, f) { |
| 1814 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1815 var e = $$i.next$0(); |
| 1816 f(e); |
| 1817 } |
| 1818 } |
| 1819 Collections.some = function(iterable, f) { |
| 1820 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1821 var e = $$i.next$0(); |
| 1822 if (f(e)) return true; |
| 1823 } |
| 1824 return false; |
| 1825 } |
| 1826 Collections.every = function(iterable, f) { |
| 1827 for (var $$i = iterable.iterator(); $$i.hasNext$0(); ) { |
| 1828 var e = $$i.next$0(); |
| 1829 if (!f(e)) return false; |
| 1830 } |
| 1831 return true; |
| 1832 } |
| 1833 Collections.filter = function(source, destination, f) { |
| 1834 for (var $$i = source.iterator(); $$i.hasNext$0(); ) { |
| 1835 var e = $$i.next$0(); |
| 1836 if (f(e)) destination.add(e); |
| 1837 } |
| 1838 return destination; |
| 1839 } |
| 1840 // ********** Code for top level ************** |
| 1841 // ********** Library node ************** |
| 1842 // ********** Code for http ************** |
| 1843 http = require('http'); |
| 1844 // ********** Code for Server ************** |
| 1845 Server = http.Server; |
| 1846 // ********** Code for process ************** |
| 1847 // ********** Code for fs ************** |
| 1848 fs = require('fs'); |
| 1849 // ********** Code for Stats ************** |
| 1850 Stats = fs.Stats; |
| 1851 Stats.prototype.isFile$0 = Stats.prototype.isFile; |
| 1852 // ********** Code for path ************** |
| 1853 path = require('path'); |
| 1854 // ********** Code for top level ************** |
| 1855 // ********** Library file_system ************** |
| 1856 // ********** Code for top level ************** |
| 1857 function joinPaths(path1, path2) { |
| 1858 var pieces = path1.split('/'); |
| 1859 var $$list = path2.split('/'); |
| 1860 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 1861 var piece = $$list.$index($$i); |
| 1862 if ($eq(piece, '..') && pieces.length > 0 && $ne(pieces.last$0(), '.') && $n
e(pieces.last$0(), '..')) { |
| 1863 pieces.removeLast$0(); |
| 1864 } |
| 1865 else if ($ne(piece, '')) { |
| 1866 if (pieces.length > 0 && $eq(pieces.last$0(), '.')) { |
| 1867 pieces.removeLast$0(); |
| 1868 } |
| 1869 pieces.add$1(piece); |
| 1870 } |
| 1871 } |
| 1872 return Strings.join(pieces, '/'); |
| 1873 } |
| 1874 function dirname(path) { |
| 1875 var lastSlash = path.lastIndexOf('/', path.length); |
| 1876 if (lastSlash == -1) { |
| 1877 return '.'; |
| 1878 } |
| 1879 else { |
| 1880 return path.substring(0, lastSlash); |
| 1881 } |
| 1882 } |
| 1883 function basename(path) { |
| 1884 var lastSlash = path.lastIndexOf('/', path.length); |
| 1885 if (lastSlash == -1) { |
| 1886 return path; |
| 1887 } |
| 1888 else { |
| 1889 return path.substring(lastSlash + 1); |
| 1890 } |
| 1891 } |
| 1892 // ********** Library file_system_node ************** |
| 1893 // ********** Code for NodeFileSystem ************** |
| 1894 function NodeFileSystem() { |
| 1895 // Initializers done |
| 1896 } |
| 1897 NodeFileSystem.prototype.readAll = function(filename) { |
| 1898 return fs.readFileSync(filename, 'utf8'); |
| 1899 } |
| 1900 NodeFileSystem.prototype.fileExists = function(filename) { |
| 1901 return path.existsSync(filename); |
| 1902 } |
| 1903 // ********** Code for top level ************** |
| 1904 // ********** Library lang ************** |
| 1905 // ********** Code for CodeWriter ************** |
| 1906 function CodeWriter() { |
| 1907 this._indentation = 0 |
| 1908 this._pendingIndent = false |
| 1909 this.writeComments = true |
| 1910 this._buf = new StringBufferImpl(""); |
| 1911 // Initializers done |
| 1912 } |
| 1913 CodeWriter.prototype.get$text = function() { |
| 1914 return this._buf.toString(); |
| 1915 } |
| 1916 CodeWriter.prototype._indent = function() { |
| 1917 this._pendingIndent = false; |
| 1918 for (var i = 0; |
| 1919 i < this._indentation; i++) { |
| 1920 this._buf.add(' '/*CodeWriter.INDENTATION*/); |
| 1921 } |
| 1922 } |
| 1923 CodeWriter.prototype.comment = function(text) { |
| 1924 if (this.writeComments) { |
| 1925 this.writeln(text); |
| 1926 } |
| 1927 } |
| 1928 CodeWriter.prototype.write = function(text) { |
| 1929 if (text.length == 0) return; |
| 1930 if (this._pendingIndent) this._indent(); |
| 1931 if (text.indexOf('\n') != -1) { |
| 1932 var lines = text.split('\n'); |
| 1933 for (var i = 0; |
| 1934 i < lines.length - 1; i++) { |
| 1935 this.writeln(lines.$index(i)); |
| 1936 } |
| 1937 this.write(lines.$index(lines.length - 1)); |
| 1938 } |
| 1939 else { |
| 1940 this._buf.add(text); |
| 1941 } |
| 1942 } |
| 1943 CodeWriter.prototype.writeln = function(text) { |
| 1944 if (text != null) { |
| 1945 this.write(text); |
| 1946 } |
| 1947 if (!text.endsWith('\n')) this._buf.add('\n'/*CodeWriter.NEWLINE*/); |
| 1948 this._pendingIndent = true; |
| 1949 } |
| 1950 CodeWriter.prototype.enterBlock = function(text) { |
| 1951 this.writeln(text); |
| 1952 this._indentation++; |
| 1953 } |
| 1954 CodeWriter.prototype.exitBlock = function(text) { |
| 1955 this._indentation--; |
| 1956 this.writeln(text); |
| 1957 } |
| 1958 CodeWriter.prototype.nextBlock = function(text) { |
| 1959 this._indentation--; |
| 1960 this.writeln(text); |
| 1961 this._indentation++; |
| 1962 } |
| 1963 // ********** Code for CoreJs ************** |
| 1964 function CoreJs() { |
| 1965 this.useStackTraceOf = false |
| 1966 this.useThrow = false |
| 1967 this.useGenStub = false |
| 1968 this.useAssert = false |
| 1969 this.useNotNullBool = false |
| 1970 this.useIndex = false |
| 1971 this.useSetIndex = false |
| 1972 this.useWrap0 = false |
| 1973 this.useWrap1 = false |
| 1974 this.useIsolates = false |
| 1975 this.useToString = false |
| 1976 this._generatedTypeNameOf = false |
| 1977 this._generatedDynamicProto = false |
| 1978 this._generatedInherits = false |
| 1979 this._usedOperators = new HashMapImplementation(); |
| 1980 this.writer = new CodeWriter(); |
| 1981 // Initializers done |
| 1982 } |
| 1983 CoreJs.prototype.useOperator = function(name) { |
| 1984 if (this._usedOperators.$index(name) != null) return; |
| 1985 var code; |
| 1986 switch (name) { |
| 1987 case ':ne': |
| 1988 |
| 1989 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}"/*null._NE_FUNCTION*/; |
| 1990 break; |
| 1991 |
| 1992 case ':eq': |
| 1993 |
| 1994 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; }"/*null._EQ_FUNCTION*/; |
| 1995 break; |
| 1996 |
| 1997 case ':bit_not': |
| 1998 |
| 1999 code = "function $bit_not(x) {\n return (typeof(x) == 'number') ? ~x : x.
$bit_not();\n}"/*null._BIT_NOT_FUNCTION*/; |
| 2000 break; |
| 2001 |
| 2002 case ':negate': |
| 2003 |
| 2004 code = "function $negate(x) {\n return (typeof(x) == 'number') ? -x : x.$
negate();\n}"/*null._NEGATE_FUNCTION*/; |
| 2005 break; |
| 2006 |
| 2007 case ':add': |
| 2008 |
| 2009 code = "function $add(x, y) {\n return ((typeof(x) == 'number' && typeof(
y) == 'number') ||\n (typeof(x) == 'string'))\n ? x + y : x.$add(y);
\n}"/*null._ADD_FUNCTION*/; |
| 2010 break; |
| 2011 |
| 2012 case ':truncdiv': |
| 2013 |
| 2014 this.useThrow = true; |
| 2015 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}"/*null._TRUNCDIV_FUNCTION*/; |
| 2016 break; |
| 2017 |
| 2018 case ':mod': |
| 2019 |
| 2020 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}"/*nu
ll._MOD_FUNCTION*/; |
| 2021 break; |
| 2022 |
| 2023 default: |
| 2024 |
| 2025 var op = TokenKind.rawOperatorFromMethod(name); |
| 2026 var jsname = $globals.world.toJsIdentifier(name); |
| 2027 code = _otherOperator(jsname, op); |
| 2028 break; |
| 2029 |
| 2030 } |
| 2031 this._usedOperators.$setindex(name, code); |
| 2032 } |
| 2033 CoreJs.prototype.ensureDynamicProto = function() { |
| 2034 if (this._generatedDynamicProto) return; |
| 2035 this._generatedDynamicProto = true; |
| 2036 this.ensureTypeNameOf(); |
| 2037 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}"/*null._DYNAMIC_FUNCTION*/); |
| 2038 } |
| 2039 CoreJs.prototype.ensureTypeNameOf = function() { |
| 2040 if (this._generatedTypeNameOf) return; |
| 2041 this._generatedTypeNameOf = true; |
| 2042 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}"/*null._TYPE_NAME_OF_FUNCTION*/); |
| 2043 } |
| 2044 CoreJs.prototype.ensureInheritsHelper = function() { |
| 2045 if (this._generatedInherits) return; |
| 2046 this._generatedInherits = true; |
| 2047 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}"/*null._INHERITS_FUNCTION
*/); |
| 2048 } |
| 2049 CoreJs.prototype.generate = function(w) { |
| 2050 w.write(this.writer.get$text()); |
| 2051 this.writer = w; |
| 2052 if (this.useGenStub) { |
| 2053 this.useThrow = true; |
| 2054 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}"/*null._GENST
UB_FUNCTION*/); |
| 2055 } |
| 2056 if (this.useStackTraceOf) { |
| 2057 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}"/*null._STACKTRACEOF_FUNCTION*/); |
| 2058 } |
| 2059 if (this.useNotNullBool) { |
| 2060 this.useThrow = true; |
| 2061 w.writeln("function $notnull_bool(test) {\n if (test === true || test === f
alse) return test;\n $throw(new TypeError(test, 'bool'));\n}"/*null._NOTNULL_BO
OL_FUNCTION*/); |
| 2062 } |
| 2063 if (this.useThrow) { |
| 2064 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}"/*null._THROW_FUNCTION*/); |
| 2065 } |
| 2066 if (this.useToString) { |
| 2067 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}"/*null._TOSTRING_FUN
CTION*/); |
| 2068 } |
| 2069 if (this.useIndex) { |
| 2070 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];
}"/*null._INDEX_OPERATORS*/); |
| 2071 } |
| 2072 if (this.useSetIndex) { |
| 2073 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; }"/*n
ull._SETINDEX_OPERATORS*/); |
| 2074 } |
| 2075 if (this.useIsolates) { |
| 2076 if (this.useWrap0) { |
| 2077 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}"/*null._WRAP_CALL0_FUNCTI
ON*/); |
| 2078 } |
| 2079 if (this.useWrap1) { |
| 2080 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}"/
*null._WRAP_CALL1_FUNCTION*/); |
| 2081 } |
| 2082 w.writeln("var $globalThis = this;\nvar $globals = null;\nvar $globalState =
null;"/*null._ISOLATE_INIT_CODE*/); |
| 2083 } |
| 2084 else { |
| 2085 if (this.useWrap0) { |
| 2086 w.writeln("function $wrap_call$0(fn) { return fn; }"/*null._EMPTY_WRAP_CAL
L0_FUNCTION*/); |
| 2087 } |
| 2088 if (this.useWrap1) { |
| 2089 w.writeln("function $wrap_call$1(fn) { return fn; }"/*null._EMPTY_WRAP_CAL
L1_FUNCTION*/); |
| 2090 } |
| 2091 } |
| 2092 var $$list = orderValuesByKeys(this._usedOperators); |
| 2093 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2094 var opImpl = $$list.$index($$i); |
| 2095 w.writeln(opImpl); |
| 2096 } |
| 2097 } |
| 2098 CoreJs.prototype.generate$1 = CoreJs.prototype.generate; |
| 2099 // ********** Code for Element ************** |
| 2100 function Element(name, _enclosingElement) { |
| 2101 this.name = name; |
| 2102 this._enclosingElement = _enclosingElement; |
| 2103 // Initializers done |
| 2104 this._jsname = $globals.world.toJsIdentifier(this.name); |
| 2105 } |
| 2106 Element.prototype.get$name = function() { return this.name; }; |
| 2107 Element.prototype.set$name = function(value) { return this.name = value; }; |
| 2108 Element.prototype.get$_jsname = function() { return this._jsname; }; |
| 2109 Element.prototype.set$_jsname = function(value) { return this._jsname = value; }
; |
| 2110 Element.prototype.get$library = function() { |
| 2111 return null; |
| 2112 } |
| 2113 Element.prototype.get$span = function() { |
| 2114 return null; |
| 2115 } |
| 2116 Element.prototype.get$isNative = function() { |
| 2117 return false; |
| 2118 } |
| 2119 Element.prototype.hashCode = function() { |
| 2120 return this.name.hashCode(); |
| 2121 } |
| 2122 Element.prototype.get$jsname = function() { |
| 2123 return this._jsname; |
| 2124 } |
| 2125 Element.prototype.resolve = function() { |
| 2126 |
| 2127 } |
| 2128 Element.prototype.get$typeParameters = function() { |
| 2129 return null; |
| 2130 } |
| 2131 Element.prototype.get$enclosingElement = function() { |
| 2132 return this._enclosingElement == null ? this.get$library() : this._enclosingEl
ement; |
| 2133 } |
| 2134 Element.prototype.set$enclosingElement = function(e) { |
| 2135 return this._enclosingElement = e; |
| 2136 } |
| 2137 Element.prototype.resolveType = function(node, typeErrors) { |
| 2138 if (node == null) return $globals.world.varType; |
| 2139 if (node.type != null) return node.type; |
| 2140 if ((node instanceof NameTypeReference)) { |
| 2141 var typeRef = node; |
| 2142 var name; |
| 2143 if (typeRef.names != null) { |
| 2144 name = typeRef.names.last().get$name(); |
| 2145 } |
| 2146 else { |
| 2147 name = typeRef.name.name; |
| 2148 } |
| 2149 if (this.get$typeParameters() != null) { |
| 2150 var $$list = this.get$typeParameters(); |
| 2151 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2152 var tp = $$list.$index($$i); |
| 2153 if ($eq(tp.get$name(), name)) { |
| 2154 typeRef.type = tp; |
| 2155 } |
| 2156 } |
| 2157 } |
| 2158 if (typeRef.type != null) { |
| 2159 return typeRef.type; |
| 2160 } |
| 2161 return this.get$enclosingElement().resolveType(node, typeErrors); |
| 2162 } |
| 2163 else if ((node instanceof GenericTypeReference)) { |
| 2164 var typeRef = node; |
| 2165 var baseType = this.resolveType(typeRef.baseType, typeErrors); |
| 2166 if (!baseType.get$isGeneric()) { |
| 2167 $globals.world.error(('' + baseType.get$name() + ' is not generic'), typeR
ef.span); |
| 2168 return null; |
| 2169 } |
| 2170 if (typeRef.typeArguments.length != baseType.get$typeParameters().length) { |
| 2171 $globals.world.error('wrong number of type arguments', typeRef.span); |
| 2172 return null; |
| 2173 } |
| 2174 var typeArgs = []; |
| 2175 for (var i = 0; |
| 2176 i < typeRef.typeArguments.length; i++) { |
| 2177 typeArgs.add$1(this.resolveType(typeRef.typeArguments.$index(i), typeError
s)); |
| 2178 } |
| 2179 typeRef.type = baseType.getOrMakeConcreteType$1(typeArgs); |
| 2180 } |
| 2181 else if ((node instanceof FunctionTypeReference)) { |
| 2182 var typeRef = node; |
| 2183 var name = ''; |
| 2184 if (typeRef.func.name != null) { |
| 2185 name = typeRef.func.name.name; |
| 2186 } |
| 2187 typeRef.type = this.get$library().getOrAddFunctionType(this, name, typeRef.f
unc); |
| 2188 } |
| 2189 else { |
| 2190 $globals.world.internalError('unknown type reference', node.span); |
| 2191 } |
| 2192 return node.type; |
| 2193 } |
| 2194 Element.prototype.hashCode$0 = Element.prototype.hashCode; |
| 2195 Element.prototype.resolve$0 = Element.prototype.resolve; |
| 2196 // ********** Code for WorldGenerator ************** |
| 2197 function WorldGenerator(main, writer) { |
| 2198 this.hasStatics = false |
| 2199 this.main = main; |
| 2200 this.writer = writer; |
| 2201 this.globals = new HashMapImplementation(); |
| 2202 this.corejs = new CoreJs(); |
| 2203 // Initializers done |
| 2204 } |
| 2205 WorldGenerator.prototype.run = function() { |
| 2206 var metaGen = new MethodGenerator(this.main, null); |
| 2207 var mainTarget = new Value.type$ctor(this.main.declaringType, this.main.get$sp
an()); |
| 2208 var mainCall = this.main.invoke(metaGen, null, mainTarget, Arguments.get$EMPTY
(), false); |
| 2209 this.main.declaringType.markUsed(); |
| 2210 if ($globals.options.compileAll) { |
| 2211 this.markLibrariesUsed([$globals.world.get$coreimpl(), $globals.world.coreli
b, this.main.declaringType.get$library()]); |
| 2212 } |
| 2213 else { |
| 2214 $globals.world.corelib.types.$index('BadNumberFormatException').markUsed$0()
; |
| 2215 $globals.world.get$coreimpl().types.$index('NumImplementation').markUsed$0()
; |
| 2216 $globals.world.get$coreimpl().types.$index('StringImplementation').markUsed$
0(); |
| 2217 this.genMethod($globals.world.get$coreimpl().types.$index('StringImplementat
ion').getMember$1('contains')); |
| 2218 } |
| 2219 if ($globals.world.corelib.types.$index('Isolate').get$isUsed() || $globals.wo
rld.get$coreimpl().types.$index('ReceivePortImpl').get$isUsed()) { |
| 2220 if (this.corejs.useWrap0 || this.corejs.useWrap1) { |
| 2221 this.genMethod($globals.world.get$coreimpl().types.$index('IsolateContext'
).getMember$1('eval')); |
| 2222 this.genMethod($globals.world.get$coreimpl().types.$index('EventLoop').get
Member$1('run')); |
| 2223 } |
| 2224 this.corejs.useIsolates = true; |
| 2225 var isolateMain = $globals.world.get$coreimpl().topType.resolveMember('start
RootIsolate').members.$index(0); |
| 2226 var isolateMainTarget = new Value.type$ctor($globals.world.get$coreimpl().to
pType, this.main.get$span()); |
| 2227 mainCall = isolateMain.invoke(metaGen, null, isolateMainTarget, new Argument
s(null, [this.main._get(metaGen, this.main.definition, null, false)]), false); |
| 2228 } |
| 2229 this.writeTypes($globals.world.get$coreimpl()); |
| 2230 this.writeTypes($globals.world.corelib); |
| 2231 this.writeTypes(this.main.declaringType.get$library()); |
| 2232 if (this._mixins != null) this.writer.write(this._mixins.get$text()); |
| 2233 this.writeGlobals(); |
| 2234 this.writer.writeln(('' + mainCall.get$code() + ';')); |
| 2235 } |
| 2236 WorldGenerator.prototype.markLibrariesUsed = function(libs) { |
| 2237 return this.getAllTypes(libs).forEach(this.get$markTypeUsed()); |
| 2238 } |
| 2239 WorldGenerator.prototype.markTypeUsed = function(type) { |
| 2240 if (!type.get$isClass()) return; |
| 2241 type.markUsed(); |
| 2242 type.isTested = true; |
| 2243 type.isTested = !type.get$isTop() && !(type.get$isNative() && type.get$members
().getValues().every$1((function (m) { |
| 2244 return m.get$isStatic() && !m.get$isFactory(); |
| 2245 }) |
| 2246 )); |
| 2247 var members = ListFactory.ListFactory$from$factory(type.get$members().getValue
s()); |
| 2248 members.addAll(type.get$constructors().getValues()); |
| 2249 type.get$factories().forEach((function (f) { |
| 2250 return members.add(f); |
| 2251 }) |
| 2252 ); |
| 2253 for (var $$i = 0;$$i < members.length; $$i++) { |
| 2254 var member = members.$index($$i); |
| 2255 if ((member instanceof PropertyMember)) { |
| 2256 if (member.get$getter() != null) this.genMethod(member.get$getter()); |
| 2257 if (member.get$setter() != null) this.genMethod(member.get$setter()); |
| 2258 } |
| 2259 if ((member instanceof MethodMember)) this.genMethod(member); |
| 2260 } |
| 2261 } |
| 2262 WorldGenerator.prototype.get$markTypeUsed = function() { |
| 2263 return WorldGenerator.prototype.markTypeUsed.bind(this); |
| 2264 } |
| 2265 WorldGenerator.prototype.getAllTypes = function(libs) { |
| 2266 var types = []; |
| 2267 var seen = new HashSetImplementation(); |
| 2268 for (var $$i = 0;$$i < libs.length; $$i++) { |
| 2269 var mainLib = libs.$index($$i); |
| 2270 var toCheck = DoubleLinkedQueue.DoubleLinkedQueue$from$factory([mainLib]); |
| 2271 while (!toCheck.isEmpty()) { |
| 2272 var lib = toCheck.removeFirst(); |
| 2273 if (seen.contains(lib)) continue; |
| 2274 seen.add(lib); |
| 2275 lib.get$imports().forEach$1((function (lib, toCheck, i) { |
| 2276 return toCheck.addLast(lib); |
| 2277 }).bind(null, lib, toCheck) |
| 2278 ); |
| 2279 lib.get$types().getValues$0().forEach$1((function (t) { |
| 2280 return types.add(t); |
| 2281 }) |
| 2282 ); |
| 2283 } |
| 2284 } |
| 2285 return types; |
| 2286 } |
| 2287 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe
ndencies) { |
| 2288 this.hasStatics = true; |
| 2289 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname
()); |
| 2290 if (!this.globals.containsKey(fullname)) { |
| 2291 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory(
field, fieldValue, dependencies)); |
| 2292 } |
| 2293 return this.globals.$index(fullname); |
| 2294 } |
| 2295 WorldGenerator.prototype.globalForConst = function(exp, dependencies) { |
| 2296 var key = exp.get$type().get$jsname() + ':' + exp.canonicalCode; |
| 2297 if (!this.globals.containsKey(key)) { |
| 2298 this.globals.$setindex(key, GlobalValue.GlobalValue$fromConst$factory(this.g
lobals.get$length(), exp, dependencies)); |
| 2299 } |
| 2300 return this.globals.$index(key); |
| 2301 } |
| 2302 WorldGenerator.prototype.writeTypes = function(lib) { |
| 2303 if (lib.isWritten) return; |
| 2304 lib.isWritten = true; |
| 2305 var $$list = lib.imports; |
| 2306 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2307 var import_ = $$list.$index($$i); |
| 2308 this.writeTypes(import_.get$library()); |
| 2309 } |
| 2310 for (var i = 0; |
| 2311 i < lib.sources.length; i++) { |
| 2312 lib.sources.$index(i).set$orderInLibrary(i); |
| 2313 } |
| 2314 this.writer.comment(('// ********** Library ' + lib.name + ' **************')
); |
| 2315 if (lib.get$isCore()) { |
| 2316 this.writer.comment('// ********** Natives dart:core **************'); |
| 2317 this.corejs.generate(this.writer); |
| 2318 } |
| 2319 var $$list = lib.natives; |
| 2320 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2321 var file = $$list.$index($$i); |
| 2322 var filename = basename(file.get$filename()); |
| 2323 this.writer.comment(('// ********** Natives ' + filename + ' **************
')); |
| 2324 this.writer.writeln(file.get$text()); |
| 2325 } |
| 2326 lib.topType.markUsed(); |
| 2327 var $$list = this._orderValues(lib.types); |
| 2328 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2329 var type = $$list.$index($$i); |
| 2330 if ((type.get$isUsed() || $eq(type.get$library(), $globals.world.get$dom())
|| type.get$isHiddenNativeType()) && type.get$isClass()) { |
| 2331 this.writeType(type); |
| 2332 if (type.get$isGeneric()) { |
| 2333 var $list0 = this._orderValues(type.get$_concreteTypes()); |
| 2334 for (var $i0 = 0;$i0 < $list0.length; $i0++) { |
| 2335 var ct = $list0.$index($i0); |
| 2336 this.writeType(ct); |
| 2337 } |
| 2338 } |
| 2339 } |
| 2340 else if (type.get$isFunction() && type.get$varStubs().length > 0) { |
| 2341 this.writer.comment(('// ********** Code for ' + type.get$jsname() + ' ***
***********')); |
| 2342 this._writeDynamicStubs(type); |
| 2343 } |
| 2344 if (type.get$typeCheckCode() != null) { |
| 2345 this.writer.writeln(type.get$typeCheckCode()); |
| 2346 } |
| 2347 } |
| 2348 } |
| 2349 WorldGenerator.prototype.genMethod = function(meth, enclosingMethod) { |
| 2350 if (!meth.isGenerated && !meth.get$isAbstract() && meth.get$definition() != nu
ll) { |
| 2351 new MethodGenerator(meth, enclosingMethod).run(); |
| 2352 } |
| 2353 } |
| 2354 WorldGenerator.prototype._prototypeOf = function(type, name) { |
| 2355 if (type.get$isSingletonNative()) { |
| 2356 return ('' + type.get$jsname() + '.' + name); |
| 2357 } |
| 2358 else if (type.get$isHiddenNativeType()) { |
| 2359 this.corejs.ensureDynamicProto(); |
| 2360 return ('\$dynamic("' + name + '").' + type.get$jsname()); |
| 2361 } |
| 2362 else { |
| 2363 return ('' + type.get$jsname() + '.prototype.' + name); |
| 2364 } |
| 2365 } |
| 2366 WorldGenerator.prototype._maybeIsTest = function(onType, checkType) { |
| 2367 var isSubtype = onType.isSubtypeOf(checkType); |
| 2368 if (checkType.isTested) { |
| 2369 this.writer.writeln(this._prototypeOf(onType, ('is\$' + checkType.get$jsname
())) + (' = function(){return ' + isSubtype + '};')); |
| 2370 } |
| 2371 if (checkType.isChecked) { |
| 2372 var body = 'return this'; |
| 2373 var checkName = ('assert\$' + checkType.get$jsname()); |
| 2374 if (!isSubtype) { |
| 2375 body = $globals.world.objectType.varStubs.$index(checkName).get$body(); |
| 2376 } |
| 2377 else if (onType.name == 'StringImplementation' || onType.name == 'NumImpleme
ntation') { |
| 2378 body = ('return ' + onType.get$nativeType().name + '(this)'); |
| 2379 } |
| 2380 this.writer.writeln(this._prototypeOf(onType, checkName) + (' = function(){'
+ body + '};')); |
| 2381 } |
| 2382 } |
| 2383 WorldGenerator.prototype.writeType = function(type) { |
| 2384 if (type.isWritten) return; |
| 2385 type.isWritten = true; |
| 2386 if (type.get$parent() != null && !type.get$isNative()) { |
| 2387 this.writeType(type.get$parent()); |
| 2388 } |
| 2389 if (type.name != null && (type instanceof ConcreteType) && $eq(type.get$librar
y(), $globals.world.get$coreimpl()) && type.name.startsWith('ListFactory')) { |
| 2390 this.writer.writeln(('' + type.get$jsname() + ' = ' + type.get$genericType()
.get$jsname() + ';')); |
| 2391 return; |
| 2392 } |
| 2393 var typeName = type.get$jsname() != null ? type.get$jsname() : 'top level'; |
| 2394 this.writer.comment(('// ********** Code for ' + typeName + ' **************')
); |
| 2395 if (type.get$isNative() && !type.get$isTop()) { |
| 2396 var nativeName = type.get$definition().get$nativeType().get$name(); |
| 2397 if ($eq(nativeName, '')) { |
| 2398 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 2399 } |
| 2400 else if (type.get$jsname() != nativeName) { |
| 2401 this.writer.writeln(('' + type.get$jsname() + ' = ' + nativeName + ';')); |
| 2402 } |
| 2403 } |
| 2404 if (!type.get$isTop()) { |
| 2405 if ((type instanceof ConcreteType)) { |
| 2406 var c = type; |
| 2407 this.corejs.ensureInheritsHelper(); |
| 2408 this.writer.writeln(('\$inherits(' + c.get$jsname() + ', ' + c.genericType
.get$jsname() + ');')); |
| 2409 for (var p = c._parent; |
| 2410 (p instanceof ConcreteType); p = p.get$_parent()) { |
| 2411 this._ensureInheritMembersHelper(); |
| 2412 this._mixins.writeln(('\$inheritsMembers(' + c.get$jsname() + ', ' + p.g
et$jsname() + ');')); |
| 2413 } |
| 2414 } |
| 2415 else if (!type.get$isNative()) { |
| 2416 if (type.get$parent() != null && !type.get$parent().get$isObject()) { |
| 2417 this.corejs.ensureInheritsHelper(); |
| 2418 this.writer.writeln(('\$inherits(' + type.get$jsname() + ', ' + type.get
$parent().get$jsname() + ');')); |
| 2419 } |
| 2420 } |
| 2421 } |
| 2422 if (type.get$isTop()) { |
| 2423 } |
| 2424 else if (type.get$constructors().get$length() == 0) { |
| 2425 if (!type.get$isNative()) { |
| 2426 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 2427 } |
| 2428 } |
| 2429 else { |
| 2430 var standardConstructor = type.get$constructors().$index(''); |
| 2431 if (standardConstructor == null || standardConstructor.generator == null) { |
| 2432 if (!type.get$isNative()) { |
| 2433 this.writer.writeln(('function ' + type.get$jsname() + '() {}')); |
| 2434 } |
| 2435 } |
| 2436 else { |
| 2437 standardConstructor.generator.writeDefinition(this.writer, null); |
| 2438 } |
| 2439 var $$list = type.get$constructors().getValues(); |
| 2440 for (var $$i = type.get$constructors().getValues().iterator$0(); $$i.hasNext
$0(); ) { |
| 2441 var c = $$i.next$0(); |
| 2442 if (c.get$generator() != null && $ne(c, standardConstructor)) { |
| 2443 c.get$generator().writeDefinition$2(this.writer); |
| 2444 } |
| 2445 } |
| 2446 } |
| 2447 if (!(type instanceof ConcreteType)) { |
| 2448 this._maybeIsTest(type, type); |
| 2449 } |
| 2450 if (type.get$genericType()._concreteTypes != null) { |
| 2451 var $$list = this._orderValues(type.get$genericType()._concreteTypes); |
| 2452 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2453 var ct = $$list.$index($$i); |
| 2454 this._maybeIsTest(type, ct); |
| 2455 } |
| 2456 } |
| 2457 if (type.get$interfaces() != null) { |
| 2458 var seen = new HashSetImplementation(); |
| 2459 var worklist = []; |
| 2460 worklist.addAll(type.get$interfaces()); |
| 2461 seen.addAll(type.get$interfaces()); |
| 2462 while (!worklist.isEmpty()) { |
| 2463 var interface_ = worklist.removeLast(); |
| 2464 this._maybeIsTest(type, interface_.get$genericType()); |
| 2465 if (interface_.get$genericType().get$_concreteTypes() != null) { |
| 2466 var $$list = this._orderValues(interface_.get$genericType().get$_concret
eTypes()); |
| 2467 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2468 var ct = $$list.$index($$i); |
| 2469 this._maybeIsTest(type, ct); |
| 2470 } |
| 2471 } |
| 2472 var $$list = interface_.get$interfaces(); |
| 2473 for (var $$i = interface_.get$interfaces().iterator$0(); $$i.hasNext$0();
) { |
| 2474 var other = $$i.next$0(); |
| 2475 if (!seen.contains(other)) { |
| 2476 worklist.addLast(other); |
| 2477 seen.add(other); |
| 2478 } |
| 2479 } |
| 2480 } |
| 2481 } |
| 2482 type.get$factories().forEach(this.get$_writeMethod()); |
| 2483 var $$list = this._orderValues(type.get$members()); |
| 2484 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2485 var member = $$list.$index($$i); |
| 2486 if ((member instanceof FieldMember)) { |
| 2487 this._writeField(member); |
| 2488 } |
| 2489 if ((member instanceof PropertyMember)) { |
| 2490 this._writeProperty(member); |
| 2491 } |
| 2492 if (member.get$isMethod()) { |
| 2493 this._writeMethod(member); |
| 2494 } |
| 2495 } |
| 2496 this._writeDynamicStubs(type); |
| 2497 } |
| 2498 WorldGenerator.prototype._ensureInheritMembersHelper = function() { |
| 2499 if (this._mixins != null) return; |
| 2500 this._mixins = new CodeWriter(); |
| 2501 this._mixins.comment('// ********** Generic Type Inheritance **************'); |
| 2502 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}"); |
| 2503 } |
| 2504 WorldGenerator.prototype._writeDynamicStubs = function(type) { |
| 2505 var $$list = orderValuesByKeys(type.varStubs); |
| 2506 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2507 var stub = $$list.$index($$i); |
| 2508 if (!stub.get$isGenerated()) stub.generate$1(this.writer); |
| 2509 } |
| 2510 } |
| 2511 WorldGenerator.prototype._writeStaticField = function(field) { |
| 2512 if (field.isFinal) return; |
| 2513 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname
()); |
| 2514 if (this.globals.containsKey(fullname)) { |
| 2515 var value = this.globals.$index(fullname); |
| 2516 if (field.declaringType.get$isTop() && !field.isNative) { |
| 2517 this.writer.writeln(('\$globals.' + field.get$jsname() + ' = ' + value.get
$exp().get$code() + ';')); |
| 2518 } |
| 2519 else { |
| 2520 this.writer.writeln(('\$globals.' + field.declaringType.get$jsname() + '_'
+ field.get$jsname()) + (' = ' + value.get$exp().get$code() + ';')); |
| 2521 } |
| 2522 } |
| 2523 } |
| 2524 WorldGenerator.prototype._writeField = function(field) { |
| 2525 if (field.declaringType.get$isTop() && !field.isNative && field.value == null)
{ |
| 2526 this.writer.writeln(('var ' + field.get$jsname() + ';')); |
| 2527 } |
| 2528 if (field._providePropertySyntax) { |
| 2529 this.writer.writeln(this._prototypeOf(field.declaringType, ('get\$' + field.
get$jsname())) + (' = function() { return this.' + field.get$jsname() + '; };'))
; |
| 2530 if (!field.isFinal) { |
| 2531 this.writer.writeln(this._prototypeOf(field.declaringType, ('set\$' + fiel
d.get$jsname())) + (' = function(value) { return this.' + field.get$jsname() + '
= value; };')); |
| 2532 } |
| 2533 } |
| 2534 } |
| 2535 WorldGenerator.prototype._writeProperty = function(property) { |
| 2536 if (property.getter != null) this._writeMethod(property.getter); |
| 2537 if (property.setter != null) this._writeMethod(property.setter); |
| 2538 if (property._provideFieldSyntax) { |
| 2539 this.writer.enterBlock('Object.defineProperty(' + ('' + property.declaringTy
pe.get$jsname() + '.prototype, "' + property.get$jsname() + '", {')); |
| 2540 if (property.getter != null) { |
| 2541 this.writer.write(('get: ' + property.declaringType.get$jsname() + '.proto
type.' + property.getter.get$jsname())); |
| 2542 this.writer.writeln(property.setter == null ? '' : ','); |
| 2543 } |
| 2544 if (property.setter != null) { |
| 2545 this.writer.writeln(('set: ' + property.declaringType.get$jsname() + '.pro
totype.' + property.setter.get$jsname())); |
| 2546 } |
| 2547 this.writer.exitBlock('});'); |
| 2548 } |
| 2549 } |
| 2550 WorldGenerator.prototype._writeMethod = function(method) { |
| 2551 if (method.generator != null) { |
| 2552 method.generator.writeDefinition(this.writer, null); |
| 2553 } |
| 2554 } |
| 2555 WorldGenerator.prototype.get$_writeMethod = function() { |
| 2556 return WorldGenerator.prototype._writeMethod.bind(this); |
| 2557 } |
| 2558 WorldGenerator.prototype.writeGlobals = function() { |
| 2559 if (this.globals.get$length() > 0) { |
| 2560 this.writer.comment('// ********** Globals **************'); |
| 2561 var list = this.globals.getValues(); |
| 2562 list.sort$1((function (a, b) { |
| 2563 return a.compareTo$1(b); |
| 2564 }) |
| 2565 ); |
| 2566 this.writer.enterBlock('function \$static_init(){'); |
| 2567 for (var $$i = list.iterator$0(); $$i.hasNext$0(); ) { |
| 2568 var global = $$i.next$0(); |
| 2569 if (global.get$field() != null) { |
| 2570 this._writeStaticField(global.get$field()); |
| 2571 } |
| 2572 } |
| 2573 this.writer.exitBlock('}'); |
| 2574 for (var $$i = list.iterator$0(); $$i.hasNext$0(); ) { |
| 2575 var global0 = $$i.next$0(); |
| 2576 if (global0.get$field() == null) { |
| 2577 this.writer.writeln(('var ' + global0.get$name() + ' = ' + global0.get$e
xp().get$code() + ';')); |
| 2578 } |
| 2579 } |
| 2580 } |
| 2581 if (!this.corejs.useIsolates) { |
| 2582 if (this.hasStatics) { |
| 2583 this.writer.writeln('var \$globals = {};'); |
| 2584 } |
| 2585 if (this.globals.get$length() > 0) { |
| 2586 this.writer.writeln('\$static_init();'); |
| 2587 } |
| 2588 } |
| 2589 } |
| 2590 WorldGenerator.prototype._orderValues = function(map) { |
| 2591 var values = map.getValues(); |
| 2592 values.sort(this.get$_compareMembers()); |
| 2593 return values; |
| 2594 } |
| 2595 WorldGenerator.prototype._compareMembers = function(x, y) { |
| 2596 if (x.get$span() != null && y.get$span() != null) { |
| 2597 var spans = x.get$span().compareTo$1(y.get$span()); |
| 2598 if (spans != 0) return spans; |
| 2599 } |
| 2600 if (x.get$span() == null) return 1; |
| 2601 if (y.get$span() == null) return -1; |
| 2602 return x.get$name().compareTo$1(y.get$name()); |
| 2603 } |
| 2604 WorldGenerator.prototype.get$_compareMembers = function() { |
| 2605 return WorldGenerator.prototype._compareMembers.bind(this); |
| 2606 } |
| 2607 // ********** Code for BlockScope ************** |
| 2608 function BlockScope(enclosingMethod, parent, reentrant) { |
| 2609 this.enclosingMethod = enclosingMethod; |
| 2610 this.parent = parent; |
| 2611 this.reentrant = reentrant; |
| 2612 this._vars = new HashMapImplementation(); |
| 2613 this._jsNames = new HashSetImplementation(); |
| 2614 // Initializers done |
| 2615 if (this.get$isMethodScope()) { |
| 2616 this._closedOver = new HashSetImplementation(); |
| 2617 } |
| 2618 else { |
| 2619 this.reentrant = reentrant || this.parent.reentrant; |
| 2620 } |
| 2621 } |
| 2622 BlockScope.prototype.get$enclosingMethod = function() { return this.enclosingMet
hod; }; |
| 2623 BlockScope.prototype.set$enclosingMethod = function(value) { return this.enclosi
ngMethod = value; }; |
| 2624 BlockScope.prototype.get$parent = function() { return this.parent; }; |
| 2625 BlockScope.prototype.set$parent = function(value) { return this.parent = value;
}; |
| 2626 BlockScope.prototype.get$_vars = function() { return this._vars; }; |
| 2627 BlockScope.prototype.set$_vars = function(value) { return this._vars = value; }; |
| 2628 BlockScope.prototype.get$_jsNames = function() { return this._jsNames; }; |
| 2629 BlockScope.prototype.set$_jsNames = function(value) { return this._jsNames = val
ue; }; |
| 2630 BlockScope.prototype.get$_closedOver = function() { return this._closedOver; }; |
| 2631 BlockScope.prototype.set$_closedOver = function(value) { return this._closedOver
= value; }; |
| 2632 BlockScope.prototype.get$rethrow = function() { return this.rethrow; }; |
| 2633 BlockScope.prototype.set$rethrow = function(value) { return this.rethrow = value
; }; |
| 2634 BlockScope.prototype.get$reentrant = function() { return this.reentrant; }; |
| 2635 BlockScope.prototype.set$reentrant = function(value) { return this.reentrant = v
alue; }; |
| 2636 BlockScope.prototype.get$isMethodScope = function() { |
| 2637 return this.parent == null || $ne(this.parent.enclosingMethod, this.enclosingM
ethod); |
| 2638 } |
| 2639 BlockScope.prototype.get$methodScope = function() { |
| 2640 var s = this; |
| 2641 while (!s.get$isMethodScope()) s = s.get$parent(); |
| 2642 return s; |
| 2643 } |
| 2644 BlockScope.prototype.lookup = function(name) { |
| 2645 var ret = this._vars.$index(name); |
| 2646 if (ret != null) return ret; |
| 2647 for (var s = this.parent; |
| 2648 s != null; s = s.get$parent()) { |
| 2649 ret = s.get$_vars().$index(name); |
| 2650 if (ret != null) { |
| 2651 if ($ne(s.get$enclosingMethod(), this.enclosingMethod)) { |
| 2652 s.get$methodScope().get$_closedOver().add$1(ret.get$code()); |
| 2653 if (this.enclosingMethod.captures != null && s.get$reentrant()) { |
| 2654 this.enclosingMethod.captures.add(ret.get$code()); |
| 2655 } |
| 2656 } |
| 2657 return ret; |
| 2658 } |
| 2659 } |
| 2660 } |
| 2661 BlockScope.prototype._isDefinedInParent = function(name) { |
| 2662 if (this.get$isMethodScope() && this._closedOver.contains(name)) return true; |
| 2663 for (var s = this.parent; |
| 2664 s != null; s = s.get$parent()) { |
| 2665 if (s.get$_vars().containsKey$1(name)) return true; |
| 2666 if (s.get$_jsNames().contains$1(name)) return true; |
| 2667 if (s.get$isMethodScope() && s.get$_closedOver().contains$1(name)) return tr
ue; |
| 2668 } |
| 2669 var type = this.enclosingMethod.method.declaringType; |
| 2670 if (type.get$library().lookup(name, null) != null) return true; |
| 2671 return false; |
| 2672 } |
| 2673 BlockScope.prototype.create = function(name, type, span, isFinal, isParameter) { |
| 2674 var jsName = $globals.world.toJsIdentifier(name); |
| 2675 if (this._vars.containsKey(name)) { |
| 2676 $globals.world.error(('duplicate name "' + name + '"'), span); |
| 2677 } |
| 2678 if (!isParameter) { |
| 2679 var index = 0; |
| 2680 while (this._isDefinedInParent(jsName)) { |
| 2681 jsName = ('' + name + (index++)); |
| 2682 } |
| 2683 } |
| 2684 var ret = new Value(type, jsName, span, false); |
| 2685 ret.set$isFinal(isFinal); |
| 2686 this._vars.$setindex(name, ret); |
| 2687 if (name != jsName) this._jsNames.add(jsName); |
| 2688 return ret; |
| 2689 } |
| 2690 BlockScope.prototype.declareParameter = function(p) { |
| 2691 return this.create(p.name, p.type, p.definition.span, false, true); |
| 2692 } |
| 2693 BlockScope.prototype.declare = function(id) { |
| 2694 var type = this.enclosingMethod.method.resolveType(id.type, false); |
| 2695 return this.create(id.name.name, type, id.span, false, false); |
| 2696 } |
| 2697 BlockScope.prototype.getRethrow = function() { |
| 2698 var scope = this; |
| 2699 while (scope.get$rethrow() == null && scope.get$parent() != null) { |
| 2700 scope = scope.get$parent(); |
| 2701 } |
| 2702 return scope.get$rethrow(); |
| 2703 } |
| 2704 // ********** Code for MethodGenerator ************** |
| 2705 function MethodGenerator(method, enclosingMethod) { |
| 2706 this.method = method; |
| 2707 this.enclosingMethod = enclosingMethod; |
| 2708 this.writer = new CodeWriter(); |
| 2709 this.needsThis = false; |
| 2710 // Initializers done |
| 2711 if (this.enclosingMethod != null) { |
| 2712 this._scope = new BlockScope(this, this.enclosingMethod._scope, false); |
| 2713 this.captures = new HashSetImplementation(); |
| 2714 } |
| 2715 else { |
| 2716 this._scope = new BlockScope(this, null, false); |
| 2717 } |
| 2718 this._usedTemps = new HashSetImplementation(); |
| 2719 this._freeTemps = []; |
| 2720 } |
| 2721 MethodGenerator.prototype.get$enclosingMethod = function() { return this.enclosi
ngMethod; }; |
| 2722 MethodGenerator.prototype.set$enclosingMethod = function(value) { return this.en
closingMethod = value; }; |
| 2723 MethodGenerator.prototype.get$needsThis = function() { return this.needsThis; }; |
| 2724 MethodGenerator.prototype.set$needsThis = function(value) { return this.needsThi
s = value; }; |
| 2725 MethodGenerator.prototype.get$library = function() { |
| 2726 return this.method.get$library(); |
| 2727 } |
| 2728 MethodGenerator.prototype.findMembers = function(name) { |
| 2729 return this.get$library()._findMembers(name); |
| 2730 } |
| 2731 MethodGenerator.prototype.get$isClosure = function() { |
| 2732 return (this.enclosingMethod != null); |
| 2733 } |
| 2734 MethodGenerator.prototype.get$isStatic = function() { |
| 2735 return this.method.get$isStatic(); |
| 2736 } |
| 2737 MethodGenerator.prototype.getTemp = function(value) { |
| 2738 return value.needsTemp ? this.forceTemp(value) : value; |
| 2739 } |
| 2740 MethodGenerator.prototype.forceTemp = function(value) { |
| 2741 var name; |
| 2742 if (this._freeTemps.length > 0) { |
| 2743 name = this._freeTemps.removeLast(); |
| 2744 } |
| 2745 else { |
| 2746 name = '\$' + this._usedTemps.get$length(); |
| 2747 } |
| 2748 this._usedTemps.add(name); |
| 2749 return new Value(value.get$type(), name, value.span, false); |
| 2750 } |
| 2751 MethodGenerator.prototype.assignTemp = function(tmp, v) { |
| 2752 if ($eq(tmp, v)) { |
| 2753 return v; |
| 2754 } |
| 2755 else { |
| 2756 return new Value(v.get$type(), ('(' + tmp.code + ' = ' + v.code + ')'), v.sp
an, true); |
| 2757 } |
| 2758 } |
| 2759 MethodGenerator.prototype.freeTemp = function(value) { |
| 2760 if (this._usedTemps.remove(value.code)) { |
| 2761 this._freeTemps.add(value.code); |
| 2762 } |
| 2763 else { |
| 2764 $globals.world.internalError(('tried to free unused value or non-temp "' + v
alue.code + '"')); |
| 2765 } |
| 2766 } |
| 2767 MethodGenerator.prototype.run = function() { |
| 2768 if (this.method.isGenerated) return; |
| 2769 this.method.isGenerated = true; |
| 2770 this.method.generator = this; |
| 2771 this.writeBody(); |
| 2772 if (this.method.get$definition().get$nativeBody() != null) { |
| 2773 this.writer = new CodeWriter(); |
| 2774 if ($eq(this.method.get$definition().get$nativeBody(), '')) { |
| 2775 this.method.generator = null; |
| 2776 } |
| 2777 else { |
| 2778 this._paramCode = map(this.method.get$parameters(), (function (p) { |
| 2779 return p.get$name(); |
| 2780 }) |
| 2781 ); |
| 2782 this.writer.write(this.method.get$definition().get$nativeBody()); |
| 2783 } |
| 2784 } |
| 2785 } |
| 2786 MethodGenerator.prototype.writeDefinition = function(defWriter, lambda) { |
| 2787 var paramCode = this._paramCode; |
| 2788 var names = null; |
| 2789 if (this.captures != null && this.captures.get$length() > 0) { |
| 2790 names = ListFactory.ListFactory$from$factory(this.captures); |
| 2791 names.sort$1((function (x, y) { |
| 2792 return x.compareTo$1(y); |
| 2793 }) |
| 2794 ); |
| 2795 paramCode = ListFactory.ListFactory$from$factory(names); |
| 2796 paramCode.addAll$1(this._paramCode); |
| 2797 } |
| 2798 var _params = ('(' + Strings.join(this._paramCode, ", ") + ')'); |
| 2799 var params = ('(' + Strings.join(paramCode, ", ") + ')'); |
| 2800 if (this.method.declaringType.get$isTop() && !this.get$isClosure()) { |
| 2801 defWriter.enterBlock(('function ' + this.method.get$jsname() + params + ' {'
)); |
| 2802 } |
| 2803 else if (this.get$isClosure()) { |
| 2804 if (this.method.name == '') { |
| 2805 defWriter.enterBlock(('(function ' + params + ' {')); |
| 2806 } |
| 2807 else if (names != null) { |
| 2808 if (lambda == null) { |
| 2809 defWriter.enterBlock(('var ' + this.method.get$jsname() + ' = (function'
+ params + ' {')); |
| 2810 } |
| 2811 else { |
| 2812 defWriter.enterBlock(('(function ' + this.method.get$jsname() + params +
' {')); |
| 2813 } |
| 2814 } |
| 2815 else { |
| 2816 defWriter.enterBlock(('function ' + this.method.get$jsname() + params + '
{')); |
| 2817 } |
| 2818 } |
| 2819 else if (this.method.get$isConstructor()) { |
| 2820 if (this.method.get$constructorName() == '') { |
| 2821 defWriter.enterBlock(('function ' + this.method.declaringType.get$jsname()
+ params + ' {')); |
| 2822 } |
| 2823 else { |
| 2824 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' +
this.method.get$constructorName() + '\$ctor = function' + params + ' {')); |
| 2825 } |
| 2826 } |
| 2827 else if (this.method.get$isFactory()) { |
| 2828 defWriter.enterBlock(('' + this.method.get$generatedFactoryName() + ' = func
tion' + _params + ' {')); |
| 2829 } |
| 2830 else if (this.method.get$isStatic()) { |
| 2831 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' + th
is.method.get$jsname() + ' = function' + _params + ' {')); |
| 2832 } |
| 2833 else { |
| 2834 defWriter.enterBlock($globals.world.gen._prototypeOf(this.method.declaringTy
pe, this.method.get$jsname()) + (' = function' + _params + ' {')); |
| 2835 } |
| 2836 if (this.needsThis) { |
| 2837 defWriter.writeln('var \$this = this; // closure support'); |
| 2838 } |
| 2839 if (this._usedTemps.get$length() > 0 || this._freeTemps.length > 0) { |
| 2840 this._freeTemps.addAll(this._usedTemps); |
| 2841 this._freeTemps.sort((function (x, y) { |
| 2842 return x.compareTo$1(y); |
| 2843 }) |
| 2844 ); |
| 2845 defWriter.writeln(('var ' + Strings.join(this._freeTemps, ", ") + ';')); |
| 2846 } |
| 2847 defWriter.writeln(this.writer.get$text()); |
| 2848 if (names != null) { |
| 2849 defWriter.exitBlock(('}).bind(null, ' + Strings.join(names, ", ") + ')')); |
| 2850 } |
| 2851 else if (this.get$isClosure() && this.method.name == '') { |
| 2852 defWriter.exitBlock('})'); |
| 2853 } |
| 2854 else { |
| 2855 defWriter.exitBlock('}'); |
| 2856 } |
| 2857 if (this.method.get$isConstructor() && this.method.get$constructorName() != ''
) { |
| 2858 defWriter.writeln(('' + this.method.declaringType.get$jsname() + '.' + this.
method.get$constructorName() + '\$ctor.prototype = ') + ('' + this.method.declar
ingType.get$jsname() + '.prototype;')); |
| 2859 } |
| 2860 this._provideOptionalParamInfo(defWriter); |
| 2861 if ((this.method instanceof MethodMember)) { |
| 2862 var m = this.method; |
| 2863 if (m._providePropertySyntax) { |
| 2864 defWriter.enterBlock(('' + m.declaringType.get$jsname() + '.prototype') +
('.get\$' + m.get$jsname() + ' = function() {')); |
| 2865 defWriter.writeln(('return ' + m.declaringType.get$jsname() + '.prototype.
') + ('' + m.get$jsname() + '.bind(this);')); |
| 2866 defWriter.exitBlock('}'); |
| 2867 if (m._provideFieldSyntax) { |
| 2868 $globals.world.internalError('bound m accessed with field syntax'); |
| 2869 } |
| 2870 } |
| 2871 } |
| 2872 } |
| 2873 MethodGenerator.prototype._provideOptionalParamInfo = function(defWriter) { |
| 2874 if ((this.method instanceof MethodMember)) { |
| 2875 var meth = this.method; |
| 2876 if (meth._provideOptionalParamInfo) { |
| 2877 var optNames = []; |
| 2878 var optValues = []; |
| 2879 meth.genParameterValues(); |
| 2880 var $$list = meth.parameters; |
| 2881 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2882 var param = $$list.$index($$i); |
| 2883 if (param.get$isOptional()) { |
| 2884 optNames.add$1(param.get$name()); |
| 2885 optValues.add$1(MethodGenerator._escapeString(param.get$value().get$co
de())); |
| 2886 } |
| 2887 } |
| 2888 if (optNames.length > 0) { |
| 2889 var start = ''; |
| 2890 if (meth.isStatic) { |
| 2891 if (!meth.declaringType.get$isTop()) { |
| 2892 start = meth.declaringType.get$jsname() + '.'; |
| 2893 } |
| 2894 } |
| 2895 else { |
| 2896 start = meth.declaringType.get$jsname() + '.prototype.'; |
| 2897 } |
| 2898 optNames.addAll$1(optValues); |
| 2899 var optional = "['" + Strings.join(optNames, "', '") + "']"; |
| 2900 defWriter.writeln(('' + start + meth.get$jsname() + '.\$optional = ' + o
ptional)); |
| 2901 } |
| 2902 } |
| 2903 } |
| 2904 } |
| 2905 MethodGenerator.prototype.writeBody = function() { |
| 2906 var initializers = null; |
| 2907 var initializedFields = null; |
| 2908 var allMembers = null; |
| 2909 if (this.method.get$isConstructor()) { |
| 2910 initializers = []; |
| 2911 initializedFields = new HashSetImplementation(); |
| 2912 allMembers = $globals.world.gen._orderValues(this.method.declaringType.getAl
lMembers()); |
| 2913 for (var $$i = allMembers.iterator$0(); $$i.hasNext$0(); ) { |
| 2914 var f = $$i.next$0(); |
| 2915 if (f.get$isField() && !f.get$isStatic()) { |
| 2916 var cv = f.computeValue$0(); |
| 2917 if (cv != null) { |
| 2918 initializers.add$1(('this.' + f.get$jsname() + ' = ' + cv.get$code()))
; |
| 2919 initializedFields.add$1(f.get$name()); |
| 2920 } |
| 2921 } |
| 2922 } |
| 2923 } |
| 2924 this._paramCode = []; |
| 2925 var $$list = this.method.get$parameters(); |
| 2926 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 2927 var p = $$list.$index($$i); |
| 2928 if (initializers != null && p.get$isInitializer()) { |
| 2929 var field = this.method.declaringType.getMember(p.get$name()); |
| 2930 if (field == null) { |
| 2931 $globals.world.error('bad this parameter - no matching field', p.get$def
inition().get$span()); |
| 2932 } |
| 2933 if (!field.get$isField()) { |
| 2934 $globals.world.error(('"this.' + p.get$name() + '" does not refer to a f
ield'), p.get$definition().get$span()); |
| 2935 } |
| 2936 var paramValue = new Value(field.get$returnType(), p.get$name(), p.get$def
inition().get$span(), false); |
| 2937 this._paramCode.add(paramValue.get$code()); |
| 2938 initializers.add$1(('this.' + field.get$jsname() + ' = ' + paramValue.get$
code() + ';')); |
| 2939 initializedFields.add$1(p.get$name()); |
| 2940 } |
| 2941 else { |
| 2942 var paramValue = this._scope.declareParameter(p); |
| 2943 this._paramCode.add(paramValue.get$code()); |
| 2944 } |
| 2945 } |
| 2946 var body = this.method.get$definition().get$body(); |
| 2947 if (body == null && !this.method.get$isConstructor() && !this.method.get$isNat
ive()) { |
| 2948 $globals.world.error(('unexpected empty body for ' + this.method.name), this
.method.get$definition().get$span()); |
| 2949 } |
| 2950 var initializerCall = null; |
| 2951 var declaredInitializers = this.method.get$definition().get$initializers(); |
| 2952 if (initializers != null) { |
| 2953 for (var $$i = initializers.iterator$0(); $$i.hasNext$0(); ) { |
| 2954 var i = $$i.next$0(); |
| 2955 this.writer.writeln(i); |
| 2956 } |
| 2957 if (declaredInitializers != null) { |
| 2958 for (var $$i = declaredInitializers.iterator$0(); $$i.hasNext$0(); ) { |
| 2959 var init = $$i.next$0(); |
| 2960 if ((init instanceof CallExpression)) { |
| 2961 if (initializerCall != null) { |
| 2962 $globals.world.error('only one initializer redirecting call is allow
ed', init.get$span()); |
| 2963 } |
| 2964 initializerCall = init; |
| 2965 } |
| 2966 else if ((init instanceof BinaryExpression) && TokenKind.kindFromAssign(
init.get$op().get$kind()) == 0) { |
| 2967 var left = init.get$x(); |
| 2968 if (!((left instanceof DotExpression) && (left.get$self() instanceof T
hisExpression) || (left instanceof VarExpression))) { |
| 2969 $globals.world.error('invalid left side of initializer', left.get$sp
an()); |
| 2970 continue; |
| 2971 } |
| 2972 var f = this.method.declaringType.getMember(left.get$name().get$name()
); |
| 2973 if (f == null) { |
| 2974 $globals.world.error('bad initializer - no matching field', left.get
$span()); |
| 2975 continue; |
| 2976 } |
| 2977 else if (!f.get$isField()) { |
| 2978 $globals.world.error(('"' + left.get$name().get$name() + '" does not
refer to a field'), left.get$span()); |
| 2979 continue; |
| 2980 } |
| 2981 initializedFields.add$1(f.get$name()); |
| 2982 this.writer.writeln(('this.' + f.get$jsname() + ' = ' + this.visitValu
e(init.get$y()).get$code() + ';')); |
| 2983 } |
| 2984 else { |
| 2985 $globals.world.error('invalid initializer', init.get$span()); |
| 2986 } |
| 2987 } |
| 2988 } |
| 2989 this.writer.comment('// Initializers done'); |
| 2990 } |
| 2991 if (this.method.get$isConstructor() && initializerCall == null && !this.method
.get$isNative()) { |
| 2992 var parentType = this.method.declaringType.get$parent(); |
| 2993 if (parentType != null && !parentType.get$isObject()) { |
| 2994 initializerCall = new CallExpression(new SuperExpression(this.method.get$s
pan()), [], this.method.get$span()); |
| 2995 } |
| 2996 } |
| 2997 if (initializerCall != null) { |
| 2998 var target = this._writeInitializerCall(initializerCall); |
| 2999 if (!target.get$isSuper()) { |
| 3000 if (initializers.length > 0) { |
| 3001 var $$list = this.method.get$parameters(); |
| 3002 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3003 var p = $$list.$index($$i); |
| 3004 if (p.get$isInitializer()) { |
| 3005 $globals.world.error('no initialization allowed on redirecting const
ructors', p.get$definition().get$span()); |
| 3006 break; |
| 3007 } |
| 3008 } |
| 3009 } |
| 3010 if (declaredInitializers != null && declaredInitializers.length > 1) { |
| 3011 var init = $eq(declaredInitializers.$index(0), initializerCall) ? declar
edInitializers.$index(1) : declaredInitializers.$index(0); |
| 3012 $globals.world.error('no initialization allowed on redirecting construct
ors', init.get$span()); |
| 3013 } |
| 3014 initializedFields = null; |
| 3015 } |
| 3016 } |
| 3017 if (initializedFields != null) { |
| 3018 for (var $$i = allMembers.iterator$0(); $$i.hasNext$0(); ) { |
| 3019 var member = $$i.next$0(); |
| 3020 if (member.get$isField() && member.get$isFinal() && !member.get$isStatic()
&& !this.method.get$isNative() && !initializedFields.contains$1(member.get$name
())) { |
| 3021 $globals.world.error(('Field "' + member.get$name() + '" is final and wa
s not initialized'), this.method.get$definition().get$span()); |
| 3022 } |
| 3023 } |
| 3024 } |
| 3025 this.visitStatementsInBlock(body); |
| 3026 } |
| 3027 MethodGenerator.prototype._writeInitializerCall = function(node) { |
| 3028 var contructorName = ''; |
| 3029 var targetExp = node.target; |
| 3030 if ((targetExp instanceof DotExpression)) { |
| 3031 var dot = targetExp; |
| 3032 targetExp = dot.self; |
| 3033 contructorName = dot.name.name; |
| 3034 } |
| 3035 var target = null; |
| 3036 if ((targetExp instanceof SuperExpression)) { |
| 3037 target = this._makeSuperValue(targetExp); |
| 3038 } |
| 3039 else if ((targetExp instanceof ThisExpression)) { |
| 3040 target = this._makeThisValue(targetExp); |
| 3041 } |
| 3042 else { |
| 3043 $globals.world.error('bad call in initializers', node.span); |
| 3044 } |
| 3045 target.set$allowDynamic(false); |
| 3046 var m = target.get$type().getConstructor$1(contructorName); |
| 3047 if (m == null) { |
| 3048 $globals.world.error(('no matching constructor for ' + target.get$type().get
$name()), node.span); |
| 3049 } |
| 3050 this.method.set$initDelegate(m); |
| 3051 var other = m; |
| 3052 while (other != null) { |
| 3053 if ($eq(other, this.method)) { |
| 3054 $globals.world.error('initialization cycle', node.span); |
| 3055 break; |
| 3056 } |
| 3057 other = other.get$initDelegate(); |
| 3058 } |
| 3059 $globals.world.gen.genMethod(m); |
| 3060 var value = m.invoke$4(this, node, target, this._makeArgs(node.arguments)); |
| 3061 if ($ne(target.get$type(), $globals.world.objectType)) { |
| 3062 this.writer.writeln(('' + value.get$code() + ';')); |
| 3063 } |
| 3064 return target; |
| 3065 } |
| 3066 MethodGenerator.prototype._makeArgs = function(arguments) { |
| 3067 var args = []; |
| 3068 var seenLabel = false; |
| 3069 for (var $$i = 0;$$i < arguments.length; $$i++) { |
| 3070 var arg = arguments.$index($$i); |
| 3071 if (arg.get$label() != null) { |
| 3072 seenLabel = true; |
| 3073 } |
| 3074 else if (seenLabel) { |
| 3075 $globals.world.error('bare argument can not follow named arguments', arg.g
et$span()); |
| 3076 } |
| 3077 args.add$1(this.visitValue(arg.get$value())); |
| 3078 } |
| 3079 return new Arguments(arguments, args); |
| 3080 } |
| 3081 MethodGenerator.prototype._invokeNative = function(name, arguments) { |
| 3082 var args = Arguments.get$EMPTY(); |
| 3083 if (arguments.length > 0) { |
| 3084 args = new Arguments(null, arguments); |
| 3085 } |
| 3086 var method = $globals.world.corelib.topType.members.$index(name); |
| 3087 return method.invoke$4(this, method.get$definition(), new Value($globals.world
.corelib.topType, null, null, true), args); |
| 3088 } |
| 3089 MethodGenerator._escapeString = function(text) { |
| 3090 return text.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '
\\n').replaceAll('\r', '\\r'); |
| 3091 } |
| 3092 MethodGenerator.prototype.visitStatementsInBlock = function(body) { |
| 3093 if ((body instanceof BlockStatement)) { |
| 3094 var block = body; |
| 3095 var $$list = block.body; |
| 3096 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3097 var stmt = $$list.$index($$i); |
| 3098 stmt.visit$1(this); |
| 3099 } |
| 3100 } |
| 3101 else { |
| 3102 if (body != null) body.visit(this); |
| 3103 } |
| 3104 return false; |
| 3105 } |
| 3106 MethodGenerator.prototype._pushBlock = function(reentrant) { |
| 3107 this._scope = new BlockScope(this, this._scope, reentrant); |
| 3108 } |
| 3109 MethodGenerator.prototype._popBlock = function() { |
| 3110 this._scope = this._scope.parent; |
| 3111 } |
| 3112 MethodGenerator.prototype._makeLambdaMethod = function(name, func) { |
| 3113 var meth = new MethodMember(name, this.method.declaringType, func); |
| 3114 meth.set$isLambda(true); |
| 3115 meth.set$enclosingElement(this.method); |
| 3116 meth.resolve$0(); |
| 3117 return meth; |
| 3118 } |
| 3119 MethodGenerator.prototype.visitBool = function(node) { |
| 3120 return this.visitValue(node).convertTo$3(this, $globals.world.nonNullBool, nod
e); |
| 3121 } |
| 3122 MethodGenerator.prototype.visitValue = function(node) { |
| 3123 if (node == null) return null; |
| 3124 var value = node.visit(this); |
| 3125 value.checkFirstClass$1(node.span); |
| 3126 return value; |
| 3127 } |
| 3128 MethodGenerator.prototype.visitTypedValue = function(node, expectedType) { |
| 3129 var val = this.visitValue(node); |
| 3130 return expectedType == null ? val : val.convertTo$3(this, expectedType, node); |
| 3131 } |
| 3132 MethodGenerator.prototype.visitVoid = function(node) { |
| 3133 if ((node instanceof PostfixExpression)) { |
| 3134 var value = this.visitPostfixExpression(node, true); |
| 3135 value.checkFirstClass$1(node.span); |
| 3136 return value; |
| 3137 } |
| 3138 else if ((node instanceof BinaryExpression)) { |
| 3139 var value = this.visitBinaryExpression(node, true); |
| 3140 value.checkFirstClass$1(node.span); |
| 3141 return value; |
| 3142 } |
| 3143 return this.visitValue(node); |
| 3144 } |
| 3145 MethodGenerator.prototype.visitDietStatement = function(node) { |
| 3146 var parser = new Parser(node.span.file, false, false, false, node.span.start); |
| 3147 this.visitStatementsInBlock(parser.block$0()); |
| 3148 return false; |
| 3149 } |
| 3150 MethodGenerator.prototype.visitVariableDefinition = function(node) { |
| 3151 var isFinal = false; |
| 3152 if (node.modifiers != null && $eq(node.modifiers.$index(0).get$kind(), 98/*Tok
enKind.FINAL*/)) { |
| 3153 isFinal = true; |
| 3154 } |
| 3155 this.writer.write('var '); |
| 3156 var type = this.method.resolveType(node.type, false); |
| 3157 for (var i = 0; |
| 3158 i < node.names.length; i++) { |
| 3159 var thisType = type; |
| 3160 if (i > 0) { |
| 3161 this.writer.write(', '); |
| 3162 } |
| 3163 var name = node.names.$index(i).get$name(); |
| 3164 var value = this.visitValue(node.values.$index(i)); |
| 3165 if (isFinal) { |
| 3166 if (value == null) { |
| 3167 $globals.world.error('no value specified for final variable', node.span)
; |
| 3168 } |
| 3169 else { |
| 3170 if (thisType.get$isVar()) thisType = value.get$type(); |
| 3171 } |
| 3172 } |
| 3173 var val = this._scope.create(name, thisType, node.names.$index(i).get$span()
, isFinal, false); |
| 3174 if (value == null) { |
| 3175 if (this._scope.reentrant) { |
| 3176 this.writer.write(('' + val.get$code() + ' = null')); |
| 3177 } |
| 3178 else { |
| 3179 this.writer.write(('' + val.get$code())); |
| 3180 } |
| 3181 } |
| 3182 else { |
| 3183 value = value.convertTo$3(this, type, node.values.$index(i)); |
| 3184 this.writer.write(('' + val.get$code() + ' = ' + value.get$code())); |
| 3185 } |
| 3186 } |
| 3187 this.writer.writeln(';'); |
| 3188 return false; |
| 3189 } |
| 3190 MethodGenerator.prototype.visitFunctionDefinition = function(node) { |
| 3191 var meth = this._makeLambdaMethod(node.name.name, node); |
| 3192 var funcValue = this._scope.create(meth.get$name(), meth.get$functionType(), t
his.method.get$definition().get$span(), true, false); |
| 3193 $globals.world.gen.genMethod(meth, this); |
| 3194 meth.get$generator().writeDefinition$2(this.writer); |
| 3195 return false; |
| 3196 } |
| 3197 MethodGenerator.prototype.visitReturnStatement = function(node) { |
| 3198 if (node.value == null) { |
| 3199 this.writer.writeln('return;'); |
| 3200 } |
| 3201 else { |
| 3202 if (this.method.get$isConstructor()) { |
| 3203 $globals.world.error('return of value not allowed from constructor', node.
span); |
| 3204 } |
| 3205 var value = this.visitTypedValue(node.value, this.method.get$returnType()); |
| 3206 this.writer.writeln(('return ' + value.get$code() + ';')); |
| 3207 } |
| 3208 return true; |
| 3209 } |
| 3210 MethodGenerator.prototype.visitThrowStatement = function(node) { |
| 3211 if (node.value != null) { |
| 3212 var value = this.visitValue(node.value); |
| 3213 value.invoke$4(this, 'toString', node, Arguments.get$EMPTY()); |
| 3214 this.writer.writeln(('\$throw(' + value.get$code() + ');')); |
| 3215 $globals.world.gen.corejs.useThrow = true; |
| 3216 } |
| 3217 else { |
| 3218 var rethrow = this._scope.getRethrow(); |
| 3219 if (rethrow == null) { |
| 3220 $globals.world.error('rethrow outside of catch', node.span); |
| 3221 } |
| 3222 else { |
| 3223 this.writer.writeln(('throw ' + rethrow.get$code() + ';')); |
| 3224 } |
| 3225 } |
| 3226 return true; |
| 3227 } |
| 3228 MethodGenerator.prototype.visitAssertStatement = function(node) { |
| 3229 var test = this.visitValue(node.test); |
| 3230 if ($globals.options.enableAsserts) { |
| 3231 var span = node.test.span; |
| 3232 var line = span.get$file().getLine$1(span.get$start()) + 1; |
| 3233 var column = span.get$file().getColumn$2(line - 1, span.get$start()) + 1; |
| 3234 var args = [test, EvaluatedValue.EvaluatedValue$factory($globals.world.strin
gType, MethodGenerator._escapeString(span.get$text()), ('"' + MethodGenerator._e
scapeString(span.get$text()) + '"'), null), EvaluatedValue.EvaluatedValue$factor
y($globals.world.stringType, MethodGenerator._escapeString(span.get$file().get$f
ilename()), ('"' + MethodGenerator._escapeString(span.get$file().get$filename())
+ '"'), null), EvaluatedValue.EvaluatedValue$factory($globals.world.intType, li
ne, line.toString$0(), null), EvaluatedValue.EvaluatedValue$factory($globals.wor
ld.intType, column, column.toString$0(), null)]; |
| 3235 var tp = $globals.world.corelib.topType; |
| 3236 var f = tp.getMember$1('_assert'); |
| 3237 var value = f.invoke(this, node, new Value.type$ctor(tp, null), new Argument
s(null, args), false); |
| 3238 this.writer.writeln(('' + value.get$code() + ';')); |
| 3239 } |
| 3240 return false; |
| 3241 } |
| 3242 MethodGenerator.prototype.visitBreakStatement = function(node) { |
| 3243 if (node.label == null) { |
| 3244 this.writer.writeln('break;'); |
| 3245 } |
| 3246 else { |
| 3247 this.writer.writeln(('break ' + node.label.name + ';')); |
| 3248 } |
| 3249 return true; |
| 3250 } |
| 3251 MethodGenerator.prototype.visitContinueStatement = function(node) { |
| 3252 if (node.label == null) { |
| 3253 this.writer.writeln('continue;'); |
| 3254 } |
| 3255 else { |
| 3256 this.writer.writeln(('continue ' + node.label.name + ';')); |
| 3257 } |
| 3258 return true; |
| 3259 } |
| 3260 MethodGenerator.prototype.visitIfStatement = function(node) { |
| 3261 var test = this.visitBool(node.test); |
| 3262 this.writer.write(('if (' + test.get$code() + ') ')); |
| 3263 var exit1 = node.trueBranch.visit(this); |
| 3264 if (node.falseBranch != null) { |
| 3265 this.writer.write('else '); |
| 3266 if (node.falseBranch.visit(this) && exit1) { |
| 3267 return true; |
| 3268 } |
| 3269 } |
| 3270 return false; |
| 3271 } |
| 3272 MethodGenerator.prototype.visitWhileStatement = function(node) { |
| 3273 var test = this.visitBool(node.test); |
| 3274 this.writer.write(('while (' + test.get$code() + ') ')); |
| 3275 this._pushBlock(true); |
| 3276 node.body.visit(this); |
| 3277 this._popBlock(); |
| 3278 return false; |
| 3279 } |
| 3280 MethodGenerator.prototype.visitDoStatement = function(node) { |
| 3281 this.writer.write('do '); |
| 3282 this._pushBlock(true); |
| 3283 node.body.visit(this); |
| 3284 this._popBlock(); |
| 3285 var test = this.visitBool(node.test); |
| 3286 this.writer.writeln(('while (' + test.get$code() + ')')); |
| 3287 return false; |
| 3288 } |
| 3289 MethodGenerator.prototype.visitForStatement = function(node) { |
| 3290 this._pushBlock(false); |
| 3291 this.writer.write('for ('); |
| 3292 if (node.init != null) node.init.visit(this); |
| 3293 else this.writer.write(';'); |
| 3294 if (node.test != null) { |
| 3295 var test = this.visitBool(node.test); |
| 3296 this.writer.write((' ' + test.get$code() + '; ')); |
| 3297 } |
| 3298 else { |
| 3299 this.writer.write('; '); |
| 3300 } |
| 3301 var needsComma = false; |
| 3302 var $$list = node.step; |
| 3303 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3304 var s = $$list.$index($$i); |
| 3305 if (needsComma) this.writer.write(', '); |
| 3306 var sv = this.visitVoid(s); |
| 3307 this.writer.write(sv.get$code()); |
| 3308 needsComma = true; |
| 3309 } |
| 3310 this.writer.write(') '); |
| 3311 this._pushBlock(true); |
| 3312 node.body.visit(this); |
| 3313 this._popBlock(); |
| 3314 this._popBlock(); |
| 3315 return false; |
| 3316 } |
| 3317 MethodGenerator.prototype._isFinal = function(typeRef) { |
| 3318 if ((typeRef instanceof GenericTypeReference)) { |
| 3319 typeRef = typeRef.get$baseType(); |
| 3320 } |
| 3321 return typeRef != null && typeRef.get$isFinal(); |
| 3322 } |
| 3323 MethodGenerator.prototype.visitForInStatement = function(node) { |
| 3324 var itemType = this.method.resolveType(node.item.type, false); |
| 3325 var itemName = node.item.name.name; |
| 3326 var list = node.list.visit(this); |
| 3327 this._pushBlock(true); |
| 3328 var isFinal = this._isFinal(node.item.type); |
| 3329 var item = this._scope.create(itemName, itemType, node.item.name.span, isFinal
, false); |
| 3330 var listVar = list; |
| 3331 if (list.get$needsTemp()) { |
| 3332 listVar = this._scope.create('\$list', list.get$type(), null, false, false); |
| 3333 this.writer.writeln(('var ' + listVar.code + ' = ' + list.get$code() + ';'))
; |
| 3334 } |
| 3335 if (list.get$type().get$isList()) { |
| 3336 var tmpi = this._scope.create('\$i', $globals.world.numType, null, false, fa
lse); |
| 3337 this.writer.enterBlock(('for (var ' + tmpi.get$code() + ' = 0;') + ('' + tmp
i.get$code() + ' < ' + listVar.code + '.length; ' + tmpi.get$code() + '++) {')); |
| 3338 var value = listVar.invoke(this, ':index', node.list, new Arguments(null, [t
mpi]), false); |
| 3339 this.writer.writeln(('var ' + item.get$code() + ' = ' + value.get$code() + '
;')); |
| 3340 } |
| 3341 else { |
| 3342 this._pushBlock(false); |
| 3343 var iterator = list.invoke$4(this, 'iterator', node.list, Arguments.get$EMPT
Y()); |
| 3344 var tmpi = this._scope.create('\$i', iterator.get$type(), null, false, false
); |
| 3345 var hasNext = tmpi.invoke$4(this, 'hasNext', node.list, Arguments.get$EMPTY(
)); |
| 3346 var next = tmpi.invoke$4(this, 'next', node.list, Arguments.get$EMPTY()); |
| 3347 this.writer.enterBlock(('for (var ' + tmpi.get$code() + ' = ' + iterator.get
$code() + '; ' + hasNext.get$code() + '; ) {')); |
| 3348 this.writer.writeln(('var ' + item.get$code() + ' = ' + next.get$code() + ';
')); |
| 3349 } |
| 3350 this.visitStatementsInBlock(node.body); |
| 3351 this.writer.exitBlock('}'); |
| 3352 this._popBlock(); |
| 3353 return false; |
| 3354 } |
| 3355 MethodGenerator.prototype._genToDartException = function(ex, node) { |
| 3356 var result = this._invokeNative("_toDartException", [ex]); |
| 3357 this.writer.writeln(('' + ex.code + ' = ' + result.get$code() + ';')); |
| 3358 } |
| 3359 MethodGenerator.prototype.visitTryStatement = function(node) { |
| 3360 this.writer.enterBlock('try {'); |
| 3361 this._pushBlock(false); |
| 3362 this.visitStatementsInBlock(node.body); |
| 3363 this._popBlock(); |
| 3364 if (node.catches.length == 1) { |
| 3365 var catch_ = node.catches.$index(0); |
| 3366 this._pushBlock(false); |
| 3367 var exType = this.method.resolveType(catch_.get$exception().get$type(), fals
e); |
| 3368 var ex = this._scope.declare(catch_.get$exception()); |
| 3369 this._scope.rethrow = ex; |
| 3370 this.writer.nextBlock(('} catch (' + ex.get$code() + ') {')); |
| 3371 if (catch_.get$trace() != null) { |
| 3372 var trace = this._scope.declare(catch_.get$trace()); |
| 3373 this.writer.writeln(('var ' + trace.get$code() + ' = \$stackTraceOf(' + ex
.get$code() + ');')); |
| 3374 $globals.world.gen.corejs.useStackTraceOf = true; |
| 3375 } |
| 3376 this._genToDartException(ex, node); |
| 3377 if (!exType.get$isVarOrObject()) { |
| 3378 var test = ex.instanceOf$3$isTrue$forceCheck(this, exType, catch_.get$exce
ption().get$span(), false, true); |
| 3379 this.writer.writeln(('if (' + test.get$code() + ') throw ' + ex.get$code()
+ ';')); |
| 3380 } |
| 3381 this.visitStatementsInBlock(node.catches.$index(0).get$body()); |
| 3382 this._popBlock(); |
| 3383 } |
| 3384 else if (node.catches.length > 0) { |
| 3385 this._pushBlock(false); |
| 3386 var ex = this._scope.create('\$ex', $globals.world.varType, null, false, fal
se); |
| 3387 this._scope.rethrow = ex; |
| 3388 this.writer.nextBlock(('} catch (' + ex.get$code() + ') {')); |
| 3389 var trace = null; |
| 3390 if (node.catches.some((function (c) { |
| 3391 return c.get$trace() != null; |
| 3392 }) |
| 3393 )) { |
| 3394 trace = this._scope.create('\$trace', $globals.world.varType, null, false,
false); |
| 3395 this.writer.writeln(('var ' + trace.get$code() + ' = \$stackTraceOf(' + ex
.get$code() + ');')); |
| 3396 $globals.world.gen.corejs.useStackTraceOf = true; |
| 3397 } |
| 3398 this._genToDartException(ex, node); |
| 3399 var needsRethrow = true; |
| 3400 for (var i = 0; |
| 3401 i < node.catches.length; i++) { |
| 3402 var catch_ = node.catches.$index(i); |
| 3403 this._pushBlock(false); |
| 3404 var tmpType = this.method.resolveType(catch_.get$exception().get$type(), f
alse); |
| 3405 var tmp = this._scope.declare(catch_.get$exception()); |
| 3406 if (!tmpType.get$isVarOrObject()) { |
| 3407 var test = ex.instanceOf$3$isTrue$forceCheck(this, tmpType, catch_.get$e
xception().get$span(), true, true); |
| 3408 if (i == 0) { |
| 3409 this.writer.enterBlock(('if (' + test.get$code() + ') {')); |
| 3410 } |
| 3411 else { |
| 3412 this.writer.nextBlock(('} else if (' + test.get$code() + ') {')); |
| 3413 } |
| 3414 } |
| 3415 else if (i > 0) { |
| 3416 this.writer.nextBlock('} else {'); |
| 3417 } |
| 3418 this.writer.writeln(('var ' + tmp.get$code() + ' = ' + ex.get$code() + ';'
)); |
| 3419 if (catch_.get$trace() != null) { |
| 3420 var tmptrace = this._scope.declare(catch_.get$trace()); |
| 3421 this.writer.writeln(('var ' + tmptrace.get$code() + ' = ' + trace.get$co
de() + ';')); |
| 3422 } |
| 3423 this.visitStatementsInBlock(catch_.get$body()); |
| 3424 this._popBlock(); |
| 3425 if (tmpType.get$isVarOrObject()) { |
| 3426 if (i + 1 < node.catches.length) { |
| 3427 $globals.world.error('Unreachable catch clause', node.catches.$index(i
+ 1).get$span()); |
| 3428 } |
| 3429 if (i > 0) { |
| 3430 this.writer.exitBlock('}'); |
| 3431 } |
| 3432 needsRethrow = false; |
| 3433 break; |
| 3434 } |
| 3435 } |
| 3436 if (needsRethrow) { |
| 3437 this.writer.nextBlock('} else {'); |
| 3438 this.writer.writeln(('throw ' + ex.get$code() + ';')); |
| 3439 this.writer.exitBlock('}'); |
| 3440 } |
| 3441 this._popBlock(); |
| 3442 } |
| 3443 if (node.finallyBlock != null) { |
| 3444 this.writer.nextBlock('} finally {'); |
| 3445 this._pushBlock(false); |
| 3446 this.visitStatementsInBlock(node.finallyBlock); |
| 3447 this._popBlock(); |
| 3448 } |
| 3449 this.writer.exitBlock('}'); |
| 3450 return false; |
| 3451 } |
| 3452 MethodGenerator.prototype.visitSwitchStatement = function(node) { |
| 3453 var test = this.visitValue(node.test); |
| 3454 this.writer.enterBlock(('switch (' + test.get$code() + ') {')); |
| 3455 var $$list = node.cases; |
| 3456 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3457 var case_ = $$list.$index($$i); |
| 3458 if (case_.get$label() != null) { |
| 3459 $globals.world.error('unimplemented: labeled case statement', case_.get$sp
an()); |
| 3460 } |
| 3461 this._pushBlock(false); |
| 3462 for (var i = 0; |
| 3463 i < case_.get$cases().length; i++) { |
| 3464 var expr = case_.get$cases().$index(i); |
| 3465 if (expr == null) { |
| 3466 if (i < case_.get$cases().length - 1) { |
| 3467 $globals.world.error('default clause must be the last case', case_.get
$span()); |
| 3468 } |
| 3469 this.writer.writeln('default:'); |
| 3470 } |
| 3471 else { |
| 3472 var value = this.visitValue(expr); |
| 3473 this.writer.writeln(('case ' + value.get$code() + ':')); |
| 3474 } |
| 3475 } |
| 3476 this.writer.enterBlock(''); |
| 3477 var caseExits = this._visitAllStatements(case_.get$statements(), false); |
| 3478 if ($ne(case_, node.cases.$index(node.cases.length - 1)) && !caseExits) { |
| 3479 var span = case_.get$statements().$index(case_.get$statements().length - 1
).get$span(); |
| 3480 this.writer.writeln('\$throw(new FallThroughError());'); |
| 3481 $globals.world.gen.corejs.useThrow = true; |
| 3482 } |
| 3483 this.writer.exitBlock(''); |
| 3484 this._popBlock(); |
| 3485 } |
| 3486 this.writer.exitBlock('}'); |
| 3487 return false; |
| 3488 } |
| 3489 MethodGenerator.prototype._visitAllStatements = function(statementList, exits) { |
| 3490 for (var i = 0; |
| 3491 i < statementList.length; i++) { |
| 3492 var stmt = statementList.$index(i); |
| 3493 exits = stmt.visit$1(this); |
| 3494 if ($ne(stmt, statementList.$index(statementList.length - 1)) && exits) { |
| 3495 $globals.world.warning('unreachable code', statementList.$index(i + 1).get
$span()); |
| 3496 } |
| 3497 } |
| 3498 return exits; |
| 3499 } |
| 3500 MethodGenerator.prototype.visitBlockStatement = function(node) { |
| 3501 this._pushBlock(false); |
| 3502 this.writer.enterBlock('{'); |
| 3503 var exits = this._visitAllStatements(node.body, false); |
| 3504 this.writer.exitBlock('}'); |
| 3505 this._popBlock(); |
| 3506 return exits; |
| 3507 } |
| 3508 MethodGenerator.prototype.visitLabeledStatement = function(node) { |
| 3509 this.writer.writeln(('' + node.name.name + ':')); |
| 3510 node.body.visit(this); |
| 3511 return false; |
| 3512 } |
| 3513 MethodGenerator.prototype.visitExpressionStatement = function(node) { |
| 3514 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi
on)) { |
| 3515 $globals.world.warning('variable used as statement', node.span); |
| 3516 } |
| 3517 var value = this.visitVoid(node.body); |
| 3518 this.writer.writeln(('' + value.get$code() + ';')); |
| 3519 return false; |
| 3520 } |
| 3521 MethodGenerator.prototype.visitEmptyStatement = function(node) { |
| 3522 this.writer.writeln(';'); |
| 3523 return false; |
| 3524 } |
| 3525 MethodGenerator.prototype._checkNonStatic = function(node) { |
| 3526 if (this.get$isStatic()) { |
| 3527 $globals.world.warning('not allowed in static method', node.span); |
| 3528 } |
| 3529 } |
| 3530 MethodGenerator.prototype._makeSuperValue = function(node) { |
| 3531 var parentType = this.method.declaringType.get$parent(); |
| 3532 this._checkNonStatic(node); |
| 3533 if (parentType == null) { |
| 3534 $globals.world.error('no super class', node.span); |
| 3535 } |
| 3536 var ret = new Value(parentType, 'this', node.span, false); |
| 3537 ret.set$isSuper(true); |
| 3538 return ret; |
| 3539 } |
| 3540 MethodGenerator.prototype._getOutermostMethod = function() { |
| 3541 var result = this; |
| 3542 while (result.get$enclosingMethod() != null) { |
| 3543 result = result.get$enclosingMethod(); |
| 3544 } |
| 3545 return result; |
| 3546 } |
| 3547 MethodGenerator.prototype._makeThisCode = function() { |
| 3548 if (this.enclosingMethod != null) { |
| 3549 this._getOutermostMethod().set$needsThis(true); |
| 3550 return '\$this'; |
| 3551 } |
| 3552 else { |
| 3553 return 'this'; |
| 3554 } |
| 3555 } |
| 3556 MethodGenerator.prototype._makeThisValue = function(node) { |
| 3557 if (this.enclosingMethod != null) { |
| 3558 var outermostMethod = this._getOutermostMethod(); |
| 3559 outermostMethod._checkNonStatic$1(node); |
| 3560 outermostMethod.set$needsThis(true); |
| 3561 return new Value(outermostMethod.method.get$declaringType(), '\$this', node
!= null ? node.span : null, false); |
| 3562 } |
| 3563 else { |
| 3564 this._checkNonStatic(node); |
| 3565 return new Value(this.method.declaringType, 'this', node != null ? node.span
: null, false); |
| 3566 } |
| 3567 } |
| 3568 MethodGenerator.prototype.visitLambdaExpression = function(node) { |
| 3569 var name = (node.func.name != null) ? node.func.name.name : ''; |
| 3570 var meth = this._makeLambdaMethod(name, node.func); |
| 3571 var lambdaGen = new MethodGenerator(meth, this); |
| 3572 if ($ne(name, '')) { |
| 3573 lambdaGen._scope.create(name, meth.get$functionType(), meth.definition.span,
true, false); |
| 3574 lambdaGen._pushBlock(false); |
| 3575 } |
| 3576 lambdaGen.run(); |
| 3577 var w = new CodeWriter(); |
| 3578 meth.generator.writeDefinition(w, node); |
| 3579 return new Value(meth.get$functionType(), w.get$text(), node.span, true); |
| 3580 } |
| 3581 MethodGenerator.prototype.visitCallExpression = function(node) { |
| 3582 var target; |
| 3583 var position = node.target; |
| 3584 var name = ':call'; |
| 3585 if ((node.target instanceof DotExpression)) { |
| 3586 var dot = node.target; |
| 3587 target = dot.self.visit(this); |
| 3588 name = dot.name.name; |
| 3589 position = dot.name; |
| 3590 } |
| 3591 else if ((node.target instanceof VarExpression)) { |
| 3592 var varExpr = node.target; |
| 3593 name = varExpr.name.name; |
| 3594 target = this._scope.lookup(name); |
| 3595 if (target != null) { |
| 3596 return target.invoke$4(this, ':call', node, this._makeArgs(node.arguments)
); |
| 3597 } |
| 3598 target = this._makeThisOrType(varExpr.span); |
| 3599 return target.invoke$4(this, name, node, this._makeArgs(node.arguments)); |
| 3600 } |
| 3601 else { |
| 3602 target = node.target.visit(this); |
| 3603 } |
| 3604 return target.invoke$4(this, name, position, this._makeArgs(node.arguments)); |
| 3605 } |
| 3606 MethodGenerator.prototype.visitIndexExpression = function(node) { |
| 3607 var target = this.visitValue(node.target); |
| 3608 var index = this.visitValue(node.index); |
| 3609 return target.invoke$4(this, ':index', node, new Arguments(null, [index])); |
| 3610 } |
| 3611 MethodGenerator.prototype.visitBinaryExpression = function(node, isVoid) { |
| 3612 var kind = node.op.kind; |
| 3613 if (kind == 35/*TokenKind.AND*/ || kind == 34/*TokenKind.OR*/) { |
| 3614 var x = this.visitTypedValue(node.x, $globals.world.nonNullBool); |
| 3615 var y = this.visitTypedValue(node.y, $globals.world.nonNullBool); |
| 3616 var code = ('' + x.get$code() + ' ' + node.op + ' ' + y.get$code()); |
| 3617 if (x.get$isConst() && y.get$isConst()) { |
| 3618 var value = (kind == 35/*TokenKind.AND*/) ? x.get$actualValue() && y.get$a
ctualValue() : x.get$actualValue() || y.get$actualValue(); |
| 3619 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v
alue, ('' + value), node.span); |
| 3620 } |
| 3621 return new Value($globals.world.nonNullBool, code, node.span, true); |
| 3622 } |
| 3623 else if (kind == 50/*TokenKind.EQ_STRICT*/ || kind == 51/*TokenKind.NE_STRICT*
/) { |
| 3624 var x = this.visitValue(node.x); |
| 3625 var y = this.visitValue(node.y); |
| 3626 if (x.get$isConst() && y.get$isConst()) { |
| 3627 var xVal = x.get$actualValue(); |
| 3628 var yVal = y.get$actualValue(); |
| 3629 if (x.get$type().get$isString() && y.get$type().get$isString() && $ne(xVal
.$index(0), yVal.$index(0))) { |
| 3630 if ($eq(xVal.$index(0), '"')) { |
| 3631 xVal = xVal.substring$2(1, xVal.length - 1); |
| 3632 yVal = toDoubleQuote(yVal.substring$2(1, yVal.length - 1)); |
| 3633 } |
| 3634 else { |
| 3635 xVal = toDoubleQuote(xVal.substring$2(1, xVal.length - 1)); |
| 3636 yVal = yVal.substring$2(1, yVal.length - 1); |
| 3637 } |
| 3638 } |
| 3639 var value = kind == 50/*TokenKind.EQ_STRICT*/ ? $eq(xVal, yVal) : $ne(xVal
, yVal); |
| 3640 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v
alue, ("" + value), node.span); |
| 3641 } |
| 3642 if ($eq(x.get$code(), 'null') || $eq(y.get$code(), 'null')) { |
| 3643 var op = node.op.toString().substring(0, 2); |
| 3644 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + op
+ ' ' + y.get$code()), node.span, true); |
| 3645 } |
| 3646 else { |
| 3647 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + no
de.op + ' ' + y.get$code()), node.span, true); |
| 3648 } |
| 3649 } |
| 3650 var assignKind = TokenKind.kindFromAssign(node.op.kind); |
| 3651 if (assignKind == -1) { |
| 3652 var x = this.visitValue(node.x); |
| 3653 var y = this.visitValue(node.y); |
| 3654 var name = TokenKind.binaryMethodName(node.op.kind); |
| 3655 if (node.op.kind == 49/*TokenKind.NE*/) { |
| 3656 name = ':ne'; |
| 3657 } |
| 3658 if (name == null) { |
| 3659 $globals.world.internalError(('unimplemented binary op ' + node.op), node.
span); |
| 3660 return; |
| 3661 } |
| 3662 return x.invoke$4(this, name, node, new Arguments(null, [y])); |
| 3663 } |
| 3664 else { |
| 3665 return this._visitAssign(assignKind, node.x, node.y, node, to$call$1(null),
isVoid); |
| 3666 } |
| 3667 } |
| 3668 MethodGenerator.prototype._visitAssign = function(kind, xn, yn, position, captur
eOriginal, isVoid) { |
| 3669 if (captureOriginal == null) { |
| 3670 captureOriginal = (function (x) { |
| 3671 return x; |
| 3672 }) |
| 3673 ; |
| 3674 } |
| 3675 if ((xn instanceof VarExpression)) { |
| 3676 return this._visitVarAssign(kind, xn, yn, position, captureOriginal); |
| 3677 } |
| 3678 else if ((xn instanceof IndexExpression)) { |
| 3679 return this._visitIndexAssign(kind, xn, yn, position, captureOriginal, isVoi
d); |
| 3680 } |
| 3681 else if ((xn instanceof DotExpression)) { |
| 3682 return this._visitDotAssign(kind, xn, yn, position, captureOriginal); |
| 3683 } |
| 3684 else { |
| 3685 $globals.world.error('illegal lhs', xn.span); |
| 3686 } |
| 3687 } |
| 3688 MethodGenerator.prototype._visitVarAssign = function(kind, xn, yn, position, cap
tureOriginal) { |
| 3689 var name = xn.name.name; |
| 3690 var x = this._scope.lookup(name); |
| 3691 var y = this.visitValue(yn); |
| 3692 if (x == null) { |
| 3693 var members = this.method.declaringType.resolveMember(name); |
| 3694 x = this._makeThisOrType(position.span); |
| 3695 if (members != null) { |
| 3696 if ($globals.options.forceDynamic && !members.get$isStatic()) { |
| 3697 members = this.findMembers(xn.name.name); |
| 3698 } |
| 3699 if (kind == 0) { |
| 3700 return x.set_$4(this, name, position, y); |
| 3701 } |
| 3702 else if (!members.get$treatAsField() || members.get$containsMethods()) { |
| 3703 var right = x.get_$3(this, name, position); |
| 3704 right = captureOriginal(right); |
| 3705 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new
Arguments(null, [y])); |
| 3706 return x.set_$4(this, name, position, y); |
| 3707 } |
| 3708 else { |
| 3709 x = x.get_$3(this, name, position); |
| 3710 } |
| 3711 } |
| 3712 else { |
| 3713 var member = this.get$library().lookup(name, xn.name.span); |
| 3714 if (member == null) { |
| 3715 $globals.world.warning(('can not resolve ' + name), xn.span); |
| 3716 return this._makeMissingValue(name); |
| 3717 } |
| 3718 members = new MemberSet(member, false); |
| 3719 if (!members.get$treatAsField() || members.get$containsMethods()) { |
| 3720 if (kind != 0) { |
| 3721 var right = members._get$3(this, position, x); |
| 3722 right = captureOriginal(right); |
| 3723 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, n
ew Arguments(null, [y])); |
| 3724 } |
| 3725 return members._set$4(this, position, x, y); |
| 3726 } |
| 3727 else { |
| 3728 x = members._get$3(this, position, x); |
| 3729 } |
| 3730 } |
| 3731 } |
| 3732 if (x.get$isFinal()) { |
| 3733 $globals.world.error(('final variable "' + x.get$code() + '" is not assignab
le'), position.span); |
| 3734 } |
| 3735 y = y.convertTo$3(this, x.get$type(), yn); |
| 3736 if (kind == 0) { |
| 3737 x = captureOriginal(x); |
| 3738 return new Value(y.get$type(), ('' + x.get$code() + ' = ' + y.get$code()), p
osition.span, true); |
| 3739 } |
| 3740 else if (x.get$type().get$isNum() && y.get$type().get$isNum() && (kind != 46/*
TokenKind.TRUNCDIV*/)) { |
| 3741 x = captureOriginal(x); |
| 3742 var op = TokenKind.kindToString(kind); |
| 3743 return new Value(y.get$type(), ('' + x.get$code() + ' ' + op + '= ' + y.get$
code()), position.span, true); |
| 3744 } |
| 3745 else { |
| 3746 var right = x; |
| 3747 right = captureOriginal(right); |
| 3748 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 3749 return new Value(y.get$type(), ('' + x.get$code() + ' = ' + y.get$code()), p
osition.span, true); |
| 3750 } |
| 3751 } |
| 3752 MethodGenerator.prototype._visitIndexAssign = function(kind, xn, yn, position, c
aptureOriginal, isVoid) { |
| 3753 var target = this.visitValue(xn.target); |
| 3754 var index = this.visitValue(xn.index); |
| 3755 var y = this.visitValue(yn); |
| 3756 var tmptarget = target; |
| 3757 var tmpindex = index; |
| 3758 if (kind != 0) { |
| 3759 tmptarget = this.getTemp(target); |
| 3760 tmpindex = this.getTemp(index); |
| 3761 index = this.assignTemp(tmpindex, index); |
| 3762 var right = tmptarget.invoke$4(this, ':index', position, new Arguments(null,
[tmpindex])); |
| 3763 right = captureOriginal(right); |
| 3764 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 3765 } |
| 3766 var tmpy = null; |
| 3767 if (!isVoid) { |
| 3768 tmpy = this.getTemp(y); |
| 3769 y = this.assignTemp(tmpy, y); |
| 3770 } |
| 3771 var ret = this.assignTemp(tmptarget, target).invoke(this, ':setindex', positio
n, new Arguments(null, [index, y]), false); |
| 3772 if (tmpy != null) { |
| 3773 ret = new Value(ret.get$type(), ('(' + ret.get$code() + ', ' + tmpy.get$code
() + ')'), ret.get$span(), true); |
| 3774 if ($ne(tmpy, y)) this.freeTemp(tmpy); |
| 3775 } |
| 3776 if ($ne(tmptarget, target)) this.freeTemp(tmptarget); |
| 3777 if ($ne(tmpindex, index)) this.freeTemp(tmpindex); |
| 3778 return ret; |
| 3779 } |
| 3780 MethodGenerator.prototype._visitDotAssign = function(kind, xn, yn, position, cap
tureOriginal) { |
| 3781 var target = xn.self.visit(this); |
| 3782 var y = this.visitValue(yn); |
| 3783 var tmptarget = target; |
| 3784 if (kind != 0) { |
| 3785 tmptarget = this.getTemp(target); |
| 3786 var right = tmptarget.get_$3(this, xn.name.name, xn.name); |
| 3787 right = captureOriginal(right); |
| 3788 y = right.invoke$4(this, TokenKind.binaryMethodName(kind), position, new Arg
uments(null, [y])); |
| 3789 } |
| 3790 var ret = this.assignTemp(tmptarget, target).set_(this, xn.name.name, xn.name,
y, false); |
| 3791 if ($ne(tmptarget, target)) this.freeTemp(tmptarget); |
| 3792 return ret; |
| 3793 } |
| 3794 MethodGenerator.prototype.visitUnaryExpression = function(node) { |
| 3795 var value = this.visitValue(node.self); |
| 3796 switch (node.op.kind) { |
| 3797 case 16/*TokenKind.INCR*/: |
| 3798 case 17/*TokenKind.DECR*/: |
| 3799 |
| 3800 if (value.get$type().get$isNum()) { |
| 3801 return new Value(value.get$type(), ('' + node.op + value.get$code()), no
de.span, true); |
| 3802 } |
| 3803 else { |
| 3804 var kind = (16/*TokenKind.INCR*/ == node.op.kind ? 42/*TokenKind.ADD*/ :
43/*TokenKind.SUB*/); |
| 3805 var operand = new LiteralExpression(1, new TypeReference(node.span, $glo
bals.world.numType), '1', node.span); |
| 3806 var assignValue = this._visitAssign(kind, node.self, operand, node, to$c
all$1(null), false); |
| 3807 return new Value(assignValue.get$type(), ('(' + assignValue.get$code() +
')'), node.span, true); |
| 3808 } |
| 3809 |
| 3810 case 19/*TokenKind.NOT*/: |
| 3811 |
| 3812 if (value.get$type().get$isBool() && value.get$isConst()) { |
| 3813 var newVal = !value.get$actualValue(); |
| 3814 return EvaluatedValue.EvaluatedValue$factory(value.get$type(), newVal, (
'' + newVal), node.span); |
| 3815 } |
| 3816 else { |
| 3817 var newVal = value.convertTo$3(this, $globals.world.nonNullBool, node); |
| 3818 return new Value(newVal.get$type(), ('!' + newVal.get$code()), node.span
, true); |
| 3819 } |
| 3820 |
| 3821 case 42/*TokenKind.ADD*/: |
| 3822 |
| 3823 return value.convertTo$3(this, $globals.world.numType, node); |
| 3824 |
| 3825 case 43/*TokenKind.SUB*/: |
| 3826 case 18/*TokenKind.BIT_NOT*/: |
| 3827 |
| 3828 if (node.op.kind == 18/*TokenKind.BIT_NOT*/) { |
| 3829 return value.invoke$4(this, ':bit_not', node, Arguments.get$EMPTY()); |
| 3830 } |
| 3831 else if (node.op.kind == 43/*TokenKind.SUB*/) { |
| 3832 return value.invoke$4(this, ':negate', node, Arguments.get$EMPTY()); |
| 3833 } |
| 3834 else { |
| 3835 $globals.world.internalError(('unimplemented: unary ' + node.op), node.s
pan); |
| 3836 } |
| 3837 $throw(new FallThroughError()); |
| 3838 |
| 3839 default: |
| 3840 |
| 3841 $globals.world.internalError(('unimplemented: ' + node.op), node.span); |
| 3842 |
| 3843 } |
| 3844 } |
| 3845 MethodGenerator.prototype.visitAwaitExpression = function(node) { |
| 3846 $globals.world.internalError('Await expressions should have been eliminated be
fore code generation', node.span); |
| 3847 } |
| 3848 MethodGenerator.prototype.visitPostfixExpression = function(node, isVoid) { |
| 3849 var $this = this; // closure support |
| 3850 var value = this.visitValue(node.body); |
| 3851 if (value.get$type().get$isNum() && !value.get$isFinal()) { |
| 3852 return new Value(value.get$type(), ('' + value.get$code() + node.op), node.s
pan, true); |
| 3853 } |
| 3854 var kind = (16/*TokenKind.INCR*/ == node.op.kind) ? 42/*TokenKind.ADD*/ : 43/*
TokenKind.SUB*/; |
| 3855 var operand = new LiteralExpression(1, new TypeReference(node.span, $globals.w
orld.numType), '1', node.span); |
| 3856 var tmpleft = null, left = null; |
| 3857 var ret = this._visitAssign(kind, node.body, operand, node, (function (l) { |
| 3858 if (isVoid) { |
| 3859 return l; |
| 3860 } |
| 3861 else { |
| 3862 left = l; |
| 3863 tmpleft = $this.forceTemp(l); |
| 3864 return $this.assignTemp(tmpleft, left); |
| 3865 } |
| 3866 }) |
| 3867 , false); |
| 3868 if (tmpleft != null) { |
| 3869 ret = new Value(ret.get$type(), ("(" + ret.get$code() + ", " + tmpleft.get$c
ode() + ")"), node.span, true); |
| 3870 } |
| 3871 if ($ne(tmpleft, left)) { |
| 3872 this.freeTemp(tmpleft); |
| 3873 } |
| 3874 return ret; |
| 3875 } |
| 3876 MethodGenerator.prototype.visitNewExpression = function(node) { |
| 3877 var typeRef = node.type; |
| 3878 var constructorName = ''; |
| 3879 if (node.name != null) { |
| 3880 constructorName = node.name.name; |
| 3881 } |
| 3882 if ($eq(constructorName, '') && !(typeRef instanceof GenericTypeReference) &&
typeRef.get$names() != null) { |
| 3883 var names = ListFactory.ListFactory$from$factory(typeRef.get$names()); |
| 3884 constructorName = names.removeLast$0().get$name(); |
| 3885 if ($eq(names.length, 0)) names = null; |
| 3886 typeRef = new NameTypeReference(typeRef.get$isFinal(), typeRef.get$name(), n
ames, typeRef.get$span()); |
| 3887 } |
| 3888 var type = this.method.resolveType(typeRef, true); |
| 3889 if (type.get$isTop()) { |
| 3890 type = type.get$library().findTypeByName$1(constructorName); |
| 3891 constructorName = ''; |
| 3892 } |
| 3893 if ((type instanceof ParameterType)) { |
| 3894 $globals.world.error('cannot instantiate a type parameter', node.span); |
| 3895 return this._makeMissingValue(constructorName); |
| 3896 } |
| 3897 var m = type.getConstructor$1(constructorName); |
| 3898 if (m == null) { |
| 3899 var name = type.get$jsname(); |
| 3900 if (type.get$isVar()) { |
| 3901 name = typeRef.get$name().get$name(); |
| 3902 } |
| 3903 $globals.world.error(('no matching constructor for ' + name), node.span); |
| 3904 return this._makeMissingValue(name); |
| 3905 } |
| 3906 if (node.isConst) { |
| 3907 if (!m.get$isConst()) { |
| 3908 $globals.world.error('can\'t use const on a non-const constructor', node.s
pan); |
| 3909 } |
| 3910 var $$list = node.arguments; |
| 3911 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3912 var arg = $$list.$index($$i); |
| 3913 if (!this.visitValue(arg.get$value()).get$isConst()) { |
| 3914 $globals.world.error('const constructor expects const arguments', arg.ge
t$span()); |
| 3915 } |
| 3916 } |
| 3917 } |
| 3918 var target = new Value.type$ctor(type, typeRef.get$span()); |
| 3919 return m.invoke$4(this, node, target, this._makeArgs(node.arguments)); |
| 3920 } |
| 3921 MethodGenerator.prototype.visitListExpression = function(node) { |
| 3922 var argsCode = []; |
| 3923 var argValues = []; |
| 3924 var type = null; |
| 3925 if (node.type != null) { |
| 3926 type = this.method.resolveType(node.type, true).get$typeArgsInOrder().$index
(0); |
| 3927 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara
ms())) { |
| 3928 $globals.world.error('type parameter cannot be used in const list literals
'); |
| 3929 } |
| 3930 } |
| 3931 var $$list = node.values; |
| 3932 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 3933 var item = $$list.$index($$i); |
| 3934 var arg = this.visitTypedValue(item, type); |
| 3935 argValues.add$1(arg); |
| 3936 if (node.isConst) { |
| 3937 if (!arg.get$isConst()) { |
| 3938 $globals.world.error('const list can only contain const values', item.ge
t$span()); |
| 3939 argsCode.add$1(arg.get$code()); |
| 3940 } |
| 3941 else { |
| 3942 argsCode.add$1(arg.get$canonicalCode()); |
| 3943 } |
| 3944 } |
| 3945 else { |
| 3946 argsCode.add$1(arg.get$code()); |
| 3947 } |
| 3948 } |
| 3949 $globals.world.get$coreimpl().types.$index('ListFactory').markUsed$0(); |
| 3950 var code = ('[' + Strings.join(argsCode, ", ") + ']'); |
| 3951 var value = new Value($globals.world.listType, code, node.span, true); |
| 3952 if (node.isConst) { |
| 3953 var immutableList = $globals.world.get$coreimpl().types.$index('ImmutableLis
t'); |
| 3954 var immutableListCtor = immutableList.getConstructor$1('from'); |
| 3955 var result = immutableListCtor.invoke$4(this, node, new Value.type$ctor(valu
e.get$type(), node.span), new Arguments(null, [value])); |
| 3956 value = $globals.world.gen.globalForConst(ConstListValue.ConstListValue$fact
ory(immutableList, argValues, ('const ' + code), result.get$code(), node.span),
argValues); |
| 3957 } |
| 3958 return value; |
| 3959 } |
| 3960 MethodGenerator.prototype.visitMapExpression = function(node) { |
| 3961 if (node.items.length == 0 && !node.isConst) { |
| 3962 return $globals.world.mapType.getConstructor('').invoke$4(this, node, new Va
lue.type$ctor($globals.world.mapType, node.span), Arguments.get$EMPTY()); |
| 3963 } |
| 3964 var argValues = []; |
| 3965 var argsCode = []; |
| 3966 var type = null; |
| 3967 if (node.type != null) { |
| 3968 type = this.method.resolveType(node.type, true).get$typeArgsInOrder().$index
(1); |
| 3969 if (node.isConst && ((type instanceof ParameterType) || type.get$hasTypePara
ms())) { |
| 3970 $globals.world.error('type parameter cannot be used in const map literals'
); |
| 3971 } |
| 3972 } |
| 3973 for (var i = 0; |
| 3974 i < node.items.length; i += 2) { |
| 3975 var key = this.visitTypedValue(node.items.$index(i), $globals.world.stringTy
pe); |
| 3976 var valueItem = node.items.$index(i + 1); |
| 3977 var value = this.visitTypedValue(valueItem, type); |
| 3978 argValues.add$1(key); |
| 3979 argValues.add$1(value); |
| 3980 if (node.isConst) { |
| 3981 if (!key.get$isConst() || !value.get$isConst()) { |
| 3982 $globals.world.error('const map can only contain const values', valueIte
m.get$span()); |
| 3983 argsCode.add$1(key.get$code()); |
| 3984 argsCode.add$1(value.get$code()); |
| 3985 } |
| 3986 else { |
| 3987 argsCode.add$1(key.get$canonicalCode()); |
| 3988 argsCode.add$1(value.get$canonicalCode()); |
| 3989 } |
| 3990 } |
| 3991 else { |
| 3992 argsCode.add$1(key.get$code()); |
| 3993 argsCode.add$1(value.get$code()); |
| 3994 } |
| 3995 } |
| 3996 var argList = ('[' + Strings.join(argsCode, ", ") + ']'); |
| 3997 var items = new Value($globals.world.listType, argList, node.span, true); |
| 3998 var tp = $globals.world.corelib.topType; |
| 3999 var f = node.isConst ? tp.getMember$1('_constMap') : tp.getMember$1('_map'); |
| 4000 var value = f.invoke(this, node, new Value.type$ctor(tp, null), new Arguments(
null, [items]), false); |
| 4001 if (node.isConst) { |
| 4002 value = ConstMapValue.ConstMapValue$factory(value.get$type(), argValues, val
ue.get$code(), value.get$code(), value.get$span()); |
| 4003 return $globals.world.gen.globalForConst(value, argValues); |
| 4004 } |
| 4005 else { |
| 4006 return value; |
| 4007 } |
| 4008 } |
| 4009 MethodGenerator.prototype.visitConditionalExpression = function(node) { |
| 4010 var test = this.visitBool(node.test); |
| 4011 var trueBranch = this.visitValue(node.trueBranch); |
| 4012 var falseBranch = this.visitValue(node.falseBranch); |
| 4013 var code = ('' + test.get$code() + ' ? ' + trueBranch.get$code() + ' : ' + fal
seBranch.get$code()); |
| 4014 return new Value(Type.union(trueBranch.get$type(), falseBranch.get$type()), co
de, node.span, true); |
| 4015 } |
| 4016 MethodGenerator.prototype.visitIsExpression = function(node) { |
| 4017 var value = this.visitValue(node.x); |
| 4018 var type = this.method.resolveType(node.type, false); |
| 4019 return value.instanceOf$4(this, type, node.span, node.isTrue); |
| 4020 } |
| 4021 MethodGenerator.prototype.visitParenExpression = function(node) { |
| 4022 var body = this.visitValue(node.body); |
| 4023 if (body.get$isConst()) { |
| 4024 return EvaluatedValue.EvaluatedValue$factory(body.get$type(), body.get$actua
lValue(), ('(' + body.get$canonicalCode() + ')'), node.span); |
| 4025 } |
| 4026 return new Value(body.get$type(), ('(' + body.get$code() + ')'), node.span, tr
ue); |
| 4027 } |
| 4028 MethodGenerator.prototype.visitDotExpression = function(node) { |
| 4029 var target = node.self.visit(this); |
| 4030 return target.get_$3(this, node.name.name, node.name); |
| 4031 } |
| 4032 MethodGenerator.prototype.visitVarExpression = function(node) { |
| 4033 var name = node.name.name; |
| 4034 var ret = this._scope.lookup(name); |
| 4035 if (ret != null) return ret; |
| 4036 return this._makeThisOrType(node.span).get_$3(this, name, node); |
| 4037 } |
| 4038 MethodGenerator.prototype._makeMissingValue = function(name) { |
| 4039 return new Value($globals.world.varType, ('' + name + '()/*NotFound*/'), null,
true); |
| 4040 } |
| 4041 MethodGenerator.prototype._makeThisOrType = function(span) { |
| 4042 return new BareValue(this, this._getOutermostMethod(), span); |
| 4043 } |
| 4044 MethodGenerator.prototype.visitThisExpression = function(node) { |
| 4045 return this._makeThisValue(node); |
| 4046 } |
| 4047 MethodGenerator.prototype.visitSuperExpression = function(node) { |
| 4048 return this._makeSuperValue(node); |
| 4049 } |
| 4050 MethodGenerator.prototype.visitNullExpression = function(node) { |
| 4051 return EvaluatedValue.EvaluatedValue$factory($globals.world.varType, null, 'nu
ll', null); |
| 4052 } |
| 4053 MethodGenerator.prototype._isUnaryIncrement = function(item) { |
| 4054 if ((item instanceof UnaryExpression)) { |
| 4055 var u = item; |
| 4056 return u.op.kind == 16/*TokenKind.INCR*/ || u.op.kind == 17/*TokenKind.DECR*
/; |
| 4057 } |
| 4058 else { |
| 4059 return false; |
| 4060 } |
| 4061 } |
| 4062 MethodGenerator.prototype.visitLiteralExpression = function(node) { |
| 4063 var $0; |
| 4064 var type = node.type.type; |
| 4065 if (!!(($0 = node.value) && $0.is$List())) { |
| 4066 var items = []; |
| 4067 var $$list = node.value; |
| 4068 for (var $$i = node.value.iterator$0(); $$i.hasNext$0(); ) { |
| 4069 var item = $$i.next$0(); |
| 4070 var val = this.visitValue(item); |
| 4071 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY()); |
| 4072 var code = val.get$code(); |
| 4073 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr
ession) || (item instanceof PostfixExpression) || this._isUnaryIncrement(item))
{ |
| 4074 code = ('(' + code + ')'); |
| 4075 } |
| 4076 if ($eq(items.length, 0) || ($ne(code, "''") && $ne(code, '""'))) { |
| 4077 items.add$1(code); |
| 4078 } |
| 4079 } |
| 4080 return new Value(type, ('(' + Strings.join(items, " + ") + ')'), node.span,
true); |
| 4081 } |
| 4082 var text = node.text; |
| 4083 if (type.get$isString()) { |
| 4084 if (text.startsWith$1('@')) { |
| 4085 text = MethodGenerator._escapeString(parseStringLiteral(text)); |
| 4086 text = ('"' + text + '"'); |
| 4087 } |
| 4088 else if (isMultilineString(text)) { |
| 4089 text = parseStringLiteral(text); |
| 4090 text = text.replaceAll$2('\n', '\\n'); |
| 4091 text = toDoubleQuote(text); |
| 4092 text = ('"' + text + '"'); |
| 4093 } |
| 4094 if (text !== node.text) { |
| 4095 node.value = text; |
| 4096 node.text = text; |
| 4097 } |
| 4098 } |
| 4099 return EvaluatedValue.EvaluatedValue$factory(type, node.value, node.text, null
); |
| 4100 } |
| 4101 MethodGenerator.prototype._checkNonStatic$1 = MethodGenerator.prototype._checkNo
nStatic; |
| 4102 MethodGenerator.prototype.visitBinaryExpression$1 = function($0) { |
| 4103 return this.visitBinaryExpression($0, false); |
| 4104 }; |
| 4105 MethodGenerator.prototype.visitPostfixExpression$1 = function($0) { |
| 4106 return this.visitPostfixExpression($0, false); |
| 4107 }; |
| 4108 MethodGenerator.prototype.writeDefinition$2 = MethodGenerator.prototype.writeDef
inition; |
| 4109 // ********** Code for Arguments ************** |
| 4110 function Arguments(nodes, values) { |
| 4111 this.nodes = nodes; |
| 4112 this.values = values; |
| 4113 // Initializers done |
| 4114 } |
| 4115 Arguments.Arguments$bare$factory = function(arity) { |
| 4116 var values = []; |
| 4117 for (var i = 0; |
| 4118 i < arity; i++) { |
| 4119 values.add$1(new Value($globals.world.varType, ('\$' + i), null, false)); |
| 4120 } |
| 4121 return new Arguments(null, values); |
| 4122 } |
| 4123 Arguments.get$EMPTY = function() { |
| 4124 if ($globals.Arguments__empty == null) { |
| 4125 $globals.Arguments__empty = new Arguments(null, []); |
| 4126 } |
| 4127 return $globals.Arguments__empty; |
| 4128 } |
| 4129 Arguments.prototype.get$values = function() { return this.values; }; |
| 4130 Arguments.prototype.set$values = function(value) { return this.values = value; }
; |
| 4131 Arguments.prototype.get$nameCount = function() { |
| 4132 return this.get$length() - this.get$bareCount(); |
| 4133 } |
| 4134 Arguments.prototype.get$hasNames = function() { |
| 4135 return this.get$bareCount() < this.get$length(); |
| 4136 } |
| 4137 Arguments.prototype.get$length = function() { |
| 4138 return this.values.length; |
| 4139 } |
| 4140 Object.defineProperty(Arguments.prototype, "length", { |
| 4141 get: Arguments.prototype.get$length |
| 4142 }); |
| 4143 Arguments.prototype.getName = function(i) { |
| 4144 return this.nodes.$index(i).get$label().get$name(); |
| 4145 } |
| 4146 Arguments.prototype.getIndexOfName = function(name) { |
| 4147 for (var i = this.get$bareCount(); |
| 4148 i < this.get$length(); i++) { |
| 4149 if (this.getName(i) == name) { |
| 4150 return i; |
| 4151 } |
| 4152 } |
| 4153 return -1; |
| 4154 } |
| 4155 Arguments.prototype.getValue = function(name) { |
| 4156 var i = this.getIndexOfName(name); |
| 4157 return i >= 0 ? this.values.$index(i) : null; |
| 4158 } |
| 4159 Arguments.prototype.get$bareCount = function() { |
| 4160 if (this._bareCount == null) { |
| 4161 this._bareCount = this.get$length(); |
| 4162 if (this.nodes != null) { |
| 4163 for (var i = 0; |
| 4164 i < this.nodes.length; i++) { |
| 4165 if (this.nodes.$index(i).get$label() != null) { |
| 4166 this._bareCount = i; |
| 4167 break; |
| 4168 } |
| 4169 } |
| 4170 } |
| 4171 } |
| 4172 return this._bareCount; |
| 4173 } |
| 4174 Arguments.prototype.getCode = function() { |
| 4175 var argsCode = []; |
| 4176 for (var i = 0; |
| 4177 i < this.get$length(); i++) { |
| 4178 argsCode.add$1(this.values.$index(i).get$code()); |
| 4179 } |
| 4180 Arguments.removeTrailingNulls(argsCode); |
| 4181 return Strings.join(argsCode, ", "); |
| 4182 } |
| 4183 Arguments.removeTrailingNulls = function(argsCode) { |
| 4184 while (argsCode.length > 0 && $eq(argsCode.last(), 'null')) { |
| 4185 argsCode.removeLast(); |
| 4186 } |
| 4187 } |
| 4188 Arguments.prototype.getNames = function() { |
| 4189 var names = []; |
| 4190 for (var i = this.get$bareCount(); |
| 4191 i < this.get$length(); i++) { |
| 4192 names.add$1(this.getName(i)); |
| 4193 } |
| 4194 return names; |
| 4195 } |
| 4196 Arguments.prototype.toCallStubArgs = function() { |
| 4197 var result = []; |
| 4198 for (var i = 0; |
| 4199 i < this.get$bareCount(); i++) { |
| 4200 result.add$1(new Value($globals.world.varType, ('\$' + i), null, false)); |
| 4201 } |
| 4202 for (var i = this.get$bareCount(); |
| 4203 i < this.get$length(); i++) { |
| 4204 var name = this.getName(i); |
| 4205 if (name == null) name = ('\$' + i); |
| 4206 result.add$1(new Value($globals.world.varType, name, null, false)); |
| 4207 } |
| 4208 return new Arguments(this.nodes, result); |
| 4209 } |
| 4210 // ********** Code for LibraryImport ************** |
| 4211 function LibraryImport(library, prefix) { |
| 4212 this.library = library; |
| 4213 this.prefix = prefix; |
| 4214 // Initializers done |
| 4215 } |
| 4216 LibraryImport.prototype.get$prefix = function() { return this.prefix; }; |
| 4217 LibraryImport.prototype.set$prefix = function(value) { return this.prefix = valu
e; }; |
| 4218 LibraryImport.prototype.get$library = function() { return this.library; }; |
| 4219 LibraryImport.prototype.set$library = function(value) { return this.library = va
lue; }; |
| 4220 // ********** Code for Library ************** |
| 4221 $inherits(Library, Element); |
| 4222 function Library(baseSource) { |
| 4223 this.isWritten = false |
| 4224 this.baseSource = baseSource; |
| 4225 // Initializers done |
| 4226 Element.call(this, null, null); |
| 4227 this.sourceDir = dirname(this.baseSource.filename); |
| 4228 this.topType = new DefinedType(null, this, null, true); |
| 4229 this.types = _map(['', this.topType]); |
| 4230 this.imports = []; |
| 4231 this.natives = []; |
| 4232 this.sources = []; |
| 4233 this._privateMembers = new HashMapImplementation(); |
| 4234 } |
| 4235 Library.prototype.get$baseSource = function() { return this.baseSource; }; |
| 4236 Library.prototype.get$types = function() { return this.types; }; |
| 4237 Library.prototype.set$types = function(value) { return this.types = value; }; |
| 4238 Library.prototype.get$imports = function() { return this.imports; }; |
| 4239 Library.prototype.set$imports = function(value) { return this.imports = value; }
; |
| 4240 Library.prototype.get$_privateMembers = function() { return this._privateMembers
; }; |
| 4241 Library.prototype.set$_privateMembers = function(value) { return this._privateMe
mbers = value; }; |
| 4242 Library.prototype.get$topType = function() { return this.topType; }; |
| 4243 Library.prototype.set$topType = function(value) { return this.topType = value; }
; |
| 4244 Library.prototype.get$enclosingElement = function() { |
| 4245 return null; |
| 4246 } |
| 4247 Library.prototype.get$library = function() { |
| 4248 return this; |
| 4249 } |
| 4250 Library.prototype.get$isNative = function() { |
| 4251 return this.topType.isNative; |
| 4252 } |
| 4253 Library.prototype.get$isCore = function() { |
| 4254 return $eq(this, $globals.world.corelib); |
| 4255 } |
| 4256 Library.prototype.get$isCoreImpl = function() { |
| 4257 return $eq(this, $globals.world.get$coreimpl()); |
| 4258 } |
| 4259 Library.prototype.get$span = function() { |
| 4260 return new SourceSpan(this.baseSource, 0, 0); |
| 4261 } |
| 4262 Library.prototype.makeFullPath = function(filename) { |
| 4263 if (filename.startsWith('dart:')) return filename; |
| 4264 if (filename.startsWith('/')) return filename; |
| 4265 if (filename.startsWith('file:///')) return filename; |
| 4266 if (filename.startsWith('http://')) return filename; |
| 4267 return joinPaths(this.sourceDir, filename); |
| 4268 } |
| 4269 Library.prototype.addImport = function(fullname, prefix) { |
| 4270 var newLib = $globals.world.getOrAddLibrary(fullname); |
| 4271 this.imports.add(new LibraryImport(newLib, prefix)); |
| 4272 return newLib; |
| 4273 } |
| 4274 Library.prototype.addNative = function(fullname) { |
| 4275 this.natives.add($globals.world.reader.readFile(fullname)); |
| 4276 } |
| 4277 Library.prototype._findMembers = function(name) { |
| 4278 if (name.startsWith('_')) { |
| 4279 return this._privateMembers.$index(name); |
| 4280 } |
| 4281 else { |
| 4282 return $globals.world._members.$index(name); |
| 4283 } |
| 4284 } |
| 4285 Library.prototype._addMember = function(member) { |
| 4286 if (member.get$isPrivate()) { |
| 4287 if (member.get$isStatic()) { |
| 4288 if (member.declaringType.get$isTop()) { |
| 4289 $globals.world._addTopName(member); |
| 4290 } |
| 4291 return; |
| 4292 } |
| 4293 var mset = this._privateMembers.$index(member.name); |
| 4294 if (mset == null) { |
| 4295 var $$list = $globals.world.libraries.getValues(); |
| 4296 for (var $$i = $globals.world.libraries.getValues().iterator$0(); $$i.hasN
ext$0(); ) { |
| 4297 var lib = $$i.next$0(); |
| 4298 if (lib.get$_privateMembers().containsKey$1(member.get$jsname())) { |
| 4299 member._jsname = ('_' + this.get$jsname() + member.get$jsname()); |
| 4300 break; |
| 4301 } |
| 4302 } |
| 4303 mset = new MemberSet(member, true); |
| 4304 this._privateMembers.$setindex(member.name, mset); |
| 4305 } |
| 4306 else { |
| 4307 mset.get$members().add$1(member); |
| 4308 } |
| 4309 } |
| 4310 else { |
| 4311 $globals.world._addMember(member); |
| 4312 } |
| 4313 } |
| 4314 Library.prototype.getOrAddFunctionType = function(enclosingElement, name, func)
{ |
| 4315 var def = new FunctionTypeDefinition(func, null, func.span); |
| 4316 var type = new DefinedType(name, this, def, false); |
| 4317 type.addMethod(':call', func); |
| 4318 var m = type.members.$index(':call'); |
| 4319 m.set$enclosingElement(enclosingElement); |
| 4320 m.resolve$0(); |
| 4321 type.interfaces = [$globals.world.functionType]; |
| 4322 return type; |
| 4323 } |
| 4324 Library.prototype.addType = function(name, definition, isClass) { |
| 4325 if (this.types.containsKey(name)) { |
| 4326 var existingType = this.types.$index(name); |
| 4327 if (this.get$isCore() && existingType.get$definition() == null) { |
| 4328 existingType.setDefinition$1(definition); |
| 4329 } |
| 4330 else { |
| 4331 $globals.world.warning(('duplicate definition of ' + name), definition.spa
n, existingType.get$span()); |
| 4332 } |
| 4333 } |
| 4334 else { |
| 4335 this.types.$setindex(name, new DefinedType(name, this, definition, isClass))
; |
| 4336 } |
| 4337 return this.types.$index(name); |
| 4338 } |
| 4339 Library.prototype.findType = function(type) { |
| 4340 var result = this.findTypeByName(type.name.name); |
| 4341 if (result == null) return null; |
| 4342 if (type.names != null) { |
| 4343 if (type.names.length > 1) { |
| 4344 return null; |
| 4345 } |
| 4346 if (!result.get$isTop()) { |
| 4347 return null; |
| 4348 } |
| 4349 return result.get$library().findTypeByName(type.names.$index(0).get$name()); |
| 4350 } |
| 4351 return result; |
| 4352 } |
| 4353 Library.prototype.findTypeByName = function(name) { |
| 4354 var ret = this.types.$index(name); |
| 4355 var $$list = this.imports; |
| 4356 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4357 var imported = $$list.$index($$i); |
| 4358 var newRet = null; |
| 4359 if (imported.get$prefix() == null) { |
| 4360 newRet = imported.get$library().get$types().$index(name); |
| 4361 } |
| 4362 else if ($eq(imported.get$prefix(), name)) { |
| 4363 newRet = imported.get$library().get$topType(); |
| 4364 } |
| 4365 if (newRet != null) { |
| 4366 if (ret != null && $ne(ret, newRet)) { |
| 4367 $globals.world.error(('conflicting types for "' + name + '"'), ret.get$s
pan(), newRet.get$span()); |
| 4368 } |
| 4369 else { |
| 4370 ret = newRet; |
| 4371 } |
| 4372 } |
| 4373 } |
| 4374 return ret; |
| 4375 } |
| 4376 Library.prototype.resolveType = function(node, typeErrors) { |
| 4377 if (node == null) return $globals.world.varType; |
| 4378 if (node.type != null) return node.type; |
| 4379 node.type = this.findType(node); |
| 4380 if (node.type == null) { |
| 4381 var message = ('cannot find type ' + Library._getDottedName(node)); |
| 4382 if (typeErrors) { |
| 4383 $globals.world.error(message, node.span); |
| 4384 node.type = $globals.world.objectType; |
| 4385 } |
| 4386 else { |
| 4387 $globals.world.warning(message, node.span); |
| 4388 node.type = $globals.world.varType; |
| 4389 } |
| 4390 } |
| 4391 return node.type; |
| 4392 } |
| 4393 Library._getDottedName = function(type) { |
| 4394 if (type.names != null) { |
| 4395 var names = map(type.names, (function (n) { |
| 4396 return n.get$name(); |
| 4397 }) |
| 4398 ); |
| 4399 return type.name.name + '.' + Strings.join(names, '.'); |
| 4400 } |
| 4401 else { |
| 4402 return type.name.name; |
| 4403 } |
| 4404 } |
| 4405 Library.prototype.lookup = function(name, span) { |
| 4406 var retType = this.findTypeByName(name); |
| 4407 var ret = null; |
| 4408 if (retType != null) { |
| 4409 ret = retType.get$typeMember(); |
| 4410 } |
| 4411 var newRet = this.topType.getMember(name); |
| 4412 if (newRet != null) { |
| 4413 if (ret != null && $ne(ret, newRet)) { |
| 4414 $globals.world.error(('conflicting members for "' + name + '"'), span, ret
.get$span(), newRet.get$span()); |
| 4415 } |
| 4416 else { |
| 4417 ret = newRet; |
| 4418 } |
| 4419 } |
| 4420 var $$list = this.imports; |
| 4421 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4422 var imported = $$list.$index($$i); |
| 4423 if (imported.get$prefix() == null) { |
| 4424 newRet = imported.get$library().get$topType().getMember$1(name); |
| 4425 if (newRet != null) { |
| 4426 if (ret != null && $ne(ret, newRet)) { |
| 4427 $globals.world.error(('conflicting members for "' + name + '"'), span,
ret.get$span(), newRet.get$span()); |
| 4428 } |
| 4429 else { |
| 4430 ret = newRet; |
| 4431 } |
| 4432 } |
| 4433 } |
| 4434 } |
| 4435 return ret; |
| 4436 } |
| 4437 Library.prototype.resolve = function() { |
| 4438 if (this.name == null) { |
| 4439 this.name = this.baseSource.filename; |
| 4440 var index = this.name.lastIndexOf('/', this.name.length); |
| 4441 if (index >= 0) { |
| 4442 this.name = this.name.substring(index + 1); |
| 4443 } |
| 4444 index = this.name.indexOf('.'); |
| 4445 if (index > 0) { |
| 4446 this.name = this.name.substring(0, index); |
| 4447 } |
| 4448 } |
| 4449 this._jsname = this.name.replaceAll('.', '_').replaceAll(':', '_').replaceAll(
' ', '_'); |
| 4450 var $$list = this.types.getValues(); |
| 4451 for (var $$i = this.types.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 4452 var type = $$i.next$0(); |
| 4453 type.resolve$0(); |
| 4454 } |
| 4455 } |
| 4456 Library.prototype.visitSources = function() { |
| 4457 var visitor = new _LibraryVisitor(this); |
| 4458 visitor.addSource$1(this.baseSource); |
| 4459 } |
| 4460 Library.prototype.toString = function() { |
| 4461 return this.baseSource.filename; |
| 4462 } |
| 4463 Library.prototype.hashCode = function() { |
| 4464 return this.baseSource.filename.hashCode(); |
| 4465 } |
| 4466 Library.prototype.$eq = function(other) { |
| 4467 return (other instanceof Library) && $eq(other.get$baseSource().get$filename()
, this.baseSource.filename); |
| 4468 } |
| 4469 Library.prototype.findTypeByName$1 = Library.prototype.findTypeByName; |
| 4470 Library.prototype.hashCode$0 = Library.prototype.hashCode; |
| 4471 Library.prototype.resolve$0 = Library.prototype.resolve; |
| 4472 Library.prototype.toString$0 = Library.prototype.toString; |
| 4473 Library.prototype.visitSources$0 = Library.prototype.visitSources; |
| 4474 // ********** Code for _LibraryVisitor ************** |
| 4475 function _LibraryVisitor(library) { |
| 4476 this.seenImport = false |
| 4477 this.seenSource = false |
| 4478 this.seenResource = false |
| 4479 this.isTop = true |
| 4480 this.library = library; |
| 4481 // Initializers done |
| 4482 this.currentType = this.library.topType; |
| 4483 this.sources = []; |
| 4484 } |
| 4485 _LibraryVisitor.prototype.get$library = function() { return this.library; }; |
| 4486 _LibraryVisitor.prototype.get$isTop = function() { return this.isTop; }; |
| 4487 _LibraryVisitor.prototype.set$isTop = function(value) { return this.isTop = valu
e; }; |
| 4488 _LibraryVisitor.prototype.addSourceFromName = function(name, span) { |
| 4489 var filename = this.library.makeFullPath(name); |
| 4490 if ($eq(filename, this.library.baseSource.filename)) { |
| 4491 $globals.world.error('library can not source itself', span); |
| 4492 return; |
| 4493 } |
| 4494 else if (this.sources.some((function (s) { |
| 4495 return $eq(s.get$filename(), filename); |
| 4496 }) |
| 4497 )) { |
| 4498 $globals.world.error(('file "' + filename + '" has already been sourced'), s
pan); |
| 4499 return; |
| 4500 } |
| 4501 var source = $globals.world.readFile(this.library.makeFullPath(name)); |
| 4502 this.sources.add(source); |
| 4503 } |
| 4504 _LibraryVisitor.prototype.addSource = function(source) { |
| 4505 var $this = this; // closure support |
| 4506 if (this.library.sources.some((function (s) { |
| 4507 return $eq(s.get$filename(), source.filename); |
| 4508 }) |
| 4509 )) { |
| 4510 $globals.world.error(('duplicate source file "' + source.filename + '"')); |
| 4511 return; |
| 4512 } |
| 4513 this.library.sources.add(source); |
| 4514 var parser = new Parser(source, $globals.options.dietParse, false, false, 0); |
| 4515 var unit = parser.compilationUnit(); |
| 4516 unit.forEach((function (def) { |
| 4517 return def.visit$1($this); |
| 4518 }) |
| 4519 ); |
| 4520 this.isTop = false; |
| 4521 var newSources = this.sources; |
| 4522 this.sources = []; |
| 4523 for (var $$i = newSources.iterator$0(); $$i.hasNext$0(); ) { |
| 4524 var source0 = $$i.next$0(); |
| 4525 this.addSource(source0); |
| 4526 } |
| 4527 } |
| 4528 _LibraryVisitor.prototype.visitDirectiveDefinition = function(node) { |
| 4529 if (!this.isTop) { |
| 4530 $globals.world.error('directives not allowed in sourced file', node.span); |
| 4531 return; |
| 4532 } |
| 4533 var name; |
| 4534 switch (node.name.name) { |
| 4535 case "library": |
| 4536 |
| 4537 name = this.getSingleStringArg(node); |
| 4538 if (this.library.name == null) { |
| 4539 this.library.name = name; |
| 4540 if ($eq(name, 'node') || $eq(name, 'dom')) { |
| 4541 this.library.topType.isNative = true; |
| 4542 } |
| 4543 if (this.seenImport || this.seenSource || this.seenResource) { |
| 4544 $globals.world.error('#library must be first directive in file', node.
span); |
| 4545 } |
| 4546 } |
| 4547 else { |
| 4548 $globals.world.error('already specified library name', node.span); |
| 4549 } |
| 4550 break; |
| 4551 |
| 4552 case "import": |
| 4553 |
| 4554 this.seenImport = true; |
| 4555 name = this.getFirstStringArg(node); |
| 4556 var prefix = this.tryGetNamedStringArg(node, 'prefix'); |
| 4557 if (node.arguments.length > 2 || node.arguments.length == 2 && prefix == n
ull) { |
| 4558 $globals.world.error('expected at most one "name" argument and one optio
nal "prefix"' + (' but found ' + node.arguments.length), node.span); |
| 4559 } |
| 4560 else if (prefix != null && prefix.indexOf$1('.') >= 0) { |
| 4561 $globals.world.error('library prefix canot contain "."', node.span); |
| 4562 } |
| 4563 else if (this.seenSource || this.seenResource) { |
| 4564 $globals.world.error('#imports must come before any #source or #resource
', node.span); |
| 4565 } |
| 4566 if ($eq(prefix, '')) prefix = null; |
| 4567 var filename = this.library.makeFullPath(name); |
| 4568 if (this.library.imports.some((function (li) { |
| 4569 return $eq(li.get$library().get$baseSource(), filename); |
| 4570 }) |
| 4571 )) { |
| 4572 $globals.world.error(('duplicate import of "' + name + '"'), node.span); |
| 4573 return; |
| 4574 } |
| 4575 var newLib = this.library.addImport(filename, prefix); |
| 4576 break; |
| 4577 |
| 4578 case "source": |
| 4579 |
| 4580 this.seenSource = true; |
| 4581 name = this.getSingleStringArg(node); |
| 4582 this.addSourceFromName(name, node.span); |
| 4583 if (this.seenResource) { |
| 4584 $globals.world.error('#sources must come before any #resource', node.spa
n); |
| 4585 } |
| 4586 break; |
| 4587 |
| 4588 case "native": |
| 4589 |
| 4590 name = this.getSingleStringArg(node); |
| 4591 this.library.addNative(this.library.makeFullPath(name)); |
| 4592 break; |
| 4593 |
| 4594 case "resource": |
| 4595 |
| 4596 this.seenResource = true; |
| 4597 this.getFirstStringArg(node); |
| 4598 break; |
| 4599 |
| 4600 default: |
| 4601 |
| 4602 $globals.world.error(('unknown directive: ' + node.name.name), node.span); |
| 4603 |
| 4604 } |
| 4605 } |
| 4606 _LibraryVisitor.prototype.getSingleStringArg = function(node) { |
| 4607 if (node.arguments.length != 1) { |
| 4608 $globals.world.error(('expected exactly one argument but found ' + node.argu
ments.length), node.span); |
| 4609 } |
| 4610 return this.getFirstStringArg(node); |
| 4611 } |
| 4612 _LibraryVisitor.prototype.getFirstStringArg = function(node) { |
| 4613 if (node.arguments.length < 1) { |
| 4614 $globals.world.error(('expected at least one argument but found ' + node.arg
uments.length), node.span); |
| 4615 } |
| 4616 var arg = node.arguments.$index(0); |
| 4617 if (arg.get$label() != null) { |
| 4618 $globals.world.error('label not allowed for directive', node.span); |
| 4619 } |
| 4620 return this._parseStringArgument(arg); |
| 4621 } |
| 4622 _LibraryVisitor.prototype.tryGetNamedStringArg = function(node, argName) { |
| 4623 var args = node.arguments.filter((function (a) { |
| 4624 return a.get$label() != null && $eq(a.get$label().get$name(), argName); |
| 4625 }) |
| 4626 ); |
| 4627 if ($eq(args.length, 0)) { |
| 4628 return null; |
| 4629 } |
| 4630 if (args.length > 1) { |
| 4631 $globals.world.error(('expected at most one "' + argName + '" argument but f
ound ') + node.arguments.length, node.span); |
| 4632 } |
| 4633 for (var $$i = args.iterator$0(); $$i.hasNext$0(); ) { |
| 4634 var arg = $$i.next$0(); |
| 4635 return this._parseStringArgument(arg); |
| 4636 } |
| 4637 } |
| 4638 _LibraryVisitor.prototype._parseStringArgument = function(arg) { |
| 4639 var expr = arg.value; |
| 4640 if (!(expr instanceof LiteralExpression) || !expr.get$type().get$type().get$is
String()) { |
| 4641 $globals.world.error('expected string', expr.get$span()); |
| 4642 } |
| 4643 return parseStringLiteral(expr.get$value()); |
| 4644 } |
| 4645 _LibraryVisitor.prototype.visitTypeDefinition = function(node) { |
| 4646 var oldType = this.currentType; |
| 4647 this.currentType = this.library.addType(node.name.name, node, node.isClass); |
| 4648 var $$list = node.body; |
| 4649 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4650 var member = $$list.$index($$i); |
| 4651 member.visit$1(this); |
| 4652 } |
| 4653 this.currentType = oldType; |
| 4654 } |
| 4655 _LibraryVisitor.prototype.visitVariableDefinition = function(node) { |
| 4656 this.currentType.addField(node); |
| 4657 } |
| 4658 _LibraryVisitor.prototype.visitFunctionDefinition = function(node) { |
| 4659 this.currentType.addMethod(node.name.name, node); |
| 4660 } |
| 4661 _LibraryVisitor.prototype.visitFunctionTypeDefinition = function(node) { |
| 4662 var type = this.library.addType(node.func.name.name, node, false); |
| 4663 type.addMethod$2(':call', node.func); |
| 4664 } |
| 4665 _LibraryVisitor.prototype.addSource$1 = _LibraryVisitor.prototype.addSource; |
| 4666 // ********** Code for Parameter ************** |
| 4667 function Parameter(definition, method) { |
| 4668 this.isInitializer = false |
| 4669 this.definition = definition; |
| 4670 this.method = method; |
| 4671 // Initializers done |
| 4672 } |
| 4673 Parameter.prototype.get$definition = function() { return this.definition; }; |
| 4674 Parameter.prototype.set$definition = function(value) { return this.definition =
value; }; |
| 4675 Parameter.prototype.get$name = function() { return this.name; }; |
| 4676 Parameter.prototype.set$name = function(value) { return this.name = value; }; |
| 4677 Parameter.prototype.get$type = function() { return this.type; }; |
| 4678 Parameter.prototype.set$type = function(value) { return this.type = value; }; |
| 4679 Parameter.prototype.get$isInitializer = function() { return this.isInitializer;
}; |
| 4680 Parameter.prototype.set$isInitializer = function(value) { return this.isInitiali
zer = value; }; |
| 4681 Parameter.prototype.get$value = function() { return this.value; }; |
| 4682 Parameter.prototype.set$value = function(value) { return this.value = value; }; |
| 4683 Parameter.prototype.resolve = function() { |
| 4684 this.name = this.definition.name.name; |
| 4685 if (this.name.startsWith('this.')) { |
| 4686 this.name = this.name.substring(5); |
| 4687 this.isInitializer = true; |
| 4688 } |
| 4689 this.type = this.method.resolveType(this.definition.type, false); |
| 4690 if (this.definition.value != null) { |
| 4691 if (!this.get$hasDefaultValue()) return; |
| 4692 if (this.method.name == ':call') { |
| 4693 if (this.method.get$definition().get$body() == null) { |
| 4694 $globals.world.error('default value not allowed on function type', this.
definition.span); |
| 4695 } |
| 4696 } |
| 4697 else if (this.method.get$isAbstract()) { |
| 4698 $globals.world.error('default value not allowed on abstract methods', this
.definition.span); |
| 4699 } |
| 4700 } |
| 4701 else if (this.isInitializer && !this.method.get$isConstructor()) { |
| 4702 $globals.world.error('initializer parameters only allowed on constructors',
this.definition.span); |
| 4703 } |
| 4704 } |
| 4705 Parameter.prototype.genValue = function(method, context) { |
| 4706 if (this.definition.value == null || this.value != null) return; |
| 4707 if (context == null) { |
| 4708 context = new MethodGenerator(method, null); |
| 4709 } |
| 4710 this.value = this.definition.value.visit(context); |
| 4711 if (!this.value.get$isConst()) { |
| 4712 $globals.world.error('default parameter values must be constant', this.value
.span); |
| 4713 } |
| 4714 this.value = this.value.convertTo(context, this.type, this.definition.value, f
alse); |
| 4715 } |
| 4716 Parameter.prototype.copyWithNewType = function(newMethod, newType) { |
| 4717 var ret = new Parameter(this.definition, newMethod); |
| 4718 ret.set$type(newType); |
| 4719 ret.set$name(this.name); |
| 4720 ret.set$isInitializer(this.isInitializer); |
| 4721 return ret; |
| 4722 } |
| 4723 Parameter.prototype.get$isOptional = function() { |
| 4724 return this.definition != null && this.definition.value != null; |
| 4725 } |
| 4726 Parameter.prototype.get$hasDefaultValue = function() { |
| 4727 return !(this.definition.value instanceof NullExpression) || (this.definition.
value.span.start != this.definition.span.start); |
| 4728 } |
| 4729 Parameter.prototype.copyWithNewType$2 = Parameter.prototype.copyWithNewType; |
| 4730 Parameter.prototype.genValue$2 = Parameter.prototype.genValue; |
| 4731 Parameter.prototype.resolve$0 = Parameter.prototype.resolve; |
| 4732 // ********** Code for Member ************** |
| 4733 $inherits(Member, Element); |
| 4734 function Member(name, declaringType) { |
| 4735 this.isGenerated = false; |
| 4736 this.declaringType = declaringType; |
| 4737 // Initializers done |
| 4738 Element.call(this, name, declaringType); |
| 4739 } |
| 4740 Member.prototype.get$declaringType = function() { return this.declaringType; }; |
| 4741 Member.prototype.get$isGenerated = function() { return this.isGenerated; }; |
| 4742 Member.prototype.set$isGenerated = function(value) { return this.isGenerated = v
alue; }; |
| 4743 Member.prototype.get$generator = function() { return this.generator; }; |
| 4744 Member.prototype.set$generator = function(value) { return this.generator = value
; }; |
| 4745 Member.prototype.get$library = function() { |
| 4746 return this.declaringType.get$library(); |
| 4747 } |
| 4748 Member.prototype.get$isPrivate = function() { |
| 4749 return this.name.startsWith('_'); |
| 4750 } |
| 4751 Member.prototype.get$isConstructor = function() { |
| 4752 return false; |
| 4753 } |
| 4754 Member.prototype.get$isField = function() { |
| 4755 return false; |
| 4756 } |
| 4757 Member.prototype.get$isMethod = function() { |
| 4758 return false; |
| 4759 } |
| 4760 Member.prototype.get$isProperty = function() { |
| 4761 return false; |
| 4762 } |
| 4763 Member.prototype.get$isAbstract = function() { |
| 4764 return false; |
| 4765 } |
| 4766 Member.prototype.get$isFinal = function() { |
| 4767 return false; |
| 4768 } |
| 4769 Member.prototype.get$isConst = function() { |
| 4770 return false; |
| 4771 } |
| 4772 Member.prototype.get$isFactory = function() { |
| 4773 return false; |
| 4774 } |
| 4775 Member.prototype.get$isOperator = function() { |
| 4776 return this.name.startsWith(':'); |
| 4777 } |
| 4778 Member.prototype.get$isCallMethod = function() { |
| 4779 return this.name == ':call'; |
| 4780 } |
| 4781 Member.prototype.get$prefersPropertySyntax = function() { |
| 4782 return true; |
| 4783 } |
| 4784 Member.prototype.get$requiresFieldSyntax = function() { |
| 4785 return false; |
| 4786 } |
| 4787 Member.prototype.get$isNative = function() { |
| 4788 return false; |
| 4789 } |
| 4790 Member.prototype.get$constructorName = function() { |
| 4791 $globals.world.internalError('can not be a constructor', this.get$span()); |
| 4792 } |
| 4793 Member.prototype.provideFieldSyntax = function() { |
| 4794 |
| 4795 } |
| 4796 Member.prototype.providePropertySyntax = function() { |
| 4797 |
| 4798 } |
| 4799 Member.prototype.get$initDelegate = function() { |
| 4800 $globals.world.internalError('cannot have initializers', this.get$span()); |
| 4801 } |
| 4802 Member.prototype.set$initDelegate = function(ctor) { |
| 4803 $globals.world.internalError('cannot have initializers', this.get$span()); |
| 4804 } |
| 4805 Member.prototype.computeValue = function() { |
| 4806 $globals.world.internalError('cannot have value', this.get$span()); |
| 4807 } |
| 4808 Member.prototype.get$inferredResult = function() { |
| 4809 var t = this.get$returnType(); |
| 4810 if (t.get$isBool() && (this.get$library().get$isCore() || this.get$library().g
et$isCoreImpl())) { |
| 4811 return $globals.world.nonNullBool; |
| 4812 } |
| 4813 return t; |
| 4814 } |
| 4815 Member.prototype.get$definition = function() { |
| 4816 return null; |
| 4817 } |
| 4818 Member.prototype.get$parameters = function() { |
| 4819 return []; |
| 4820 } |
| 4821 Member.prototype.canInvoke = function(context, args) { |
| 4822 return this.get$canGet() && new Value(this.get$returnType(), null, null, true)
.canInvoke(context, ':call', args); |
| 4823 } |
| 4824 Member.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 4825 var newTarget = this._get(context, node, target, isDynamic); |
| 4826 return newTarget.invoke$5(context, ':call', node, args, isDynamic); |
| 4827 } |
| 4828 Member.prototype.override = function(other) { |
| 4829 if (this.get$isStatic()) { |
| 4830 $globals.world.error('static members can not hide parent members', this.get$
span(), other.get$span()); |
| 4831 return false; |
| 4832 } |
| 4833 else if (other.get$isStatic()) { |
| 4834 $globals.world.error('can not override static member', this.get$span(), othe
r.get$span()); |
| 4835 return false; |
| 4836 } |
| 4837 return true; |
| 4838 } |
| 4839 Member.prototype.get$generatedFactoryName = function() { |
| 4840 var prefix = ('' + this.declaringType.get$jsname() + '.' + this.get$constructo
rName() + '\$'); |
| 4841 if (this.name == '') { |
| 4842 return ('' + prefix + 'factory'); |
| 4843 } |
| 4844 else { |
| 4845 return ('' + prefix + this.name + '\$factory'); |
| 4846 } |
| 4847 } |
| 4848 Member.prototype.hashCode = function() { |
| 4849 var typeCode = this.declaringType == null ? 1 : this.declaringType.hashCode(); |
| 4850 var nameCode = this.get$isConstructor() ? this.get$constructorName().hashCode(
) : this.name.hashCode(); |
| 4851 return (typeCode << 4) ^ nameCode; |
| 4852 } |
| 4853 Member.prototype.$eq = function(other) { |
| 4854 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.get$name()); |
| 4855 } |
| 4856 Member.prototype._get$3 = Member.prototype._get; |
| 4857 Member.prototype._get$3$isDynamic = Member.prototype._get; |
| 4858 Member.prototype._get$4 = Member.prototype._get; |
| 4859 Member.prototype._set$4 = Member.prototype._set; |
| 4860 Member.prototype._set$4$isDynamic = Member.prototype._set; |
| 4861 Member.prototype._set$5 = Member.prototype._set; |
| 4862 Member.prototype.canInvoke$2 = Member.prototype.canInvoke; |
| 4863 Member.prototype.computeValue$0 = Member.prototype.computeValue; |
| 4864 Member.prototype.hashCode$0 = Member.prototype.hashCode; |
| 4865 Member.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 4866 return this.invoke($0, $1, $2, $3, false); |
| 4867 }; |
| 4868 Member.prototype.invoke$4$isDynamic = Member.prototype.invoke; |
| 4869 Member.prototype.invoke$5 = Member.prototype.invoke; |
| 4870 Member.prototype.provideFieldSyntax$0 = Member.prototype.provideFieldSyntax; |
| 4871 Member.prototype.providePropertySyntax$0 = Member.prototype.providePropertySynta
x; |
| 4872 // ********** Code for TypeMember ************** |
| 4873 $inherits(TypeMember, Member); |
| 4874 function TypeMember(type) { |
| 4875 this.type = type; |
| 4876 // Initializers done |
| 4877 Member.call(this, type.name, type.library.topType); |
| 4878 } |
| 4879 TypeMember.prototype.get$type = function() { return this.type; }; |
| 4880 TypeMember.prototype.get$span = function() { |
| 4881 return this.type.definition.span; |
| 4882 } |
| 4883 TypeMember.prototype.get$isStatic = function() { |
| 4884 return true; |
| 4885 } |
| 4886 TypeMember.prototype.get$returnType = function() { |
| 4887 return $globals.world.varType; |
| 4888 } |
| 4889 TypeMember.prototype.canInvoke = function(context, args) { |
| 4890 return false; |
| 4891 } |
| 4892 TypeMember.prototype.get$canGet = function() { |
| 4893 return true; |
| 4894 } |
| 4895 TypeMember.prototype.get$canSet = function() { |
| 4896 return false; |
| 4897 } |
| 4898 TypeMember.prototype.get$requiresFieldSyntax = function() { |
| 4899 return true; |
| 4900 } |
| 4901 TypeMember.prototype._get = function(context, node, target, isDynamic) { |
| 4902 return new Value.type$ctor(this.type, node.span); |
| 4903 } |
| 4904 TypeMember.prototype._set = function(context, node, target, value, isDynamic) { |
| 4905 $globals.world.error('cannot set type', node.span); |
| 4906 } |
| 4907 TypeMember.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 4908 $globals.world.error('cannot invoke type', node.span); |
| 4909 } |
| 4910 TypeMember.prototype._get$3 = function($0, $1, $2) { |
| 4911 return this._get($0, $1, $2, false); |
| 4912 }; |
| 4913 TypeMember.prototype._get$3$isDynamic = TypeMember.prototype._get; |
| 4914 TypeMember.prototype._get$4 = TypeMember.prototype._get; |
| 4915 TypeMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 4916 return this._set($0, $1, $2, $3, false); |
| 4917 }; |
| 4918 TypeMember.prototype._set$4$isDynamic = TypeMember.prototype._set; |
| 4919 TypeMember.prototype._set$5 = TypeMember.prototype._set; |
| 4920 TypeMember.prototype.canInvoke$2 = TypeMember.prototype.canInvoke; |
| 4921 TypeMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 4922 return this.invoke($0, $1, $2, $3, false); |
| 4923 }; |
| 4924 TypeMember.prototype.invoke$4$isDynamic = TypeMember.prototype.invoke; |
| 4925 TypeMember.prototype.invoke$5 = TypeMember.prototype.invoke; |
| 4926 // ********** Code for FieldMember ************** |
| 4927 $inherits(FieldMember, Member); |
| 4928 function FieldMember(name, declaringType, definition, value) { |
| 4929 this._providePropertySyntax = false |
| 4930 this._computing = false |
| 4931 this.definition = definition; |
| 4932 this.value = value; |
| 4933 this.isNative = false; |
| 4934 // Initializers done |
| 4935 Member.call(this, name, declaringType); |
| 4936 } |
| 4937 FieldMember.prototype.get$definition = function() { return this.definition; }; |
| 4938 FieldMember.prototype.get$value = function() { return this.value; }; |
| 4939 FieldMember.prototype.get$type = function() { return this.type; }; |
| 4940 FieldMember.prototype.set$type = function(value) { return this.type = value; }; |
| 4941 FieldMember.prototype.get$isStatic = function() { return this.isStatic; }; |
| 4942 FieldMember.prototype.set$isStatic = function(value) { return this.isStatic = va
lue; }; |
| 4943 FieldMember.prototype.get$isFinal = function() { return this.isFinal; }; |
| 4944 FieldMember.prototype.set$isFinal = function(value) { return this.isFinal = valu
e; }; |
| 4945 FieldMember.prototype.get$isNative = function() { return this.isNative; }; |
| 4946 FieldMember.prototype.set$isNative = function(value) { return this.isNative = va
lue; }; |
| 4947 FieldMember.prototype.override = function(other) { |
| 4948 if (!Member.prototype.override.call(this, other)) return false; |
| 4949 if (other.get$isProperty()) { |
| 4950 return true; |
| 4951 } |
| 4952 else { |
| 4953 $globals.world.error('field can not override anything but property', this.ge
t$span(), other.get$span()); |
| 4954 return false; |
| 4955 } |
| 4956 } |
| 4957 FieldMember.prototype.get$prefersPropertySyntax = function() { |
| 4958 return false; |
| 4959 } |
| 4960 FieldMember.prototype.get$requiresFieldSyntax = function() { |
| 4961 return this.isNative; |
| 4962 } |
| 4963 FieldMember.prototype.provideFieldSyntax = function() { |
| 4964 |
| 4965 } |
| 4966 FieldMember.prototype.providePropertySyntax = function() { |
| 4967 this._providePropertySyntax = true; |
| 4968 } |
| 4969 FieldMember.prototype.get$span = function() { |
| 4970 return this.definition == null ? null : this.definition.span; |
| 4971 } |
| 4972 FieldMember.prototype.get$returnType = function() { |
| 4973 return this.type; |
| 4974 } |
| 4975 FieldMember.prototype.get$canGet = function() { |
| 4976 return true; |
| 4977 } |
| 4978 FieldMember.prototype.get$canSet = function() { |
| 4979 return !this.isFinal; |
| 4980 } |
| 4981 FieldMember.prototype.get$isField = function() { |
| 4982 return true; |
| 4983 } |
| 4984 FieldMember.prototype.resolve = function() { |
| 4985 this.isStatic = this.declaringType.get$isTop(); |
| 4986 this.isFinal = false; |
| 4987 if (this.definition.modifiers != null) { |
| 4988 var $$list = this.definition.modifiers; |
| 4989 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 4990 var mod = $$list.$index($$i); |
| 4991 if ($eq(mod.get$kind(), 86/*TokenKind.STATIC*/)) { |
| 4992 if (this.isStatic) { |
| 4993 $globals.world.error('duplicate static modifier', mod.get$span()); |
| 4994 } |
| 4995 this.isStatic = true; |
| 4996 } |
| 4997 else if ($eq(mod.get$kind(), 98/*TokenKind.FINAL*/)) { |
| 4998 if (this.isFinal) { |
| 4999 $globals.world.error('duplicate final modifier', mod.get$span()); |
| 5000 } |
| 5001 this.isFinal = true; |
| 5002 } |
| 5003 else { |
| 5004 $globals.world.error(('' + mod + ' modifier not allowed on field'), mod.
get$span()); |
| 5005 } |
| 5006 } |
| 5007 } |
| 5008 this.type = this.resolveType(this.definition.type, false); |
| 5009 if (this.isStatic && this.type.get$hasTypeParams()) { |
| 5010 $globals.world.error('using type parameter in static context', this.definiti
on.type.span); |
| 5011 } |
| 5012 if (this.isStatic && this.isFinal && this.value == null) { |
| 5013 $globals.world.error('static final field is missing initializer', this.get$s
pan()); |
| 5014 } |
| 5015 this.get$library()._addMember(this); |
| 5016 } |
| 5017 FieldMember.prototype.computeValue = function() { |
| 5018 if (this.value == null) return null; |
| 5019 if (this._computedValue == null) { |
| 5020 if (this._computing) { |
| 5021 $globals.world.error('circular reference', this.value.span); |
| 5022 return null; |
| 5023 } |
| 5024 this._computing = true; |
| 5025 var finalMethod = new MethodMember('final_context', this.declaringType, null
); |
| 5026 finalMethod.set$isStatic(true); |
| 5027 var finalGen = new MethodGenerator(finalMethod, null); |
| 5028 this._computedValue = this.value.visit(finalGen); |
| 5029 if (!this._computedValue.get$isConst()) { |
| 5030 if (this.isStatic) { |
| 5031 $globals.world.error('non constant static field must be initialized in f
unctions', this.value.span); |
| 5032 } |
| 5033 else { |
| 5034 $globals.world.error('non constant field must be initialized in construc
tor', this.value.span); |
| 5035 } |
| 5036 } |
| 5037 if (this.isStatic) { |
| 5038 this._computedValue = $globals.world.gen.globalForStaticField(this, this._
computedValue, [this._computedValue]); |
| 5039 } |
| 5040 this._computing = false; |
| 5041 } |
| 5042 return this._computedValue; |
| 5043 } |
| 5044 FieldMember.prototype._get = function(context, node, target, isDynamic) { |
| 5045 if (this.isNative && this.get$returnType() != null) { |
| 5046 this.get$returnType().markUsed(); |
| 5047 if ((this.get$returnType() instanceof DefinedType)) { |
| 5048 var factory_ = this.get$returnType().get$genericType().factory_; |
| 5049 if (factory_ != null && factory_.get$isNative()) { |
| 5050 factory_.markUsed$0(); |
| 5051 } |
| 5052 } |
| 5053 } |
| 5054 if (this.isStatic) { |
| 5055 this.declaringType.markUsed(); |
| 5056 var cv = this.computeValue(); |
| 5057 if (this.isFinal) { |
| 5058 return cv; |
| 5059 } |
| 5060 $globals.world.gen.hasStatics = true; |
| 5061 if (this.declaringType.get$isTop()) { |
| 5062 if ($eq(this.declaringType.get$library(), $globals.world.get$dom())) { |
| 5063 return new Value(this.type, ('' + this.get$jsname()), node.span, true); |
| 5064 } |
| 5065 else { |
| 5066 return new Value(this.type, ('\$globals.' + this.get$jsname()), node.spa
n, true); |
| 5067 } |
| 5068 } |
| 5069 else if (this.declaringType.get$isNative()) { |
| 5070 if (this.declaringType.get$isHiddenNativeType()) { |
| 5071 $globals.world.error('static field of hidden native type is inaccessible
', node.span); |
| 5072 } |
| 5073 return new Value(this.type, ('' + this.declaringType.get$jsname() + '.' +
this.get$jsname()), node.span, true); |
| 5074 } |
| 5075 else { |
| 5076 return new Value(this.type, ('\$globals.' + this.declaringType.get$jsname(
) + '_' + this.get$jsname()), node.span, true); |
| 5077 } |
| 5078 } |
| 5079 else if (target.get$isConst() && this.isFinal) { |
| 5080 var constTarget = (target instanceof GlobalValue) ? target.get$dynamic().get
$exp() : target; |
| 5081 if ((constTarget instanceof ConstObjectValue)) { |
| 5082 return constTarget.get$fields().$index(this.name); |
| 5083 } |
| 5084 else if ($eq(constTarget.get$type(), $globals.world.stringType) && this.name
== 'length') { |
| 5085 return new Value(this.type, ('' + constTarget.get$actualValue().length), n
ode.span, true); |
| 5086 } |
| 5087 } |
| 5088 return new Value(this.type, ('' + target.code + '.' + this.get$jsname()), node
.span, true); |
| 5089 } |
| 5090 FieldMember.prototype._set = function(context, node, target, value, isDynamic) { |
| 5091 var lhs = this._get(context, node, target, isDynamic); |
| 5092 value = value.convertTo(context, this.type, node, isDynamic); |
| 5093 return new Value(this.type, ('' + lhs.get$code() + ' = ' + value.code), node.s
pan, true); |
| 5094 } |
| 5095 FieldMember.prototype._get$3 = function($0, $1, $2) { |
| 5096 return this._get($0, $1, $2, false); |
| 5097 }; |
| 5098 FieldMember.prototype._get$3$isDynamic = FieldMember.prototype._get; |
| 5099 FieldMember.prototype._get$4 = FieldMember.prototype._get; |
| 5100 FieldMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 5101 return this._set($0, $1, $2, $3, false); |
| 5102 }; |
| 5103 FieldMember.prototype._set$4$isDynamic = FieldMember.prototype._set; |
| 5104 FieldMember.prototype._set$5 = FieldMember.prototype._set; |
| 5105 FieldMember.prototype.computeValue$0 = FieldMember.prototype.computeValue; |
| 5106 FieldMember.prototype.provideFieldSyntax$0 = FieldMember.prototype.provideFieldS
yntax; |
| 5107 FieldMember.prototype.providePropertySyntax$0 = FieldMember.prototype.providePro
pertySyntax; |
| 5108 FieldMember.prototype.resolve$0 = FieldMember.prototype.resolve; |
| 5109 // ********** Code for PropertyMember ************** |
| 5110 $inherits(PropertyMember, Member); |
| 5111 function PropertyMember(name, declaringType) { |
| 5112 this._provideFieldSyntax = false |
| 5113 // Initializers done |
| 5114 Member.call(this, name, declaringType); |
| 5115 } |
| 5116 PropertyMember.prototype.get$getter = function() { return this.getter; }; |
| 5117 PropertyMember.prototype.set$getter = function(value) { return this.getter = val
ue; }; |
| 5118 PropertyMember.prototype.get$setter = function() { return this.setter; }; |
| 5119 PropertyMember.prototype.set$setter = function(value) { return this.setter = val
ue; }; |
| 5120 PropertyMember.prototype.get$span = function() { |
| 5121 return this.getter != null ? this.getter.get$span() : null; |
| 5122 } |
| 5123 PropertyMember.prototype.get$canGet = function() { |
| 5124 return this.getter != null; |
| 5125 } |
| 5126 PropertyMember.prototype.get$canSet = function() { |
| 5127 return this.setter != null; |
| 5128 } |
| 5129 PropertyMember.prototype.get$prefersPropertySyntax = function() { |
| 5130 return true; |
| 5131 } |
| 5132 PropertyMember.prototype.get$requiresFieldSyntax = function() { |
| 5133 return false; |
| 5134 } |
| 5135 PropertyMember.prototype.provideFieldSyntax = function() { |
| 5136 this._provideFieldSyntax = true; |
| 5137 } |
| 5138 PropertyMember.prototype.providePropertySyntax = function() { |
| 5139 |
| 5140 } |
| 5141 PropertyMember.prototype.get$isStatic = function() { |
| 5142 return this.getter == null ? this.setter.isStatic : this.getter.isStatic; |
| 5143 } |
| 5144 PropertyMember.prototype.get$isProperty = function() { |
| 5145 return true; |
| 5146 } |
| 5147 PropertyMember.prototype.get$returnType = function() { |
| 5148 return this.getter == null ? this.setter.returnType : this.getter.returnType; |
| 5149 } |
| 5150 PropertyMember.prototype.override = function(other) { |
| 5151 if (!Member.prototype.override.call(this, other)) return false; |
| 5152 if (other.get$isProperty() || other.get$isField()) { |
| 5153 if (other.get$isProperty()) this.addFromParent(other); |
| 5154 else this._overriddenField = other; |
| 5155 return true; |
| 5156 } |
| 5157 else { |
| 5158 $globals.world.error('property can only override field or property', this.ge
t$span(), other.get$span()); |
| 5159 return false; |
| 5160 } |
| 5161 } |
| 5162 PropertyMember.prototype._get = function(context, node, target, isDynamic) { |
| 5163 if (this.getter == null) { |
| 5164 if (this._overriddenField != null) { |
| 5165 return this._overriddenField._get(context, node, target, isDynamic); |
| 5166 } |
| 5167 return target.invokeNoSuchMethod(context, ('get:' + this.name), node); |
| 5168 } |
| 5169 return this.getter.invoke(context, node, target, Arguments.get$EMPTY(), false)
; |
| 5170 } |
| 5171 PropertyMember.prototype._set = function(context, node, target, value, isDynamic
) { |
| 5172 if (this.setter == null) { |
| 5173 if (this._overriddenField != null) { |
| 5174 return this._overriddenField._set(context, node, target, value, isDynamic)
; |
| 5175 } |
| 5176 return target.invokeNoSuchMethod(context, ('set:' + this.name), node, new Ar
guments(null, [value])); |
| 5177 } |
| 5178 return this.setter.invoke(context, node, target, new Arguments(null, [value]),
isDynamic); |
| 5179 } |
| 5180 PropertyMember.prototype.addFromParent = function(parentMember) { |
| 5181 var parent; |
| 5182 if ((parentMember instanceof ConcreteMember)) { |
| 5183 var c = parentMember; |
| 5184 parent = c.baseMember; |
| 5185 } |
| 5186 else { |
| 5187 parent = parentMember; |
| 5188 } |
| 5189 if (this.getter == null) this.getter = parent.getter; |
| 5190 if (this.setter == null) this.setter = parent.setter; |
| 5191 } |
| 5192 PropertyMember.prototype.resolve = function() { |
| 5193 if (this.getter != null) { |
| 5194 this.getter.resolve(); |
| 5195 if (this.getter.parameters.length != 0) { |
| 5196 $globals.world.error('getter methods should take no arguments', this.gette
r.definition.span); |
| 5197 } |
| 5198 if (this.getter.returnType.get$isVoid()) { |
| 5199 $globals.world.warning('getter methods should not be void', this.getter.de
finition.returnType.span); |
| 5200 } |
| 5201 } |
| 5202 if (this.setter != null) { |
| 5203 this.setter.resolve(); |
| 5204 if (this.setter.parameters.length != 1) { |
| 5205 $globals.world.error('setter methods should take a single argument', this.
setter.definition.span); |
| 5206 } |
| 5207 if (!this.setter.returnType.get$isVoid() && this.setter.definition.returnTyp
e != null) { |
| 5208 $globals.world.warning('setter methods should be void', this.setter.defini
tion.returnType.span); |
| 5209 } |
| 5210 } |
| 5211 this.get$library()._addMember(this); |
| 5212 } |
| 5213 PropertyMember.prototype._get$3 = function($0, $1, $2) { |
| 5214 return this._get($0, $1, $2, false); |
| 5215 }; |
| 5216 PropertyMember.prototype._get$3$isDynamic = PropertyMember.prototype._get; |
| 5217 PropertyMember.prototype._get$4 = PropertyMember.prototype._get; |
| 5218 PropertyMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 5219 return this._set($0, $1, $2, $3, false); |
| 5220 }; |
| 5221 PropertyMember.prototype._set$4$isDynamic = PropertyMember.prototype._set; |
| 5222 PropertyMember.prototype._set$5 = PropertyMember.prototype._set; |
| 5223 PropertyMember.prototype.provideFieldSyntax$0 = PropertyMember.prototype.provide
FieldSyntax; |
| 5224 PropertyMember.prototype.providePropertySyntax$0 = PropertyMember.prototype.prov
idePropertySyntax; |
| 5225 PropertyMember.prototype.resolve$0 = PropertyMember.prototype.resolve; |
| 5226 // ********** Code for ConcreteMember ************** |
| 5227 $inherits(ConcreteMember, Member); |
| 5228 function ConcreteMember(name, declaringType, baseMember) { |
| 5229 this.baseMember = baseMember; |
| 5230 // Initializers done |
| 5231 Member.call(this, name, declaringType); |
| 5232 this.parameters = []; |
| 5233 this.returnType = this.baseMember.get$returnType().resolveTypeParams(declaring
Type); |
| 5234 var $$list = this.baseMember.get$parameters(); |
| 5235 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5236 var p = $$list.$index($$i); |
| 5237 var newType = p.get$type().resolveTypeParams$1(declaringType); |
| 5238 if ($ne(newType, p.get$type())) { |
| 5239 this.parameters.add(p.copyWithNewType$2(this, newType)); |
| 5240 } |
| 5241 else { |
| 5242 this.parameters.add(p); |
| 5243 } |
| 5244 } |
| 5245 } |
| 5246 ConcreteMember.prototype.get$returnType = function() { return this.returnType; }
; |
| 5247 ConcreteMember.prototype.set$returnType = function(value) { return this.returnTy
pe = value; }; |
| 5248 ConcreteMember.prototype.get$parameters = function() { return this.parameters; }
; |
| 5249 ConcreteMember.prototype.set$parameters = function(value) { return this.paramete
rs = value; }; |
| 5250 ConcreteMember.prototype.get$span = function() { |
| 5251 return this.baseMember.get$span(); |
| 5252 } |
| 5253 ConcreteMember.prototype.get$isStatic = function() { |
| 5254 return this.baseMember.get$isStatic(); |
| 5255 } |
| 5256 ConcreteMember.prototype.get$isAbstract = function() { |
| 5257 return this.baseMember.get$isAbstract(); |
| 5258 } |
| 5259 ConcreteMember.prototype.get$isConst = function() { |
| 5260 return this.baseMember.get$isConst(); |
| 5261 } |
| 5262 ConcreteMember.prototype.get$isFactory = function() { |
| 5263 return this.baseMember.get$isFactory(); |
| 5264 } |
| 5265 ConcreteMember.prototype.get$isFinal = function() { |
| 5266 return this.baseMember.get$isFinal(); |
| 5267 } |
| 5268 ConcreteMember.prototype.get$isNative = function() { |
| 5269 return this.baseMember.get$isNative(); |
| 5270 } |
| 5271 ConcreteMember.prototype.get$jsname = function() { |
| 5272 return this.baseMember.get$jsname(); |
| 5273 } |
| 5274 ConcreteMember.prototype.get$canGet = function() { |
| 5275 return this.baseMember.get$canGet(); |
| 5276 } |
| 5277 ConcreteMember.prototype.get$canSet = function() { |
| 5278 return this.baseMember.get$canSet(); |
| 5279 } |
| 5280 ConcreteMember.prototype.canInvoke = function(context, args) { |
| 5281 return this.baseMember.canInvoke(context, args); |
| 5282 } |
| 5283 ConcreteMember.prototype.get$isField = function() { |
| 5284 return this.baseMember.get$isField(); |
| 5285 } |
| 5286 ConcreteMember.prototype.get$isMethod = function() { |
| 5287 return this.baseMember.get$isMethod(); |
| 5288 } |
| 5289 ConcreteMember.prototype.get$isProperty = function() { |
| 5290 return this.baseMember.get$isProperty(); |
| 5291 } |
| 5292 ConcreteMember.prototype.get$prefersPropertySyntax = function() { |
| 5293 return this.baseMember.get$prefersPropertySyntax(); |
| 5294 } |
| 5295 ConcreteMember.prototype.get$requiresFieldSyntax = function() { |
| 5296 return this.baseMember.get$requiresFieldSyntax(); |
| 5297 } |
| 5298 ConcreteMember.prototype.provideFieldSyntax = function() { |
| 5299 return this.baseMember.provideFieldSyntax(); |
| 5300 } |
| 5301 ConcreteMember.prototype.providePropertySyntax = function() { |
| 5302 return this.baseMember.providePropertySyntax(); |
| 5303 } |
| 5304 ConcreteMember.prototype.get$isConstructor = function() { |
| 5305 return this.name == this.declaringType.name; |
| 5306 } |
| 5307 ConcreteMember.prototype.get$constructorName = function() { |
| 5308 return this.baseMember.get$constructorName(); |
| 5309 } |
| 5310 ConcreteMember.prototype.get$definition = function() { |
| 5311 return this.baseMember.get$definition(); |
| 5312 } |
| 5313 ConcreteMember.prototype.get$initDelegate = function() { |
| 5314 return this.baseMember.get$initDelegate(); |
| 5315 } |
| 5316 ConcreteMember.prototype.set$initDelegate = function(ctor) { |
| 5317 this.baseMember.set$initDelegate(ctor); |
| 5318 } |
| 5319 ConcreteMember.prototype.resolveType = function(node, isRequired) { |
| 5320 var type = this.baseMember.resolveType(node, isRequired); |
| 5321 return type.resolveTypeParams$1(this.declaringType); |
| 5322 } |
| 5323 ConcreteMember.prototype.computeValue = function() { |
| 5324 return this.baseMember.computeValue(); |
| 5325 } |
| 5326 ConcreteMember.prototype.override = function(other) { |
| 5327 return this.baseMember.override(other); |
| 5328 } |
| 5329 ConcreteMember.prototype._get = function(context, node, target, isDynamic) { |
| 5330 var ret = this.baseMember._get(context, node, target, isDynamic); |
| 5331 return new Value(this.get$inferredResult(), ret.code, node.span, true); |
| 5332 } |
| 5333 ConcreteMember.prototype._set = function(context, node, target, value, isDynamic
) { |
| 5334 var ret = this.baseMember._set(context, node, target, value, isDynamic); |
| 5335 return new Value(this.returnType, ret.code, node.span, true); |
| 5336 } |
| 5337 ConcreteMember.prototype.invoke = function(context, node, target, args, isDynami
c) { |
| 5338 var ret = this.baseMember.invoke(context, node, target, args, isDynamic); |
| 5339 var code = ret.code; |
| 5340 if (this.get$isConstructor()) { |
| 5341 code = code.replaceFirst$2(this.declaringType.get$genericType().get$jsname()
, this.declaringType.get$jsname()); |
| 5342 } |
| 5343 if ((this.baseMember instanceof MethodMember)) { |
| 5344 this.declaringType.genMethod(this); |
| 5345 } |
| 5346 return new Value(this.get$inferredResult(), code, node.span, true); |
| 5347 } |
| 5348 ConcreteMember.prototype._get$3 = function($0, $1, $2) { |
| 5349 return this._get($0, $1, $2, false); |
| 5350 }; |
| 5351 ConcreteMember.prototype._get$3$isDynamic = ConcreteMember.prototype._get; |
| 5352 ConcreteMember.prototype._get$4 = ConcreteMember.prototype._get; |
| 5353 ConcreteMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 5354 return this._set($0, $1, $2, $3, false); |
| 5355 }; |
| 5356 ConcreteMember.prototype._set$4$isDynamic = ConcreteMember.prototype._set; |
| 5357 ConcreteMember.prototype._set$5 = ConcreteMember.prototype._set; |
| 5358 ConcreteMember.prototype.canInvoke$2 = ConcreteMember.prototype.canInvoke; |
| 5359 ConcreteMember.prototype.computeValue$0 = ConcreteMember.prototype.computeValue; |
| 5360 ConcreteMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 5361 return this.invoke($0, $1, $2, $3, false); |
| 5362 }; |
| 5363 ConcreteMember.prototype.invoke$4$isDynamic = ConcreteMember.prototype.invoke; |
| 5364 ConcreteMember.prototype.invoke$5 = ConcreteMember.prototype.invoke; |
| 5365 ConcreteMember.prototype.provideFieldSyntax$0 = ConcreteMember.prototype.provide
FieldSyntax; |
| 5366 ConcreteMember.prototype.providePropertySyntax$0 = ConcreteMember.prototype.prov
idePropertySyntax; |
| 5367 // ********** Code for MethodMember ************** |
| 5368 $inherits(MethodMember, Member); |
| 5369 function MethodMember(name, declaringType, definition) { |
| 5370 this.isStatic = false |
| 5371 this.isAbstract = false |
| 5372 this.isConst = false |
| 5373 this.isFactory = false |
| 5374 this.isLambda = false |
| 5375 this._providePropertySyntax = false |
| 5376 this._provideFieldSyntax = false |
| 5377 this._provideOptionalParamInfo = false |
| 5378 this.definition = definition; |
| 5379 // Initializers done |
| 5380 Member.call(this, name, declaringType); |
| 5381 } |
| 5382 MethodMember.prototype.get$definition = function() { return this.definition; }; |
| 5383 MethodMember.prototype.set$definition = function(value) { return this.definition
= value; }; |
| 5384 MethodMember.prototype.get$returnType = function() { return this.returnType; }; |
| 5385 MethodMember.prototype.set$returnType = function(value) { return this.returnType
= value; }; |
| 5386 MethodMember.prototype.get$parameters = function() { return this.parameters; }; |
| 5387 MethodMember.prototype.set$parameters = function(value) { return this.parameters
= value; }; |
| 5388 MethodMember.prototype.get$typeParameters = function() { return this.typeParamet
ers; }; |
| 5389 MethodMember.prototype.set$typeParameters = function(value) { return this.typePa
rameters = value; }; |
| 5390 MethodMember.prototype.get$isStatic = function() { return this.isStatic; }; |
| 5391 MethodMember.prototype.set$isStatic = function(value) { return this.isStatic = v
alue; }; |
| 5392 MethodMember.prototype.get$isAbstract = function() { return this.isAbstract; }; |
| 5393 MethodMember.prototype.set$isAbstract = function(value) { return this.isAbstract
= value; }; |
| 5394 MethodMember.prototype.get$isConst = function() { return this.isConst; }; |
| 5395 MethodMember.prototype.set$isConst = function(value) { return this.isConst = val
ue; }; |
| 5396 MethodMember.prototype.get$isFactory = function() { return this.isFactory; }; |
| 5397 MethodMember.prototype.set$isFactory = function(value) { return this.isFactory =
value; }; |
| 5398 MethodMember.prototype.get$isLambda = function() { return this.isLambda; }; |
| 5399 MethodMember.prototype.set$isLambda = function(value) { return this.isLambda = v
alue; }; |
| 5400 MethodMember.prototype.get$initDelegate = function() { return this.initDelegate;
}; |
| 5401 MethodMember.prototype.set$initDelegate = function(value) { return this.initDele
gate = value; }; |
| 5402 MethodMember.prototype.get$isConstructor = function() { |
| 5403 return this.name == this.declaringType.name; |
| 5404 } |
| 5405 MethodMember.prototype.get$isMethod = function() { |
| 5406 return !this.get$isConstructor(); |
| 5407 } |
| 5408 MethodMember.prototype.get$isNative = function() { |
| 5409 return this.definition.nativeBody != null; |
| 5410 } |
| 5411 MethodMember.prototype.get$canGet = function() { |
| 5412 return false; |
| 5413 } |
| 5414 MethodMember.prototype.get$canSet = function() { |
| 5415 return false; |
| 5416 } |
| 5417 MethodMember.prototype.get$span = function() { |
| 5418 return this.definition == null ? null : this.definition.span; |
| 5419 } |
| 5420 MethodMember.prototype.get$constructorName = function() { |
| 5421 var returnType = this.definition.returnType; |
| 5422 if (returnType == null) return ''; |
| 5423 if ((returnType instanceof GenericTypeReference)) { |
| 5424 return ''; |
| 5425 } |
| 5426 if (returnType.get$names() != null) { |
| 5427 return returnType.get$names().$index(0).get$name(); |
| 5428 } |
| 5429 else if (returnType.get$name() != null) { |
| 5430 return returnType.get$name().get$name(); |
| 5431 } |
| 5432 $globals.world.internalError('no valid constructor name', this.definition.span
); |
| 5433 } |
| 5434 MethodMember.prototype.get$functionType = function() { |
| 5435 if (this._functionType == null) { |
| 5436 this._functionType = this.get$library().getOrAddFunctionType(this.declaringT
ype, this.name, this.definition); |
| 5437 if (this.parameters == null) { |
| 5438 this.resolve(); |
| 5439 } |
| 5440 } |
| 5441 return this._functionType; |
| 5442 } |
| 5443 MethodMember.prototype.override = function(other) { |
| 5444 if (!Member.prototype.override.call(this, other)) return false; |
| 5445 if (other.get$isMethod()) { |
| 5446 return true; |
| 5447 } |
| 5448 else { |
| 5449 $globals.world.error('method can only override methods', this.get$span(), ot
her.get$span()); |
| 5450 return false; |
| 5451 } |
| 5452 } |
| 5453 MethodMember.prototype.canInvoke = function(context, args) { |
| 5454 var bareCount = args.get$bareCount(); |
| 5455 if (bareCount > this.parameters.length) return false; |
| 5456 if (bareCount == this.parameters.length) { |
| 5457 if (bareCount != args.get$length()) return false; |
| 5458 } |
| 5459 else { |
| 5460 if (!this.parameters.$index(bareCount).get$isOptional()) return false; |
| 5461 for (var i = bareCount; |
| 5462 i < args.get$length(); i++) { |
| 5463 if (this.indexOfParameter(args.getName(i)) < 0) { |
| 5464 return false; |
| 5465 } |
| 5466 } |
| 5467 } |
| 5468 return true; |
| 5469 } |
| 5470 MethodMember.prototype.indexOfParameter = function(name) { |
| 5471 for (var i = 0; |
| 5472 i < this.parameters.length; i++) { |
| 5473 var p = this.parameters.$index(i); |
| 5474 if (p.get$isOptional() && $eq(p.get$name(), name)) { |
| 5475 return i; |
| 5476 } |
| 5477 } |
| 5478 return -1; |
| 5479 } |
| 5480 MethodMember.prototype.get$prefersPropertySyntax = function() { |
| 5481 return true; |
| 5482 } |
| 5483 MethodMember.prototype.get$requiresFieldSyntax = function() { |
| 5484 return false; |
| 5485 } |
| 5486 MethodMember.prototype.provideFieldSyntax = function() { |
| 5487 this._provideFieldSyntax = true; |
| 5488 } |
| 5489 MethodMember.prototype.providePropertySyntax = function() { |
| 5490 this._providePropertySyntax = true; |
| 5491 } |
| 5492 MethodMember.prototype._set = function(context, node, target, value, isDynamic)
{ |
| 5493 $globals.world.error('cannot set method', node.span); |
| 5494 } |
| 5495 MethodMember.prototype._get = function(context, node, target, isDynamic) { |
| 5496 this.declaringType.genMethod(this); |
| 5497 this._provideOptionalParamInfo = true; |
| 5498 if (this.isStatic) { |
| 5499 this.declaringType.markUsed(); |
| 5500 var type = this.declaringType.get$isTop() ? '' : ('' + this.declaringType.ge
t$jsname() + '.'); |
| 5501 return new Value(this.get$functionType(), ('' + type + this.get$jsname()), n
ode.span, true); |
| 5502 } |
| 5503 this._providePropertySyntax = true; |
| 5504 return new Value(this.get$functionType(), ('' + target.code + '.get\$' + this.
get$jsname() + '()'), node.span, true); |
| 5505 } |
| 5506 MethodMember.prototype.namesInOrder = function(args) { |
| 5507 if (!args.get$hasNames()) return true; |
| 5508 var lastParameter = null; |
| 5509 for (var i = args.get$bareCount(); |
| 5510 i < this.parameters.length; i++) { |
| 5511 var p = args.getIndexOfName(this.parameters.$index(i).get$name()); |
| 5512 if (p >= 0 && args.values.$index(p).get$needsTemp()) { |
| 5513 if (lastParameter != null && lastParameter > p) { |
| 5514 return false; |
| 5515 } |
| 5516 lastParameter = p; |
| 5517 } |
| 5518 } |
| 5519 return true; |
| 5520 } |
| 5521 MethodMember.prototype.needsArgumentConversion = function(args) { |
| 5522 var bareCount = args.get$bareCount(); |
| 5523 for (var i = 0; |
| 5524 i < bareCount; i++) { |
| 5525 var arg = args.values.$index(i); |
| 5526 if (arg.needsConversion$1(this.parameters.$index(i).get$type())) { |
| 5527 return true; |
| 5528 } |
| 5529 } |
| 5530 if (bareCount < this.parameters.length) { |
| 5531 this.genParameterValues(); |
| 5532 for (var i = bareCount; |
| 5533 i < this.parameters.length; i++) { |
| 5534 var arg = args.getValue(this.parameters.$index(i).get$name()); |
| 5535 if (arg != null && arg.needsConversion$1(this.parameters.$index(i).get$typ
e())) { |
| 5536 return true; |
| 5537 } |
| 5538 } |
| 5539 } |
| 5540 return false; |
| 5541 } |
| 5542 MethodMember._argCountMsg = function(actual, expected, atLeast) { |
| 5543 return 'wrong number of positional arguments, expected ' + ('' + (atLeast ? "a
t least " : "") + expected + ' but found ' + actual); |
| 5544 } |
| 5545 MethodMember.prototype._argError = function(context, node, target, args, msg, sp
an) { |
| 5546 if (this.isStatic || this.get$isConstructor()) { |
| 5547 $globals.world.error(msg, span); |
| 5548 } |
| 5549 else { |
| 5550 $globals.world.warning(msg, span); |
| 5551 } |
| 5552 return target.invokeNoSuchMethod(context, this.name, node, args); |
| 5553 } |
| 5554 MethodMember.prototype.genParameterValues = function() { |
| 5555 var $$list = this.parameters; |
| 5556 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5557 var p = $$list.$index($$i); |
| 5558 p.genValue$2(this, this.generator); |
| 5559 } |
| 5560 } |
| 5561 MethodMember.prototype.invoke = function(context, node, target, args, isDynamic)
{ |
| 5562 if (this.parameters == null) { |
| 5563 $globals.world.info(('surprised to need to resolve: ' + this.declaringType.n
ame + '.' + this.name)); |
| 5564 this.resolve(); |
| 5565 } |
| 5566 this.declaringType.genMethod(this); |
| 5567 if (this.isStatic || this.isFactory) { |
| 5568 this.declaringType.markUsed(); |
| 5569 } |
| 5570 if (this.get$isNative() && this.returnType != null) this.returnType.markUsed()
; |
| 5571 if (!this.namesInOrder(args)) { |
| 5572 return context.findMembers(this.name).invokeOnVar(context, node, target, arg
s); |
| 5573 } |
| 5574 var argsCode = []; |
| 5575 if (!target.isType && (this.get$isConstructor() || target.isSuper)) { |
| 5576 argsCode.add$1('this'); |
| 5577 } |
| 5578 var bareCount = args.get$bareCount(); |
| 5579 for (var i = 0; |
| 5580 i < bareCount; i++) { |
| 5581 var arg = args.values.$index(i); |
| 5582 if (i >= this.parameters.length) { |
| 5583 var msg = MethodMember._argCountMsg(args.get$length(), this.parameters.len
gth, false); |
| 5584 return this._argError(context, node, target, args, msg, args.nodes.$index(
i).get$span()); |
| 5585 } |
| 5586 arg = arg.convertTo$4(context, this.parameters.$index(i).get$type(), node, i
sDynamic); |
| 5587 if (this.isConst && arg.get$isConst()) { |
| 5588 argsCode.add$1(arg.get$canonicalCode()); |
| 5589 } |
| 5590 else { |
| 5591 argsCode.add$1(arg.get$code()); |
| 5592 } |
| 5593 } |
| 5594 var namedArgsUsed = 0; |
| 5595 if (bareCount < this.parameters.length) { |
| 5596 this.genParameterValues(); |
| 5597 for (var i = bareCount; |
| 5598 i < this.parameters.length; i++) { |
| 5599 var arg = args.getValue(this.parameters.$index(i).get$name()); |
| 5600 if (arg == null) { |
| 5601 arg = this.parameters.$index(i).get$value(); |
| 5602 } |
| 5603 else { |
| 5604 arg = arg.convertTo$4(context, this.parameters.$index(i).get$type(), nod
e, isDynamic); |
| 5605 namedArgsUsed++; |
| 5606 } |
| 5607 if (arg == null || !this.parameters.$index(i).get$isOptional()) { |
| 5608 var msg = MethodMember._argCountMsg(Math.min(i, args.get$length()), i +
1, true); |
| 5609 return this._argError(context, node, target, args, msg, args.nodes.$inde
x(i).get$span()); |
| 5610 } |
| 5611 else { |
| 5612 argsCode.add$1(this.isConst && arg.get$isConst() ? arg.get$canonicalCode
() : arg.get$code()); |
| 5613 } |
| 5614 } |
| 5615 Arguments.removeTrailingNulls(argsCode); |
| 5616 } |
| 5617 if (namedArgsUsed < args.get$nameCount()) { |
| 5618 var seen = new HashSetImplementation(); |
| 5619 for (var i = bareCount; |
| 5620 i < args.get$length(); i++) { |
| 5621 var name = args.getName(i); |
| 5622 if (seen.contains$1(name)) { |
| 5623 return this._argError(context, node, target, args, ('duplicate argument
"' + name + '"'), args.nodes.$index(i).get$span()); |
| 5624 } |
| 5625 seen.add$1(name); |
| 5626 var p = this.indexOfParameter(name); |
| 5627 if (p < 0) { |
| 5628 return this._argError(context, node, target, args, ('method does not hav
e optional parameter "' + name + '"'), args.nodes.$index(i).get$span()); |
| 5629 } |
| 5630 else if (p < bareCount) { |
| 5631 return this._argError(context, node, target, args, ('argument "' + name
+ '" passed as positional and named'), args.nodes.$index(p).get$span()); |
| 5632 } |
| 5633 } |
| 5634 $globals.world.internalError(('wrong named arguments calling ' + this.name),
node.span); |
| 5635 } |
| 5636 var argsString = Strings.join(argsCode, ', '); |
| 5637 if (this.get$isConstructor()) { |
| 5638 return this._invokeConstructor(context, node, target, args, argsString); |
| 5639 } |
| 5640 if (target.isSuper) { |
| 5641 return new Value(this.get$inferredResult(), ('' + this.declaringType.get$jsn
ame() + '.prototype.' + this.get$jsname() + '.call(' + argsString + ')'), node.s
pan, true); |
| 5642 } |
| 5643 if (this.get$isOperator()) { |
| 5644 return this._invokeBuiltin(context, node, target, args, argsCode, isDynamic)
; |
| 5645 } |
| 5646 if (this.isFactory) { |
| 5647 return new Value(target.get$type(), ('' + this.get$generatedFactoryName() +
'(' + argsString + ')'), node.span, true); |
| 5648 } |
| 5649 if (this.isStatic) { |
| 5650 if (this.declaringType.get$isTop()) { |
| 5651 return new Value(this.get$inferredResult(), ('' + this.get$jsname() + '('
+ argsString + ')'), node != null ? node.span : node, true); |
| 5652 } |
| 5653 return new Value(this.get$inferredResult(), ('' + this.declaringType.get$jsn
ame() + '.' + this.get$jsname() + '(' + argsString + ')'), node.span, true); |
| 5654 } |
| 5655 var code = ('' + target.code + '.' + this.get$jsname() + '(' + argsString + ')
'); |
| 5656 if (target.get$isConst()) { |
| 5657 if ((target instanceof GlobalValue)) { |
| 5658 target = target.get$dynamic().get$exp(); |
| 5659 } |
| 5660 if (this.name == 'get:length') { |
| 5661 if ((target instanceof ConstListValue) || (target instanceof ConstMapValue
)) { |
| 5662 code = ('' + target.get$dynamic().get$values().length); |
| 5663 } |
| 5664 } |
| 5665 else if (this.name == 'isEmpty') { |
| 5666 if ((target instanceof ConstListValue) || (target instanceof ConstMapValue
)) { |
| 5667 code = ('' + target.get$dynamic().get$values().isEmpty$0()); |
| 5668 } |
| 5669 } |
| 5670 } |
| 5671 if (this.name == 'get:typeName' && $eq(this.declaringType.get$library(), $glob
als.world.get$dom())) { |
| 5672 $globals.world.gen.corejs.ensureTypeNameOf(); |
| 5673 } |
| 5674 return new Value(this.get$inferredResult(), code, node.span, true); |
| 5675 } |
| 5676 MethodMember.prototype._invokeConstructor = function(context, node, target, args
, argsString) { |
| 5677 this.declaringType.markUsed(); |
| 5678 if (!target.isType) { |
| 5679 var code = (this.get$constructorName() != '') ? ('' + this.declaringType.get
$jsname() + '.' + this.get$constructorName() + '\$ctor.call(' + argsString + ')'
) : ('' + this.declaringType.get$jsname() + '.call(' + argsString + ')'); |
| 5680 return new Value(target.get$type(), code, node.span, true); |
| 5681 } |
| 5682 else { |
| 5683 var code = (this.get$constructorName() != '') ? ('new ' + this.declaringType
.get$jsname() + '.' + this.get$constructorName() + '\$ctor(' + argsString + ')')
: ('new ' + this.declaringType.get$jsname() + '(' + argsString + ')'); |
| 5684 if (this.isConst && (node instanceof NewExpression) && node.get$dynamic().ge
t$isConst()) { |
| 5685 return this._invokeConstConstructor(node, code, target, args); |
| 5686 } |
| 5687 else { |
| 5688 return new Value(target.get$type(), code, node.span, true); |
| 5689 } |
| 5690 } |
| 5691 } |
| 5692 MethodMember.prototype._invokeConstConstructor = function(node, code, target, ar
gs) { |
| 5693 var fields = new HashMapImplementation(); |
| 5694 for (var i = 0; |
| 5695 i < this.parameters.length; i++) { |
| 5696 var param = this.parameters.$index(i); |
| 5697 if (param.get$isInitializer()) { |
| 5698 var value = null; |
| 5699 if (i < args.get$length()) { |
| 5700 value = args.values.$index(i); |
| 5701 } |
| 5702 else { |
| 5703 value = args.getValue(param.get$name()); |
| 5704 if (value == null) { |
| 5705 value = param.get$value(); |
| 5706 } |
| 5707 } |
| 5708 fields.$setindex(param.get$name(), value); |
| 5709 } |
| 5710 } |
| 5711 if (this.definition.initializers != null) { |
| 5712 this.generator._pushBlock(false); |
| 5713 for (var j = 0; |
| 5714 j < this.definition.formals.length; j++) { |
| 5715 var name = this.definition.formals.$index(j).get$name().get$name(); |
| 5716 var value = null; |
| 5717 if (j < args.get$length()) { |
| 5718 value = args.values.$index(j); |
| 5719 } |
| 5720 else { |
| 5721 value = args.getValue(this.parameters.$index(j).get$name()); |
| 5722 if (value == null) { |
| 5723 value = this.parameters.$index(j).get$value(); |
| 5724 } |
| 5725 } |
| 5726 this.generator._scope._vars.$setindex(name, value); |
| 5727 } |
| 5728 var $$list = this.definition.initializers; |
| 5729 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5730 var init = $$list.$index($$i); |
| 5731 if ((init instanceof CallExpression)) { |
| 5732 var delegateArgs = this.generator._makeArgs(init.get$arguments()); |
| 5733 var value = this.initDelegate.invoke(this.generator, node, target, deleg
ateArgs, false); |
| 5734 if ((init.get$target() instanceof ThisExpression)) { |
| 5735 return value; |
| 5736 } |
| 5737 else { |
| 5738 if ((value instanceof GlobalValue)) { |
| 5739 value = value.get$exp(); |
| 5740 } |
| 5741 var $list0 = value.get$fields().getKeys$0(); |
| 5742 for (var $i0 = value.get$fields().getKeys$0().iterator$0(); $i0.hasNex
t$0(); ) { |
| 5743 var fname = $i0.next$0(); |
| 5744 fields.$setindex(fname, value.get$fields().$index(fname)); |
| 5745 } |
| 5746 } |
| 5747 } |
| 5748 else { |
| 5749 var assign = init; |
| 5750 var x = assign.x; |
| 5751 var fname = x.get$name().get$name(); |
| 5752 var val = this.generator.visitValue(assign.y); |
| 5753 if (!val.get$isConst()) { |
| 5754 $globals.world.error('invalid non-const initializer in const construct
or', assign.y.span); |
| 5755 } |
| 5756 fields.$setindex(fname, val); |
| 5757 } |
| 5758 } |
| 5759 this.generator._popBlock(); |
| 5760 } |
| 5761 var $$list = this.declaringType.get$members().getValues(); |
| 5762 for (var $$i = this.declaringType.get$members().getValues().iterator$0(); $$i.
hasNext$0(); ) { |
| 5763 var f = $$i.next$0(); |
| 5764 if ((f instanceof FieldMember) && !f.get$isStatic() && !fields.containsKey(f
.get$name())) { |
| 5765 if (!f.get$isFinal()) { |
| 5766 $globals.world.error(('const class "' + this.declaringType.name + '" has
non-final ') + ('field "' + f.get$name() + '"'), f.get$span()); |
| 5767 } |
| 5768 if (f.get$value() != null) { |
| 5769 fields.$setindex(f.get$name(), f.computeValue$0()); |
| 5770 } |
| 5771 } |
| 5772 } |
| 5773 return $globals.world.gen.globalForConst(ConstObjectValue.ConstObjectValue$fac
tory(target.get$type(), fields, code, node.span), args.values); |
| 5774 } |
| 5775 MethodMember.prototype._invokeBuiltin = function(context, node, target, args, ar
gsCode, isDynamic) { |
| 5776 var allConst = target.get$isConst() && args.values.every((function (arg) { |
| 5777 return arg.get$isConst(); |
| 5778 }) |
| 5779 ); |
| 5780 if (this.declaringType.get$isNum()) { |
| 5781 if (!allConst) { |
| 5782 var code; |
| 5783 if (this.name == ':negate') { |
| 5784 code = ('-' + target.code); |
| 5785 } |
| 5786 else if (this.name == ':bit_not') { |
| 5787 code = ('~' + target.code); |
| 5788 } |
| 5789 else if (this.name == ':truncdiv' || this.name == ':mod') { |
| 5790 $globals.world.gen.corejs.useOperator(this.name); |
| 5791 code = ('' + this.get$jsname() + '(' + target.code + ', ' + argsCode.$in
dex(0) + ')'); |
| 5792 } |
| 5793 else { |
| 5794 var op = TokenKind.rawOperatorFromMethod(this.name); |
| 5795 code = ('' + target.code + ' ' + op + ' ' + argsCode.$index(0)); |
| 5796 } |
| 5797 return new Value(this.get$inferredResult(), code, node.span, true); |
| 5798 } |
| 5799 else { |
| 5800 var value; |
| 5801 var val0, val1, ival0, ival1; |
| 5802 val0 = target.get$dynamic().get$actualValue(); |
| 5803 ival0 = val0.toInt(); |
| 5804 if (args.values.length > 0) { |
| 5805 val1 = args.values.$index(0).get$dynamic().get$actualValue(); |
| 5806 ival1 = val1.toInt(); |
| 5807 } |
| 5808 switch (this.name) { |
| 5809 case ':negate': |
| 5810 |
| 5811 value = -val0; |
| 5812 break; |
| 5813 |
| 5814 case ':add': |
| 5815 |
| 5816 value = val0 + val1; |
| 5817 break; |
| 5818 |
| 5819 case ':sub': |
| 5820 |
| 5821 value = val0 - val1; |
| 5822 break; |
| 5823 |
| 5824 case ':mul': |
| 5825 |
| 5826 value = val0 * val1; |
| 5827 break; |
| 5828 |
| 5829 case ':div': |
| 5830 |
| 5831 value = val0 / val1; |
| 5832 break; |
| 5833 |
| 5834 case ':truncdiv': |
| 5835 |
| 5836 value = $truncdiv(val0, val1); |
| 5837 break; |
| 5838 |
| 5839 case ':mod': |
| 5840 |
| 5841 value = $mod(val0, val1); |
| 5842 break; |
| 5843 |
| 5844 case ':eq': |
| 5845 |
| 5846 value = val0 == val1; |
| 5847 break; |
| 5848 |
| 5849 case ':lt': |
| 5850 |
| 5851 value = val0 < val1; |
| 5852 break; |
| 5853 |
| 5854 case ':gt': |
| 5855 |
| 5856 value = val0 > val1; |
| 5857 break; |
| 5858 |
| 5859 case ':lte': |
| 5860 |
| 5861 value = val0 <= val1; |
| 5862 break; |
| 5863 |
| 5864 case ':gte': |
| 5865 |
| 5866 value = val0 >= val1; |
| 5867 break; |
| 5868 |
| 5869 case ':ne': |
| 5870 |
| 5871 value = val0 != val1; |
| 5872 break; |
| 5873 |
| 5874 case ':bit_not': |
| 5875 |
| 5876 value = (~ival0).toDouble(); |
| 5877 break; |
| 5878 |
| 5879 case ':bit_or': |
| 5880 |
| 5881 value = (ival0 | ival1).toDouble(); |
| 5882 break; |
| 5883 |
| 5884 case ':bit_xor': |
| 5885 |
| 5886 value = (ival0 ^ ival1).toDouble(); |
| 5887 break; |
| 5888 |
| 5889 case ':bit_and': |
| 5890 |
| 5891 value = (ival0 & ival1).toDouble(); |
| 5892 break; |
| 5893 |
| 5894 case ':shl': |
| 5895 |
| 5896 value = (ival0 << ival1).toDouble(); |
| 5897 break; |
| 5898 |
| 5899 case ':sar': |
| 5900 |
| 5901 value = (ival0 >> ival1).toDouble(); |
| 5902 break; |
| 5903 |
| 5904 case ':shr': |
| 5905 |
| 5906 value = (ival0 >>> ival1).toDouble(); |
| 5907 break; |
| 5908 |
| 5909 } |
| 5910 return EvaluatedValue.EvaluatedValue$factory(this.get$inferredResult(), va
lue, ("" + value), node.span); |
| 5911 } |
| 5912 } |
| 5913 else if (this.declaringType.get$isString()) { |
| 5914 if (this.name == ':index') { |
| 5915 return new Value(this.declaringType, ('' + target.code + '[' + argsCode.$i
ndex(0) + ']'), node.span, true); |
| 5916 } |
| 5917 else if (this.name == ':add') { |
| 5918 if (allConst) { |
| 5919 var value = this._normConcat(target, args.values.$index(0)); |
| 5920 return EvaluatedValue.EvaluatedValue$factory($globals.world.stringType,
value, value, node.span); |
| 5921 } |
| 5922 return new Value(this.declaringType, ('' + target.code + ' + ' + argsCode.
$index(0)), node.span, true); |
| 5923 } |
| 5924 } |
| 5925 else if (this.declaringType.get$isNative()) { |
| 5926 if (this.name == ':index') { |
| 5927 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde
x(0) + ']'), node.span, true); |
| 5928 } |
| 5929 else if (this.name == ':setindex') { |
| 5930 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde
x(0) + '] = ' + argsCode.$index(1)), node.span, true); |
| 5931 } |
| 5932 } |
| 5933 if (this.name == ':eq' || this.name == ':ne') { |
| 5934 var op = this.name == ':eq' ? '==' : '!='; |
| 5935 if (this.name == ':ne') { |
| 5936 target.invoke(context, ':eq', node, args, isDynamic); |
| 5937 } |
| 5938 if (allConst) { |
| 5939 var val0 = target.get$dynamic().get$actualValue(); |
| 5940 var val1 = args.values.$index(0).get$dynamic().get$actualValue(); |
| 5941 var newVal = this.name == ':eq' ? $eq(val0, val1) : $ne(val0, val1); |
| 5942 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, n
ewVal, ("" + newVal), node.span); |
| 5943 } |
| 5944 if ($eq(argsCode.$index(0), 'null')) { |
| 5945 return new Value(this.get$inferredResult(), ('' + target.code + ' ' + op +
' null'), node.span, true); |
| 5946 } |
| 5947 else if (target.get$type().get$isNum() || target.get$type().get$isString())
{ |
| 5948 return new Value(this.get$inferredResult(), ('' + target.code + ' ' + op +
' ' + argsCode.$index(0)), node.span, true); |
| 5949 } |
| 5950 $globals.world.gen.corejs.useOperator(this.name); |
| 5951 return new Value(this.get$inferredResult(), ('' + this.get$jsname() + '(' +
target.code + ', ' + argsCode.$index(0) + ')'), node.span, true); |
| 5952 } |
| 5953 if (this.get$isCallMethod()) { |
| 5954 this.declaringType.markUsed(); |
| 5955 return new Value(this.get$inferredResult(), ('' + target.code + '(' + String
s.join(argsCode, ", ") + ')'), node.span, true); |
| 5956 } |
| 5957 if (this.name == ':index') { |
| 5958 $globals.world.gen.corejs.useIndex = true; |
| 5959 } |
| 5960 else if (this.name == ':setindex') { |
| 5961 $globals.world.gen.corejs.useSetIndex = true; |
| 5962 } |
| 5963 var argsString = Strings.join(argsCode, ', '); |
| 5964 return new Value(this.get$inferredResult(), ('' + target.code + '.' + this.get
$jsname() + '(' + argsString + ')'), node.span, true); |
| 5965 } |
| 5966 MethodMember.prototype._normConcat = function(a, b) { |
| 5967 var val0 = a.get$dynamic().get$actualValue(); |
| 5968 var quote0 = val0.$index(0); |
| 5969 val0 = val0.substring$2(1, val0.length - 1); |
| 5970 var val1 = b.get$dynamic().get$actualValue(); |
| 5971 var quote1 = null; |
| 5972 if (b.get$type().get$isString()) { |
| 5973 quote1 = val1.$index(0); |
| 5974 val1 = val1.substring$2(1, val1.length - 1); |
| 5975 } |
| 5976 var value; |
| 5977 if ($eq(quote0, quote1) || quote1 == null) { |
| 5978 value = ('' + quote0 + val0 + val1 + quote0); |
| 5979 } |
| 5980 else if ($eq(quote0, '"')) { |
| 5981 value = ('' + quote0 + val0 + toDoubleQuote(val1) + quote0); |
| 5982 } |
| 5983 else { |
| 5984 value = ('' + quote1 + toDoubleQuote(val0) + val1 + quote1); |
| 5985 } |
| 5986 return value; |
| 5987 } |
| 5988 MethodMember.prototype.resolve = function() { |
| 5989 this.isStatic = this.declaringType.get$isTop(); |
| 5990 this.isConst = false; |
| 5991 this.isFactory = false; |
| 5992 this.isAbstract = !this.declaringType.get$isClass(); |
| 5993 if (this.definition.modifiers != null) { |
| 5994 var $$list = this.definition.modifiers; |
| 5995 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 5996 var mod = $$list.$index($$i); |
| 5997 if ($eq(mod.get$kind(), 86/*TokenKind.STATIC*/)) { |
| 5998 if (this.isStatic) { |
| 5999 $globals.world.error('duplicate static modifier', mod.get$span()); |
| 6000 } |
| 6001 this.isStatic = true; |
| 6002 } |
| 6003 else if (this.get$isConstructor() && $eq(mod.get$kind(), 92/*TokenKind.CON
ST*/)) { |
| 6004 if (this.isConst) { |
| 6005 $globals.world.error('duplicate const modifier', mod.get$span()); |
| 6006 } |
| 6007 this.isConst = true; |
| 6008 } |
| 6009 else if ($eq(mod.get$kind(), 75/*TokenKind.FACTORY*/)) { |
| 6010 if (this.isFactory) { |
| 6011 $globals.world.error('duplicate factory modifier', mod.get$span()); |
| 6012 } |
| 6013 this.isFactory = true; |
| 6014 } |
| 6015 else if ($eq(mod.get$kind(), 71/*TokenKind.ABSTRACT*/)) { |
| 6016 if (this.isAbstract) { |
| 6017 if (this.declaringType.get$isClass()) { |
| 6018 $globals.world.error('duplicate abstract modifier', mod.get$span()); |
| 6019 } |
| 6020 else { |
| 6021 $globals.world.error('abstract modifier not allowed on interface mem
bers', mod.get$span()); |
| 6022 } |
| 6023 } |
| 6024 this.isAbstract = true; |
| 6025 } |
| 6026 else { |
| 6027 $globals.world.error(('' + mod + ' modifier not allowed on method'), mod
.get$span()); |
| 6028 } |
| 6029 } |
| 6030 } |
| 6031 if (this.isFactory) { |
| 6032 this.isStatic = true; |
| 6033 } |
| 6034 if (this.definition.typeParameters != null) { |
| 6035 if (!this.isFactory) { |
| 6036 $globals.world.error('Only factories are allowed to have explicit type par
ameters', this.definition.typeParameters.$index(0).get$span()); |
| 6037 } |
| 6038 else { |
| 6039 this.typeParameters = this.definition.typeParameters; |
| 6040 var $$list = this.definition.typeParameters; |
| 6041 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6042 var tp = $$list.$index($$i); |
| 6043 tp.set$enclosingElement(this); |
| 6044 tp.resolve$0(); |
| 6045 } |
| 6046 } |
| 6047 } |
| 6048 if (this.get$isOperator() && this.isStatic && !this.get$isCallMethod()) { |
| 6049 $globals.world.error(('operator method may not be static "' + this.name + '"
'), this.get$span()); |
| 6050 } |
| 6051 if (this.isAbstract) { |
| 6052 if (this.definition.body != null && !(this.declaringType.get$definition() in
stanceof FunctionTypeDefinition)) { |
| 6053 $globals.world.error('abstract method can not have a body', this.get$span(
)); |
| 6054 } |
| 6055 if (this.isStatic && !(this.declaringType.get$definition() instanceof Functi
onTypeDefinition)) { |
| 6056 $globals.world.error('static method can not be abstract', this.get$span())
; |
| 6057 } |
| 6058 } |
| 6059 else { |
| 6060 if (this.definition.body == null && !this.get$isConstructor() && !this.get$i
sNative()) { |
| 6061 $globals.world.error('method needs a body', this.get$span()); |
| 6062 } |
| 6063 } |
| 6064 if (this.get$isConstructor() && !this.isFactory) { |
| 6065 this.returnType = this.declaringType; |
| 6066 } |
| 6067 else { |
| 6068 this.returnType = this.resolveType(this.definition.returnType, false); |
| 6069 } |
| 6070 this.parameters = []; |
| 6071 var $$list = this.definition.formals; |
| 6072 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6073 var formal = $$list.$index($$i); |
| 6074 var param = new Parameter(formal, this); |
| 6075 param.resolve$0(); |
| 6076 this.parameters.add(param); |
| 6077 } |
| 6078 if (!this.isLambda) { |
| 6079 this.get$library()._addMember(this); |
| 6080 } |
| 6081 } |
| 6082 MethodMember.prototype.resolveType = function(node, typeErrors) { |
| 6083 var t = Element.prototype.resolveType.call(this, node, typeErrors); |
| 6084 if (this.isStatic && (t instanceof ParameterType) && (this.typeParameters == n
ull || !this.typeParameters.some((function (p) { |
| 6085 return p === t; |
| 6086 }) |
| 6087 ))) { |
| 6088 $globals.world.error('using type parameter in static context.', node.span); |
| 6089 } |
| 6090 return t; |
| 6091 } |
| 6092 MethodMember.prototype._get$3 = function($0, $1, $2) { |
| 6093 return this._get($0, $1, $2, false); |
| 6094 }; |
| 6095 MethodMember.prototype._get$3$isDynamic = MethodMember.prototype._get; |
| 6096 MethodMember.prototype._get$4 = MethodMember.prototype._get; |
| 6097 MethodMember.prototype._set$4 = function($0, $1, $2, $3) { |
| 6098 return this._set($0, $1, $2, $3, false); |
| 6099 }; |
| 6100 MethodMember.prototype._set$4$isDynamic = MethodMember.prototype._set; |
| 6101 MethodMember.prototype._set$5 = MethodMember.prototype._set; |
| 6102 MethodMember.prototype.canInvoke$2 = MethodMember.prototype.canInvoke; |
| 6103 MethodMember.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 6104 return this.invoke($0, $1, $2, $3, false); |
| 6105 }; |
| 6106 MethodMember.prototype.invoke$4$isDynamic = MethodMember.prototype.invoke; |
| 6107 MethodMember.prototype.invoke$5 = MethodMember.prototype.invoke; |
| 6108 MethodMember.prototype.namesInOrder$1 = MethodMember.prototype.namesInOrder; |
| 6109 MethodMember.prototype.provideFieldSyntax$0 = MethodMember.prototype.provideFiel
dSyntax; |
| 6110 MethodMember.prototype.providePropertySyntax$0 = MethodMember.prototype.provideP
ropertySyntax; |
| 6111 MethodMember.prototype.resolve$0 = MethodMember.prototype.resolve; |
| 6112 // ********** Code for MemberSet ************** |
| 6113 function MemberSet(member, isVar) { |
| 6114 this.name = member.name; |
| 6115 this.members = [member]; |
| 6116 this.jsname = member.get$jsname(); |
| 6117 this.isVar = isVar; |
| 6118 // Initializers done |
| 6119 } |
| 6120 MemberSet.prototype.get$name = function() { return this.name; }; |
| 6121 MemberSet.prototype.get$members = function() { return this.members; }; |
| 6122 MemberSet.prototype.get$jsname = function() { return this.jsname; }; |
| 6123 MemberSet.prototype.get$isVar = function() { return this.isVar; }; |
| 6124 MemberSet.prototype.toString = function() { |
| 6125 return ('' + this.name + ':' + this.members.length); |
| 6126 } |
| 6127 MemberSet.prototype.get$containsMethods = function() { |
| 6128 return this.members.some((function (m) { |
| 6129 return (m instanceof MethodMember); |
| 6130 }) |
| 6131 ); |
| 6132 } |
| 6133 MemberSet.prototype.add = function(member) { |
| 6134 return this.members.add(member); |
| 6135 } |
| 6136 MemberSet.prototype.get$isStatic = function() { |
| 6137 return this.members.length == 1 && this.members.$index(0).get$isStatic(); |
| 6138 } |
| 6139 MemberSet.prototype.get$isOperator = function() { |
| 6140 return this.members.$index(0).get$isOperator(); |
| 6141 } |
| 6142 MemberSet.prototype.canInvoke = function(context, args) { |
| 6143 return this.members.some((function (m) { |
| 6144 return m.canInvoke$2(context, args); |
| 6145 }) |
| 6146 ); |
| 6147 } |
| 6148 MemberSet.prototype._makeError = function(node, target, action) { |
| 6149 if (!target.get$type().get$isVar()) { |
| 6150 $globals.world.warning(('could not find applicable ' + action + ' for "' + t
his.name + '"'), node.span); |
| 6151 } |
| 6152 return new Value($globals.world.varType, ('' + target.code + '.' + this.jsname
+ '() /*no applicable ' + action + '*/'), node.span, true); |
| 6153 } |
| 6154 MemberSet.prototype.get$treatAsField = function() { |
| 6155 if (this._treatAsField == null) { |
| 6156 this._treatAsField = !this.isVar; |
| 6157 var $$list = this.members; |
| 6158 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6159 var member = $$list.$index($$i); |
| 6160 if (member.get$requiresFieldSyntax()) { |
| 6161 this._treatAsField = true; |
| 6162 break; |
| 6163 } |
| 6164 if (member.get$prefersPropertySyntax()) { |
| 6165 this._treatAsField = false; |
| 6166 } |
| 6167 } |
| 6168 var $$list = this.members; |
| 6169 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 6170 var member = $$list.$index($$i); |
| 6171 if (this._treatAsField) { |
| 6172 member.provideFieldSyntax$0(); |
| 6173 } |
| 6174 else { |
| 6175 member.providePropertySyntax$0(); |
| 6176 } |
| 6177 } |
| 6178 } |
| 6179 return this._treatAsField; |
| 6180 } |
| 6181 MemberSet.prototype._get = function(context, node, target, isDynamic) { |
| 6182 var returnValue; |
| 6183 var targets = this.members.filter((function (m) { |
| 6184 return m.get$canGet(); |
| 6185 }) |
| 6186 ); |
| 6187 if (this.isVar) { |
| 6188 targets.forEach$1((function (m) { |
| 6189 return m._get$3$isDynamic(context, node, target, true); |
| 6190 }) |
| 6191 ); |
| 6192 returnValue = new Value(this._foldTypes(targets), null, node.span, true); |
| 6193 } |
| 6194 else { |
| 6195 if (this.members.length == 1) { |
| 6196 return this.members.$index(0)._get$4(context, node, target, isDynamic); |
| 6197 } |
| 6198 else if ($eq(targets.length, 1)) { |
| 6199 return targets.$index(0)._get$4(context, node, target, isDynamic); |
| 6200 } |
| 6201 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 6202 var member = $$i.next$0(); |
| 6203 var value = member._get$3$isDynamic(context, node, target, true); |
| 6204 returnValue = this._tryUnion(returnValue, value, node); |
| 6205 } |
| 6206 if (returnValue == null) { |
| 6207 return this._makeError(node, target, 'getter'); |
| 6208 } |
| 6209 } |
| 6210 if (returnValue.code == null) { |
| 6211 if (this.get$treatAsField()) { |
| 6212 return new Value(returnValue.get$type(), ('' + target.code + '.' + this.js
name), node.span, true); |
| 6213 } |
| 6214 else { |
| 6215 return new Value(returnValue.get$type(), ('' + target.code + '.get\$' + th
is.jsname + '()'), node.span, true); |
| 6216 } |
| 6217 } |
| 6218 return returnValue; |
| 6219 } |
| 6220 MemberSet.prototype._set = function(context, node, target, value, isDynamic) { |
| 6221 var returnValue; |
| 6222 var targets = this.members.filter((function (m) { |
| 6223 return m.get$canSet(); |
| 6224 }) |
| 6225 ); |
| 6226 if (this.isVar) { |
| 6227 targets.forEach$1((function (m) { |
| 6228 return m._set$4$isDynamic(context, node, target, value, true); |
| 6229 }) |
| 6230 ); |
| 6231 returnValue = new Value(this._foldTypes(targets), null, node.span, true); |
| 6232 } |
| 6233 else { |
| 6234 if (this.members.length == 1) { |
| 6235 return this.members.$index(0)._set$5(context, node, target, value, isDynam
ic); |
| 6236 } |
| 6237 else if ($eq(targets.length, 1)) { |
| 6238 return targets.$index(0)._set$5(context, node, target, value, isDynamic); |
| 6239 } |
| 6240 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 6241 var member = $$i.next$0(); |
| 6242 var res = member._set$4$isDynamic(context, node, target, value, true); |
| 6243 returnValue = this._tryUnion(returnValue, res, node); |
| 6244 } |
| 6245 if (returnValue == null) { |
| 6246 return this._makeError(node, target, 'setter'); |
| 6247 } |
| 6248 } |
| 6249 if (returnValue.code == null) { |
| 6250 if (this.get$treatAsField()) { |
| 6251 return new Value(returnValue.get$type(), ('' + target.code + '.' + this.js
name + ' = ' + value.code), node.span, true); |
| 6252 } |
| 6253 else { |
| 6254 return new Value(returnValue.get$type(), ('' + target.code + '.set\$' + th
is.jsname + '(' + value.code + ')'), node.span, true); |
| 6255 } |
| 6256 } |
| 6257 return returnValue; |
| 6258 } |
| 6259 MemberSet.prototype.invoke = function(context, node, target, args, isDynamic) { |
| 6260 if (this.isVar && !this.get$isOperator()) { |
| 6261 return this.invokeOnVar(context, node, target, args); |
| 6262 } |
| 6263 if (this.members.length == 1) { |
| 6264 return this.members.$index(0).invoke$5(context, node, target, args, isDynami
c); |
| 6265 } |
| 6266 var targets = this.members.filter((function (m) { |
| 6267 return m.canInvoke$2(context, args); |
| 6268 }) |
| 6269 ); |
| 6270 if ($eq(targets.length, 1)) { |
| 6271 return targets.$index(0).invoke$5(context, node, target, args, isDynamic); |
| 6272 } |
| 6273 var returnValue = null; |
| 6274 for (var $$i = targets.iterator$0(); $$i.hasNext$0(); ) { |
| 6275 var member = $$i.next$0(); |
| 6276 var res = member.invoke$4$isDynamic(context, node, target, args, true); |
| 6277 returnValue = this._tryUnion(returnValue, res, node); |
| 6278 } |
| 6279 if (returnValue == null) { |
| 6280 return this._makeError(node, target, 'method'); |
| 6281 } |
| 6282 if (returnValue.code == null) { |
| 6283 if (this.name == ':call') { |
| 6284 return target._varCall(context, args); |
| 6285 } |
| 6286 else if (this.get$isOperator()) { |
| 6287 return this.invokeSpecial(target, args, returnValue.get$type()); |
| 6288 } |
| 6289 else { |
| 6290 return this.invokeOnVar(context, node, target, args); |
| 6291 } |
| 6292 } |
| 6293 return returnValue; |
| 6294 } |
| 6295 MemberSet.prototype.invokeSpecial = function(target, args, returnType) { |
| 6296 var argsString = args.getCode(); |
| 6297 if (this.name == ':index' || this.name == ':setindex') { |
| 6298 return new Value(returnType, ('' + target.code + '.' + this.jsname + '(' + a
rgsString + ')'), target.span, true); |
| 6299 } |
| 6300 else { |
| 6301 if (argsString.length > 0) argsString = (', ' + argsString); |
| 6302 $globals.world.gen.corejs.useOperator(this.name); |
| 6303 return new Value(returnType, ('' + this.jsname + '(' + target.code + argsStr
ing + ')'), target.span, true); |
| 6304 } |
| 6305 } |
| 6306 MemberSet.prototype.invokeOnVar = function(context, node, target, args) { |
| 6307 var member = this.getVarMember(context, node, args); |
| 6308 return member.invoke$4(context, node, target, args); |
| 6309 } |
| 6310 MemberSet.prototype._tryUnion = function(x, y, node) { |
| 6311 if (x == null) return y; |
| 6312 var type = Type.union(x.get$type(), y.get$type()); |
| 6313 if (x.code == y.code) { |
| 6314 if ($eq(type, x.get$type())) { |
| 6315 return x; |
| 6316 } |
| 6317 else if (x.get$isConst() || y.get$isConst()) { |
| 6318 $globals.world.internalError("unexpected: union of const values "); |
| 6319 } |
| 6320 else { |
| 6321 var ret = new Value(type, x.code, node.span, true); |
| 6322 ret.set$isSuper(x.isSuper && y.isSuper); |
| 6323 ret.set$needsTemp(x.needsTemp || y.needsTemp); |
| 6324 ret.set$isType(x.isType && y.isType); |
| 6325 return ret; |
| 6326 } |
| 6327 } |
| 6328 else { |
| 6329 return new Value(type, null, node.span, true); |
| 6330 } |
| 6331 } |
| 6332 MemberSet.prototype.getVarMember = function(context, node, args) { |
| 6333 if ($globals.world.objectType.varStubs == null) { |
| 6334 $globals.world.objectType.varStubs = new HashMapImplementation(); |
| 6335 } |
| 6336 var stubName = _getCallStubName(this.name, args); |
| 6337 var stub = $globals.world.objectType.varStubs.$index(stubName); |
| 6338 if (stub == null) { |
| 6339 var mset = context.findMembers(this.name).members; |
| 6340 var targets = mset.filter((function (m) { |
| 6341 return m.canInvoke$2(context, args); |
| 6342 }) |
| 6343 ); |
| 6344 stub = new VarMethodSet(this.name, stubName, targets, args, this._foldTypes(
targets)); |
| 6345 $globals.world.objectType.varStubs.$setindex(stubName, stub); |
| 6346 } |
| 6347 return stub; |
| 6348 } |
| 6349 MemberSet.prototype._foldTypes = function(targets) { |
| 6350 return reduce(map(targets, (function (t) { |
| 6351 return t.get$returnType(); |
| 6352 }) |
| 6353 ), Type.union, $globals.world.varType); |
| 6354 } |
| 6355 MemberSet.prototype._get$3 = function($0, $1, $2) { |
| 6356 return this._get($0, $1, $2, false); |
| 6357 }; |
| 6358 MemberSet.prototype._get$3$isDynamic = MemberSet.prototype._get; |
| 6359 MemberSet.prototype._get$4 = MemberSet.prototype._get; |
| 6360 MemberSet.prototype._set$4 = function($0, $1, $2, $3) { |
| 6361 return this._set($0, $1, $2, $3, false); |
| 6362 }; |
| 6363 MemberSet.prototype._set$4$isDynamic = MemberSet.prototype._set; |
| 6364 MemberSet.prototype._set$5 = MemberSet.prototype._set; |
| 6365 MemberSet.prototype.add$1 = MemberSet.prototype.add; |
| 6366 MemberSet.prototype.canInvoke$2 = MemberSet.prototype.canInvoke; |
| 6367 MemberSet.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 6368 return this.invoke($0, $1, $2, $3, false); |
| 6369 }; |
| 6370 MemberSet.prototype.invoke$4$isDynamic = MemberSet.prototype.invoke; |
| 6371 MemberSet.prototype.invoke$5 = MemberSet.prototype.invoke; |
| 6372 MemberSet.prototype.toString$0 = MemberSet.prototype.toString; |
| 6373 // ********** Code for FactoryMap ************** |
| 6374 function FactoryMap() { |
| 6375 this.factories = new HashMapImplementation(); |
| 6376 // Initializers done |
| 6377 } |
| 6378 FactoryMap.prototype.getFactoriesFor = function(typeName) { |
| 6379 var ret = this.factories.$index(typeName); |
| 6380 if (ret == null) { |
| 6381 ret = new HashMapImplementation(); |
| 6382 this.factories.$setindex(typeName, ret); |
| 6383 } |
| 6384 return ret; |
| 6385 } |
| 6386 FactoryMap.prototype.addFactory = function(typeName, name, member) { |
| 6387 this.getFactoriesFor(typeName).$setindex(name, member); |
| 6388 } |
| 6389 FactoryMap.prototype.getFactory = function(typeName, name) { |
| 6390 return this.getFactoriesFor(typeName).$index(name); |
| 6391 } |
| 6392 FactoryMap.prototype.forEach = function(f) { |
| 6393 this.factories.forEach((function (_, constructors) { |
| 6394 constructors.forEach((function (_, member) { |
| 6395 f(member); |
| 6396 }) |
| 6397 ); |
| 6398 }) |
| 6399 ); |
| 6400 } |
| 6401 FactoryMap.prototype.forEach$1 = function($0) { |
| 6402 return this.forEach(to$call$1($0)); |
| 6403 }; |
| 6404 FactoryMap.prototype.getFactory$2 = FactoryMap.prototype.getFactory; |
| 6405 // ********** Code for Token ************** |
| 6406 function Token(kind, source, start, end) { |
| 6407 this.kind = kind; |
| 6408 this.source = source; |
| 6409 this.start = start; |
| 6410 this.end = end; |
| 6411 // Initializers done |
| 6412 } |
| 6413 Token.prototype.get$kind = function() { return this.kind; }; |
| 6414 Token.prototype.get$end = function() { return this.end; }; |
| 6415 Token.prototype.get$start = function() { return this.start; }; |
| 6416 Token.prototype.get$text = function() { |
| 6417 return this.source.get$text().substring(this.start, this.end); |
| 6418 } |
| 6419 Token.prototype.toString = function() { |
| 6420 var kindText = TokenKind.kindToString(this.kind); |
| 6421 var actualText = this.get$text(); |
| 6422 if ($ne(kindText, actualText)) { |
| 6423 if (actualText.length > 10) { |
| 6424 actualText = actualText.substring$2(0, 8) + '...'; |
| 6425 } |
| 6426 return ('' + kindText + '(' + actualText + ')'); |
| 6427 } |
| 6428 else { |
| 6429 return kindText; |
| 6430 } |
| 6431 } |
| 6432 Token.prototype.get$span = function() { |
| 6433 return new SourceSpan(this.source, this.start, this.end); |
| 6434 } |
| 6435 Token.prototype.end$0 = function() { |
| 6436 return this.end(); |
| 6437 }; |
| 6438 Token.prototype.start$0 = function() { |
| 6439 return this.start(); |
| 6440 }; |
| 6441 Token.prototype.toString$0 = Token.prototype.toString; |
| 6442 // ********** Code for ErrorToken ************** |
| 6443 $inherits(ErrorToken, Token); |
| 6444 function ErrorToken(kind, source, start, end, message) { |
| 6445 this.message = message; |
| 6446 // Initializers done |
| 6447 Token.call(this, kind, source, start, end); |
| 6448 } |
| 6449 ErrorToken.prototype.get$message = function() { return this.message; }; |
| 6450 ErrorToken.prototype.set$message = function(value) { return this.message = value
; }; |
| 6451 // ********** Code for SourceFile ************** |
| 6452 function SourceFile(filename, _text) { |
| 6453 this.filename = filename; |
| 6454 this._text = _text; |
| 6455 // Initializers done |
| 6456 } |
| 6457 SourceFile.prototype.get$filename = function() { return this.filename; }; |
| 6458 SourceFile.prototype.get$orderInLibrary = function() { return this.orderInLibrar
y; }; |
| 6459 SourceFile.prototype.set$orderInLibrary = function(value) { return this.orderInL
ibrary = value; }; |
| 6460 SourceFile.prototype.get$text = function() { |
| 6461 return this._text; |
| 6462 } |
| 6463 SourceFile.prototype.get$lineStarts = function() { |
| 6464 if (this._lineStarts == null) { |
| 6465 var starts = [0]; |
| 6466 var index = 0; |
| 6467 while (index < this.get$text().length) { |
| 6468 index = this.get$text().indexOf('\n', index) + 1; |
| 6469 if (index <= 0) break; |
| 6470 starts.add$1(index); |
| 6471 } |
| 6472 starts.add$1(this.get$text().length + 1); |
| 6473 this._lineStarts = starts; |
| 6474 } |
| 6475 return this._lineStarts; |
| 6476 } |
| 6477 SourceFile.prototype.getLine = function(position) { |
| 6478 var starts = this.get$lineStarts(); |
| 6479 for (var i = 0; |
| 6480 i < starts.length; i++) { |
| 6481 if (starts.$index(i) > position) return i - 1; |
| 6482 } |
| 6483 $globals.world.internalError('bad position'); |
| 6484 } |
| 6485 SourceFile.prototype.getColumn = function(line, position) { |
| 6486 return position - this.get$lineStarts().$index(line); |
| 6487 } |
| 6488 SourceFile.prototype.getLocationMessage = function(message, start, end, includeT
ext) { |
| 6489 var line = this.getLine(start); |
| 6490 var column = this.getColumn(line, start); |
| 6491 var buf = new StringBufferImpl(('' + this.filename + ':' + (line + 1) + ':' +
(column + 1) + ': ' + message)); |
| 6492 if (includeText) { |
| 6493 buf.add$1('\n'); |
| 6494 var textLine; |
| 6495 if ((line + 2) < this._lineStarts.length) { |
| 6496 textLine = this.get$text().substring(this._lineStarts.$index(line), this._
lineStarts.$index(line + 1)); |
| 6497 } |
| 6498 else { |
| 6499 textLine = this.get$text().substring(this._lineStarts.$index(line)) + '\n'
; |
| 6500 } |
| 6501 var toColumn = Math.min(column + (end - start), textLine.length); |
| 6502 if ($globals.options.useColors) { |
| 6503 buf.add$1(textLine.substring$2(0, column)); |
| 6504 buf.add$1($globals._RED_COLOR); |
| 6505 buf.add$1(textLine.substring$2(column, toColumn)); |
| 6506 buf.add$1($globals._NO_COLOR); |
| 6507 buf.add$1(textLine.substring$1(toColumn)); |
| 6508 } |
| 6509 else { |
| 6510 buf.add$1(textLine); |
| 6511 } |
| 6512 var i = 0; |
| 6513 for (; i < column; i++) { |
| 6514 buf.add$1(' '); |
| 6515 } |
| 6516 if ($globals.options.useColors) buf.add$1($globals._RED_COLOR); |
| 6517 for (; i < toColumn; i++) { |
| 6518 buf.add$1('^'); |
| 6519 } |
| 6520 if ($globals.options.useColors) buf.add$1($globals._NO_COLOR); |
| 6521 } |
| 6522 return buf.toString$0(); |
| 6523 } |
| 6524 SourceFile.prototype.compareTo = function(other) { |
| 6525 if (this.orderInLibrary != null && other.orderInLibrary != null) { |
| 6526 return this.orderInLibrary - other.orderInLibrary; |
| 6527 } |
| 6528 else { |
| 6529 return this.filename.compareTo(other.filename); |
| 6530 } |
| 6531 } |
| 6532 SourceFile.prototype.compareTo$1 = SourceFile.prototype.compareTo; |
| 6533 SourceFile.prototype.getColumn$2 = SourceFile.prototype.getColumn; |
| 6534 SourceFile.prototype.getLine$1 = SourceFile.prototype.getLine; |
| 6535 // ********** Code for SourceSpan ************** |
| 6536 function SourceSpan(file, start, end) { |
| 6537 this.file = file; |
| 6538 this.start = start; |
| 6539 this.end = end; |
| 6540 // Initializers done |
| 6541 } |
| 6542 SourceSpan.prototype.get$file = function() { return this.file; }; |
| 6543 SourceSpan.prototype.get$start = function() { return this.start; }; |
| 6544 SourceSpan.prototype.get$end = function() { return this.end; }; |
| 6545 SourceSpan.prototype.get$text = function() { |
| 6546 return this.file.get$text().substring(this.start, this.end); |
| 6547 } |
| 6548 SourceSpan.prototype.toMessageString = function(message) { |
| 6549 return this.file.getLocationMessage(message, this.start, this.end, true); |
| 6550 } |
| 6551 SourceSpan.prototype.get$locationText = function() { |
| 6552 var line = this.file.getLine(this.start); |
| 6553 var column = this.file.getColumn(line, this.start); |
| 6554 return ('' + this.file.filename + ':' + (line + 1) + ':' + (column + 1)); |
| 6555 } |
| 6556 SourceSpan.prototype.compareTo = function(other) { |
| 6557 if ($eq(this.file, other.file)) { |
| 6558 var d = this.start - other.start; |
| 6559 return d == 0 ? (this.end - other.end) : d; |
| 6560 } |
| 6561 return this.file.compareTo(other.file); |
| 6562 } |
| 6563 SourceSpan.prototype.compareTo$1 = SourceSpan.prototype.compareTo; |
| 6564 SourceSpan.prototype.end$0 = function() { |
| 6565 return this.end(); |
| 6566 }; |
| 6567 SourceSpan.prototype.start$0 = function() { |
| 6568 return this.start(); |
| 6569 }; |
| 6570 // ********** Code for InterpStack ************** |
| 6571 function InterpStack(previous, quote, isMultiline) { |
| 6572 this.previous = previous; |
| 6573 this.quote = quote; |
| 6574 this.isMultiline = isMultiline; |
| 6575 this.depth = -1; |
| 6576 // Initializers done |
| 6577 } |
| 6578 InterpStack.prototype.get$previous = function() { return this.previous; }; |
| 6579 InterpStack.prototype.set$previous = function(value) { return this.previous = va
lue; }; |
| 6580 InterpStack.prototype.get$quote = function() { return this.quote; }; |
| 6581 InterpStack.prototype.get$isMultiline = function() { return this.isMultiline; }; |
| 6582 InterpStack.prototype.get$depth = function() { return this.depth; }; |
| 6583 InterpStack.prototype.set$depth = function(value) { return this.depth = value; }
; |
| 6584 InterpStack.prototype.pop = function() { |
| 6585 return this.previous; |
| 6586 } |
| 6587 InterpStack.push = function(stack, quote, isMultiline) { |
| 6588 var newStack = new InterpStack(stack, quote, isMultiline); |
| 6589 if (stack != null) newStack.set$previous(stack); |
| 6590 return newStack; |
| 6591 } |
| 6592 InterpStack.prototype.next$0 = function() { |
| 6593 return this.next(); |
| 6594 }; |
| 6595 // ********** Code for TokenizerHelpers ************** |
| 6596 function TokenizerHelpers() { |
| 6597 // Initializers done |
| 6598 } |
| 6599 TokenizerHelpers.isIdentifierStart = function(c) { |
| 6600 return ((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c == 95); |
| 6601 } |
| 6602 TokenizerHelpers.isDigit = function(c) { |
| 6603 return (c >= 48 && c <= 57); |
| 6604 } |
| 6605 TokenizerHelpers.isHexDigit = function(c) { |
| 6606 return (TokenizerHelpers.isDigit(c) || (c >= 97 && c <= 102) || (c >= 65 && c
<= 70)); |
| 6607 } |
| 6608 TokenizerHelpers.isIdentifierPart = function(c) { |
| 6609 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c) |
| c == 36); |
| 6610 } |
| 6611 TokenizerHelpers.isInterpIdentifierPart = function(c) { |
| 6612 return (TokenizerHelpers.isIdentifierStart(c) || TokenizerHelpers.isDigit(c)); |
| 6613 } |
| 6614 // ********** Code for TokenizerBase ************** |
| 6615 $inherits(TokenizerBase, TokenizerHelpers); |
| 6616 function TokenizerBase(_source, _skipWhitespace, index) { |
| 6617 this._source = _source; |
| 6618 this._skipWhitespace = _skipWhitespace; |
| 6619 this._index = index; |
| 6620 // Initializers done |
| 6621 TokenizerHelpers.call(this); |
| 6622 this._text = this._source.get$text(); |
| 6623 } |
| 6624 TokenizerBase.prototype._nextChar = function() { |
| 6625 if (this._index < this._text.length) { |
| 6626 return this._text.charCodeAt(this._index++); |
| 6627 } |
| 6628 else { |
| 6629 return 0; |
| 6630 } |
| 6631 } |
| 6632 TokenizerBase.prototype._peekChar = function() { |
| 6633 if (this._index < this._text.length) { |
| 6634 return this._text.charCodeAt(this._index); |
| 6635 } |
| 6636 else { |
| 6637 return 0; |
| 6638 } |
| 6639 } |
| 6640 TokenizerBase.prototype._maybeEatChar = function(ch) { |
| 6641 if (this._index < this._text.length) { |
| 6642 if (this._text.charCodeAt(this._index) == ch) { |
| 6643 this._index++; |
| 6644 return true; |
| 6645 } |
| 6646 else { |
| 6647 return false; |
| 6648 } |
| 6649 } |
| 6650 else { |
| 6651 return false; |
| 6652 } |
| 6653 } |
| 6654 TokenizerBase.prototype._finishToken = function(kind) { |
| 6655 return new Token(kind, this._source, this._startIndex, this._index); |
| 6656 } |
| 6657 TokenizerBase.prototype._errorToken = function(message) { |
| 6658 return new ErrorToken(65/*TokenKind.ERROR*/, this._source, this._startIndex, t
his._index, message); |
| 6659 } |
| 6660 TokenizerBase.prototype.finishWhitespace = function() { |
| 6661 this._index--; |
| 6662 while (this._index < this._text.length) { |
| 6663 var ch = this._text.charCodeAt(this._index++); |
| 6664 if (ch == 32 || ch == 9 || ch == 13) { |
| 6665 } |
| 6666 else if (ch == 10) { |
| 6667 if (!this._skipWhitespace) { |
| 6668 return this._finishToken(63/*TokenKind.WHITESPACE*/); |
| 6669 } |
| 6670 } |
| 6671 else { |
| 6672 this._index--; |
| 6673 if (this._skipWhitespace) { |
| 6674 return this.next(); |
| 6675 } |
| 6676 else { |
| 6677 return this._finishToken(63/*TokenKind.WHITESPACE*/); |
| 6678 } |
| 6679 } |
| 6680 } |
| 6681 return this._finishToken(1/*TokenKind.END_OF_FILE*/); |
| 6682 } |
| 6683 TokenizerBase.prototype.finishHashBang = function() { |
| 6684 while (true) { |
| 6685 var ch = this._nextChar(); |
| 6686 if (ch == 0 || ch == 10 || ch == 13) { |
| 6687 return this._finishToken(13/*TokenKind.HASHBANG*/); |
| 6688 } |
| 6689 } |
| 6690 } |
| 6691 TokenizerBase.prototype.finishSingleLineComment = function() { |
| 6692 while (true) { |
| 6693 var ch = this._nextChar(); |
| 6694 if (ch == 0 || ch == 10 || ch == 13) { |
| 6695 if (this._skipWhitespace) { |
| 6696 return this.next(); |
| 6697 } |
| 6698 else { |
| 6699 return this._finishToken(64/*TokenKind.COMMENT*/); |
| 6700 } |
| 6701 } |
| 6702 } |
| 6703 } |
| 6704 TokenizerBase.prototype.finishMultiLineComment = function() { |
| 6705 while (true) { |
| 6706 var ch = this._nextChar(); |
| 6707 if (ch == 0) { |
| 6708 return this._finishToken(67/*TokenKind.INCOMPLETE_COMMENT*/); |
| 6709 } |
| 6710 else if (ch == 42) { |
| 6711 if (this._maybeEatChar(47)) { |
| 6712 if (this._skipWhitespace) { |
| 6713 return this.next(); |
| 6714 } |
| 6715 else { |
| 6716 return this._finishToken(64/*TokenKind.COMMENT*/); |
| 6717 } |
| 6718 } |
| 6719 } |
| 6720 } |
| 6721 return this._errorToken(); |
| 6722 } |
| 6723 TokenizerBase.prototype.eatDigits = function() { |
| 6724 while (this._index < this._text.length) { |
| 6725 if (TokenizerHelpers.isDigit(this._text.charCodeAt(this._index))) { |
| 6726 this._index++; |
| 6727 } |
| 6728 else { |
| 6729 return; |
| 6730 } |
| 6731 } |
| 6732 } |
| 6733 TokenizerBase.prototype.eatHexDigits = function() { |
| 6734 while (this._index < this._text.length) { |
| 6735 if (TokenizerHelpers.isHexDigit(this._text.charCodeAt(this._index))) { |
| 6736 this._index++; |
| 6737 } |
| 6738 else { |
| 6739 return; |
| 6740 } |
| 6741 } |
| 6742 } |
| 6743 TokenizerBase.prototype.maybeEatHexDigit = function() { |
| 6744 if (this._index < this._text.length && TokenizerHelpers.isHexDigit(this._text.
charCodeAt(this._index))) { |
| 6745 this._index++; |
| 6746 return true; |
| 6747 } |
| 6748 return false; |
| 6749 } |
| 6750 TokenizerBase.prototype.finishHex = function() { |
| 6751 this.eatHexDigits(); |
| 6752 return this._finishToken(61/*TokenKind.HEX_INTEGER*/); |
| 6753 } |
| 6754 TokenizerBase.prototype.finishNumber = function() { |
| 6755 this.eatDigits(); |
| 6756 if (this._peekChar() == 46) { |
| 6757 this._nextChar(); |
| 6758 if (TokenizerHelpers.isDigit(this._peekChar())) { |
| 6759 this.eatDigits(); |
| 6760 return this.finishNumberExtra(62/*TokenKind.DOUBLE*/); |
| 6761 } |
| 6762 else { |
| 6763 this._index--; |
| 6764 } |
| 6765 } |
| 6766 return this.finishNumberExtra(60/*TokenKind.INTEGER*/); |
| 6767 } |
| 6768 TokenizerBase.prototype.finishNumberExtra = function(kind) { |
| 6769 if (this._maybeEatChar(101) || this._maybeEatChar(69)) { |
| 6770 kind = 62/*TokenKind.DOUBLE*/; |
| 6771 this._maybeEatChar(45); |
| 6772 this._maybeEatChar(43); |
| 6773 this.eatDigits(); |
| 6774 } |
| 6775 if (this._peekChar() != 0 && TokenizerHelpers.isIdentifierStart(this._peekChar
())) { |
| 6776 this._nextChar(); |
| 6777 return this._errorToken("illegal character in number"); |
| 6778 } |
| 6779 return this._finishToken(kind); |
| 6780 } |
| 6781 TokenizerBase.prototype.finishMultilineString = function(quote) { |
| 6782 while (true) { |
| 6783 var ch = this._nextChar(); |
| 6784 if (ch == 0) { |
| 6785 var kind = quote == 34 ? 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/ :
69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/; |
| 6786 return this._finishToken(kind); |
| 6787 } |
| 6788 else if (ch == quote) { |
| 6789 if (this._maybeEatChar(quote)) { |
| 6790 if (this._maybeEatChar(quote)) { |
| 6791 return this._finishToken(58/*TokenKind.STRING*/); |
| 6792 } |
| 6793 } |
| 6794 } |
| 6795 else if (ch == 36) { |
| 6796 this._interpStack = InterpStack.push(this._interpStack, quote, true); |
| 6797 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 6798 } |
| 6799 else if (ch == 92) { |
| 6800 if (!this.eatEscapeSequence()) { |
| 6801 return this._errorToken("invalid hex escape sequence"); |
| 6802 } |
| 6803 } |
| 6804 } |
| 6805 } |
| 6806 TokenizerBase.prototype._finishOpenBrace = function() { |
| 6807 var $0; |
| 6808 if (this._interpStack != null) { |
| 6809 if (this._interpStack.depth == -1) { |
| 6810 this._interpStack.depth = 1; |
| 6811 } |
| 6812 else { |
| 6813 ($0 = this._interpStack).depth = $0.depth + 1; |
| 6814 } |
| 6815 } |
| 6816 return this._finishToken(6/*TokenKind.LBRACE*/); |
| 6817 } |
| 6818 TokenizerBase.prototype._finishCloseBrace = function() { |
| 6819 var $0; |
| 6820 if (this._interpStack != null) { |
| 6821 ($0 = this._interpStack).depth = $0.depth - 1; |
| 6822 } |
| 6823 return this._finishToken(7/*TokenKind.RBRACE*/); |
| 6824 } |
| 6825 TokenizerBase.prototype.finishString = function(quote) { |
| 6826 if (this._maybeEatChar(quote)) { |
| 6827 if (this._maybeEatChar(quote)) { |
| 6828 return this.finishMultilineString(quote); |
| 6829 } |
| 6830 else { |
| 6831 return this._finishToken(58/*TokenKind.STRING*/); |
| 6832 } |
| 6833 } |
| 6834 return this.finishStringBody(quote); |
| 6835 } |
| 6836 TokenizerBase.prototype.finishRawString = function(quote) { |
| 6837 if (this._maybeEatChar(quote)) { |
| 6838 if (this._maybeEatChar(quote)) { |
| 6839 return this.finishMultilineRawString(quote); |
| 6840 } |
| 6841 else { |
| 6842 return this._finishToken(58/*TokenKind.STRING*/); |
| 6843 } |
| 6844 } |
| 6845 while (true) { |
| 6846 var ch = this._nextChar(); |
| 6847 if (ch == quote) { |
| 6848 return this._finishToken(58/*TokenKind.STRING*/); |
| 6849 } |
| 6850 else if (ch == 0) { |
| 6851 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 6852 } |
| 6853 } |
| 6854 } |
| 6855 TokenizerBase.prototype.finishMultilineRawString = function(quote) { |
| 6856 while (true) { |
| 6857 var ch = this._nextChar(); |
| 6858 if (ch == 0) { |
| 6859 var kind = quote == 34 ? 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/ :
69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/; |
| 6860 return this._finishToken(kind); |
| 6861 } |
| 6862 else if (ch == quote && this._maybeEatChar(quote) && this._maybeEatChar(quot
e)) { |
| 6863 return this._finishToken(58/*TokenKind.STRING*/); |
| 6864 } |
| 6865 } |
| 6866 } |
| 6867 TokenizerBase.prototype.finishStringBody = function(quote) { |
| 6868 while (true) { |
| 6869 var ch = this._nextChar(); |
| 6870 if (ch == quote) { |
| 6871 return this._finishToken(58/*TokenKind.STRING*/); |
| 6872 } |
| 6873 else if (ch == 36) { |
| 6874 this._interpStack = InterpStack.push(this._interpStack, quote, false); |
| 6875 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 6876 } |
| 6877 else if (ch == 0) { |
| 6878 return this._finishToken(66/*TokenKind.INCOMPLETE_STRING*/); |
| 6879 } |
| 6880 else if (ch == 92) { |
| 6881 if (!this.eatEscapeSequence()) { |
| 6882 return this._errorToken("invalid hex escape sequence"); |
| 6883 } |
| 6884 } |
| 6885 } |
| 6886 } |
| 6887 TokenizerBase.prototype.eatEscapeSequence = function() { |
| 6888 var hex; |
| 6889 switch (this._nextChar()) { |
| 6890 case 120: |
| 6891 |
| 6892 return this.maybeEatHexDigit() && this.maybeEatHexDigit(); |
| 6893 |
| 6894 case 117: |
| 6895 |
| 6896 if (this._maybeEatChar(123)) { |
| 6897 var start = this._index; |
| 6898 this.eatHexDigits(); |
| 6899 var chars = this._index - start; |
| 6900 if (chars > 0 && chars <= 6 && this._maybeEatChar(125)) { |
| 6901 hex = this._text.substring(start, start + chars); |
| 6902 break; |
| 6903 } |
| 6904 else { |
| 6905 return false; |
| 6906 } |
| 6907 } |
| 6908 else { |
| 6909 if (this.maybeEatHexDigit() && this.maybeEatHexDigit() && this.maybeEatH
exDigit() && this.maybeEatHexDigit()) { |
| 6910 hex = this._text.substring(this._index - 4, this._index); |
| 6911 break; |
| 6912 } |
| 6913 else { |
| 6914 return false; |
| 6915 } |
| 6916 } |
| 6917 |
| 6918 default: |
| 6919 |
| 6920 return true; |
| 6921 |
| 6922 } |
| 6923 var n = Parser.parseHex(hex); |
| 6924 return n < 0xD800 || n > 0xDFFF && n <= 0x10FFFF; |
| 6925 } |
| 6926 TokenizerBase.prototype.finishDot = function() { |
| 6927 if (TokenizerHelpers.isDigit(this._peekChar())) { |
| 6928 this.eatDigits(); |
| 6929 return this.finishNumberExtra(62/*TokenKind.DOUBLE*/); |
| 6930 } |
| 6931 else { |
| 6932 return this._finishToken(14/*TokenKind.DOT*/); |
| 6933 } |
| 6934 } |
| 6935 TokenizerBase.prototype.finishIdentifier = function(ch) { |
| 6936 if (this._interpStack != null && this._interpStack.depth == -1) { |
| 6937 this._interpStack.depth = 0; |
| 6938 if (ch == 36) { |
| 6939 return this._errorToken("illegal character after $ in string interpolation
"); |
| 6940 } |
| 6941 while (this._index < this._text.length) { |
| 6942 if (!TokenizerHelpers.isInterpIdentifierPart(this._text.charCodeAt(this._i
ndex++))) { |
| 6943 this._index--; |
| 6944 break; |
| 6945 } |
| 6946 } |
| 6947 } |
| 6948 else { |
| 6949 while (this._index < this._text.length) { |
| 6950 if (!TokenizerHelpers.isIdentifierPart(this._text.charCodeAt(this._index++
))) { |
| 6951 this._index--; |
| 6952 break; |
| 6953 } |
| 6954 } |
| 6955 } |
| 6956 var kind = this.getIdentifierKind(); |
| 6957 if (kind == 70/*TokenKind.IDENTIFIER*/) { |
| 6958 return this._finishToken(70/*TokenKind.IDENTIFIER*/); |
| 6959 } |
| 6960 else { |
| 6961 return this._finishToken(kind); |
| 6962 } |
| 6963 } |
| 6964 TokenizerBase.prototype.next$0 = TokenizerBase.prototype.next; |
| 6965 // ********** Code for Tokenizer ************** |
| 6966 $inherits(Tokenizer, TokenizerBase); |
| 6967 function Tokenizer(source, skipWhitespace, index) { |
| 6968 // Initializers done |
| 6969 TokenizerBase.call(this, source, skipWhitespace, index); |
| 6970 } |
| 6971 Tokenizer.prototype.next = function() { |
| 6972 this._startIndex = this._index; |
| 6973 if (this._interpStack != null && this._interpStack.depth == 0) { |
| 6974 var istack = this._interpStack; |
| 6975 this._interpStack = this._interpStack.pop(); |
| 6976 if (istack.get$isMultiline()) { |
| 6977 return this.finishMultilineString(istack.get$quote()); |
| 6978 } |
| 6979 else { |
| 6980 return this.finishStringBody(istack.get$quote()); |
| 6981 } |
| 6982 } |
| 6983 var ch; |
| 6984 ch = this._nextChar(); |
| 6985 switch (ch) { |
| 6986 case 0: |
| 6987 |
| 6988 return this._finishToken(1/*TokenKind.END_OF_FILE*/); |
| 6989 |
| 6990 case 32: |
| 6991 case 9: |
| 6992 case 10: |
| 6993 case 13: |
| 6994 |
| 6995 return this.finishWhitespace(); |
| 6996 |
| 6997 case 33: |
| 6998 |
| 6999 if (this._maybeEatChar(61)) { |
| 7000 if (this._maybeEatChar(61)) { |
| 7001 return this._finishToken(51/*TokenKind.NE_STRICT*/); |
| 7002 } |
| 7003 else { |
| 7004 return this._finishToken(49/*TokenKind.NE*/); |
| 7005 } |
| 7006 } |
| 7007 else { |
| 7008 return this._finishToken(19/*TokenKind.NOT*/); |
| 7009 } |
| 7010 |
| 7011 case 34: |
| 7012 |
| 7013 return this.finishString(34); |
| 7014 |
| 7015 case 35: |
| 7016 |
| 7017 if (this._maybeEatChar(33)) { |
| 7018 return this.finishHashBang(); |
| 7019 } |
| 7020 else { |
| 7021 return this._finishToken(12/*TokenKind.HASH*/); |
| 7022 } |
| 7023 |
| 7024 case 36: |
| 7025 |
| 7026 if (this._maybeEatChar(34)) { |
| 7027 return this.finishString(34); |
| 7028 } |
| 7029 else if (this._maybeEatChar(39)) { |
| 7030 return this.finishString(39); |
| 7031 } |
| 7032 else { |
| 7033 return this.finishIdentifier(36); |
| 7034 } |
| 7035 |
| 7036 case 37: |
| 7037 |
| 7038 if (this._maybeEatChar(61)) { |
| 7039 return this._finishToken(32/*TokenKind.ASSIGN_MOD*/); |
| 7040 } |
| 7041 else { |
| 7042 return this._finishToken(47/*TokenKind.MOD*/); |
| 7043 } |
| 7044 |
| 7045 case 38: |
| 7046 |
| 7047 if (this._maybeEatChar(38)) { |
| 7048 return this._finishToken(35/*TokenKind.AND*/); |
| 7049 } |
| 7050 else if (this._maybeEatChar(61)) { |
| 7051 return this._finishToken(23/*TokenKind.ASSIGN_AND*/); |
| 7052 } |
| 7053 else { |
| 7054 return this._finishToken(38/*TokenKind.BIT_AND*/); |
| 7055 } |
| 7056 |
| 7057 case 39: |
| 7058 |
| 7059 return this.finishString(39); |
| 7060 |
| 7061 case 40: |
| 7062 |
| 7063 return this._finishToken(2/*TokenKind.LPAREN*/); |
| 7064 |
| 7065 case 41: |
| 7066 |
| 7067 return this._finishToken(3/*TokenKind.RPAREN*/); |
| 7068 |
| 7069 case 42: |
| 7070 |
| 7071 if (this._maybeEatChar(61)) { |
| 7072 return this._finishToken(29/*TokenKind.ASSIGN_MUL*/); |
| 7073 } |
| 7074 else { |
| 7075 return this._finishToken(44/*TokenKind.MUL*/); |
| 7076 } |
| 7077 |
| 7078 case 43: |
| 7079 |
| 7080 if (this._maybeEatChar(43)) { |
| 7081 return this._finishToken(16/*TokenKind.INCR*/); |
| 7082 } |
| 7083 else if (this._maybeEatChar(61)) { |
| 7084 return this._finishToken(27/*TokenKind.ASSIGN_ADD*/); |
| 7085 } |
| 7086 else { |
| 7087 return this._finishToken(42/*TokenKind.ADD*/); |
| 7088 } |
| 7089 |
| 7090 case 44: |
| 7091 |
| 7092 return this._finishToken(11/*TokenKind.COMMA*/); |
| 7093 |
| 7094 case 45: |
| 7095 |
| 7096 if (this._maybeEatChar(45)) { |
| 7097 return this._finishToken(17/*TokenKind.DECR*/); |
| 7098 } |
| 7099 else if (this._maybeEatChar(61)) { |
| 7100 return this._finishToken(28/*TokenKind.ASSIGN_SUB*/); |
| 7101 } |
| 7102 else { |
| 7103 return this._finishToken(43/*TokenKind.SUB*/); |
| 7104 } |
| 7105 |
| 7106 case 46: |
| 7107 |
| 7108 if (this._maybeEatChar(46)) { |
| 7109 if (this._maybeEatChar(46)) { |
| 7110 return this._finishToken(15/*TokenKind.ELLIPSIS*/); |
| 7111 } |
| 7112 else { |
| 7113 return this._errorToken(); |
| 7114 } |
| 7115 } |
| 7116 else { |
| 7117 return this.finishDot(); |
| 7118 } |
| 7119 |
| 7120 case 47: |
| 7121 |
| 7122 if (this._maybeEatChar(42)) { |
| 7123 return this.finishMultiLineComment(); |
| 7124 } |
| 7125 else if (this._maybeEatChar(47)) { |
| 7126 return this.finishSingleLineComment(); |
| 7127 } |
| 7128 else if (this._maybeEatChar(61)) { |
| 7129 return this._finishToken(30/*TokenKind.ASSIGN_DIV*/); |
| 7130 } |
| 7131 else { |
| 7132 return this._finishToken(45/*TokenKind.DIV*/); |
| 7133 } |
| 7134 |
| 7135 case 48: |
| 7136 |
| 7137 if (this._maybeEatChar(88)) { |
| 7138 return this.finishHex(); |
| 7139 } |
| 7140 else if (this._maybeEatChar(120)) { |
| 7141 return this.finishHex(); |
| 7142 } |
| 7143 else { |
| 7144 return this.finishNumber(); |
| 7145 } |
| 7146 |
| 7147 case 58: |
| 7148 |
| 7149 return this._finishToken(8/*TokenKind.COLON*/); |
| 7150 |
| 7151 case 59: |
| 7152 |
| 7153 return this._finishToken(10/*TokenKind.SEMICOLON*/); |
| 7154 |
| 7155 case 60: |
| 7156 |
| 7157 if (this._maybeEatChar(60)) { |
| 7158 if (this._maybeEatChar(61)) { |
| 7159 return this._finishToken(24/*TokenKind.ASSIGN_SHL*/); |
| 7160 } |
| 7161 else { |
| 7162 return this._finishToken(39/*TokenKind.SHL*/); |
| 7163 } |
| 7164 } |
| 7165 else if (this._maybeEatChar(61)) { |
| 7166 return this._finishToken(54/*TokenKind.LTE*/); |
| 7167 } |
| 7168 else { |
| 7169 return this._finishToken(52/*TokenKind.LT*/); |
| 7170 } |
| 7171 |
| 7172 case 61: |
| 7173 |
| 7174 if (this._maybeEatChar(61)) { |
| 7175 if (this._maybeEatChar(61)) { |
| 7176 return this._finishToken(50/*TokenKind.EQ_STRICT*/); |
| 7177 } |
| 7178 else { |
| 7179 return this._finishToken(48/*TokenKind.EQ*/); |
| 7180 } |
| 7181 } |
| 7182 else if (this._maybeEatChar(62)) { |
| 7183 return this._finishToken(9/*TokenKind.ARROW*/); |
| 7184 } |
| 7185 else { |
| 7186 return this._finishToken(20/*TokenKind.ASSIGN*/); |
| 7187 } |
| 7188 |
| 7189 case 62: |
| 7190 |
| 7191 if (this._maybeEatChar(61)) { |
| 7192 return this._finishToken(55/*TokenKind.GTE*/); |
| 7193 } |
| 7194 else if (this._maybeEatChar(62)) { |
| 7195 if (this._maybeEatChar(61)) { |
| 7196 return this._finishToken(25/*TokenKind.ASSIGN_SAR*/); |
| 7197 } |
| 7198 else if (this._maybeEatChar(62)) { |
| 7199 if (this._maybeEatChar(61)) { |
| 7200 return this._finishToken(26/*TokenKind.ASSIGN_SHR*/); |
| 7201 } |
| 7202 else { |
| 7203 return this._finishToken(41/*TokenKind.SHR*/); |
| 7204 } |
| 7205 } |
| 7206 else { |
| 7207 return this._finishToken(40/*TokenKind.SAR*/); |
| 7208 } |
| 7209 } |
| 7210 else { |
| 7211 return this._finishToken(53/*TokenKind.GT*/); |
| 7212 } |
| 7213 |
| 7214 case 63: |
| 7215 |
| 7216 return this._finishToken(33/*TokenKind.CONDITIONAL*/); |
| 7217 |
| 7218 case 64: |
| 7219 |
| 7220 if (this._maybeEatChar(34)) { |
| 7221 return this.finishRawString(34); |
| 7222 } |
| 7223 else if (this._maybeEatChar(39)) { |
| 7224 return this.finishRawString(39); |
| 7225 } |
| 7226 else { |
| 7227 return this._errorToken(); |
| 7228 } |
| 7229 |
| 7230 case 91: |
| 7231 |
| 7232 if (this._maybeEatChar(93)) { |
| 7233 if (this._maybeEatChar(61)) { |
| 7234 return this._finishToken(57/*TokenKind.SETINDEX*/); |
| 7235 } |
| 7236 else { |
| 7237 return this._finishToken(56/*TokenKind.INDEX*/); |
| 7238 } |
| 7239 } |
| 7240 else { |
| 7241 return this._finishToken(4/*TokenKind.LBRACK*/); |
| 7242 } |
| 7243 |
| 7244 case 93: |
| 7245 |
| 7246 return this._finishToken(5/*TokenKind.RBRACK*/); |
| 7247 |
| 7248 case 94: |
| 7249 |
| 7250 if (this._maybeEatChar(61)) { |
| 7251 return this._finishToken(22/*TokenKind.ASSIGN_XOR*/); |
| 7252 } |
| 7253 else { |
| 7254 return this._finishToken(37/*TokenKind.BIT_XOR*/); |
| 7255 } |
| 7256 |
| 7257 case 123: |
| 7258 |
| 7259 return this._finishOpenBrace(); |
| 7260 |
| 7261 case 124: |
| 7262 |
| 7263 if (this._maybeEatChar(61)) { |
| 7264 return this._finishToken(21/*TokenKind.ASSIGN_OR*/); |
| 7265 } |
| 7266 else if (this._maybeEatChar(124)) { |
| 7267 return this._finishToken(34/*TokenKind.OR*/); |
| 7268 } |
| 7269 else { |
| 7270 return this._finishToken(36/*TokenKind.BIT_OR*/); |
| 7271 } |
| 7272 |
| 7273 case 125: |
| 7274 |
| 7275 return this._finishCloseBrace(); |
| 7276 |
| 7277 case 126: |
| 7278 |
| 7279 if (this._maybeEatChar(47)) { |
| 7280 if (this._maybeEatChar(61)) { |
| 7281 return this._finishToken(31/*TokenKind.ASSIGN_TRUNCDIV*/); |
| 7282 } |
| 7283 else { |
| 7284 return this._finishToken(46/*TokenKind.TRUNCDIV*/); |
| 7285 } |
| 7286 } |
| 7287 else { |
| 7288 return this._finishToken(18/*TokenKind.BIT_NOT*/); |
| 7289 } |
| 7290 |
| 7291 default: |
| 7292 |
| 7293 if (TokenizerHelpers.isIdentifierStart(ch)) { |
| 7294 return this.finishIdentifier(ch); |
| 7295 } |
| 7296 else if (TokenizerHelpers.isDigit(ch)) { |
| 7297 return this.finishNumber(); |
| 7298 } |
| 7299 else { |
| 7300 return this._errorToken(); |
| 7301 } |
| 7302 |
| 7303 } |
| 7304 } |
| 7305 Tokenizer.prototype.getIdentifierKind = function() { |
| 7306 var i0 = this._startIndex; |
| 7307 switch (this._index - i0) { |
| 7308 case 2: |
| 7309 |
| 7310 if (this._text.charCodeAt(i0) == 100) { |
| 7311 if (this._text.charCodeAt(i0 + 1) == 111) return 95/*TokenKind.DO*/; |
| 7312 } |
| 7313 else if (this._text.charCodeAt(i0) == 105) { |
| 7314 if (this._text.charCodeAt(i0 + 1) == 102) { |
| 7315 return 101/*TokenKind.IF*/; |
| 7316 } |
| 7317 else if (this._text.charCodeAt(i0 + 1) == 110) { |
| 7318 return 102/*TokenKind.IN*/; |
| 7319 } |
| 7320 else if (this._text.charCodeAt(i0 + 1) == 115) { |
| 7321 return 103/*TokenKind.IS*/; |
| 7322 } |
| 7323 } |
| 7324 return 70/*TokenKind.IDENTIFIER*/; |
| 7325 |
| 7326 case 3: |
| 7327 |
| 7328 if (this._text.charCodeAt(i0) == 102) { |
| 7329 if (this._text.charCodeAt(i0 + 1) == 111 && this._text.charCodeAt(i0 + 2
) == 114) return 100/*TokenKind.FOR*/; |
| 7330 } |
| 7331 else if (this._text.charCodeAt(i0) == 103) { |
| 7332 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 116) return 76/*TokenKind.GET*/; |
| 7333 } |
| 7334 else if (this._text.charCodeAt(i0) == 110) { |
| 7335 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 119) return 104/*TokenKind.NEW*/; |
| 7336 } |
| 7337 else if (this._text.charCodeAt(i0) == 115) { |
| 7338 if (this._text.charCodeAt(i0 + 1) == 101 && this._text.charCodeAt(i0 + 2
) == 116) return 84/*TokenKind.SET*/; |
| 7339 } |
| 7340 else if (this._text.charCodeAt(i0) == 116) { |
| 7341 if (this._text.charCodeAt(i0 + 1) == 114 && this._text.charCodeAt(i0 + 2
) == 121) return 112/*TokenKind.TRY*/; |
| 7342 } |
| 7343 else if (this._text.charCodeAt(i0) == 118) { |
| 7344 if (this._text.charCodeAt(i0 + 1) == 97 && this._text.charCodeAt(i0 + 2)
== 114) return 113/*TokenKind.VAR*/; |
| 7345 } |
| 7346 return 70/*TokenKind.IDENTIFIER*/; |
| 7347 |
| 7348 case 4: |
| 7349 |
| 7350 if (this._text.charCodeAt(i0) == 99) { |
| 7351 if (this._text.charCodeAt(i0 + 1) == 97 && this._text.charCodeAt(i0 + 2)
== 115 && this._text.charCodeAt(i0 + 3) == 101) return 90/*TokenKind.CASE*/; |
| 7352 } |
| 7353 else if (this._text.charCodeAt(i0) == 101) { |
| 7354 if (this._text.charCodeAt(i0 + 1) == 108 && this._text.charCodeAt(i0 + 2
) == 115 && this._text.charCodeAt(i0 + 3) == 101) return 96/*TokenKind.ELSE*/; |
| 7355 } |
| 7356 else if (this._text.charCodeAt(i0) == 110) { |
| 7357 if (this._text.charCodeAt(i0 + 1) == 117 && this._text.charCodeAt(i0 + 2
) == 108 && this._text.charCodeAt(i0 + 3) == 108) return 105/*TokenKind.NULL*/; |
| 7358 } |
| 7359 else if (this._text.charCodeAt(i0) == 116) { |
| 7360 if (this._text.charCodeAt(i0 + 1) == 104) { |
| 7361 if (this._text.charCodeAt(i0 + 2) == 105 && this._text.charCodeAt(i0 +
3) == 115) return 109/*TokenKind.THIS*/; |
| 7362 } |
| 7363 else if (this._text.charCodeAt(i0 + 1) == 114) { |
| 7364 if (this._text.charCodeAt(i0 + 2) == 117 && this._text.charCodeAt(i0 +
3) == 101) return 111/*TokenKind.TRUE*/; |
| 7365 } |
| 7366 } |
| 7367 else if (this._text.charCodeAt(i0) == 118) { |
| 7368 if (this._text.charCodeAt(i0 + 1) == 111 && this._text.charCodeAt(i0 + 2
) == 105 && this._text.charCodeAt(i0 + 3) == 100) return 114/*TokenKind.VOID*/; |
| 7369 } |
| 7370 return 70/*TokenKind.IDENTIFIER*/; |
| 7371 |
| 7372 case 5: |
| 7373 |
| 7374 if (this._text.charCodeAt(i0) == 97) { |
| 7375 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*/; |
| 7376 } |
| 7377 else if (this._text.charCodeAt(i0) == 98) { |
| 7378 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*/; |
| 7379 } |
| 7380 else if (this._text.charCodeAt(i0) == 99) { |
| 7381 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 7382 if (this._text.charCodeAt(i0 + 2) == 116 && this._text.charCodeAt(i0 +
3) == 99 && this._text.charCodeAt(i0 + 4) == 104) return 91/*TokenKind.CATCH*/; |
| 7383 } |
| 7384 else if (this._text.charCodeAt(i0 + 1) == 108) { |
| 7385 if (this._text.charCodeAt(i0 + 2) == 97 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 115) return 73/*TokenKind.CLASS*/; |
| 7386 } |
| 7387 else if (this._text.charCodeAt(i0 + 1) == 111) { |
| 7388 if (this._text.charCodeAt(i0 + 2) == 110 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 116) return 92/*TokenKind.CONST*/
; |
| 7389 } |
| 7390 } |
| 7391 else if (this._text.charCodeAt(i0) == 102) { |
| 7392 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 7393 if (this._text.charCodeAt(i0 + 2) == 108 && this._text.charCodeAt(i0 +
3) == 115 && this._text.charCodeAt(i0 + 4) == 101) return 97/*TokenKind.FALSE*/
; |
| 7394 } |
| 7395 else if (this._text.charCodeAt(i0 + 1) == 105) { |
| 7396 if (this._text.charCodeAt(i0 + 2) == 110 && this._text.charCodeAt(i0 +
3) == 97 && this._text.charCodeAt(i0 + 4) == 108) return 98/*TokenKind.FINAL*/; |
| 7397 } |
| 7398 } |
| 7399 else if (this._text.charCodeAt(i0) == 115) { |
| 7400 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*/; |
| 7401 } |
| 7402 else if (this._text.charCodeAt(i0) == 116) { |
| 7403 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*/; |
| 7404 } |
| 7405 else if (this._text.charCodeAt(i0) == 119) { |
| 7406 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*/; |
| 7407 } |
| 7408 return 70/*TokenKind.IDENTIFIER*/; |
| 7409 |
| 7410 case 6: |
| 7411 |
| 7412 if (this._text.charCodeAt(i0) == 97) { |
| 7413 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*/; |
| 7414 } |
| 7415 else if (this._text.charCodeAt(i0) == 105) { |
| 7416 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*/; |
| 7417 } |
| 7418 else if (this._text.charCodeAt(i0) == 110) { |
| 7419 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 7420 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*/; |
| 7421 } |
| 7422 else if (this._text.charCodeAt(i0 + 1) == 101) { |
| 7423 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*/; |
| 7424 } |
| 7425 } |
| 7426 else if (this._text.charCodeAt(i0) == 114) { |
| 7427 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*/
; |
| 7428 } |
| 7429 else if (this._text.charCodeAt(i0) == 115) { |
| 7430 if (this._text.charCodeAt(i0 + 1) == 111) { |
| 7431 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*/; |
| 7432 } |
| 7433 else if (this._text.charCodeAt(i0 + 1) == 116) { |
| 7434 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*/; |
| 7435 } |
| 7436 else if (this._text.charCodeAt(i0 + 1) == 119) { |
| 7437 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*/; |
| 7438 } |
| 7439 } |
| 7440 return 70/*TokenKind.IDENTIFIER*/; |
| 7441 |
| 7442 case 7: |
| 7443 |
| 7444 if (this._text.charCodeAt(i0) == 100) { |
| 7445 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*/; |
| 7446 } |
| 7447 else if (this._text.charCodeAt(i0) == 101) { |
| 7448 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*/; |
| 7449 } |
| 7450 else if (this._text.charCodeAt(i0) == 102) { |
| 7451 if (this._text.charCodeAt(i0 + 1) == 97) { |
| 7452 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*
/; |
| 7453 } |
| 7454 else if (this._text.charCodeAt(i0 + 1) == 105) { |
| 7455 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*
/; |
| 7456 } |
| 7457 } |
| 7458 else if (this._text.charCodeAt(i0) == 108) { |
| 7459 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*/; |
| 7460 } |
| 7461 else if (this._text.charCodeAt(i0) == 116) { |
| 7462 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*/; |
| 7463 } |
| 7464 return 70/*TokenKind.IDENTIFIER*/; |
| 7465 |
| 7466 case 8: |
| 7467 |
| 7468 if (this._text.charCodeAt(i0) == 97) { |
| 7469 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*/; |
| 7470 } |
| 7471 else if (this._text.charCodeAt(i0) == 99) { |
| 7472 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*
/; |
| 7473 } |
| 7474 else if (this._text.charCodeAt(i0) == 111) { |
| 7475 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*/
; |
| 7476 } |
| 7477 return 70/*TokenKind.IDENTIFIER*/; |
| 7478 |
| 7479 case 9: |
| 7480 |
| 7481 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*/; |
| 7482 return 70/*TokenKind.IDENTIFIER*/; |
| 7483 |
| 7484 case 10: |
| 7485 |
| 7486 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*/; |
| 7487 return 70/*TokenKind.IDENTIFIER*/; |
| 7488 |
| 7489 default: |
| 7490 |
| 7491 return 70/*TokenKind.IDENTIFIER*/; |
| 7492 |
| 7493 } |
| 7494 } |
| 7495 Tokenizer.prototype.next$0 = Tokenizer.prototype.next; |
| 7496 // ********** Code for TokenKind ************** |
| 7497 function TokenKind() {} |
| 7498 TokenKind.kindToString = function(kind) { |
| 7499 switch (kind) { |
| 7500 case 1/*TokenKind.END_OF_FILE*/: |
| 7501 |
| 7502 return "end of file"; |
| 7503 |
| 7504 case 2/*TokenKind.LPAREN*/: |
| 7505 |
| 7506 return "("; |
| 7507 |
| 7508 case 3/*TokenKind.RPAREN*/: |
| 7509 |
| 7510 return ")"; |
| 7511 |
| 7512 case 4/*TokenKind.LBRACK*/: |
| 7513 |
| 7514 return "["; |
| 7515 |
| 7516 case 5/*TokenKind.RBRACK*/: |
| 7517 |
| 7518 return "]"; |
| 7519 |
| 7520 case 6/*TokenKind.LBRACE*/: |
| 7521 |
| 7522 return "{"; |
| 7523 |
| 7524 case 7/*TokenKind.RBRACE*/: |
| 7525 |
| 7526 return "}"; |
| 7527 |
| 7528 case 8/*TokenKind.COLON*/: |
| 7529 |
| 7530 return ":"; |
| 7531 |
| 7532 case 9/*TokenKind.ARROW*/: |
| 7533 |
| 7534 return "=>"; |
| 7535 |
| 7536 case 10/*TokenKind.SEMICOLON*/: |
| 7537 |
| 7538 return ";"; |
| 7539 |
| 7540 case 11/*TokenKind.COMMA*/: |
| 7541 |
| 7542 return ","; |
| 7543 |
| 7544 case 12/*TokenKind.HASH*/: |
| 7545 |
| 7546 return "#"; |
| 7547 |
| 7548 case 13/*TokenKind.HASHBANG*/: |
| 7549 |
| 7550 return "#!"; |
| 7551 |
| 7552 case 14/*TokenKind.DOT*/: |
| 7553 |
| 7554 return "."; |
| 7555 |
| 7556 case 15/*TokenKind.ELLIPSIS*/: |
| 7557 |
| 7558 return "..."; |
| 7559 |
| 7560 case 16/*TokenKind.INCR*/: |
| 7561 |
| 7562 return "++"; |
| 7563 |
| 7564 case 17/*TokenKind.DECR*/: |
| 7565 |
| 7566 return "--"; |
| 7567 |
| 7568 case 18/*TokenKind.BIT_NOT*/: |
| 7569 |
| 7570 return "~"; |
| 7571 |
| 7572 case 19/*TokenKind.NOT*/: |
| 7573 |
| 7574 return "!"; |
| 7575 |
| 7576 case 20/*TokenKind.ASSIGN*/: |
| 7577 |
| 7578 return "="; |
| 7579 |
| 7580 case 21/*TokenKind.ASSIGN_OR*/: |
| 7581 |
| 7582 return "|="; |
| 7583 |
| 7584 case 22/*TokenKind.ASSIGN_XOR*/: |
| 7585 |
| 7586 return "^="; |
| 7587 |
| 7588 case 23/*TokenKind.ASSIGN_AND*/: |
| 7589 |
| 7590 return "&="; |
| 7591 |
| 7592 case 24/*TokenKind.ASSIGN_SHL*/: |
| 7593 |
| 7594 return "<<="; |
| 7595 |
| 7596 case 25/*TokenKind.ASSIGN_SAR*/: |
| 7597 |
| 7598 return ">>="; |
| 7599 |
| 7600 case 26/*TokenKind.ASSIGN_SHR*/: |
| 7601 |
| 7602 return ">>>="; |
| 7603 |
| 7604 case 27/*TokenKind.ASSIGN_ADD*/: |
| 7605 |
| 7606 return "+="; |
| 7607 |
| 7608 case 28/*TokenKind.ASSIGN_SUB*/: |
| 7609 |
| 7610 return "-="; |
| 7611 |
| 7612 case 29/*TokenKind.ASSIGN_MUL*/: |
| 7613 |
| 7614 return "*="; |
| 7615 |
| 7616 case 30/*TokenKind.ASSIGN_DIV*/: |
| 7617 |
| 7618 return "/="; |
| 7619 |
| 7620 case 31/*TokenKind.ASSIGN_TRUNCDIV*/: |
| 7621 |
| 7622 return "~/="; |
| 7623 |
| 7624 case 32/*TokenKind.ASSIGN_MOD*/: |
| 7625 |
| 7626 return "%="; |
| 7627 |
| 7628 case 33/*TokenKind.CONDITIONAL*/: |
| 7629 |
| 7630 return "?"; |
| 7631 |
| 7632 case 34/*TokenKind.OR*/: |
| 7633 |
| 7634 return "||"; |
| 7635 |
| 7636 case 35/*TokenKind.AND*/: |
| 7637 |
| 7638 return "&&"; |
| 7639 |
| 7640 case 36/*TokenKind.BIT_OR*/: |
| 7641 |
| 7642 return "|"; |
| 7643 |
| 7644 case 37/*TokenKind.BIT_XOR*/: |
| 7645 |
| 7646 return "^"; |
| 7647 |
| 7648 case 38/*TokenKind.BIT_AND*/: |
| 7649 |
| 7650 return "&"; |
| 7651 |
| 7652 case 39/*TokenKind.SHL*/: |
| 7653 |
| 7654 return "<<"; |
| 7655 |
| 7656 case 40/*TokenKind.SAR*/: |
| 7657 |
| 7658 return ">>"; |
| 7659 |
| 7660 case 41/*TokenKind.SHR*/: |
| 7661 |
| 7662 return ">>>"; |
| 7663 |
| 7664 case 42/*TokenKind.ADD*/: |
| 7665 |
| 7666 return "+"; |
| 7667 |
| 7668 case 43/*TokenKind.SUB*/: |
| 7669 |
| 7670 return "-"; |
| 7671 |
| 7672 case 44/*TokenKind.MUL*/: |
| 7673 |
| 7674 return "*"; |
| 7675 |
| 7676 case 45/*TokenKind.DIV*/: |
| 7677 |
| 7678 return "/"; |
| 7679 |
| 7680 case 46/*TokenKind.TRUNCDIV*/: |
| 7681 |
| 7682 return "~/"; |
| 7683 |
| 7684 case 47/*TokenKind.MOD*/: |
| 7685 |
| 7686 return "%"; |
| 7687 |
| 7688 case 48/*TokenKind.EQ*/: |
| 7689 |
| 7690 return "=="; |
| 7691 |
| 7692 case 49/*TokenKind.NE*/: |
| 7693 |
| 7694 return "!="; |
| 7695 |
| 7696 case 50/*TokenKind.EQ_STRICT*/: |
| 7697 |
| 7698 return "==="; |
| 7699 |
| 7700 case 51/*TokenKind.NE_STRICT*/: |
| 7701 |
| 7702 return "!=="; |
| 7703 |
| 7704 case 52/*TokenKind.LT*/: |
| 7705 |
| 7706 return "<"; |
| 7707 |
| 7708 case 53/*TokenKind.GT*/: |
| 7709 |
| 7710 return ">"; |
| 7711 |
| 7712 case 54/*TokenKind.LTE*/: |
| 7713 |
| 7714 return "<="; |
| 7715 |
| 7716 case 55/*TokenKind.GTE*/: |
| 7717 |
| 7718 return ">="; |
| 7719 |
| 7720 case 56/*TokenKind.INDEX*/: |
| 7721 |
| 7722 return "[]"; |
| 7723 |
| 7724 case 57/*TokenKind.SETINDEX*/: |
| 7725 |
| 7726 return "[]="; |
| 7727 |
| 7728 case 58/*TokenKind.STRING*/: |
| 7729 |
| 7730 return "string"; |
| 7731 |
| 7732 case 59/*TokenKind.STRING_PART*/: |
| 7733 |
| 7734 return "string part"; |
| 7735 |
| 7736 case 60/*TokenKind.INTEGER*/: |
| 7737 |
| 7738 return "integer"; |
| 7739 |
| 7740 case 61/*TokenKind.HEX_INTEGER*/: |
| 7741 |
| 7742 return "hex integer"; |
| 7743 |
| 7744 case 62/*TokenKind.DOUBLE*/: |
| 7745 |
| 7746 return "double"; |
| 7747 |
| 7748 case 63/*TokenKind.WHITESPACE*/: |
| 7749 |
| 7750 return "whitespace"; |
| 7751 |
| 7752 case 64/*TokenKind.COMMENT*/: |
| 7753 |
| 7754 return "comment"; |
| 7755 |
| 7756 case 65/*TokenKind.ERROR*/: |
| 7757 |
| 7758 return "error"; |
| 7759 |
| 7760 case 66/*TokenKind.INCOMPLETE_STRING*/: |
| 7761 |
| 7762 return "incomplete string"; |
| 7763 |
| 7764 case 67/*TokenKind.INCOMPLETE_COMMENT*/: |
| 7765 |
| 7766 return "incomplete comment"; |
| 7767 |
| 7768 case 68/*TokenKind.INCOMPLETE_MULTILINE_STRING_DQ*/: |
| 7769 |
| 7770 return "incomplete multiline string dq"; |
| 7771 |
| 7772 case 69/*TokenKind.INCOMPLETE_MULTILINE_STRING_SQ*/: |
| 7773 |
| 7774 return "incomplete multiline string sq"; |
| 7775 |
| 7776 case 70/*TokenKind.IDENTIFIER*/: |
| 7777 |
| 7778 return "identifier"; |
| 7779 |
| 7780 case 71/*TokenKind.ABSTRACT*/: |
| 7781 |
| 7782 return "pseudo-keyword 'abstract'"; |
| 7783 |
| 7784 case 72/*TokenKind.ASSERT*/: |
| 7785 |
| 7786 return "pseudo-keyword 'assert'"; |
| 7787 |
| 7788 case 73/*TokenKind.CLASS*/: |
| 7789 |
| 7790 return "pseudo-keyword 'class'"; |
| 7791 |
| 7792 case 74/*TokenKind.EXTENDS*/: |
| 7793 |
| 7794 return "pseudo-keyword 'extends'"; |
| 7795 |
| 7796 case 75/*TokenKind.FACTORY*/: |
| 7797 |
| 7798 return "pseudo-keyword 'factory'"; |
| 7799 |
| 7800 case 76/*TokenKind.GET*/: |
| 7801 |
| 7802 return "pseudo-keyword 'get'"; |
| 7803 |
| 7804 case 77/*TokenKind.IMPLEMENTS*/: |
| 7805 |
| 7806 return "pseudo-keyword 'implements'"; |
| 7807 |
| 7808 case 78/*TokenKind.IMPORT*/: |
| 7809 |
| 7810 return "pseudo-keyword 'import'"; |
| 7811 |
| 7812 case 79/*TokenKind.INTERFACE*/: |
| 7813 |
| 7814 return "pseudo-keyword 'interface'"; |
| 7815 |
| 7816 case 80/*TokenKind.LIBRARY*/: |
| 7817 |
| 7818 return "pseudo-keyword 'library'"; |
| 7819 |
| 7820 case 81/*TokenKind.NATIVE*/: |
| 7821 |
| 7822 return "pseudo-keyword 'native'"; |
| 7823 |
| 7824 case 82/*TokenKind.NEGATE*/: |
| 7825 |
| 7826 return "pseudo-keyword 'negate'"; |
| 7827 |
| 7828 case 83/*TokenKind.OPERATOR*/: |
| 7829 |
| 7830 return "pseudo-keyword 'operator'"; |
| 7831 |
| 7832 case 84/*TokenKind.SET*/: |
| 7833 |
| 7834 return "pseudo-keyword 'set'"; |
| 7835 |
| 7836 case 85/*TokenKind.SOURCE*/: |
| 7837 |
| 7838 return "pseudo-keyword 'source'"; |
| 7839 |
| 7840 case 86/*TokenKind.STATIC*/: |
| 7841 |
| 7842 return "pseudo-keyword 'static'"; |
| 7843 |
| 7844 case 87/*TokenKind.TYPEDEF*/: |
| 7845 |
| 7846 return "pseudo-keyword 'typedef'"; |
| 7847 |
| 7848 case 88/*TokenKind.AWAIT*/: |
| 7849 |
| 7850 return "keyword 'await'"; |
| 7851 |
| 7852 case 89/*TokenKind.BREAK*/: |
| 7853 |
| 7854 return "keyword 'break'"; |
| 7855 |
| 7856 case 90/*TokenKind.CASE*/: |
| 7857 |
| 7858 return "keyword 'case'"; |
| 7859 |
| 7860 case 91/*TokenKind.CATCH*/: |
| 7861 |
| 7862 return "keyword 'catch'"; |
| 7863 |
| 7864 case 92/*TokenKind.CONST*/: |
| 7865 |
| 7866 return "keyword 'const'"; |
| 7867 |
| 7868 case 93/*TokenKind.CONTINUE*/: |
| 7869 |
| 7870 return "keyword 'continue'"; |
| 7871 |
| 7872 case 94/*TokenKind.DEFAULT*/: |
| 7873 |
| 7874 return "keyword 'default'"; |
| 7875 |
| 7876 case 95/*TokenKind.DO*/: |
| 7877 |
| 7878 return "keyword 'do'"; |
| 7879 |
| 7880 case 96/*TokenKind.ELSE*/: |
| 7881 |
| 7882 return "keyword 'else'"; |
| 7883 |
| 7884 case 97/*TokenKind.FALSE*/: |
| 7885 |
| 7886 return "keyword 'false'"; |
| 7887 |
| 7888 case 98/*TokenKind.FINAL*/: |
| 7889 |
| 7890 return "keyword 'final'"; |
| 7891 |
| 7892 case 99/*TokenKind.FINALLY*/: |
| 7893 |
| 7894 return "keyword 'finally'"; |
| 7895 |
| 7896 case 100/*TokenKind.FOR*/: |
| 7897 |
| 7898 return "keyword 'for'"; |
| 7899 |
| 7900 case 101/*TokenKind.IF*/: |
| 7901 |
| 7902 return "keyword 'if'"; |
| 7903 |
| 7904 case 102/*TokenKind.IN*/: |
| 7905 |
| 7906 return "keyword 'in'"; |
| 7907 |
| 7908 case 103/*TokenKind.IS*/: |
| 7909 |
| 7910 return "keyword 'is'"; |
| 7911 |
| 7912 case 104/*TokenKind.NEW*/: |
| 7913 |
| 7914 return "keyword 'new'"; |
| 7915 |
| 7916 case 105/*TokenKind.NULL*/: |
| 7917 |
| 7918 return "keyword 'null'"; |
| 7919 |
| 7920 case 106/*TokenKind.RETURN*/: |
| 7921 |
| 7922 return "keyword 'return'"; |
| 7923 |
| 7924 case 107/*TokenKind.SUPER*/: |
| 7925 |
| 7926 return "keyword 'super'"; |
| 7927 |
| 7928 case 108/*TokenKind.SWITCH*/: |
| 7929 |
| 7930 return "keyword 'switch'"; |
| 7931 |
| 7932 case 109/*TokenKind.THIS*/: |
| 7933 |
| 7934 return "keyword 'this'"; |
| 7935 |
| 7936 case 110/*TokenKind.THROW*/: |
| 7937 |
| 7938 return "keyword 'throw'"; |
| 7939 |
| 7940 case 111/*TokenKind.TRUE*/: |
| 7941 |
| 7942 return "keyword 'true'"; |
| 7943 |
| 7944 case 112/*TokenKind.TRY*/: |
| 7945 |
| 7946 return "keyword 'try'"; |
| 7947 |
| 7948 case 113/*TokenKind.VAR*/: |
| 7949 |
| 7950 return "keyword 'var'"; |
| 7951 |
| 7952 case 114/*TokenKind.VOID*/: |
| 7953 |
| 7954 return "keyword 'void'"; |
| 7955 |
| 7956 case 115/*TokenKind.WHILE*/: |
| 7957 |
| 7958 return "keyword 'while'"; |
| 7959 |
| 7960 default: |
| 7961 |
| 7962 return "TokenKind(" + kind.toString() + ")"; |
| 7963 |
| 7964 } |
| 7965 } |
| 7966 TokenKind.isIdentifier = function(kind) { |
| 7967 return kind >= 70/*TokenKind.IDENTIFIER*/ && kind < 88/*TokenKind.AWAIT*/; |
| 7968 } |
| 7969 TokenKind.infixPrecedence = function(kind) { |
| 7970 switch (kind) { |
| 7971 case 20/*TokenKind.ASSIGN*/: |
| 7972 |
| 7973 return 2; |
| 7974 |
| 7975 case 21/*TokenKind.ASSIGN_OR*/: |
| 7976 |
| 7977 return 2; |
| 7978 |
| 7979 case 22/*TokenKind.ASSIGN_XOR*/: |
| 7980 |
| 7981 return 2; |
| 7982 |
| 7983 case 23/*TokenKind.ASSIGN_AND*/: |
| 7984 |
| 7985 return 2; |
| 7986 |
| 7987 case 24/*TokenKind.ASSIGN_SHL*/: |
| 7988 |
| 7989 return 2; |
| 7990 |
| 7991 case 25/*TokenKind.ASSIGN_SAR*/: |
| 7992 |
| 7993 return 2; |
| 7994 |
| 7995 case 26/*TokenKind.ASSIGN_SHR*/: |
| 7996 |
| 7997 return 2; |
| 7998 |
| 7999 case 27/*TokenKind.ASSIGN_ADD*/: |
| 8000 |
| 8001 return 2; |
| 8002 |
| 8003 case 28/*TokenKind.ASSIGN_SUB*/: |
| 8004 |
| 8005 return 2; |
| 8006 |
| 8007 case 29/*TokenKind.ASSIGN_MUL*/: |
| 8008 |
| 8009 return 2; |
| 8010 |
| 8011 case 30/*TokenKind.ASSIGN_DIV*/: |
| 8012 |
| 8013 return 2; |
| 8014 |
| 8015 case 31/*TokenKind.ASSIGN_TRUNCDIV*/: |
| 8016 |
| 8017 return 2; |
| 8018 |
| 8019 case 32/*TokenKind.ASSIGN_MOD*/: |
| 8020 |
| 8021 return 2; |
| 8022 |
| 8023 case 33/*TokenKind.CONDITIONAL*/: |
| 8024 |
| 8025 return 3; |
| 8026 |
| 8027 case 34/*TokenKind.OR*/: |
| 8028 |
| 8029 return 4; |
| 8030 |
| 8031 case 35/*TokenKind.AND*/: |
| 8032 |
| 8033 return 5; |
| 8034 |
| 8035 case 36/*TokenKind.BIT_OR*/: |
| 8036 |
| 8037 return 6; |
| 8038 |
| 8039 case 37/*TokenKind.BIT_XOR*/: |
| 8040 |
| 8041 return 7; |
| 8042 |
| 8043 case 38/*TokenKind.BIT_AND*/: |
| 8044 |
| 8045 return 8; |
| 8046 |
| 8047 case 39/*TokenKind.SHL*/: |
| 8048 |
| 8049 return 11; |
| 8050 |
| 8051 case 40/*TokenKind.SAR*/: |
| 8052 |
| 8053 return 11; |
| 8054 |
| 8055 case 41/*TokenKind.SHR*/: |
| 8056 |
| 8057 return 11; |
| 8058 |
| 8059 case 42/*TokenKind.ADD*/: |
| 8060 |
| 8061 return 12; |
| 8062 |
| 8063 case 43/*TokenKind.SUB*/: |
| 8064 |
| 8065 return 12; |
| 8066 |
| 8067 case 44/*TokenKind.MUL*/: |
| 8068 |
| 8069 return 13; |
| 8070 |
| 8071 case 45/*TokenKind.DIV*/: |
| 8072 |
| 8073 return 13; |
| 8074 |
| 8075 case 46/*TokenKind.TRUNCDIV*/: |
| 8076 |
| 8077 return 13; |
| 8078 |
| 8079 case 47/*TokenKind.MOD*/: |
| 8080 |
| 8081 return 13; |
| 8082 |
| 8083 case 48/*TokenKind.EQ*/: |
| 8084 |
| 8085 return 9; |
| 8086 |
| 8087 case 49/*TokenKind.NE*/: |
| 8088 |
| 8089 return 9; |
| 8090 |
| 8091 case 50/*TokenKind.EQ_STRICT*/: |
| 8092 |
| 8093 return 9; |
| 8094 |
| 8095 case 51/*TokenKind.NE_STRICT*/: |
| 8096 |
| 8097 return 9; |
| 8098 |
| 8099 case 52/*TokenKind.LT*/: |
| 8100 |
| 8101 return 10; |
| 8102 |
| 8103 case 53/*TokenKind.GT*/: |
| 8104 |
| 8105 return 10; |
| 8106 |
| 8107 case 54/*TokenKind.LTE*/: |
| 8108 |
| 8109 return 10; |
| 8110 |
| 8111 case 55/*TokenKind.GTE*/: |
| 8112 |
| 8113 return 10; |
| 8114 |
| 8115 case 103/*TokenKind.IS*/: |
| 8116 |
| 8117 return 10; |
| 8118 |
| 8119 default: |
| 8120 |
| 8121 return -1; |
| 8122 |
| 8123 } |
| 8124 } |
| 8125 TokenKind.rawOperatorFromMethod = function(name) { |
| 8126 switch (name) { |
| 8127 case ':bit_not': |
| 8128 |
| 8129 return '~'; |
| 8130 |
| 8131 case ':bit_or': |
| 8132 |
| 8133 return '|'; |
| 8134 |
| 8135 case ':bit_xor': |
| 8136 |
| 8137 return '^'; |
| 8138 |
| 8139 case ':bit_and': |
| 8140 |
| 8141 return '&'; |
| 8142 |
| 8143 case ':shl': |
| 8144 |
| 8145 return '<<'; |
| 8146 |
| 8147 case ':sar': |
| 8148 |
| 8149 return '>>'; |
| 8150 |
| 8151 case ':shr': |
| 8152 |
| 8153 return '>>>'; |
| 8154 |
| 8155 case ':add': |
| 8156 |
| 8157 return '+'; |
| 8158 |
| 8159 case ':sub': |
| 8160 |
| 8161 return '-'; |
| 8162 |
| 8163 case ':mul': |
| 8164 |
| 8165 return '*'; |
| 8166 |
| 8167 case ':div': |
| 8168 |
| 8169 return '/'; |
| 8170 |
| 8171 case ':truncdiv': |
| 8172 |
| 8173 return '~/'; |
| 8174 |
| 8175 case ':mod': |
| 8176 |
| 8177 return '%'; |
| 8178 |
| 8179 case ':eq': |
| 8180 |
| 8181 return '=='; |
| 8182 |
| 8183 case ':lt': |
| 8184 |
| 8185 return '<'; |
| 8186 |
| 8187 case ':gt': |
| 8188 |
| 8189 return '>'; |
| 8190 |
| 8191 case ':lte': |
| 8192 |
| 8193 return '<='; |
| 8194 |
| 8195 case ':gte': |
| 8196 |
| 8197 return '>='; |
| 8198 |
| 8199 case ':index': |
| 8200 |
| 8201 return '[]'; |
| 8202 |
| 8203 case ':setindex': |
| 8204 |
| 8205 return '[]='; |
| 8206 |
| 8207 case ':ne': |
| 8208 |
| 8209 return '!='; |
| 8210 |
| 8211 } |
| 8212 } |
| 8213 TokenKind.binaryMethodName = function(kind) { |
| 8214 switch (kind) { |
| 8215 case 18/*TokenKind.BIT_NOT*/: |
| 8216 |
| 8217 return ':bit_not'; |
| 8218 |
| 8219 case 36/*TokenKind.BIT_OR*/: |
| 8220 |
| 8221 return ':bit_or'; |
| 8222 |
| 8223 case 37/*TokenKind.BIT_XOR*/: |
| 8224 |
| 8225 return ':bit_xor'; |
| 8226 |
| 8227 case 38/*TokenKind.BIT_AND*/: |
| 8228 |
| 8229 return ':bit_and'; |
| 8230 |
| 8231 case 39/*TokenKind.SHL*/: |
| 8232 |
| 8233 return ':shl'; |
| 8234 |
| 8235 case 40/*TokenKind.SAR*/: |
| 8236 |
| 8237 return ':sar'; |
| 8238 |
| 8239 case 41/*TokenKind.SHR*/: |
| 8240 |
| 8241 return ':shr'; |
| 8242 |
| 8243 case 42/*TokenKind.ADD*/: |
| 8244 |
| 8245 return ':add'; |
| 8246 |
| 8247 case 43/*TokenKind.SUB*/: |
| 8248 |
| 8249 return ':sub'; |
| 8250 |
| 8251 case 44/*TokenKind.MUL*/: |
| 8252 |
| 8253 return ':mul'; |
| 8254 |
| 8255 case 45/*TokenKind.DIV*/: |
| 8256 |
| 8257 return ':div'; |
| 8258 |
| 8259 case 46/*TokenKind.TRUNCDIV*/: |
| 8260 |
| 8261 return ':truncdiv'; |
| 8262 |
| 8263 case 47/*TokenKind.MOD*/: |
| 8264 |
| 8265 return ':mod'; |
| 8266 |
| 8267 case 48/*TokenKind.EQ*/: |
| 8268 |
| 8269 return ':eq'; |
| 8270 |
| 8271 case 52/*TokenKind.LT*/: |
| 8272 |
| 8273 return ':lt'; |
| 8274 |
| 8275 case 53/*TokenKind.GT*/: |
| 8276 |
| 8277 return ':gt'; |
| 8278 |
| 8279 case 54/*TokenKind.LTE*/: |
| 8280 |
| 8281 return ':lte'; |
| 8282 |
| 8283 case 55/*TokenKind.GTE*/: |
| 8284 |
| 8285 return ':gte'; |
| 8286 |
| 8287 case 56/*TokenKind.INDEX*/: |
| 8288 |
| 8289 return ':index'; |
| 8290 |
| 8291 case 57/*TokenKind.SETINDEX*/: |
| 8292 |
| 8293 return ':setindex'; |
| 8294 |
| 8295 } |
| 8296 } |
| 8297 TokenKind.kindFromAssign = function(kind) { |
| 8298 if (kind == 20/*TokenKind.ASSIGN*/) return 0; |
| 8299 if (kind > 20/*TokenKind.ASSIGN*/ && kind <= 32/*TokenKind.ASSIGN_MOD*/) { |
| 8300 return kind + (15)/*(ADD - ASSIGN_ADD)*/; |
| 8301 } |
| 8302 return -1; |
| 8303 } |
| 8304 // ********** Code for Parser ************** |
| 8305 function Parser(source, diet, throwOnIncomplete, optionalSemicolons, startOffset
) { |
| 8306 this._inhibitLambda = false |
| 8307 this._afterParensIndex = 0 |
| 8308 this._recover = false |
| 8309 this.source = source; |
| 8310 this.diet = diet; |
| 8311 this.throwOnIncomplete = throwOnIncomplete; |
| 8312 this.optionalSemicolons = optionalSemicolons; |
| 8313 // Initializers done |
| 8314 this.tokenizer = new Tokenizer(this.source, true, startOffset); |
| 8315 this._peekToken = this.tokenizer.next(); |
| 8316 this._afterParens = []; |
| 8317 } |
| 8318 Parser.prototype.get$enableAwait = function() { |
| 8319 return $globals.experimentalAwaitPhase != null; |
| 8320 } |
| 8321 Parser.prototype.isPrematureEndOfFile = function() { |
| 8322 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*/)) { |
| 8323 $throw(new IncompleteSourceException(this._previousToken)); |
| 8324 } |
| 8325 else if (this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { |
| 8326 this._lang_error('unexpected end of file', this._peekToken.get$span()); |
| 8327 return true; |
| 8328 } |
| 8329 else { |
| 8330 return false; |
| 8331 } |
| 8332 } |
| 8333 Parser.prototype._recoverTo = function(kind1, kind2, kind3) { |
| 8334 while (!this.isPrematureEndOfFile()) { |
| 8335 var kind = this._peek(); |
| 8336 if (kind == kind1 || kind == kind2 || kind == kind3) { |
| 8337 this._recover = false; |
| 8338 return true; |
| 8339 } |
| 8340 this._lang_next(); |
| 8341 } |
| 8342 return false; |
| 8343 } |
| 8344 Parser.prototype._peek = function() { |
| 8345 return this._peekToken.kind; |
| 8346 } |
| 8347 Parser.prototype._lang_next = function() { |
| 8348 this._previousToken = this._peekToken; |
| 8349 this._peekToken = this.tokenizer.next(); |
| 8350 return this._previousToken; |
| 8351 } |
| 8352 Parser.prototype._peekKind = function(kind) { |
| 8353 return this._peekToken.kind == kind; |
| 8354 } |
| 8355 Parser.prototype._peekIdentifier = function() { |
| 8356 return this._isIdentifier(this._peekToken.kind); |
| 8357 } |
| 8358 Parser.prototype._isIdentifier = function(kind) { |
| 8359 return TokenKind.isIdentifier(kind) || (!this.get$enableAwait() && $eq(kind, 8
8/*TokenKind.AWAIT*/)); |
| 8360 } |
| 8361 Parser.prototype._maybeEat = function(kind) { |
| 8362 if (this._peekToken.kind == kind) { |
| 8363 this._previousToken = this._peekToken; |
| 8364 this._peekToken = this.tokenizer.next(); |
| 8365 return true; |
| 8366 } |
| 8367 else { |
| 8368 return false; |
| 8369 } |
| 8370 } |
| 8371 Parser.prototype._eat = function(kind) { |
| 8372 if (!this._maybeEat(kind)) { |
| 8373 this._errorExpected(TokenKind.kindToString(kind)); |
| 8374 } |
| 8375 } |
| 8376 Parser.prototype._eatSemicolon = function() { |
| 8377 if (this.optionalSemicolons && this._peekKind(1/*TokenKind.END_OF_FILE*/)) ret
urn; |
| 8378 this._eat(10/*TokenKind.SEMICOLON*/); |
| 8379 } |
| 8380 Parser.prototype._errorExpected = function(expected) { |
| 8381 if (this.throwOnIncomplete) this.isPrematureEndOfFile(); |
| 8382 var tok = this._lang_next(); |
| 8383 if ((tok instanceof ErrorToken) && tok.get$message() != null) { |
| 8384 this._lang_error(tok.get$message(), tok.get$span()); |
| 8385 } |
| 8386 else { |
| 8387 this._lang_error(('expected ' + expected + ', but found ' + tok), tok.get$sp
an()); |
| 8388 } |
| 8389 } |
| 8390 Parser.prototype._lang_error = function(message, location) { |
| 8391 if (this._recover) return; |
| 8392 if (location == null) { |
| 8393 location = this._peekToken.get$span(); |
| 8394 } |
| 8395 $globals.world.fatal(message, location); |
| 8396 this._recover = true; |
| 8397 } |
| 8398 Parser.prototype._skipBlock = function() { |
| 8399 var depth = 1; |
| 8400 this._eat(6/*TokenKind.LBRACE*/); |
| 8401 while (true) { |
| 8402 var tok = this._lang_next(); |
| 8403 if ($eq(tok.get$kind(), 6/*TokenKind.LBRACE*/)) { |
| 8404 depth += 1; |
| 8405 } |
| 8406 else if ($eq(tok.get$kind(), 7/*TokenKind.RBRACE*/)) { |
| 8407 depth -= 1; |
| 8408 if (depth == 0) return; |
| 8409 } |
| 8410 else if ($eq(tok.get$kind(), 1/*TokenKind.END_OF_FILE*/)) { |
| 8411 this._lang_error('unexpected end of file during diet parse', tok.get$span(
)); |
| 8412 return; |
| 8413 } |
| 8414 } |
| 8415 } |
| 8416 Parser.prototype._makeSpan = function(start) { |
| 8417 return new SourceSpan(this.source, start, this._previousToken.end); |
| 8418 } |
| 8419 Parser.prototype.compilationUnit = function() { |
| 8420 var ret = []; |
| 8421 this._maybeEat(13/*TokenKind.HASHBANG*/); |
| 8422 while (this._peekKind(12/*TokenKind.HASH*/)) { |
| 8423 ret.add$1(this.directive()); |
| 8424 } |
| 8425 this._recover = false; |
| 8426 while (!this._maybeEat(1/*TokenKind.END_OF_FILE*/)) { |
| 8427 ret.add$1(this.topLevelDefinition()); |
| 8428 } |
| 8429 this._recover = false; |
| 8430 return ret; |
| 8431 } |
| 8432 Parser.prototype.directive = function() { |
| 8433 var start = this._peekToken.start; |
| 8434 this._eat(12/*TokenKind.HASH*/); |
| 8435 var name = this.identifier(); |
| 8436 var args = this.arguments(); |
| 8437 this._eatSemicolon(); |
| 8438 return new DirectiveDefinition(name, args, this._makeSpan(start)); |
| 8439 } |
| 8440 Parser.prototype.topLevelDefinition = function() { |
| 8441 switch (this._peek()) { |
| 8442 case 73/*TokenKind.CLASS*/: |
| 8443 |
| 8444 return this.classDefinition(73/*TokenKind.CLASS*/); |
| 8445 |
| 8446 case 79/*TokenKind.INTERFACE*/: |
| 8447 |
| 8448 return this.classDefinition(79/*TokenKind.INTERFACE*/); |
| 8449 |
| 8450 case 87/*TokenKind.TYPEDEF*/: |
| 8451 |
| 8452 return this.functionTypeAlias(); |
| 8453 |
| 8454 default: |
| 8455 |
| 8456 return this.declaration(true); |
| 8457 |
| 8458 } |
| 8459 } |
| 8460 Parser.prototype.classDefinition = function(kind) { |
| 8461 var start = this._peekToken.start; |
| 8462 this._eat(kind); |
| 8463 var name = this.identifier(); |
| 8464 var typeParams = null; |
| 8465 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 8466 typeParams = this.typeParameters(); |
| 8467 } |
| 8468 var _extends = null; |
| 8469 if (this._maybeEat(74/*TokenKind.EXTENDS*/)) { |
| 8470 _extends = this.typeList(); |
| 8471 } |
| 8472 var _implements = null; |
| 8473 if (this._maybeEat(77/*TokenKind.IMPLEMENTS*/)) { |
| 8474 _implements = this.typeList(); |
| 8475 } |
| 8476 var _native = null; |
| 8477 if (this._maybeEat(81/*TokenKind.NATIVE*/)) { |
| 8478 _native = this.maybeStringLiteral(); |
| 8479 if (_native != null) _native = new NativeType(_native); |
| 8480 } |
| 8481 var _factory = null; |
| 8482 if (this._maybeEat(75/*TokenKind.FACTORY*/)) { |
| 8483 _factory = this.nameTypeReference(); |
| 8484 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 8485 this.typeParameters(); |
| 8486 } |
| 8487 } |
| 8488 var body = []; |
| 8489 if (this._maybeEat(6/*TokenKind.LBRACE*/)) { |
| 8490 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 8491 body.add$1(this.declaration(true)); |
| 8492 if (this._recover) { |
| 8493 if (!this._recoverTo(7/*TokenKind.RBRACE*/, 10/*TokenKind.SEMICOLON*/))
break; |
| 8494 this._maybeEat(10/*TokenKind.SEMICOLON*/); |
| 8495 } |
| 8496 } |
| 8497 } |
| 8498 else { |
| 8499 this._errorExpected('block starting with "{" or ";"'); |
| 8500 } |
| 8501 return new TypeDefinition(kind == 73/*TokenKind.CLASS*/, name, typeParams, _ex
tends, _implements, _native, _factory, body, this._makeSpan(start)); |
| 8502 } |
| 8503 Parser.prototype.functionTypeAlias = function() { |
| 8504 var start = this._peekToken.start; |
| 8505 this._eat(87/*TokenKind.TYPEDEF*/); |
| 8506 var di = this.declaredIdentifier(false); |
| 8507 var typeParams = null; |
| 8508 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 8509 typeParams = this.typeParameters(); |
| 8510 } |
| 8511 var formals = this.formalParameterList(); |
| 8512 this._eatSemicolon(); |
| 8513 var func = new FunctionDefinition(null, di.get$type(), di.get$name(), formals,
null, null, null, null, this._makeSpan(start)); |
| 8514 return new FunctionTypeDefinition(func, typeParams, this._makeSpan(start)); |
| 8515 } |
| 8516 Parser.prototype.initializers = function() { |
| 8517 this._inhibitLambda = true; |
| 8518 var ret = []; |
| 8519 do { |
| 8520 ret.add$1(this.expression()); |
| 8521 } |
| 8522 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 8523 this._inhibitLambda = false; |
| 8524 return ret; |
| 8525 } |
| 8526 Parser.prototype.get$initializers = function() { |
| 8527 return Parser.prototype.initializers.bind(this); |
| 8528 } |
| 8529 Parser.prototype.functionBody = function(inExpression) { |
| 8530 var start = this._peekToken.start; |
| 8531 if (this._maybeEat(9/*TokenKind.ARROW*/)) { |
| 8532 var expr = this.expression(); |
| 8533 if (!inExpression) { |
| 8534 this._eatSemicolon(); |
| 8535 } |
| 8536 return new ReturnStatement(expr, this._makeSpan(start)); |
| 8537 } |
| 8538 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 8539 if (this.diet) { |
| 8540 this._skipBlock(); |
| 8541 return new DietStatement(this._makeSpan(start)); |
| 8542 } |
| 8543 else { |
| 8544 return this.block(); |
| 8545 } |
| 8546 } |
| 8547 else if (!inExpression) { |
| 8548 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 8549 return null; |
| 8550 } |
| 8551 } |
| 8552 this._lang_error('Expected function body (neither { nor => found)'); |
| 8553 } |
| 8554 Parser.prototype.finishField = function(start, modifiers, typeParams, type, name
, value) { |
| 8555 if (typeParams != null) { |
| 8556 $globals.world.internalError('trying to create a generic field', this._makeS
pan(start)); |
| 8557 } |
| 8558 var names = [name]; |
| 8559 var values = [value]; |
| 8560 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 8561 names.add$1(this.identifier()); |
| 8562 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 8563 values.add$1(this.expression()); |
| 8564 } |
| 8565 else { |
| 8566 values.add$1(); |
| 8567 } |
| 8568 } |
| 8569 this._eatSemicolon(); |
| 8570 return new VariableDefinition(modifiers, type, names, values, this._makeSpan(s
tart)); |
| 8571 } |
| 8572 Parser.prototype.finishDefinition = function(start, modifiers, di, typeParams) { |
| 8573 switch (this._peek()) { |
| 8574 case 2/*TokenKind.LPAREN*/: |
| 8575 |
| 8576 var formals = this.formalParameterList(); |
| 8577 var inits = null, native_ = null; |
| 8578 if (this._maybeEat(8/*TokenKind.COLON*/)) { |
| 8579 inits = this.initializers(); |
| 8580 } |
| 8581 if (this._maybeEat(81/*TokenKind.NATIVE*/)) { |
| 8582 native_ = this.maybeStringLiteral(); |
| 8583 if (native_ == null) native_ = ''; |
| 8584 } |
| 8585 var body = this.functionBody(false); |
| 8586 if (di.get$name() == null) { |
| 8587 di.set$name(di.get$type().get$name()); |
| 8588 } |
| 8589 return new FunctionDefinition(modifiers, di.get$type(), di.get$name(), for
mals, typeParams, inits, native_, body, this._makeSpan(start)); |
| 8590 |
| 8591 case 20/*TokenKind.ASSIGN*/: |
| 8592 |
| 8593 this._eat(20/*TokenKind.ASSIGN*/); |
| 8594 var value = this.expression(); |
| 8595 return this.finishField(start, modifiers, typeParams, di.get$type(), di.ge
t$name(), value); |
| 8596 |
| 8597 case 11/*TokenKind.COMMA*/: |
| 8598 case 10/*TokenKind.SEMICOLON*/: |
| 8599 |
| 8600 return this.finishField(start, modifiers, typeParams, di.get$type(), di.ge
t$name(), null); |
| 8601 |
| 8602 default: |
| 8603 |
| 8604 this._errorExpected('declaration'); |
| 8605 return null; |
| 8606 |
| 8607 } |
| 8608 } |
| 8609 Parser.prototype.declaration = function(includeOperators) { |
| 8610 var start = this._peekToken.start; |
| 8611 if (this._peekKind(75/*TokenKind.FACTORY*/)) { |
| 8612 return this.factoryConstructorDeclaration(); |
| 8613 } |
| 8614 var modifiers = this._readModifiers(); |
| 8615 return this.finishDefinition(start, modifiers, this.declaredIdentifier(include
Operators), null); |
| 8616 } |
| 8617 Parser.prototype.factoryConstructorDeclaration = function() { |
| 8618 var start = this._peekToken.start; |
| 8619 var factoryToken = this._lang_next(); |
| 8620 var names = [this.identifier()]; |
| 8621 while (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 8622 names.add$1(this.identifier()); |
| 8623 } |
| 8624 var typeParams = null; |
| 8625 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 8626 typeParams = this.typeParameters(); |
| 8627 } |
| 8628 var name = null; |
| 8629 var type = null; |
| 8630 if (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 8631 name = this.identifier(); |
| 8632 } |
| 8633 else if (typeParams == null) { |
| 8634 if (names.length > 1) { |
| 8635 name = names.removeLast$0(); |
| 8636 } |
| 8637 else { |
| 8638 name = new Identifier('', names.$index(0).get$span()); |
| 8639 } |
| 8640 } |
| 8641 else { |
| 8642 name = new Identifier('', names.$index(0).get$span()); |
| 8643 } |
| 8644 if (names.length > 1) { |
| 8645 this._lang_error('unsupported qualified name for factory', names.$index(0).g
et$span()); |
| 8646 } |
| 8647 type = new NameTypeReference(false, names.$index(0), null, names.$index(0).get
$span()); |
| 8648 var di = new DeclaredIdentifier(type, name, this._makeSpan(start)); |
| 8649 return this.finishDefinition(start, [factoryToken], di, typeParams); |
| 8650 } |
| 8651 Parser.prototype.statement = function() { |
| 8652 switch (this._peek()) { |
| 8653 case 89/*TokenKind.BREAK*/: |
| 8654 |
| 8655 return this.breakStatement(); |
| 8656 |
| 8657 case 93/*TokenKind.CONTINUE*/: |
| 8658 |
| 8659 return this.continueStatement(); |
| 8660 |
| 8661 case 106/*TokenKind.RETURN*/: |
| 8662 |
| 8663 return this.returnStatement(); |
| 8664 |
| 8665 case 110/*TokenKind.THROW*/: |
| 8666 |
| 8667 return this.throwStatement(); |
| 8668 |
| 8669 case 72/*TokenKind.ASSERT*/: |
| 8670 |
| 8671 return this.assertStatement(); |
| 8672 |
| 8673 case 115/*TokenKind.WHILE*/: |
| 8674 |
| 8675 return this.whileStatement(); |
| 8676 |
| 8677 case 95/*TokenKind.DO*/: |
| 8678 |
| 8679 return this.doStatement(); |
| 8680 |
| 8681 case 100/*TokenKind.FOR*/: |
| 8682 |
| 8683 return this.forStatement(); |
| 8684 |
| 8685 case 101/*TokenKind.IF*/: |
| 8686 |
| 8687 return this.ifStatement(); |
| 8688 |
| 8689 case 108/*TokenKind.SWITCH*/: |
| 8690 |
| 8691 return this.switchStatement(); |
| 8692 |
| 8693 case 112/*TokenKind.TRY*/: |
| 8694 |
| 8695 return this.tryStatement(); |
| 8696 |
| 8697 case 6/*TokenKind.LBRACE*/: |
| 8698 |
| 8699 return this.block(); |
| 8700 |
| 8701 case 10/*TokenKind.SEMICOLON*/: |
| 8702 |
| 8703 return this.emptyStatement(); |
| 8704 |
| 8705 case 98/*TokenKind.FINAL*/: |
| 8706 |
| 8707 return this.declaration(false); |
| 8708 |
| 8709 case 113/*TokenKind.VAR*/: |
| 8710 |
| 8711 return this.declaration(false); |
| 8712 |
| 8713 default: |
| 8714 |
| 8715 return this.finishExpressionAsStatement(this.expression()); |
| 8716 |
| 8717 } |
| 8718 } |
| 8719 Parser.prototype.finishExpressionAsStatement = function(expr) { |
| 8720 var start = expr.get$span().get$start(); |
| 8721 if (this._maybeEat(8/*TokenKind.COLON*/)) { |
| 8722 var label = this._makeLabel(expr); |
| 8723 return new LabeledStatement(label, this.statement(), this._makeSpan(start)); |
| 8724 } |
| 8725 if ((expr instanceof LambdaExpression)) { |
| 8726 if (!(expr.get$func().get$body() instanceof BlockStatement)) { |
| 8727 this._eatSemicolon(); |
| 8728 expr.get$func().set$span(this._makeSpan(start)); |
| 8729 } |
| 8730 return expr.get$func(); |
| 8731 } |
| 8732 else if ((expr instanceof DeclaredIdentifier)) { |
| 8733 var value = null; |
| 8734 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 8735 value = this.expression(); |
| 8736 } |
| 8737 return this.finishField(start, null, null, expr.get$type(), expr.get$name(),
value); |
| 8738 } |
| 8739 else if (this._isBin(expr, 20/*TokenKind.ASSIGN*/) && ((expr.get$x() instanceo
f DeclaredIdentifier))) { |
| 8740 var di = expr.get$x(); |
| 8741 return this.finishField(start, null, null, di.type, di.name, expr.get$y()); |
| 8742 } |
| 8743 else if (this._isBin(expr, 52/*TokenKind.LT*/) && this._maybeEat(11/*TokenKind
.COMMA*/)) { |
| 8744 var baseType = this._makeType(expr.get$x()); |
| 8745 var typeArgs = [this._makeType(expr.get$y())]; |
| 8746 var gt = this._finishTypeArguments(baseType, 0, typeArgs); |
| 8747 var name = this.identifier(); |
| 8748 var value = null; |
| 8749 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 8750 value = this.expression(); |
| 8751 } |
| 8752 return this.finishField(expr.get$span().get$start(), null, null, gt, name, v
alue); |
| 8753 } |
| 8754 else { |
| 8755 this._eatSemicolon(); |
| 8756 return new ExpressionStatement(expr, this._makeSpan(expr.get$span().get$star
t())); |
| 8757 } |
| 8758 } |
| 8759 Parser.prototype.testCondition = function() { |
| 8760 this._eatLeftParen(); |
| 8761 var ret = this.expression(); |
| 8762 this._eat(3/*TokenKind.RPAREN*/); |
| 8763 return ret; |
| 8764 } |
| 8765 Parser.prototype.block = function() { |
| 8766 var start = this._peekToken.start; |
| 8767 this._eat(6/*TokenKind.LBRACE*/); |
| 8768 var stmts = []; |
| 8769 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 8770 stmts.add$1(this.statement()); |
| 8771 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 10/*TokenKind.S
EMICOLON*/)) break; |
| 8772 } |
| 8773 this._recover = false; |
| 8774 return new BlockStatement(stmts, this._makeSpan(start)); |
| 8775 } |
| 8776 Parser.prototype.emptyStatement = function() { |
| 8777 var start = this._peekToken.start; |
| 8778 this._eat(10/*TokenKind.SEMICOLON*/); |
| 8779 return new EmptyStatement(this._makeSpan(start)); |
| 8780 } |
| 8781 Parser.prototype.ifStatement = function() { |
| 8782 var start = this._peekToken.start; |
| 8783 this._eat(101/*TokenKind.IF*/); |
| 8784 var test = this.testCondition(); |
| 8785 var trueBranch = this.statement(); |
| 8786 var falseBranch = null; |
| 8787 if (this._maybeEat(96/*TokenKind.ELSE*/)) { |
| 8788 falseBranch = this.statement(); |
| 8789 } |
| 8790 return new IfStatement(test, trueBranch, falseBranch, this._makeSpan(start)); |
| 8791 } |
| 8792 Parser.prototype.whileStatement = function() { |
| 8793 var start = this._peekToken.start; |
| 8794 this._eat(115/*TokenKind.WHILE*/); |
| 8795 var test = this.testCondition(); |
| 8796 var body = this.statement(); |
| 8797 return new WhileStatement(test, body, this._makeSpan(start)); |
| 8798 } |
| 8799 Parser.prototype.doStatement = function() { |
| 8800 var start = this._peekToken.start; |
| 8801 this._eat(95/*TokenKind.DO*/); |
| 8802 var body = this.statement(); |
| 8803 this._eat(115/*TokenKind.WHILE*/); |
| 8804 var test = this.testCondition(); |
| 8805 this._eatSemicolon(); |
| 8806 return new DoStatement(body, test, this._makeSpan(start)); |
| 8807 } |
| 8808 Parser.prototype.forStatement = function() { |
| 8809 var start = this._peekToken.start; |
| 8810 this._eat(100/*TokenKind.FOR*/); |
| 8811 this._eatLeftParen(); |
| 8812 var init = this.forInitializerStatement(start); |
| 8813 if ((init instanceof ForInStatement)) { |
| 8814 return init; |
| 8815 } |
| 8816 var test = null; |
| 8817 if (!this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 8818 test = this.expression(); |
| 8819 this._eatSemicolon(); |
| 8820 } |
| 8821 var step = []; |
| 8822 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 8823 step.add$1(this.expression()); |
| 8824 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 8825 step.add$1(this.expression()); |
| 8826 } |
| 8827 this._eat(3/*TokenKind.RPAREN*/); |
| 8828 } |
| 8829 var body = this.statement(); |
| 8830 return new ForStatement(init, test, step, body, this._makeSpan(start)); |
| 8831 } |
| 8832 Parser.prototype.forInitializerStatement = function(start) { |
| 8833 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 8834 return null; |
| 8835 } |
| 8836 else { |
| 8837 var init = this.expression(); |
| 8838 if (this._peekKind(11/*TokenKind.COMMA*/) && this._isBin(init, 52/*TokenKind
.LT*/)) { |
| 8839 this._eat(11/*TokenKind.COMMA*/); |
| 8840 var baseType = this._makeType(init.get$x()); |
| 8841 var typeArgs = [this._makeType(init.get$y())]; |
| 8842 var gt = this._finishTypeArguments(baseType, 0, typeArgs); |
| 8843 var name = this.identifier(); |
| 8844 init = new DeclaredIdentifier(gt, name, this._makeSpan(init.get$span().get
$start())); |
| 8845 } |
| 8846 if (this._maybeEat(102/*TokenKind.IN*/)) { |
| 8847 return this._finishForIn(start, this._makeDeclaredIdentifier(init)); |
| 8848 } |
| 8849 else { |
| 8850 return this.finishExpressionAsStatement(init); |
| 8851 } |
| 8852 } |
| 8853 } |
| 8854 Parser.prototype._finishForIn = function(start, di) { |
| 8855 var expr = this.expression(); |
| 8856 this._eat(3/*TokenKind.RPAREN*/); |
| 8857 var body = this.statement(); |
| 8858 return new ForInStatement(di, expr, body, this._makeSpan(start)); |
| 8859 } |
| 8860 Parser.prototype.tryStatement = function() { |
| 8861 var start = this._peekToken.start; |
| 8862 this._eat(112/*TokenKind.TRY*/); |
| 8863 var body = this.block(); |
| 8864 var catches = []; |
| 8865 while (this._peekKind(91/*TokenKind.CATCH*/)) { |
| 8866 catches.add$1(this.catchNode()); |
| 8867 } |
| 8868 var finallyBlock = null; |
| 8869 if (this._maybeEat(99/*TokenKind.FINALLY*/)) { |
| 8870 finallyBlock = this.block(); |
| 8871 } |
| 8872 return new TryStatement(body, catches, finallyBlock, this._makeSpan(start)); |
| 8873 } |
| 8874 Parser.prototype.catchNode = function() { |
| 8875 var start = this._peekToken.start; |
| 8876 this._eat(91/*TokenKind.CATCH*/); |
| 8877 this._eatLeftParen(); |
| 8878 var exc = this.declaredIdentifier(false); |
| 8879 var trace = null; |
| 8880 if (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 8881 trace = this.declaredIdentifier(false); |
| 8882 } |
| 8883 this._eat(3/*TokenKind.RPAREN*/); |
| 8884 var body = this.block(); |
| 8885 return new CatchNode(exc, trace, body, this._makeSpan(start)); |
| 8886 } |
| 8887 Parser.prototype.switchStatement = function() { |
| 8888 var start = this._peekToken.start; |
| 8889 this._eat(108/*TokenKind.SWITCH*/); |
| 8890 var test = this.testCondition(); |
| 8891 var cases = []; |
| 8892 this._eat(6/*TokenKind.LBRACE*/); |
| 8893 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 8894 cases.add$1(this.caseNode()); |
| 8895 } |
| 8896 return new SwitchStatement(test, cases, this._makeSpan(start)); |
| 8897 } |
| 8898 Parser.prototype._peekCaseEnd = function() { |
| 8899 var kind = this._peek(); |
| 8900 return $eq(kind, 7/*TokenKind.RBRACE*/) || $eq(kind, 90/*TokenKind.CASE*/) ||
$eq(kind, 94/*TokenKind.DEFAULT*/); |
| 8901 } |
| 8902 Parser.prototype.caseNode = function() { |
| 8903 var start = this._peekToken.start; |
| 8904 var label = null; |
| 8905 if (this._peekIdentifier()) { |
| 8906 label = this.identifier(); |
| 8907 this._eat(8/*TokenKind.COLON*/); |
| 8908 } |
| 8909 var cases = []; |
| 8910 while (true) { |
| 8911 if (this._maybeEat(90/*TokenKind.CASE*/)) { |
| 8912 cases.add$1(this.expression()); |
| 8913 this._eat(8/*TokenKind.COLON*/); |
| 8914 } |
| 8915 else if (this._maybeEat(94/*TokenKind.DEFAULT*/)) { |
| 8916 cases.add$1(); |
| 8917 this._eat(8/*TokenKind.COLON*/); |
| 8918 } |
| 8919 else { |
| 8920 break; |
| 8921 } |
| 8922 } |
| 8923 if ($eq(cases.length, 0)) { |
| 8924 this._lang_error('case or default'); |
| 8925 } |
| 8926 var stmts = []; |
| 8927 while (!this._peekCaseEnd()) { |
| 8928 stmts.add$1(this.statement()); |
| 8929 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 90/*TokenKind.C
ASE*/, 94/*TokenKind.DEFAULT*/)) { |
| 8930 break; |
| 8931 } |
| 8932 } |
| 8933 return new CaseNode(label, cases, stmts, this._makeSpan(start)); |
| 8934 } |
| 8935 Parser.prototype.returnStatement = function() { |
| 8936 var start = this._peekToken.start; |
| 8937 this._eat(106/*TokenKind.RETURN*/); |
| 8938 var expr; |
| 8939 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 8940 expr = null; |
| 8941 } |
| 8942 else { |
| 8943 expr = this.expression(); |
| 8944 this._eatSemicolon(); |
| 8945 } |
| 8946 return new ReturnStatement(expr, this._makeSpan(start)); |
| 8947 } |
| 8948 Parser.prototype.throwStatement = function() { |
| 8949 var start = this._peekToken.start; |
| 8950 this._eat(110/*TokenKind.THROW*/); |
| 8951 var expr; |
| 8952 if (this._maybeEat(10/*TokenKind.SEMICOLON*/)) { |
| 8953 expr = null; |
| 8954 } |
| 8955 else { |
| 8956 expr = this.expression(); |
| 8957 this._eatSemicolon(); |
| 8958 } |
| 8959 return new ThrowStatement(expr, this._makeSpan(start)); |
| 8960 } |
| 8961 Parser.prototype.assertStatement = function() { |
| 8962 var start = this._peekToken.start; |
| 8963 this._eat(72/*TokenKind.ASSERT*/); |
| 8964 this._eatLeftParen(); |
| 8965 var expr = this.expression(); |
| 8966 this._eat(3/*TokenKind.RPAREN*/); |
| 8967 this._eatSemicolon(); |
| 8968 return new AssertStatement(expr, this._makeSpan(start)); |
| 8969 } |
| 8970 Parser.prototype.breakStatement = function() { |
| 8971 var start = this._peekToken.start; |
| 8972 this._eat(89/*TokenKind.BREAK*/); |
| 8973 var name = null; |
| 8974 if (this._peekIdentifier()) { |
| 8975 name = this.identifier(); |
| 8976 } |
| 8977 this._eatSemicolon(); |
| 8978 return new BreakStatement(name, this._makeSpan(start)); |
| 8979 } |
| 8980 Parser.prototype.continueStatement = function() { |
| 8981 var start = this._peekToken.start; |
| 8982 this._eat(93/*TokenKind.CONTINUE*/); |
| 8983 var name = null; |
| 8984 if (this._peekIdentifier()) { |
| 8985 name = this.identifier(); |
| 8986 } |
| 8987 this._eatSemicolon(); |
| 8988 return new ContinueStatement(name, this._makeSpan(start)); |
| 8989 } |
| 8990 Parser.prototype.expression = function() { |
| 8991 return this.infixExpression(0); |
| 8992 } |
| 8993 Parser.prototype._makeType = function(expr) { |
| 8994 if ((expr instanceof VarExpression)) { |
| 8995 return new NameTypeReference(false, expr.get$name(), null, expr.get$span()); |
| 8996 } |
| 8997 else if ((expr instanceof DotExpression)) { |
| 8998 var type = this._makeType(expr.get$self()); |
| 8999 if (type.get$names() == null) { |
| 9000 type.set$names([expr.get$name()]); |
| 9001 } |
| 9002 else { |
| 9003 type.get$names().add$1(expr.get$name()); |
| 9004 } |
| 9005 type.set$span(expr.get$span()); |
| 9006 return type; |
| 9007 } |
| 9008 else { |
| 9009 this._lang_error('expected type reference'); |
| 9010 return null; |
| 9011 } |
| 9012 } |
| 9013 Parser.prototype.infixExpression = function(precedence) { |
| 9014 return this.finishInfixExpression(this.unaryExpression(), precedence); |
| 9015 } |
| 9016 Parser.prototype._finishDeclaredId = function(type) { |
| 9017 var name = this.identifier(); |
| 9018 return this.finishPostfixExpression(new DeclaredIdentifier(type, name, this._m
akeSpan(type.get$span().get$start()))); |
| 9019 } |
| 9020 Parser.prototype._fixAsType = function(x) { |
| 9021 if (this._maybeEat(53/*TokenKind.GT*/)) { |
| 9022 var base = this._makeType(x.x); |
| 9023 var typeParam = this._makeType(x.y); |
| 9024 var type = new GenericTypeReference(base, [typeParam], 0, this._makeSpan(x.s
pan.start)); |
| 9025 return this._finishDeclaredId(type); |
| 9026 } |
| 9027 else { |
| 9028 var base = this._makeType(x.x); |
| 9029 var paramBase = this._makeType(x.y); |
| 9030 var firstParam = this.addTypeArguments(paramBase, 1); |
| 9031 var type; |
| 9032 if (firstParam.get$depth() <= 0) { |
| 9033 type = new GenericTypeReference(base, [firstParam], 0, this._makeSpan(x.sp
an.start)); |
| 9034 } |
| 9035 else if (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9036 type = this._finishTypeArguments(base, 0, [firstParam]); |
| 9037 } |
| 9038 else { |
| 9039 this._eat(53/*TokenKind.GT*/); |
| 9040 type = new GenericTypeReference(base, [firstParam], 0, this._makeSpan(x.sp
an.start)); |
| 9041 } |
| 9042 return this._finishDeclaredId(type); |
| 9043 } |
| 9044 } |
| 9045 Parser.prototype.finishInfixExpression = function(x, precedence) { |
| 9046 while (true) { |
| 9047 var kind = this._peek(); |
| 9048 var prec = TokenKind.infixPrecedence(this._peek()); |
| 9049 if (prec >= precedence) { |
| 9050 if (kind == 52/*TokenKind.LT*/ || kind == 53/*TokenKind.GT*/) { |
| 9051 if (this._isBin(x, 52/*TokenKind.LT*/)) { |
| 9052 return this._fixAsType(x); |
| 9053 } |
| 9054 } |
| 9055 var op = this._lang_next(); |
| 9056 if ($eq(op.get$kind(), 103/*TokenKind.IS*/)) { |
| 9057 var isTrue = !this._maybeEat(19/*TokenKind.NOT*/); |
| 9058 var typeRef = this.type(0); |
| 9059 x = new IsExpression(isTrue, x, typeRef, this._makeSpan(x.span.start)); |
| 9060 continue; |
| 9061 } |
| 9062 var y = this.infixExpression($eq(prec, 2) ? prec : prec + 1); |
| 9063 if ($eq(op.get$kind(), 33/*TokenKind.CONDITIONAL*/)) { |
| 9064 this._eat(8/*TokenKind.COLON*/); |
| 9065 var z = this.infixExpression(prec); |
| 9066 x = new ConditionalExpression(x, y, z, this._makeSpan(x.span.start)); |
| 9067 } |
| 9068 else { |
| 9069 x = new BinaryExpression(op, x, y, this._makeSpan(x.span.start)); |
| 9070 } |
| 9071 } |
| 9072 else { |
| 9073 break; |
| 9074 } |
| 9075 } |
| 9076 return x; |
| 9077 } |
| 9078 Parser.prototype._isPrefixUnaryOperator = function(kind) { |
| 9079 switch (kind) { |
| 9080 case 42/*TokenKind.ADD*/: |
| 9081 case 43/*TokenKind.SUB*/: |
| 9082 case 19/*TokenKind.NOT*/: |
| 9083 case 18/*TokenKind.BIT_NOT*/: |
| 9084 case 16/*TokenKind.INCR*/: |
| 9085 case 17/*TokenKind.DECR*/: |
| 9086 |
| 9087 return true; |
| 9088 |
| 9089 default: |
| 9090 |
| 9091 return false; |
| 9092 |
| 9093 } |
| 9094 } |
| 9095 Parser.prototype.unaryExpression = function() { |
| 9096 var start = this._peekToken.start; |
| 9097 if (this._isPrefixUnaryOperator(this._peek())) { |
| 9098 var tok = this._lang_next(); |
| 9099 var expr = this.unaryExpression(); |
| 9100 return new UnaryExpression(tok, expr, this._makeSpan(start)); |
| 9101 } |
| 9102 else if (this.get$enableAwait() && this._maybeEat(88/*TokenKind.AWAIT*/)) { |
| 9103 var expr = this.unaryExpression(); |
| 9104 return new AwaitExpression(expr, this._makeSpan(start)); |
| 9105 } |
| 9106 return this.finishPostfixExpression(this.primary()); |
| 9107 } |
| 9108 Parser.prototype.argument = function() { |
| 9109 var start = this._peekToken.start; |
| 9110 var expr; |
| 9111 var label = null; |
| 9112 if (this._maybeEat(15/*TokenKind.ELLIPSIS*/)) { |
| 9113 label = new Identifier('...', this._makeSpan(start)); |
| 9114 } |
| 9115 expr = this.expression(); |
| 9116 if (label == null && this._maybeEat(8/*TokenKind.COLON*/)) { |
| 9117 label = this._makeLabel(expr); |
| 9118 expr = this.expression(); |
| 9119 } |
| 9120 return new ArgumentNode(label, expr, this._makeSpan(start)); |
| 9121 } |
| 9122 Parser.prototype.arguments = function() { |
| 9123 var args = []; |
| 9124 this._eatLeftParen(); |
| 9125 var saved = this._inhibitLambda; |
| 9126 this._inhibitLambda = false; |
| 9127 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 9128 do { |
| 9129 args.add$1(this.argument()); |
| 9130 } |
| 9131 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9132 this._eat(3/*TokenKind.RPAREN*/); |
| 9133 } |
| 9134 this._inhibitLambda = saved; |
| 9135 return args; |
| 9136 } |
| 9137 Parser.prototype.get$arguments = function() { |
| 9138 return Parser.prototype.arguments.bind(this); |
| 9139 } |
| 9140 Parser.prototype.finishPostfixExpression = function(expr) { |
| 9141 switch (this._peek()) { |
| 9142 case 2/*TokenKind.LPAREN*/: |
| 9143 |
| 9144 return this.finishCallOrLambdaExpression(expr); |
| 9145 |
| 9146 case 4/*TokenKind.LBRACK*/: |
| 9147 |
| 9148 this._eat(4/*TokenKind.LBRACK*/); |
| 9149 var index = this.expression(); |
| 9150 this._eat(5/*TokenKind.RBRACK*/); |
| 9151 return this.finishPostfixExpression(new IndexExpression(expr, index, this.
_makeSpan(expr.get$span().get$start()))); |
| 9152 |
| 9153 case 14/*TokenKind.DOT*/: |
| 9154 |
| 9155 this._eat(14/*TokenKind.DOT*/); |
| 9156 var name = this.identifier(); |
| 9157 var ret = new DotExpression(expr, name, this._makeSpan(expr.get$span().get
$start())); |
| 9158 return this.finishPostfixExpression(ret); |
| 9159 |
| 9160 case 16/*TokenKind.INCR*/: |
| 9161 case 17/*TokenKind.DECR*/: |
| 9162 |
| 9163 var tok = this._lang_next(); |
| 9164 return new PostfixExpression(expr, tok, this._makeSpan(expr.get$span().get
$start())); |
| 9165 |
| 9166 case 9/*TokenKind.ARROW*/: |
| 9167 case 6/*TokenKind.LBRACE*/: |
| 9168 |
| 9169 return expr; |
| 9170 |
| 9171 default: |
| 9172 |
| 9173 if (this._peekIdentifier()) { |
| 9174 return this.finishPostfixExpression(new DeclaredIdentifier(this._makeTyp
e(expr), this.identifier(), this._makeSpan(expr.get$span().get$start()))); |
| 9175 } |
| 9176 else { |
| 9177 return expr; |
| 9178 } |
| 9179 |
| 9180 } |
| 9181 } |
| 9182 Parser.prototype.finishCallOrLambdaExpression = function(expr) { |
| 9183 if (this._atClosureParameters()) { |
| 9184 var formals = this.formalParameterList(); |
| 9185 var body = this.functionBody(true); |
| 9186 return this._makeFunction(expr, formals, body); |
| 9187 } |
| 9188 else { |
| 9189 if ((expr instanceof DeclaredIdentifier)) { |
| 9190 this._lang_error('illegal target for call, did you mean to declare a funct
ion?', expr.get$span()); |
| 9191 } |
| 9192 var args = this.arguments(); |
| 9193 return this.finishPostfixExpression(new CallExpression(expr, args, this._mak
eSpan(expr.get$span().get$start()))); |
| 9194 } |
| 9195 } |
| 9196 Parser.prototype._isBin = function(expr, kind) { |
| 9197 return (expr instanceof BinaryExpression) && $eq(expr.get$op().get$kind(), kin
d); |
| 9198 } |
| 9199 Parser.prototype._boolTypeRef = function(span) { |
| 9200 return new TypeReference(span, $globals.world.nonNullBool); |
| 9201 } |
| 9202 Parser.prototype._intTypeRef = function(span) { |
| 9203 return new TypeReference(span, $globals.world.intType); |
| 9204 } |
| 9205 Parser.prototype._doubleTypeRef = function(span) { |
| 9206 return new TypeReference(span, $globals.world.doubleType); |
| 9207 } |
| 9208 Parser.prototype._stringTypeRef = function(span) { |
| 9209 return new TypeReference(span, $globals.world.stringType); |
| 9210 } |
| 9211 Parser.prototype.primary = function() { |
| 9212 var start = this._peekToken.start; |
| 9213 switch (this._peek()) { |
| 9214 case 109/*TokenKind.THIS*/: |
| 9215 |
| 9216 this._eat(109/*TokenKind.THIS*/); |
| 9217 return new ThisExpression(this._makeSpan(start)); |
| 9218 |
| 9219 case 107/*TokenKind.SUPER*/: |
| 9220 |
| 9221 this._eat(107/*TokenKind.SUPER*/); |
| 9222 return new SuperExpression(this._makeSpan(start)); |
| 9223 |
| 9224 case 92/*TokenKind.CONST*/: |
| 9225 |
| 9226 this._eat(92/*TokenKind.CONST*/); |
| 9227 if (this._peekKind(4/*TokenKind.LBRACK*/) || this._peekKind(56/*TokenKind.
INDEX*/)) { |
| 9228 return this.finishListLiteral(start, true, null); |
| 9229 } |
| 9230 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 9231 return this.finishMapLiteral(start, true, null); |
| 9232 } |
| 9233 else if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9234 return this.finishTypedLiteral(start, true); |
| 9235 } |
| 9236 else { |
| 9237 return this.finishNewExpression(start, true); |
| 9238 } |
| 9239 |
| 9240 case 104/*TokenKind.NEW*/: |
| 9241 |
| 9242 this._eat(104/*TokenKind.NEW*/); |
| 9243 return this.finishNewExpression(start, false); |
| 9244 |
| 9245 case 2/*TokenKind.LPAREN*/: |
| 9246 |
| 9247 return this._parenOrLambda(); |
| 9248 |
| 9249 case 4/*TokenKind.LBRACK*/: |
| 9250 case 56/*TokenKind.INDEX*/: |
| 9251 |
| 9252 return this.finishListLiteral(start, false, null); |
| 9253 |
| 9254 case 6/*TokenKind.LBRACE*/: |
| 9255 |
| 9256 return this.finishMapLiteral(start, false, null); |
| 9257 |
| 9258 case 105/*TokenKind.NULL*/: |
| 9259 |
| 9260 this._eat(105/*TokenKind.NULL*/); |
| 9261 return new NullExpression(this._makeSpan(start)); |
| 9262 |
| 9263 case 111/*TokenKind.TRUE*/: |
| 9264 |
| 9265 this._eat(111/*TokenKind.TRUE*/); |
| 9266 return new LiteralExpression(true, this._boolTypeRef(this._makeSpan(start)
), 'true', this._makeSpan(start)); |
| 9267 |
| 9268 case 97/*TokenKind.FALSE*/: |
| 9269 |
| 9270 this._eat(97/*TokenKind.FALSE*/); |
| 9271 return new LiteralExpression(false, this._boolTypeRef(this._makeSpan(start
)), 'false', this._makeSpan(start)); |
| 9272 |
| 9273 case 61/*TokenKind.HEX_INTEGER*/: |
| 9274 |
| 9275 var t = this._lang_next(); |
| 9276 return new LiteralExpression(Parser.parseHex(t.get$text().substring$1(2)),
this._intTypeRef(this._makeSpan(start)), t.get$text(), this._makeSpan(start)); |
| 9277 |
| 9278 case 60/*TokenKind.INTEGER*/: |
| 9279 |
| 9280 var t = this._lang_next(); |
| 9281 return new LiteralExpression(Math.parseInt(t.get$text()), this._intTypeRef
(this._makeSpan(start)), t.get$text(), this._makeSpan(start)); |
| 9282 |
| 9283 case 62/*TokenKind.DOUBLE*/: |
| 9284 |
| 9285 var t = this._lang_next(); |
| 9286 return new LiteralExpression(Math.parseDouble(t.get$text()), this._doubleT
ypeRef(this._makeSpan(start)), t.get$text(), this._makeSpan(start)); |
| 9287 |
| 9288 case 58/*TokenKind.STRING*/: |
| 9289 |
| 9290 return this.stringLiteralExpr(); |
| 9291 |
| 9292 case 66/*TokenKind.INCOMPLETE_STRING*/: |
| 9293 |
| 9294 return this.stringInterpolation(); |
| 9295 |
| 9296 case 52/*TokenKind.LT*/: |
| 9297 |
| 9298 return this.finishTypedLiteral(start, false); |
| 9299 |
| 9300 case 114/*TokenKind.VOID*/: |
| 9301 case 113/*TokenKind.VAR*/: |
| 9302 case 98/*TokenKind.FINAL*/: |
| 9303 |
| 9304 return this.declaredIdentifier(false); |
| 9305 |
| 9306 default: |
| 9307 |
| 9308 if (!this._peekIdentifier()) { |
| 9309 this._errorExpected('expression'); |
| 9310 } |
| 9311 return new VarExpression(this.identifier(), this._makeSpan(start)); |
| 9312 |
| 9313 } |
| 9314 } |
| 9315 Parser.prototype.stringInterpolation = function() { |
| 9316 var start = this._peekToken.start; |
| 9317 var lits = []; |
| 9318 var startQuote = null, endQuote = null; |
| 9319 while (this._peekKind(66/*TokenKind.INCOMPLETE_STRING*/)) { |
| 9320 var token = this._lang_next(); |
| 9321 var text = token.get$text(); |
| 9322 if (startQuote == null) { |
| 9323 if (isMultilineString(text)) { |
| 9324 endQuote = text.substring$2(0, 3); |
| 9325 startQuote = endQuote + '\n'; |
| 9326 } |
| 9327 else { |
| 9328 startQuote = endQuote = text.$index(0); |
| 9329 } |
| 9330 text = text.substring$2(0, text.length - 1) + endQuote; |
| 9331 } |
| 9332 else { |
| 9333 text = startQuote + text.substring$2(0, text.length - 1) + endQuote; |
| 9334 } |
| 9335 lits.add$1(this.makeStringLiteral(text, token.get$span())); |
| 9336 if (this._maybeEat(6/*TokenKind.LBRACE*/)) { |
| 9337 lits.add$1(this.expression()); |
| 9338 this._eat(7/*TokenKind.RBRACE*/); |
| 9339 } |
| 9340 else if (this._maybeEat(109/*TokenKind.THIS*/)) { |
| 9341 lits.add$1(new ThisExpression(this._previousToken.get$span())); |
| 9342 } |
| 9343 else { |
| 9344 var id = this.identifier(); |
| 9345 lits.add$1(new VarExpression(id, id.get$span())); |
| 9346 } |
| 9347 } |
| 9348 var tok = this._lang_next(); |
| 9349 if ($ne(tok.get$kind(), 58/*TokenKind.STRING*/)) { |
| 9350 this._errorExpected('interpolated string'); |
| 9351 } |
| 9352 var text = startQuote + tok.get$text(); |
| 9353 lits.add$1(this.makeStringLiteral(text, tok.get$span())); |
| 9354 var span = this._makeSpan(start); |
| 9355 return new LiteralExpression(lits, this._stringTypeRef(span), '\$\$\$', span); |
| 9356 } |
| 9357 Parser.prototype.makeStringLiteral = function(text, span) { |
| 9358 return new LiteralExpression(text, this._stringTypeRef(span), text, span); |
| 9359 } |
| 9360 Parser.prototype.stringLiteralExpr = function() { |
| 9361 var token = this._lang_next(); |
| 9362 return this.makeStringLiteral(token.get$text(), token.get$span()); |
| 9363 } |
| 9364 Parser.prototype.maybeStringLiteral = function() { |
| 9365 var kind = this._peek(); |
| 9366 if ($eq(kind, 58/*TokenKind.STRING*/)) { |
| 9367 return parseStringLiteral(this._lang_next().get$text()); |
| 9368 } |
| 9369 else if ($eq(kind, 59/*TokenKind.STRING_PART*/)) { |
| 9370 this._lang_next(); |
| 9371 this._errorExpected('string literal, but found interpolated string start'); |
| 9372 } |
| 9373 else if ($eq(kind, 66/*TokenKind.INCOMPLETE_STRING*/)) { |
| 9374 this._lang_next(); |
| 9375 this._errorExpected('string literal, but found incomplete string'); |
| 9376 } |
| 9377 return null; |
| 9378 } |
| 9379 Parser.prototype._parenOrLambda = function() { |
| 9380 var start = this._peekToken.start; |
| 9381 if (this._atClosureParameters()) { |
| 9382 var formals = this.formalParameterList(); |
| 9383 var body = this.functionBody(true); |
| 9384 var func = new FunctionDefinition(null, null, null, formals, null, null, nul
l, body, this._makeSpan(start)); |
| 9385 return new LambdaExpression(func, func.get$span()); |
| 9386 } |
| 9387 else { |
| 9388 this._eatLeftParen(); |
| 9389 var saved = this._inhibitLambda; |
| 9390 this._inhibitLambda = false; |
| 9391 var expr = this.expression(); |
| 9392 this._eat(3/*TokenKind.RPAREN*/); |
| 9393 this._inhibitLambda = saved; |
| 9394 return new ParenExpression(expr, this._makeSpan(start)); |
| 9395 } |
| 9396 } |
| 9397 Parser.prototype._atClosureParameters = function() { |
| 9398 if (this._inhibitLambda) return false; |
| 9399 var after = this._peekAfterCloseParen(); |
| 9400 return after.kind == 9/*TokenKind.ARROW*/ || after.kind == 6/*TokenKind.LBRACE
*/; |
| 9401 } |
| 9402 Parser.prototype._eatLeftParen = function() { |
| 9403 this._eat(2/*TokenKind.LPAREN*/); |
| 9404 this._afterParensIndex++; |
| 9405 } |
| 9406 Parser.prototype._peekAfterCloseParen = function() { |
| 9407 if (this._afterParensIndex < this._afterParens.length) { |
| 9408 return this._afterParens.$index(this._afterParensIndex); |
| 9409 } |
| 9410 this._afterParensIndex = 0; |
| 9411 this._afterParens.clear(); |
| 9412 var tokens = [this._lang_next()]; |
| 9413 this._lookaheadAfterParens(tokens); |
| 9414 var after = this._peekToken; |
| 9415 tokens.add$1(after); |
| 9416 this.tokenizer = new DivertedTokenSource(tokens, this, this.tokenizer); |
| 9417 this._lang_next(); |
| 9418 return after; |
| 9419 } |
| 9420 Parser.prototype._lookaheadAfterParens = function(tokens) { |
| 9421 var saved = this._afterParens.length; |
| 9422 this._afterParens.add(null); |
| 9423 while (true) { |
| 9424 var token = this._lang_next(); |
| 9425 tokens.add(token); |
| 9426 var kind = token.kind; |
| 9427 if (kind == 3/*TokenKind.RPAREN*/ || kind == 1/*TokenKind.END_OF_FILE*/) { |
| 9428 this._afterParens.$setindex(saved, this._peekToken); |
| 9429 return; |
| 9430 } |
| 9431 else if (kind == 2/*TokenKind.LPAREN*/) { |
| 9432 this._lookaheadAfterParens(tokens); |
| 9433 } |
| 9434 } |
| 9435 } |
| 9436 Parser.prototype._typeAsIdentifier = function(type) { |
| 9437 return type.get$name(); |
| 9438 } |
| 9439 Parser.prototype._specialIdentifier = function(includeOperators) { |
| 9440 var start = this._peekToken.start; |
| 9441 var name; |
| 9442 switch (this._peek()) { |
| 9443 case 15/*TokenKind.ELLIPSIS*/: |
| 9444 |
| 9445 this._eat(15/*TokenKind.ELLIPSIS*/); |
| 9446 this._lang_error('rest no longer supported', this._previousToken.get$span(
)); |
| 9447 name = this.identifier().get$name(); |
| 9448 break; |
| 9449 |
| 9450 case 109/*TokenKind.THIS*/: |
| 9451 |
| 9452 this._eat(109/*TokenKind.THIS*/); |
| 9453 this._eat(14/*TokenKind.DOT*/); |
| 9454 name = ('this.' + this.identifier().get$name()); |
| 9455 break; |
| 9456 |
| 9457 case 76/*TokenKind.GET*/: |
| 9458 |
| 9459 if (!includeOperators) return null; |
| 9460 this._eat(76/*TokenKind.GET*/); |
| 9461 if (this._peekIdentifier()) { |
| 9462 name = ('get:' + this.identifier().get$name()); |
| 9463 } |
| 9464 else { |
| 9465 name = 'get'; |
| 9466 } |
| 9467 break; |
| 9468 |
| 9469 case 84/*TokenKind.SET*/: |
| 9470 |
| 9471 if (!includeOperators) return null; |
| 9472 this._eat(84/*TokenKind.SET*/); |
| 9473 if (this._peekIdentifier()) { |
| 9474 name = ('set:' + this.identifier().get$name()); |
| 9475 } |
| 9476 else { |
| 9477 name = 'set'; |
| 9478 } |
| 9479 break; |
| 9480 |
| 9481 case 83/*TokenKind.OPERATOR*/: |
| 9482 |
| 9483 if (!includeOperators) return null; |
| 9484 this._eat(83/*TokenKind.OPERATOR*/); |
| 9485 var kind = this._peek(); |
| 9486 if ($eq(kind, 82/*TokenKind.NEGATE*/)) { |
| 9487 name = ':negate'; |
| 9488 this._lang_next(); |
| 9489 } |
| 9490 else { |
| 9491 name = TokenKind.binaryMethodName(kind); |
| 9492 if (name == null) { |
| 9493 name = 'operator'; |
| 9494 } |
| 9495 else { |
| 9496 this._lang_next(); |
| 9497 } |
| 9498 } |
| 9499 break; |
| 9500 |
| 9501 default: |
| 9502 |
| 9503 return null; |
| 9504 |
| 9505 } |
| 9506 return new Identifier(name, this._makeSpan(start)); |
| 9507 } |
| 9508 Parser.prototype.declaredIdentifier = function(includeOperators) { |
| 9509 var start = this._peekToken.start; |
| 9510 var myType = null; |
| 9511 var name = this._specialIdentifier(includeOperators); |
| 9512 if (name == null) { |
| 9513 myType = this.type(0); |
| 9514 name = this._specialIdentifier(includeOperators); |
| 9515 if (name == null) { |
| 9516 if (this._peekIdentifier()) { |
| 9517 name = this.identifier(); |
| 9518 } |
| 9519 else if ((myType instanceof NameTypeReference) && myType.get$names() == nu
ll) { |
| 9520 name = this._typeAsIdentifier(myType); |
| 9521 myType = null; |
| 9522 } |
| 9523 else { |
| 9524 } |
| 9525 } |
| 9526 } |
| 9527 return new DeclaredIdentifier(myType, name, this._makeSpan(start)); |
| 9528 } |
| 9529 Parser._hexDigit = function(c) { |
| 9530 if (c >= 48 && c <= 57) { |
| 9531 return c - 48; |
| 9532 } |
| 9533 else if (c >= 97 && c <= 102) { |
| 9534 return c - 87; |
| 9535 } |
| 9536 else if (c >= 65 && c <= 70) { |
| 9537 return c - 55; |
| 9538 } |
| 9539 else { |
| 9540 return -1; |
| 9541 } |
| 9542 } |
| 9543 Parser.parseHex = function(hex) { |
| 9544 var result = 0; |
| 9545 for (var i = 0; |
| 9546 i < hex.length; i++) { |
| 9547 var digit = Parser._hexDigit(hex.charCodeAt(i)); |
| 9548 result = (result * 16) + digit; |
| 9549 } |
| 9550 return result; |
| 9551 } |
| 9552 Parser.prototype.finishNewExpression = function(start, isConst) { |
| 9553 var type = this.type(0); |
| 9554 var name = null; |
| 9555 if (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 9556 name = this.identifier(); |
| 9557 } |
| 9558 var args = this.arguments(); |
| 9559 return new NewExpression(isConst, type, name, args, this._makeSpan(start)); |
| 9560 } |
| 9561 Parser.prototype.finishListLiteral = function(start, isConst, type) { |
| 9562 if (this._maybeEat(56/*TokenKind.INDEX*/)) { |
| 9563 return new ListExpression(isConst, type, [], this._makeSpan(start)); |
| 9564 } |
| 9565 var values = []; |
| 9566 this._eat(4/*TokenKind.LBRACK*/); |
| 9567 while (!this._maybeEat(5/*TokenKind.RBRACK*/)) { |
| 9568 values.add$1(this.expression()); |
| 9569 if (this._recover && !this._recoverTo(5/*TokenKind.RBRACK*/, 11/*TokenKind.C
OMMA*/)) break; |
| 9570 if (!this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9571 this._eat(5/*TokenKind.RBRACK*/); |
| 9572 break; |
| 9573 } |
| 9574 } |
| 9575 return new ListExpression(isConst, type, values, this._makeSpan(start)); |
| 9576 } |
| 9577 Parser.prototype.finishMapLiteral = function(start, isConst, type) { |
| 9578 var items = []; |
| 9579 this._eat(6/*TokenKind.LBRACE*/); |
| 9580 while (!this._maybeEat(7/*TokenKind.RBRACE*/)) { |
| 9581 items.add$1(this.expression()); |
| 9582 this._eat(8/*TokenKind.COLON*/); |
| 9583 items.add$1(this.expression()); |
| 9584 if (this._recover && !this._recoverTo(7/*TokenKind.RBRACE*/, 11/*TokenKind.C
OMMA*/)) break; |
| 9585 if (!this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9586 this._eat(7/*TokenKind.RBRACE*/); |
| 9587 break; |
| 9588 } |
| 9589 } |
| 9590 return new MapExpression(isConst, type, items, this._makeSpan(start)); |
| 9591 } |
| 9592 Parser.prototype.finishTypedLiteral = function(start, isConst) { |
| 9593 var span = this._makeSpan(start); |
| 9594 var typeToBeNamedLater = new NameTypeReference(false, null, null, span); |
| 9595 var genericType = this.addTypeArguments(typeToBeNamedLater, 0); |
| 9596 if (this._peekKind(4/*TokenKind.LBRACK*/) || this._peekKind(56/*TokenKind.INDE
X*/)) { |
| 9597 genericType.set$baseType(new TypeReference(span, $globals.world.listType)); |
| 9598 return this.finishListLiteral(start, isConst, genericType); |
| 9599 } |
| 9600 else if (this._peekKind(6/*TokenKind.LBRACE*/)) { |
| 9601 genericType.set$baseType(new TypeReference(span, $globals.world.mapType)); |
| 9602 var typeArgs = genericType.get$typeArguments(); |
| 9603 if ($eq(typeArgs.length, 1)) { |
| 9604 genericType.set$typeArguments([new TypeReference(span, $globals.world.stri
ngType), typeArgs.$index(0)]); |
| 9605 } |
| 9606 else if ($eq(typeArgs.length, 2)) { |
| 9607 var keyType = typeArgs.$index(0); |
| 9608 if (!(keyType instanceof NameTypeReference) || $ne(keyType.get$name().get$
name(), "String")) { |
| 9609 $globals.world.error('the key type of a map literal is implicitly "Strin
g"', keyType.get$span()); |
| 9610 } |
| 9611 else { |
| 9612 $globals.world.warning('a map literal takes one type argument specifying
the value type', keyType.get$span()); |
| 9613 } |
| 9614 } |
| 9615 return this.finishMapLiteral(start, isConst, genericType); |
| 9616 } |
| 9617 else { |
| 9618 this._errorExpected('array or map literal'); |
| 9619 } |
| 9620 } |
| 9621 Parser.prototype._readModifiers = function() { |
| 9622 var modifiers = null; |
| 9623 while (true) { |
| 9624 switch (this._peek()) { |
| 9625 case 86/*TokenKind.STATIC*/: |
| 9626 case 98/*TokenKind.FINAL*/: |
| 9627 case 92/*TokenKind.CONST*/: |
| 9628 case 71/*TokenKind.ABSTRACT*/: |
| 9629 case 75/*TokenKind.FACTORY*/: |
| 9630 |
| 9631 if (modifiers == null) modifiers = []; |
| 9632 modifiers.add$1(this._lang_next()); |
| 9633 break; |
| 9634 |
| 9635 default: |
| 9636 |
| 9637 return modifiers; |
| 9638 |
| 9639 } |
| 9640 } |
| 9641 return null; |
| 9642 } |
| 9643 Parser.prototype.typeParameter = function() { |
| 9644 var start = this._peekToken.start; |
| 9645 var name = this.identifier(); |
| 9646 var myType = null; |
| 9647 if (this._maybeEat(74/*TokenKind.EXTENDS*/)) { |
| 9648 myType = this.type(1); |
| 9649 } |
| 9650 var tp = new TypeParameter(name, myType, this._makeSpan(start)); |
| 9651 return new ParameterType(name.get$name(), tp); |
| 9652 } |
| 9653 Parser.prototype.get$typeParameter = function() { |
| 9654 return Parser.prototype.typeParameter.bind(this); |
| 9655 } |
| 9656 Parser.prototype.typeParameters = function() { |
| 9657 this._eat(52/*TokenKind.LT*/); |
| 9658 var closed = false; |
| 9659 var ret = []; |
| 9660 do { |
| 9661 var tp = this.typeParameter(); |
| 9662 ret.add$1(tp); |
| 9663 if ((tp.get$typeParameter().get$extendsType() instanceof GenericTypeReferenc
e) && $eq(tp.get$typeParameter().get$extendsType().get$depth(), 0)) { |
| 9664 closed = true; |
| 9665 break; |
| 9666 } |
| 9667 } |
| 9668 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9669 if (!closed) { |
| 9670 this._eat(53/*TokenKind.GT*/); |
| 9671 } |
| 9672 return ret; |
| 9673 } |
| 9674 Parser.prototype.get$typeParameters = function() { |
| 9675 return Parser.prototype.typeParameters.bind(this); |
| 9676 } |
| 9677 Parser.prototype._eatClosingAngle = function(depth) { |
| 9678 if (this._maybeEat(53/*TokenKind.GT*/)) { |
| 9679 return depth; |
| 9680 } |
| 9681 else if (depth > 0 && this._maybeEat(40/*TokenKind.SAR*/)) { |
| 9682 return depth - 1; |
| 9683 } |
| 9684 else if (depth > 1 && this._maybeEat(41/*TokenKind.SHR*/)) { |
| 9685 return depth - 2; |
| 9686 } |
| 9687 else { |
| 9688 this._errorExpected('>'); |
| 9689 return depth; |
| 9690 } |
| 9691 } |
| 9692 Parser.prototype.addTypeArguments = function(baseType, depth) { |
| 9693 this._eat(52/*TokenKind.LT*/); |
| 9694 return this._finishTypeArguments(baseType, depth, []); |
| 9695 } |
| 9696 Parser.prototype._finishTypeArguments = function(baseType, depth, types) { |
| 9697 var delta = -1; |
| 9698 do { |
| 9699 var myType = this.type(depth + 1); |
| 9700 types.add$1(myType); |
| 9701 if ((myType instanceof GenericTypeReference) && myType.get$depth() <= depth)
{ |
| 9702 delta = depth - myType.get$depth(); |
| 9703 break; |
| 9704 } |
| 9705 } |
| 9706 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9707 if (delta >= 0) { |
| 9708 depth = depth - delta; |
| 9709 } |
| 9710 else { |
| 9711 depth = this._eatClosingAngle(depth); |
| 9712 } |
| 9713 var span = this._makeSpan(baseType.span.start); |
| 9714 return new GenericTypeReference(baseType, types, depth, span); |
| 9715 } |
| 9716 Parser.prototype.typeList = function() { |
| 9717 var types = []; |
| 9718 do { |
| 9719 types.add$1(this.type(0)); |
| 9720 } |
| 9721 while (this._maybeEat(11/*TokenKind.COMMA*/)) |
| 9722 return types; |
| 9723 } |
| 9724 Parser.prototype.nameTypeReference = function() { |
| 9725 var start = this._peekToken.start; |
| 9726 var name; |
| 9727 var names = null; |
| 9728 var typeArgs = null; |
| 9729 var isFinal = false; |
| 9730 switch (this._peek()) { |
| 9731 case 114/*TokenKind.VOID*/: |
| 9732 |
| 9733 return new TypeReference(this._lang_next().get$span(), $globals.world.void
Type); |
| 9734 |
| 9735 case 113/*TokenKind.VAR*/: |
| 9736 |
| 9737 return new TypeReference(this._lang_next().get$span(), $globals.world.varT
ype); |
| 9738 |
| 9739 case 98/*TokenKind.FINAL*/: |
| 9740 |
| 9741 this._eat(98/*TokenKind.FINAL*/); |
| 9742 isFinal = true; |
| 9743 name = this.identifier(); |
| 9744 break; |
| 9745 |
| 9746 default: |
| 9747 |
| 9748 name = this.identifier(); |
| 9749 break; |
| 9750 |
| 9751 } |
| 9752 while (this._maybeEat(14/*TokenKind.DOT*/)) { |
| 9753 if (names == null) names = []; |
| 9754 names.add$1(this.identifier()); |
| 9755 } |
| 9756 return new NameTypeReference(isFinal, name, names, this._makeSpan(start)); |
| 9757 } |
| 9758 Parser.prototype.type = function(depth) { |
| 9759 var typeRef = this.nameTypeReference(); |
| 9760 if (this._peekKind(52/*TokenKind.LT*/)) { |
| 9761 return this.addTypeArguments(typeRef, depth); |
| 9762 } |
| 9763 else { |
| 9764 return typeRef; |
| 9765 } |
| 9766 } |
| 9767 Parser.prototype.get$type = function() { |
| 9768 return Parser.prototype.type.bind(this); |
| 9769 } |
| 9770 Parser.prototype.formalParameter = function(inOptionalBlock) { |
| 9771 var start = this._peekToken.start; |
| 9772 var isThis = false; |
| 9773 var isRest = false; |
| 9774 var di = this.declaredIdentifier(false); |
| 9775 var type = di.get$type(); |
| 9776 var name = di.get$name(); |
| 9777 var value = null; |
| 9778 if (this._maybeEat(20/*TokenKind.ASSIGN*/)) { |
| 9779 if (!inOptionalBlock) { |
| 9780 this._lang_error('default values only allowed inside [optional] section'); |
| 9781 } |
| 9782 value = this.expression(); |
| 9783 } |
| 9784 else if (this._peekKind(2/*TokenKind.LPAREN*/)) { |
| 9785 var formals = this.formalParameterList(); |
| 9786 var func = new FunctionDefinition(null, type, name, formals, null, null, nul
l, null, this._makeSpan(start)); |
| 9787 type = new FunctionTypeReference(false, func, func.get$span()); |
| 9788 } |
| 9789 if (inOptionalBlock && value == null) { |
| 9790 value = new NullExpression(this._makeSpan(start)); |
| 9791 } |
| 9792 return new FormalNode(isThis, isRest, type, name, value, this._makeSpan(start)
); |
| 9793 } |
| 9794 Parser.prototype.formalParameterList = function() { |
| 9795 this._eatLeftParen(); |
| 9796 var formals = []; |
| 9797 var inOptionalBlock = false; |
| 9798 if (!this._maybeEat(3/*TokenKind.RPAREN*/)) { |
| 9799 if (this._maybeEat(4/*TokenKind.LBRACK*/)) { |
| 9800 inOptionalBlock = true; |
| 9801 } |
| 9802 formals.add$1(this.formalParameter(inOptionalBlock)); |
| 9803 while (this._maybeEat(11/*TokenKind.COMMA*/)) { |
| 9804 if (this._maybeEat(4/*TokenKind.LBRACK*/)) { |
| 9805 if (inOptionalBlock) { |
| 9806 this._lang_error('already inside an optional block', this._previousTok
en.get$span()); |
| 9807 } |
| 9808 inOptionalBlock = true; |
| 9809 } |
| 9810 formals.add$1(this.formalParameter(inOptionalBlock)); |
| 9811 } |
| 9812 if (inOptionalBlock) { |
| 9813 this._eat(5/*TokenKind.RBRACK*/); |
| 9814 } |
| 9815 this._eat(3/*TokenKind.RPAREN*/); |
| 9816 } |
| 9817 return formals; |
| 9818 } |
| 9819 Parser.prototype.identifier = function() { |
| 9820 var tok = this._lang_next(); |
| 9821 if (!this._isIdentifier(tok.get$kind())) { |
| 9822 this._lang_error(('expected identifier, but found ' + tok), tok.get$span()); |
| 9823 } |
| 9824 return new Identifier(tok.get$text(), this._makeSpan(tok.get$start())); |
| 9825 } |
| 9826 Parser.prototype._makeFunction = function(expr, formals, body) { |
| 9827 var name, type; |
| 9828 if ((expr instanceof VarExpression)) { |
| 9829 name = expr.get$name(); |
| 9830 type = null; |
| 9831 } |
| 9832 else if ((expr instanceof DeclaredIdentifier)) { |
| 9833 name = expr.get$name(); |
| 9834 type = expr.get$type(); |
| 9835 } |
| 9836 else { |
| 9837 this._lang_error('bad function body', expr.get$span()); |
| 9838 } |
| 9839 var span = new SourceSpan(expr.get$span().get$file(), expr.get$span().get$star
t(), body.get$span().get$end()); |
| 9840 var func = new FunctionDefinition(null, type, name, formals, null, null, null,
body, span); |
| 9841 return new LambdaExpression(func, func.get$span()); |
| 9842 } |
| 9843 Parser.prototype._makeDeclaredIdentifier = function(e) { |
| 9844 if ((e instanceof VarExpression)) { |
| 9845 return new DeclaredIdentifier(null, e.get$name(), e.get$span()); |
| 9846 } |
| 9847 else if ((e instanceof DeclaredIdentifier)) { |
| 9848 return e; |
| 9849 } |
| 9850 else { |
| 9851 this._lang_error('expected declared identifier'); |
| 9852 return new DeclaredIdentifier(null, null, e.get$span()); |
| 9853 } |
| 9854 } |
| 9855 Parser.prototype._makeLabel = function(expr) { |
| 9856 if ((expr instanceof VarExpression)) { |
| 9857 return expr.get$name(); |
| 9858 } |
| 9859 else { |
| 9860 this._errorExpected('label'); |
| 9861 return null; |
| 9862 } |
| 9863 } |
| 9864 Parser.prototype.block$0 = Parser.prototype.block; |
| 9865 // ********** Code for IncompleteSourceException ************** |
| 9866 function IncompleteSourceException(token) { |
| 9867 this.token = token; |
| 9868 // Initializers done |
| 9869 } |
| 9870 IncompleteSourceException.prototype.toString = function() { |
| 9871 if (this.token.get$span() == null) return ('Unexpected ' + this.token); |
| 9872 return this.token.get$span().toMessageString(('Unexpected ' + this.token)); |
| 9873 } |
| 9874 IncompleteSourceException.prototype.toString$0 = IncompleteSourceException.proto
type.toString; |
| 9875 // ********** Code for DivertedTokenSource ************** |
| 9876 function DivertedTokenSource(tokens, parser, previousTokenizer) { |
| 9877 this._lang_pos = 0 |
| 9878 this.tokens = tokens; |
| 9879 this.parser = parser; |
| 9880 this.previousTokenizer = previousTokenizer; |
| 9881 // Initializers done |
| 9882 } |
| 9883 DivertedTokenSource.prototype.next = function() { |
| 9884 var token = this.tokens.$index(this._lang_pos); |
| 9885 ++this._lang_pos; |
| 9886 if (this._lang_pos == this.tokens.length) { |
| 9887 this.parser.tokenizer = this.previousTokenizer; |
| 9888 } |
| 9889 return token; |
| 9890 } |
| 9891 DivertedTokenSource.prototype.next$0 = DivertedTokenSource.prototype.next; |
| 9892 // ********** Code for Node ************** |
| 9893 function Node(span) { |
| 9894 this.span = span; |
| 9895 // Initializers done |
| 9896 } |
| 9897 Node.prototype.get$span = function() { return this.span; }; |
| 9898 Node.prototype.set$span = function(value) { return this.span = value; }; |
| 9899 Node.prototype.visit$1 = Node.prototype.visit; |
| 9900 // ********** Code for Statement ************** |
| 9901 $inherits(Statement, Node); |
| 9902 function Statement(span) { |
| 9903 // Initializers done |
| 9904 Node.call(this, span); |
| 9905 } |
| 9906 // ********** Code for Definition ************** |
| 9907 $inherits(Definition, Statement); |
| 9908 function Definition(span) { |
| 9909 // Initializers done |
| 9910 Statement.call(this, span); |
| 9911 } |
| 9912 Definition.prototype.get$typeParameters = function() { |
| 9913 return null; |
| 9914 } |
| 9915 Definition.prototype.get$nativeType = function() { |
| 9916 return null; |
| 9917 } |
| 9918 // ********** Code for Expression ************** |
| 9919 $inherits(Expression, Node); |
| 9920 function Expression(span) { |
| 9921 // Initializers done |
| 9922 Node.call(this, span); |
| 9923 } |
| 9924 // ********** Code for TypeReference ************** |
| 9925 $inherits(TypeReference, Node); |
| 9926 function TypeReference(span, type) { |
| 9927 this.type = type; |
| 9928 // Initializers done |
| 9929 Node.call(this, span); |
| 9930 } |
| 9931 TypeReference.prototype.get$type = function() { return this.type; }; |
| 9932 TypeReference.prototype.set$type = function(value) { return this.type = value; }
; |
| 9933 TypeReference.prototype.visit = function(visitor) { |
| 9934 return visitor.visitTypeReference(this); |
| 9935 } |
| 9936 TypeReference.prototype.get$isFinal = function() { |
| 9937 return false; |
| 9938 } |
| 9939 TypeReference.prototype.visit$1 = TypeReference.prototype.visit; |
| 9940 // ********** Code for DirectiveDefinition ************** |
| 9941 $inherits(DirectiveDefinition, Definition); |
| 9942 function DirectiveDefinition(name, arguments, span) { |
| 9943 this.name = name; |
| 9944 this.arguments = arguments; |
| 9945 // Initializers done |
| 9946 Definition.call(this, span); |
| 9947 } |
| 9948 DirectiveDefinition.prototype.get$name = function() { return this.name; }; |
| 9949 DirectiveDefinition.prototype.set$name = function(value) { return this.name = va
lue; }; |
| 9950 DirectiveDefinition.prototype.get$arguments = function() { return this.arguments
; }; |
| 9951 DirectiveDefinition.prototype.set$arguments = function(value) { return this.argu
ments = value; }; |
| 9952 DirectiveDefinition.prototype.visit = function(visitor) { |
| 9953 return visitor.visitDirectiveDefinition(this); |
| 9954 } |
| 9955 DirectiveDefinition.prototype.visit$1 = DirectiveDefinition.prototype.visit; |
| 9956 // ********** Code for TypeDefinition ************** |
| 9957 $inherits(TypeDefinition, Definition); |
| 9958 function TypeDefinition(isClass, name, typeParameters, extendsTypes, implementsT
ypes, nativeType, factoryType, body, span) { |
| 9959 this.isClass = isClass; |
| 9960 this.name = name; |
| 9961 this.typeParameters = typeParameters; |
| 9962 this.extendsTypes = extendsTypes; |
| 9963 this.implementsTypes = implementsTypes; |
| 9964 this.nativeType = nativeType; |
| 9965 this.factoryType = factoryType; |
| 9966 this.body = body; |
| 9967 // Initializers done |
| 9968 Definition.call(this, span); |
| 9969 } |
| 9970 TypeDefinition.prototype.get$isClass = function() { return this.isClass; }; |
| 9971 TypeDefinition.prototype.set$isClass = function(value) { return this.isClass = v
alue; }; |
| 9972 TypeDefinition.prototype.get$name = function() { return this.name; }; |
| 9973 TypeDefinition.prototype.set$name = function(value) { return this.name = value;
}; |
| 9974 TypeDefinition.prototype.get$typeParameters = function() { return this.typeParam
eters; }; |
| 9975 TypeDefinition.prototype.set$typeParameters = function(value) { return this.type
Parameters = value; }; |
| 9976 TypeDefinition.prototype.get$nativeType = function() { return this.nativeType; }
; |
| 9977 TypeDefinition.prototype.set$nativeType = function(value) { return this.nativeTy
pe = value; }; |
| 9978 TypeDefinition.prototype.get$body = function() { return this.body; }; |
| 9979 TypeDefinition.prototype.set$body = function(value) { return this.body = value;
}; |
| 9980 TypeDefinition.prototype.visit = function(visitor) { |
| 9981 return visitor.visitTypeDefinition(this); |
| 9982 } |
| 9983 TypeDefinition.prototype.visit$1 = TypeDefinition.prototype.visit; |
| 9984 // ********** Code for FunctionTypeDefinition ************** |
| 9985 $inherits(FunctionTypeDefinition, Definition); |
| 9986 function FunctionTypeDefinition(func, typeParameters, span) { |
| 9987 this.func = func; |
| 9988 this.typeParameters = typeParameters; |
| 9989 // Initializers done |
| 9990 Definition.call(this, span); |
| 9991 } |
| 9992 FunctionTypeDefinition.prototype.get$func = function() { return this.func; }; |
| 9993 FunctionTypeDefinition.prototype.set$func = function(value) { return this.func =
value; }; |
| 9994 FunctionTypeDefinition.prototype.get$typeParameters = function() { return this.t
ypeParameters; }; |
| 9995 FunctionTypeDefinition.prototype.set$typeParameters = function(value) { return t
his.typeParameters = value; }; |
| 9996 FunctionTypeDefinition.prototype.visit = function(visitor) { |
| 9997 return visitor.visitFunctionTypeDefinition(this); |
| 9998 } |
| 9999 FunctionTypeDefinition.prototype.visit$1 = FunctionTypeDefinition.prototype.visi
t; |
| 10000 // ********** Code for VariableDefinition ************** |
| 10001 $inherits(VariableDefinition, Definition); |
| 10002 function VariableDefinition(modifiers, type, names, values, span) { |
| 10003 this.modifiers = modifiers; |
| 10004 this.type = type; |
| 10005 this.names = names; |
| 10006 this.values = values; |
| 10007 // Initializers done |
| 10008 Definition.call(this, span); |
| 10009 } |
| 10010 VariableDefinition.prototype.get$type = function() { return this.type; }; |
| 10011 VariableDefinition.prototype.set$type = function(value) { return this.type = val
ue; }; |
| 10012 VariableDefinition.prototype.get$names = function() { return this.names; }; |
| 10013 VariableDefinition.prototype.set$names = function(value) { return this.names = v
alue; }; |
| 10014 VariableDefinition.prototype.get$values = function() { return this.values; }; |
| 10015 VariableDefinition.prototype.set$values = function(value) { return this.values =
value; }; |
| 10016 VariableDefinition.prototype.visit = function(visitor) { |
| 10017 return visitor.visitVariableDefinition(this); |
| 10018 } |
| 10019 VariableDefinition.prototype.visit$1 = VariableDefinition.prototype.visit; |
| 10020 // ********** Code for FunctionDefinition ************** |
| 10021 $inherits(FunctionDefinition, Definition); |
| 10022 function FunctionDefinition(modifiers, returnType, name, formals, typeParameters
, initializers, nativeBody, body, span) { |
| 10023 this.modifiers = modifiers; |
| 10024 this.returnType = returnType; |
| 10025 this.name = name; |
| 10026 this.formals = formals; |
| 10027 this.typeParameters = typeParameters; |
| 10028 this.initializers = initializers; |
| 10029 this.nativeBody = nativeBody; |
| 10030 this.body = body; |
| 10031 // Initializers done |
| 10032 Definition.call(this, span); |
| 10033 } |
| 10034 FunctionDefinition.prototype.get$returnType = function() { return this.returnTyp
e; }; |
| 10035 FunctionDefinition.prototype.set$returnType = function(value) { return this.retu
rnType = value; }; |
| 10036 FunctionDefinition.prototype.get$name = function() { return this.name; }; |
| 10037 FunctionDefinition.prototype.set$name = function(value) { return this.name = val
ue; }; |
| 10038 FunctionDefinition.prototype.get$typeParameters = function() { return this.typeP
arameters; }; |
| 10039 FunctionDefinition.prototype.set$typeParameters = function(value) { return this.
typeParameters = value; }; |
| 10040 FunctionDefinition.prototype.get$initializers = function() { return this.initial
izers; }; |
| 10041 FunctionDefinition.prototype.set$initializers = function(value) { return this.in
itializers = value; }; |
| 10042 FunctionDefinition.prototype.get$nativeBody = function() { return this.nativeBod
y; }; |
| 10043 FunctionDefinition.prototype.set$nativeBody = function(value) { return this.nati
veBody = value; }; |
| 10044 FunctionDefinition.prototype.get$body = function() { return this.body; }; |
| 10045 FunctionDefinition.prototype.set$body = function(value) { return this.body = val
ue; }; |
| 10046 FunctionDefinition.prototype.visit = function(visitor) { |
| 10047 return visitor.visitFunctionDefinition(this); |
| 10048 } |
| 10049 FunctionDefinition.prototype.visit$1 = FunctionDefinition.prototype.visit; |
| 10050 // ********** Code for ReturnStatement ************** |
| 10051 $inherits(ReturnStatement, Statement); |
| 10052 function ReturnStatement(value, span) { |
| 10053 this.value = value; |
| 10054 // Initializers done |
| 10055 Statement.call(this, span); |
| 10056 } |
| 10057 ReturnStatement.prototype.get$value = function() { return this.value; }; |
| 10058 ReturnStatement.prototype.set$value = function(value) { return this.value = valu
e; }; |
| 10059 ReturnStatement.prototype.visit = function(visitor) { |
| 10060 return visitor.visitReturnStatement(this); |
| 10061 } |
| 10062 ReturnStatement.prototype.visit$1 = ReturnStatement.prototype.visit; |
| 10063 // ********** Code for ThrowStatement ************** |
| 10064 $inherits(ThrowStatement, Statement); |
| 10065 function ThrowStatement(value, span) { |
| 10066 this.value = value; |
| 10067 // Initializers done |
| 10068 Statement.call(this, span); |
| 10069 } |
| 10070 ThrowStatement.prototype.get$value = function() { return this.value; }; |
| 10071 ThrowStatement.prototype.set$value = function(value) { return this.value = value
; }; |
| 10072 ThrowStatement.prototype.visit = function(visitor) { |
| 10073 return visitor.visitThrowStatement(this); |
| 10074 } |
| 10075 ThrowStatement.prototype.visit$1 = ThrowStatement.prototype.visit; |
| 10076 // ********** Code for AssertStatement ************** |
| 10077 $inherits(AssertStatement, Statement); |
| 10078 function AssertStatement(test, span) { |
| 10079 this.test = test; |
| 10080 // Initializers done |
| 10081 Statement.call(this, span); |
| 10082 } |
| 10083 AssertStatement.prototype.visit = function(visitor) { |
| 10084 return visitor.visitAssertStatement(this); |
| 10085 } |
| 10086 AssertStatement.prototype.visit$1 = AssertStatement.prototype.visit; |
| 10087 // ********** Code for BreakStatement ************** |
| 10088 $inherits(BreakStatement, Statement); |
| 10089 function BreakStatement(label, span) { |
| 10090 this.label = label; |
| 10091 // Initializers done |
| 10092 Statement.call(this, span); |
| 10093 } |
| 10094 BreakStatement.prototype.get$label = function() { return this.label; }; |
| 10095 BreakStatement.prototype.set$label = function(value) { return this.label = value
; }; |
| 10096 BreakStatement.prototype.visit = function(visitor) { |
| 10097 return visitor.visitBreakStatement(this); |
| 10098 } |
| 10099 BreakStatement.prototype.visit$1 = BreakStatement.prototype.visit; |
| 10100 // ********** Code for ContinueStatement ************** |
| 10101 $inherits(ContinueStatement, Statement); |
| 10102 function ContinueStatement(label, span) { |
| 10103 this.label = label; |
| 10104 // Initializers done |
| 10105 Statement.call(this, span); |
| 10106 } |
| 10107 ContinueStatement.prototype.get$label = function() { return this.label; }; |
| 10108 ContinueStatement.prototype.set$label = function(value) { return this.label = va
lue; }; |
| 10109 ContinueStatement.prototype.visit = function(visitor) { |
| 10110 return visitor.visitContinueStatement(this); |
| 10111 } |
| 10112 ContinueStatement.prototype.visit$1 = ContinueStatement.prototype.visit; |
| 10113 // ********** Code for IfStatement ************** |
| 10114 $inherits(IfStatement, Statement); |
| 10115 function IfStatement(test, trueBranch, falseBranch, span) { |
| 10116 this.test = test; |
| 10117 this.trueBranch = trueBranch; |
| 10118 this.falseBranch = falseBranch; |
| 10119 // Initializers done |
| 10120 Statement.call(this, span); |
| 10121 } |
| 10122 IfStatement.prototype.visit = function(visitor) { |
| 10123 return visitor.visitIfStatement(this); |
| 10124 } |
| 10125 IfStatement.prototype.visit$1 = IfStatement.prototype.visit; |
| 10126 // ********** Code for WhileStatement ************** |
| 10127 $inherits(WhileStatement, Statement); |
| 10128 function WhileStatement(test, body, span) { |
| 10129 this.test = test; |
| 10130 this.body = body; |
| 10131 // Initializers done |
| 10132 Statement.call(this, span); |
| 10133 } |
| 10134 WhileStatement.prototype.get$body = function() { return this.body; }; |
| 10135 WhileStatement.prototype.set$body = function(value) { return this.body = value;
}; |
| 10136 WhileStatement.prototype.visit = function(visitor) { |
| 10137 return visitor.visitWhileStatement(this); |
| 10138 } |
| 10139 WhileStatement.prototype.visit$1 = WhileStatement.prototype.visit; |
| 10140 // ********** Code for DoStatement ************** |
| 10141 $inherits(DoStatement, Statement); |
| 10142 function DoStatement(body, test, span) { |
| 10143 this.body = body; |
| 10144 this.test = test; |
| 10145 // Initializers done |
| 10146 Statement.call(this, span); |
| 10147 } |
| 10148 DoStatement.prototype.get$body = function() { return this.body; }; |
| 10149 DoStatement.prototype.set$body = function(value) { return this.body = value; }; |
| 10150 DoStatement.prototype.visit = function(visitor) { |
| 10151 return visitor.visitDoStatement(this); |
| 10152 } |
| 10153 DoStatement.prototype.visit$1 = DoStatement.prototype.visit; |
| 10154 // ********** Code for ForStatement ************** |
| 10155 $inherits(ForStatement, Statement); |
| 10156 function ForStatement(init, test, step, body, span) { |
| 10157 this.init = init; |
| 10158 this.test = test; |
| 10159 this.step = step; |
| 10160 this.body = body; |
| 10161 // Initializers done |
| 10162 Statement.call(this, span); |
| 10163 } |
| 10164 ForStatement.prototype.get$body = function() { return this.body; }; |
| 10165 ForStatement.prototype.set$body = function(value) { return this.body = value; }; |
| 10166 ForStatement.prototype.visit = function(visitor) { |
| 10167 return visitor.visitForStatement(this); |
| 10168 } |
| 10169 ForStatement.prototype.visit$1 = ForStatement.prototype.visit; |
| 10170 // ********** Code for ForInStatement ************** |
| 10171 $inherits(ForInStatement, Statement); |
| 10172 function ForInStatement(item, list, body, span) { |
| 10173 this.item = item; |
| 10174 this.list = list; |
| 10175 this.body = body; |
| 10176 // Initializers done |
| 10177 Statement.call(this, span); |
| 10178 } |
| 10179 ForInStatement.prototype.get$body = function() { return this.body; }; |
| 10180 ForInStatement.prototype.set$body = function(value) { return this.body = value;
}; |
| 10181 ForInStatement.prototype.visit = function(visitor) { |
| 10182 return visitor.visitForInStatement(this); |
| 10183 } |
| 10184 ForInStatement.prototype.visit$1 = ForInStatement.prototype.visit; |
| 10185 // ********** Code for TryStatement ************** |
| 10186 $inherits(TryStatement, Statement); |
| 10187 function TryStatement(body, catches, finallyBlock, span) { |
| 10188 this.body = body; |
| 10189 this.catches = catches; |
| 10190 this.finallyBlock = finallyBlock; |
| 10191 // Initializers done |
| 10192 Statement.call(this, span); |
| 10193 } |
| 10194 TryStatement.prototype.get$body = function() { return this.body; }; |
| 10195 TryStatement.prototype.set$body = function(value) { return this.body = value; }; |
| 10196 TryStatement.prototype.visit = function(visitor) { |
| 10197 return visitor.visitTryStatement(this); |
| 10198 } |
| 10199 TryStatement.prototype.visit$1 = TryStatement.prototype.visit; |
| 10200 // ********** Code for SwitchStatement ************** |
| 10201 $inherits(SwitchStatement, Statement); |
| 10202 function SwitchStatement(test, cases, span) { |
| 10203 this.test = test; |
| 10204 this.cases = cases; |
| 10205 // Initializers done |
| 10206 Statement.call(this, span); |
| 10207 } |
| 10208 SwitchStatement.prototype.get$cases = function() { return this.cases; }; |
| 10209 SwitchStatement.prototype.set$cases = function(value) { return this.cases = valu
e; }; |
| 10210 SwitchStatement.prototype.visit = function(visitor) { |
| 10211 return visitor.visitSwitchStatement(this); |
| 10212 } |
| 10213 SwitchStatement.prototype.visit$1 = SwitchStatement.prototype.visit; |
| 10214 // ********** Code for BlockStatement ************** |
| 10215 $inherits(BlockStatement, Statement); |
| 10216 function BlockStatement(body, span) { |
| 10217 this.body = body; |
| 10218 // Initializers done |
| 10219 Statement.call(this, span); |
| 10220 } |
| 10221 BlockStatement.prototype.get$body = function() { return this.body; }; |
| 10222 BlockStatement.prototype.set$body = function(value) { return this.body = value;
}; |
| 10223 BlockStatement.prototype.visit = function(visitor) { |
| 10224 return visitor.visitBlockStatement(this); |
| 10225 } |
| 10226 BlockStatement.prototype.visit$1 = BlockStatement.prototype.visit; |
| 10227 // ********** Code for LabeledStatement ************** |
| 10228 $inherits(LabeledStatement, Statement); |
| 10229 function LabeledStatement(name, body, span) { |
| 10230 this.name = name; |
| 10231 this.body = body; |
| 10232 // Initializers done |
| 10233 Statement.call(this, span); |
| 10234 } |
| 10235 LabeledStatement.prototype.get$name = function() { return this.name; }; |
| 10236 LabeledStatement.prototype.set$name = function(value) { return this.name = value
; }; |
| 10237 LabeledStatement.prototype.get$body = function() { return this.body; }; |
| 10238 LabeledStatement.prototype.set$body = function(value) { return this.body = value
; }; |
| 10239 LabeledStatement.prototype.visit = function(visitor) { |
| 10240 return visitor.visitLabeledStatement(this); |
| 10241 } |
| 10242 LabeledStatement.prototype.visit$1 = LabeledStatement.prototype.visit; |
| 10243 // ********** Code for ExpressionStatement ************** |
| 10244 $inherits(ExpressionStatement, Statement); |
| 10245 function ExpressionStatement(body, span) { |
| 10246 this.body = body; |
| 10247 // Initializers done |
| 10248 Statement.call(this, span); |
| 10249 } |
| 10250 ExpressionStatement.prototype.get$body = function() { return this.body; }; |
| 10251 ExpressionStatement.prototype.set$body = function(value) { return this.body = va
lue; }; |
| 10252 ExpressionStatement.prototype.visit = function(visitor) { |
| 10253 return visitor.visitExpressionStatement(this); |
| 10254 } |
| 10255 ExpressionStatement.prototype.visit$1 = ExpressionStatement.prototype.visit; |
| 10256 // ********** Code for EmptyStatement ************** |
| 10257 $inherits(EmptyStatement, Statement); |
| 10258 function EmptyStatement(span) { |
| 10259 // Initializers done |
| 10260 Statement.call(this, span); |
| 10261 } |
| 10262 EmptyStatement.prototype.visit = function(visitor) { |
| 10263 return visitor.visitEmptyStatement(this); |
| 10264 } |
| 10265 EmptyStatement.prototype.visit$1 = EmptyStatement.prototype.visit; |
| 10266 // ********** Code for DietStatement ************** |
| 10267 $inherits(DietStatement, Statement); |
| 10268 function DietStatement(span) { |
| 10269 // Initializers done |
| 10270 Statement.call(this, span); |
| 10271 } |
| 10272 DietStatement.prototype.visit = function(visitor) { |
| 10273 return visitor.visitDietStatement(this); |
| 10274 } |
| 10275 DietStatement.prototype.visit$1 = DietStatement.prototype.visit; |
| 10276 // ********** Code for LambdaExpression ************** |
| 10277 $inherits(LambdaExpression, Expression); |
| 10278 function LambdaExpression(func, span) { |
| 10279 this.func = func; |
| 10280 // Initializers done |
| 10281 Expression.call(this, span); |
| 10282 } |
| 10283 LambdaExpression.prototype.get$func = function() { return this.func; }; |
| 10284 LambdaExpression.prototype.set$func = function(value) { return this.func = value
; }; |
| 10285 LambdaExpression.prototype.visit = function(visitor) { |
| 10286 return visitor.visitLambdaExpression(this); |
| 10287 } |
| 10288 LambdaExpression.prototype.visit$1 = LambdaExpression.prototype.visit; |
| 10289 // ********** Code for CallExpression ************** |
| 10290 $inherits(CallExpression, Expression); |
| 10291 function CallExpression(target, arguments, span) { |
| 10292 this.target = target; |
| 10293 this.arguments = arguments; |
| 10294 // Initializers done |
| 10295 Expression.call(this, span); |
| 10296 } |
| 10297 CallExpression.prototype.get$target = function() { return this.target; }; |
| 10298 CallExpression.prototype.set$target = function(value) { return this.target = val
ue; }; |
| 10299 CallExpression.prototype.get$arguments = function() { return this.arguments; }; |
| 10300 CallExpression.prototype.set$arguments = function(value) { return this.arguments
= value; }; |
| 10301 CallExpression.prototype.visit = function(visitor) { |
| 10302 return visitor.visitCallExpression(this); |
| 10303 } |
| 10304 CallExpression.prototype.visit$1 = CallExpression.prototype.visit; |
| 10305 // ********** Code for IndexExpression ************** |
| 10306 $inherits(IndexExpression, Expression); |
| 10307 function IndexExpression(target, index, span) { |
| 10308 this.target = target; |
| 10309 this.index = index; |
| 10310 // Initializers done |
| 10311 Expression.call(this, span); |
| 10312 } |
| 10313 IndexExpression.prototype.get$target = function() { return this.target; }; |
| 10314 IndexExpression.prototype.set$target = function(value) { return this.target = va
lue; }; |
| 10315 IndexExpression.prototype.visit = function(visitor) { |
| 10316 return visitor.visitIndexExpression(this); |
| 10317 } |
| 10318 IndexExpression.prototype.visit$1 = IndexExpression.prototype.visit; |
| 10319 // ********** Code for BinaryExpression ************** |
| 10320 $inherits(BinaryExpression, Expression); |
| 10321 function BinaryExpression(op, x, y, span) { |
| 10322 this.op = op; |
| 10323 this.x = x; |
| 10324 this.y = y; |
| 10325 // Initializers done |
| 10326 Expression.call(this, span); |
| 10327 } |
| 10328 BinaryExpression.prototype.get$op = function() { return this.op; }; |
| 10329 BinaryExpression.prototype.set$op = function(value) { return this.op = value; }; |
| 10330 BinaryExpression.prototype.get$x = function() { return this.x; }; |
| 10331 BinaryExpression.prototype.set$x = function(value) { return this.x = value; }; |
| 10332 BinaryExpression.prototype.get$y = function() { return this.y; }; |
| 10333 BinaryExpression.prototype.set$y = function(value) { return this.y = value; }; |
| 10334 BinaryExpression.prototype.visit = function(visitor) { |
| 10335 return visitor.visitBinaryExpression$1(this); |
| 10336 } |
| 10337 BinaryExpression.prototype.visit$1 = BinaryExpression.prototype.visit; |
| 10338 // ********** Code for UnaryExpression ************** |
| 10339 $inherits(UnaryExpression, Expression); |
| 10340 function UnaryExpression(op, self, span) { |
| 10341 this.op = op; |
| 10342 this.self = self; |
| 10343 // Initializers done |
| 10344 Expression.call(this, span); |
| 10345 } |
| 10346 UnaryExpression.prototype.get$op = function() { return this.op; }; |
| 10347 UnaryExpression.prototype.set$op = function(value) { return this.op = value; }; |
| 10348 UnaryExpression.prototype.get$self = function() { return this.self; }; |
| 10349 UnaryExpression.prototype.set$self = function(value) { return this.self = value;
}; |
| 10350 UnaryExpression.prototype.visit = function(visitor) { |
| 10351 return visitor.visitUnaryExpression(this); |
| 10352 } |
| 10353 UnaryExpression.prototype.visit$1 = UnaryExpression.prototype.visit; |
| 10354 // ********** Code for PostfixExpression ************** |
| 10355 $inherits(PostfixExpression, Expression); |
| 10356 function PostfixExpression(body, op, span) { |
| 10357 this.body = body; |
| 10358 this.op = op; |
| 10359 // Initializers done |
| 10360 Expression.call(this, span); |
| 10361 } |
| 10362 PostfixExpression.prototype.get$body = function() { return this.body; }; |
| 10363 PostfixExpression.prototype.set$body = function(value) { return this.body = valu
e; }; |
| 10364 PostfixExpression.prototype.get$op = function() { return this.op; }; |
| 10365 PostfixExpression.prototype.set$op = function(value) { return this.op = value; }
; |
| 10366 PostfixExpression.prototype.visit = function(visitor) { |
| 10367 return visitor.visitPostfixExpression$1(this); |
| 10368 } |
| 10369 PostfixExpression.prototype.visit$1 = PostfixExpression.prototype.visit; |
| 10370 // ********** Code for NewExpression ************** |
| 10371 $inherits(NewExpression, Expression); |
| 10372 function NewExpression(isConst, type, name, arguments, span) { |
| 10373 this.isConst = isConst; |
| 10374 this.type = type; |
| 10375 this.name = name; |
| 10376 this.arguments = arguments; |
| 10377 // Initializers done |
| 10378 Expression.call(this, span); |
| 10379 } |
| 10380 NewExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 10381 NewExpression.prototype.set$isConst = function(value) { return this.isConst = va
lue; }; |
| 10382 NewExpression.prototype.get$type = function() { return this.type; }; |
| 10383 NewExpression.prototype.set$type = function(value) { return this.type = value; }
; |
| 10384 NewExpression.prototype.get$name = function() { return this.name; }; |
| 10385 NewExpression.prototype.set$name = function(value) { return this.name = value; }
; |
| 10386 NewExpression.prototype.get$arguments = function() { return this.arguments; }; |
| 10387 NewExpression.prototype.set$arguments = function(value) { return this.arguments
= value; }; |
| 10388 NewExpression.prototype.visit = function(visitor) { |
| 10389 return visitor.visitNewExpression(this); |
| 10390 } |
| 10391 NewExpression.prototype.visit$1 = NewExpression.prototype.visit; |
| 10392 // ********** Code for ListExpression ************** |
| 10393 $inherits(ListExpression, Expression); |
| 10394 function ListExpression(isConst, type, values, span) { |
| 10395 this.isConst = isConst; |
| 10396 this.type = type; |
| 10397 this.values = values; |
| 10398 // Initializers done |
| 10399 Expression.call(this, span); |
| 10400 } |
| 10401 ListExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 10402 ListExpression.prototype.set$isConst = function(value) { return this.isConst = v
alue; }; |
| 10403 ListExpression.prototype.get$type = function() { return this.type; }; |
| 10404 ListExpression.prototype.set$type = function(value) { return this.type = value;
}; |
| 10405 ListExpression.prototype.get$values = function() { return this.values; }; |
| 10406 ListExpression.prototype.set$values = function(value) { return this.values = val
ue; }; |
| 10407 ListExpression.prototype.visit = function(visitor) { |
| 10408 return visitor.visitListExpression(this); |
| 10409 } |
| 10410 ListExpression.prototype.visit$1 = ListExpression.prototype.visit; |
| 10411 // ********** Code for MapExpression ************** |
| 10412 $inherits(MapExpression, Expression); |
| 10413 function MapExpression(isConst, type, items, span) { |
| 10414 this.isConst = isConst; |
| 10415 this.type = type; |
| 10416 this.items = items; |
| 10417 // Initializers done |
| 10418 Expression.call(this, span); |
| 10419 } |
| 10420 MapExpression.prototype.get$isConst = function() { return this.isConst; }; |
| 10421 MapExpression.prototype.set$isConst = function(value) { return this.isConst = va
lue; }; |
| 10422 MapExpression.prototype.get$type = function() { return this.type; }; |
| 10423 MapExpression.prototype.set$type = function(value) { return this.type = value; }
; |
| 10424 MapExpression.prototype.visit = function(visitor) { |
| 10425 return visitor.visitMapExpression(this); |
| 10426 } |
| 10427 MapExpression.prototype.visit$1 = MapExpression.prototype.visit; |
| 10428 // ********** Code for ConditionalExpression ************** |
| 10429 $inherits(ConditionalExpression, Expression); |
| 10430 function ConditionalExpression(test, trueBranch, falseBranch, span) { |
| 10431 this.test = test; |
| 10432 this.trueBranch = trueBranch; |
| 10433 this.falseBranch = falseBranch; |
| 10434 // Initializers done |
| 10435 Expression.call(this, span); |
| 10436 } |
| 10437 ConditionalExpression.prototype.visit = function(visitor) { |
| 10438 return visitor.visitConditionalExpression(this); |
| 10439 } |
| 10440 ConditionalExpression.prototype.visit$1 = ConditionalExpression.prototype.visit; |
| 10441 // ********** Code for IsExpression ************** |
| 10442 $inherits(IsExpression, Expression); |
| 10443 function IsExpression(isTrue, x, type, span) { |
| 10444 this.isTrue = isTrue; |
| 10445 this.x = x; |
| 10446 this.type = type; |
| 10447 // Initializers done |
| 10448 Expression.call(this, span); |
| 10449 } |
| 10450 IsExpression.prototype.get$x = function() { return this.x; }; |
| 10451 IsExpression.prototype.set$x = function(value) { return this.x = value; }; |
| 10452 IsExpression.prototype.get$type = function() { return this.type; }; |
| 10453 IsExpression.prototype.set$type = function(value) { return this.type = value; }; |
| 10454 IsExpression.prototype.visit = function(visitor) { |
| 10455 return visitor.visitIsExpression(this); |
| 10456 } |
| 10457 IsExpression.prototype.visit$1 = IsExpression.prototype.visit; |
| 10458 // ********** Code for ParenExpression ************** |
| 10459 $inherits(ParenExpression, Expression); |
| 10460 function ParenExpression(body, span) { |
| 10461 this.body = body; |
| 10462 // Initializers done |
| 10463 Expression.call(this, span); |
| 10464 } |
| 10465 ParenExpression.prototype.get$body = function() { return this.body; }; |
| 10466 ParenExpression.prototype.set$body = function(value) { return this.body = value;
}; |
| 10467 ParenExpression.prototype.visit = function(visitor) { |
| 10468 return visitor.visitParenExpression(this); |
| 10469 } |
| 10470 ParenExpression.prototype.visit$1 = ParenExpression.prototype.visit; |
| 10471 // ********** Code for AwaitExpression ************** |
| 10472 $inherits(AwaitExpression, Expression); |
| 10473 function AwaitExpression(body, span) { |
| 10474 this.body = body; |
| 10475 // Initializers done |
| 10476 Expression.call(this, span); |
| 10477 } |
| 10478 AwaitExpression.prototype.get$body = function() { return this.body; }; |
| 10479 AwaitExpression.prototype.set$body = function(value) { return this.body = value;
}; |
| 10480 AwaitExpression.prototype.visit = function(visitor) { |
| 10481 return visitor.visitAwaitExpression(this); |
| 10482 } |
| 10483 AwaitExpression.prototype.visit$1 = AwaitExpression.prototype.visit; |
| 10484 // ********** Code for DotExpression ************** |
| 10485 $inherits(DotExpression, Expression); |
| 10486 function DotExpression(self, name, span) { |
| 10487 this.self = self; |
| 10488 this.name = name; |
| 10489 // Initializers done |
| 10490 Expression.call(this, span); |
| 10491 } |
| 10492 DotExpression.prototype.get$self = function() { return this.self; }; |
| 10493 DotExpression.prototype.set$self = function(value) { return this.self = value; }
; |
| 10494 DotExpression.prototype.get$name = function() { return this.name; }; |
| 10495 DotExpression.prototype.set$name = function(value) { return this.name = value; }
; |
| 10496 DotExpression.prototype.visit = function(visitor) { |
| 10497 return visitor.visitDotExpression(this); |
| 10498 } |
| 10499 DotExpression.prototype.visit$1 = DotExpression.prototype.visit; |
| 10500 // ********** Code for VarExpression ************** |
| 10501 $inherits(VarExpression, Expression); |
| 10502 function VarExpression(name, span) { |
| 10503 this.name = name; |
| 10504 // Initializers done |
| 10505 Expression.call(this, span); |
| 10506 } |
| 10507 VarExpression.prototype.get$name = function() { return this.name; }; |
| 10508 VarExpression.prototype.set$name = function(value) { return this.name = value; }
; |
| 10509 VarExpression.prototype.visit = function(visitor) { |
| 10510 return visitor.visitVarExpression(this); |
| 10511 } |
| 10512 VarExpression.prototype.visit$1 = VarExpression.prototype.visit; |
| 10513 // ********** Code for ThisExpression ************** |
| 10514 $inherits(ThisExpression, Expression); |
| 10515 function ThisExpression(span) { |
| 10516 // Initializers done |
| 10517 Expression.call(this, span); |
| 10518 } |
| 10519 ThisExpression.prototype.visit = function(visitor) { |
| 10520 return visitor.visitThisExpression(this); |
| 10521 } |
| 10522 ThisExpression.prototype.visit$1 = ThisExpression.prototype.visit; |
| 10523 // ********** Code for SuperExpression ************** |
| 10524 $inherits(SuperExpression, Expression); |
| 10525 function SuperExpression(span) { |
| 10526 // Initializers done |
| 10527 Expression.call(this, span); |
| 10528 } |
| 10529 SuperExpression.prototype.visit = function(visitor) { |
| 10530 return visitor.visitSuperExpression(this); |
| 10531 } |
| 10532 SuperExpression.prototype.visit$1 = SuperExpression.prototype.visit; |
| 10533 // ********** Code for NullExpression ************** |
| 10534 $inherits(NullExpression, Expression); |
| 10535 function NullExpression(span) { |
| 10536 // Initializers done |
| 10537 Expression.call(this, span); |
| 10538 } |
| 10539 NullExpression.prototype.visit = function(visitor) { |
| 10540 return visitor.visitNullExpression(this); |
| 10541 } |
| 10542 NullExpression.prototype.visit$1 = NullExpression.prototype.visit; |
| 10543 // ********** Code for LiteralExpression ************** |
| 10544 $inherits(LiteralExpression, Expression); |
| 10545 function LiteralExpression(value, type, text, span) { |
| 10546 this.value = value; |
| 10547 this.type = type; |
| 10548 this.text = text; |
| 10549 // Initializers done |
| 10550 Expression.call(this, span); |
| 10551 } |
| 10552 LiteralExpression.prototype.get$value = function() { return this.value; }; |
| 10553 LiteralExpression.prototype.set$value = function(value) { return this.value = va
lue; }; |
| 10554 LiteralExpression.prototype.get$type = function() { return this.type; }; |
| 10555 LiteralExpression.prototype.set$type = function(value) { return this.type = valu
e; }; |
| 10556 LiteralExpression.prototype.get$text = function() { return this.text; }; |
| 10557 LiteralExpression.prototype.set$text = function(value) { return this.text = valu
e; }; |
| 10558 LiteralExpression.prototype.visit = function(visitor) { |
| 10559 return visitor.visitLiteralExpression(this); |
| 10560 } |
| 10561 LiteralExpression.prototype.visit$1 = LiteralExpression.prototype.visit; |
| 10562 // ********** Code for NameTypeReference ************** |
| 10563 $inherits(NameTypeReference, TypeReference); |
| 10564 function NameTypeReference(isFinal, name, names, span) { |
| 10565 this.isFinal = isFinal; |
| 10566 this.name = name; |
| 10567 this.names = names; |
| 10568 // Initializers done |
| 10569 TypeReference.call(this, span); |
| 10570 } |
| 10571 NameTypeReference.prototype.get$isFinal = function() { return this.isFinal; }; |
| 10572 NameTypeReference.prototype.set$isFinal = function(value) { return this.isFinal
= value; }; |
| 10573 NameTypeReference.prototype.get$name = function() { return this.name; }; |
| 10574 NameTypeReference.prototype.set$name = function(value) { return this.name = valu
e; }; |
| 10575 NameTypeReference.prototype.get$names = function() { return this.names; }; |
| 10576 NameTypeReference.prototype.set$names = function(value) { return this.names = va
lue; }; |
| 10577 NameTypeReference.prototype.visit = function(visitor) { |
| 10578 return visitor.visitNameTypeReference(this); |
| 10579 } |
| 10580 NameTypeReference.prototype.visit$1 = NameTypeReference.prototype.visit; |
| 10581 // ********** Code for GenericTypeReference ************** |
| 10582 $inherits(GenericTypeReference, TypeReference); |
| 10583 function GenericTypeReference(baseType, typeArguments, depth, span) { |
| 10584 this.baseType = baseType; |
| 10585 this.typeArguments = typeArguments; |
| 10586 this.depth = depth; |
| 10587 // Initializers done |
| 10588 TypeReference.call(this, span); |
| 10589 } |
| 10590 GenericTypeReference.prototype.get$baseType = function() { return this.baseType;
}; |
| 10591 GenericTypeReference.prototype.set$baseType = function(value) { return this.base
Type = value; }; |
| 10592 GenericTypeReference.prototype.get$typeArguments = function() { return this.type
Arguments; }; |
| 10593 GenericTypeReference.prototype.set$typeArguments = function(value) { return this
.typeArguments = value; }; |
| 10594 GenericTypeReference.prototype.get$depth = function() { return this.depth; }; |
| 10595 GenericTypeReference.prototype.set$depth = function(value) { return this.depth =
value; }; |
| 10596 GenericTypeReference.prototype.visit = function(visitor) { |
| 10597 return visitor.visitGenericTypeReference(this); |
| 10598 } |
| 10599 GenericTypeReference.prototype.visit$1 = GenericTypeReference.prototype.visit; |
| 10600 // ********** Code for FunctionTypeReference ************** |
| 10601 $inherits(FunctionTypeReference, TypeReference); |
| 10602 function FunctionTypeReference(isFinal, func, span) { |
| 10603 this.isFinal = isFinal; |
| 10604 this.func = func; |
| 10605 // Initializers done |
| 10606 TypeReference.call(this, span); |
| 10607 } |
| 10608 FunctionTypeReference.prototype.get$isFinal = function() { return this.isFinal;
}; |
| 10609 FunctionTypeReference.prototype.set$isFinal = function(value) { return this.isFi
nal = value; }; |
| 10610 FunctionTypeReference.prototype.get$func = function() { return this.func; }; |
| 10611 FunctionTypeReference.prototype.set$func = function(value) { return this.func =
value; }; |
| 10612 FunctionTypeReference.prototype.visit = function(visitor) { |
| 10613 return visitor.visitFunctionTypeReference(this); |
| 10614 } |
| 10615 FunctionTypeReference.prototype.visit$1 = FunctionTypeReference.prototype.visit; |
| 10616 // ********** Code for ArgumentNode ************** |
| 10617 $inherits(ArgumentNode, Node); |
| 10618 function ArgumentNode(label, value, span) { |
| 10619 this.label = label; |
| 10620 this.value = value; |
| 10621 // Initializers done |
| 10622 Node.call(this, span); |
| 10623 } |
| 10624 ArgumentNode.prototype.get$label = function() { return this.label; }; |
| 10625 ArgumentNode.prototype.set$label = function(value) { return this.label = value;
}; |
| 10626 ArgumentNode.prototype.get$value = function() { return this.value; }; |
| 10627 ArgumentNode.prototype.set$value = function(value) { return this.value = value;
}; |
| 10628 ArgumentNode.prototype.visit = function(visitor) { |
| 10629 return visitor.visitArgumentNode(this); |
| 10630 } |
| 10631 ArgumentNode.prototype.visit$1 = ArgumentNode.prototype.visit; |
| 10632 // ********** Code for FormalNode ************** |
| 10633 $inherits(FormalNode, Node); |
| 10634 function FormalNode(isThis, isRest, type, name, value, span) { |
| 10635 this.isThis = isThis; |
| 10636 this.isRest = isRest; |
| 10637 this.type = type; |
| 10638 this.name = name; |
| 10639 this.value = value; |
| 10640 // Initializers done |
| 10641 Node.call(this, span); |
| 10642 } |
| 10643 FormalNode.prototype.get$type = function() { return this.type; }; |
| 10644 FormalNode.prototype.set$type = function(value) { return this.type = value; }; |
| 10645 FormalNode.prototype.get$name = function() { return this.name; }; |
| 10646 FormalNode.prototype.set$name = function(value) { return this.name = value; }; |
| 10647 FormalNode.prototype.get$value = function() { return this.value; }; |
| 10648 FormalNode.prototype.set$value = function(value) { return this.value = value; }; |
| 10649 FormalNode.prototype.visit = function(visitor) { |
| 10650 return visitor.visitFormalNode(this); |
| 10651 } |
| 10652 FormalNode.prototype.visit$1 = FormalNode.prototype.visit; |
| 10653 // ********** Code for CatchNode ************** |
| 10654 $inherits(CatchNode, Node); |
| 10655 function CatchNode(exception, trace, body, span) { |
| 10656 this.exception = exception; |
| 10657 this.trace = trace; |
| 10658 this.body = body; |
| 10659 // Initializers done |
| 10660 Node.call(this, span); |
| 10661 } |
| 10662 CatchNode.prototype.get$exception = function() { return this.exception; }; |
| 10663 CatchNode.prototype.set$exception = function(value) { return this.exception = va
lue; }; |
| 10664 CatchNode.prototype.get$trace = function() { return this.trace; }; |
| 10665 CatchNode.prototype.set$trace = function(value) { return this.trace = value; }; |
| 10666 CatchNode.prototype.get$body = function() { return this.body; }; |
| 10667 CatchNode.prototype.set$body = function(value) { return this.body = value; }; |
| 10668 CatchNode.prototype.visit = function(visitor) { |
| 10669 return visitor.visitCatchNode(this); |
| 10670 } |
| 10671 CatchNode.prototype.visit$1 = CatchNode.prototype.visit; |
| 10672 // ********** Code for CaseNode ************** |
| 10673 $inherits(CaseNode, Node); |
| 10674 function CaseNode(label, cases, statements, span) { |
| 10675 this.label = label; |
| 10676 this.cases = cases; |
| 10677 this.statements = statements; |
| 10678 // Initializers done |
| 10679 Node.call(this, span); |
| 10680 } |
| 10681 CaseNode.prototype.get$label = function() { return this.label; }; |
| 10682 CaseNode.prototype.set$label = function(value) { return this.label = value; }; |
| 10683 CaseNode.prototype.get$cases = function() { return this.cases; }; |
| 10684 CaseNode.prototype.set$cases = function(value) { return this.cases = value; }; |
| 10685 CaseNode.prototype.get$statements = function() { return this.statements; }; |
| 10686 CaseNode.prototype.set$statements = function(value) { return this.statements = v
alue; }; |
| 10687 CaseNode.prototype.visit = function(visitor) { |
| 10688 return visitor.visitCaseNode(this); |
| 10689 } |
| 10690 CaseNode.prototype.visit$1 = CaseNode.prototype.visit; |
| 10691 // ********** Code for TypeParameter ************** |
| 10692 $inherits(TypeParameter, Node); |
| 10693 function TypeParameter(name, extendsType, span) { |
| 10694 this.name = name; |
| 10695 this.extendsType = extendsType; |
| 10696 // Initializers done |
| 10697 Node.call(this, span); |
| 10698 } |
| 10699 TypeParameter.prototype.get$name = function() { return this.name; }; |
| 10700 TypeParameter.prototype.set$name = function(value) { return this.name = value; }
; |
| 10701 TypeParameter.prototype.get$extendsType = function() { return this.extendsType;
}; |
| 10702 TypeParameter.prototype.set$extendsType = function(value) { return this.extendsT
ype = value; }; |
| 10703 TypeParameter.prototype.visit = function(visitor) { |
| 10704 return visitor.visitTypeParameter(this); |
| 10705 } |
| 10706 TypeParameter.prototype.visit$1 = TypeParameter.prototype.visit; |
| 10707 // ********** Code for Identifier ************** |
| 10708 $inherits(Identifier, Node); |
| 10709 function Identifier(name, span) { |
| 10710 this.name = name; |
| 10711 // Initializers done |
| 10712 Node.call(this, span); |
| 10713 } |
| 10714 Identifier.prototype.get$name = function() { return this.name; }; |
| 10715 Identifier.prototype.set$name = function(value) { return this.name = value; }; |
| 10716 Identifier.prototype.visit = function(visitor) { |
| 10717 return visitor.visitIdentifier(this); |
| 10718 } |
| 10719 Identifier.prototype.visit$1 = Identifier.prototype.visit; |
| 10720 // ********** Code for DeclaredIdentifier ************** |
| 10721 $inherits(DeclaredIdentifier, Expression); |
| 10722 function DeclaredIdentifier(type, name, span) { |
| 10723 this.type = type; |
| 10724 this.name = name; |
| 10725 // Initializers done |
| 10726 Expression.call(this, span); |
| 10727 } |
| 10728 DeclaredIdentifier.prototype.get$type = function() { return this.type; }; |
| 10729 DeclaredIdentifier.prototype.set$type = function(value) { return this.type = val
ue; }; |
| 10730 DeclaredIdentifier.prototype.get$name = function() { return this.name; }; |
| 10731 DeclaredIdentifier.prototype.set$name = function(value) { return this.name = val
ue; }; |
| 10732 DeclaredIdentifier.prototype.visit = function(visitor) { |
| 10733 return visitor.visitDeclaredIdentifier(this); |
| 10734 } |
| 10735 DeclaredIdentifier.prototype.visit$1 = DeclaredIdentifier.prototype.visit; |
| 10736 // ********** Code for Type ************** |
| 10737 $inherits(Type, Element); |
| 10738 function Type(name) { |
| 10739 this.isTested = false |
| 10740 this.isChecked = false |
| 10741 this.isWritten = false |
| 10742 this._resolvedMembers = new HashMapImplementation(); |
| 10743 this.varStubs = new HashMapImplementation(); |
| 10744 // Initializers done |
| 10745 Element.call(this, name, null); |
| 10746 } |
| 10747 Type.prototype.get$typeCheckCode = function() { return this.typeCheckCode; }; |
| 10748 Type.prototype.set$typeCheckCode = function(value) { return this.typeCheckCode =
value; }; |
| 10749 Type.prototype.get$varStubs = function() { return this.varStubs; }; |
| 10750 Type.prototype.set$varStubs = function(value) { return this.varStubs = value; }; |
| 10751 Type.prototype.markUsed = function() { |
| 10752 |
| 10753 } |
| 10754 Type.prototype.get$typeMember = function() { |
| 10755 if (this._typeMember == null) { |
| 10756 this._typeMember = new TypeMember(this); |
| 10757 } |
| 10758 return this._typeMember; |
| 10759 } |
| 10760 Type.prototype.getMember = function(name) { |
| 10761 return null; |
| 10762 } |
| 10763 Type.prototype.get$subtypes = function() { |
| 10764 return null; |
| 10765 } |
| 10766 Type.prototype.get$isVar = function() { |
| 10767 return false; |
| 10768 } |
| 10769 Type.prototype.get$isTop = function() { |
| 10770 return false; |
| 10771 } |
| 10772 Type.prototype.get$isObject = function() { |
| 10773 return false; |
| 10774 } |
| 10775 Type.prototype.get$isString = function() { |
| 10776 return false; |
| 10777 } |
| 10778 Type.prototype.get$isBool = function() { |
| 10779 return false; |
| 10780 } |
| 10781 Type.prototype.get$isFunction = function() { |
| 10782 return false; |
| 10783 } |
| 10784 Type.prototype.get$isList = function() { |
| 10785 return false; |
| 10786 } |
| 10787 Type.prototype.get$isNum = function() { |
| 10788 return false; |
| 10789 } |
| 10790 Type.prototype.get$isVoid = function() { |
| 10791 return false; |
| 10792 } |
| 10793 Type.prototype.get$isNullable = function() { |
| 10794 return true; |
| 10795 } |
| 10796 Type.prototype.get$isVarOrFunction = function() { |
| 10797 return this.get$isVar() || this.get$isFunction(); |
| 10798 } |
| 10799 Type.prototype.get$isVarOrObject = function() { |
| 10800 return this.get$isVar() || this.get$isObject(); |
| 10801 } |
| 10802 Type.prototype.getCallMethod = function() { |
| 10803 return null; |
| 10804 } |
| 10805 Type.prototype.get$isClosed = function() { |
| 10806 return this.get$isString() || this.get$isBool() || this.get$isNum() || this.ge
t$isFunction() || this.get$isVar(); |
| 10807 } |
| 10808 Type.prototype.get$isUsed = function() { |
| 10809 return false; |
| 10810 } |
| 10811 Type.prototype.get$isGeneric = function() { |
| 10812 return false; |
| 10813 } |
| 10814 Type.prototype.get$nativeType = function() { |
| 10815 return null; |
| 10816 } |
| 10817 Type.prototype.get$isHiddenNativeType = function() { |
| 10818 return (this.get$nativeType() != null && this.get$nativeType().isConstructorHi
dden); |
| 10819 } |
| 10820 Type.prototype.get$isSingletonNative = function() { |
| 10821 return (this.get$nativeType() != null && this.get$nativeType().isSingleton); |
| 10822 } |
| 10823 Type.prototype.get$isJsGlobalObject = function() { |
| 10824 return (this.get$nativeType() != null && this.get$nativeType().isJsGlobalObjec
t); |
| 10825 } |
| 10826 Type.prototype.get$hasTypeParams = function() { |
| 10827 return false; |
| 10828 } |
| 10829 Type.prototype.get$typeofName = function() { |
| 10830 return null; |
| 10831 } |
| 10832 Type.prototype.get$members = function() { |
| 10833 return null; |
| 10834 } |
| 10835 Type.prototype.get$definition = function() { |
| 10836 return null; |
| 10837 } |
| 10838 Type.prototype.get$factories = function() { |
| 10839 return null; |
| 10840 } |
| 10841 Type.prototype.get$typeArgsInOrder = function() { |
| 10842 return null; |
| 10843 } |
| 10844 Type.prototype.get$genericType = function() { |
| 10845 return this; |
| 10846 } |
| 10847 Type.prototype.get$interfaces = function() { |
| 10848 return null; |
| 10849 } |
| 10850 Type.prototype.get$parent = function() { |
| 10851 return null; |
| 10852 } |
| 10853 Type.prototype.getAllMembers = function() { |
| 10854 return new HashMapImplementation(); |
| 10855 } |
| 10856 Type.prototype.get$hasNativeSubtypes = function() { |
| 10857 if (this._hasNativeSubtypes == null) { |
| 10858 this._hasNativeSubtypes = this.get$subtypes().some((function (t) { |
| 10859 return t.get$isNative(); |
| 10860 }) |
| 10861 ); |
| 10862 } |
| 10863 return this._hasNativeSubtypes; |
| 10864 } |
| 10865 Type.prototype._checkExtends = function() { |
| 10866 var typeParams = this.get$genericType().typeParameters; |
| 10867 if (typeParams != null && this.get$typeArgsInOrder() != null) { |
| 10868 var args = this.get$typeArgsInOrder().iterator$0(); |
| 10869 var params = typeParams.iterator$0(); |
| 10870 while (args.hasNext$0() && params.hasNext$0()) { |
| 10871 var typeParam = params.next$0(); |
| 10872 var typeArg = args.next$0(); |
| 10873 if (typeParam.get$extendsType() != null && typeArg != null) { |
| 10874 typeArg.ensureSubtypeOf$3(typeParam.get$extendsType(), typeParam.get$spa
n(), true); |
| 10875 } |
| 10876 } |
| 10877 } |
| 10878 if (this.get$interfaces() != null) { |
| 10879 var $$list = this.get$interfaces(); |
| 10880 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 10881 var i = $$list.$index($$i); |
| 10882 i._checkExtends$0(); |
| 10883 } |
| 10884 } |
| 10885 } |
| 10886 Type.prototype._checkOverride = function(member) { |
| 10887 var parentMember = this._getMemberInParents(member.name); |
| 10888 if (parentMember != null) { |
| 10889 if (!member.get$isPrivate() || $eq(member.get$library(), parentMember.get$li
brary())) { |
| 10890 member.override(parentMember); |
| 10891 } |
| 10892 } |
| 10893 } |
| 10894 Type.prototype._createNotEqualMember = function() { |
| 10895 var eq = this.get$members().$index(':eq'); |
| 10896 if (eq == null) { |
| 10897 return; |
| 10898 } |
| 10899 var ne = new MethodMember(':ne', this, eq.definition); |
| 10900 ne.isGenerated = true; |
| 10901 ne.returnType = eq.returnType; |
| 10902 ne.parameters = eq.parameters; |
| 10903 ne.isStatic = eq.isStatic; |
| 10904 ne.isAbstract = eq.isAbstract; |
| 10905 this.get$members().$setindex(':ne', ne); |
| 10906 } |
| 10907 Type.prototype._getMemberInParents = function(memberName) { |
| 10908 if (this.get$isClass()) { |
| 10909 if (this.get$parent() != null) { |
| 10910 return this.get$parent().getMember(memberName); |
| 10911 } |
| 10912 else { |
| 10913 return null; |
| 10914 } |
| 10915 } |
| 10916 else { |
| 10917 if (this.get$interfaces() != null && this.get$interfaces().length > 0) { |
| 10918 var $$list = this.get$interfaces(); |
| 10919 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 10920 var i = $$list.$index($$i); |
| 10921 var ret = i.getMember$1(memberName); |
| 10922 if (ret != null) { |
| 10923 return ret; |
| 10924 } |
| 10925 } |
| 10926 } |
| 10927 return $globals.world.objectType.getMember(memberName); |
| 10928 } |
| 10929 } |
| 10930 Type.prototype.resolveMember = function(memberName) { |
| 10931 var ret = this._resolvedMembers.$index(memberName); |
| 10932 if (ret != null) return ret; |
| 10933 var member = this.getMember(memberName); |
| 10934 if (member == null) { |
| 10935 return null; |
| 10936 } |
| 10937 ret = new MemberSet(member, false); |
| 10938 this._resolvedMembers.$setindex(memberName, ret); |
| 10939 if (member.get$isStatic()) { |
| 10940 return ret; |
| 10941 } |
| 10942 else { |
| 10943 var $$list = this.get$subtypes(); |
| 10944 for (var $$i = this.get$subtypes().iterator(); $$i.hasNext$0(); ) { |
| 10945 var t = $$i.next$0(); |
| 10946 if (!this.get$isClass() && t.get$isClass()) { |
| 10947 var m = t.getMember$1(memberName); |
| 10948 if (m != null && ret.members.indexOf(m) == -1) { |
| 10949 ret.add(m); |
| 10950 } |
| 10951 } |
| 10952 else { |
| 10953 var m = t.get$members().$index(memberName); |
| 10954 if (m != null) ret.add(m); |
| 10955 } |
| 10956 } |
| 10957 return ret; |
| 10958 } |
| 10959 } |
| 10960 Type.prototype.ensureSubtypeOf = function(other, span, typeErrors) { |
| 10961 if (!this.isSubtypeOf(other)) { |
| 10962 var msg = ('type ' + this.name + ' is not a subtype of ' + other.name); |
| 10963 if (typeErrors) { |
| 10964 $globals.world.error(msg, span); |
| 10965 } |
| 10966 else { |
| 10967 $globals.world.warning(msg, span); |
| 10968 } |
| 10969 } |
| 10970 } |
| 10971 Type.prototype.needsVarCall = function(args) { |
| 10972 if (this.get$isVarOrFunction()) { |
| 10973 return true; |
| 10974 } |
| 10975 var call = this.getCallMethod(); |
| 10976 if (call != null) { |
| 10977 if (args.get$length() != call.get$parameters().length || !call.namesInOrder$
1(args)) { |
| 10978 return true; |
| 10979 } |
| 10980 } |
| 10981 return false; |
| 10982 } |
| 10983 Type.union = function(x, y) { |
| 10984 if ($eq(x, y)) return x; |
| 10985 if (x.get$isNum() && y.get$isNum()) return $globals.world.numType; |
| 10986 if (x.get$isString() && y.get$isString()) return $globals.world.stringType; |
| 10987 return $globals.world.varType; |
| 10988 } |
| 10989 Type.prototype.isAssignable = function(other) { |
| 10990 return this.isSubtypeOf(other) || other.isSubtypeOf(this); |
| 10991 } |
| 10992 Type.prototype._isDirectSupertypeOf = function(other) { |
| 10993 var $this = this; // closure support |
| 10994 if (other.get$isClass()) { |
| 10995 return $eq(other.get$parent(), this) || this.get$isObject() && other.get$par
ent() == null; |
| 10996 } |
| 10997 else { |
| 10998 if (other.get$interfaces() == null || other.get$interfaces().isEmpty()) { |
| 10999 return this.get$isObject(); |
| 11000 } |
| 11001 else { |
| 11002 return other.get$interfaces().some((function (i) { |
| 11003 return $eq(i, $this); |
| 11004 }) |
| 11005 ); |
| 11006 } |
| 11007 } |
| 11008 } |
| 11009 Type.prototype.isSubtypeOf = function(other) { |
| 11010 if ((other instanceof ParameterType)) { |
| 11011 return true; |
| 11012 } |
| 11013 if ($eq(this, other)) return true; |
| 11014 if (this.get$isVar()) return true; |
| 11015 if (other.get$isVar()) return true; |
| 11016 if (other._isDirectSupertypeOf(this)) return true; |
| 11017 var call = this.getCallMethod(); |
| 11018 var otherCall = other.getCallMethod(); |
| 11019 if (call != null && otherCall != null) { |
| 11020 return Type._isFunctionSubtypeOf(call, otherCall); |
| 11021 } |
| 11022 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)) { |
| 11023 var t = this.get$typeArgsInOrder().iterator$0(); |
| 11024 var s = other.get$typeArgsInOrder().iterator$0(); |
| 11025 while (t.hasNext$0()) { |
| 11026 if (!t.next$0().isSubtypeOf$1(s.next$0())) return false; |
| 11027 } |
| 11028 return true; |
| 11029 } |
| 11030 if (this.get$parent() != null && this.get$parent().isSubtypeOf(other)) { |
| 11031 return true; |
| 11032 } |
| 11033 if (this.get$interfaces() != null && this.get$interfaces().some((function (i)
{ |
| 11034 return i.isSubtypeOf$1(other); |
| 11035 }) |
| 11036 )) { |
| 11037 return true; |
| 11038 } |
| 11039 return false; |
| 11040 } |
| 11041 Type.prototype.hashCode = function() { |
| 11042 var libraryCode = this.get$library() == null ? 1 : this.get$library().hashCode
(); |
| 11043 var nameCode = this.name == null ? 1 : this.name.hashCode(); |
| 11044 return (libraryCode << 4) ^ nameCode; |
| 11045 } |
| 11046 Type.prototype.$eq = function(other) { |
| 11047 return (other instanceof Type) && $eq(other.get$name(), this.name) && $eq(this
.get$library(), other.get$library()); |
| 11048 } |
| 11049 Type._isFunctionSubtypeOf = function(t, s) { |
| 11050 if (!s.returnType.get$isVoid() && !s.returnType.isAssignable(t.returnType)) { |
| 11051 return false; |
| 11052 } |
| 11053 var tp = t.parameters; |
| 11054 var sp = s.parameters; |
| 11055 if (tp.length < sp.length) return false; |
| 11056 for (var i = 0; |
| 11057 i < sp.length; i++) { |
| 11058 if ($ne(tp.$index(i).get$isOptional(), sp.$index(i).get$isOptional())) retur
n false; |
| 11059 if (tp.$index(i).get$isOptional() && $ne(tp.$index(i).get$name(), sp.$index(
i).get$name())) return false; |
| 11060 if (!tp.$index(i).get$type().isAssignable$1(sp.$index(i).get$type())) return
false; |
| 11061 } |
| 11062 if (tp.length > sp.length && !tp.$index(sp.length).get$isOptional()) return fa
lse; |
| 11063 return true; |
| 11064 } |
| 11065 Type.prototype._checkExtends$0 = Type.prototype._checkExtends; |
| 11066 Type.prototype.addDirectSubtype$1 = Type.prototype.addDirectSubtype; |
| 11067 Type.prototype.ensureSubtypeOf$3 = Type.prototype.ensureSubtypeOf; |
| 11068 Type.prototype.getConstructor$1 = Type.prototype.getConstructor; |
| 11069 Type.prototype.getFactory$2 = Type.prototype.getFactory; |
| 11070 Type.prototype.getMember$1 = Type.prototype.getMember; |
| 11071 Type.prototype.getOrMakeConcreteType$1 = Type.prototype.getOrMakeConcreteType; |
| 11072 Type.prototype.hashCode$0 = Type.prototype.hashCode; |
| 11073 Type.prototype.isAssignable$1 = Type.prototype.isAssignable; |
| 11074 Type.prototype.isSubtypeOf$1 = Type.prototype.isSubtypeOf; |
| 11075 Type.prototype.markUsed$0 = Type.prototype.markUsed; |
| 11076 Type.prototype.resolveTypeParams$1 = Type.prototype.resolveTypeParams; |
| 11077 // ********** Code for ParameterType ************** |
| 11078 $inherits(ParameterType, Type); |
| 11079 function ParameterType(name, typeParameter) { |
| 11080 this.typeParameter = typeParameter; |
| 11081 // Initializers done |
| 11082 Type.call(this, name); |
| 11083 } |
| 11084 ParameterType.prototype.get$typeParameter = function() { return this.typeParamet
er; }; |
| 11085 ParameterType.prototype.set$typeParameter = function(value) { return this.typePa
rameter = value; }; |
| 11086 ParameterType.prototype.get$extendsType = function() { return this.extendsType;
}; |
| 11087 ParameterType.prototype.set$extendsType = function(value) { return this.extendsT
ype = value; }; |
| 11088 ParameterType.prototype.get$isClass = function() { |
| 11089 return false; |
| 11090 } |
| 11091 ParameterType.prototype.get$library = function() { |
| 11092 return null; |
| 11093 } |
| 11094 ParameterType.prototype.get$span = function() { |
| 11095 return this.typeParameter.span; |
| 11096 } |
| 11097 ParameterType.prototype.get$constructors = function() { |
| 11098 $globals.world.internalError('no constructors on type parameters yet'); |
| 11099 } |
| 11100 ParameterType.prototype.getCallMethod = function() { |
| 11101 return this.extendsType.getCallMethod(); |
| 11102 } |
| 11103 ParameterType.prototype.genMethod = function(method) { |
| 11104 this.extendsType.genMethod(method); |
| 11105 } |
| 11106 ParameterType.prototype.isSubtypeOf = function(other) { |
| 11107 return true; |
| 11108 } |
| 11109 ParameterType.prototype.resolveMember = function(memberName) { |
| 11110 return this.extendsType.resolveMember(memberName); |
| 11111 } |
| 11112 ParameterType.prototype.getConstructor = function(constructorName) { |
| 11113 $globals.world.internalError('no constructors on type parameters yet'); |
| 11114 } |
| 11115 ParameterType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11116 $globals.world.internalError('no concrete types of type parameters yet', this.
get$span()); |
| 11117 } |
| 11118 ParameterType.prototype.resolveTypeParams = function(inType) { |
| 11119 return inType.typeArguments.$index(this.name); |
| 11120 } |
| 11121 ParameterType.prototype.addDirectSubtype = function(type) { |
| 11122 $globals.world.internalError('no subtypes of type parameters yet', this.get$sp
an()); |
| 11123 } |
| 11124 ParameterType.prototype.resolve = function() { |
| 11125 if (this.typeParameter.extendsType != null) { |
| 11126 this.extendsType = this.get$enclosingElement().resolveType(this.typeParamete
r.extendsType, true); |
| 11127 } |
| 11128 else { |
| 11129 this.extendsType = $globals.world.objectType; |
| 11130 } |
| 11131 } |
| 11132 ParameterType.prototype.addDirectSubtype$1 = ParameterType.prototype.addDirectSu
btype; |
| 11133 ParameterType.prototype.getConstructor$1 = ParameterType.prototype.getConstructo
r; |
| 11134 ParameterType.prototype.getOrMakeConcreteType$1 = ParameterType.prototype.getOrM
akeConcreteType; |
| 11135 ParameterType.prototype.isSubtypeOf$1 = ParameterType.prototype.isSubtypeOf; |
| 11136 ParameterType.prototype.resolve$0 = ParameterType.prototype.resolve; |
| 11137 ParameterType.prototype.resolveTypeParams$1 = ParameterType.prototype.resolveTyp
eParams; |
| 11138 // ********** Code for NonNullableType ************** |
| 11139 $inherits(NonNullableType, Type); |
| 11140 function NonNullableType(type) { |
| 11141 this.type = type; |
| 11142 // Initializers done |
| 11143 Type.call(this, type.name); |
| 11144 } |
| 11145 NonNullableType.prototype.get$type = function() { return this.type; }; |
| 11146 NonNullableType.prototype.get$isNullable = function() { |
| 11147 return false; |
| 11148 } |
| 11149 NonNullableType.prototype.get$isBool = function() { |
| 11150 return this.type.get$isBool(); |
| 11151 } |
| 11152 NonNullableType.prototype.get$isUsed = function() { |
| 11153 return false; |
| 11154 } |
| 11155 NonNullableType.prototype.isSubtypeOf = function(other) { |
| 11156 return $eq(this, other) || $eq(this.type, other) || this.type.isSubtypeOf(othe
r); |
| 11157 } |
| 11158 NonNullableType.prototype.resolveType = function(node, isRequired) { |
| 11159 return this.type.resolveType(node, isRequired); |
| 11160 } |
| 11161 NonNullableType.prototype.resolveTypeParams = function(inType) { |
| 11162 return this.type.resolveTypeParams(inType); |
| 11163 } |
| 11164 NonNullableType.prototype.addDirectSubtype = function(subtype) { |
| 11165 this.type.addDirectSubtype(subtype); |
| 11166 } |
| 11167 NonNullableType.prototype.markUsed = function() { |
| 11168 this.type.markUsed(); |
| 11169 } |
| 11170 NonNullableType.prototype.genMethod = function(method) { |
| 11171 this.type.genMethod(method); |
| 11172 } |
| 11173 NonNullableType.prototype.get$span = function() { |
| 11174 return this.type.get$span(); |
| 11175 } |
| 11176 NonNullableType.prototype.resolveMember = function(name) { |
| 11177 return this.type.resolveMember(name); |
| 11178 } |
| 11179 NonNullableType.prototype.getMember = function(name) { |
| 11180 return this.type.getMember(name); |
| 11181 } |
| 11182 NonNullableType.prototype.getConstructor = function(name) { |
| 11183 return this.type.getConstructor(name); |
| 11184 } |
| 11185 NonNullableType.prototype.getFactory = function(t, name) { |
| 11186 return this.type.getFactory(t, name); |
| 11187 } |
| 11188 NonNullableType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11189 return this.type.getOrMakeConcreteType(typeArgs); |
| 11190 } |
| 11191 NonNullableType.prototype.get$constructors = function() { |
| 11192 return this.type.get$constructors(); |
| 11193 } |
| 11194 NonNullableType.prototype.get$isClass = function() { |
| 11195 return this.type.get$isClass(); |
| 11196 } |
| 11197 NonNullableType.prototype.get$library = function() { |
| 11198 return this.type.get$library(); |
| 11199 } |
| 11200 NonNullableType.prototype.getCallMethod = function() { |
| 11201 return this.type.getCallMethod(); |
| 11202 } |
| 11203 NonNullableType.prototype.get$isGeneric = function() { |
| 11204 return this.type.get$isGeneric(); |
| 11205 } |
| 11206 NonNullableType.prototype.get$hasTypeParams = function() { |
| 11207 return this.type.get$hasTypeParams(); |
| 11208 } |
| 11209 NonNullableType.prototype.get$typeofName = function() { |
| 11210 return this.type.get$typeofName(); |
| 11211 } |
| 11212 NonNullableType.prototype.get$jsname = function() { |
| 11213 return this.type.get$jsname(); |
| 11214 } |
| 11215 NonNullableType.prototype.get$members = function() { |
| 11216 return this.type.get$members(); |
| 11217 } |
| 11218 NonNullableType.prototype.get$definition = function() { |
| 11219 return this.type.get$definition(); |
| 11220 } |
| 11221 NonNullableType.prototype.get$factories = function() { |
| 11222 return this.type.get$factories(); |
| 11223 } |
| 11224 NonNullableType.prototype.get$typeArgsInOrder = function() { |
| 11225 return this.type.get$typeArgsInOrder(); |
| 11226 } |
| 11227 NonNullableType.prototype.get$genericType = function() { |
| 11228 return this.type.get$genericType(); |
| 11229 } |
| 11230 NonNullableType.prototype.get$interfaces = function() { |
| 11231 return this.type.get$interfaces(); |
| 11232 } |
| 11233 NonNullableType.prototype.get$parent = function() { |
| 11234 return this.type.get$parent(); |
| 11235 } |
| 11236 NonNullableType.prototype.getAllMembers = function() { |
| 11237 return this.type.getAllMembers(); |
| 11238 } |
| 11239 NonNullableType.prototype.get$isNative = function() { |
| 11240 return this.type.get$isNative(); |
| 11241 } |
| 11242 NonNullableType.prototype.addDirectSubtype$1 = NonNullableType.prototype.addDire
ctSubtype; |
| 11243 NonNullableType.prototype.getConstructor$1 = NonNullableType.prototype.getConstr
uctor; |
| 11244 NonNullableType.prototype.getFactory$2 = NonNullableType.prototype.getFactory; |
| 11245 NonNullableType.prototype.getMember$1 = NonNullableType.prototype.getMember; |
| 11246 NonNullableType.prototype.getOrMakeConcreteType$1 = NonNullableType.prototype.ge
tOrMakeConcreteType; |
| 11247 NonNullableType.prototype.isSubtypeOf$1 = NonNullableType.prototype.isSubtypeOf; |
| 11248 NonNullableType.prototype.markUsed$0 = NonNullableType.prototype.markUsed; |
| 11249 NonNullableType.prototype.resolveTypeParams$1 = NonNullableType.prototype.resolv
eTypeParams; |
| 11250 // ********** Code for ConcreteType ************** |
| 11251 $inherits(ConcreteType, Type); |
| 11252 function ConcreteType(name, genericType, typeArguments, typeArgsInOrder) { |
| 11253 this.isUsed = false |
| 11254 this.genericType = genericType; |
| 11255 this.typeArguments = typeArguments; |
| 11256 this.typeArgsInOrder = typeArgsInOrder; |
| 11257 this.constructors = new HashMapImplementation(); |
| 11258 this.members = new HashMapImplementation(); |
| 11259 this.factories = new FactoryMap(); |
| 11260 // Initializers done |
| 11261 Type.call(this, name); |
| 11262 } |
| 11263 ConcreteType.prototype.get$genericType = function() { return this.genericType; }
; |
| 11264 ConcreteType.prototype.get$typeArguments = function() { return this.typeArgument
s; }; |
| 11265 ConcreteType.prototype.set$typeArguments = function(value) { return this.typeArg
uments = value; }; |
| 11266 ConcreteType.prototype.get$_parent = function() { return this._parent; }; |
| 11267 ConcreteType.prototype.set$_parent = function(value) { return this._parent = val
ue; }; |
| 11268 ConcreteType.prototype.get$typeArgsInOrder = function() { return this.typeArgsIn
Order; }; |
| 11269 ConcreteType.prototype.set$typeArgsInOrder = function(value) { return this.typeA
rgsInOrder = value; }; |
| 11270 ConcreteType.prototype.get$isList = function() { |
| 11271 return this.genericType.get$isList(); |
| 11272 } |
| 11273 ConcreteType.prototype.get$isClass = function() { |
| 11274 return this.genericType.isClass; |
| 11275 } |
| 11276 ConcreteType.prototype.get$library = function() { |
| 11277 return this.genericType.library; |
| 11278 } |
| 11279 ConcreteType.prototype.get$span = function() { |
| 11280 return this.genericType.get$span(); |
| 11281 } |
| 11282 ConcreteType.prototype.get$hasTypeParams = function() { |
| 11283 return this.typeArguments.getValues().some$1((function (e) { |
| 11284 return (e instanceof ParameterType); |
| 11285 }) |
| 11286 ); |
| 11287 } |
| 11288 ConcreteType.prototype.get$isUsed = function() { return this.isUsed; }; |
| 11289 ConcreteType.prototype.set$isUsed = function(value) { return this.isUsed = value
; }; |
| 11290 ConcreteType.prototype.get$members = function() { return this.members; }; |
| 11291 ConcreteType.prototype.set$members = function(value) { return this.members = val
ue; }; |
| 11292 ConcreteType.prototype.get$constructors = function() { return this.constructors;
}; |
| 11293 ConcreteType.prototype.set$constructors = function(value) { return this.construc
tors = value; }; |
| 11294 ConcreteType.prototype.get$factories = function() { return this.factories; }; |
| 11295 ConcreteType.prototype.set$factories = function(value) { return this.factories =
value; }; |
| 11296 ConcreteType.prototype.resolveTypeParams = function(inType) { |
| 11297 var newTypeArgs = []; |
| 11298 var needsNewType = false; |
| 11299 var $$list = this.typeArgsInOrder; |
| 11300 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11301 var t = $$list.$index($$i); |
| 11302 var newType = t.resolveTypeParams$1(inType); |
| 11303 if ($ne(newType, t)) needsNewType = true; |
| 11304 newTypeArgs.add$1(newType); |
| 11305 } |
| 11306 if (!needsNewType) return this; |
| 11307 return this.genericType.getOrMakeConcreteType(newTypeArgs); |
| 11308 } |
| 11309 ConcreteType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11310 return this.genericType.getOrMakeConcreteType(typeArgs); |
| 11311 } |
| 11312 ConcreteType.prototype.get$parent = function() { |
| 11313 if (this._parent == null && this.genericType.get$parent() != null) { |
| 11314 this._parent = this.genericType.get$parent().resolveTypeParams(this); |
| 11315 } |
| 11316 return this._parent; |
| 11317 } |
| 11318 ConcreteType.prototype.get$interfaces = function() { |
| 11319 if (this._interfaces == null && this.genericType.interfaces != null) { |
| 11320 this._interfaces = []; |
| 11321 var $$list = this.genericType.interfaces; |
| 11322 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11323 var i = $$list.$index($$i); |
| 11324 this._interfaces.add(i.resolveTypeParams$1(this)); |
| 11325 } |
| 11326 } |
| 11327 return this._interfaces; |
| 11328 } |
| 11329 ConcreteType.prototype.get$subtypes = function() { |
| 11330 if (this._subtypes == null) { |
| 11331 this._subtypes = new HashSetImplementation(); |
| 11332 var $$list = this.genericType.get$subtypes(); |
| 11333 for (var $$i = this.genericType.get$subtypes().iterator(); $$i.hasNext$0();
) { |
| 11334 var s = $$i.next$0(); |
| 11335 this._subtypes.add(s.resolveTypeParams$1(this)); |
| 11336 } |
| 11337 } |
| 11338 return this._subtypes; |
| 11339 } |
| 11340 ConcreteType.prototype.getCallMethod = function() { |
| 11341 return this.genericType.getCallMethod(); |
| 11342 } |
| 11343 ConcreteType.prototype.getAllMembers = function() { |
| 11344 var result = this.genericType.getAllMembers(); |
| 11345 var $$list = result.getKeys$0(); |
| 11346 for (var $$i = result.getKeys$0().iterator$0(); $$i.hasNext$0(); ) { |
| 11347 var memberName = $$i.next$0(); |
| 11348 var myMember = this.members.$index(memberName); |
| 11349 if (myMember != null) { |
| 11350 result.$setindex(memberName, myMember); |
| 11351 } |
| 11352 } |
| 11353 return result; |
| 11354 } |
| 11355 ConcreteType.prototype.markUsed = function() { |
| 11356 if (this.isUsed) return; |
| 11357 this.isUsed = true; |
| 11358 this._checkExtends(); |
| 11359 this.genericType.markUsed(); |
| 11360 } |
| 11361 ConcreteType.prototype.genMethod = function(method) { |
| 11362 return this.genericType.genMethod(method); |
| 11363 } |
| 11364 ConcreteType.prototype.getFactory = function(type, constructorName) { |
| 11365 return this.genericType.getFactory(type, constructorName); |
| 11366 } |
| 11367 ConcreteType.prototype.getConstructor = function(constructorName) { |
| 11368 var ret = this.constructors.$index(constructorName); |
| 11369 if (ret != null) return ret; |
| 11370 ret = this.factories.getFactory(this.name, constructorName); |
| 11371 if (ret != null) return ret; |
| 11372 var genericMember = this.genericType.getConstructor(constructorName); |
| 11373 if (genericMember == null) return null; |
| 11374 if ($ne(genericMember.get$declaringType(), this.genericType)) { |
| 11375 if (!genericMember.get$declaringType().get$isGeneric()) return genericMember
; |
| 11376 var newDeclaringType = genericMember.get$declaringType().getOrMakeConcreteTy
pe$1(this.typeArgsInOrder); |
| 11377 var factory = newDeclaringType.getFactory$2(this.genericType, constructorNam
e); |
| 11378 if (factory != null) return factory; |
| 11379 return newDeclaringType.getConstructor$1(constructorName); |
| 11380 } |
| 11381 if (genericMember.get$isFactory()) { |
| 11382 ret = new ConcreteMember(genericMember.get$name(), this, genericMember); |
| 11383 this.factories.addFactory(this.name, constructorName, ret); |
| 11384 } |
| 11385 else { |
| 11386 ret = new ConcreteMember(this.name, this, genericMember); |
| 11387 this.constructors.$setindex(constructorName, ret); |
| 11388 } |
| 11389 return ret; |
| 11390 } |
| 11391 ConcreteType.prototype.getMember = function(memberName) { |
| 11392 var member = this.members.$index(memberName); |
| 11393 if (member != null) { |
| 11394 this._checkOverride(member); |
| 11395 return member; |
| 11396 } |
| 11397 var genericMember = this.genericType.members.$index(memberName); |
| 11398 if (genericMember != null) { |
| 11399 member = new ConcreteMember(genericMember.get$name(), this, genericMember); |
| 11400 this.members.$setindex(memberName, member); |
| 11401 return member; |
| 11402 } |
| 11403 return this._getMemberInParents(memberName); |
| 11404 } |
| 11405 ConcreteType.prototype.resolveType = function(node, isRequired) { |
| 11406 var ret = this.genericType.resolveType(node, isRequired); |
| 11407 return ret; |
| 11408 } |
| 11409 ConcreteType.prototype.addDirectSubtype = function(type) { |
| 11410 this.genericType.addDirectSubtype(type); |
| 11411 } |
| 11412 ConcreteType.prototype.addDirectSubtype$1 = ConcreteType.prototype.addDirectSubt
ype; |
| 11413 ConcreteType.prototype.getConstructor$1 = ConcreteType.prototype.getConstructor; |
| 11414 ConcreteType.prototype.getFactory$2 = ConcreteType.prototype.getFactory; |
| 11415 ConcreteType.prototype.getMember$1 = ConcreteType.prototype.getMember; |
| 11416 ConcreteType.prototype.getOrMakeConcreteType$1 = ConcreteType.prototype.getOrMak
eConcreteType; |
| 11417 ConcreteType.prototype.markUsed$0 = ConcreteType.prototype.markUsed; |
| 11418 ConcreteType.prototype.resolveTypeParams$1 = ConcreteType.prototype.resolveTypeP
arams; |
| 11419 // ********** Code for DefinedType ************** |
| 11420 $inherits(DefinedType, Type); |
| 11421 function DefinedType(name, library, definition, isClass) { |
| 11422 this.isUsed = false |
| 11423 this.isNative = false |
| 11424 this.library = library; |
| 11425 this.isClass = isClass; |
| 11426 this.directSubtypes = new HashSetImplementation(); |
| 11427 this.constructors = new HashMapImplementation(); |
| 11428 this.members = new HashMapImplementation(); |
| 11429 this.factories = new FactoryMap(); |
| 11430 // Initializers done |
| 11431 Type.call(this, name); |
| 11432 this.setDefinition(definition); |
| 11433 } |
| 11434 DefinedType.prototype.get$definition = function() { return this.definition; }; |
| 11435 DefinedType.prototype.set$definition = function(value) { return this.definition
= value; }; |
| 11436 DefinedType.prototype.get$library = function() { return this.library; }; |
| 11437 DefinedType.prototype.get$isClass = function() { return this.isClass; }; |
| 11438 DefinedType.prototype.get$_parent = function() { return this._parent; }; |
| 11439 DefinedType.prototype.set$_parent = function(value) { return this._parent = valu
e; }; |
| 11440 DefinedType.prototype.get$parent = function() { |
| 11441 return this._parent; |
| 11442 } |
| 11443 DefinedType.prototype.set$parent = function(p) { |
| 11444 this._parent = p; |
| 11445 } |
| 11446 DefinedType.prototype.get$interfaces = function() { return this.interfaces; }; |
| 11447 DefinedType.prototype.set$interfaces = function(value) { return this.interfaces
= value; }; |
| 11448 DefinedType.prototype.get$typeParameters = function() { return this.typeParamete
rs; }; |
| 11449 DefinedType.prototype.set$typeParameters = function(value) { return this.typePar
ameters = value; }; |
| 11450 DefinedType.prototype.get$constructors = function() { return this.constructors;
}; |
| 11451 DefinedType.prototype.set$constructors = function(value) { return this.construct
ors = value; }; |
| 11452 DefinedType.prototype.get$members = function() { return this.members; }; |
| 11453 DefinedType.prototype.set$members = function(value) { return this.members = valu
e; }; |
| 11454 DefinedType.prototype.get$factories = function() { return this.factories; }; |
| 11455 DefinedType.prototype.set$factories = function(value) { return this.factories =
value; }; |
| 11456 DefinedType.prototype.get$_concreteTypes = function() { return this._concreteTyp
es; }; |
| 11457 DefinedType.prototype.set$_concreteTypes = function(value) { return this._concre
teTypes = value; }; |
| 11458 DefinedType.prototype.get$isUsed = function() { return this.isUsed; }; |
| 11459 DefinedType.prototype.set$isUsed = function(value) { return this.isUsed = value;
}; |
| 11460 DefinedType.prototype.get$isNative = function() { return this.isNative; }; |
| 11461 DefinedType.prototype.set$isNative = function(value) { return this.isNative = va
lue; }; |
| 11462 DefinedType.prototype.setDefinition = function(def) { |
| 11463 this.definition = def; |
| 11464 if ((this.definition instanceof TypeDefinition) && this.definition.get$nativeT
ype() != null) { |
| 11465 this.isNative = true; |
| 11466 } |
| 11467 if (this.definition != null && this.definition.get$typeParameters() != null) { |
| 11468 this._concreteTypes = new HashMapImplementation(); |
| 11469 this.typeParameters = this.definition.get$typeParameters(); |
| 11470 } |
| 11471 } |
| 11472 DefinedType.prototype.get$nativeType = function() { |
| 11473 return (this.definition != null ? this.definition.get$nativeType() : null); |
| 11474 } |
| 11475 DefinedType.prototype.get$typeArgsInOrder = function() { |
| 11476 if (this.typeParameters == null) return null; |
| 11477 if (this._typeArgsInOrder == null) { |
| 11478 this._typeArgsInOrder = new FixedCollection_Type($globals.world.varType, thi
s.typeParameters.length); |
| 11479 } |
| 11480 return this._typeArgsInOrder; |
| 11481 } |
| 11482 DefinedType.prototype.get$isVar = function() { |
| 11483 return $eq(this, $globals.world.varType); |
| 11484 } |
| 11485 DefinedType.prototype.get$isVoid = function() { |
| 11486 return $eq(this, $globals.world.voidType); |
| 11487 } |
| 11488 DefinedType.prototype.get$isTop = function() { |
| 11489 return this.name == null; |
| 11490 } |
| 11491 DefinedType.prototype.get$isObject = function() { |
| 11492 return this.library.get$isCore() && this.name == 'Object'; |
| 11493 } |
| 11494 DefinedType.prototype.get$isString = function() { |
| 11495 return this.library.get$isCore() && this.name == 'String' || this.library.get$
isCoreImpl() && this.name == 'StringImplementation'; |
| 11496 } |
| 11497 DefinedType.prototype.get$isBool = function() { |
| 11498 return this.library.get$isCore() && this.name == 'bool'; |
| 11499 } |
| 11500 DefinedType.prototype.get$isFunction = function() { |
| 11501 return this.library.get$isCore() && this.name == 'Function'; |
| 11502 } |
| 11503 DefinedType.prototype.get$isList = function() { |
| 11504 return this.library.get$isCore() && this.name == 'List'; |
| 11505 } |
| 11506 DefinedType.prototype.get$isGeneric = function() { |
| 11507 return this.typeParameters != null; |
| 11508 } |
| 11509 DefinedType.prototype.get$span = function() { |
| 11510 return this.definition == null ? null : this.definition.span; |
| 11511 } |
| 11512 DefinedType.prototype.get$typeofName = function() { |
| 11513 if (!this.library.get$isCore()) return null; |
| 11514 if (this.get$isBool()) return 'boolean'; |
| 11515 else if (this.get$isNum()) return 'number'; |
| 11516 else if (this.get$isString()) return 'string'; |
| 11517 else if (this.get$isFunction()) return 'function'; |
| 11518 else return null; |
| 11519 } |
| 11520 DefinedType.prototype.get$isNum = function() { |
| 11521 return this.library != null && this.library.get$isCore() && (this.name == 'num
' || this.name == 'int' || this.name == 'double'); |
| 11522 } |
| 11523 DefinedType.prototype.getCallMethod = function() { |
| 11524 return this.members.$index(':call'); |
| 11525 } |
| 11526 DefinedType.prototype.getAllMembers = function() { |
| 11527 return HashMapImplementation.HashMapImplementation$from$factory(this.members); |
| 11528 } |
| 11529 DefinedType.prototype.markUsed = function() { |
| 11530 if (this.isUsed) return; |
| 11531 this.isUsed = true; |
| 11532 this._checkExtends(); |
| 11533 if (this._lazyGenMethods != null) { |
| 11534 var $$list = orderValuesByKeys(this._lazyGenMethods); |
| 11535 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11536 var method = $$list.$index($$i); |
| 11537 $globals.world.gen.genMethod(method); |
| 11538 } |
| 11539 this._lazyGenMethods = null; |
| 11540 } |
| 11541 if (this.get$parent() != null) this.get$parent().markUsed(); |
| 11542 } |
| 11543 DefinedType.prototype.genMethod = function(method) { |
| 11544 if (this.isUsed) { |
| 11545 $globals.world.gen.genMethod(method); |
| 11546 } |
| 11547 else if (this.isClass) { |
| 11548 if (this._lazyGenMethods == null) this._lazyGenMethods = new HashMapImplemen
tation(); |
| 11549 this._lazyGenMethods.$setindex(method.name, method); |
| 11550 } |
| 11551 } |
| 11552 DefinedType.prototype._resolveInterfaces = function(types) { |
| 11553 if (types == null) return []; |
| 11554 var interfaces = []; |
| 11555 for (var $$i = 0;$$i < types.length; $$i++) { |
| 11556 var type = types.$index($$i); |
| 11557 var resolvedInterface = this.resolveType(type, true); |
| 11558 if (resolvedInterface.get$isClosed() && !(this.library.get$isCore() || this.
library.get$isCoreImpl())) { |
| 11559 $globals.world.error(('can not implement "' + resolvedInterface.get$name()
+ '": ') + 'only native implementation allowed', type.get$span()); |
| 11560 } |
| 11561 resolvedInterface.addDirectSubtype$1(this); |
| 11562 interfaces.add$1(resolvedInterface); |
| 11563 } |
| 11564 return interfaces; |
| 11565 } |
| 11566 DefinedType.prototype.addDirectSubtype = function(type) { |
| 11567 this.directSubtypes.add(type); |
| 11568 } |
| 11569 DefinedType.prototype.get$subtypes = function() { |
| 11570 if (this._subtypes == null) { |
| 11571 this._subtypes = new HashSetImplementation(); |
| 11572 var $$list = this.directSubtypes; |
| 11573 for (var $$i = this.directSubtypes.iterator(); $$i.hasNext$0(); ) { |
| 11574 var st = $$i.next$0(); |
| 11575 this._subtypes.add(st); |
| 11576 this._subtypes.addAll(st.get$subtypes()); |
| 11577 } |
| 11578 } |
| 11579 return this._subtypes; |
| 11580 } |
| 11581 DefinedType.prototype._cycleInClassExtends = function() { |
| 11582 var seen = new HashSetImplementation(); |
| 11583 seen.add(this); |
| 11584 var ancestor = this.get$parent(); |
| 11585 while (ancestor != null) { |
| 11586 if (ancestor === this) { |
| 11587 return true; |
| 11588 } |
| 11589 if (seen.contains(ancestor)) { |
| 11590 return false; |
| 11591 } |
| 11592 seen.add(ancestor); |
| 11593 ancestor = ancestor.get$parent(); |
| 11594 } |
| 11595 return false; |
| 11596 } |
| 11597 DefinedType.prototype._cycleInInterfaceExtends = function() { |
| 11598 var $this = this; // closure support |
| 11599 var seen = new HashSetImplementation(); |
| 11600 seen.add(this); |
| 11601 function _helper(ancestor) { |
| 11602 if (ancestor == null) return false; |
| 11603 if (ancestor === $this) return true; |
| 11604 if (seen.contains(ancestor)) { |
| 11605 return false; |
| 11606 } |
| 11607 seen.add(ancestor); |
| 11608 if (ancestor.get$interfaces() != null) { |
| 11609 var $$list = ancestor.get$interfaces(); |
| 11610 for (var $$i = ancestor.get$interfaces().iterator$0(); $$i.hasNext$0(); )
{ |
| 11611 var parent = $$i.next$0(); |
| 11612 if (_helper(parent)) return true; |
| 11613 } |
| 11614 } |
| 11615 return false; |
| 11616 } |
| 11617 for (var i = 0; |
| 11618 i < this.interfaces.length; i++) { |
| 11619 if (_helper(this.interfaces.$index(i))) return i; |
| 11620 } |
| 11621 return -1; |
| 11622 } |
| 11623 DefinedType.prototype.resolve = function() { |
| 11624 if ((this.definition instanceof TypeDefinition)) { |
| 11625 var typeDef = this.definition; |
| 11626 if (this.isClass) { |
| 11627 if (typeDef.extendsTypes != null && typeDef.extendsTypes.length > 0) { |
| 11628 if (typeDef.extendsTypes.length > 1) { |
| 11629 $globals.world.error('more than one base class', typeDef.extendsTypes.
$index(1).get$span()); |
| 11630 } |
| 11631 var extendsTypeRef = typeDef.extendsTypes.$index(0); |
| 11632 if ((extendsTypeRef instanceof GenericTypeReference)) { |
| 11633 var g = extendsTypeRef; |
| 11634 this.set$parent(this.resolveType(g.baseType, true)); |
| 11635 } |
| 11636 this.set$parent(this.resolveType(extendsTypeRef, true)); |
| 11637 if (!this.get$parent().get$isClass()) { |
| 11638 $globals.world.error('class may not extend an interface - use implemen
ts', typeDef.extendsTypes.$index(0).get$span()); |
| 11639 } |
| 11640 this.get$parent().addDirectSubtype(this); |
| 11641 if (this._cycleInClassExtends()) { |
| 11642 $globals.world.error(('class "' + this.name + '" has a cycle in its in
heritance chain'), extendsTypeRef.get$span()); |
| 11643 } |
| 11644 } |
| 11645 else { |
| 11646 if (!this.get$isObject()) { |
| 11647 this.set$parent($globals.world.objectType); |
| 11648 this.get$parent().addDirectSubtype(this); |
| 11649 } |
| 11650 } |
| 11651 this.interfaces = this._resolveInterfaces(typeDef.implementsTypes); |
| 11652 if (typeDef.factoryType != null) { |
| 11653 $globals.world.error('factory not allowed on classes', typeDef.factoryTy
pe.span); |
| 11654 } |
| 11655 } |
| 11656 else { |
| 11657 if (typeDef.implementsTypes != null && typeDef.implementsTypes.length > 0)
{ |
| 11658 $globals.world.error('implements not allowed on interfaces (use extends)
', typeDef.implementsTypes.$index(0).get$span()); |
| 11659 } |
| 11660 this.interfaces = this._resolveInterfaces(typeDef.extendsTypes); |
| 11661 var res = this._cycleInInterfaceExtends(); |
| 11662 if (res >= 0) { |
| 11663 $globals.world.error(('interface "' + this.name + '" has a cycle in its
inheritance chain'), typeDef.extendsTypes.$index(res).get$span()); |
| 11664 } |
| 11665 if (typeDef.factoryType != null) { |
| 11666 this.factory_ = this.resolveType(typeDef.factoryType, true); |
| 11667 if (this.factory_ == null) { |
| 11668 $globals.world.warning('unresolved factory', typeDef.factoryType.span)
; |
| 11669 } |
| 11670 } |
| 11671 } |
| 11672 } |
| 11673 else if ((this.definition instanceof FunctionTypeDefinition)) { |
| 11674 this.interfaces = [$globals.world.functionType]; |
| 11675 } |
| 11676 if (this.typeParameters != null) { |
| 11677 var $$list = this.typeParameters; |
| 11678 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 11679 var tp = $$list.$index($$i); |
| 11680 tp.set$enclosingElement(this); |
| 11681 tp.resolve$0(); |
| 11682 } |
| 11683 } |
| 11684 if (this.get$isObject()) this._createNotEqualMember(); |
| 11685 $globals.world._addType(this); |
| 11686 var $$list = this.constructors.getValues(); |
| 11687 for (var $$i = this.constructors.getValues().iterator$0(); $$i.hasNext$0(); )
{ |
| 11688 var c = $$i.next$0(); |
| 11689 c.resolve$0(); |
| 11690 } |
| 11691 var $list0 = this.members.getValues(); |
| 11692 for (var $$i = this.members.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 11693 var m = $$i.next$0(); |
| 11694 m.resolve$0(); |
| 11695 } |
| 11696 this.factories.forEach((function (f) { |
| 11697 return f.resolve$0(); |
| 11698 }) |
| 11699 ); |
| 11700 if (this.get$isJsGlobalObject()) { |
| 11701 var $list1 = this.members.getValues(); |
| 11702 for (var $$i = this.members.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 11703 var m0 = $$i.next$0(); |
| 11704 if (!m0.get$isStatic()) $globals.world._addTopName(m0); |
| 11705 } |
| 11706 } |
| 11707 } |
| 11708 DefinedType.prototype.addMethod = function(methodName, definition) { |
| 11709 if (methodName == null) methodName = definition.name.name; |
| 11710 var method = new MethodMember(methodName, this, definition); |
| 11711 if (method.get$isConstructor()) { |
| 11712 if (this.constructors.containsKey(method.get$constructorName())) { |
| 11713 $globals.world.error(('duplicate constructor definition of ' + method.get$
name()), definition.span); |
| 11714 return; |
| 11715 } |
| 11716 this.constructors.$setindex(method.get$constructorName(), method); |
| 11717 return; |
| 11718 } |
| 11719 if (definition.modifiers != null && definition.modifiers.length == 1 && $eq(de
finition.modifiers.$index(0).get$kind(), 75/*TokenKind.FACTORY*/)) { |
| 11720 if (this.factories.getFactory(method.get$constructorName(), method.get$name(
)) != null) { |
| 11721 $globals.world.error(('duplicate factory definition of "' + method.get$nam
e() + '"'), definition.span); |
| 11722 return; |
| 11723 } |
| 11724 this.factories.addFactory(method.get$constructorName(), method.get$name(), m
ethod); |
| 11725 return; |
| 11726 } |
| 11727 if (methodName.startsWith('get:') || methodName.startsWith('set:')) { |
| 11728 var propName = methodName.substring(4); |
| 11729 var prop = this.members.$index(propName); |
| 11730 if (prop == null) { |
| 11731 prop = new PropertyMember(propName, this); |
| 11732 this.members.$setindex(propName, prop); |
| 11733 } |
| 11734 if (!(prop instanceof PropertyMember)) { |
| 11735 $globals.world.error(('property conflicts with field "' + propName + '"'),
definition.span); |
| 11736 return; |
| 11737 } |
| 11738 if (methodName[0] == 'g') { |
| 11739 if (prop.get$getter() != null) { |
| 11740 $globals.world.error(('duplicate getter definition for "' + propName + '
"'), definition.span); |
| 11741 } |
| 11742 prop.set$getter(method); |
| 11743 } |
| 11744 else { |
| 11745 if (prop.get$setter() != null) { |
| 11746 $globals.world.error(('duplicate setter definition for "' + propName + '
"'), definition.span); |
| 11747 } |
| 11748 prop.set$setter(method); |
| 11749 } |
| 11750 return; |
| 11751 } |
| 11752 if (this.members.containsKey(methodName)) { |
| 11753 $globals.world.error(('duplicate method definition of "' + method.get$name()
+ '"'), definition.span); |
| 11754 return; |
| 11755 } |
| 11756 this.members.$setindex(methodName, method); |
| 11757 } |
| 11758 DefinedType.prototype.addField = function(definition) { |
| 11759 for (var i = 0; |
| 11760 i < definition.names.length; i++) { |
| 11761 var name = definition.names.$index(i).get$name(); |
| 11762 if (this.members.containsKey(name)) { |
| 11763 $globals.world.error(('duplicate field definition of "' + name + '"'), def
inition.span); |
| 11764 return; |
| 11765 } |
| 11766 var value = null; |
| 11767 if (definition.values != null) { |
| 11768 value = definition.values.$index(i); |
| 11769 } |
| 11770 var field = new FieldMember(name, this, definition, value); |
| 11771 this.members.$setindex(name, field); |
| 11772 if (this.isNative) { |
| 11773 field.set$isNative(true); |
| 11774 } |
| 11775 } |
| 11776 } |
| 11777 DefinedType.prototype.getFactory = function(type, constructorName) { |
| 11778 var ret = this.factories.getFactory(type.name, constructorName); |
| 11779 if (ret != null) return ret; |
| 11780 ret = this.factories.getFactory(this.name, constructorName); |
| 11781 if (ret != null) return ret; |
| 11782 ret = this.constructors.$index(constructorName); |
| 11783 if (ret != null) return ret; |
| 11784 return this._tryCreateDefaultConstructor(constructorName); |
| 11785 } |
| 11786 DefinedType.prototype.getConstructor = function(constructorName) { |
| 11787 var ret = this.constructors.$index(constructorName); |
| 11788 if (ret != null) { |
| 11789 if (this.factory_ != null) { |
| 11790 return this.factory_.getFactory(this, constructorName); |
| 11791 } |
| 11792 return ret; |
| 11793 } |
| 11794 ret = this.factories.getFactory(this.name, constructorName); |
| 11795 if (ret != null) return ret; |
| 11796 return this._tryCreateDefaultConstructor(constructorName); |
| 11797 } |
| 11798 DefinedType.prototype._tryCreateDefaultConstructor = function(name) { |
| 11799 if (name == '' && this.definition != null && this.isClass && this.constructors
.get$length() == 0) { |
| 11800 var span = this.definition.span; |
| 11801 var inits = null, native_ = null, body = null; |
| 11802 if (this.isNative) { |
| 11803 native_ = ''; |
| 11804 inits = null; |
| 11805 } |
| 11806 else { |
| 11807 body = null; |
| 11808 inits = [new CallExpression(new SuperExpression(span), [], span)]; |
| 11809 } |
| 11810 var typeDef = this.definition; |
| 11811 var c = new FunctionDefinition(null, null, typeDef.name, [], null, inits, na
tive_, body, span); |
| 11812 this.addMethod(null, c); |
| 11813 this.constructors.$index('').resolve$0(); |
| 11814 return this.constructors.$index(''); |
| 11815 } |
| 11816 return null; |
| 11817 } |
| 11818 DefinedType.prototype.getMember = function(memberName) { |
| 11819 var member = this.members.$index(memberName); |
| 11820 if (member != null) { |
| 11821 this._checkOverride(member); |
| 11822 return member; |
| 11823 } |
| 11824 if (this.get$isTop()) { |
| 11825 var libType = this.library.findTypeByName(memberName); |
| 11826 if (libType != null) { |
| 11827 return libType.get$typeMember(); |
| 11828 } |
| 11829 } |
| 11830 return this._getMemberInParents(memberName); |
| 11831 } |
| 11832 DefinedType.prototype.resolveTypeParams = function(inType) { |
| 11833 return this; |
| 11834 } |
| 11835 DefinedType.prototype.getOrMakeConcreteType = function(typeArgs) { |
| 11836 var jsnames = []; |
| 11837 var names = []; |
| 11838 var typeMap = new HashMapImplementation(); |
| 11839 for (var i = 0; |
| 11840 i < typeArgs.length; i++) { |
| 11841 var paramName = this.typeParameters.$index(i).get$name(); |
| 11842 typeMap.$setindex(paramName, typeArgs.$index(i)); |
| 11843 names.add$1(typeArgs.$index(i).get$name()); |
| 11844 jsnames.add$1(typeArgs.$index(i).get$jsname()); |
| 11845 } |
| 11846 var jsname = ('' + this.get$jsname() + '_' + Strings.join(jsnames, '\$')); |
| 11847 var simpleName = ('' + this.name + '<' + Strings.join(names, ', ') + '>'); |
| 11848 var key = Strings.join(names, '\$'); |
| 11849 var ret = this._concreteTypes.$index(key); |
| 11850 if (ret == null) { |
| 11851 ret = new ConcreteType(simpleName, this, typeMap, typeArgs); |
| 11852 ret.set$_jsname(jsname); |
| 11853 this._concreteTypes.$setindex(key, ret); |
| 11854 } |
| 11855 return ret; |
| 11856 } |
| 11857 DefinedType.prototype.getCallStub = function(args) { |
| 11858 var name = _getCallStubName('call', args); |
| 11859 var stub = this.varStubs.$index(name); |
| 11860 if (stub == null) { |
| 11861 stub = new VarFunctionStub(name, args); |
| 11862 this.varStubs.$setindex(name, stub); |
| 11863 } |
| 11864 return stub; |
| 11865 } |
| 11866 DefinedType.prototype.addDirectSubtype$1 = DefinedType.prototype.addDirectSubtyp
e; |
| 11867 DefinedType.prototype.addMethod$2 = DefinedType.prototype.addMethod; |
| 11868 DefinedType.prototype.getConstructor$1 = DefinedType.prototype.getConstructor; |
| 11869 DefinedType.prototype.getFactory$2 = DefinedType.prototype.getFactory; |
| 11870 DefinedType.prototype.getMember$1 = DefinedType.prototype.getMember; |
| 11871 DefinedType.prototype.getOrMakeConcreteType$1 = DefinedType.prototype.getOrMakeC
oncreteType; |
| 11872 DefinedType.prototype.markUsed$0 = DefinedType.prototype.markUsed; |
| 11873 DefinedType.prototype.resolve$0 = DefinedType.prototype.resolve; |
| 11874 DefinedType.prototype.resolveTypeParams$1 = DefinedType.prototype.resolveTypePar
ams; |
| 11875 DefinedType.prototype.setDefinition$1 = DefinedType.prototype.setDefinition; |
| 11876 // ********** Code for NativeType ************** |
| 11877 function NativeType(name) { |
| 11878 this.isConstructorHidden = false |
| 11879 this.isJsGlobalObject = false |
| 11880 this.isSingleton = false |
| 11881 this.name = name; |
| 11882 // Initializers done |
| 11883 while (true) { |
| 11884 if (this.name.startsWith('@')) { |
| 11885 this.name = this.name.substring(1); |
| 11886 this.isJsGlobalObject = true; |
| 11887 } |
| 11888 else if (this.name.startsWith('*')) { |
| 11889 this.name = this.name.substring(1); |
| 11890 this.isConstructorHidden = true; |
| 11891 } |
| 11892 else { |
| 11893 break; |
| 11894 } |
| 11895 } |
| 11896 if (this.name.startsWith('=')) { |
| 11897 this.name = this.name.substring(1); |
| 11898 this.isSingleton = true; |
| 11899 } |
| 11900 } |
| 11901 NativeType.prototype.get$name = function() { return this.name; }; |
| 11902 NativeType.prototype.set$name = function(value) { return this.name = value; }; |
| 11903 // ********** Code for FixedCollection ************** |
| 11904 function FixedCollection(value, length) { |
| 11905 this.value = value; |
| 11906 this.length = length; |
| 11907 // Initializers done |
| 11908 } |
| 11909 FixedCollection.prototype.get$value = function() { return this.value; }; |
| 11910 FixedCollection.prototype.iterator = function() { |
| 11911 return new FixedIterator_E(this.value, this.length); |
| 11912 } |
| 11913 FixedCollection.prototype.forEach = function(f) { |
| 11914 Collections.forEach(this, f); |
| 11915 } |
| 11916 FixedCollection.prototype.filter = function(f) { |
| 11917 return Collections.filter(this, new ListFactory(), f); |
| 11918 } |
| 11919 FixedCollection.prototype.every = function(f) { |
| 11920 return Collections.every(this, f); |
| 11921 } |
| 11922 FixedCollection.prototype.some = function(f) { |
| 11923 return Collections.some(this, f); |
| 11924 } |
| 11925 FixedCollection.prototype.isEmpty = function() { |
| 11926 return this.length == 0; |
| 11927 } |
| 11928 FixedCollection.prototype.every$1 = function($0) { |
| 11929 return this.every(to$call$1($0)); |
| 11930 }; |
| 11931 FixedCollection.prototype.filter$1 = function($0) { |
| 11932 return this.filter(to$call$1($0)); |
| 11933 }; |
| 11934 FixedCollection.prototype.forEach$1 = function($0) { |
| 11935 return this.forEach(to$call$1($0)); |
| 11936 }; |
| 11937 FixedCollection.prototype.isEmpty$0 = FixedCollection.prototype.isEmpty; |
| 11938 FixedCollection.prototype.iterator$0 = FixedCollection.prototype.iterator; |
| 11939 FixedCollection.prototype.some$1 = function($0) { |
| 11940 return this.some(to$call$1($0)); |
| 11941 }; |
| 11942 // ********** Code for FixedCollection_Type ************** |
| 11943 $inherits(FixedCollection_Type, FixedCollection); |
| 11944 function FixedCollection_Type(value, length) { |
| 11945 this.value = value; |
| 11946 this.length = length; |
| 11947 // Initializers done |
| 11948 } |
| 11949 // ********** Code for FixedIterator ************** |
| 11950 function FixedIterator(value, length) { |
| 11951 this._index = 0 |
| 11952 this.value = value; |
| 11953 this.length = length; |
| 11954 // Initializers done |
| 11955 } |
| 11956 FixedIterator.prototype.get$value = function() { return this.value; }; |
| 11957 FixedIterator.prototype.hasNext = function() { |
| 11958 return this._index < this.length; |
| 11959 } |
| 11960 FixedIterator.prototype.next = function() { |
| 11961 this._index++; |
| 11962 return this.value; |
| 11963 } |
| 11964 FixedIterator.prototype.hasNext$0 = FixedIterator.prototype.hasNext; |
| 11965 FixedIterator.prototype.next$0 = FixedIterator.prototype.next; |
| 11966 // ********** Code for FixedIterator_E ************** |
| 11967 $inherits(FixedIterator_E, FixedIterator); |
| 11968 function FixedIterator_E(value, length) { |
| 11969 this._index = 0 |
| 11970 this.value = value; |
| 11971 this.length = length; |
| 11972 // Initializers done |
| 11973 } |
| 11974 // ********** Code for Value ************** |
| 11975 function Value(_type, code, span, needsTemp) { |
| 11976 this.isSuper = false |
| 11977 this.isType = false |
| 11978 this.isFinal = false |
| 11979 this.allowDynamic = true |
| 11980 this._type = _type; |
| 11981 this.code = code; |
| 11982 this.span = span; |
| 11983 this.needsTemp = needsTemp; |
| 11984 // Initializers done |
| 11985 if (this._type == null) $globals.world.internalError('type passed as null', th
is.span); |
| 11986 } |
| 11987 Value.type$ctor = function(_type, span) { |
| 11988 this.isSuper = false |
| 11989 this.isType = false |
| 11990 this.isFinal = false |
| 11991 this.allowDynamic = true |
| 11992 this._type = _type; |
| 11993 this.span = span; |
| 11994 this.code = null; |
| 11995 this.needsTemp = false; |
| 11996 this.isType = true; |
| 11997 // Initializers done |
| 11998 if (this._type == null) $globals.world.internalError('type passed as null', th
is.span); |
| 11999 } |
| 12000 Value.type$ctor.prototype = Value.prototype; |
| 12001 Value.prototype.get$code = function() { return this.code; }; |
| 12002 Value.prototype.set$code = function(value) { return this.code = value; }; |
| 12003 Value.prototype.get$span = function() { return this.span; }; |
| 12004 Value.prototype.set$span = function(value) { return this.span = value; }; |
| 12005 Value.prototype.get$isSuper = function() { return this.isSuper; }; |
| 12006 Value.prototype.set$isSuper = function(value) { return this.isSuper = value; }; |
| 12007 Value.prototype.get$isType = function() { return this.isType; }; |
| 12008 Value.prototype.set$isType = function(value) { return this.isType = value; }; |
| 12009 Value.prototype.get$isFinal = function() { return this.isFinal; }; |
| 12010 Value.prototype.set$isFinal = function(value) { return this.isFinal = value; }; |
| 12011 Value.prototype.get$allowDynamic = function() { return this.allowDynamic; }; |
| 12012 Value.prototype.set$allowDynamic = function(value) { return this.allowDynamic =
value; }; |
| 12013 Value.prototype.get$needsTemp = function() { return this.needsTemp; }; |
| 12014 Value.prototype.set$needsTemp = function(value) { return this.needsTemp = value;
}; |
| 12015 Value.prototype.get$_typeIsVarOrParameterType = function() { |
| 12016 return this.get$type().get$isVar() || (this.get$type() instanceof ParameterTyp
e); |
| 12017 } |
| 12018 Value.prototype.get$type = function() { |
| 12019 if (!$globals.options.forceDynamic || !this.allowDynamic || this.isType || thi
s.isSuper || this.get$isConst()) { |
| 12020 return this._type; |
| 12021 } |
| 12022 else { |
| 12023 return $globals.world.varType; |
| 12024 } |
| 12025 } |
| 12026 Value.prototype.get$isConst = function() { |
| 12027 return false; |
| 12028 } |
| 12029 Value.prototype.get$canonicalCode = function() { |
| 12030 return null; |
| 12031 } |
| 12032 Value.prototype.get_ = function(context, name, node) { |
| 12033 var member = this._resolveMember(context, name, node, false); |
| 12034 if (member != null) { |
| 12035 return member._get$3(context, node, this); |
| 12036 } |
| 12037 else { |
| 12038 return this.invokeNoSuchMethod(context, ('get:' + name), node); |
| 12039 } |
| 12040 } |
| 12041 Value.prototype.set_ = function(context, name, node, value, isDynamic) { |
| 12042 var member = this._resolveMember(context, name, node, isDynamic); |
| 12043 if (member != null) { |
| 12044 return member._set$5(context, node, this, value, isDynamic); |
| 12045 } |
| 12046 else { |
| 12047 return this.invokeNoSuchMethod(context, ('set:' + name), node, new Arguments
(null, [value])); |
| 12048 } |
| 12049 } |
| 12050 Value.prototype.invoke = function(context, name, node, args, isDynamic) { |
| 12051 if (name == ':call') { |
| 12052 if (this.isType) { |
| 12053 $globals.world.error('must use "new" or "const" to construct a new instanc
e', node.span); |
| 12054 } |
| 12055 if (this.get$type().needsVarCall(args)) { |
| 12056 return this._varCall(context, args); |
| 12057 } |
| 12058 } |
| 12059 var member = this._resolveMember(context, name, node, isDynamic); |
| 12060 if (member == null) { |
| 12061 return this.invokeNoSuchMethod(context, name, node, args); |
| 12062 } |
| 12063 else { |
| 12064 return member.invoke$5(context, node, this, args, isDynamic); |
| 12065 } |
| 12066 } |
| 12067 Value.prototype.canInvoke = function(context, name, args) { |
| 12068 if (this.get$type().get$isVarOrFunction() && name == ':call') { |
| 12069 return true; |
| 12070 } |
| 12071 var member = this._resolveMember(context, name, null, true); |
| 12072 return member != null && member.canInvoke$2(context, args); |
| 12073 } |
| 12074 Value.prototype._hasOverriddenNoSuchMethod = function() { |
| 12075 if (this.isSuper) { |
| 12076 var m = this.get$type().getMember('noSuchMethod'); |
| 12077 return m != null && !m.get$declaringType().get$isObject(); |
| 12078 } |
| 12079 else { |
| 12080 var m = this.get$type().resolveMember('noSuchMethod'); |
| 12081 return m != null && m.get$members().length > 1; |
| 12082 } |
| 12083 } |
| 12084 Value.prototype._tryResolveMember = function(context, name) { |
| 12085 if (this.isSuper) { |
| 12086 return this.get$type().getMember(name); |
| 12087 } |
| 12088 else { |
| 12089 return this.get$type().resolveMember(name); |
| 12090 } |
| 12091 } |
| 12092 Value.prototype._resolveMember = function(context, name, node, isDynamic) { |
| 12093 var member; |
| 12094 if (!this.get$_typeIsVarOrParameterType()) { |
| 12095 member = this._tryResolveMember(context, name); |
| 12096 if (member != null && this.isType && !member.get$isStatic()) { |
| 12097 if (!isDynamic) { |
| 12098 $globals.world.error('can not refer to instance member as static', node.
span); |
| 12099 } |
| 12100 return null; |
| 12101 } |
| 12102 if (member == null && !isDynamic && !this._hasOverriddenNoSuchMethod()) { |
| 12103 var typeName = this.get$type().name == null ? this.get$type().get$library(
).name : this.get$type().name; |
| 12104 var message = ('can not resolve "' + name + '" on "' + typeName + '"'); |
| 12105 if (this.isType) { |
| 12106 $globals.world.error(message, node.span); |
| 12107 } |
| 12108 else { |
| 12109 $globals.world.warning(message, node.span); |
| 12110 } |
| 12111 } |
| 12112 } |
| 12113 if (member == null && !this.isSuper && !this.isType) { |
| 12114 member = context.findMembers(name); |
| 12115 if (member == null && !isDynamic) { |
| 12116 var where = 'the world'; |
| 12117 if (name.startsWith('_')) { |
| 12118 where = ('library "' + context.get$library().name + '"'); |
| 12119 } |
| 12120 $globals.world.warning(('' + name + ' is not defined anywhere in ' + where
+ '.'), node.span); |
| 12121 } |
| 12122 } |
| 12123 return member; |
| 12124 } |
| 12125 Value.prototype.checkFirstClass = function(span) { |
| 12126 if (this.isType) { |
| 12127 $globals.world.error('Types are not first class', span); |
| 12128 } |
| 12129 } |
| 12130 Value.prototype._varCall = function(context, args) { |
| 12131 var stub = $globals.world.functionType.getCallStub(args); |
| 12132 return new Value($globals.world.varType, ('' + this.code + '.' + stub.get$name
() + '(' + args.getCode() + ')'), this.span, true); |
| 12133 } |
| 12134 Value.prototype.needsConversion = function(toType) { |
| 12135 var callMethod = toType.getCallMethod(); |
| 12136 if (callMethod != null) { |
| 12137 var arity = callMethod.get$parameters().length; |
| 12138 var myCall = this.get$type().getCallMethod(); |
| 12139 if (myCall == null || $ne(myCall.get$parameters().length, arity)) { |
| 12140 return true; |
| 12141 } |
| 12142 } |
| 12143 if ($globals.options.enableTypeChecks) { |
| 12144 var fromType = this.get$type(); |
| 12145 if (this.get$type().get$isVar() && (this.code != 'null' || !toType.get$isNul
lable())) { |
| 12146 fromType = $globals.world.objectType; |
| 12147 } |
| 12148 var bothNum = this.get$type().get$isNum() && toType.get$isNum(); |
| 12149 return !(fromType.isSubtypeOf(toType) || bothNum); |
| 12150 } |
| 12151 return false; |
| 12152 } |
| 12153 Value.prototype.convertTo = function(context, toType, node, isDynamic) { |
| 12154 var checked = !isDynamic; |
| 12155 var callMethod = toType.getCallMethod(); |
| 12156 if (callMethod != null) { |
| 12157 if (checked && !toType.isAssignable(this.get$type())) { |
| 12158 this.convertWarning(toType, node); |
| 12159 } |
| 12160 var arity = callMethod.get$parameters().length; |
| 12161 var myCall = this.get$type().getCallMethod(); |
| 12162 if (myCall == null || $ne(myCall.get$parameters().length, arity)) { |
| 12163 var stub = $globals.world.functionType.getCallStub(Arguments.Arguments$bar
e$factory(arity)); |
| 12164 var val = new Value(toType, ('to\$' + stub.name + '(' + this.code + ')'),
node.span, true); |
| 12165 return this._isDomCallback(toType) && !this._isDomCallback(this.get$type()
) ? val._wrapDomCallback$2(toType, arity) : val; |
| 12166 } |
| 12167 else if (this._isDomCallback(toType) && !this._isDomCallback(this.get$type()
)) { |
| 12168 return this._wrapDomCallback(toType, arity); |
| 12169 } |
| 12170 } |
| 12171 var fromType = this.get$type(); |
| 12172 if (this.get$type().get$isVar() && (this.code != 'null' || !toType.get$isNulla
ble())) { |
| 12173 fromType = $globals.world.objectType; |
| 12174 } |
| 12175 var bothNum = this.get$type().get$isNum() && toType.get$isNum(); |
| 12176 if (fromType.isSubtypeOf(toType) || bothNum) { |
| 12177 return this; |
| 12178 } |
| 12179 if (checked && !toType.isSubtypeOf(this.get$type())) { |
| 12180 this.convertWarning(toType, node); |
| 12181 } |
| 12182 if ($globals.options.enableTypeChecks) { |
| 12183 return this._typeAssert(context, toType, node, isDynamic); |
| 12184 } |
| 12185 else { |
| 12186 return this; |
| 12187 } |
| 12188 } |
| 12189 Value.prototype._isDomCallback = function(toType) { |
| 12190 return ((toType.get$definition() instanceof FunctionTypeDefinition) && $eq(toT
ype.get$library(), $globals.world.get$dom())); |
| 12191 } |
| 12192 Value.prototype._wrapDomCallback = function(toType, arity) { |
| 12193 if (arity == 0) { |
| 12194 $globals.world.gen.corejs.useWrap0 = true; |
| 12195 } |
| 12196 else { |
| 12197 $globals.world.gen.corejs.useWrap1 = true; |
| 12198 } |
| 12199 return new Value(toType, ('\$wrap_call\$' + arity + '(' + this.code + ')'), th
is.span, true); |
| 12200 } |
| 12201 Value.prototype._typeAssert = function(context, toType, node, isDynamic) { |
| 12202 if ((toType instanceof ParameterType)) { |
| 12203 var p = toType; |
| 12204 toType = p.extendsType; |
| 12205 } |
| 12206 if (toType.get$isObject() || toType.get$isVar()) { |
| 12207 $globals.world.internalError(('We thought ' + this.get$type().name + ' is no
t a subtype of ' + toType.name + '?')); |
| 12208 } |
| 12209 function throwTypeError(paramName) { |
| 12210 return $globals.world.withoutForceDynamic((function () { |
| 12211 var typeError = $globals.world.corelib.types.$index('TypeError'); |
| 12212 var typeErrorCtor = typeError.getConstructor$1('_internal'); |
| 12213 $globals.world.gen.corejs.ensureTypeNameOf(); |
| 12214 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); |
| 12215 $globals.world.gen.corejs.useThrow = true; |
| 12216 return ('\$throw(' + result.get$code() + ')'); |
| 12217 }) |
| 12218 ); |
| 12219 } |
| 12220 if (toType.get$isNum()) toType = $globals.world.numType; |
| 12221 var check; |
| 12222 if (toType.get$isVoid()) { |
| 12223 check = ('\$assert_void(' + this.code + ')'); |
| 12224 if (toType.typeCheckCode == null) { |
| 12225 toType.typeCheckCode = ("function $assert_void(x) {\n if (x == null) retu
rn null;\n " + throwTypeError("x") + "\n}"); |
| 12226 } |
| 12227 } |
| 12228 else if ($eq(toType, $globals.world.nonNullBool)) { |
| 12229 $globals.world.gen.corejs.useNotNullBool = true; |
| 12230 check = ('\$notnull_bool(' + this.code + ')'); |
| 12231 } |
| 12232 else if (toType.get$library().get$isCore() && toType.get$typeofName() != null)
{ |
| 12233 check = ('\$assert_' + toType.name + '(' + this.code + ')'); |
| 12234 if (toType.typeCheckCode == null) { |
| 12235 toType.typeCheckCode = ("function $assert_" + toType.name + "(x) {\n if (
x == null || typeof(x) == \"" + toType.get$typeofName() + "\") return x;\n " +
throwTypeError("x") + "\n}"); |
| 12236 } |
| 12237 } |
| 12238 else { |
| 12239 toType.isChecked = true; |
| 12240 var checkName = 'assert\$' + toType.get$jsname(); |
| 12241 var temp = context.getTemp(this); |
| 12242 check = ('(' + context.assignTemp(temp, this).code + ' == null ? null :'); |
| 12243 check = check + (' ' + temp.get$code() + '.' + checkName + '())'); |
| 12244 if ($ne(this, temp)) context.freeTemp(temp); |
| 12245 if (!$globals.world.objectType.varStubs.containsKey(checkName)) { |
| 12246 $globals.world.objectType.varStubs.$setindex(checkName, new VarMethodStub(
checkName, null, Arguments.get$EMPTY(), throwTypeError('this'))); |
| 12247 } |
| 12248 } |
| 12249 return new Value(toType, check, this.span, true); |
| 12250 } |
| 12251 Value.prototype.instanceOf = function(context, toType, span, isTrue, forceCheck)
{ |
| 12252 if (toType.get$isVar()) { |
| 12253 $globals.world.error('can not resolve type', span); |
| 12254 } |
| 12255 var testCode = null; |
| 12256 if (toType.get$isVar() || toType.get$isObject() || (toType instanceof Paramete
rType)) { |
| 12257 if (this.needsTemp) { |
| 12258 return new Value($globals.world.nonNullBool, ('(' + this.code + ', true)')
, span, true); |
| 12259 } |
| 12260 else { |
| 12261 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, t
rue, 'true', null); |
| 12262 } |
| 12263 } |
| 12264 if (toType.get$library().get$isCore()) { |
| 12265 var typeofName = toType.get$typeofName(); |
| 12266 if (typeofName != null) { |
| 12267 testCode = ("(typeof(" + this.code + ") " + (isTrue ? '==' : '!=') + " '"
+ typeofName + "')"); |
| 12268 } |
| 12269 } |
| 12270 if (toType.get$isClass() && !(toType instanceof ConcreteType) && !toType.get$i
sHiddenNativeType()) { |
| 12271 toType.markUsed(); |
| 12272 testCode = ('(' + this.code + ' instanceof ' + toType.get$jsname() + ')'); |
| 12273 if (!isTrue) { |
| 12274 testCode = '!' + testCode; |
| 12275 } |
| 12276 } |
| 12277 if (testCode == null) { |
| 12278 toType.isTested = true; |
| 12279 var temp = context.getTemp(this); |
| 12280 var checkName = ('is\$' + toType.get$jsname()); |
| 12281 testCode = ('(' + context.assignTemp(temp, this).code + ' &&'); |
| 12282 testCode = testCode + (' ' + temp.get$code() + '.' + checkName + '())'); |
| 12283 if (isTrue) { |
| 12284 testCode = '!!' + testCode; |
| 12285 } |
| 12286 else { |
| 12287 testCode = '!' + testCode; |
| 12288 } |
| 12289 if ($ne(this, temp)) context.freeTemp(temp); |
| 12290 if (!$globals.world.objectType.varStubs.containsKey(checkName)) { |
| 12291 $globals.world.objectType.varStubs.$setindex(checkName, new VarMethodStub(
checkName, null, Arguments.get$EMPTY(), 'return false')); |
| 12292 } |
| 12293 } |
| 12294 return new Value($globals.world.nonNullBool, testCode, span, true); |
| 12295 } |
| 12296 Value.prototype.convertWarning = function(toType, node) { |
| 12297 $globals.world.warning(('type "' + this.get$type().name + '" is not assignable
to "' + toType.name + '"'), node.span); |
| 12298 } |
| 12299 Value.prototype.invokeNoSuchMethod = function(context, name, node, args) { |
| 12300 var pos = ''; |
| 12301 if (args != null) { |
| 12302 var argsCode = []; |
| 12303 for (var i = 0; |
| 12304 i < args.get$length(); i++) { |
| 12305 argsCode.add$1(args.values.$index(i).get$code()); |
| 12306 } |
| 12307 pos = Strings.join(argsCode, ", "); |
| 12308 } |
| 12309 var noSuchArgs = [new Value($globals.world.stringType, ('"' + name + '"'), nod
e.span, true), new Value($globals.world.listType, ('[' + pos + ']'), node.span,
true)]; |
| 12310 return this._resolveMember(context, 'noSuchMethod', node, false).invoke$4(cont
ext, node, this, new Arguments(null, noSuchArgs)); |
| 12311 } |
| 12312 Value.prototype._wrapDomCallback$2 = Value.prototype._wrapDomCallback; |
| 12313 Value.prototype.checkFirstClass$1 = Value.prototype.checkFirstClass; |
| 12314 Value.prototype.convertTo$3 = function($0, $1, $2) { |
| 12315 return this.convertTo($0, $1, $2, false); |
| 12316 }; |
| 12317 Value.prototype.convertTo$4 = Value.prototype.convertTo; |
| 12318 Value.prototype.get_$3 = Value.prototype.get_; |
| 12319 Value.prototype.instanceOf$3$isTrue$forceCheck = Value.prototype.instanceOf; |
| 12320 Value.prototype.instanceOf$4 = function($0, $1, $2, $3) { |
| 12321 return this.instanceOf($0, $1, $2, $3, false); |
| 12322 }; |
| 12323 Value.prototype.invoke$4 = function($0, $1, $2, $3) { |
| 12324 return this.invoke($0, $1, $2, $3, false); |
| 12325 }; |
| 12326 Value.prototype.invoke$4$isDynamic = Value.prototype.invoke; |
| 12327 Value.prototype.invoke$5 = Value.prototype.invoke; |
| 12328 Value.prototype.needsConversion$1 = Value.prototype.needsConversion; |
| 12329 Value.prototype.set_$4 = function($0, $1, $2, $3) { |
| 12330 return this.set_($0, $1, $2, $3, false); |
| 12331 }; |
| 12332 // ********** Code for EvaluatedValue ************** |
| 12333 $inherits(EvaluatedValue, Value); |
| 12334 function EvaluatedValue() {} |
| 12335 EvaluatedValue._internal$ctor = function(type, actualValue, canonicalCode, span,
code) { |
| 12336 this.actualValue = actualValue; |
| 12337 this.canonicalCode = canonicalCode; |
| 12338 // Initializers done |
| 12339 Value.call(this, type, code, span, false); |
| 12340 } |
| 12341 EvaluatedValue._internal$ctor.prototype = EvaluatedValue.prototype; |
| 12342 EvaluatedValue.EvaluatedValue$factory = function(type, actualValue, canonicalCod
e, span) { |
| 12343 return new EvaluatedValue._internal$ctor(type, actualValue, canonicalCode, spa
n, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 12344 } |
| 12345 EvaluatedValue.prototype.get$actualValue = function() { return this.actualValue;
}; |
| 12346 EvaluatedValue.prototype.set$actualValue = function(value) { return this.actualV
alue = value; }; |
| 12347 EvaluatedValue.prototype.get$isConst = function() { |
| 12348 return true; |
| 12349 } |
| 12350 EvaluatedValue.prototype.get$canonicalCode = function() { return this.canonicalC
ode; }; |
| 12351 EvaluatedValue.prototype.set$canonicalCode = function(value) { return this.canon
icalCode = value; }; |
| 12352 EvaluatedValue.codeWithComments = function(canonicalCode, span) { |
| 12353 return (span != null && span.get$text() != canonicalCode) ? ('' + canonicalCod
e + '/*' + _escapeForComment(span.get$text()) + '*/') : canonicalCode; |
| 12354 } |
| 12355 // ********** Code for ConstListValue ************** |
| 12356 $inherits(ConstListValue, EvaluatedValue); |
| 12357 function ConstListValue() {} |
| 12358 ConstListValue._internal$ctor = function(type, values, actualValue, canonicalCod
e, span, code) { |
| 12359 this.values = values; |
| 12360 // Initializers done |
| 12361 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 12362 } |
| 12363 ConstListValue._internal$ctor.prototype = ConstListValue.prototype; |
| 12364 ConstListValue.ConstListValue$factory = function(type, values, actualValue, cano
nicalCode, span) { |
| 12365 return new ConstListValue._internal$ctor(type, values, actualValue, canonicalC
ode, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 12366 } |
| 12367 ConstListValue.prototype.get$values = function() { return this.values; }; |
| 12368 ConstListValue.prototype.set$values = function(value) { return this.values = val
ue; }; |
| 12369 // ********** Code for ConstMapValue ************** |
| 12370 $inherits(ConstMapValue, EvaluatedValue); |
| 12371 function ConstMapValue() {} |
| 12372 ConstMapValue._internal$ctor = function(type, values, actualValue, canonicalCode
, span, code) { |
| 12373 this.values = values; |
| 12374 // Initializers done |
| 12375 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 12376 } |
| 12377 ConstMapValue._internal$ctor.prototype = ConstMapValue.prototype; |
| 12378 ConstMapValue.ConstMapValue$factory = function(type, keyValuePairs, actualValue,
canonicalCode, span) { |
| 12379 var values = new HashMapImplementation(); |
| 12380 for (var i = 0; |
| 12381 i < keyValuePairs.length; i += 2) { |
| 12382 values.$setindex(keyValuePairs.$index(i).get$actualValue(), keyValuePairs.$i
ndex(i + 1)); |
| 12383 } |
| 12384 return new ConstMapValue._internal$ctor(type, values, actualValue, canonicalCo
de, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 12385 } |
| 12386 ConstMapValue.prototype.get$values = function() { return this.values; }; |
| 12387 ConstMapValue.prototype.set$values = function(value) { return this.values = valu
e; }; |
| 12388 // ********** Code for ConstObjectValue ************** |
| 12389 $inherits(ConstObjectValue, EvaluatedValue); |
| 12390 function ConstObjectValue() {} |
| 12391 ConstObjectValue._internal$ctor = function(type, fields, actualValue, canonicalC
ode, span, code) { |
| 12392 this.fields = fields; |
| 12393 // Initializers done |
| 12394 EvaluatedValue._internal$ctor.call(this, type, actualValue, canonicalCode, spa
n, code); |
| 12395 } |
| 12396 ConstObjectValue._internal$ctor.prototype = ConstObjectValue.prototype; |
| 12397 ConstObjectValue.ConstObjectValue$factory = function(type, fields, canonicalCode
, span) { |
| 12398 var fieldValues = []; |
| 12399 var $$list = fields.getKeys(); |
| 12400 for (var $$i = fields.getKeys().iterator$0(); $$i.hasNext$0(); ) { |
| 12401 var f = $$i.next$0(); |
| 12402 fieldValues.add(('' + f + ' = ' + fields.$index(f).get$actualValue())); |
| 12403 } |
| 12404 fieldValues.sort((function (a, b) { |
| 12405 return a.compareTo$1(b); |
| 12406 }) |
| 12407 ); |
| 12408 var actualValue = ('const ' + type.get$jsname() + ' [') + Strings.join(fieldVa
lues, ',') + ']'; |
| 12409 return new ConstObjectValue._internal$ctor(type, fields, actualValue, canonica
lCode, span, EvaluatedValue.codeWithComments(canonicalCode, span)); |
| 12410 } |
| 12411 ConstObjectValue.prototype.get$fields = function() { return this.fields; }; |
| 12412 ConstObjectValue.prototype.set$fields = function(value) { return this.fields = v
alue; }; |
| 12413 // ********** Code for GlobalValue ************** |
| 12414 $inherits(GlobalValue, Value); |
| 12415 function GlobalValue(type, code, isConst, field, name, exp, canonicalCode, span,
_dependencies) { |
| 12416 this.field = field; |
| 12417 this.name = name; |
| 12418 this.exp = exp; |
| 12419 this.canonicalCode = canonicalCode; |
| 12420 this.dependencies = []; |
| 12421 // Initializers done |
| 12422 Value.call(this, type, code, span, !isConst); |
| 12423 for (var $$i = 0;$$i < _dependencies.length; $$i++) { |
| 12424 var dep = _dependencies.$index($$i); |
| 12425 this.dependencies.add(dep); |
| 12426 this.dependencies.addAll(dep.get$dependencies()); |
| 12427 } |
| 12428 } |
| 12429 GlobalValue.GlobalValue$fromStatic$factory = function(field, exp, dependencies)
{ |
| 12430 var code = (exp.get$isConst() ? exp.get$canonicalCode() : exp.code); |
| 12431 var codeWithComment = ('' + code + '/*' + field.get$declaringType().get$name()
+ '.' + field.get$name() + '*/'); |
| 12432 return new GlobalValue(exp.get$type(), codeWithComment, field.get$isFinal(), f
ield, null, exp, code, exp.span, dependencies.filter$1((function (d) { |
| 12433 return (d instanceof GlobalValue); |
| 12434 }) |
| 12435 )); |
| 12436 } |
| 12437 GlobalValue.GlobalValue$fromConst$factory = function(uniqueId, exp, dependencies
) { |
| 12438 var name = ("const\$" + uniqueId); |
| 12439 var codeWithComment = ("" + name + "/*" + _escapeForComment(exp.span.get$text(
)) + "*/"); |
| 12440 return new GlobalValue(exp.get$type(), codeWithComment, true, null, name, exp,
name, exp.span, dependencies.filter$1((function (d) { |
| 12441 return (d instanceof GlobalValue); |
| 12442 }) |
| 12443 )); |
| 12444 } |
| 12445 GlobalValue.prototype.get$field = function() { return this.field; }; |
| 12446 GlobalValue.prototype.set$field = function(value) { return this.field = value; }
; |
| 12447 GlobalValue.prototype.get$name = function() { return this.name; }; |
| 12448 GlobalValue.prototype.set$name = function(value) { return this.name = value; }; |
| 12449 GlobalValue.prototype.get$exp = function() { return this.exp; }; |
| 12450 GlobalValue.prototype.set$exp = function(value) { return this.exp = value; }; |
| 12451 GlobalValue.prototype.get$canonicalCode = function() { return this.canonicalCode
; }; |
| 12452 GlobalValue.prototype.set$canonicalCode = function(value) { return this.canonica
lCode = value; }; |
| 12453 GlobalValue.prototype.get$isConst = function() { |
| 12454 return this.exp.get$isConst() && (this.field == null || this.field.isFinal); |
| 12455 } |
| 12456 GlobalValue.prototype.get$actualValue = function() { |
| 12457 return this.exp.get$dynamic().get$actualValue(); |
| 12458 } |
| 12459 GlobalValue.prototype.get$dependencies = function() { return this.dependencies;
}; |
| 12460 GlobalValue.prototype.set$dependencies = function(value) { return this.dependenc
ies = value; }; |
| 12461 GlobalValue.prototype.compareTo = function(other) { |
| 12462 if ($eq(other, this)) { |
| 12463 return 0; |
| 12464 } |
| 12465 else if (this.dependencies.indexOf(other) >= 0) { |
| 12466 return 1; |
| 12467 } |
| 12468 else if (other.dependencies.indexOf(this) >= 0) { |
| 12469 return -1; |
| 12470 } |
| 12471 else if (this.dependencies.length > other.dependencies.length) { |
| 12472 return 1; |
| 12473 } |
| 12474 else if (this.dependencies.length < other.dependencies.length) { |
| 12475 return -1; |
| 12476 } |
| 12477 else if (this.name == null && other.name != null) { |
| 12478 return 1; |
| 12479 } |
| 12480 else if (this.name != null && other.name == null) { |
| 12481 return -1; |
| 12482 } |
| 12483 else if (this.name != null) { |
| 12484 return this.name.compareTo(other.name); |
| 12485 } |
| 12486 else { |
| 12487 return this.field.name.compareTo(other.field.name); |
| 12488 } |
| 12489 } |
| 12490 GlobalValue.prototype.compareTo$1 = GlobalValue.prototype.compareTo; |
| 12491 // ********** Code for BareValue ************** |
| 12492 $inherits(BareValue, Value); |
| 12493 function BareValue(home, outermost, span) { |
| 12494 this.home = home; |
| 12495 // Initializers done |
| 12496 Value.call(this, outermost.method.declaringType, null, span, false); |
| 12497 this.isType = outermost.get$isStatic(); |
| 12498 } |
| 12499 BareValue.prototype.get$type = function() { |
| 12500 return this._type; |
| 12501 } |
| 12502 BareValue.prototype._ensureCode = function() { |
| 12503 if (this.code != null) return; |
| 12504 if (this.isType) { |
| 12505 this.code = this.get$type().get$jsname(); |
| 12506 } |
| 12507 else { |
| 12508 this.code = this.home._makeThisCode(); |
| 12509 } |
| 12510 } |
| 12511 BareValue.prototype._tryResolveMember = function(context, name) { |
| 12512 var member = this.get$type().resolveMember(name); |
| 12513 if (member != null) { |
| 12514 if ($globals.options.forceDynamic && !member.get$isStatic()) { |
| 12515 member = context.findMembers(name); |
| 12516 } |
| 12517 this._ensureCode(); |
| 12518 return member; |
| 12519 } |
| 12520 member = this.home.get$library().lookup(name, this.span); |
| 12521 if (member != null) { |
| 12522 return member; |
| 12523 } |
| 12524 this._ensureCode(); |
| 12525 return null; |
| 12526 } |
| 12527 // ********** Code for CompilerException ************** |
| 12528 function CompilerException(_message, _location) { |
| 12529 this._message = _message; |
| 12530 this._location = _location; |
| 12531 // Initializers done |
| 12532 } |
| 12533 CompilerException.prototype.toString = function() { |
| 12534 if (this._location != null) { |
| 12535 return ('CompilerException: ' + this._location.toMessageString(this._message
)); |
| 12536 } |
| 12537 else { |
| 12538 return ('CompilerException: ' + this._message); |
| 12539 } |
| 12540 } |
| 12541 CompilerException.prototype.toString$0 = CompilerException.prototype.toString; |
| 12542 // ********** Code for World ************** |
| 12543 function World(files) { |
| 12544 this.errors = 0 |
| 12545 this.warnings = 0 |
| 12546 this.dartBytesRead = 0 |
| 12547 this.jsBytesWritten = 0 |
| 12548 this.seenFatal = false |
| 12549 this.files = files; |
| 12550 this.libraries = new HashMapImplementation(); |
| 12551 this._todo = []; |
| 12552 this._members = new HashMapImplementation(); |
| 12553 this._topNames = new HashMapImplementation(); |
| 12554 this.reader = new LibraryReader(); |
| 12555 // Initializers done |
| 12556 } |
| 12557 World.prototype.get$coreimpl = function() { |
| 12558 return this.libraries.$index('dart:coreimpl'); |
| 12559 } |
| 12560 World.prototype.get$dom = function() { |
| 12561 return this.libraries.$index('dart:dom'); |
| 12562 } |
| 12563 World.prototype.get$functionType = function() { return this.functionType; }; |
| 12564 World.prototype.set$functionType = function(value) { return this.functionType =
value; }; |
| 12565 World.prototype.reset = function() { |
| 12566 this.libraries = new HashMapImplementation(); |
| 12567 this._todo = []; |
| 12568 this._members = new HashMapImplementation(); |
| 12569 this._topNames = new HashMapImplementation(); |
| 12570 this.errors = this.warnings = 0; |
| 12571 this.seenFatal = false; |
| 12572 this.init(); |
| 12573 } |
| 12574 World.prototype.init = function() { |
| 12575 this.corelib = new Library(this.readFile('dart:core')); |
| 12576 this.libraries.$setindex('dart:core', this.corelib); |
| 12577 this._todo.add(this.corelib); |
| 12578 this.voidType = this._addToCoreLib('void', false); |
| 12579 this.dynamicType = this._addToCoreLib('Dynamic', false); |
| 12580 this.varType = this.dynamicType; |
| 12581 this.objectType = this._addToCoreLib('Object', true); |
| 12582 this.numType = this._addToCoreLib('num', false); |
| 12583 this.intType = this._addToCoreLib('int', false); |
| 12584 this.doubleType = this._addToCoreLib('double', false); |
| 12585 this.boolType = this._addToCoreLib('bool', false); |
| 12586 this.stringType = this._addToCoreLib('String', false); |
| 12587 this.listType = this._addToCoreLib('List', false); |
| 12588 this.mapType = this._addToCoreLib('Map', false); |
| 12589 this.functionType = this._addToCoreLib('Function', false); |
| 12590 this.nonNullBool = new NonNullableType(this.boolType); |
| 12591 } |
| 12592 World.prototype._addMember = function(member) { |
| 12593 if (member.get$isStatic()) { |
| 12594 if (member.declaringType.get$isTop()) { |
| 12595 this._addTopName(member); |
| 12596 } |
| 12597 return; |
| 12598 } |
| 12599 var mset = this._members.$index(member.name); |
| 12600 if (mset == null) { |
| 12601 mset = new MemberSet(member, true); |
| 12602 this._members.$setindex(mset.get$name(), mset); |
| 12603 } |
| 12604 else { |
| 12605 mset.get$members().add$1(member); |
| 12606 } |
| 12607 } |
| 12608 World.prototype._addTopName = function(named) { |
| 12609 var existing = this._topNames.$index(named.get$jsname()); |
| 12610 if (existing != null) { |
| 12611 this.info(('mangling matching top level name "' + named.get$jsname() + '" in
') + ('both "' + named.get$library().get$jsname() + '" and "' + existing.get$li
brary().get$jsname() + '"')); |
| 12612 if (named.get$isNative()) { |
| 12613 if (existing.get$isNative()) { |
| 12614 $globals.world.internalError(('conflicting native names "' + named.get$j
sname() + '" ') + ('(already defined in ' + existing.get$span().get$locationText
() + ')'), named.get$span()); |
| 12615 } |
| 12616 else { |
| 12617 this._topNames.$setindex(named.get$jsname(), named); |
| 12618 this._addJavascriptTopName(existing); |
| 12619 } |
| 12620 } |
| 12621 else if (named.get$library().get$isCore()) { |
| 12622 if (existing.get$library().get$isCore()) { |
| 12623 $globals.world.internalError(('conflicting top-level names in core "' +
named.get$jsname() + '" ') + ('(previously defined in ' + existing.get$span().ge
t$locationText() + ')'), named.get$span()); |
| 12624 } |
| 12625 else { |
| 12626 this._topNames.$setindex(named.get$jsname(), named); |
| 12627 this._addJavascriptTopName(existing); |
| 12628 } |
| 12629 } |
| 12630 else { |
| 12631 this._addJavascriptTopName(named); |
| 12632 } |
| 12633 } |
| 12634 else { |
| 12635 this._topNames.$setindex(named.get$jsname(), named); |
| 12636 } |
| 12637 } |
| 12638 World.prototype._addJavascriptTopName = function(named) { |
| 12639 named._jsname = ('' + named.get$library().get$jsname() + '_' + named.get$jsnam
e()); |
| 12640 var existing = this._topNames.$index(named.get$jsname()); |
| 12641 if (existing != null && $ne(existing, named)) { |
| 12642 $globals.world.internalError(('name mangling failed for "' + named.get$jsnam
e() + '" ') + ('("' + named.get$jsname() + '" defined also in ' + existing.get$s
pan().get$locationText() + ')'), named.get$span()); |
| 12643 } |
| 12644 this._topNames.$setindex(named.get$jsname(), named); |
| 12645 } |
| 12646 World.prototype._addType = function(type) { |
| 12647 if (!type.get$isTop()) this._addTopName(type); |
| 12648 } |
| 12649 World.prototype._addToCoreLib = function(name, isClass) { |
| 12650 var ret = new DefinedType(name, this.corelib, null, isClass); |
| 12651 this.corelib.types.$setindex(name, ret); |
| 12652 return ret; |
| 12653 } |
| 12654 World.prototype.toJsIdentifier = function(name) { |
| 12655 if (name == null) return null; |
| 12656 if (this._jsKeywords == null) { |
| 12657 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'])
; |
| 12658 } |
| 12659 if (this._jsKeywords.contains(name)) { |
| 12660 return name + '_'; |
| 12661 } |
| 12662 else { |
| 12663 return name.replaceAll("$", "$$").replaceAll(':', "$"); |
| 12664 } |
| 12665 } |
| 12666 World.prototype.compile = function() { |
| 12667 if ($globals.options.dartScript == null) { |
| 12668 this.fatal('no script provided to compile'); |
| 12669 return false; |
| 12670 } |
| 12671 try { |
| 12672 this.info(('compiling ' + $globals.options.dartScript + ' with corelib ' + t
his.corelib)); |
| 12673 if (!this.runLeg()) this.runCompilationPhases(); |
| 12674 } catch (exc) { |
| 12675 exc = _toDartException(exc); |
| 12676 if (this.get$hasErrors() && !$globals.options.throwOnErrors) { |
| 12677 } |
| 12678 else { |
| 12679 throw exc; |
| 12680 } |
| 12681 } |
| 12682 this.printStatus(); |
| 12683 return !this.get$hasErrors(); |
| 12684 } |
| 12685 World.prototype.runLeg = function() { |
| 12686 var $this = this; // closure support |
| 12687 if (!$globals.options.enableLeg) return false; |
| 12688 if ($globals.legCompile == null) { |
| 12689 this.fatal('requested leg enabled, but no leg compiler available'); |
| 12690 } |
| 12691 var res = this.withTiming('try leg compile', (function () { |
| 12692 return $globals.legCompile($this); |
| 12693 }) |
| 12694 ); |
| 12695 if (!res && $globals.options.legOnly) { |
| 12696 this.fatal(("Leg could not compile " + $globals.options.dartScript)); |
| 12697 return true; |
| 12698 } |
| 12699 return res; |
| 12700 } |
| 12701 World.prototype.runCompilationPhases = function() { |
| 12702 var $this = this; // closure support |
| 12703 var lib = this.withTiming('first pass', (function () { |
| 12704 return $this.processDartScript(); |
| 12705 }) |
| 12706 ); |
| 12707 this.withTiming('resolve top level', this.get$resolveAll()); |
| 12708 if ($globals.experimentalAwaitPhase != null) { |
| 12709 this.withTiming('await translation', to$call$0($globals.experimentalAwaitPha
se)); |
| 12710 } |
| 12711 this.withTiming('generate code', (function () { |
| 12712 $this.generateCode(lib); |
| 12713 }) |
| 12714 ); |
| 12715 } |
| 12716 World.prototype.getGeneratedCode = function() { |
| 12717 if (this.legCode != null) { |
| 12718 return this.legCode; |
| 12719 } |
| 12720 else { |
| 12721 return this.gen.writer.get$text(); |
| 12722 } |
| 12723 } |
| 12724 World.prototype.readFile = function(filename) { |
| 12725 try { |
| 12726 var sourceFile = this.reader.readFile(filename); |
| 12727 this.dartBytesRead += sourceFile.get$text().length; |
| 12728 return sourceFile; |
| 12729 } catch (e) { |
| 12730 e = _toDartException(e); |
| 12731 this.warning(('Error reading file: ' + filename)); |
| 12732 return new SourceFile(filename, ''); |
| 12733 } |
| 12734 } |
| 12735 World.prototype.getOrAddLibrary = function(filename) { |
| 12736 var library = this.libraries.$index(filename); |
| 12737 if (library == null) { |
| 12738 library = new Library(this.readFile(filename)); |
| 12739 this.info(('read library ' + filename)); |
| 12740 if (!library.get$isCore() && !library.imports.some((function (li) { |
| 12741 return li.get$library().get$isCore(); |
| 12742 }) |
| 12743 )) { |
| 12744 library.imports.add(new LibraryImport(this.corelib)); |
| 12745 } |
| 12746 this.libraries.$setindex(filename, library); |
| 12747 this._todo.add(library); |
| 12748 } |
| 12749 return library; |
| 12750 } |
| 12751 World.prototype.process = function() { |
| 12752 while (this._todo.length > 0) { |
| 12753 var todo = this._todo; |
| 12754 this._todo = []; |
| 12755 for (var $$i = 0;$$i < todo.length; $$i++) { |
| 12756 var lib = todo.$index($$i); |
| 12757 lib.visitSources$0(); |
| 12758 } |
| 12759 } |
| 12760 } |
| 12761 World.prototype.processDartScript = function(script) { |
| 12762 if (script == null) script = $globals.options.dartScript; |
| 12763 var library = this.getOrAddLibrary(script); |
| 12764 this.process(); |
| 12765 return library; |
| 12766 } |
| 12767 World.prototype.resolveAll = function() { |
| 12768 var $$list = this.libraries.getValues(); |
| 12769 for (var $$i = this.libraries.getValues().iterator$0(); $$i.hasNext$0(); ) { |
| 12770 var lib = $$i.next$0(); |
| 12771 lib.resolve$0(); |
| 12772 } |
| 12773 } |
| 12774 World.prototype.get$resolveAll = function() { |
| 12775 return World.prototype.resolveAll.bind(this); |
| 12776 } |
| 12777 World.prototype.generateCode = function(lib) { |
| 12778 var mainMembers = lib.topType.resolveMember('main'); |
| 12779 var main = null; |
| 12780 if (mainMembers == null || $eq(mainMembers.get$members().length, 0)) { |
| 12781 this.fatal('no main method specified'); |
| 12782 } |
| 12783 else if (mainMembers.get$members().length > 1) { |
| 12784 var $$list = mainMembers.get$members(); |
| 12785 for (var $$i = mainMembers.get$members().iterator$0(); $$i.hasNext$0(); ) { |
| 12786 var m = $$i.next$0(); |
| 12787 main = m; |
| 12788 this.error('more than one main member (using last?)', main.get$span()); |
| 12789 } |
| 12790 } |
| 12791 else { |
| 12792 main = mainMembers.get$members().$index(0); |
| 12793 } |
| 12794 var codeWriter = new CodeWriter(); |
| 12795 this.gen = new WorldGenerator(main, codeWriter); |
| 12796 this.gen.run(); |
| 12797 this.jsBytesWritten = codeWriter.get$text().length; |
| 12798 } |
| 12799 World.prototype._message = function(color, prefix, message, span, span1, span2,
throwing) { |
| 12800 if (this.messageHandler != null) { |
| 12801 this.messageHandler(prefix, message, span); |
| 12802 if (span1 != null) { |
| 12803 this.messageHandler(prefix, message, span1); |
| 12804 } |
| 12805 if (span2 != null) { |
| 12806 this.messageHandler(prefix, message, span2); |
| 12807 } |
| 12808 } |
| 12809 var messageWithPrefix = $globals.options.useColors ? (color + prefix + $global
s._NO_COLOR + message) : (prefix + message); |
| 12810 var text = messageWithPrefix; |
| 12811 if (span != null) { |
| 12812 text = span.toMessageString(messageWithPrefix); |
| 12813 } |
| 12814 print(text); |
| 12815 if (span1 != null) { |
| 12816 print(span1.toMessageString(messageWithPrefix)); |
| 12817 } |
| 12818 if (span2 != null) { |
| 12819 print(span2.toMessageString(messageWithPrefix)); |
| 12820 } |
| 12821 if (throwing) { |
| 12822 $throw(new CompilerException(messageWithPrefix, span)); |
| 12823 } |
| 12824 } |
| 12825 World.prototype.error = function(message, span, span1, span2) { |
| 12826 this.errors++; |
| 12827 this._message($globals._RED_COLOR, 'error: ', message, span, span1, span2, $gl
obals.options.throwOnErrors); |
| 12828 } |
| 12829 World.prototype.warning = function(message, span, span1, span2) { |
| 12830 if ($globals.options.warningsAsErrors) { |
| 12831 this.error(message, span, span1, span2); |
| 12832 return; |
| 12833 } |
| 12834 this.warnings++; |
| 12835 if ($globals.options.showWarnings) { |
| 12836 this._message($globals._MAGENTA_COLOR, 'warning: ', message, span, span1, sp
an2, $globals.options.throwOnWarnings); |
| 12837 } |
| 12838 } |
| 12839 World.prototype.fatal = function(message, span, span1, span2) { |
| 12840 this.errors++; |
| 12841 this.seenFatal = true; |
| 12842 this._message($globals._RED_COLOR, 'fatal: ', message, span, span1, span2, $gl
obals.options.throwOnFatal || $globals.options.throwOnErrors); |
| 12843 } |
| 12844 World.prototype.internalError = function(message, span, span1, span2) { |
| 12845 this._message($globals._NO_COLOR, 'We are sorry, but...', message, span, span1
, span2, true); |
| 12846 } |
| 12847 World.prototype.info = function(message, span, span1, span2) { |
| 12848 if ($globals.options.showInfo) { |
| 12849 this._message($globals._GREEN_COLOR, 'info: ', message, span, span1, span2,
false); |
| 12850 } |
| 12851 } |
| 12852 World.prototype.withoutForceDynamic = function(fn) { |
| 12853 var oldForceDynamic = $globals.options.forceDynamic; |
| 12854 $globals.options.forceDynamic = false; |
| 12855 try { |
| 12856 return fn(); |
| 12857 } finally { |
| 12858 $globals.options.forceDynamic = oldForceDynamic; |
| 12859 } |
| 12860 } |
| 12861 World.prototype.get$hasErrors = function() { |
| 12862 return this.errors > 0; |
| 12863 } |
| 12864 World.prototype.printStatus = function() { |
| 12865 this.info(('compiled ' + this.dartBytesRead + ' bytes Dart -> ' + this.jsBytes
Written + ' bytes JS')); |
| 12866 if (this.get$hasErrors()) { |
| 12867 print(('compilation failed with ' + this.errors + ' errors')); |
| 12868 } |
| 12869 else { |
| 12870 if (this.warnings > 0) { |
| 12871 this.info(('compilation completed successfully with ' + this.warnings + '
warnings')); |
| 12872 } |
| 12873 else { |
| 12874 this.info('compilation completed sucessfully'); |
| 12875 } |
| 12876 } |
| 12877 } |
| 12878 World.prototype.withTiming = function(name, f) { |
| 12879 var sw = new StopwatchImplementation(); |
| 12880 sw.start(); |
| 12881 var result = f(); |
| 12882 sw.stop(); |
| 12883 this.info(('' + name + ' in ' + sw.elapsedInMs() + 'msec')); |
| 12884 return result; |
| 12885 } |
| 12886 // ********** Code for FrogOptions ************** |
| 12887 function FrogOptions(homedir, args, files) { |
| 12888 this.config = 'dev' |
| 12889 this.enableLeg = false |
| 12890 this.legOnly = false |
| 12891 this.enableAsserts = false |
| 12892 this.enableTypeChecks = false |
| 12893 this.warningsAsErrors = false |
| 12894 this.verifyImplements = false |
| 12895 this.compileAll = false |
| 12896 this.forceDynamic = false |
| 12897 this.dietParse = false |
| 12898 this.compileOnly = false |
| 12899 this.throwOnErrors = false |
| 12900 this.throwOnWarnings = false |
| 12901 this.throwOnFatal = false |
| 12902 this.showInfo = false |
| 12903 this.showWarnings = true |
| 12904 this.useColors = true |
| 12905 // Initializers done |
| 12906 if ($eq(this.config, 'dev')) { |
| 12907 this.libDir = joinPaths(homedir, '/lib'); |
| 12908 } |
| 12909 else if ($eq(this.config, 'sdk')) { |
| 12910 this.libDir = joinPaths(homedir, '/../lib'); |
| 12911 } |
| 12912 else { |
| 12913 $globals.world.error(('Invalid configuration ' + this.config)); |
| 12914 $throw(('Invalid configuration')); |
| 12915 } |
| 12916 var ignoreUnrecognizedFlags = false; |
| 12917 var passedLibDir = false; |
| 12918 this.childArgs = []; |
| 12919 loop: |
| 12920 for (var i = 2; |
| 12921 i < args.length; i++) { |
| 12922 var arg = args.$index(i); |
| 12923 switch (arg) { |
| 12924 case '--enable_leg': |
| 12925 |
| 12926 this.enableLeg = true; |
| 12927 break; |
| 12928 |
| 12929 case '--leg_only': |
| 12930 |
| 12931 this.enableLeg = true; |
| 12932 this.legOnly = true; |
| 12933 break; |
| 12934 |
| 12935 case '--enable_asserts': |
| 12936 |
| 12937 this.enableAsserts = true; |
| 12938 break; |
| 12939 |
| 12940 case '--enable_type_checks': |
| 12941 |
| 12942 this.enableTypeChecks = true; |
| 12943 this.enableAsserts = true; |
| 12944 break; |
| 12945 |
| 12946 case '--verify_implements': |
| 12947 |
| 12948 this.verifyImplements = true; |
| 12949 break; |
| 12950 |
| 12951 case '--compile_all': |
| 12952 |
| 12953 this.compileAll = true; |
| 12954 break; |
| 12955 |
| 12956 case '--diet-parse': |
| 12957 |
| 12958 this.dietParse = true; |
| 12959 break; |
| 12960 |
| 12961 case '--ignore-unrecognized-flags': |
| 12962 |
| 12963 ignoreUnrecognizedFlags = true; |
| 12964 break; |
| 12965 |
| 12966 case '--verbose': |
| 12967 |
| 12968 this.showInfo = true; |
| 12969 break; |
| 12970 |
| 12971 case '--suppress_warnings': |
| 12972 |
| 12973 this.showWarnings = false; |
| 12974 break; |
| 12975 |
| 12976 case '--warnings_as_errors': |
| 12977 |
| 12978 this.warningsAsErrors = true; |
| 12979 break; |
| 12980 |
| 12981 case '--throw_on_errors': |
| 12982 |
| 12983 this.throwOnErrors = true; |
| 12984 break; |
| 12985 |
| 12986 case '--throw_on_warnings': |
| 12987 |
| 12988 this.throwOnWarnings = true; |
| 12989 break; |
| 12990 |
| 12991 case '--compile-only': |
| 12992 |
| 12993 this.compileOnly = true; |
| 12994 break; |
| 12995 |
| 12996 case '--force_dynamic': |
| 12997 |
| 12998 this.forceDynamic = true; |
| 12999 break; |
| 13000 |
| 13001 case '--no_colors': |
| 13002 |
| 13003 this.useColors = false; |
| 13004 break; |
| 13005 |
| 13006 default: |
| 13007 |
| 13008 if (arg.endsWith$1('.dart')) { |
| 13009 this.dartScript = arg; |
| 13010 this.childArgs = args.getRange(i + 1, args.length - i - 1); |
| 13011 break loop; |
| 13012 } |
| 13013 else if (arg.startsWith$1('--out=')) { |
| 13014 this.outfile = arg.substring$1('--out='.length); |
| 13015 } |
| 13016 else if (arg.startsWith$1('--libdir=')) { |
| 13017 this.libDir = arg.substring$1('--libdir='.length); |
| 13018 passedLibDir = true; |
| 13019 } |
| 13020 else { |
| 13021 if (!ignoreUnrecognizedFlags) { |
| 13022 print(('unrecognized flag: "' + arg + '"')); |
| 13023 } |
| 13024 } |
| 13025 |
| 13026 } |
| 13027 } |
| 13028 if (!passedLibDir && $eq(this.config, 'dev') && !files.fileExists(this.libDir)
) { |
| 13029 var temp = 'frog/lib'; |
| 13030 if (files.fileExists(temp)) { |
| 13031 this.libDir = temp; |
| 13032 } |
| 13033 else { |
| 13034 this.libDir = 'lib'; |
| 13035 } |
| 13036 } |
| 13037 } |
| 13038 // ********** Code for LibraryReader ************** |
| 13039 function LibraryReader() { |
| 13040 // Initializers done |
| 13041 if ($eq($globals.options.config, 'dev')) { |
| 13042 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')]); |
| 13043 } |
| 13044 else if ($eq($globals.options.config, 'sdk')) { |
| 13045 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')]); |
| 13046 } |
| 13047 else { |
| 13048 $globals.world.error(('Invalid configuration ' + $globals.options.config)); |
| 13049 } |
| 13050 } |
| 13051 LibraryReader.prototype.readFile = function(fullname) { |
| 13052 var filename = this._specialLibs.$index(fullname); |
| 13053 if (filename == null) { |
| 13054 filename = fullname; |
| 13055 } |
| 13056 if ($globals.world.files.fileExists(filename)) { |
| 13057 return new SourceFile(filename, $globals.world.files.readAll(filename)); |
| 13058 } |
| 13059 else { |
| 13060 $globals.world.error(('File not found: ' + filename)); |
| 13061 return new SourceFile(filename, ''); |
| 13062 } |
| 13063 } |
| 13064 // ********** Code for VarMember ************** |
| 13065 function VarMember(name) { |
| 13066 this.isGenerated = false |
| 13067 this.name = name; |
| 13068 // Initializers done |
| 13069 } |
| 13070 VarMember.prototype.get$name = function() { return this.name; }; |
| 13071 VarMember.prototype.get$isGenerated = function() { return this.isGenerated; }; |
| 13072 VarMember.prototype.set$isGenerated = function(value) { return this.isGenerated
= value; }; |
| 13073 VarMember.prototype.get$returnType = function() { |
| 13074 return $globals.world.varType; |
| 13075 } |
| 13076 VarMember.prototype.invoke = function(context, node, target, args) { |
| 13077 return new Value(this.get$returnType(), ('' + target.code + '.' + this.name +
'(' + args.getCode() + ')'), node.span, true); |
| 13078 } |
| 13079 VarMember.prototype.generate$1 = VarMember.prototype.generate; |
| 13080 VarMember.prototype.invoke$4 = VarMember.prototype.invoke; |
| 13081 // ********** Code for VarFunctionStub ************** |
| 13082 $inherits(VarFunctionStub, VarMember); |
| 13083 function VarFunctionStub(name, callArgs) { |
| 13084 this.args = callArgs.toCallStubArgs(); |
| 13085 // Initializers done |
| 13086 VarMember.call(this, name); |
| 13087 $globals.world.gen.corejs.useGenStub = true; |
| 13088 } |
| 13089 VarFunctionStub.prototype.generate = function(code) { |
| 13090 this.isGenerated = true; |
| 13091 if (this.args.get$hasNames()) { |
| 13092 this.generateNamed(code); |
| 13093 } |
| 13094 else { |
| 13095 this.generatePositional(code); |
| 13096 } |
| 13097 } |
| 13098 VarFunctionStub.prototype.generatePositional = function(w) { |
| 13099 var arity = this.args.get$length(); |
| 13100 w.enterBlock(('Function.prototype.to\$' + this.name + ' = function() {')); |
| 13101 w.writeln(('this.' + this.name + ' = this.\$genStub(' + arity + ');')); |
| 13102 w.writeln(('this.to\$' + this.name + ' = function() { return this.' + this.nam
e + '; };')); |
| 13103 w.writeln(('return this.' + this.name + ';')); |
| 13104 w.exitBlock('};'); |
| 13105 var argsCode = this.args.getCode(); |
| 13106 w.enterBlock(('Function.prototype.' + this.name + ' = function(' + argsCode +
') {')); |
| 13107 w.writeln(('return this.to\$' + this.name + '()(' + argsCode + ');')); |
| 13108 w.exitBlock('};'); |
| 13109 w.writeln(('function to\$' + this.name + '(f) { return f && f.to\$' + this.nam
e + '(); }')); |
| 13110 } |
| 13111 VarFunctionStub.prototype.generateNamed = function(w) { |
| 13112 var named = Strings.join(this.args.getNames(), '", "'); |
| 13113 var argsCode = this.args.getCode(); |
| 13114 w.enterBlock(('Function.prototype.' + this.name + ' = function(' + argsCode +
') {')); |
| 13115 w.writeln(('this.' + this.name + ' = this.\$genStub(' + this.args.get$length()
+ ', ["' + named + '"]);')); |
| 13116 w.writeln(('return this.' + this.name + '(' + argsCode + ');')); |
| 13117 w.exitBlock('}'); |
| 13118 } |
| 13119 VarFunctionStub.prototype.generate$1 = VarFunctionStub.prototype.generate; |
| 13120 // ********** Code for VarMethodStub ************** |
| 13121 $inherits(VarMethodStub, VarMember); |
| 13122 function VarMethodStub(name, member, args, body) { |
| 13123 this.member = member; |
| 13124 this.args = args; |
| 13125 this.body = body; |
| 13126 // Initializers done |
| 13127 VarMember.call(this, name); |
| 13128 } |
| 13129 VarMethodStub.prototype.get$body = function() { return this.body; }; |
| 13130 VarMethodStub.prototype.get$isHidden = function() { |
| 13131 return this.member != null ? this.member.declaringType.get$isHiddenNativeType(
) : false; |
| 13132 } |
| 13133 VarMethodStub.prototype.get$returnType = function() { |
| 13134 return this.member != null ? this.member.get$returnType() : $globals.world.var
Type; |
| 13135 } |
| 13136 VarMethodStub.prototype.get$declaringType = function() { |
| 13137 return this.member != null ? this.member.declaringType : $globals.world.object
Type; |
| 13138 } |
| 13139 VarMethodStub.prototype.generate = function(code) { |
| 13140 this.isGenerated = true; |
| 13141 code.write($globals.world.gen._prototypeOf(this.get$declaringType(), this.name
) + ' = '); |
| 13142 if (!this.get$isHidden() && this._useDirectCall(this.args)) { |
| 13143 code.writeln($globals.world.gen._prototypeOf(this.get$declaringType(), this.
member.get$jsname()) + ';'); |
| 13144 } |
| 13145 else if (this._needsExactTypeCheck()) { |
| 13146 code.enterBlock(('function(' + this.args.getCode() + ') {')); |
| 13147 code.enterBlock(('if (Object.getPrototypeOf(this).hasOwnProperty("' + this.n
ame + '")) {')); |
| 13148 code.writeln(('' + this.body + ';')); |
| 13149 code.exitBlock('}'); |
| 13150 var argsCode = this.args.getCode(); |
| 13151 if (argsCode != '') argsCode = ', ' + argsCode; |
| 13152 code.writeln(('return Object.prototype.' + this.name + '.call(this' + argsCo
de + ');')); |
| 13153 code.exitBlock('};'); |
| 13154 } |
| 13155 else { |
| 13156 code.enterBlock(('function(' + this.args.getCode() + ') {')); |
| 13157 code.writeln(('' + this.body + ';')); |
| 13158 code.exitBlock('};'); |
| 13159 } |
| 13160 } |
| 13161 VarMethodStub.prototype._needsExactTypeCheck = function() { |
| 13162 var $this = this; // closure support |
| 13163 if (this.member == null || this.member.declaringType.get$isObject()) return fa
lse; |
| 13164 var members = this.member.declaringType.resolveMember(this.member.name).member
s; |
| 13165 return members.filter$1((function (m) { |
| 13166 return $ne(m, $this.member) && m.get$declaringType().get$isHiddenNativeType(
); |
| 13167 }) |
| 13168 ).length >= 1; |
| 13169 } |
| 13170 VarMethodStub.prototype._useDirectCall = function(args) { |
| 13171 if ((this.member instanceof MethodMember) && !this.member.declaringType.get$ha
sNativeSubtypes()) { |
| 13172 var method = this.member; |
| 13173 if (method.needsArgumentConversion(args)) { |
| 13174 return false; |
| 13175 } |
| 13176 for (var i = args.get$length(); |
| 13177 i < method.parameters.length; i++) { |
| 13178 if ($ne(method.parameters.$index(i).get$value().get$code(), 'null')) { |
| 13179 return false; |
| 13180 } |
| 13181 } |
| 13182 return method.namesInOrder(args); |
| 13183 } |
| 13184 else { |
| 13185 return false; |
| 13186 } |
| 13187 } |
| 13188 VarMethodStub.prototype.generate$1 = VarMethodStub.prototype.generate; |
| 13189 // ********** Code for VarMethodSet ************** |
| 13190 $inherits(VarMethodSet, VarMember); |
| 13191 function VarMethodSet(baseName, name, members, callArgs, returnType) { |
| 13192 this.invoked = false |
| 13193 this.baseName = baseName; |
| 13194 this.members = members; |
| 13195 this.returnType = returnType; |
| 13196 this.args = callArgs.toCallStubArgs(); |
| 13197 // Initializers done |
| 13198 VarMember.call(this, name); |
| 13199 } |
| 13200 VarMethodSet.prototype.get$members = function() { return this.members; }; |
| 13201 VarMethodSet.prototype.get$returnType = function() { return this.returnType; }; |
| 13202 VarMethodSet.prototype.invoke = function(context, node, target, args) { |
| 13203 this._invokeMembers(context, node); |
| 13204 return VarMember.prototype.invoke.call(this, context, node, target, args); |
| 13205 } |
| 13206 VarMethodSet.prototype._invokeMembers = function(context, node) { |
| 13207 if (this.invoked) return; |
| 13208 this.invoked = true; |
| 13209 var hasObjectType = false; |
| 13210 var $$list = this.members; |
| 13211 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 13212 var member = $$list.$index($$i); |
| 13213 var type = member.get$declaringType(); |
| 13214 var target = new Value(type, 'this', node.span, true); |
| 13215 var result = member.invoke$4$isDynamic(context, node, target, this.args, tru
e); |
| 13216 var stub = new VarMethodStub(this.name, member, this.args, 'return ' + resul
t.get$code()); |
| 13217 type.get$varStubs().$setindex(stub.get$name(), stub); |
| 13218 if (type.get$isObject()) hasObjectType = true; |
| 13219 } |
| 13220 if (!hasObjectType) { |
| 13221 var target = new Value($globals.world.objectType, 'this', node.span, true); |
| 13222 var result = target.invokeNoSuchMethod(context, this.baseName, node, this.ar
gs); |
| 13223 var stub = new VarMethodStub(this.name, null, this.args, 'return ' + result.
get$code()); |
| 13224 $globals.world.objectType.varStubs.$setindex(stub.get$name(), stub); |
| 13225 } |
| 13226 } |
| 13227 VarMethodSet.prototype.generate = function(code) { |
| 13228 |
| 13229 } |
| 13230 VarMethodSet.prototype.generate$1 = VarMethodSet.prototype.generate; |
| 13231 VarMethodSet.prototype.invoke$4 = VarMethodSet.prototype.invoke; |
| 13232 // ********** Code for top level ************** |
| 13233 function _otherOperator(jsname, op) { |
| 13234 return ("function " + jsname + "(x, y) {\n return (typeof(x) == 'number' && t
ypeof(y) == 'number')\n ? x " + op + " y : x." + jsname + "(y);\n}"); |
| 13235 } |
| 13236 function map(source, mapper) { |
| 13237 var result = new ListFactory(); |
| 13238 if (!!(source && source.is$List())) { |
| 13239 var list = source; |
| 13240 result.length = list.length; |
| 13241 for (var i = 0; |
| 13242 i < list.length; i++) { |
| 13243 result.$setindex(i, mapper(list.$index(i))); |
| 13244 } |
| 13245 } |
| 13246 else { |
| 13247 for (var $$i = source.iterator(); $$i.hasNext$0(); ) { |
| 13248 var item = $$i.next$0(); |
| 13249 result.add(mapper(item)); |
| 13250 } |
| 13251 } |
| 13252 return result; |
| 13253 } |
| 13254 function reduce(source, callback, initialValue) { |
| 13255 var i = source.iterator(); |
| 13256 var current = initialValue; |
| 13257 if (current == null && i.hasNext$0()) { |
| 13258 current = i.next$0(); |
| 13259 } |
| 13260 while (i.hasNext$0()) { |
| 13261 current = callback.call$2(current, i.next$0()); |
| 13262 } |
| 13263 return current; |
| 13264 } |
| 13265 function orderValuesByKeys(map) { |
| 13266 var keys = map.getKeys(); |
| 13267 keys.sort((function (x, y) { |
| 13268 return x.compareTo$1(y); |
| 13269 }) |
| 13270 ); |
| 13271 var values = []; |
| 13272 for (var $$i = 0;$$i < keys.length; $$i++) { |
| 13273 var k = keys.$index($$i); |
| 13274 values.add(map.$index(k)); |
| 13275 } |
| 13276 return values; |
| 13277 } |
| 13278 function isMultilineString(text) { |
| 13279 return text.startsWith('"""') || text.startsWith("'''"); |
| 13280 } |
| 13281 function isRawMultilineString(text) { |
| 13282 return text.startsWith('@"""') || text.startsWith("@'''"); |
| 13283 } |
| 13284 function toDoubleQuote(s) { |
| 13285 return s.replaceAll('"', '\\"').replaceAll("\\'", "'"); |
| 13286 } |
| 13287 function parseStringLiteral(lit) { |
| 13288 if (lit.startsWith('@')) { |
| 13289 if (isRawMultilineString(lit)) { |
| 13290 return stripLeadingNewline(lit.substring(4, lit.length - 3)); |
| 13291 } |
| 13292 else { |
| 13293 return lit.substring(2, lit.length - 1); |
| 13294 } |
| 13295 } |
| 13296 else if (isMultilineString(lit)) { |
| 13297 lit = lit.substring(3, lit.length - 3).replaceAll('\\\$', '\$'); |
| 13298 return stripLeadingNewline(lit); |
| 13299 } |
| 13300 else { |
| 13301 return lit.substring(1, lit.length - 1).replaceAll('\\\$', '\$'); |
| 13302 } |
| 13303 } |
| 13304 function stripLeadingNewline(text) { |
| 13305 if (text.startsWith('\n')) { |
| 13306 return text.substring(1); |
| 13307 } |
| 13308 else if (text.startsWith('\r')) { |
| 13309 if (text.startsWith('\r\n')) { |
| 13310 return text.substring(2); |
| 13311 } |
| 13312 else { |
| 13313 return text.substring(1); |
| 13314 } |
| 13315 } |
| 13316 else { |
| 13317 return text; |
| 13318 } |
| 13319 } |
| 13320 function _escapeForComment(text) { |
| 13321 return text.replaceAll('/*', '/ *').replaceAll('*/', '* /'); |
| 13322 } |
| 13323 var world; |
| 13324 var experimentalAwaitPhase; |
| 13325 var legCompile; |
| 13326 function initializeWorld(files) { |
| 13327 $globals.world = new World(files); |
| 13328 $globals.world.init(); |
| 13329 } |
| 13330 var options; |
| 13331 function parseOptions(homedir, args, files) { |
| 13332 $globals.options = new FrogOptions(homedir, args, files); |
| 13333 } |
| 13334 function _getCallStubName(name, args) { |
| 13335 var nameBuilder = new StringBufferImpl(('' + name + '\$' + args.get$bareCount(
))); |
| 13336 for (var i = args.get$bareCount(); |
| 13337 i < args.get$length(); i++) { |
| 13338 nameBuilder.add('\$').add(args.getName(i)); |
| 13339 } |
| 13340 return nameBuilder.toString(); |
| 13341 } |
| 13342 // ********** Library toss ************** |
| 13343 // ********** Code for top level ************** |
| 13344 function compileDart(basename, filename) { |
| 13345 var basedir = path.dirname(basename); |
| 13346 var fullname = ('' + basedir + '/' + filename); |
| 13347 $globals.world.reset(); |
| 13348 $globals.options.dartScript = fullname; |
| 13349 if ($globals.world.compile()) { |
| 13350 return $globals.world.getGeneratedCode(); |
| 13351 } |
| 13352 else { |
| 13353 return ('alert("compilation of ' + filename + ' failed, see console for erro
rs");'); |
| 13354 } |
| 13355 } |
| 13356 function frogify(filename) { |
| 13357 var s = "<script\\s+type=\"application/dart\"(?:\\s+src=\"([/\\w]+.dart)\")?>(
[\\s\\S]*)</script>"; |
| 13358 var text = fs.readFileSync(filename, 'utf8'); |
| 13359 var re = new JSSyntaxRegExp(s, true, false); |
| 13360 var m = re.firstMatch(text); |
| 13361 if (m == null) return text; |
| 13362 var dname = m.group$1(1); |
| 13363 var contents = m.group$1(2); |
| 13364 print(('compiling ' + dname)); |
| 13365 var compiled = compileDart(filename, dname); |
| 13366 return text.substring(0, m.start$0()) + ('<script type="application/javascript
">' + compiled + '</script>') + text.substring(m.start$0() + m.group$1(0).length
); |
| 13367 } |
| 13368 function initializeCompiler(homedir) { |
| 13369 var filesystem = new NodeFileSystem(); |
| 13370 parseOptions(homedir, [null, null], filesystem); |
| 13371 initializeWorld(filesystem); |
| 13372 } |
| 13373 function dirToHtml(url, dirname) { |
| 13374 var names = new StringBufferImpl(""); |
| 13375 var $$list = fs.readdirSync(dirname); |
| 13376 for (var $$i = 0;$$i < $$list.length; $$i++) { |
| 13377 var name = $$list.$index($$i); |
| 13378 var link = ('' + url + '/' + name); |
| 13379 names.add$1(('<li><a href=' + link + '>' + name + '</a></li>\n')); |
| 13380 } |
| 13381 return (" <html><head><title>" + dirname + "</title></head>\n <h3>" + dirn
ame + "</h3>\n <ul>\n " + names + "\n </ul>\n </html>\n "); |
| 13382 } |
| 13383 function main() { |
| 13384 var homedir = path.dirname(fs.realpathSync(process.argv.$index(1))); |
| 13385 var dartdir = path.dirname(homedir); |
| 13386 print(('running with dart root at ' + dartdir)); |
| 13387 initializeCompiler(homedir); |
| 13388 http.createServer((function (req, res) { |
| 13389 var filename; |
| 13390 if (req.url.endsWith('.html')) { |
| 13391 res.setHeader('Content-Type', 'text/html'); |
| 13392 } |
| 13393 else if (req.url.endsWith('.css')) { |
| 13394 res.setHeader('Content-Type', 'text/css'); |
| 13395 } |
| 13396 else { |
| 13397 res.setHeader('Content-Type', 'text/plain'); |
| 13398 } |
| 13399 filename = ('' + dartdir + '/' + req.url); |
| 13400 if (path.existsSync(filename)) { |
| 13401 var stat = fs.statSync(filename); |
| 13402 if (stat.isFile$0()) { |
| 13403 res.statusCode = 200; |
| 13404 var data; |
| 13405 if (filename.endsWith$1('.html')) { |
| 13406 res.end(frogify(filename), 'utf8'); |
| 13407 } |
| 13408 else { |
| 13409 res.end(fs.readFileSync(filename, 'utf8'), 'utf8'); |
| 13410 } |
| 13411 return; |
| 13412 } |
| 13413 else { |
| 13414 res.setHeader('Content-Type', 'text/html'); |
| 13415 res.end(dirToHtml(req.url, filename), 'utf8'); |
| 13416 } |
| 13417 } |
| 13418 res.statusCode = 404; |
| 13419 res.end('', 'utf8'); |
| 13420 }) |
| 13421 ).listen(1337, "localhost"); |
| 13422 print('Server running at http://localhost:1337/'); |
| 13423 } |
| 13424 // ********** Generic Type Inheritance ************** |
| 13425 /** Implements extends for generic types. */ |
| 13426 function $inheritsMembers(child, parent) { |
| 13427 child = child.prototype; |
| 13428 parent = parent.prototype; |
| 13429 Object.getOwnPropertyNames(parent).forEach(function(name) { |
| 13430 if (typeof(child[name]) == 'undefined') child[name] = parent[name]; |
| 13431 }); |
| 13432 } |
| 13433 $inheritsMembers(_DoubleLinkedQueueEntrySentinel_E, DoubleLinkedQueueEntry_E); |
| 13434 $inheritsMembers(_DoubleLinkedQueueEntrySentinel_KeyValuePair_K$V, DoubleLinkedQ
ueueEntry_KeyValuePair_K$V); |
| 13435 // ********** Globals ************** |
| 13436 function $static_init(){ |
| 13437 $globals._GREEN_COLOR = '\u001b[32m'; |
| 13438 $globals._MAGENTA_COLOR = '\u001b[35m'; |
| 13439 $globals._NO_COLOR = '\u001b[0m'; |
| 13440 $globals._RED_COLOR = '\u001b[31m'; |
| 13441 } |
| 13442 var const$1 = new EmptyQueueException()/*const EmptyQueueException()*/; |
| 13443 var const$2 = new _DeletedKeySentinel()/*const _DeletedKeySentinel()*/; |
| 13444 var const$7 = new NoMoreElementsException()/*const NoMoreElementsException()*/; |
| 13445 var $globals = {}; |
| 13446 $static_init(); |
| 13447 main(); |
OLD | NEW |