diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp index 1db0c63..9530cad 100644 --- a/duchain/declarationbuilder.cpp +++ b/duchain/declarationbuilder.cpp @@ -1,158 +1,156 @@ #include "declarationbuilder.h" #include #include #include "types/declarationtypes.h" #include "nodetraits.h" #include "rustdebug.h" namespace Rust { using namespace KDevelop; RSVisitResult DeclarationBuilder::visitNode(RustNode *node, RustNode *parent) { RSNodeKind kind = node_get_kind(node->data()); switch (kind) { case Module: return buildDeclaration(node, parent); case StructDecl: return buildDeclaration(node, parent); case EnumDecl: return buildDeclaration(node, parent); case FunctionDecl: return buildDeclaration(node, parent); - case ImplDecl: - return buildDeclaration(node, parent); case TraitDecl: return buildDeclaration(node, parent); case TypeAliasDecl: return buildDeclaration(node, parent); case EnumVariantDecl: return buildDeclaration(node, parent); case FieldDecl: return buildDeclaration(node, parent); case VarDecl: return buildDeclaration(node, parent); default: return ContextBuilder::visitNode(node, parent); } } template RSVisitResult DeclarationBuilder::buildDeclaration(RustNode *node, RustNode *parent) { Q_UNUSED(parent); constexpr bool hasContext = NodeTraits::hasContext(Kind); RustPath name(node); createDeclaration(node, &name, hasContext); RSVisitResult ret = buildContext(node, parent); if (hasContext) eventuallyAssignInternalContext(); closeDeclaration(); return ret; } template Declaration *DeclarationBuilder::createDeclaration(RustNode *node, RustPath *name, bool hasContext) { auto range = editorFindSpellingRange(node, name->value); typename DeclType::Type *decl = openDeclaration::Type>(Identifier(name->value), range, hasContext ? DeclarationIsDefinition : NoFlags); if (NodeTraits::isTypeDeclaration(Kind)) { decl->setKind(Declaration::Type); } auto type = createType(node); openType(type); setDeclData(decl); setType(decl, type.data()); closeType(); return decl; } template > typename IdType::Type::Ptr DeclarationBuilder::createType(RustNode *node) { Q_UNUSED(node); return typename IdType::Type::Ptr(new typename IdType::Type); } template > FunctionType::Ptr DeclarationBuilder::createType(RustNode *node) { Q_UNUSED(node); return FunctionType::Ptr(new FunctionType); } template > AbstractType::Ptr DeclarationBuilder::createType(RustNode *node) { Q_UNUSED(node); return AbstractType::Ptr(nullptr); } template void DeclarationBuilder::setType(Declaration *decl, typename IdType::Type *type) { setType(decl, static_cast(type)); setType(decl, static_cast(type)); } template void DeclarationBuilder::setType(Declaration *decl, IdentifiedType *type) { type->setDeclaration(decl); } template void DeclarationBuilder::setType(Declaration *decl, AbstractType *type) { decl->setAbstractType(AbstractType::Ptr(type)); } template> void DeclarationBuilder::setDeclData(ClassDeclaration *decl) { if (Kind == StructDecl || Kind == ImplDecl) { decl->setClassType(ClassDeclarationData::Struct); } else if (Kind == TraitDecl) { decl->setClassType(ClassDeclarationData::Trait); } } template> void DeclarationBuilder::setDeclData(Declaration *decl) { decl->setKind(Declaration::Namespace); } template> void DeclarationBuilder::setDeclData(Declaration *decl) { decl->setKind(Declaration::Instance); } template> void DeclarationBuilder::setDeclData(AliasDeclaration *decl) { decl->setIsTypeAlias(true); decl->setKind(Declaration::Type); } template> void DeclarationBuilder::setDeclData(Declaration *decl) { Q_UNUSED(decl); } }