From 8c437362bc6e0374aa9b2dc9338aba1e5cf545a0 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Sun, 12 May 2019 20:49:00 -0700 Subject: C++: Support single quote digit separator in integer literals C++14 supports the use of single quotes inserted between integer digits as a separator. Updates the built-in C++ code model to recognize such quotes. This fixes highlighting and indentation issues. Change-Id: Ic35ce93060b96700a11d108dce1f3cf6c4543632 Fixes: QTCREATORBUG-14939 Reviewed-by: Nikolai Kosjar --- src/libs/3rdparty/cplusplus/Lexer.cpp | 12 ++++++++---- src/libs/3rdparty/cplusplus/Token.h | 1 + src/libs/cplusplus/MatchingText.cpp | 1 + src/plugins/cpptools/cppcodeformatter.cpp | 2 ++ src/plugins/cpptools/projectpart.cpp | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index 079ae0ca6e6..d1858f007cf 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -954,7 +954,8 @@ void Lexer::scanNumericLiteral(Token *tok) yyinp(); while (std::isdigit(_yychar) || (_yychar >= 'a' && _yychar <= 'f') || - (_yychar >= 'A' && _yychar <= 'F')) { + (_yychar >= 'A' && _yychar <= 'F') || + ((_yychar == '\'') && _languageFeatures.cxx14Enabled)) { yyinp(); } if (!scanOptionalIntegerSuffix()) @@ -962,7 +963,8 @@ void Lexer::scanNumericLiteral(Token *tok) goto theEnd; } else if (_yychar == 'b' || _yychar == 'B') { // see n3472 yyinp(); - while (_yychar == '0' || _yychar == '1') + while (_yychar == '0' || _yychar == '1' || + ((_yychar == '\'') && _languageFeatures.cxx14Enabled)) yyinp(); if (!scanOptionalIntegerSuffix()) scanOptionalUserDefinedLiteral(tok); @@ -970,7 +972,8 @@ void Lexer::scanNumericLiteral(Token *tok) } else if (_yychar >= '0' && _yychar <= '7') { do { yyinp(); - } while (_yychar >= '0' && _yychar <= '7'); + } while ((_yychar >= '0' && _yychar <= '7') || + ((_yychar == '\'') && _languageFeatures.cxx14Enabled)); if (!scanOptionalIntegerSuffix()) scanOptionalUserDefinedLiteral(tok); goto theEnd; @@ -989,7 +992,8 @@ void Lexer::scanNumericLiteral(Token *tok) if (scanExponentPart() && !scanOptionalFloatingSuffix()) scanOptionalUserDefinedLiteral(tok); break; - } else if (std::isdigit(_yychar)) { + } else if (std::isdigit(_yychar) || + ((_yychar == '\'') && _languageFeatures.cxx14Enabled)) { yyinp(); } else { if (!scanOptionalIntegerSuffix()) diff --git a/src/libs/3rdparty/cplusplus/Token.h b/src/libs/3rdparty/cplusplus/Token.h index 67378b28a39..36a893efff3 100644 --- a/src/libs/3rdparty/cplusplus/Token.h +++ b/src/libs/3rdparty/cplusplus/Token.h @@ -437,6 +437,7 @@ struct LanguageFeatures unsigned int qtKeywordsEnabled : 1; // If Qt is used but QT_NO_KEYWORDS defined unsigned int cxxEnabled : 1; unsigned int cxx11Enabled : 1; + unsigned int cxx14Enabled : 1; unsigned int objCEnabled : 1; unsigned int c99Enabled : 1; }; diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp index 59440813a70..5aea683f1e5 100644 --- a/src/libs/cplusplus/MatchingText.cpp +++ b/src/libs/cplusplus/MatchingText.cpp @@ -145,6 +145,7 @@ static LanguageFeatures languageFeatures() features.qtKeywordsEnabled = false; features.qtMocRunEnabled = false; features.cxx11Enabled = true; + features.cxx14Enabled = true; features.cxxEnabled = true; features.c99Enabled = true; features.objCEnabled = true; diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 069359d8691..fca7998ece9 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -1054,6 +1054,8 @@ int CodeFormatter::tokenizeBlock(const QTextBlock &block, bool *endedJoined) features.qtKeywordsEnabled = true; features.cxxEnabled = true; features.objCEnabled = true; + features.cxx11Enabled = true; + features.cxx14Enabled = true; SimpleLexer tokenize; tokenize.setLanguageFeatures(features); diff --git a/src/plugins/cpptools/projectpart.cpp b/src/plugins/cpptools/projectpart.cpp index 4569f231d1a..2205fb07b57 100644 --- a/src/plugins/cpptools/projectpart.cpp +++ b/src/plugins/cpptools/projectpart.cpp @@ -38,6 +38,7 @@ void ProjectPart::updateLanguageFeatures() const bool hasCxx = languageVersion >= Utils::LanguageVersion::CXX98; const bool hasQt = hasCxx && qtVersion != NoQt; languageFeatures.cxx11Enabled = languageVersion >= Utils::LanguageVersion::CXX11; + languageFeatures.cxx14Enabled = languageVersion >= Utils::LanguageVersion::CXX14; languageFeatures.cxxEnabled = hasCxx; languageFeatures.c99Enabled = languageVersion >= Utils::LanguageVersion::C99; languageFeatures.objCEnabled = languageExtensions.testFlag(Utils::LanguageExtension::ObjectiveC); -- cgit v1.2.3