IPCCompiler: Add include parsing for endpoints

This will find all lines at the start of the file beginning with # and
copy them straight through.
This commit is contained in:
Timothy 2021-07-02 21:35:27 -07:00 committed by Andreas Kling
parent 128e504de6
commit 83fb97c301
Notes: sideshowbarker 2024-07-18 11:04:45 +09:00

View file

@ -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>