From da89725f340ac702cc6199962fa82ea8edcbede8 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sat, 26 Feb 2022 13:06:34 +0100 Subject: fix(coverity/175977): big parameter passed by value --- src/nvim/viml/parser/expressions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 8a14710351..9d1318724e 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1592,7 +1592,7 @@ typedef struct { /// string is a regex. /// @param[in] is_invalid Whether currently processed token is not valid. static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const node, - const LexExprToken token, const ExprASTStack ast_stack, + const LexExprToken token, const ExprASTStack *ast_stack, const bool is_invalid) FUNC_ATTR_NONNULL_ALL { @@ -2907,7 +2907,7 @@ viml_pexpr_parse_no_paren_closing_error: {} ? kExprNodeDoubleQuotedString : kExprNodeSingleQuotedString)); *top_node_p = cur_node; - parse_quoted_string(pstate, cur_node, cur_token, ast_stack, is_invalid); + parse_quoted_string(pstate, cur_node, cur_token, &ast_stack, is_invalid); want_node = kENodeOperator; break; } -- cgit From 0648100fed65cbe8efe774ae997ab841cae01872 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 25 Apr 2022 04:18:43 +0200 Subject: refactor: convert macros to all-caps (#17895) Closes https://github.com/neovim/neovim/issues/6297 --- src/nvim/viml/parser/expressions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 9d1318724e..b8b0a38f44 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -66,7 +66,7 @@ #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" -#define vim_str2nr(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) +#define VIM_STR2NR(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) typedef kvec_withinit_t(ExprASTNode **, 16) ExprASTStack; @@ -371,7 +371,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) significand_part = significand_part * 10 + (pline.data[i] - '0'); } if (exp_start) { - vim_str2nr(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, + VIM_STR2NR(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, (int)(ret.len - exp_start), false); } if (exp_negative) { @@ -389,7 +389,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) } else { int len; int prep; - vim_str2nr(pline.data, &prep, &len, STR2NR_ALL, NULL, + VIM_STR2NR(pline.data, &prep, &len, STR2NR_ALL, NULL, &ret.data.num.val.integer, (int)pline.size, false); ret.len = (size_t)len; const uint8_t bases[] = { -- cgit From dde4f09f51ffaf8df5cc2a81eed935e31e1f94ba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 31 Mar 2022 15:47:53 +0800 Subject: vim-patch:8.1.2145: cannot map when modifyOtherKeys is enabled Problem: Cannot map when modifyOtherKeys is enabled. Solution: Add the mapping twice, both with modifier and as 0x08. Use only the first one when modifyOtherKeys has been detected. https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84 Add REPTERM_NO_SPECIAL instead of REPTERM_SPECIAL because the meaning of "special" is different between Vim and Nvim. Omit seenModifyOtherKeys as Nvim supports attaching multiple UIs. Omit tests as they send terminal codes. Keep the behavior of API functions. --- src/nvim/viml/parser/expressions.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index b8b0a38f44..ec747d56d4 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1817,9 +1817,8 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no } // Special key, e.g.: "\" case '<': { - const size_t special_len = ( - trans_special((const char_u **)&p, (size_t)(e - p), - (char_u *)v_p, true, true)); + const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), + (char_u *)v_p, true, true, true, NULL); if (special_len != 0) { v_p += special_len; } else { -- cgit From abe91e1efec84c47c03a69ab8a998bb16f628084 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Apr 2022 15:05:56 +0800 Subject: vim-patch:8.2.0855: GUI tests fail because the test doesn't use a modifier Problem: GUI tests fail because the test doesn't use a modifier. Solution: Add "\{xxx}" to be able to encode a modifier. https://github.com/vim/vim/commit/ebe9d34aa07037cff2188a8dd424ee1f59cbb0bf Change macros to enums to use them in unit tests. --- src/nvim/viml/parser/expressions.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index ec747d56d4..1beae0d003 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1815,10 +1815,18 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no *v_p++ = (char)ch; break; } - // Special key, e.g.: "\" - case '<': { + // Special key, e.g.: "\" or "\{C-W}" + case '<': + case '{': { + int flags = FSK_KEYCODE | FSK_IN_STRING; + + if (*p == '<') { + flags |= FSK_SIMPLIFY; + } else { + flags |= FSK_CURLY; + } const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), - (char_u *)v_p, true, true, true, NULL); + (char_u *)v_p, flags, NULL); if (special_len != 0) { v_p += special_len; } else { -- cgit From d531ef6813919dd6df8ca6927cd99ec3c0a65635 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Apr 2022 15:31:29 +0800 Subject: vim-patch:8.2.0867: using \{xxx} for encoding a modifier is not nice Problem: Using \{xxx} for encoding a modifier is not nice. Solution: Use \<*xxx> instead, since it's the same as \ but producing a different code. https://github.com/vim/vim/commit/fccd93f0917234b962ce07d1df3adf9d7105936f Use this notation in langmap_spec. --- src/nvim/viml/parser/expressions.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 1beae0d003..b0fbc586b2 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1815,15 +1815,12 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no *v_p++ = (char)ch; break; } - // Special key, e.g.: "\" or "\{C-W}" - case '<': - case '{': { + // Special key, e.g.: "\" + case '<': { int flags = FSK_KEYCODE | FSK_IN_STRING; - if (*p == '<') { + if (p[1] != '*') { flags |= FSK_SIMPLIFY; - } else { - flags |= FSK_CURLY; } const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), (char_u *)v_p, flags, NULL); -- cgit From eef8de4df0247157e57f306062b1b86e01a41454 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 29 Apr 2022 13:53:42 +0200 Subject: refactor(uncrustify): change rules to better align with the style guide Add space around arithmetic operators '+' and '-'. Remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. Remove space between '((' or '))' of control statements. Add space between ')' and '{' of control statements. Remove space between function name and '(' on function declaration. Collapse empty blocks between '{' and '}'. Remove newline at the end of the file. Remove newline between 'enum' and '{'. Remove newline between '}' and ')' in a function invocation. Remove newline between '}' and 'while' of 'do' statement. --- src/nvim/viml/parser/expressions.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index b0fbc586b2..29d686193d 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -541,8 +541,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) ret.data.opt.len = 4; ret.len += 4; } else { - for (; p < e && ASCII_ISALPHA(*p); p++) { - } + for (; p < e && ASCII_ISALPHA(*p); p++) {} ret.data.opt.len = (size_t)(p - ret.data.opt.name); if (ret.data.opt.len == 0) { OPTNAMEMISS(ret); -- cgit From 27149e0071c3fa38c81526f63a997bedfd6e2be8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 May 2022 06:11:22 +0800 Subject: vim-patch:8.2.4858: K_SPECIAL may be escaped twice Problem: K_SPECIAL may be escaped twice. Solution: Avoid double escaping. (closes vim/vim#10340) https://github.com/vim/vim/commit/db08887f24d20be11d184ce321bc0890613e42bd --- src/nvim/viml/parser/expressions.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 29d686193d..01fc282891 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1651,10 +1651,11 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no } switch (*p) { // A "\" form occupies at least 4 characters, and produces up to - // 6 characters: reserve space for 2 extra, but do not compute actual - // length just now, it would be costy. + // to 9 characters (6 for the char and 3 for a modifier): + // reserve space for 5 extra, but do not compute actual length + // just now, it would be costly. case '<': - size += 2; + size += 5; break; // Hexadecimal, always single byte, but at least three bytes each. case 'x': @@ -1822,7 +1823,7 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no flags |= FSK_SIMPLIFY; } const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), - (char_u *)v_p, flags, NULL); + (char_u *)v_p, flags, false, NULL); if (special_len != 0) { v_p += special_len; } else { -- cgit From d0897243f6a6bb802fc9622486afd69eb65fa6d5 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 6 May 2022 17:40:52 +0200 Subject: build(clint): remove "function size is too large" warning This warning is essentially only triggered for ported vim functions. It's unlikely that we'll refactor vim functions solely based on their size since it'd mean we'd greatly deviate from vim, which is a high cost when it comes to importing the vim patches. Thus, this warning only serves as an annoyance and should be removed. --- src/nvim/viml/parser/expressions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 01fc282891..2693093f4a 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -3067,7 +3067,7 @@ viml_pexpr_parse_end: } kvi_destroy(ast_stack); return ast; -} // NOLINT(readability/fn_size) +} #undef NEW_NODE #undef HL -- cgit From e31b32a293f6ba8708499a176234f8be1df6a145 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Thu, 5 May 2022 13:36:14 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/viml/parser/expressions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 2693093f4a..41b4a7edd6 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1788,7 +1788,7 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no if (is_hex) { *v_p++ = (char)nr; } else { - v_p += utf_char2bytes(nr, (char_u *)v_p); + v_p += utf_char2bytes(nr, v_p); } } else { is_unknown = true; -- cgit From 045aacc38470114daa969c5751276c90a3158f9b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 21 May 2022 05:41:57 +0200 Subject: ci: lint with uncrustify #18563 This lint job will ensure that the C codebase is properly formatted at all times. This helps eliminate most of clint.py. To save CI time, it's faster to manually compile uncrustify and cache the binary instead of using homebrew (the apt-get package is too old). --- src/nvim/viml/parser/expressions.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/viml/parser/expressions.c') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 41b4a7edd6..fd7dc17ee3 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -2646,6 +2646,7 @@ viml_pexpr_parse_figure_brace_closing_error: kvi_push(pt_stack, kEPTLambdaArguments); lambda_node = cur_node; } else { + // uncrustify:off ADD_IDENT(do { NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeCurlyBracesIdentifier); @@ -2660,6 +2661,7 @@ viml_pexpr_parse_figure_brace_closing_error: want_node = kENodeValue; } while (0), Curly); + // uncrustify:on } if (pt_is_assignment(cur_pt) && !pt_is_assignment(kv_last(pt_stack))) { @@ -2737,6 +2739,7 @@ viml_pexpr_parse_figure_brace_closing_error: : HL(IdentifierName))); } else { if (scope == kExprVarScopeMissing) { + // uncrustify:off ADD_IDENT(do { NEW_NODE_WITH_CUR_POS(cur_node, kExprNodePlainIdentifier); cur_node->data.var.scope = scope; @@ -2745,6 +2748,7 @@ viml_pexpr_parse_figure_brace_closing_error: want_node = kENodeOperator; } while (0), IdentifierName); + // uncrustify:on } else { OP_MISSING; } -- cgit