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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Issue 2695633002: Annotate native methods. (Closed)
Patch Set: Created 3 years, 10 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.kernel_library_builder; 5 library fasta.kernel_library_builder;
6 6
7 import 'package:kernel/ast.dart'; 7 import 'package:kernel/ast.dart';
8 8
9 import 'package:kernel/clone.dart' show 9 import 'package:kernel/clone.dart' show
10 CloneVisitor; 10 CloneVisitor;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 TypeVariableBuilder; 58 TypeVariableBuilder;
59 59
60 class KernelLibraryBuilder 60 class KernelLibraryBuilder
61 extends SourceLibraryBuilder<KernelTypeBuilder, Library> { 61 extends SourceLibraryBuilder<KernelTypeBuilder, Library> {
62 final Library library; 62 final Library library;
63 63
64 final List<Class> mixinApplicationClasses = <Class>[]; 64 final List<Class> mixinApplicationClasses = <Class>[];
65 65
66 final List<List> argumentsWithMissingDefaultValues = <List>[]; 66 final List<List> argumentsWithMissingDefaultValues = <List>[];
67 67
68 final List<KernelProcedureBuilder> nativeMethods = <KernelProcedureBuilder>[];
69
68 final List<KernelTypeVariableBuilder> boundlessTypeVariables = 70 final List<KernelTypeVariableBuilder> boundlessTypeVariables =
69 <KernelTypeVariableBuilder>[]; 71 <KernelTypeVariableBuilder>[];
70 72
71 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader) 73 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader)
72 : library = new Library(uri, fileUri: relativizeUri(fileUri)), 74 : library = new Library(uri, fileUri: relativizeUri(fileUri)),
73 super(loader, fileUri); 75 super(loader, fileUri);
74 76
75 Uri get uri => library.importUri; 77 Uri get uri => library.importUri;
76 78
77 KernelTypeBuilder addNamedType(String name, 79 KernelTypeBuilder addNamedType(String name,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void addField(List<MetadataBuilder> metadata, 136 void addField(List<MetadataBuilder> metadata,
135 int modifiers, KernelTypeBuilder type, String name, int charOffset) { 137 int modifiers, KernelTypeBuilder type, String name, int charOffset) {
136 addBuilder(name, new KernelFieldBuilder( 138 addBuilder(name, new KernelFieldBuilder(
137 metadata, type, name, modifiers, this, charOffset), charOffset); 139 metadata, type, name, modifiers, this, charOffset), charOffset);
138 } 140 }
139 141
140 void addProcedure(List<MetadataBuilder> metadata, 142 void addProcedure(List<MetadataBuilder> metadata,
141 int modifiers, KernelTypeBuilder returnType, String name, 143 int modifiers, KernelTypeBuilder returnType, String name,
142 List<TypeVariableBuilder> typeVariables, 144 List<TypeVariableBuilder> typeVariables,
143 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier, 145 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier,
144 ProcedureKind kind, int charOffset, {bool isTopLevel}) { 146 ProcedureKind kind, int charOffset, String nativeMethodName,
147 {bool isTopLevel}) {
145 // Nested declaration began in `OutlineBuilder.beginMethod` or 148 // Nested declaration began in `OutlineBuilder.beginMethod` or
146 // `OutlineBuilder.beginTopLevelMethod`. 149 // `OutlineBuilder.beginTopLevelMethod`.
147 endNestedDeclaration().resolveTypes(typeVariables, this); 150 endNestedDeclaration().resolveTypes(typeVariables, this);
148 ProcedureBuilder procedure; 151 ProcedureBuilder procedure;
149 if (!isTopLevel && isConstructorName(name, currentDeclaration.name)) { 152 if (!isTopLevel && isConstructorName(name, currentDeclaration.name)) {
150 int index = name.indexOf("."); 153 int index = name.indexOf(".");
151 name = index == -1 ? "" : name.substring(index + 1); 154 name = index == -1 ? "" : name.substring(index + 1);
152 procedure = new KernelConstructorBuilder(metadata, 155 procedure = new KernelConstructorBuilder(metadata,
153 modifiers & ~abstractMask, returnType, name, typeVariables, formals, 156 modifiers & ~abstractMask, returnType, name, typeVariables, formals,
154 this, charOffset); 157 this, charOffset, nativeMethodName);
155 } else { 158 } else {
156 procedure = new KernelProcedureBuilder(metadata, modifiers, returnType, 159 procedure = new KernelProcedureBuilder(metadata, modifiers, returnType,
157 name, typeVariables, formals, asyncModifier, kind, this, charOffset); 160 name, typeVariables, formals, asyncModifier, kind, this, charOffset,
161 nativeMethodName);
158 } 162 }
159 addBuilder(name, procedure, charOffset); 163 addBuilder(name, procedure, charOffset);
164 if (nativeMethodName != null) {
165 addNativeMethod(procedure);
166 }
160 } 167 }
161 168
162 void addFactoryMethod(List<MetadataBuilder> metadata, 169 void addFactoryMethod(List<MetadataBuilder> metadata,
163 ConstructorReferenceBuilder constructorName, 170 ConstructorReferenceBuilder constructorName,
164 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier, 171 List<FormalParameterBuilder> formals, AsyncMarker asyncModifier,
165 ConstructorReferenceBuilder redirectionTarget, int charOffset) { 172 ConstructorReferenceBuilder redirectionTarget, int charOffset,
173 String nativeMethodName) {
166 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. 174 // Nested declaration began in `OutlineBuilder.beginFactoryMethod`.
167 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration = 175 DeclarationBuilder<KernelTypeBuilder> factoryDeclaration =
168 endNestedDeclaration(); 176 endNestedDeclaration();
169 String name = constructorName.name; 177 String name = constructorName.name;
170 int index = name.indexOf("."); 178 int index = name.indexOf(".");
171 name = index == -1 ? "" : name.substring(index + 1); 179 name = index == -1 ? "" : name.substring(index + 1);
172 assert(constructorName.suffix == null); 180 assert(constructorName.suffix == null);
173 KernelProcedureBuilder procedure = new KernelProcedureBuilder(metadata, 181 KernelProcedureBuilder procedure = new KernelProcedureBuilder(metadata,
174 staticMask, null, name, <TypeVariableBuilder>[], formals, asyncModifier, 182 staticMask, null, name, <TypeVariableBuilder>[], formals, asyncModifier,
175 ProcedureKind.Factory, this, charOffset, redirectionTarget); 183 ProcedureKind.Factory, this, charOffset, nativeMethodName,
184 redirectionTarget);
176 currentDeclaration.addFactoryDeclaration(procedure, factoryDeclaration); 185 currentDeclaration.addFactoryDeclaration(procedure, factoryDeclaration);
177 addBuilder(name, procedure, charOffset); 186 addBuilder(name, procedure, charOffset);
187 if (nativeMethodName != null) {
188 addNativeMethod(procedure);
189 }
178 } 190 }
179 191
180 void addEnum(List<MetadataBuilder> metadata, String name, 192 void addEnum(List<MetadataBuilder> metadata, String name,
181 List<String> constants, int charOffset) { 193 List<String> constants, int charOffset) {
182 addBuilder(name, 194 addBuilder(name,
183 new KernelEnumBuilder(metadata, name, constants, this, charOffset), 195 new KernelEnumBuilder(metadata, name, constants, this, charOffset),
184 charOffset); 196 charOffset);
185 } 197 }
186 198
187 void addFunctionTypeAlias(List<MetadataBuilder> metadata, 199 void addFunctionTypeAlias(List<MetadataBuilder> metadata,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 314 }
303 expression.value = 315 expression.value =
304 defaultArgumentFrom(names[expression.name].initializer) 316 defaultArgumentFrom(names[expression.name].initializer)
305 ..parent = expression; 317 ..parent = expression;
306 } 318 }
307 } 319 }
308 } 320 }
309 return argumentsWithMissingDefaultValues.length; 321 return argumentsWithMissingDefaultValues.length;
310 } 322 }
311 323
324 void addNativeMethod(KernelProcedureBuilder method) {
325 nativeMethods.add(method);
326 }
327
328 int finishNativeMethods() {
329 for (KernelProcedureBuilder method in nativeMethods) {
330 method.becomeNative(loader);
331 }
332 return nativeMethods.length;
333 }
334
312 List<TypeVariableBuilder> copyTypeVariables( 335 List<TypeVariableBuilder> copyTypeVariables(
313 List<TypeVariableBuilder> original) { 336 List<TypeVariableBuilder> original) {
314 List<TypeVariableBuilder> copy = <TypeVariableBuilder>[]; 337 List<TypeVariableBuilder> copy = <TypeVariableBuilder>[];
315 for (KernelTypeVariableBuilder variable in original) { 338 for (KernelTypeVariableBuilder variable in original) {
316 var newVariable = new KernelTypeVariableBuilder( 339 var newVariable = new KernelTypeVariableBuilder(
317 variable.name, this, variable.charOffset); 340 variable.name, this, variable.charOffset);
318 copy.add(newVariable); 341 copy.add(newVariable);
319 boundlessTypeVariables.add(newVariable); 342 boundlessTypeVariables.add(newVariable);
320 } 343 }
321 Map<TypeVariableBuilder, TypeBuilder> substitution = 344 Map<TypeVariableBuilder, TypeBuilder> substitution =
(...skipping 14 matching lines...) Expand all
336 for (KernelTypeVariableBuilder builder in boundlessTypeVariables) { 359 for (KernelTypeVariableBuilder builder in boundlessTypeVariables) {
337 builder.finish(object); 360 builder.finish(object);
338 } 361 }
339 boundlessTypeVariables.clear(); 362 boundlessTypeVariables.clear();
340 return count; 363 return count;
341 } 364 }
342 365
343 @override 366 @override
344 void includePart(KernelLibraryBuilder part) { 367 void includePart(KernelLibraryBuilder part) {
345 super.includePart(part); 368 super.includePart(part);
369 nativeMethods.addAll(part.nativeMethods);
346 boundlessTypeVariables.addAll(part.boundlessTypeVariables); 370 boundlessTypeVariables.addAll(part.boundlessTypeVariables);
347 mixinApplicationClasses.addAll(part.mixinApplicationClasses); 371 mixinApplicationClasses.addAll(part.mixinApplicationClasses);
348 } 372 }
349 } 373 }
350 374
351 bool isConstructorName(String name, String className) { 375 bool isConstructorName(String name, String className) {
352 if (name.startsWith(className)) { 376 if (name.startsWith(className)) {
353 if (name.length == className.length) return true; 377 if (name.length == className.length) return true;
354 if (name.startsWith(".", className.length)) return true; 378 if (name.startsWith(".", className.length)) return true;
355 } 379 }
356 return false; 380 return false;
357 } 381 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_procedure_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698