-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This symbol has information about the type of whatever it represents. Care has also been taken to support pointers, const-qualifiers and other type specifiers.
- Loading branch information
1 parent
8c0e224
commit f662fc5
Showing
9 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# TypedSymbol | ||
|
||
Represents a symbol with a type [More...](#detailed-description) | ||
|
||
```qml | ||
import Knut | ||
``` | ||
|
||
## Properties | ||
|
||
| | Name | | ||
|-|-| | ||
|string|**[type](#type)**| | ||
|
||
## Detailed Description | ||
|
||
This symbol has a type associated with it, like a variable or a member of a class. | ||
|
||
## Property Documentation | ||
|
||
#### <a name="type"></a>string **type** | ||
|
||
The type of this symbol. | ||
|
||
The type is the part of the symbol that describes what kind of value it holds. For example, the type of a variable. | ||
This symbol will extract the type as-written in the original source, but with whitespace | ||
[simplified](https://doc.qt.io/qt-6/qstring.html#simplified). So if e.g. the source code is `const string &`, it | ||
will be extracted as `const string &`. The type will **not** be resolved to a fully qualified path (like | ||
`std::string` for the previous example). | ||
|
||
This property is read-only. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "typedsymbol.h" | ||
|
||
#include <kdalgorithms.h> | ||
|
||
namespace Core { | ||
|
||
/*! | ||
* \qmltype TypedSymbol | ||
* \brief Represents a symbol with a type | ||
* \inqmlmodule Knut | ||
* \ingroup CodeDocument | ||
* | ||
* This symbol has a type associated with it, like a variable or a member of a class. | ||
*/ | ||
|
||
/*! | ||
* \qmlproperty string TypedSymbol::type | ||
* The type of this symbol. | ||
* | ||
* The type is the part of the symbol that describes what kind of value it holds. For example, the type of a variable. | ||
* This symbol will extract the type as-written in the original source, but with whitespace | ||
* [simplified](https://doc.qt.io/qt-6/qstring.html#simplified). So if e.g. the source code is `const string &`, it | ||
* will be extracted as `const string &`. The type will **not** be resolved to a fully qualified path (like | ||
* `std::string` for the previous example). | ||
* | ||
* This property is read-only. | ||
*/ | ||
|
||
TypedSymbol::TypedSymbol(QObject *parent, const QueryMatch &match, Kind kind) | ||
: Symbol(parent, match, kind) | ||
{ | ||
// C++ has a strange way of parsing, where pointer and reference specifiers are parsed as a parent | ||
// of the identifier, and not part of the type. The easiest way to remedy this is to get the whole | ||
// range spanning the type and name and then erase the name. | ||
auto typeAndName = match.getAllJoined("typeAndName"); | ||
if (typeAndName.isValid()) { | ||
m_type = typeAndName.textExcept(match.get("name")).simplified(); | ||
} else { | ||
m_type = kdalgorithms::transformed(match.getAll("type"), &RangeMark::text).join(" ").simplified(); | ||
} | ||
} | ||
|
||
QString TypedSymbol::type() const | ||
{ | ||
return m_type; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "symbol.h" | ||
|
||
namespace Core { | ||
|
||
class TypedSymbol : public Symbol | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(QString type READ type CONSTANT) | ||
|
||
public: | ||
QString type() const; | ||
|
||
private: | ||
friend class Symbol; | ||
TypedSymbol(QObject *parent, const QueryMatch &match, Kind kind); | ||
|
||
QString m_type; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
class TestClass { | ||
private: | ||
void *m_ptr; | ||
const std::string &m_lvalue_reference; | ||
std::string&& m_rvalue_reference; | ||
const class T*const m_const_ptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters