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

Side by Side Diff: components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc

Issue 2217703002: Tracing V2: Field number constants for protobuf plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove template Created 4 years, 4 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
« no previous file with comments | « components/tracing/test/proto_zero_generation_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "proto_zero_generator.h" 5 #include "proto_zero_generator.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 for (int j = 0; j < nested_enum->value_count(); ++j) { 456 for (int j = 0; j < nested_enum->value_count(); ++j) {
457 const EnumValueDescriptor* value = nested_enum->value(j); 457 const EnumValueDescriptor* value = nested_enum->value(j);
458 stub_h_->Print( 458 stub_h_->Print(
459 "static const $class$ $name$ = $full_name$;\n", 459 "static const $class$ $name$ = $full_name$;\n",
460 "class", nested_enum->name(), 460 "class", nested_enum->name(),
461 "name", value->name(), 461 "name", value->name(),
462 "full_name", value_name_prefix + value->name()); 462 "full_name", value_name_prefix + value->name());
463 } 463 }
464 } 464 }
465 465
466 // Fields descriptors. 466 // Field numbers.
467 if (message->field_count() > 0) {
468 stub_h_->Print("enum : int32_t {\n");
469 stub_h_->Indent();
470
471 for (int i = 0; i < message->field_count(); ++i) {
472 const FieldDescriptor* field = message->field(i);
473 std::string name = field->camelcase_name();
474 if (!name.empty()) {
475 name.at(0) = toupper(name.at(0));
476 } else {
477 // Protoc allows fields like 'bool _ = 1'.
478 Abort("Empty field name in camel case notation.");
479 }
480
481 stub_h_->Print(
482 "k$name$FieldNumber = $id$,\n",
483 "name", name,
484 "id", std::to_string(field->number()));
485 }
486 stub_h_->Outdent();
487 stub_h_->Print("};\n");
488 }
489
490 // Field descriptors.
467 for (int i = 0; i < message->field_count(); ++i) { 491 for (int i = 0; i < message->field_count(); ++i) {
468 const FieldDescriptor* field = message->field(i); 492 const FieldDescriptor* field = message->field(i);
469 if (field->is_packed()) { 493 if (field->is_packed()) {
470 Abort("Packed repeated fields are not supported."); 494 Abort("Packed repeated fields are not supported.");
471 return; 495 return;
472 } 496 }
473 if (field->type() != FieldDescriptor::TYPE_MESSAGE) { 497 if (field->type() != FieldDescriptor::TYPE_MESSAGE) {
474 GenerateSimpleFieldDescriptor(field); 498 GenerateSimpleFieldDescriptor(field);
475 } else { 499 } else {
476 GenerateNestedMessageFieldDescriptor(field); 500 GenerateNestedMessageFieldDescriptor(field);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 GeneratorJob job(file, &stub_h_printer, &stub_cc_printer); 555 GeneratorJob job(file, &stub_h_printer, &stub_cc_printer);
532 if (!job.GenerateStubs()) { 556 if (!job.GenerateStubs()) {
533 *error = job.GetFirstError(); 557 *error = job.GetFirstError();
534 return false; 558 return false;
535 } 559 }
536 return true; 560 return true;
537 } 561 }
538 562
539 } // namespace proto 563 } // namespace proto
540 } // namespace tracing 564 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/test/proto_zero_generation_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698