forked from qt-creator/qt-creator
QmlDesigner: Handle implicit and explicit type names
Types are now handled by their import. Impicitly by an import list or explicit for exported type. Task-number: QDS-4496 Change-Id: I63f40df32760389e25b73597b4363f95ee304592 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -102,6 +102,12 @@ public:
|
||||
return importIds;
|
||||
}
|
||||
|
||||
ImportIds fetchImportDependencyIds(ImportIds importIds) const
|
||||
{
|
||||
return fetchImportDependencyIdsStatement.template valuesWithTransaction<ImportId>(
|
||||
16, static_cast<void *>(importIds.data()), static_cast<long long>(importIds.size()));
|
||||
}
|
||||
|
||||
PropertyDeclarationId upsertPropertyDeclaration(TypeId typeId,
|
||||
Utils::SmallStringView name,
|
||||
TypeId propertyTypeId)
|
||||
@@ -122,16 +128,10 @@ public:
|
||||
return selectTypeIdByExportedNameStatement.template valueWithTransaction<TypeId>(name);
|
||||
}
|
||||
|
||||
TypeId fetchTypeIdByImportIdsAndExportedName(const ImportIds &importsIds,
|
||||
Utils::SmallStringView name) const
|
||||
TypeId fetchTypeIdByImportIdsAndExportedName(ImportIds importIds, Utils::SmallStringView name) const
|
||||
{
|
||||
std::vector<ImportId::DatabaseType> ids;
|
||||
ids.resize(importsIds.size());
|
||||
|
||||
std::memcpy(ids.data(), importsIds.data(), ids.size() * sizeof(ImportId::DatabaseType));
|
||||
|
||||
return selectTypeIdByImportIdsAndExportedNameStatement
|
||||
.template valueWithTransaction<TypeId>(Utils::span{ids}, name);
|
||||
return selectTypeIdByImportIdsAndExportedNameStatement.template valueWithTransaction<TypeId>(
|
||||
static_cast<void *>(importIds.data()), static_cast<long long>(importIds.size()), name);
|
||||
}
|
||||
|
||||
TypeId fetchTypeIdByName(ImportId importId, Utils::SmallStringView name)
|
||||
@@ -465,7 +465,8 @@ private:
|
||||
}
|
||||
|
||||
void synchronizePropertyDeclarations(TypeId typeId,
|
||||
Storage::PropertyDeclarations &propertyDeclarations)
|
||||
Storage::PropertyDeclarations &propertyDeclarations,
|
||||
ImportIds &importIds)
|
||||
{
|
||||
std::sort(propertyDeclarations.begin(),
|
||||
propertyDeclarations.end(),
|
||||
@@ -482,7 +483,7 @@ private:
|
||||
};
|
||||
|
||||
auto insert = [&](const Storage::PropertyDeclaration &value) {
|
||||
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName);
|
||||
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName, importIds);
|
||||
|
||||
insertPropertyDeclarationStatement.write(&typeId,
|
||||
value.name,
|
||||
@@ -492,7 +493,7 @@ private:
|
||||
|
||||
auto update = [&](const Storage::PropertyDeclarationView &view,
|
||||
const Storage::PropertyDeclaration &value) {
|
||||
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName);
|
||||
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName, importIds);
|
||||
|
||||
if (view.traits == value.traits && propertyTypeId == view.typeId)
|
||||
return;
|
||||
@@ -686,6 +687,9 @@ private:
|
||||
static_cast<int>(type.accessSemantics),
|
||||
&type.sourceId);
|
||||
|
||||
for (const auto &exportedType : type.exportedTypes)
|
||||
upsertExportedType(type.importId, exportedType.name, type.typeId);
|
||||
|
||||
return type.typeId;
|
||||
}
|
||||
|
||||
@@ -693,25 +697,55 @@ private:
|
||||
{
|
||||
auto typeId = type.typeId;
|
||||
|
||||
auto prototypeId = fetchTypeIdByNameUngarded(type.prototype);
|
||||
auto prototypeId = fetchTypeIdByNameUngarded(type.prototype, type.importIds);
|
||||
|
||||
updatePrototypeStatement.write(&typeId, &prototypeId);
|
||||
|
||||
for (const auto &exportedType : type.exportedTypes)
|
||||
upsertExportedType(type.importId, exportedType.qualifiedTypeName, typeId);
|
||||
|
||||
synchronizePropertyDeclarations(typeId, type.propertyDeclarations);
|
||||
synchronizePropertyDeclarations(typeId, type.propertyDeclarations, type.importIds);
|
||||
synchronizeFunctionDeclarations(typeId, type.functionDeclarations);
|
||||
synchronizeSignalDeclarations(typeId, type.signalDeclarations);
|
||||
synchronizeEnumerationDeclarations(typeId, type.enumerationDeclarations);
|
||||
}
|
||||
|
||||
TypeId fetchTypeIdByNameUngarded(Utils::SmallStringView name)
|
||||
TypeId fetchTypeIdByNameUngarded(const Storage::TypeName &name, ImportIds &importIds)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
if (Utils::visit([](auto &&type) -> bool { return type.name.isEmpty(); }, name))
|
||||
return TypeId{};
|
||||
|
||||
return selectTypeIdByNameStatement.template value<TypeId>(name);
|
||||
struct Inspect
|
||||
{
|
||||
TypeId operator()(const Storage::NativeType &nativeType)
|
||||
{
|
||||
return storage.selectTypeIdByImportIdsAndNameStatement
|
||||
.template value<TypeId>(static_cast<void *>(importIds.data()),
|
||||
static_cast<long long>(importIds.size()),
|
||||
nativeType.name);
|
||||
}
|
||||
|
||||
TypeId operator()(const Storage::ExportedType &exportedType)
|
||||
{
|
||||
return storage.selectTypeIdByImportIdsAndExportedNameStatement
|
||||
.template value<TypeId>(static_cast<void *>(importIds.data()),
|
||||
static_cast<long long>(importIds.size()),
|
||||
exportedType.name);
|
||||
}
|
||||
|
||||
TypeId operator()(const Storage::ExplicitExportedType &exportedType)
|
||||
{
|
||||
return storage.selectTypeIdByImportIdAndExportedNameStatement
|
||||
.template value<TypeId>(&exportedType.importId, exportedType.name);
|
||||
}
|
||||
|
||||
ProjectStorage &storage;
|
||||
ImportIds &importIds;
|
||||
};
|
||||
|
||||
auto typeId = Utils::visit(Inspect{*this, importIds}, name);
|
||||
|
||||
if (typeId)
|
||||
return typeId;
|
||||
|
||||
throw TypeNameDoesNotExists{};
|
||||
}
|
||||
|
||||
SourceContextId readSourceContextId(Utils::SmallStringView sourceContextPath)
|
||||
@@ -879,8 +913,7 @@ private:
|
||||
typesTable.addForeignKeyColumn("prototypeId",
|
||||
typesTable,
|
||||
Sqlite::ForeignKeyAction::NoAction,
|
||||
Sqlite::ForeignKeyAction::Restrict,
|
||||
Sqlite::Enforment::Deferred);
|
||||
Sqlite::ForeignKeyAction::Restrict);
|
||||
|
||||
typesTable.addUniqueIndex({importIdColumn, typesNameColumn});
|
||||
|
||||
@@ -898,8 +931,7 @@ private:
|
||||
propertyDeclarationTable.addForeignKeyColumn("propertyTypeId",
|
||||
typesTable,
|
||||
Sqlite::ForeignKeyAction::NoAction,
|
||||
Sqlite::ForeignKeyAction::Restrict,
|
||||
Sqlite::Enforment::Deferred);
|
||||
Sqlite::ForeignKeyAction::Restrict);
|
||||
propertyDeclarationTable.addColumn("propertyTraits");
|
||||
|
||||
propertyDeclarationTable.addUniqueIndex({typeIdColumn, nameColumn});
|
||||
@@ -1068,8 +1100,8 @@ public:
|
||||
"INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database};
|
||||
mutable ReadStatement<3> selectAllSourcesStatement{
|
||||
"SELECT sourceName, sourceContextId, sourceId FROM sources", database};
|
||||
mutable ReadStatement<1> selectTypeIdByNameStatement{"SELECT typeId FROM types WHERE name=?",
|
||||
database};
|
||||
mutable ReadStatement<1> selectTypeIdByImportIdsAndNameStatement{
|
||||
"SELECT typeId FROM types WHERE importId IN carray(?1, ?2, 'int64') AND name=?3", database};
|
||||
mutable ReadStatement<5> selectTypeByTypeIdStatement{
|
||||
"SELECT importId, name, (SELECT name FROM types WHERE typeId=outerTypes.prototypeId), "
|
||||
"accessSemantics, ifnull(sourceId, -1) FROM types AS outerTypes WHERE typeId=?",
|
||||
@@ -1204,7 +1236,18 @@ public:
|
||||
mutable ReadStatement<1> selectTypeIdByImportIdAndNameStatement{
|
||||
"SELECT typeId FROM types WHERE importId=?1 and name=?2", database};
|
||||
mutable ReadStatement<1> selectTypeIdByImportIdsAndExportedNameStatement{
|
||||
"SELECT typeId FROM exportedTypes WHERE importId IN carray(?1) AND name=?2", database};
|
||||
"SELECT typeId FROM exportedTypes WHERE importId IN carray(?1, ?2, 'int64') AND name=?3",
|
||||
database};
|
||||
mutable ReadStatement<1> selectTypeIdByImportIdAndExportedNameStatement{
|
||||
"SELECT typeId FROM exportedTypes WHERE importId=?1 AND name=?2", database};
|
||||
mutable ReadStatement<1> fetchImportDependencyIdsStatement{
|
||||
"WITH RECURSIVE "
|
||||
" importIds(importId) AS ("
|
||||
" SELECT value FROM carray(?1, ?2, 'int64') "
|
||||
" UNION "
|
||||
" SELECT parentImportId FROM importDependencies JOIN importIds USING(importId)) "
|
||||
"SELECT importId FROM importIds",
|
||||
database};
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -74,7 +74,13 @@ public:
|
||||
class ImportDoesNotExists : std::exception
|
||||
{
|
||||
public:
|
||||
const char *what() const noexcept override { return "The simport does not exist!"; }
|
||||
const char *what() const noexcept override { return "The import does not exist!"; }
|
||||
};
|
||||
|
||||
class TypeNameDoesNotExists : std::exception
|
||||
{
|
||||
public:
|
||||
const char *what() const noexcept override { return "The type name does not exist!"; }
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "projectstorageids.h"
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
#include <utils/variant.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -105,16 +106,44 @@ class ExportedType
|
||||
{
|
||||
public:
|
||||
explicit ExportedType() = default;
|
||||
explicit ExportedType(Utils::SmallStringView qualifiedTypeName)
|
||||
: qualifiedTypeName{qualifiedTypeName}
|
||||
explicit ExportedType(Utils::SmallStringView name)
|
||||
: name{name}
|
||||
{}
|
||||
|
||||
public:
|
||||
Utils::SmallString qualifiedTypeName;
|
||||
Utils::SmallString name;
|
||||
};
|
||||
|
||||
class ExplicitExportedType
|
||||
{
|
||||
public:
|
||||
explicit ExplicitExportedType() = default;
|
||||
explicit ExplicitExportedType(Utils::SmallStringView name, ImportId importId)
|
||||
: name{name}
|
||||
, importId{importId}
|
||||
{}
|
||||
|
||||
public:
|
||||
Utils::SmallString name;
|
||||
ImportId importId;
|
||||
};
|
||||
|
||||
using ExportedTypes = std::vector<ExportedType>;
|
||||
|
||||
class NativeType
|
||||
{
|
||||
public:
|
||||
explicit NativeType() = default;
|
||||
explicit NativeType(Utils::SmallStringView name)
|
||||
: name{name}
|
||||
{}
|
||||
|
||||
public:
|
||||
Utils::SmallString name;
|
||||
};
|
||||
|
||||
using TypeName = Utils::variant<NativeType, ExportedType, ExplicitExportedType>;
|
||||
|
||||
class EnumeratorDeclaration
|
||||
{
|
||||
public:
|
||||
@@ -316,23 +345,21 @@ class PropertyDeclaration
|
||||
{
|
||||
public:
|
||||
explicit PropertyDeclaration() = default;
|
||||
explicit PropertyDeclaration(Utils::SmallStringView name,
|
||||
Utils::SmallStringView typeName,
|
||||
DeclarationTraits traits)
|
||||
explicit PropertyDeclaration(Utils::SmallStringView name, TypeName typeName, DeclarationTraits traits)
|
||||
: name{name}
|
||||
, typeName{typeName}
|
||||
, typeName{std::move(typeName)}
|
||||
, traits{traits}
|
||||
{}
|
||||
|
||||
explicit PropertyDeclaration(Utils::SmallStringView name, Utils::SmallStringView typeName, int traits)
|
||||
: name{name}
|
||||
, typeName{typeName}
|
||||
, typeName{NativeType{typeName}}
|
||||
, traits{static_cast<DeclarationTraits>(traits)}
|
||||
{}
|
||||
|
||||
public:
|
||||
Utils::SmallString name;
|
||||
Utils::SmallString typeName;
|
||||
TypeName typeName;
|
||||
DeclarationTraits traits = {};
|
||||
TypeId typeId;
|
||||
};
|
||||
@@ -366,9 +393,10 @@ public:
|
||||
explicit Type() = default;
|
||||
explicit Type(ImportId importId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView prototype,
|
||||
TypeName prototype,
|
||||
TypeAccessSemantics accessSemantics,
|
||||
SourceId sourceId,
|
||||
ImportIds importIds = {},
|
||||
ExportedTypes exportedTypes = {},
|
||||
PropertyDeclarations propertyDeclarations = {},
|
||||
FunctionDeclarations functionDeclarations = {},
|
||||
@@ -376,7 +404,8 @@ public:
|
||||
EnumerationDeclarations enumerationDeclarations = {},
|
||||
TypeId typeId = TypeId{})
|
||||
: typeName{typeName}
|
||||
, prototype{prototype}
|
||||
, prototype{std::move(prototype)}
|
||||
, importIds{std::move(importIds)}
|
||||
, exportedTypes{std::move(exportedTypes)}
|
||||
, propertyDeclarations{std::move(propertyDeclarations)}
|
||||
, functionDeclarations{std::move(functionDeclarations)}
|
||||
@@ -394,7 +423,7 @@ public:
|
||||
int accessSemantics,
|
||||
int sourceId)
|
||||
: typeName{typeName}
|
||||
, prototype{prototype}
|
||||
, prototype{NativeType{prototype}}
|
||||
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
|
||||
, sourceId{sourceId}
|
||||
, importId{importId}
|
||||
@@ -408,7 +437,7 @@ public:
|
||||
int accessSemantics,
|
||||
int sourceId)
|
||||
: typeName{typeName}
|
||||
, prototype{prototype}
|
||||
, prototype{NativeType{prototype}}
|
||||
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
|
||||
, sourceId{sourceId}
|
||||
, typeId{typeId}
|
||||
@@ -417,8 +446,9 @@ public:
|
||||
|
||||
public:
|
||||
Utils::SmallString typeName;
|
||||
Utils::SmallString prototype;
|
||||
TypeName prototype;
|
||||
Utils::SmallString attachedType;
|
||||
ImportIds importIds;
|
||||
ExportedTypes exportedTypes;
|
||||
PropertyDeclarations propertyDeclarations;
|
||||
FunctionDeclarations functionDeclarations;
|
||||
|
@@ -1022,19 +1022,33 @@ std::ostream &operator<<(std::ostream &out, Version version)
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ExportedType &exportedType)
|
||||
{
|
||||
return out << "(\"" << exportedType.qualifiedTypeName << "\")";
|
||||
return out << "(\"" << exportedType.name << "\")";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ExplicitExportedType &exportedType)
|
||||
{
|
||||
return out << "(\"" << exportedType.name << "\"" << exportedType.importId << ")";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const NativeType &nativeType)
|
||||
{
|
||||
return out << "(\"" << nativeType.name << "\")";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Type &type)
|
||||
{
|
||||
return out << "(import: " << type.importId << ", \"" << type.typeName << "\", \""
|
||||
<< type.prototype << "\", " << type.accessSemantics << ", source: " << type.sourceId
|
||||
<< ", " << type.exportedTypes << ", " << type.propertyDeclarations << ", "
|
||||
<< type.functionDeclarations << ", " << type.signalDeclarations << ")";
|
||||
using Utils::operator<<;
|
||||
return out << "(import: " << type.importId << ", typename: \"" << type.typeName
|
||||
<< "\", prototype: \"" << type.prototype << "\", " << type.accessSemantics
|
||||
<< ", source: " << type.sourceId << ", exports: " << type.exportedTypes
|
||||
<< ", properties: " << type.propertyDeclarations
|
||||
<< ", functions: " << type.functionDeclarations
|
||||
<< ", signals: " << type.signalDeclarations << ")";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const PropertyDeclaration &propertyDeclaration)
|
||||
{
|
||||
using Utils::operator<<;
|
||||
return out << "(\"" << propertyDeclaration.name << "\", \"" << propertyDeclaration.typeName
|
||||
<< "\", " << propertyDeclaration.traits << ", " << propertyDeclaration.typeId << ")";
|
||||
}
|
||||
|
@@ -26,8 +26,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/cpplanguage_details.h>
|
||||
#include <utils/smallstringio.h>
|
||||
#include <utils/optional.h>
|
||||
#include <utils/smallstringio.h>
|
||||
#include <utils/variant.h>
|
||||
|
||||
#include <clangsupport_global.h>
|
||||
|
||||
@@ -82,8 +83,8 @@ std::ostream &operator<<(std::ostream &out, const Utils::LanguageVersion &langua
|
||||
std::ostream &operator<<(std::ostream &out, const Utils::LanguageExtension &languageExtension);
|
||||
std::ostream &operator<<(std::ostream &out, const FilePath &filePath);
|
||||
|
||||
template <typename Type>
|
||||
std::ostream &operator<<(std::ostream &out, const Utils::optional<Type> &optional)
|
||||
template<typename Type>
|
||||
std::ostream &operator<<(std::ostream &out, const optional<Type> &optional)
|
||||
{
|
||||
if (optional)
|
||||
return out << "optional " << optional.value();
|
||||
@@ -91,12 +92,18 @@ std::ostream &operator<<(std::ostream &out, const Utils::optional<Type> &optiona
|
||||
return out << "empty optional()";
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void PrintTo(const Utils::optional<Type> &optional, ::std::ostream *os)
|
||||
template<typename Type>
|
||||
void PrintTo(const optional<Type> &optional, ::std::ostream *os)
|
||||
{
|
||||
*os << optional;
|
||||
}
|
||||
|
||||
template<typename... Type>
|
||||
std::ostream &operator<<(std::ostream &out, const variant<Type...> &variant)
|
||||
{
|
||||
return Utils::visit([&](auto &&value) -> std::ostream & { return out << value; }, variant);
|
||||
}
|
||||
|
||||
void PrintTo(Utils::SmallStringView text, ::std::ostream *os);
|
||||
void PrintTo(const Utils::SmallString &text, ::std::ostream *os);
|
||||
void PrintTo(const Utils::PathString &text, ::std::ostream *os);
|
||||
@@ -230,6 +237,9 @@ std::ostream &operator<<(std::ostream &out, const SourceContext &sourceContext);
|
||||
namespace Storage {
|
||||
class Type;
|
||||
class ExportedType;
|
||||
class NativeType;
|
||||
class ExplicitExportedType;
|
||||
using TypeName = Utils::variant<NativeType, ExportedType, ExplicitExportedType>;
|
||||
class Version;
|
||||
class VersionNumber;
|
||||
enum class TypeAccessSemantics : int;
|
||||
@@ -248,6 +258,8 @@ std::ostream &operator<<(std::ostream &out, VersionNumber versionNumber);
|
||||
std::ostream &operator<<(std::ostream &out, Version version);
|
||||
std::ostream &operator<<(std::ostream &out, const Type &type);
|
||||
std::ostream &operator<<(std::ostream &out, const ExportedType &exportedType);
|
||||
std::ostream &operator<<(std::ostream &out, const NativeType &nativeType);
|
||||
std::ostream &operator<<(std::ostream &out, const ExplicitExportedType &exportedType);
|
||||
std::ostream &operator<<(std::ostream &out, const PropertyDeclaration &propertyDeclaration);
|
||||
std::ostream &operator<<(std::ostream &out, DeclarationTraits traits);
|
||||
std::ostream &operator<<(std::ostream &out, const FunctionDeclaration &functionDeclaration);
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user