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

Side by Side Diff: pkg/smoke/lib/static_debug.dart

Issue 204143002: Changes in smoke in preparation of polymer's codegen: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Static implementation of smoke services that uses code-generated data and
6 /// verifies that the results match what we would get with a mirror-based
7 /// implementation.
8 library smoke.static_debug;
9
10 export 'package:smoke/static.dart' show StaticConfiguration, Getter, Setter;
11 import 'package:smoke/static.dart';
12 import 'package:smoke/mirrors.dart';
13 import 'package:smoke/smoke.dart';
14
15 import 'src/common.dart' show compareLists;
16
17 /// Set up the smoke package to use a static implementation based on the given
18 /// [configuration].
19 useGeneratedCode(StaticConfiguration configuration) {
20 configure(new _DebugObjectAccessorService(configuration),
21 new _DebugTypeInspectorService(configuration),
22 new _DebugSymbolConverterService(configuration));
23 }
24
25 /// Implements [ObjectAccessorService] using a static configuration.
26 class _DebugObjectAccessorService implements ObjectAccessorService {
27 GeneratedObjectAccessorService _static;
28 ReflectiveObjectAccessorService _mirrors;
29
30 _DebugObjectAccessorService(StaticConfiguration configuration)
31 : _static = new GeneratedObjectAccessorService(configuration),
32 _mirrors = new ReflectiveObjectAccessorService();
33
34 read(Object object, Symbol name) =>
35 _check('read', [object, name],
36 _static.read(object, name),
37 _mirrors.read(object, name));
38
39 // Note: we can't verify operations with side-effects like write or invoke.
40 void write(Object object, Symbol name, value) =>
41 _static.write(object, name, value);
42
43 invoke(object, Symbol name, List args, {Map namedArgs, bool adjust: false}) =>
44 _static.invoke(object, name, args, namedArgs: namedArgs, adjust: adjust);
45 }
46
47 /// Implements [TypeInspectorService] using a static configuration.
48 class _DebugTypeInspectorService implements TypeInspectorService {
49 GeneratedTypeInspectorService _static;
50 ReflectiveTypeInspectorService _mirrors;
51
52 _DebugTypeInspectorService(StaticConfiguration configuration)
53 : _static = new GeneratedTypeInspectorService(configuration),
54 _mirrors = new ReflectiveTypeInspectorService();
55
56 bool isSubclassOf(Type type, Type supertype) =>
57 _check('isSubclassOf', [type, supertype],
58 _static.isSubclassOf(type, supertype),
59 _mirrors.isSubclassOf(type, supertype));
60
61 bool hasGetter(Type type, Symbol name) =>
62 _check('hasGetter', [type, name],
63 _static.hasGetter(type, name),
64 _mirrors.hasGetter(type, name));
65
66 bool hasSetter(Type type, Symbol name) =>
67 _check('hasSetter', [type, name],
68 _static.hasSetter(type, name),
69 _mirrors.hasSetter(type, name));
70
71 bool hasInstanceMethod(Type type, Symbol name) =>
72 _check('hasInstanceMethod', [type, name],
73 _static.hasInstanceMethod(type, name),
74 _mirrors.hasInstanceMethod(type, name));
75
76 bool hasStaticMethod(Type type, Symbol name) =>
77 _check('hasStaticMethod', [type, name],
78 _static.hasStaticMethod(type, name),
79 _mirrors.hasStaticMethod(type, name));
80
81 Declaration getDeclaration(Type type, Symbol name) =>
82 _check('getDeclaration', [type, name],
83 _static.getDeclaration(type, name),
84 _mirrors.getDeclaration(type, name));
85
86 List<Declaration> query(Type type, QueryOptions options) =>
87 _check('query', [type, options],
88 _static.query(type, options),
89 _mirrors.query(type, options));
90 }
91
92 /// Implements [SymbolConverterService] using a static configuration.
93 class _DebugSymbolConverterService implements SymbolConverterService {
94 GeneratedSymbolConverterService _static;
95 ReflectiveSymbolConverterService _mirrors;
96
97 _DebugSymbolConverterService(StaticConfiguration configuration)
98 : _static = new GeneratedSymbolConverterService(configuration),
99 _mirrors = new ReflectiveSymbolConverterService();
100
101 String symbolToName(Symbol symbol) =>
102 _check('symbolToName', [symbol],
103 _static.symbolToName(symbol),
104 _mirrors.symbolToName(symbol));
105
106 Symbol nameToSymbol(String name) =>
107 _check('nameToSymbol', [name],
108 _static.nameToSymbol(name),
109 _mirrors.nameToSymbol(name));
110 }
111
112 _check(String operation, List arguments, staticResult, mirrorResult) {
113 if (staticResult == mirrorResult) return staticResult;
114 if (staticResult is List && mirrorResult is List &&
115 compareLists(staticResult, mirrorResult, unordered: true)) {
116 return staticResult;
117 }
118 print('warning: inconsistent result on $operation(${arguments.join(', ')})\n'
119 'smoke.mirrors result: $mirrorResult\n'
120 'smoke.static result: $staticResult\n');
121 return staticResult;
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698