1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:47:35 +00:00

LibCpp: Understand preprocessor macro definition and invocation

The preprocessor now understands when a function-like macro is defined,
and can also parse calls to such macros.

The actual evaluation of function-like macros will be done in a
separate commit.
This commit is contained in:
Itamar 2021-08-11 22:31:43 +03:00 committed by Andreas Kling
parent c7d3a7789c
commit 8505fcb8ae
4 changed files with 155 additions and 31 deletions

View file

@ -165,7 +165,7 @@ Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_na
if (reference_scope.is_empty()) {
for (auto& preprocessor_name : document.preprocessor().definitions().keys()) {
if (preprocessor_name.starts_with(partial_text)) {
suggestions.append({ preprocessor_name.to_string(), partial_text.length(), GUI::AutocompleteProvider::CompletionKind::PreprocessorDefinition });
suggestions.append({ preprocessor_name, partial_text.length(), GUI::AutocompleteProvider::CompletionKind::PreprocessorDefinition });
}
}
}
@ -413,9 +413,9 @@ Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::fin
// Search for a replaced preprocessor token that intersects with text_position
for (auto& substitution : document.preprocessor().substitutions()) {
if (substitution.original_token.start() > cpp_position)
if (substitution.original_tokens.first().start() > cpp_position)
continue;
if (substitution.original_token.end() < cpp_position)
if (substitution.original_tokens.first().end() < cpp_position)
continue;
return GUI::AutocompleteProvider::ProjectLocation { substitution.defined_value.filename, substitution.defined_value.line, substitution.defined_value.column };