From 8dd07c3075a365d7589ac79bd20fdf0dcf7f6b7f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 3 Aug 2019 17:24:47 +0200 Subject: IPCCompiler: Emit message parameter getters For simplicity's sake, they are all "const type& name() const" --- DevTools/IPCCompiler/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index 04cf175b62..8278b71d32 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -182,6 +182,7 @@ int main(int argc, char** argv) while (index < file_contents.size()) parse_endpoint(); + dbg() << "#pragma once"; dbg() << "#include "; dbg() << "#include "; dbg() << "#include "; @@ -255,8 +256,13 @@ int main(int argc, char** argv) dbg() << " (void)stream;"; for (auto& parameter : parameters) { - dbg() << " " << parameter.type << " " << parameter.name << ";"; + String initial_value = "{}"; + if (parameter.type == "bool") + initial_value = "false"; + dbg() << " " << parameter.type << " " << parameter.name << " = " << initial_value << ";"; dbg() << " stream >> " << parameter.name << ";"; + dbg() << " if (stream.handle_read_failure())"; + dbg() << " return nullptr;"; } StringBuilder builder; @@ -280,6 +286,9 @@ int main(int argc, char** argv) dbg() << " stream.snip();"; dbg() << " return buffer;"; dbg() << " }"; + for (auto& parameter : parameters) { + dbg() << " const " << parameter.type << "& " << parameter.name << "() const { return m_" << parameter.name << "; }"; + } dbg() << "private:"; for (auto& parameter : parameters) { dbg() << " " << parameter.type << " m_" << parameter.name << ";"; @@ -298,7 +307,7 @@ int main(int argc, char** argv) dbg() << "} // namespace " << endpoint.name; dbg(); - dbg() << "class " << endpoint.name << "Endpoint final : public IEndpoint {"; + dbg() << "class " << endpoint.name << "Endpoint : public IEndpoint {"; dbg() << "public:"; dbg() << " " << endpoint.name << "Endpoint() {}"; dbg() << " virtual ~" << endpoint.name << "Endpoint() override {}"; @@ -335,7 +344,7 @@ int main(int argc, char** argv) builder.append("Response"); return_type = builder.to_string(); } - dbg() << " " << return_type << " handle(const " << endpoint.name << "::" << message.name << "&);"; + dbg() << " virtual " << return_type << " handle(const " << endpoint.name << "::" << message.name << "&) = 0;"; } dbg() << "private:"; -- cgit v1.2.3