From 099ff00908e143baac86c6dae8d7bbc514697f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Fri, 21 Apr 2017 12:11:02 +0200 Subject: [PATCH] Workaround weird issue with broken children of function definition --- src/libclang/function_parser.cpp | 5 +++++ src/libclang/tokenizer.cpp | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libclang/function_parser.cpp b/src/libclang/function_parser.cpp index 0eee2c9..80c1973 100644 --- a/src/libclang/function_parser.cpp +++ b/src/libclang/function_parser.cpp @@ -333,6 +333,8 @@ namespace else stream.bump(); } + if (stream.peek() == "{" || stream.peek() == ":" || stream.peek() == "try") + result.body_kind = cpp_function_definition; } else { @@ -356,6 +358,9 @@ namespace if (detail::skip_if(stream, "=")) parse_body(stream, result, allow_virtual); + else if (detail::skip_if(stream, "{") || detail::skip_if(stream, ":") + || detail::skip_if(stream, "try")) + result.body_kind = cpp_function_definition; } return result; diff --git a/src/libclang/tokenizer.cpp b/src/libclang/tokenizer.cpp index 74f8e2a..c127769 100644 --- a/src/libclang/tokenizer.cpp +++ b/src/libclang/tokenizer.cpp @@ -94,7 +94,7 @@ namespace auto kind = clang_getCursorKind(cur); if (cursor_is_function(kind) || cursor_is_function(clang_getTemplateCursorKind(cur))) { - auto range_shrunk = false; + auto is_definition = false; // if a function we need to remove the body // it does not need to be parsed @@ -105,11 +105,22 @@ namespace { auto child_extent = clang_getCursorExtent(child); end = clang_getRangeStart(child_extent); - range_shrunk = true; + is_definition = true; } }); - if (!range_shrunk && !token_after_is(tu, file, cur, end, ";")) + if (!is_definition) + { + // i have no idea why this is necessary + is_definition = token_after_is(tu, file, cur, end, "{") + || token_after_is(tu, file, cur, end, "try") + || token_after_is(tu, file, cur, end, ":"); + if (is_definition) + // need to extend range here to include the token + end = get_next_location(tu, file, end); + } + + if (!is_definition && !token_after_is(tu, file, cur, end, ";")) { // we do not have a body, but it is not a declaration either do