diff options
author | Christopher Wiley <wiley@google.com> | 2016-02-02 17:58:39 -0800 |
---|---|---|
committer | Christopher Wiley <wiley@google.com> | 2016-02-04 17:12:56 +0000 |
commit | fd7dc03fdd1e0cd558df43a155ab1644cbe2b553 (patch) | |
tree | 300b3bbee480021838b64e9c893bfabf5df20b23 /generate_cpp.cpp | |
parent | 2359cddf18b1d37787cc398c4c567a776802c7ba (diff) | |
download | android_system_tools_aidl-fd7dc03fdd1e0cd558df43a155ab1644cbe2b553.tar.gz android_system_tools_aidl-fd7dc03fdd1e0cd558df43a155ab1644cbe2b553.tar.bz2 android_system_tools_aidl-fd7dc03fdd1e0cd558df43a155ab1644cbe2b553.zip |
Declare interface constants as enum in C++
While constexpr hints to the compiler that it can optimize
away the address of these integer expressions, it does not
mandate this behavior. This can cause linkage errors when
the same generated header is included from multiple compilation
units and everyone expects the integer constant to defined
elsewhere.
Bug: 26942276
Test: unittests pass
Change-Id: I7dfda08b5226344d5169b3f298413cd8a1ceb692
Diffstat (limited to 'generate_cpp.cpp')
-rw-r--r-- | generate_cpp.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/generate_cpp.cpp b/generate_cpp.cpp index de4ab5a..f9ce9f7 100644 --- a/generate_cpp.cpp +++ b/generate_cpp.cpp @@ -676,10 +676,13 @@ unique_ptr<Document> BuildInterfaceHeader(const TypeNamespace& types, "DECLARE_META_INTERFACE", ArgList{vector<string>{ClassName(interface, ClassNames::BASE)}}}}); + unique_ptr<Enum> constant_enum{new Enum{"", "int32_t"}}; for (const auto& constant : interface.GetConstants()) { - unique_ptr<ConstDecl> declaration{ - new ConstDecl(constant->GetName(), constant->GetValue())}; - if_class->AddPublic(std::move(declaration)); + constant_enum->AddValue( + constant->GetName(), std::to_string(constant->GetValue())); + } + if (constant_enum->HasValues()) { + if_class->AddPublic(std::move(constant_enum)); } unique_ptr<Enum> call_enum{new Enum{"Call"}}; |