diff options
author | Itamar <itamar8910@gmail.com> | 2021-08-06 11:15:57 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-07 21:24:11 +0200 |
commit | 0c4dc00f01aa283e08bb04a6e10f9bc6627bdb25 (patch) | |
tree | 9a710bce75a66a44276340c17bd0fe1e164b4a5e /Userland/DevTools/HackStudio | |
parent | 4673a517f6223558b17809216acc57f03b6889bd (diff) | |
download | serenity-0c4dc00f01aa283e08bb04a6e10f9bc6627bdb25.zip |
LibCpp: Import definitions from headers while processing
When the preprocessor encounters an #include statement it now adds
the preprocessor definitions that exist in the included header to its
own set of definitions.
We previously only aggregated the definitions from headers after
processing the source, which was less correct. (For example, there
could be an #ifdef that depends on a definition from another header).
Diffstat (limited to 'Userland/DevTools/HackStudio')
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp index fd07b4f370..84c776faff 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp @@ -569,11 +569,16 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu document_data->m_preprocessor = make<Preprocessor>(document_data->m_filename, document_data->text()); document_data->preprocessor().set_ignore_unsupported_keywords(true); document_data->preprocessor().set_keep_include_statements(true); - auto tokens = document_data->preprocessor().process_and_lex(); - Preprocessor::Definitions preprocessor_definitions; - for (auto item : document_data->preprocessor().definitions()) - preprocessor_definitions.set(move(item.key), move(item.value)); + document_data->preprocessor().definitions_in_header_callback = [this](StringView include_path) -> Preprocessor::Definitions { + auto included_document = get_or_create_document_data(document_path_from_include_path(include_path)); + if (!included_document) + return {}; + + return included_document->preprocessor().definitions(); + }; + + auto tokens = document_data->preprocessor().process_and_lex(); for (auto include_path : document_data->preprocessor().included_paths()) { auto include_fullpath = document_path_from_include_path(include_path); @@ -585,12 +590,9 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu for (auto& header : included_document->m_available_headers) document_data->m_available_headers.set(header); - - for (auto item : included_document->parser().preprocessor_definitions()) - preprocessor_definitions.set(move(item.key), move(item.value)); } - document_data->m_parser = make<Parser>(move(tokens), filename, move(preprocessor_definitions)); + document_data->m_parser = make<Parser>(move(tokens), filename, document_data->preprocessor().definitions()); auto root = document_data->parser().parse(); |