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

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

Issue 194813007: Add codegen support in smoke (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
« no previous file with comments | « pkg/smoke/lib/codegen/recorder.dart ('k') | pkg/smoke/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 /// Static implementation of smoke services using code-generated data. 5 /// Static implementation of smoke services using code-generated data.
6 library smoke.static; 6 library smoke.static;
7 7
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:logging/logging.dart'; 10 import 'package:logging/logging.dart';
(...skipping 19 matching lines...) Expand all
30 final Map<Type, Type> parents; 30 final Map<Type, Type> parents;
31 31
32 /// For each type, a map of declarations per symbol (property or method). 32 /// For each type, a map of declarations per symbol (property or method).
33 final Map<Type, Map<Symbol, Declaration>> declarations; 33 final Map<Type, Map<Symbol, Declaration>> declarations;
34 34
35 /// A map from symbol to strings. 35 /// A map from symbol to strings.
36 final Map<Symbol, String> names; 36 final Map<Symbol, String> names;
37 37
38 /// A map from strings to symbols (the reverse of [names]). 38 /// A map from strings to symbols (the reverse of [names]).
39 final Map<String, Symbol> symbols; 39 final Map<String, Symbol> symbols;
40
41 /// Whether to check for missing declarations, otherwise, return default
42 /// values (for example a missing parent class can be treated as Object)
43 final bool checkedMode;
44
40 StaticConfiguration({ 45 StaticConfiguration({
41 this.getters: const {}, this.setters: const {}, this.parents: const {}, 46 this.getters: const {}, this.setters: const {}, this.parents: const {},
42 this.declarations: const {}, this.names: const {}}) 47 this.declarations: const {}, this.names: const {},
48 this.checkedMode: true})
43 : this.symbols = {} { 49 : this.symbols = {} {
44 names.forEach((k, v) { symbols[v] = k; }); 50 names.forEach((k, v) { symbols[v] = k; });
45 } 51 }
46 } 52 }
47 53
48 /// Set up the smoke package to use a static implementation based on the given 54 /// Set up the smoke package to use a static implementation based on the given
49 /// [configuration]. 55 /// [configuration].
50 useGeneratedCode(StaticConfiguration configuration) { 56 useGeneratedCode(StaticConfiguration configuration) {
51 _configuration = configuration; 57 _configuration = configuration;
52 configure(new _GeneratedObjectAccessorService(), 58 configure(new _GeneratedObjectAccessorService(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 119 }
114 120
115 /// Implements [TypeInspectorService] using a static configuration. 121 /// Implements [TypeInspectorService] using a static configuration.
116 class _GeneratedTypeInspectorService implements TypeInspectorService { 122 class _GeneratedTypeInspectorService implements TypeInspectorService {
117 bool isSubclassOf(Type type, Type supertype) { 123 bool isSubclassOf(Type type, Type supertype) {
118 if (type == supertype || supertype == Object) return true; 124 if (type == supertype || supertype == Object) return true;
119 while (type != Object) { 125 while (type != Object) {
120 var parentType = _configuration.parents[type]; 126 var parentType = _configuration.parents[type];
121 if (parentType == supertype) return true; 127 if (parentType == supertype) return true;
122 if (parentType == null) { 128 if (parentType == null) {
129 if (!_configuration.checkedMode) return false;
123 throw new MissingCodeException('superclass of "$type" ($parentType)'); 130 throw new MissingCodeException('superclass of "$type" ($parentType)');
124 } 131 }
125 type = parentType; 132 type = parentType;
126 } 133 }
127 return false; 134 return false;
128 } 135 }
129 136
130 bool hasGetter(Type type, Symbol name) { 137 bool hasGetter(Type type, Symbol name) {
131 var decl = _findDeclaration(type, name); 138 var decl = _findDeclaration(type, name);
132 // No need to check decl.isProperty because methods are also automatically 139 // No need to check decl.isProperty because methods are also automatically
133 // considered getters (auto-closures). 140 // considered getters (auto-closures).
134 return decl != null && !decl.isStatic; 141 return decl != null && !decl.isStatic;
135 } 142 }
136 143
137 bool hasSetter(Type type, Symbol name) { 144 bool hasSetter(Type type, Symbol name) {
138 var decl = _findDeclaration(type, name); 145 var decl = _findDeclaration(type, name);
139 return decl != null && !decl.isMethod && !decl.isFinal && !decl.isStatic; 146 return decl != null && !decl.isMethod && !decl.isFinal && !decl.isStatic;
140 } 147 }
141 148
142 bool hasInstanceMethod(Type type, Symbol name) { 149 bool hasInstanceMethod(Type type, Symbol name) {
143 var decl = _findDeclaration(type, name); 150 var decl = _findDeclaration(type, name);
144 return decl != null && decl.isMethod && !decl.isStatic; 151 return decl != null && decl.isMethod && !decl.isStatic;
145 } 152 }
146 153
147 bool hasStaticMethod(Type type, Symbol name) { 154 bool hasStaticMethod(Type type, Symbol name) {
148 final map = _configuration.declarations[type]; 155 final map = _configuration.declarations[type];
149 if (map == null) { 156 if (map == null) {
157 if (!_configuration.checkedMode) return false;
150 throw new MissingCodeException('declarations for $type'); 158 throw new MissingCodeException('declarations for $type');
151 } 159 }
152 final decl = map[name]; 160 final decl = map[name];
153 return decl != null && decl.isMethod && decl.isStatic; 161 return decl != null && decl.isMethod && decl.isStatic;
154 } 162 }
155 163
156 Declaration getDeclaration(Type type, Symbol name) { 164 Declaration getDeclaration(Type type, Symbol name) {
157 var decl = _findDeclaration(type, name); 165 var decl = _findDeclaration(type, name);
158 if (decl == null) { 166 if (decl == null) {
167 if (!_configuration.checkedMode) return null;
159 throw new MissingCodeException('declaration for $type.$name'); 168 throw new MissingCodeException('declaration for $type.$name');
160 } 169 }
161 return decl; 170 return decl;
162 } 171 }
163 172
164 List<Declaration> query(Type type, QueryOptions options) { 173 List<Declaration> query(Type type, QueryOptions options) {
165 var result; 174 var result = [];
166 if (options.includeInherited) { 175 if (options.includeInherited) {
167 var superclass = _configuration.parents[type]; 176 var superclass = _configuration.parents[type];
168 if (superclass == null) { 177 if (superclass == null) {
169 throw new MissingCodeException('superclass of "$type"'); 178 if (_configuration.checkedMode) {
179 throw new MissingCodeException('superclass of "$type"');
180 }
181 } else if (superclass != options.includeUpTo) {
182 result = query(superclass, options);
170 } 183 }
171 result = (superclass == options.includeUpTo) ? []
172 : query(superclass, options);
173 } else {
174 result = [];
175 } 184 }
176 var map = _configuration.declarations[type]; 185 var map = _configuration.declarations[type];
177 if (map == null) { 186 if (map == null) {
187 if (!_configuration.checkedMode) return result;
178 throw new MissingCodeException('declarations for $type'); 188 throw new MissingCodeException('declarations for $type');
179 } 189 }
180 for (var decl in map.values) { 190 for (var decl in map.values) {
181 if (!options.includeFields && decl.isField) continue; 191 if (!options.includeFields && decl.isField) continue;
182 if (!options.includeProperties && decl.isProperty) continue; 192 if (!options.includeProperties && decl.isProperty) continue;
183 if (options.excludeFinal && decl.isFinal) continue; 193 if (options.excludeFinal && decl.isFinal) continue;
184 if (!options.includeMethods && decl.isMethod) continue; 194 if (!options.includeMethods && decl.isMethod) continue;
185 if (options.withAnnotations != null && 195 if (options.withAnnotations != null &&
186 !matchesAnnotation(decl.annotations, options.withAnnotations)) { 196 !matchesAnnotation(decl.annotations, options.withAnnotations)) {
187 continue; 197 continue;
(...skipping 23 matching lines...) Expand all
211 221
212 Declaration _findDeclaration(Type type, Symbol name) { 222 Declaration _findDeclaration(Type type, Symbol name) {
213 while (type != Object) { 223 while (type != Object) {
214 final declarations = _configuration.declarations[type]; 224 final declarations = _configuration.declarations[type];
215 if (declarations != null) { 225 if (declarations != null) {
216 final declaration = declarations[name]; 226 final declaration = declarations[name];
217 if (declaration != null) return declaration; 227 if (declaration != null) return declaration;
218 } 228 }
219 var parentType = _configuration.parents[type]; 229 var parentType = _configuration.parents[type];
220 if (parentType == null) { 230 if (parentType == null) {
231 if (!_configuration.checkedMode) return null;
221 throw new MissingCodeException('superclass of "$type"'); 232 throw new MissingCodeException('superclass of "$type"');
222 } 233 }
223 type = parentType; 234 type = parentType;
224 } 235 }
225 return null; 236 return null;
226 } 237 }
OLDNEW
« no previous file with comments | « pkg/smoke/lib/codegen/recorder.dart ('k') | pkg/smoke/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698