diff options
author | Yi Jin <jinyithu@google.com> | 2017-09-12 20:00:25 -0700 |
---|---|---|
committer | Yi Jin <jinyithu@google.com> | 2017-09-13 14:32:42 -0700 |
commit | 7e0b4e5880d389e6af1af602373aefa5b0b04d34 (patch) | |
tree | 5a7eb1fb7c65ed5389abd2128702442e02a6f02e /tools/incident_section_gen | |
parent | e57a4f85bf1948d316a90ca354b5bf84aa99b448 (diff) |
Fixes regarding to comments in ag/2839267
1. use struct {} to instantiate privacy fields for efficiency reason
2. use vector<uint8_t>* instead of vector<uint8_t>& to indicate the
caller knows the value gets changed.
3. binary search privay policy for sections
Bug: 65595927
Test: unit test covers
Change-Id: Ic58c2f607465d1a7f10352b9a38c3d8b1a5cf352
Diffstat (limited to 'tools/incident_section_gen')
-rw-r--r-- | tools/incident_section_gen/main.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp index 7966d886d5a0..900690cf36d6 100644 --- a/tools/incident_section_gen/main.cpp +++ b/tools/incident_section_gen/main.cpp @@ -135,7 +135,7 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const char* alias if (generatePrivacyFlags(field->message_type(), field_name, msgNames) && isDefaultDest(field)) break; - printf("Privacy %s(%d, %s_LIST);\n", field_name, field->number(), field_name); + printf("Privacy %s { %d, %d, %s_LIST, %d, NULL };\n", field_name, field->number(), field->type(), field_name, p.dest()); hasDefaultFlags[i] = false; break; case FieldDescriptor::TYPE_STRING: @@ -147,12 +147,12 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const char* alias printf(" \"%s\",\n", replaceAll(p.patterns(i), '\\', "\\\\").c_str()); } printf(" NULL };\n"); - printf("Privacy %s(%d, %d, %s_patterns);\n", field_name, field->number(), p.dest(), field_name); + printf("Privacy %s { %d, %d, NULL, %d, %s_patterns };\n", field_name, field->number(), field->type(), p.dest(), field_name); hasDefaultFlags[i] = false; break; default: if (isDefaultDest(field)) break; - printf("Privacy %s(%d, %d, %d);\n", field_name, field->number(), (int) field->type(), p.dest()); + printf("Privacy %s { %d, %d, NULL, %d, NULL };\n", field_name, field->number(), field->type(), p.dest()); hasDefaultFlags[i] = false; } // add the field name to message map, true means it has default flags @@ -166,13 +166,23 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const char* alias if (allDefaults) return true; emptyline(); - printf("const Privacy* %s_LIST[] = {\n", alias); + + bool needConst = strcmp(alias, "PRIVACY_POLICY") == 0; + int policyCount = 0; + + printf("%s Privacy* %s_LIST[] = {\n", needConst ? "const" : "", alias); for (int i=0; i<descriptor->field_count(); i++) { const FieldDescriptor* field = descriptor->field(i); if (hasDefaultFlags[i]) continue; printf(" &%s,\n", replaceAll(field->full_name(), '.', "__").c_str()); + policyCount++; + } + if (needConst) { + printf("};\n\n"); + printf("const int PRIVACY_POLICY_COUNT = %d;\n", policyCount); + } else { + printf(" NULL };\n"); } - printf(" NULL };\n"); emptyline(); return false; } @@ -214,7 +224,8 @@ static bool generateSectionListCpp(Descriptor const* descriptor) { map<string, bool> messageNames; if (generatePrivacyFlags(descriptor, "PRIVACY_POLICY", messageNames)) { // if no privacy options set at all, define an empty list - printf("const Privacy* PRIVACY_POLICY_LIST[] = { NULL };\n"); + printf("const Privacy* PRIVACY_POLICY_LIST[] = {};\n"); + printf("const int PRIVACY_POLICY_COUNT = 0;\n"); } return true; |