~fsx/protobluff

fc92d42990c4e96e767101ceee744e20073e27b8 — Frank Smit 11 months ago f49d39f
Match for-loop variable type with return type of function used in condition.
M src/generator/enum.cc => src/generator/enum.cc +11 -6
@@ 62,13 62,15 @@ namespace protobluff {

    /* Sort enum value generators by number */
    vector<EnumValue *> sorted;
    for (size_t v = 0; v < descriptor_->value_count(); v++)
    for (int v = 0; v < descriptor_->value_count(); v++) {
      sorted.push_back(new EnumValue(descriptor_->value(v)));
    }
    sort(sorted.begin(), sorted.end(), EnumValueComparator);

    /* Initialize enum value generators */
    for (size_t v = 0; v < descriptor_->value_count(); v++)
    for (int v = 0; v < descriptor_->value_count(); v++) {
      values_[v].reset(sorted[v]);
    }

    /* Extract full name for signature */
    variables_["signature"] = descriptor_->full_name();


@@ 89,8 91,9 @@ namespace protobluff {
    assert(printer);
    printer->Print(variables_,
      "/* `signature` : values */\n");
    for (size_t v = 0; v < descriptor_->value_count(); v++)
    for (int v = 0; v < descriptor_->value_count(); v++) {
      values_[v]->GenerateValue(printer);
    }
    printer->Print("\n");
  }



@@ 129,16 132,18 @@ namespace protobluff {
        "  (const pb_enum_value_descriptor_t []){\n");

      /* Generate enum value descriptors */
      for (size_t i = 0; i < 2; i++)
      for (size_t i = 0; i < 2; i++) {
        printer->Indent();
      for (size_t v = 0; v < descriptor_->value_count(); v++) {
      }
      for (int v = 0; v < descriptor_->value_count(); v++) {
        values_[v]->GenerateDescriptor(printer);
        if (v < descriptor_->value_count() - 1)
          printer->Print(",");
        printer->Print("\n");
      }
      for (size_t i = 0; i < 2; i++)
      for (size_t i = 0; i < 2; i++) {
        printer->Outdent();
      }

      /* Generate descriptor footer */
      printer->Print(

M src/generator/field.cc => src/generator/field.cc +3 -3
@@ 389,7 389,7 @@ namespace protobluff {
    /* Generate encoder for enum fields */
    if (descriptor_->enum_type()) {
      const EnumDescriptor *descriptor = descriptor_->enum_type();
      for (size_t v = 0; v < descriptor->value_count(); v++) {
      for (int v = 0; v < descriptor->value_count(); v++) {
        const EnumValueDescriptor *value = descriptor->value(v);
        map<string, string> variables (variables_);



@@ 523,7 523,7 @@ namespace protobluff {
      /* Generate accessors for enum fields */
      if (descriptor_->enum_type()) {
        const EnumDescriptor *descriptor = descriptor_->enum_type();
        for (size_t v = 0; v < descriptor->value_count(); v++) {
        for (int v = 0; v < descriptor->value_count(); v++) {
          const EnumValueDescriptor *value = descriptor->value(v);
          map<string, string> variables (variables_);



@@ 723,7 723,7 @@ namespace protobluff {
      /* Generate accessors for enum fields */
      if (descriptor_->enum_type()) {
        const EnumDescriptor *descriptor = descriptor_->enum_type();
        for (size_t v = 0; v < descriptor->value_count(); v++) {
        for (int v = 0; v < descriptor->value_count(); v++) {
          const EnumValueDescriptor *value = descriptor->value(v);
          map<string, string> enum_variables (variables);


M src/generator/file.cc => src/generator/file.cc +87 -49
@@ 74,25 74,30 @@ namespace protobluff {
      messages_(new unique_ptr<Message>[descriptor_->message_type_count()]) {

    /* Initialize enum generators */
    for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
    for (int e = 0; e < descriptor_->enum_type_count(); e++) {
      enums_[e].reset(new Enum(descriptor_->enum_type(e)));
    }

    /* Initialize message generators */
    for (size_t m = 0; m < descriptor_->message_type_count(); m++)
    for (int m = 0; m < descriptor_->message_type_count(); m++) {
      messages_[m].reset(new Message(descriptor_->message_type(m)));
    }

    /* Build set of unique extended descriptors */
    set<const Descriptor *> unique;
    for (size_t e = 0; e < descriptor_->extension_count(); e++)
    for (int e = 0; e < descriptor_->extension_count(); e++) {
      unique.insert(descriptor_->extension(e)->containing_type());
    }

    /* Initialize extension generators */
    for (set<const Descriptor *>::iterator it  = unique.begin();
                                           it != unique.end(); ++it) {
      Extension *extension = new Extension(*it);
      for (size_t e = 0; e < descriptor_->extension_count(); e++)
        if (descriptor_->extension(e)->containing_type() == *it)
      for (int e = 0; e < descriptor_->extension_count(); e++) {
        if (descriptor_->extension(e)->containing_type() == *it) {
          extension->AddField(descriptor_->extension(e));
        }
      }

      /* Add to list of extension generators */
      extensions_.push_back(extension);


@@ 150,7 155,7 @@ namespace protobluff {
    /* Generate dependent includes */
    if (descriptor_->dependency_count()) {
      bool includes = false;
      for (size_t d = 0; d < descriptor_->dependency_count(); d++) {
      for (int d = 0; d < descriptor_->dependency_count(); d++) {
        string dependency = descriptor_->dependency(d)->name();
        printer->Print("#include \"`dependency`.pb.h\"\n", "dependency",
          StripSuffixString(dependency, ".proto"));


@@ 165,14 170,16 @@ namespace protobluff {
      PrintBanner(printer, "Enum values");

      /* Generate values for enums */
      for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
      for (int e = 0; e < descriptor_->enum_type_count(); e++) {
        enums_[e]->GenerateValues(printer);
      }

      /* Generate values for nested enums */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Enum *> enums = messages_[m]->GetEnums();
        for (size_t e = 0; e < enums.size(); e++)
        for (size_t e = 0; e < enums.size(); e++) {
          enums[e]->GenerateValues(printer);
        }
      }
    }



@@ 181,14 188,16 @@ namespace protobluff {
      PrintBanner(printer, "Enum descriptors");

      /* Generate descriptors for enums */
      for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
      for (int e = 0; e < descriptor_->enum_type_count(); e++) {
        enums_[e]->GenerateDeclaration(printer);
      }

      /* Generate descriptors for nested enums */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Enum *> enums = messages_[m]->GetEnums();
        for (size_t e = 0; e < enums.size(); e++)
        for (size_t e = 0; e < enums.size(); e++) {
          enums[e]->GenerateDeclaration(printer);
        }
      }
    }



@@ 197,10 206,11 @@ namespace protobluff {
      PrintBanner(printer, "Oneof descriptors");

      /* Generate descriptors for oneofs */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Oneof *> oneofs = messages_[m]->GetOneofs();
        for (size_t o = 0; o < oneofs.size(); o++)
        for (size_t o = 0; o < oneofs.size(); o++) {
          oneofs[o]->GenerateDeclaration(printer);
        }
      }
    }



@@ 209,29 219,33 @@ namespace protobluff {
      PrintBanner(printer, "Tags");

      /* Generate tags for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateTags(printer);
      }

      /* Generate descriptors for messages */
      PrintBanner(printer, "Descriptors");

      /* Generate descriptors for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateDeclaration(printer);
      }

      /* Generate decoder banner */
      PrintBanner(printer, "Decoders");

      /* Generate decoders for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateDecoder(printer);
      }

      /* Generate encoder banner */
      PrintBanner(printer, "Encoders");

      /* Generate encoders for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateEncoder(printer);
      }
    }

    /* Don't generate accessor code for lite runtime */


@@ 242,8 256,9 @@ namespace protobluff {
        PrintBanner(printer, "Accessors");

        /* Generate accessors for messages and nested messages */
        for (size_t m = 0; m < descriptor_->message_type_count(); m++)
        for (int m = 0; m < descriptor_->message_type_count(); m++) {
          messages_[m]->GenerateAccessors(printer);
        }
      }

      /* Generate accessors for oneofs */


@@ 251,10 266,11 @@ namespace protobluff {
        PrintBanner(printer, "Oneof accessors");

        /* Generate accessors for oneofs */
        for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
        for (int m = 0; m < descriptor_->message_type_count(); m++) {
          const vector<const Oneof *> oneofs = messages_[m]->GetOneofs();
          for (size_t o = 0; o < oneofs.size(); o++)
          for (size_t o = 0; o < oneofs.size(); o++) {
            oneofs[o]->GenerateAccessors(printer);
          }
        }
      }



@@ 263,15 279,17 @@ namespace protobluff {
        PrintBanner(printer, "Extension accessors");

        /* Generate accessors for extensions */
        for (size_t e = 0; e < extensions_.size(); e++)
        for (size_t e = 0; e < extensions_.size(); e++) {
          extensions_[e]->GenerateAccessors(printer);
        }

        /* Generate accessors for nested extensions */
        for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
        for (int m = 0; m < descriptor_->message_type_count(); m++) {
          const vector<const Extension *> extensions =
            messages_[m]->GetExtensions();
          for (size_t e = 0; e < extensions.size(); e++)
          for (size_t e = 0; e < extensions.size(); e++) {
            extensions[e]->GenerateAccessors(printer);
          }
        }
      }
    }


@@ 308,19 326,22 @@ namespace protobluff {
      PrintBanner(printer, "Defaults");

      /* Generate default values for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateDefaults(printer);
      }

      /* Generate default values for extensions */
      for (size_t e = 0; e < extensions_.size(); e++)
      for (size_t e = 0; e < extensions_.size(); e++) {
        extensions_[e]->GenerateDefaults(printer);
      }

      /* Generate default values for nested extensions */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Extension *> extensions =
          messages_[m]->GetExtensions();
        for (size_t e = 0; e < extensions.size(); e++)
        for (size_t e = 0; e < extensions.size(); e++) {
          extensions[e]->GenerateDefaults(printer);
        }
      }
    }



@@ 329,14 350,16 @@ namespace protobluff {
      PrintBanner(printer, "Enum descriptors");

      /* Generate descriptors for enums */
      for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
      for (int e = 0; e < descriptor_->enum_type_count(); e++) {
        enums_[e]->GenerateDescriptor(printer);
      }

      /* Generate descriptors for nested enums */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Enum *> enums = messages_[m]->GetEnums();
        for (size_t e = 0; e < enums.size(); e++)
        for (size_t e = 0; e < enums.size(); e++) {
          enums[e]->GenerateDescriptor(printer);
        }
      }
    }



@@ 345,10 368,11 @@ namespace protobluff {
      PrintBanner(printer, "Oneof descriptors");

      /* Generate descriptors for oneofs */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Oneof *> oneofs = messages_[m]->GetOneofs();
        for (size_t o = 0; o < oneofs.size(); o++)
        for (size_t o = 0; o < oneofs.size(); o++) {
          oneofs[o]->GenerateDescriptor(printer);
        }
      }
    }



@@ 357,8 381,9 @@ namespace protobluff {
      PrintBanner(printer, "Descriptors");

      /* Generate descriptors for messages and nested messages */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        messages_[m]->GenerateDescriptor(printer);
      }
    }

    /* Generate descriptors and initializers for extensions */


@@ 370,26 395,29 @@ namespace protobluff {
        extensions_[e]->GenerateDescriptor(printer);

      /* Generate descriptors for nested extensions */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Extension *> extensions =
          messages_[m]->GetExtensions();
        for (size_t e = 0; e < extensions.size(); e++)
        for (size_t e = 0; e < extensions.size(); e++) {
          extensions[e]->GenerateDescriptor(printer);
        }
      }

      /* Generate initializer banner */
      PrintBanner(printer, "Extension initializers");

      /* Generate initializer for extensions */
      for (size_t e = 0; e < extensions_.size(); e++)
      for (size_t e = 0; e < extensions_.size(); e++) {
        extensions_[e]->GenerateInitializer(printer);
      }

      /* Generate initializer for nested extensions */
      for (size_t m = 0; m < descriptor_->message_type_count(); m++) {
      for (int m = 0; m < descriptor_->message_type_count(); m++) {
        const vector<const Extension *> extensions =
          messages_[m]->GetExtensions();
        for (size_t e = 0; e < extensions.size(); e++)
        for (size_t e = 0; e < extensions.size(); e++) {
          extensions[e]->GenerateInitializer(printer);
        }
      }
    }
  }


@@ 401,14 429,18 @@ namespace protobluff {
   */
  bool File::
  HasDefaults() const {
    for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      if (messages_[m]->HasDefaults())
    for (int m = 0; m < descriptor_->message_type_count(); m++) {
      if (messages_[m]->HasDefaults()) {
        return true;
      }
    }

    /* Check extensions for default values */
    for (size_t e = 0; e < extensions_.size(); e++)
      if (extensions_[e]->HasDefaults())
    for (size_t e = 0; e < extensions_.size(); e++) {
      if (extensions_[e]->HasDefaults()) {
        return true;
      }
    }

    /* No default values */
    return false;


@@ 425,9 457,11 @@ namespace protobluff {
      return true;

    /* Check messages for enums */
    for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      if (messages_[m]->HasEnums())
    for (int m = 0; m < descriptor_->message_type_count(); m++) {
      if (messages_[m]->HasEnums()) {
        return true;
      }
    }

    /* No enums */
    return false;


@@ 440,9 474,11 @@ namespace protobluff {
   */
  bool File::
  HasOneofs() const {
    for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      if (messages_[m]->HasOneofs())
    for (int m = 0; m < descriptor_->message_type_count(); m++) {
      if (messages_[m]->HasOneofs()) {
        return true;
      }
    }

    /* No oneofs */
    return false;


@@ 459,9 495,11 @@ namespace protobluff {
      return true;

    /* Check messages for extensions */
    for (size_t m = 0; m < descriptor_->message_type_count(); m++)
      if (messages_[m]->HasExtensions())
    for (int m = 0; m < descriptor_->message_type_count(); m++) {
      if (messages_[m]->HasExtensions()) {
        return true;
      }
    }

    /* No extensions */
    return false;

M src/generator/message.cc => src/generator/message.cc +78 -42
@@ 70,38 70,46 @@ namespace protobluff {

    /* Sort field generators by tag */
    vector<Field *> sorted;
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      sorted.push_back(new Field(descriptor_->field(f)));
    }
    sort(sorted.begin(), sorted.end(), FieldComparator);

    /* Initialize field generators */
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f].reset(sorted[f]);
    }

    /* Initialize enum generators */
    for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
    enums_[e].reset(new Enum(descriptor_->enum_type(e)));
    for (int e = 0; e < descriptor_->enum_type_count(); e++) {
      enums_[e].reset(new Enum(descriptor_->enum_type(e)));
    }

    /* Initialize oneof generators */
    for (size_t o = 0; o < descriptor_->oneof_decl_count(); o++)
    oneofs_[o].reset(new Oneof(descriptor_->oneof_decl(o)));
    for (int o = 0; o < descriptor_->oneof_decl_count(); o++) {
      oneofs_[o].reset(new Oneof(descriptor_->oneof_decl(o)));
    }

    /* Initialize nested message generators */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n].reset(new Message(descriptor_->nested_type(n)));
    }

    /* Build set of unique extended descriptors */
    set<const Descriptor *> unique;
    for (size_t e = 0; e < descriptor_->extension_count(); e++)
    for (int e = 0; e < descriptor_->extension_count(); e++) {
      unique.insert(descriptor_->extension(e)->containing_type());
    }

    /* Initialize extension generators */
    for (set<const Descriptor *>::iterator it  = unique.begin();
                                           it != unique.end(); ++it) {
      Extension *extension = new Extension(*it, descriptor_);
      for (size_t e = 0; e < descriptor_->extension_count(); e++)
        if (descriptor_->extension(e)->containing_type() == *it)
      for (int e = 0; e < descriptor_->extension_count(); e++) {
        if (descriptor_->extension(e)->containing_type() == *it) {
          extension->AddField(descriptor_->extension(e));
        }
      }

      /* Add to list of extension generators */
      extensions_.push_back(extension);


@@ 131,13 139,15 @@ namespace protobluff {
    assert(printer);
    printer->Print(variables_,
      "/* `signature` : tags */\n");
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f]->GenerateTag(printer);
    }
    printer->Print("\n");

    /* Generate tags for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateTags(printer);
    }
  }

  /*!


@@ 148,13 158,16 @@ namespace protobluff {
  void Message::
  GenerateDefaults(Printer *printer) const {
    assert(printer);
    for (size_t f = 0; f < descriptor_->field_count(); f++)
      if (fields_[f]->HasDefault())
    for (int f = 0; f < descriptor_->field_count(); f++) {
      if (fields_[f]->HasDefault()) {
        fields_[f]->GenerateDefault(printer);
      }
    }

    /* Generate default values for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateDefaults(printer);
    }
  }

  /*!


@@ 174,8 187,9 @@ namespace protobluff {
      "\n");

    /* Generate forward declarations for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateDeclaration(printer);
    }
  }

  /*!


@@ 196,16 210,19 @@ namespace protobluff {
        "  (const pb_field_descriptor_t []){\n");

      /* Generate field descriptors */
      for (size_t i = 0; i < 2; i++)
      for (size_t i = 0; i < 2; i++) {
        printer->Indent();
      for (size_t f = 0; f < descriptor_->field_count(); f++) {
      }
      for (int f = 0; f < descriptor_->field_count(); f++) {
        fields_[f]->GenerateDescriptor(printer);
        if (f < descriptor_->field_count() - 1)
        if (f < descriptor_->field_count() - 1) {
          printer->Print(",");
        }
        printer->Print("\n");
      }
      for (size_t i = 0; i < 2; i++)
      for (size_t i = 0; i < 2; i++) {
        printer->Outdent();
      }

      /* Generate descriptor footer */
      printer->Print(


@@ 223,8 240,9 @@ namespace protobluff {
    }

    /* Generate descriptors for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateDescriptor(printer);
    }
  }

  /*!


@@ 277,8 295,9 @@ namespace protobluff {
      "\n");

    /* Generate decoders for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateDecoder(printer);
    }
  }

  /*!


@@ 329,12 348,14 @@ namespace protobluff {
      "\n");

    /* Generate encoders for fields */
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f]->GenerateEncoder(printer);
    }

    /* Generate encoders for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateEncoder(printer);
    }
  }

  /*!


@@ 373,12 394,14 @@ namespace protobluff {
      "\n");

    /* Generate accessors for fields */
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f]->GenerateAccessors(printer);
    }

    /* Generate accessors for nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      nested_[n]->GenerateAccessors(printer);
    }
  }

  /*!


@@ 394,8 417,9 @@ namespace protobluff {
  GenerateAccessors(
      Printer *printer, vector<const FieldDescriptor *> &trace) const {
    assert(printer);
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f]->GenerateAccessors(printer, trace);
    }
  }

  /*!


@@ 405,14 429,18 @@ namespace protobluff {
   */
  bool Message::
  HasDefaults() const {
    for (size_t f = 0; f < descriptor_->field_count(); f++)
      if (fields_[f]->HasDefault())
    for (int f = 0; f < descriptor_->field_count(); f++) {
      if (fields_[f]->HasDefault()) {
        return true;
      }
    }

    /* Check nested messages for default values */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
      if (nested_[n]->HasDefaults())
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      if (nested_[n]->HasDefaults()) {
        return true;
      }
    }

    /* No default values */
    return false;


@@ 429,9 457,11 @@ namespace protobluff {
      return true;

    /* Check nested messages for enums */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
      if (nested_[n]->HasEnums())
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      if (nested_[n]->HasEnums()) {
        return true;
      }
    }

    /* No enums */
    return false;


@@ 448,9 478,11 @@ namespace protobluff {
      return true;

    /* Check nested messages for oneofs */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
      if (nested_[n]->HasOneofs())
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      if (nested_[n]->HasOneofs()) {
        return true;
      }
    }

    /* No oneofs */
    return false;


@@ 467,9 499,11 @@ namespace protobluff {
      return true;

    /* Check nested messages for extensions */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++)
      if (nested_[n]->HasExtensions())
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      if (nested_[n]->HasExtensions()) {
        return true;
      }
    }

    /* No extensions */
    return false;


@@ 483,11 517,12 @@ namespace protobluff {
  const vector<const Enum *> Message::
  GetEnums() const {
    vector<const Enum *> enums;
    for (size_t e = 0; e < descriptor_->enum_type_count(); e++)
    for (int e = 0; e < descriptor_->enum_type_count(); e++) {
      enums.push_back(enums_[e].get());
    }

    /* Retrieve extensions from nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++) {
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      vector<const Enum *> nested = nested_[n]->GetEnums();
      enums.insert(enums.end(), nested.begin(), nested.end());
    }


@@ 502,11 537,12 @@ namespace protobluff {
  const vector<const Oneof *> Message::
  GetOneofs() const {
    vector<const Oneof *> oneofs;
    for (size_t o = 0; o < descriptor_->oneof_decl_count(); o++)
    for (int o = 0; o < descriptor_->oneof_decl_count(); o++) {
      oneofs.push_back(oneofs_[o].get());
    }

    /* Retrieve oneofs from nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++) {
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      vector<const Oneof *> nested = nested_[n]->GetOneofs();
      oneofs.insert(oneofs.end(), nested.begin(), nested.end());
    }


@@ 525,7 561,7 @@ namespace protobluff {
      extensions_.begin(), extensions_.end());

    /* Retrieve extensions from nested messages */
    for (size_t n = 0; n < descriptor_->nested_type_count(); n++) {
    for (int n = 0; n < descriptor_->nested_type_count(); n++) {
      vector<const Extension *> nested = nested_[n]->GetExtensions();
      extensions.insert(extensions.end(), nested.begin(), nested.end());
    }

M src/generator/oneof.cc => src/generator/oneof.cc +7 -4
@@ 65,13 65,15 @@ namespace protobluff {

    /* Sort field generators by tag */
    vector<Field *> sorted;
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      sorted.push_back(new Field(descriptor_->field(f)));
    }
    sort(sorted.begin(), sorted.end(), FieldComparator);

    /* Initialize field generators */
    for (size_t f = 0; f < descriptor_->field_count(); f++)
    for (int f = 0; f < descriptor_->field_count(); f++) {
      fields_[f].reset(sorted[f]);
    }

    /* Extract full name for signature */
    variables_["signature"] = descriptor_->full_name();


@@ 130,14 132,15 @@ namespace protobluff {

    /* Retrieve all field tags */
    vector<int> tags;
    for (size_t f = 0; f < descriptor->field_count(); f++)
    for (int f = 0; f < descriptor->field_count(); f++) {
      tags.push_back(descriptor->field(f)->number());
    }

    /* Sort tags to determine indexes */
    sort(tags.begin(), tags.end());

    /* Generate indexes */
    for (size_t f = 0, g = 0; f < descriptor->field_count(); f++) {
    for (int f = 0, g = 0; f < descriptor->field_count(); f++) {
      if (descriptor->field(f) == descriptor_->field(g)) {
        printer->Print("`index`", "index", SimpleItoa(f));
        if (g < descriptor_->field_count() - 1)