blob: 717c6bb392bf60641bcfd9d1f6bc6f17e0f95775 [file] [log] [blame]
// Copyright (c) 2015, 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.
part of protoc;
/// Resolves all cross-references in a set of proto files.
void link(GenerationOptions options, Iterable<FileGenerator> files) {
GenerationContext ctx = new GenerationContext(options);
// Register the targets of cross-references.
for (var f in files) {
for (var m in f.messageGenerators) {
for (var e in f.enumGenerators) {
for (var f in files) {
// Resolve service generators last.
// (They depend on all messages being resolved.)
for (var f in files) {
for (var s in f.serviceGenerators) {
for (var s in f.grpcGenerators) {
class GenerationContext {
final GenerationOptions options;
/// The files available for import.
final Map<String, FileGenerator> _files = <String, FileGenerator>{};
/// The types available to proto fields.
final Map<String, ProtobufContainer> _typeRegistry =
<String, ProtobufContainer>{};
/// Makes info about a .pb.dart file available for reference,
/// using the filename given to us by protoc.
void registerProtoFile(FileGenerator f) {
_files[] = f;
/// Makes a message, group, or enum available for reference.
void registerFieldType(ProtobufContainer type) {
// Register the name with a leading '.' to be compatible with input from
// protoc.
_typeRegistry[type.dottedName] = type;
/// Returns info about a .pb.dart being imported,
/// based on the filename given to us by protoc.
FileGenerator getImportedProtoFile(String name) => _files[name];
/// Returns info about the type of a message, group, or enum field,
/// based on the fully qualified name given to us by protoc.
ProtobufContainer getFieldType(String name) => _typeRegistry[name];