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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_test.dart

Issue 1576663002: Use FlatBuffers for summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.summary.summary_test; 5 library analyzer.test.src.summary.summary_test;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 /** 93 /**
94 * Serialize the given [library] element, then deserialize it and store the 94 * Serialize the given [library] element, then deserialize it and store the
95 * resulting summary in [prelinked] and [unlinkedUnits]. 95 * resulting summary in [prelinked] and [unlinkedUnits].
96 */ 96 */
97 void serializeLibraryElement(LibraryElement library) { 97 void serializeLibraryElement(LibraryElement library) {
98 summarize_elements.LibrarySerializationResult serializedLib = 98 summarize_elements.LibrarySerializationResult serializedLib =
99 summarize_elements.serializeLibrary( 99 summarize_elements.serializeLibrary(
100 builderContext, library, typeProvider); 100 builderContext, library, typeProvider);
101 prelinked = 101 {
102 new PrelinkedLibrary.fromBuffer(serializedLib.prelinked.toBuffer()); 102 List<int> buffer = serializedLib.prelinked.toBuffer();
103 unlinkedUnits = serializedLib.unlinkedUnits 103 prelinked = new PrelinkedLibrary.fromBuffer(buffer);
104 .map((UnlinkedUnitBuilder b) => 104 }
105 new UnlinkedUnit.fromBuffer(b.toBuffer())) 105 unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) {
106 .toList(); 106 List<int> buffer = b.toBuffer();
107 return new UnlinkedUnit.fromBuffer(buffer);
108 }).toList();
107 unitUris = serializedLib.unitUris; 109 unitUris = serializedLib.unitUris;
108 } 110 }
109 111
110 @override 112 @override
111 void serializeLibraryText(String text, {bool allowErrors: false}) { 113 void serializeLibraryText(String text, {bool allowErrors: false}) {
112 Source source = addSource(text); 114 Source source = addSource(text);
113 LibraryElement library = resolve2(source); 115 LibraryElement library = resolve2(source);
114 if (!allowErrors) { 116 if (!allowErrors) {
115 assertNoErrors(source); 117 assertNoErrors(source);
116 } 118 }
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 590
589 /** 591 /**
590 * Serialize a type declaration using the given [text] as a type name, and 592 * Serialize a type declaration using the given [text] as a type name, and
591 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 593 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
592 * declaration needs to refer to types that are not available in core, those 594 * declaration needs to refer to types that are not available in core, those
593 * types may be declared in [otherDeclarations]. 595 * types may be declared in [otherDeclarations].
594 */ 596 */
595 UnlinkedTypeRef serializeTypeText(String text, 597 UnlinkedTypeRef serializeTypeText(String text,
596 {String otherDeclarations: '', bool allowErrors: false}) { 598 {String otherDeclarations: '', bool allowErrors: false}) {
597 return serializeVariableText('$otherDeclarations\n$text v;', 599 return serializeVariableText('$otherDeclarations\n$text v;',
598 allowErrors: allowErrors).type; 600 allowErrors: allowErrors)
601 .type;
599 } 602 }
600 603
601 /** 604 /**
602 * Serialize the given library [text] and return the summary of the variable 605 * Serialize the given library [text] and return the summary of the variable
603 * with the given [variableName]. 606 * with the given [variableName].
604 */ 607 */
605 UnlinkedVariable serializeVariableText(String text, 608 UnlinkedVariable serializeVariableText(String text,
606 {String variableName: 'v', bool allowErrors: false}) { 609 {String variableName: 'v', bool allowErrors: false}) {
607 serializeLibraryText(text, allowErrors: allowErrors); 610 serializeLibraryText(text, allowErrors: allowErrors);
608 return findVariable(variableName, failIfAbsent: true); 611 return findVariable(variableName, failIfAbsent: true);
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 expect(executable.isConst, false); 1618 expect(executable.isConst, false);
1616 expect(executable.isFactory, false); 1619 expect(executable.isFactory, false);
1617 expect(executable.isStatic, false); 1620 expect(executable.isStatic, false);
1618 expect(executable.parameters, hasLength(1)); 1621 expect(executable.parameters, hasLength(1));
1619 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 1622 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1620 expect(executable.typeParameters, isEmpty); 1623 expect(executable.typeParameters, isEmpty);
1621 } 1624 }
1622 1625
1623 test_executable_operator_index_set() { 1626 test_executable_operator_index_set() {
1624 UnlinkedExecutable executable = serializeClassText( 1627 UnlinkedExecutable executable = serializeClassText(
1625 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; 1628 'class C { void operator[]=(int i, bool v) => null; }')
1629 .executables[0];
1626 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1630 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1627 expect(executable.name, '[]='); 1631 expect(executable.name, '[]=');
1628 expect(executable.hasImplicitReturnType, false); 1632 expect(executable.hasImplicitReturnType, false);
1629 expect(executable.isAbstract, false); 1633 expect(executable.isAbstract, false);
1630 expect(executable.isConst, false); 1634 expect(executable.isConst, false);
1631 expect(executable.isFactory, false); 1635 expect(executable.isFactory, false);
1632 expect(executable.isStatic, false); 1636 expect(executable.isStatic, false);
1633 expect(executable.parameters, hasLength(2)); 1637 expect(executable.parameters, hasLength(2));
1634 expect(executable.returnType, isNull); 1638 expect(executable.returnType, isNull);
1635 expect(executable.typeParameters, isEmpty); 1639 expect(executable.typeParameters, isEmpty);
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
2653 UnlinkedVariable variable = 2657 UnlinkedVariable variable =
2654 serializeVariableText('int i;', variableName: 'i'); 2658 serializeVariableText('int i;', variableName: 'i');
2655 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2659 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2656 } 2660 }
2657 2661
2658 test_varible_private() { 2662 test_varible_private() {
2659 serializeVariableText('int _i;', variableName: '_i'); 2663 serializeVariableText('int _i;', variableName: '_i');
2660 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2664 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2661 } 2665 }
2662 } 2666 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698