Generate .cpp/.h files with aidl-cpp
These files contain only stubs for now but we can now create them
with a command like:
./out/host/linux-x86/bin/aidl-cpp \
external/easybinder/IPingResponder.aidl \
out/demo/
Test: Above command generates code, unittests
Bug: 24220933
Change-Id: I283971dda61d05949ff74057e6e7d3f276380601
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index 72d692e..6ad4e17 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -15,14 +15,112 @@
*/
#include "generate_cpp.h"
+
+#include <memory>
+#include <string>
+
+#include "ast_cpp.h"
+#include "code_writer.h"
#include "logging.h"
+using std::unique_ptr;
+using std::string;
+
namespace android {
namespace aidl {
+namespace {
-int generate_cpp(const CppOptions& options, interface_type* parsed_doc) {
- UNIMPLEMENTED(FATAL) << "cpp generation is not implemented";
- return 0;
+unique_ptr<CppDocument> BuildClientSource(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppSource{
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+unique_ptr<CppDocument> BuildServerSource(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppSource{
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+unique_ptr<CppDocument> BuildInterfaceSource(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppSource{
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+unique_ptr<CppDocument> BuildClientHeader(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppHeader{
+ "FILL_ME_IN",
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+unique_ptr<CppDocument> BuildServerHeader(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppHeader{
+ "FILL_ME_IN",
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+unique_ptr<CppDocument> BuildInterfaceHeader(interface_type* parsed_doc) {
+ return unique_ptr<CppDocument>{new CppHeader{
+ "FILL_ME_IN",
+ {},
+ new CppNamespace{
+ "android",
+ {}
+ }
+ }};
+}
+
+bool GenerateCppForFile(const std::string& name, unique_ptr<CppDocument> doc) {
+ if (!doc) {
+ return false;
+ }
+ unique_ptr<CodeWriter> writer = GetFileWriter(name);
+ doc->Write(writer.get());
+ return true;
+}
+
+} // namespace
+
+bool GenerateCpp(const CppOptions& options, interface_type* parsed_doc) {
+ bool success = true;
+
+ success &= GenerateCppForFile(options.ClientCppFileName(),
+ BuildClientSource(parsed_doc));
+ success &= GenerateCppForFile(options.ClientHeaderFileName(),
+ BuildClientHeader(parsed_doc));
+ success &= GenerateCppForFile(options.ServerCppFileName(),
+ BuildServerSource(parsed_doc));
+ success &= GenerateCppForFile(options.ServerHeaderFileName(),
+ BuildServerHeader(parsed_doc));
+ success &= GenerateCppForFile(options.InterfaceCppFileName(),
+ BuildInterfaceSource(parsed_doc));
+ success &= GenerateCppForFile(options.InterfaceHeaderFileName(),
+ BuildInterfaceHeader(parsed_doc));
+
+ return success;
}
} // namespace android