From 83fb97c30153e01fe501de0414ac07808a8b1339 Mon Sep 17 00:00:00 2001 From: Timothy Date: Fri, 2 Jul 2021 21:35:27 -0700 Subject: [PATCH] IPCCompiler: Add include parsing for endpoints This will find all lines at the start of the file beginning with # and copy them straight through. --- Userland/DevTools/IPCCompiler/main.cpp | 36 +++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Userland/DevTools/IPCCompiler/main.cpp b/Userland/DevTools/IPCCompiler/main.cpp index 4e2d61f317..2affb167dd 100644 --- a/Userland/DevTools/IPCCompiler/main.cpp +++ b/Userland/DevTools/IPCCompiler/main.cpp @@ -58,6 +58,7 @@ struct Message { }; struct Endpoint { + Vector includes; String name; u32 magic; Vector messages; @@ -197,9 +198,30 @@ int main(int argc, char** argv) } }; + auto parse_include = [&] { + String include; + consume_whitespace(); + include = lexer.consume_while([](char ch) { return ch != '\n'; }); + consume_whitespace(); + + endpoints.last().includes.append(move(include)); + }; + + auto parse_includes = [&] { + for (;;) { + consume_whitespace(); + if (lexer.peek() != '#') + break; + parse_include(); + consume_whitespace(); + } + }; + auto parse_endpoint = [&] { endpoints.empend(); consume_whitespace(); + parse_includes(); + consume_whitespace(); lexer.consume_specific("endpoint"); consume_whitespace(); endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); }); @@ -241,9 +263,17 @@ int main(int argc, char** argv) StringBuilder builder; SourceGenerator generator { builder }; - generator.append(R"~~~( -#pragma once -#include + generator.append("#pragma once\n"); + + // This must occur before LibIPC/Decoder.h + for (auto& endpoint : endpoints) { + for (auto& include : endpoint.includes) { + generator.append(include); + generator.append("\n"); + } + } + + generator.append(R"~~~(#include #include #include #include