blob: c4bfb5fb84d74d3c4efcae25252d9e5386cb0822 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:kernel/ast.dart'
show
Member,
LoadLibrary,
Procedure,
ProcedureKind,
Name,
FunctionNode,
ExpressionStatement,
LibraryDependency;
import 'builder.dart' show Builder, LibraryBuilder;
/// Builder to represent the `deferLibrary.loadLibrary` calls and tear-offs.
class LoadLibraryBuilder extends Builder {
final LibraryBuilder parent;
final LibraryDependency importDependency;
/// Offset of the import prefix.
final int charOffset;
/// Synthetic static method to represent the tear-off of 'loadLibrary'. If
/// null, no tear-offs were seen in the code and no method is generated.
Member tearoff;
LoadLibraryBuilder(this.parent, this.importDependency, this.charOffset)
: super(parent, charOffset, parent.fileUri);
LoadLibrary createLoadLibrary(int charOffset) {
return new LoadLibrary(importDependency)..fileOffset = charOffset;
}
Procedure createTearoffMethod() {
if (tearoff != null) return tearoff;
LoadLibrary expression = createLoadLibrary(charOffset);
String prefix = expression.import.name;
tearoff = new Procedure(
new Name('__loadLibrary_$prefix', parent.target),
ProcedureKind.Method,
new FunctionNode(new ExpressionStatement(expression)),
fileUri: parent.target.fileUri)
..fileOffset = charOffset;
return tearoff;
}
@override
String get fullNameForErrors => 'loadLibrary';
}