Example #1
0
AbstractType::Ptr TypeRepository::registerType(AbstractType::Ptr input)
{
  if (!input) {
    kWarning(9007) << "Asked to register a null type." ;
    return input;
  }

  switch (input->whichType()) {
    case AbstractType::TypeAbstract:
      return input;

    case AbstractType::TypeIntegral:
      return input;

    case AbstractType::TypePointer:
      return registerPointer(CppPointerType::Ptr::dynamicCast(input));

    case AbstractType::TypeReference:
      return registerReference(CppReferenceType::Ptr::dynamicCast(input));

    case AbstractType::TypeFunction:
      return registerFunction(CppFunctionType::Ptr::dynamicCast(input));

    case AbstractType::TypeStructure:
      return input;

    case AbstractType::TypeArray:
      return registerArray(ArrayType::Ptr::dynamicCast(input));

    case AbstractType::TypeDelayed:
      return registerDelayedType(DelayedType::Ptr::dynamicCast(input));
    default:
      return input;
  }
}
QList< TypePtr< StructureType > > ExpressionVisitor::possibleStructureTypes(AbstractType::Ptr type)
{
    QList< TypePtr< StructureType > > result;
    type = Helper::resolveType(type);
    if ( ! type ) {
        return result;
    }
    if ( type->whichType() == KDevelop::AbstractType::TypeUnsure ) {
        AbstractType::Ptr current;
        UnsureType::Ptr possible = type.cast<UnsureType>();
        int amount = possible->typesSize();
        for ( int i = 0; i < amount; i++ ) {
            StructureType::Ptr current = Helper::resolveType(possible->types()[i].abstractType()).cast<StructureType>();
            if ( current ) {
                result << current;
            }
        }
    }
    else {
        StructureType::Ptr c = type.cast<StructureType>();
        if ( c ) {
            result << c;
        }
    }
    return result;
}
Example #3
0
AbstractType::Ptr mergeTypes(AbstractType::Ptr type, const AbstractType::Ptr newType)
{
    if (newType && newType->whichType() == AbstractType::TypeFunction) {
        return newType;
    } else {
        return TypeUtils::mergeTypes(type, newType);
    }
}
Example #4
0
QVariant CompletionItem::data(const QModelIndex& index, int role, const KDevelop::CodeCompletionModel* model) const
{
    switch(role)
    {
        case Qt::DisplayRole:
        {
            if (index.column() == CodeCompletionModel::Prefix && m_prefix != "") {
                return m_prefix;
            }
            break;
        }
        case CodeCompletionModel::BestMatchesCount:
            return 5;
        case CodeCompletionModel::MatchQuality:
        {
            if(!declaration())
                return QVariant();
            //type aliases are actually different types
            if(declaration()->isTypeAlias())
                return QVariant();
            AbstractType::Ptr typeToMatch = static_cast<go::CodeCompletionContext*>(model->completionContext().data())->typeToMatch();
            if(!typeToMatch)
                return QVariant();
            AbstractType::Ptr declType = declaration()->abstractType();
            if (!declType)
                return QVariant();
            //ignore constants
            typeToMatch->setModifiers(AbstractType::NoModifiers);
            declType->setModifiers(AbstractType::NoModifiers);
            if(declType->equals(typeToMatch.constData()))
            {
                return QVariant(10);
            }
            else if(declType->whichType() == AbstractType::TypeFunction)
            {
                GoFunctionType* function = fastCast<GoFunctionType*>(declType.constData());
                auto args = function->returnArguments();
                if(args.size() != 0)
                {
                    AbstractType::Ptr first = args.first();
                    first->setModifiers(AbstractType::NoModifiers);
                    if(first->equals(typeToMatch.constData()))
                        return QVariant(10);
                }
            }else
            {
                return QVariant();
            }
        }
    }
    return NormalDeclarationCompletionItem::data(index, role, model);
}
Example #5
0
QList<CompletionTreeItemPointer> CodeCompletionContext::getCompletionItemsFromType(AbstractType::Ptr type, bool scoped)
{
    QList<CompletionTreeItemPointer> res;
    if (type->whichType() == AbstractType::TypeUnsure) {
        UnsureType::Ptr unsure = type.cast<UnsureType>();
        int count = unsure->typesSize();
        for (int i = 0; i < count; i++) {
            res.append(getCompletionItemsForOneType(unsure->types()[i].abstractType(), scoped));
        }
    } else {
        res = getCompletionItemsForOneType(type, scoped);
    }
    return res;
}
Example #6
0
void ADLHelper::addArgumentType(const AbstractType::Ptr typePtr)
{
    if(m_alreadyProcessed.contains(typePtr.data()))
      return;

    if (typePtr)
    {
#ifdef DEBUG_ADL
        qCDebug(CPPDUCHAIN) << "    added argument type " << typePtr->toString() << " to ADL lookup";
#endif
        // the enumeration and enumerator types are not part of the TypeVisitor interface
        switch (typePtr->whichType())
        {
        case AbstractType::TypeEnumeration:
        {
            EnumerationType* specificType = fastCast<EnumerationType*>(typePtr.data());
            if (specificType)
            {
                Declaration * enumDecl = specificType->declaration(m_topContext.data());
                addDeclarationScopeIdentifier(enumDecl);
            }
            break;
        }
        case AbstractType::TypeEnumerator:
        {
            if (m_templateArgsDepth == 0)
            {
                EnumeratorType* specificType = fastCast<EnumeratorType*>(typePtr.data());
                if (specificType)
                {
                    // use the enumeration context for the enumerator value declaration to find out the namespace
                    Declaration * enumeratorDecl = specificType->declaration(m_topContext.data());
                    if (enumeratorDecl) {
                        DUContext * enumContext = enumeratorDecl->context();
                        if (enumContext) {
                            addAssociatedNamespace(enumContext->scopeIdentifier(false));
                        }
                    }
                }
            }
            break;
        }
        default:
            typePtr->accept(&m_typeVisitor);
        }
    }

    m_alreadyProcessed.insert(typePtr.data());
}