diff options
Diffstat (limited to 'src/nvim/indent_c.c')
-rw-r--r-- | src/nvim/indent_c.c | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 6f03cf6037..4a6393ac36 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include <assert.h> #include <inttypes.h> #include <stdint.h> @@ -10,6 +13,7 @@ #include "nvim/edit.h" #include "nvim/indent.h" #include "nvim/indent_c.h" +#include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/option.h" @@ -173,9 +177,8 @@ static char_u *skip_string(char_u *p) char_u *delim = p + 2; char_u *paren = vim_strchr(delim, '('); - if (paren != NULL) - { - long delim_len = paren - delim; + if (paren != NULL) { + const ptrdiff_t delim_len = paren - delim; for (p += 3; *p; ++p) if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0 @@ -512,34 +515,41 @@ int cin_isscopedecl(char_u *s) /* Maximum number of lines to search back for a "namespace" line. */ #define FIND_NAMESPACE_LIM 20 -/* - * Recognize a "namespace" scope declaration. - */ -static int cin_is_cpp_namespace(char_u *s) +// Recognize a "namespace" scope declaration. +static bool cin_is_cpp_namespace(char_u *s) { - char_u *p; - int has_name = FALSE; + char_u *p; + bool has_name = false; + bool has_name_start = false; s = cin_skipcomment(s); if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9]))) { p = cin_skipcomment(skipwhite(s + 9)); while (*p != NUL) { if (ascii_iswhite(*p)) { - has_name = TRUE; /* found end of a name */ + has_name = true; // found end of a name p = cin_skipcomment(skipwhite(p)); } else if (*p == '{') { break; } else if (vim_iswordc(*p)) { - if (has_name) - return FALSE; /* word character after skipping past name */ - ++p; + has_name_start = true; + if (has_name) { + return false; // word character after skipping past name + } + p++; + } else if (p[0] == ':' && p[1] == ':' && vim_iswordc(p[2])) { + if (!has_name_start || has_name) { + return false; + } + // C++ 17 nested namespace + p += 3; } else { - return FALSE; + return false; } } - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -819,21 +829,22 @@ cin_isterminated ( return found_start; } -/* - * Recognize the basic picture of a function declaration -- it needs to - * have an open paren somewhere and a close paren at the end of the line and - * no semicolons anywhere. - * When a line ends in a comma we continue looking in the next line. - * "sp" points to a string with the line. When looking at other lines it must - * be restored to the line. When it's NULL fetch lines here. - * "lnum" is where we start looking. - * "min_lnum" is the line before which we will not be looking. - */ +/// Recognizes the basic picture of a function declaration -- it needs to +/// have an open paren somewhere and a close paren at the end of the line and +/// no semicolons anywhere. +/// When a line ends in a comma we continue looking in the next line. +/// +/// @param[in] sp Points to a string with the line. When looking at other +/// lines it must be restored to the line. When it's NULL fetch +/// lines here. +/// @param[in] first_lnum Where to start looking. +/// @param[in] min_lnum The line before which we will not be looking. static int cin_isfuncdecl(char_u **sp, linenr_T first_lnum, linenr_T min_lnum) { char_u *s; linenr_T lnum = first_lnum; - int retval = FALSE; + linenr_T save_lnum = curwin->w_cursor.lnum; + int retval = false; pos_T *trypos; int just_started = TRUE; @@ -842,18 +853,22 @@ static int cin_isfuncdecl(char_u **sp, linenr_T first_lnum, linenr_T min_lnum) else s = *sp; + curwin->w_cursor.lnum = lnum; if (find_last_paren(s, '(', ')') && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { lnum = trypos->lnum; - if (lnum < min_lnum) - return FALSE; - + if (lnum < min_lnum) { + curwin->w_cursor.lnum = save_lnum; + return false; + } s = ml_get(lnum); } - /* Ignore line starting with #. */ - if (cin_ispreproc(s)) - return FALSE; + curwin->w_cursor.lnum = save_lnum; + // Ignore line starting with #. + if (cin_ispreproc(s)) { + return false; + } while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"') { // ignore comments |