| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('mock_compiler'); | 5 #library('mock_compiler'); |
| 6 | 6 |
| 7 #import("dart:uri"); | 7 #import("dart:uri"); |
| 8 | 8 |
| 9 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 9 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 10 #import("../../../lib/compiler/implementation/leg.dart"); | 10 #import("../../../lib/compiler/implementation/leg.dart"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 final String DEFAULT_HELPERLIB = @''' | 23 final String DEFAULT_HELPERLIB = @''' |
| 24 lt() {} add(var a, var b) {} sub() {} mul() {} div() {} tdiv() {} mod() {} | 24 lt() {} add(var a, var b) {} sub() {} mul() {} div() {} tdiv() {} mod() {} |
| 25 neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {} | 25 neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {} |
| 26 or() {} and() {} not() {} eqNull(a) {} eqq() {} | 26 or() {} and() {} not() {} eqNull(a) {} eqq() {} |
| 27 ltB() {} leB() {} eqB() {} gtB() {} geB() {} eqNullB(a) {} | 27 ltB() {} leB() {} eqB() {} gtB() {} geB() {} eqNullB(a) {} |
| 28 iae(x) {throw x;} ioore(x) {throw x;} | 28 iae(x) {throw x;} ioore(x) {throw x;} |
| 29 guard$array(x) { return x; } | 29 guard$array(x) { return x; } |
| 30 guard$num(x) { return x; } | 30 guard$num(x) { return x; } |
| 31 guard$string(x) { return x; } | 31 guard$string(x) { return x; } |
| 32 guard$stringOrArray(x) { return x; } | 32 guard$stringOrArray(x) { return x; } |
| 33 builtin$add$1(receiver, value) {} | |
| 34 builtin$get$length(var receiver) {} | |
| 35 builtin$filter$1(receiver, predicate) {} | |
| 36 builtin$removeLast$0(receiver) {} | |
| 37 index(a, index) {} | 33 index(a, index) {} |
| 38 indexSet(a, index, value) {} | 34 indexSet(a, index, value) {} |
| 39 builtin$iterator$0() {} | |
| 40 builtin$next$0() {} | |
| 41 builtin$hasNext$0() {} | |
| 42 setRuntimeTypeInfo(a, b) {} | 35 setRuntimeTypeInfo(a, b) {} |
| 43 getRuntimeTypeInfo(a) {} | 36 getRuntimeTypeInfo(a) {} |
| 44 stringConcat() {} | 37 stringConcat() {} |
| 45 stringToString() {}'''; | 38 stringToString() {}'''; |
| 46 | 39 |
| 40 final String DEFAULT_INTERCEPTORSLIB = @''' |
| 41 add$1(receiver, value) {} |
| 42 get$length(receiver) {} |
| 43 filter(receiver, predicate) {} |
| 44 removeLast(receiver) {} |
| 45 iterator(receiver) {} |
| 46 next(receiver) {} |
| 47 hasNext(receiver) {}'''; |
| 48 |
| 47 final String DEFAULT_CORELIB = @''' | 49 final String DEFAULT_CORELIB = @''' |
| 48 print(var obj) {} | 50 print(var obj) {} |
| 49 class int {} | 51 class int {} |
| 50 class double {} | 52 class double {} |
| 51 class bool {} | 53 class bool {} |
| 52 class String {} | 54 class String {} |
| 53 class Object {} | 55 class Object {} |
| 54 class num {} | 56 class num {} |
| 55 class Function {} | 57 class Function {} |
| 56 class List {} | 58 class List {} |
| 57 class Closure {} | 59 class Closure {} |
| 58 class Null {} | 60 class Null {} |
| 59 class Dynamic {}'''; | 61 class Dynamic {}'''; |
| 60 | 62 |
| 61 class MockCompiler extends Compiler { | 63 class MockCompiler extends Compiler { |
| 62 List<WarningMessage> warnings; | 64 List<WarningMessage> warnings; |
| 63 List<WarningMessage> errors; | 65 List<WarningMessage> errors; |
| 64 final Map<String, String> sources; | 66 final Map<String, String> sources; |
| 65 Node parsedTree; | 67 Node parsedTree; |
| 66 | 68 |
| 67 MockCompiler([String coreSource = DEFAULT_CORELIB, | 69 MockCompiler([String coreSource = DEFAULT_CORELIB, |
| 68 String helperSource = DEFAULT_HELPERLIB]) | 70 String helperSource = DEFAULT_HELPERLIB, |
| 71 String interceptorsSource = DEFAULT_INTERCEPTORSLIB]) |
| 69 : warnings = [], errors = [], | 72 : warnings = [], errors = [], |
| 70 sources = new Map<String, String>(), | 73 sources = new Map<String, String>(), |
| 71 super() { | 74 super() { |
| 72 Uri uri = new Uri(scheme: "source"); | 75 Uri uri = new Uri(scheme: "source"); |
| 73 var script = new Script(uri, new MockFile(coreSource)); | 76 var script = new Script(uri, new MockFile(coreSource)); |
| 74 coreLibrary = new LibraryElement(script); | 77 coreLibrary = new LibraryElement(script); |
| 75 parseScript(coreSource, coreLibrary); | 78 parseScript(coreSource, coreLibrary); |
| 79 |
| 76 script = new Script(uri, new MockFile(helperSource)); | 80 script = new Script(uri, new MockFile(helperSource)); |
| 77 jsHelperLibrary = new LibraryElement(script); | 81 jsHelperLibrary = new LibraryElement(script); |
| 78 parseScript(helperSource, jsHelperLibrary); | 82 parseScript(helperSource, jsHelperLibrary); |
| 83 |
| 84 script = new Script(uri, new MockFile(interceptorsSource)); |
| 85 interceptorsLibrary = new LibraryElement(script); |
| 86 parseScript(interceptorsSource, interceptorsLibrary); |
| 87 |
| 79 scanner.importLibrary(jsHelperLibrary, coreLibrary, null); | 88 scanner.importLibrary(jsHelperLibrary, coreLibrary, null); |
| 89 scanner.importLibrary(interceptorsLibrary, coreLibrary, null); |
| 80 mainApp = mockLibrary(this, ""); | 90 mainApp = mockLibrary(this, ""); |
| 81 initializeSpecialClasses(); | 91 initializeSpecialClasses(); |
| 82 } | 92 } |
| 83 | 93 |
| 84 void reportWarning(Node node, var message) { | 94 void reportWarning(Node node, var message) { |
| 85 warnings.add(new WarningMessage(node, message.message)); | 95 warnings.add(new WarningMessage(node, message.message)); |
| 86 } | 96 } |
| 87 | 97 |
| 88 void reportError(Node node, var message) { | 98 void reportError(Node node, var message) { |
| 89 if (message is String && message.startsWith("no #library tag found in")) { | 99 if (message is String && message.startsWith("no #library tag found in")) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 importLibrary(library, compiler.coreLibrary, compiler); | 203 importLibrary(library, compiler.coreLibrary, compiler); |
| 194 return library; | 204 return library; |
| 195 } | 205 } |
| 196 | 206 |
| 197 class StringScript extends Script { | 207 class StringScript extends Script { |
| 198 final String code; | 208 final String code; |
| 199 StringScript(this.code) : super(null, null); | 209 StringScript(this.code) : super(null, null); |
| 200 String get text() => code; | 210 String get text() => code; |
| 201 String get name() => "mock script"; | 211 String get name() => "mock script"; |
| 202 } | 212 } |
| OLD | NEW |