Skip to content

Commit

Permalink
feat: Create a list of C++ keywords for verification
Browse files Browse the repository at this point in the history
Task-Id: KNUT-125
Change-Id: I361db61b298029eefe6e2a6c8f0bc25c33a7cd47
Reviewed-on: https://codereview.kdab.com/c/knut/+/142833
Reviewed-by: Michel Boyer de la Giroday <michel.giroday@kdab.com>
Tested-by: Continuous Integration <build@kdab.com>
  • Loading branch information
mgiroday authored and LeonMatthesKDAB committed Jun 17, 2024
1 parent bbf31ac commit d53fb72
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 135 deletions.
14 changes: 14 additions & 0 deletions docs/API/script/cppdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ Inherited properties: [CodeDocument properties](../script/codedocument.md#proper
||**[insertCodeInMethod](#insertCodeInMethod)**(string methodName, string code, Position insertAt)|
||**[insertForwardDeclaration](#insertForwardDeclaration)**(string forwardDeclaration)|
||**[insertInclude](#insertInclude)**(string include, bool newGroup = false)|
|QStringList |**[keywords](#keywords)**()|
|[DataExchange](../script/dataexchange.md) |**[mfcExtractDDX](#mfcExtractDDX)**(string className)|
|[MessageMap](../script/messagemap.md) |**[mfcExtractMessageMap](#mfcExtractMessageMap)**(string className = "")|
|[CppDocument](../script/cppdocument.md) |**[openHeaderSource](#openHeaderSource)**()|
|QStringList |**[primitiveTypes](#primitiveTypes)**()|
|[QueryMatch](../script/querymatch.md) |**[queryClassDefinition](#queryClassDefinition)**(string className)|
|array<[QueryMatch](../script/querymatch.md)> |**[queryFunctionCall](#queryFunctionCall)**(string functionName)|
|array<[QueryMatch](../script/querymatch.md)> |**[queryFunctionCall](#queryFunctionCall)**(string functionName, array<string> argumentCaptures)|
Expand Down Expand Up @@ -213,6 +215,12 @@ in the file.
If `newGroup` is true, it will insert the include at the end, with a new line separating the other includes.
#### <a name="keywords"></a>QStringList **keywords**()
Returns a list of cpp keywords
See: Utils::cppKeywords()
#### <a name="mfcExtractDDX"></a>[DataExchange](../script/dataexchange.md) **mfcExtractDDX**(string className)
Extracts the DDX information from a MFC class.
Expand All @@ -229,6 +237,12 @@ The `className` parameter can be used to ensure the result matches to a specific
Opens the corresponding source or header files, the current document is the new file.
If no files have been found, it's a no-op.
#### <a name="primitiveTypes"></a>QStringList **primitiveTypes**()
Returns a list of cpp primitive types
See Utils::cppPrimitiveTypes()
#### <a name="queryClassDefinition"></a>[QueryMatch](../script/querymatch.md) **queryClassDefinition**(string className)
Returns the class or struct definition matching the given `className`.
Expand Down
10 changes: 10 additions & 0 deletions docs/API/script/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Script 1.0
||**[addScriptPath](#addScriptPath)**(string path, bool projectOnly)|
|string |**[convertCase](#convertCase)**(string str, Case from, Case to)|
|string |**[copyToClipboard](#copyToClipboard)**(string text)|
|string |**[cppKeywords](#cppKeywords)**()|
|string |**[cppPrimitiveTypes](#cppPrimitiveTypes)**()|
|string |**[getEnv](#getEnv)**(string varName)|
|string |**[getGlobal](#getGlobal)**(string varName)|
|string |**[mktemp](#mktemp)**(string pattern)|
Expand Down Expand Up @@ -62,6 +64,14 @@ The different cases are:

Copy the text to the clipboard

#### <a name="cppKeywords"></a>string **cppKeywords**()

Returns a list of cpp keywords.

#### <a name="cppPrimitiveTypes"></a>string **cppPrimitiveTypes**()

Returns a list of cpp primitive types

#### <a name="getEnv"></a>string **getEnv**(string varName)

Returns the value of the environment variable `varName`.
Expand Down
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ set(PROJECT_SOURCES
conversionprogressdialog.h
conversionprogressdialog.cpp
conversionprogressdialog.ui
cpplanguagedata.h
cpplanguagedata.cpp
cppdocument.h
cppdocument.cpp
cppdocument_p.h
Expand Down
23 changes: 23 additions & 0 deletions src/core/cppdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "logger.h"
#include "project.h"
#include "settings.h"
#include "utils.h"
#include "utils/log.h"

#include <QFileInfo>
Expand Down Expand Up @@ -1519,4 +1520,26 @@ bool CppDocument::changeBaseClass(const QString &className, const QString &newCl
return changeBaseClass(header, source, className, newClassBaseName);
}

/*!
* \qmlmethod QStringList CppDocument::keywords()
* Returns a list of cpp keywords
*
* See: Utils::cppKeywords()
*/
QStringList CppDocument::keywords() const
{
return Utils::cppKeywords();
}

/*!
* \qmlmethod QStringList CppDocument::primitiveTypes()
* Returns a list of cpp primitive types
*
* See Utils::cppPrimitiveTypes()
*/
QStringList CppDocument::primitiveTypes() const
{
return Utils::cppPrimitiveTypes();
}

} // namespace Core
4 changes: 4 additions & 0 deletions src/core/cppdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ class CppDocument : public CodeDocument
Q_INVOKABLE Core::DataExchange mfcExtractDDX(const QString &className);
Q_INVOKABLE Core::MessageMap mfcExtractMessageMap(const QString &className = "");

Q_INVOKABLE QStringList keywords() const;
Q_INVOKABLE QStringList primitiveTypes() const;

bool changeBaseClass(CppDocument *header, CppDocument *source, const QString &className,
const QString &newClassBaseName);

public slots:
Core::CppDocument *openHeaderSource();

Expand Down
114 changes: 0 additions & 114 deletions src/core/cpplanguagedata.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions src/core/cpplanguagedata.h

This file was deleted.

1 change: 0 additions & 1 deletion src/core/functionsymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "functionsymbol.h"
#include "codedocument.h"
#include "cpplanguagedata.h"
#include "lsp/lsp_utils.h"
#include "utils/log.h"

Expand Down
113 changes: 113 additions & 0 deletions src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,117 @@ void Utils::copyToClipboard(const QString &text)
clipboard->setText(text);
}

/*!
* \qmlmethod string Utils::cppKeywords()
* Returns a list of cpp keywords.
*/
// Source: https://en.cppreference.com/w/cpp/keyword
// As of August 2022
//
// Added a 'readonly' (C++ attribute) keyword:
// Source: https://learn.microsoft.com/en-us/cpp/windows/attributes/readonly-cpp?view=msvc-170
// Prohibits assignment to a data member.
// Applies to Interface method.
// The readonly C++ attribute has the same functionality as the readonly MIDL attribute.
QStringList Utils::cppKeywords()
{
return QStringList {"alignas",
"alignof",
"and",
"and_eq",
"asm",
"atomic_cancel",
"atomic_commit",
"atomic_noexcept",
"auto",
"bitand",
"bitor",
"bool",
"break",
"case",
"catch",
"class",
"compl",
"concept",
"const",
"consteval",
"constexpr",
"constinit",
"const_cast",
"continue",
"co_await",
"co_return",
"co_yield",
"decltype",
"default",
"delete",
"do",
"dynamic_cast",
"else",
"enum",
"explicit",
"export",
"extern",
"false",
"for",
"friend",
"goto",
"if",
"inline",
"mutable",
"namespace",
"new",
"noexcept",
"not",
"not_eq",
"nullptr",
"operator",
"or",
"or_eq",
"private",
"protected",
"public",
"readonly",
"reflexpr",
"register",
"reinterpret_cast",
"requires",
"return",
"signed",
"sizeof",
"static",
"static_assert",
"static_cast",
"struct",
"switch",
"synchronized",
"template",
"this",
"thread_local",
"throw",
"true",
"try",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"volatile",
"while",
"xor",
"xor_eq"};
}

/*!
* \qmlmethod string Utils::cppPrimitiveTypes()
* Returns a list of cpp primitive types
*/
QStringList Utils::cppPrimitiveTypes()
{
return QStringList {"int", "long", "short", "void", "float", "double",
"char", "char8_t", "char16_t", "char32_t", "wchar_t"};
}

} // namespace Core
4 changes: 4 additions & 0 deletions src/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public slots:

static void copyToClipboard(const QString &text);

static QStringList cppKeywords();

static QStringList cppPrimitiveTypes();

private:
static QHash<QString, QString> m_globals;
};
Expand Down
Loading

0 comments on commit d53fb72

Please sign in to comment.