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

Unified Diff: pkg/front_end/lib/src/fasta/builder/library_builder.dart

Issue 2697523002: Add accessor for getting target-specific constructor. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/builder/library_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/builder/library_builder.dart b/pkg/front_end/lib/src/fasta/builder/library_builder.dart
index d163b8c5be333ae21ff2de288c5d1b3125ba1ec6..f3932b3be29e07204bec8afaac191b61d360ced9 100644
--- a/pkg/front_end/lib/src/fasta/builder/library_builder.dart
+++ b/pkg/front_end/lib/src/fasta/builder/library_builder.dart
@@ -8,7 +8,8 @@ import '../combinator.dart' show
Combinator;
import '../errors.dart' show
- InputError;
+ InputError,
+ internalError;
import '../export.dart' show
Export;
@@ -71,5 +72,33 @@ abstract class LibraryBuilder<T extends TypeBuilder, R> extends Builder {
int finishStaticInvocations() => 0;
+ /// Looks up [constructorName] in the class named [className]. It's an error
+ /// if no such class is exported by this library, or if the class doesn't
+ /// have a matching constructor (or factory).
+ ///
+ /// If [constructorName] is null or the empty string, it's assumed to be an
+ /// unnamed constructor.
+ Builder getConstructor(String className,
+ {String constructorName, bool isPrivate: false}) {
+ constructorName ??= "";
+ Builder cls = (isPrivate ? members : exports)[className];
+ if (cls is ClassBuilder) {
+ // TODO(ahe): This code is similar to code in `handleNewExpression` in
+ // `body_builder.dart`, try to share it.
+ Builder constructor = cls.findConstructorOrFactory(constructorName);
+ if (constructor == null) {
+ // Fall-through to internal error below.
+ } else if (constructor.isConstructor) {
+ if (!cls.isAbstract) {
+ return constructor;
+ }
+ } else if (constructor.isFactory) {
+ return constructor;
+ }
+ }
+ throw internalError("Internal error: No constructor named"
+ " '$className::$constructorName' in '$uri'.");
+ }
+
int finishTypeVariables(ClassBuilder object) => 0;
}
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698