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:
Marco Bubke
2021-06-07 16:16:24 +02:00
parent a5789e2e47
commit 90cc7fed3b
6 changed files with 641 additions and 236 deletions

View File

@@ -102,6 +102,12 @@ public:
return importIds; 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, PropertyDeclarationId upsertPropertyDeclaration(TypeId typeId,
Utils::SmallStringView name, Utils::SmallStringView name,
TypeId propertyTypeId) TypeId propertyTypeId)
@@ -122,16 +128,10 @@ public:
return selectTypeIdByExportedNameStatement.template valueWithTransaction<TypeId>(name); return selectTypeIdByExportedNameStatement.template valueWithTransaction<TypeId>(name);
} }
TypeId fetchTypeIdByImportIdsAndExportedName(const ImportIds &importsIds, TypeId fetchTypeIdByImportIdsAndExportedName(ImportIds importIds, Utils::SmallStringView name) const
Utils::SmallStringView name) const
{ {
std::vector<ImportId::DatabaseType> ids; return selectTypeIdByImportIdsAndExportedNameStatement.template valueWithTransaction<TypeId>(
ids.resize(importsIds.size()); static_cast<void *>(importIds.data()), static_cast<long long>(importIds.size()), name);
std::memcpy(ids.data(), importsIds.data(), ids.size() * sizeof(ImportId::DatabaseType));
return selectTypeIdByImportIdsAndExportedNameStatement
.template valueWithTransaction<TypeId>(Utils::span{ids}, name);
} }
TypeId fetchTypeIdByName(ImportId importId, Utils::SmallStringView name) TypeId fetchTypeIdByName(ImportId importId, Utils::SmallStringView name)
@@ -465,7 +465,8 @@ private:
} }
void synchronizePropertyDeclarations(TypeId typeId, void synchronizePropertyDeclarations(TypeId typeId,
Storage::PropertyDeclarations &propertyDeclarations) Storage::PropertyDeclarations &propertyDeclarations,
ImportIds &importIds)
{ {
std::sort(propertyDeclarations.begin(), std::sort(propertyDeclarations.begin(),
propertyDeclarations.end(), propertyDeclarations.end(),
@@ -482,7 +483,7 @@ private:
}; };
auto insert = [&](const Storage::PropertyDeclaration &value) { auto insert = [&](const Storage::PropertyDeclaration &value) {
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName); auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName, importIds);
insertPropertyDeclarationStatement.write(&typeId, insertPropertyDeclarationStatement.write(&typeId,
value.name, value.name,
@@ -492,7 +493,7 @@ private:
auto update = [&](const Storage::PropertyDeclarationView &view, auto update = [&](const Storage::PropertyDeclarationView &view,
const Storage::PropertyDeclaration &value) { const Storage::PropertyDeclaration &value) {
auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName); auto propertyTypeId = fetchTypeIdByNameUngarded(value.typeName, importIds);
if (view.traits == value.traits && propertyTypeId == view.typeId) if (view.traits == value.traits && propertyTypeId == view.typeId)
return; return;
@@ -686,6 +687,9 @@ private:
static_cast<int>(type.accessSemantics), static_cast<int>(type.accessSemantics),
&type.sourceId); &type.sourceId);
for (const auto &exportedType : type.exportedTypes)
upsertExportedType(type.importId, exportedType.name, type.typeId);
return type.typeId; return type.typeId;
} }
@@ -693,25 +697,55 @@ private:
{ {
auto typeId = type.typeId; auto typeId = type.typeId;
auto prototypeId = fetchTypeIdByNameUngarded(type.prototype); auto prototypeId = fetchTypeIdByNameUngarded(type.prototype, type.importIds);
updatePrototypeStatement.write(&typeId, &prototypeId); updatePrototypeStatement.write(&typeId, &prototypeId);
for (const auto &exportedType : type.exportedTypes) synchronizePropertyDeclarations(typeId, type.propertyDeclarations, type.importIds);
upsertExportedType(type.importId, exportedType.qualifiedTypeName, typeId);
synchronizePropertyDeclarations(typeId, type.propertyDeclarations);
synchronizeFunctionDeclarations(typeId, type.functionDeclarations); synchronizeFunctionDeclarations(typeId, type.functionDeclarations);
synchronizeSignalDeclarations(typeId, type.signalDeclarations); synchronizeSignalDeclarations(typeId, type.signalDeclarations);
synchronizeEnumerationDeclarations(typeId, type.enumerationDeclarations); 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 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) SourceContextId readSourceContextId(Utils::SmallStringView sourceContextPath)
@@ -879,8 +913,7 @@ private:
typesTable.addForeignKeyColumn("prototypeId", typesTable.addForeignKeyColumn("prototypeId",
typesTable, typesTable,
Sqlite::ForeignKeyAction::NoAction, Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Restrict, Sqlite::ForeignKeyAction::Restrict);
Sqlite::Enforment::Deferred);
typesTable.addUniqueIndex({importIdColumn, typesNameColumn}); typesTable.addUniqueIndex({importIdColumn, typesNameColumn});
@@ -898,8 +931,7 @@ private:
propertyDeclarationTable.addForeignKeyColumn("propertyTypeId", propertyDeclarationTable.addForeignKeyColumn("propertyTypeId",
typesTable, typesTable,
Sqlite::ForeignKeyAction::NoAction, Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Restrict, Sqlite::ForeignKeyAction::Restrict);
Sqlite::Enforment::Deferred);
propertyDeclarationTable.addColumn("propertyTraits"); propertyDeclarationTable.addColumn("propertyTraits");
propertyDeclarationTable.addUniqueIndex({typeIdColumn, nameColumn}); propertyDeclarationTable.addUniqueIndex({typeIdColumn, nameColumn});
@@ -1068,8 +1100,8 @@ public:
"INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database}; "INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database};
mutable ReadStatement<3> selectAllSourcesStatement{ mutable ReadStatement<3> selectAllSourcesStatement{
"SELECT sourceName, sourceContextId, sourceId FROM sources", database}; "SELECT sourceName, sourceContextId, sourceId FROM sources", database};
mutable ReadStatement<1> selectTypeIdByNameStatement{"SELECT typeId FROM types WHERE name=?", mutable ReadStatement<1> selectTypeIdByImportIdsAndNameStatement{
database}; "SELECT typeId FROM types WHERE importId IN carray(?1, ?2, 'int64') AND name=?3", database};
mutable ReadStatement<5> selectTypeByTypeIdStatement{ mutable ReadStatement<5> selectTypeByTypeIdStatement{
"SELECT importId, name, (SELECT name FROM types WHERE typeId=outerTypes.prototypeId), " "SELECT importId, name, (SELECT name FROM types WHERE typeId=outerTypes.prototypeId), "
"accessSemantics, ifnull(sourceId, -1) FROM types AS outerTypes WHERE typeId=?", "accessSemantics, ifnull(sourceId, -1) FROM types AS outerTypes WHERE typeId=?",
@@ -1204,7 +1236,18 @@ public:
mutable ReadStatement<1> selectTypeIdByImportIdAndNameStatement{ mutable ReadStatement<1> selectTypeIdByImportIdAndNameStatement{
"SELECT typeId FROM types WHERE importId=?1 and name=?2", database}; "SELECT typeId FROM types WHERE importId=?1 and name=?2", database};
mutable ReadStatement<1> selectTypeIdByImportIdsAndExportedNameStatement{ 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 } // namespace QmlDesigner

View File

@@ -74,7 +74,13 @@ public:
class ImportDoesNotExists : std::exception class ImportDoesNotExists : std::exception
{ {
public: 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 } // namespace QmlDesigner

View File

@@ -28,6 +28,7 @@
#include "projectstorageids.h" #include "projectstorageids.h"
#include <utils/smallstring.h> #include <utils/smallstring.h>
#include <utils/variant.h>
#include <vector> #include <vector>
@@ -105,16 +106,44 @@ class ExportedType
{ {
public: public:
explicit ExportedType() = default; explicit ExportedType() = default;
explicit ExportedType(Utils::SmallStringView qualifiedTypeName) explicit ExportedType(Utils::SmallStringView name)
: qualifiedTypeName{qualifiedTypeName} : name{name}
{} {}
public: 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>; 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 class EnumeratorDeclaration
{ {
public: public:
@@ -316,23 +345,21 @@ class PropertyDeclaration
{ {
public: public:
explicit PropertyDeclaration() = default; explicit PropertyDeclaration() = default;
explicit PropertyDeclaration(Utils::SmallStringView name, explicit PropertyDeclaration(Utils::SmallStringView name, TypeName typeName, DeclarationTraits traits)
Utils::SmallStringView typeName,
DeclarationTraits traits)
: name{name} : name{name}
, typeName{typeName} , typeName{std::move(typeName)}
, traits{traits} , traits{traits}
{} {}
explicit PropertyDeclaration(Utils::SmallStringView name, Utils::SmallStringView typeName, int traits) explicit PropertyDeclaration(Utils::SmallStringView name, Utils::SmallStringView typeName, int traits)
: name{name} : name{name}
, typeName{typeName} , typeName{NativeType{typeName}}
, traits{static_cast<DeclarationTraits>(traits)} , traits{static_cast<DeclarationTraits>(traits)}
{} {}
public: public:
Utils::SmallString name; Utils::SmallString name;
Utils::SmallString typeName; TypeName typeName;
DeclarationTraits traits = {}; DeclarationTraits traits = {};
TypeId typeId; TypeId typeId;
}; };
@@ -366,9 +393,10 @@ public:
explicit Type() = default; explicit Type() = default;
explicit Type(ImportId importId, explicit Type(ImportId importId,
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
Utils::SmallStringView prototype, TypeName prototype,
TypeAccessSemantics accessSemantics, TypeAccessSemantics accessSemantics,
SourceId sourceId, SourceId sourceId,
ImportIds importIds = {},
ExportedTypes exportedTypes = {}, ExportedTypes exportedTypes = {},
PropertyDeclarations propertyDeclarations = {}, PropertyDeclarations propertyDeclarations = {},
FunctionDeclarations functionDeclarations = {}, FunctionDeclarations functionDeclarations = {},
@@ -376,7 +404,8 @@ public:
EnumerationDeclarations enumerationDeclarations = {}, EnumerationDeclarations enumerationDeclarations = {},
TypeId typeId = TypeId{}) TypeId typeId = TypeId{})
: typeName{typeName} : typeName{typeName}
, prototype{prototype} , prototype{std::move(prototype)}
, importIds{std::move(importIds)}
, exportedTypes{std::move(exportedTypes)} , exportedTypes{std::move(exportedTypes)}
, propertyDeclarations{std::move(propertyDeclarations)} , propertyDeclarations{std::move(propertyDeclarations)}
, functionDeclarations{std::move(functionDeclarations)} , functionDeclarations{std::move(functionDeclarations)}
@@ -394,7 +423,7 @@ public:
int accessSemantics, int accessSemantics,
int sourceId) int sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{prototype} , prototype{NativeType{prototype}}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)} , accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
, sourceId{sourceId} , sourceId{sourceId}
, importId{importId} , importId{importId}
@@ -408,7 +437,7 @@ public:
int accessSemantics, int accessSemantics,
int sourceId) int sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{prototype} , prototype{NativeType{prototype}}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)} , accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
, sourceId{sourceId} , sourceId{sourceId}
, typeId{typeId} , typeId{typeId}
@@ -417,8 +446,9 @@ public:
public: public:
Utils::SmallString typeName; Utils::SmallString typeName;
Utils::SmallString prototype; TypeName prototype;
Utils::SmallString attachedType; Utils::SmallString attachedType;
ImportIds importIds;
ExportedTypes exportedTypes; ExportedTypes exportedTypes;
PropertyDeclarations propertyDeclarations; PropertyDeclarations propertyDeclarations;
FunctionDeclarations functionDeclarations; FunctionDeclarations functionDeclarations;

View File

@@ -1022,19 +1022,33 @@ std::ostream &operator<<(std::ostream &out, Version version)
std::ostream &operator<<(std::ostream &out, const ExportedType &exportedType) 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) std::ostream &operator<<(std::ostream &out, const Type &type)
{ {
return out << "(import: " << type.importId << ", \"" << type.typeName << "\", \"" using Utils::operator<<;
<< type.prototype << "\", " << type.accessSemantics << ", source: " << type.sourceId return out << "(import: " << type.importId << ", typename: \"" << type.typeName
<< ", " << type.exportedTypes << ", " << type.propertyDeclarations << ", " << "\", prototype: \"" << type.prototype << "\", " << type.accessSemantics
<< type.functionDeclarations << ", " << type.signalDeclarations << ")"; << ", source: " << type.sourceId << ", exports: " << type.exportedTypes
<< ", properties: " << type.propertyDeclarations
<< ", functions: " << type.functionDeclarations
<< ", signals: " << type.signalDeclarations << ")";
} }
std::ostream &operator<<(std::ostream &out, const PropertyDeclaration &propertyDeclaration) std::ostream &operator<<(std::ostream &out, const PropertyDeclaration &propertyDeclaration)
{ {
using Utils::operator<<;
return out << "(\"" << propertyDeclaration.name << "\", \"" << propertyDeclaration.typeName return out << "(\"" << propertyDeclaration.name << "\", \"" << propertyDeclaration.typeName
<< "\", " << propertyDeclaration.traits << ", " << propertyDeclaration.typeId << ")"; << "\", " << propertyDeclaration.traits << ", " << propertyDeclaration.typeId << ")";
} }

View File

@@ -26,8 +26,9 @@
#pragma once #pragma once
#include <utils/cpplanguage_details.h> #include <utils/cpplanguage_details.h>
#include <utils/smallstringio.h>
#include <utils/optional.h> #include <utils/optional.h>
#include <utils/smallstringio.h>
#include <utils/variant.h>
#include <clangsupport_global.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 Utils::LanguageExtension &languageExtension);
std::ostream &operator<<(std::ostream &out, const FilePath &filePath); std::ostream &operator<<(std::ostream &out, const FilePath &filePath);
template <typename Type> template<typename Type>
std::ostream &operator<<(std::ostream &out, const Utils::optional<Type> &optional) std::ostream &operator<<(std::ostream &out, const optional<Type> &optional)
{ {
if (optional) if (optional)
return out << "optional " << optional.value(); return out << "optional " << optional.value();
@@ -91,12 +92,18 @@ std::ostream &operator<<(std::ostream &out, const Utils::optional<Type> &optiona
return out << "empty optional()"; return out << "empty optional()";
} }
template <typename Type> template<typename Type>
void PrintTo(const Utils::optional<Type> &optional, ::std::ostream *os) void PrintTo(const optional<Type> &optional, ::std::ostream *os)
{ {
*os << optional; *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(Utils::SmallStringView text, ::std::ostream *os);
void PrintTo(const Utils::SmallString &text, ::std::ostream *os); void PrintTo(const Utils::SmallString &text, ::std::ostream *os);
void PrintTo(const Utils::PathString &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 { namespace Storage {
class Type; class Type;
class ExportedType; class ExportedType;
class NativeType;
class ExplicitExportedType;
using TypeName = Utils::variant<NativeType, ExportedType, ExplicitExportedType>;
class Version; class Version;
class VersionNumber; class VersionNumber;
enum class TypeAccessSemantics : int; 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, Version version);
std::ostream &operator<<(std::ostream &out, const Type &type); 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 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, const PropertyDeclaration &propertyDeclaration);
std::ostream &operator<<(std::ostream &out, DeclarationTraits traits); std::ostream &operator<<(std::ostream &out, DeclarationTraits traits);
std::ostream &operator<<(std::ostream &out, const FunctionDeclaration &functionDeclaration); std::ostream &operator<<(std::ostream &out, const FunctionDeclaration &functionDeclaration);

File diff suppressed because it is too large Load Diff