Преглед изворни кода

IPCCompiler: Add include parsing for endpoints

This will find all lines at the start of the file beginning with # and
copy them straight through.
Timothy пре 4 година
родитељ
комит
83fb97c301
1 измењених фајлова са 33 додато и 3 уклоњено
  1. 33 3
      Userland/DevTools/IPCCompiler/main.cpp

+ 33 - 3
Userland/DevTools/IPCCompiler/main.cpp

@@ -58,6 +58,7 @@ struct Message {
 };
 
 struct Endpoint {
+    Vector<String> includes;
     String name;
     u32 magic;
     Vector<Message> 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 <AK/MemoryStream.h>
+    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 <AK/MemoryStream.h>
 #include <AK/OwnPtr.h>
 #include <AK/Result.h>
 #include <AK/URL.h>