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

Side by Side Diff: lib/compiler/implementation/universe/universe.dart

Issue 10917285: Stub implementation of patch invariants for the patch refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Leftovers from rebase. Created 8 years, 3 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
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('universe'); 5 #library('universe');
6 6
7 #import('../closure.dart'); 7 #import('../closure.dart');
8 #import('../elements/elements.dart'); 8 #import('../elements/elements.dart');
9 #import('../leg.dart'); 9 #import('../leg.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
11 // For RuntimeTypeInformation. TODO(ngeoffray): remove this dependency. 11 // For RuntimeTypeInformation. TODO(ngeoffray): remove this dependency.
12 #import('../ssa/ssa.dart'); 12 #import('../ssa/ssa.dart');
13 #import('../tree/tree.dart'); 13 #import('../tree/tree.dart');
14 #import('../util/util.dart'); 14 #import('../util/util.dart');
15 15
16 #source('function_set.dart'); 16 #source('function_set.dart');
17 #source('partial_type_tree.dart'); 17 #source('partial_type_tree.dart');
18 #source('selector_map.dart'); 18 #source('selector_map.dart');
19 19
20 class Universe { 20 class Universe {
21 /// Invariant: Key elements are declaration elements.
21 Map<Element, CodeBuffer> generatedCode; 22 Map<Element, CodeBuffer> generatedCode;
23 /// Invariant: Key elements are declaration elements.
22 Map<Element, CodeBuffer> generatedBailoutCode; 24 Map<Element, CodeBuffer> generatedBailoutCode;
25 /// Invariant: Elements are declaration elements.
23 final Set<ClassElement> instantiatedClasses; 26 final Set<ClassElement> instantiatedClasses;
27 /// Invariant: Elements are declaration elements.
24 final Set<FunctionElement> staticFunctionsNeedingGetter; 28 final Set<FunctionElement> staticFunctionsNeedingGetter;
25 final Map<SourceString, Set<Selector>> invokedNames; 29 final Map<SourceString, Set<Selector>> invokedNames;
26 final Map<SourceString, Set<Selector>> invokedGetters; 30 final Map<SourceString, Set<Selector>> invokedGetters;
27 final Map<SourceString, Set<Selector>> invokedSetters; 31 final Map<SourceString, Set<Selector>> invokedSetters;
28 final Map<SourceString, Set<Selector>> fieldGetters; 32 final Map<SourceString, Set<Selector>> fieldGetters;
29 final Map<SourceString, Set<Selector>> fieldSetters; 33 final Map<SourceString, Set<Selector>> fieldSetters;
30 final Set<DartType> isChecks; 34 final Set<DartType> isChecks;
31 // TODO(karlklose): move this data to RuntimeTypeInformation. 35 // TODO(karlklose): move this data to RuntimeTypeInformation.
36 // Invariant: Elements are declarations.
32 Set<Element> checkedClasses; 37 Set<Element> checkedClasses;
33 final RuntimeTypeInformation rti; 38 final RuntimeTypeInformation rti;
34 39
35 Universe() : generatedCode = new Map<Element, CodeBuffer>(), 40 Universe() : generatedCode = new Map<Element, CodeBuffer>(),
36 generatedBailoutCode = new Map<Element, CodeBuffer>(), 41 generatedBailoutCode = new Map<Element, CodeBuffer>(),
37 instantiatedClasses = new Set<ClassElement>(), 42 instantiatedClasses = new Set<ClassElement>(),
38 staticFunctionsNeedingGetter = new Set<FunctionElement>(), 43 staticFunctionsNeedingGetter = new Set<FunctionElement>(),
39 invokedNames = new Map<SourceString, Set<Selector>>(), 44 invokedNames = new Map<SourceString, Set<Selector>>(),
40 invokedGetters = new Map<SourceString, Set<Selector>>(), 45 invokedGetters = new Map<SourceString, Set<Selector>>(),
41 invokedSetters = new Map<SourceString, Set<Selector>>(), 46 invokedSetters = new Map<SourceString, Set<Selector>>(),
42 fieldGetters = new Map<SourceString, Set<Selector>>(), 47 fieldGetters = new Map<SourceString, Set<Selector>>(),
43 fieldSetters = new Map<SourceString, Set<Selector>>(), 48 fieldSetters = new Map<SourceString, Set<Selector>>(),
44 isChecks = new Set<DartType>(), 49 isChecks = new Set<DartType>(),
45 rti = new RuntimeTypeInformation(); 50 rti = new RuntimeTypeInformation();
46 51
47 // TODO(karlklose): add the set of instantiatedtypes as second argument. 52 // TODO(karlklose): add the set of instantiatedtypes as second argument.
48 void computeRequiredTypes(Set<DartType> isChecks) { 53 void computeRequiredTypes(Set<DartType> isChecks) {
49 assert(checkedClasses == null); 54 assert(checkedClasses == null);
50 checkedClasses = new Set<Element>(); 55 checkedClasses = new Set<Element>();
51 isChecks.forEach((DartType t) => checkedClasses.add(t.element)); 56 isChecks.forEach((DartType t) => checkedClasses.add(t.element));
52 } 57 }
53 58
54 void addGeneratedCode(WorkItem work, CodeBuffer codeBuffer) { 59 void addGeneratedCode(WorkItem work, CodeBuffer codeBuffer) {
60 assert(work.element.isDeclaration);
55 generatedCode[work.element] = codeBuffer; 61 generatedCode[work.element] = codeBuffer;
56 } 62 }
57 63
58 void addBailoutCode(WorkItem work, CodeBuffer codeBuffer) { 64 void addBailoutCode(WorkItem work, CodeBuffer codeBuffer) {
65 assert(work.element.isDeclaration);
59 generatedBailoutCode[work.element] = codeBuffer; 66 generatedBailoutCode[work.element] = codeBuffer;
60 } 67 }
61 68
62 bool hasMatchingSelector(Set<Selector> selectors, 69 bool hasMatchingSelector(Set<Selector> selectors,
63 Element member, 70 Element member,
64 Compiler compiler) { 71 Compiler compiler) {
65 if (selectors === null) return false; 72 if (selectors === null) return false;
66 for (Selector selector in selectors) { 73 for (Selector selector in selectors) {
67 if (selector.applies(member, compiler)) return true; 74 if (selector.applies(member, compiler)) return true;
68 } 75 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 293 }
287 294
288 // TODO(5074): Remove this method once we don't accept the 295 // TODO(5074): Remove this method once we don't accept the
289 // deprecated parameter specification. 296 // deprecated parameter specification.
290 bool addOptionalArgumentsToListDEPRECATED(Link<Node> arguments, 297 bool addOptionalArgumentsToListDEPRECATED(Link<Node> arguments,
291 List list, 298 List list,
292 FunctionElement element, 299 FunctionElement element,
293 compileArgument(Node argument), 300 compileArgument(Node argument),
294 compileConstant(Element element), 301 compileConstant(Element element),
295 Compiler compiler) { 302 Compiler compiler) {
303 assert(element.isImplementation);
ngeoffray 2012/09/17 12:46:24 No sure you need this restriction.
Johnni Winther 2012/09/20 08:12:23 The only call-site enforces the invariant so I'll
296 // If there are named arguments, provide them in the order 304 // If there are named arguments, provide them in the order
297 // expected by the called function, which is the source order. 305 // expected by the called function, which is the source order.
298 FunctionSignature parameters = element.computeSignature(compiler); 306 FunctionSignature parameters = element.computeSignature(compiler);
299 307
300 // Visit positional arguments and add them to the list. 308 // Visit positional arguments and add them to the list.
301 for (int i = parameters.requiredParameterCount; 309 for (int i = parameters.requiredParameterCount;
302 i < positionalArgumentCount; 310 i < positionalArgumentCount;
303 arguments = arguments.tail, i++) { 311 arguments = arguments.tail, i++) {
304 list.add(compileArgument(arguments.head)); 312 list.add(compileArgument(arguments.head));
305 } 313 }
(...skipping 27 matching lines...) Expand all
333 } else { 341 } else {
334 list.add(compileConstant(parameter)); 342 list.add(compileConstant(parameter));
335 } 343 }
336 } 344 }
337 } 345 }
338 346
339 347
340 /** 348 /**
341 * Returns [:true:] if the selector and the [element] match; [:false:] 349 * Returns [:true:] if the selector and the [element] match; [:false:]
342 * otherwise. 350 * otherwise.
351 *
352 * Invariant: [element] must be the implementation element.
343 */ 353 */
344 bool addArgumentsToList(Link<Node> arguments, 354 bool addArgumentsToList(Link<Node> arguments,
345 List list, 355 List list,
346 FunctionElement element, 356 FunctionElement element,
347 compileArgument(Node argument), 357 compileArgument(Node argument),
348 compileConstant(Element element), 358 compileConstant(Element element),
349 Compiler compiler) { 359 Compiler compiler) {
360 assert(element.isImplementation);
ngeoffray 2012/09/17 12:46:24 ditto
Johnni Winther 2012/09/20 08:12:23 The call-sites enforces the invariant so I'll keep
350 if (!this.applies(element, compiler)) return false; 361 if (!this.applies(element, compiler)) return false;
351 362
352 FunctionSignature parameters = element.computeSignature(compiler); 363 FunctionSignature parameters = element.computeSignature(compiler);
353 parameters.forEachRequiredParameter((element) { 364 parameters.forEachRequiredParameter((element) {
354 list.add(compileArgument(arguments.head)); 365 list.add(compileArgument(arguments.head));
355 arguments = arguments.tail; 366 arguments = arguments.tail;
356 }); 367 });
357 368
358 if (!parameters.optionalParametersAreNamed) { 369 if (!parameters.optionalParametersAreNamed) {
359 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) { 370 if (!Compiler.REJECT_NAMED_ARGUMENT_AS_POSITIONAL) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 513
503 if (!self.isInterface() && self.isSubclassOf(other)) { 514 if (!self.isInterface() && self.isSubclassOf(other)) {
504 // Resolve an invocation of [element.name] on [self]. If it 515 // Resolve an invocation of [element.name] on [self]. If it
505 // is found, this selector is a candidate. 516 // is found, this selector is a candidate.
506 return hasElementIn(self, element) && appliesUntyped(element, compiler); 517 return hasElementIn(self, element) && appliesUntyped(element, compiler);
507 } 518 }
508 519
509 return false; 520 return false;
510 } 521 }
511 } 522 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698