diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-08-17 18:10:53 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-08-23 13:52:11 +0000 |
commit | ca00b874a75d8cd64f9768d21959a530b928c6dc (patch) | |
tree | 8292188e0ac3952854cd653bfa573c1cf94772de /src/libs/3rdparty/cplusplus/Parser.cpp | |
parent | 5fab54d95aadaf28c4f7d10e601cc12feb682429 (diff) | |
download | qt-creator-ca00b874a75d8cd64f9768d21959a530b928c6dc.tar.gz |
CPlusPlus: Support structured bindings
While we do recommend clangd for modern code bases, we should still be
able to parse basic language constructs.
Fixes: QTCREATORBUG-27975
Change-Id: I189b991685a5cd5f62f2afce77878b60c895e8f9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Parser.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Parser.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 7116f1abf4..9938fa9dde 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -1568,6 +1568,8 @@ bool Parser::parseDeclaratorOrAbstractDeclarator(DeclaratorAST *&node, Specifier return parseAbstractDeclarator(node, decl_specifier_list); } + + bool Parser::parseCoreDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list, ClassSpecifierAST *) { DEBUG_THIS_RULE(); @@ -1616,11 +1618,51 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_sp node = ast; return true; } + } else if (const auto decl = parseDecompositionDeclarator()) { + DeclaratorAST *ast = new (_pool) DeclaratorAST; + ast->attribute_list = attributes; + ast->ptr_operator_list = ptr_operators; + ast->core_declarator = decl; + node = ast; + return true; } rewind(start); return false; } +DecompositionDeclaratorAST *Parser::parseDecompositionDeclarator() +{ + if (LA() != T_LBRACKET) + return nullptr; + consumeToken(); + + const auto decl = new (_pool) DecompositionDeclaratorAST; + for (NameListAST **iter = &decl->identifiers; ; iter = &(*iter)->next) { + NameAST *name_ast = nullptr; + if (!parseName(name_ast)) { + error(cursor(), "expected an identifier"); + return nullptr; + } + *iter = new (_pool) NameListAST; + (*iter)->value = name_ast; + + if (LA() == T_RBRACKET) { + consumeToken(); + return decl; + } + + if (LA() == T_COMMA) { + consumeToken(); + continue; + } + + error(cursor(), "expected ',' or ']'"); + return nullptr; + } + + return nullptr; +} + static bool maybeCppInitializer(DeclaratorAST *declarator) { if (declarator->ptr_operator_list) |