当前位置: 首页>>代码示例>>C++>>正文


C++ FullySpecifiedType::asFunctionType方法代码示例

本文整理汇总了C++中FullySpecifiedType::asFunctionType方法的典型用法代码示例。如果您正苦于以下问题:C++ FullySpecifiedType::asFunctionType方法的具体用法?C++ FullySpecifiedType::asFunctionType怎么用?C++ FullySpecifiedType::asFunctionType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FullySpecifiedType的用法示例。


在下文中一共展示了FullySpecifiedType::asFunctionType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: visit

bool CheckExpression::visit(QtMethodAST *ast)
{
    const Name *name = 0;
    Scope dummy;
    FullySpecifiedType methTy = semantic()->check(ast->declarator, FullySpecifiedType(),
                                                  &dummy, &name);
    Function *fty = methTy->asFunctionType();
    if (! fty)
        translationUnit()->warning(ast->firstToken(), "expected a function declarator");
    else {
        for (unsigned i = 0; i < fty->argumentCount(); ++i) {
            Symbol *arg = fty->argumentAt(i);
            if (arg->name())
                translationUnit()->warning(arg->sourceLocation(),
                                           "argument should be anonymous");
        }
    }
    return false;
}
开发者ID:ionionica,项目名称:qt-mobility,代码行数:19,代码来源:CheckExpression.cpp

示例2: visit

bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
{
    FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope);
    FullySpecifiedType qualTy = ty.qualifiedType();
    Name *name = 0;
    FullySpecifiedType funTy = semantic()->check(ast->declarator, qualTy,
                                                 _scope, &name);
    if (! (funTy && funTy->isFunctionType())) {
        translationUnit()->error(ast->firstToken(),
                                 "expected a function prototype");
        return false;
    }

    Function *fun = funTy->asFunctionType();
    fun->setVirtual(ty.isVirtual());
    fun->setStartOffset(tokenAt(ast->firstToken()).offset);
    fun->setEndOffset(tokenAt(ast->lastToken()).offset);
    if (ast->declarator)
        fun->setSourceLocation(ast->declarator->firstToken());
    fun->setName(name);
    fun->setTemplateParameters(_templateParameters);
    fun->setVisibility(semantic()->currentVisibility());
    fun->setMethodKey(semantic()->currentMethodKey());

    const bool isQ_SLOT   = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SLOT;
    const bool isQ_SIGNAL = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SIGNAL;

    if (isQ_SIGNAL)
        fun->setMethodKey(Function::SignalMethod);
    else if (isQ_SLOT)
        fun->setMethodKey(Function::SlotMethod);

    checkFunctionArguments(fun);

    ast->symbol = fun;
    _scope->enterSymbol(fun);

    if (! semantic()->skipFunctionBodies()) {
        if (ast->ctor_initializer) {
            bool looksLikeCtor = false;
            if (ty.isValid() || ! fun->identity())
                looksLikeCtor = false;
            else if (fun->identity()->isNameId() || fun->identity()->isTemplateNameId())
                looksLikeCtor = true;

            if (! looksLikeCtor) {
                translationUnit()->error(ast->ctor_initializer->firstToken(),
                                         "only constructors take base initializers");
            }
            accept(ast->ctor_initializer);
        }

        const int previousVisibility = semantic()->switchVisibility(Symbol::Public);
        const int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod);

        semantic()->check(ast->function_body, fun->members());

        semantic()->switchMethodKey(previousMethodKey);
        semantic()->switchVisibility(previousVisibility);
    }

    return false;
}
开发者ID:halsten,项目名称:beaverdbg,代码行数:63,代码来源:CheckDeclaration.cpp

示例3: checkAndRewrite

/*!
    Performs some further checks and rewrites the type and name of \a symbol
    into the substitution range in the file specified by \a tokenRange.
 */
void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator,
                                                  Symbol *symbol,
                                                  TokenRange tokenRange,
                                                  unsigned charactersToRemove)
{
    CHECK_R(tokenRange.end > 0, "TokenRange invalid1");
    CHECK_R(tokenRange.start < tokenRange.end, "TokenRange invalid2");
    CHECK_R(symbol, "No symbol");

    // Check for expanded tokens
    for (unsigned token = tokenRange.start; token <= tokenRange.end; ++token)
        CHECK_R(!tokenAt(token).expanded(), "Token is expanded");

    Range range(m_cppRefactoringFile->startOf(tokenRange.start),
                m_cppRefactoringFile->endOf(tokenRange.end));

    CHECK_R(range.start >= 0 && range.end > 0, "ChangeRange invalid1");
    CHECK_R(range.start < range.end, "ChangeRange invalid2");

    // Check range with respect to cursor position / selection
    if (m_cursorHandling == RespectCursor) {
        const QTextCursor cursor = m_cppRefactoringFile->cursor();
        if (cursor.hasSelection()) {
            CHECK_R(cursor.selectionStart() <= range.start, "Change not in selection range");
            CHECK_R(range.end <= cursor.selectionEnd(), "Change not in selection range");
        } else {
            CHECK_R(range.start <= cursor.selectionStart(), "Cursor before activation range");
            CHECK_R(cursor.selectionEnd() <= range.end, "Cursor after activation range");
        }
    }

    FullySpecifiedType type = symbol->type();
    if (Function *function = type->asFunctionType())
        type = function->returnType();

    // Check if pointers or references are involved
    const QString originalDeclaration = m_cppRefactoringFile->textOf(range);
    CHECK_R(originalDeclaration.contains(QLatin1Char('&'))
            || originalDeclaration.contains(QLatin1Char('*')), "No pointer or references");

    // Does the rewritten declaration (part) differs from the original source (part)?
    QString rewrittenDeclaration;
    const Name *name = symbol->name();
    if (name) {
        if (name->isOperatorNameId()
                || (name->isQualifiedNameId()
                    && name->asQualifiedNameId()->name()->isOperatorNameId())) {
            const QString operatorText = m_cppRefactoringFile->textOf(declarator->core_declarator);
            m_overview.includeWhiteSpaceInOperatorName = operatorText.contains(QLatin1Char(' '));
        }
    }
    rewrittenDeclaration = m_overview.prettyType(type, name);
    rewrittenDeclaration.remove(0, charactersToRemove);

    CHECK_R(originalDeclaration != rewrittenDeclaration, "Rewritten is same as original");
    CHECK_R(rewrittenDeclaration.contains(QLatin1Char('&'))
            || rewrittenDeclaration.contains(QLatin1Char('*')),
            "No pointer or references in rewritten declaration");

    if (DEBUG_OUTPUT) {
        qDebug("==> Rewritten: \"%s\" --> \"%s\"", originalDeclaration.toLatin1().constData(),
               rewrittenDeclaration.toLatin1().constData());
    }

    // Creating the replacement in the changeset may fail due to operations
    // in the changeset that overlap with the current range.
    //
    // Consider this case:
    //
    //    void (*foo)(char * s) = 0;
    //
    // First visit(SimpleDeclarationAST *ast) will be called. It creates a
    // replacement that also includes the parameter.
    // Next visit(ParameterDeclarationAST *ast) is called with the
    // original source. It tries to create an replacement operation
    // at this position and fails due to overlapping ranges (the
    // simple declaration range includes parameter declaration range).
    ChangeSet change(m_changeSet);
    if (change.replace(range, rewrittenDeclaration))
        m_changeSet = change;
    else if (DEBUG_OUTPUT)
        qDebug() << "Replacement operation failed";
}
开发者ID:Herysutrisno,项目名称:qt-creator,代码行数:87,代码来源:cpppointerdeclarationformatter.cpp

示例4: noResult

QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(const CppQuickFixState &state)
{
    const QList<AST *> &path = state.path();

    if (path.isEmpty())
        return noResult();

    AST * const ast = path.last();
    QtPropertyDeclarationAST *qtPropertyDeclaration = ast->asQtPropertyDeclaration();
    if (!qtPropertyDeclaration)
        return noResult();

    ClassSpecifierAST *klass = 0;
    for (int i = path.size() - 2; i >= 0; --i) {
        klass = path.at(i)->asClassSpecifier();
        if (klass)
            break;
    }
    if (!klass)
        return noResult();

    CppRefactoringChanges refactoring(state.snapshot());
    const CppRefactoringFile &file = refactoring.file(state.document()->fileName());
    const QString propertyName = file.textOf(qtPropertyDeclaration->property_name);
    QString getterName;
    QString setterName;
    QString signalName;
    int generateFlags = 0;
    for (QtPropertyDeclarationItemListAST *it = qtPropertyDeclaration->property_declaration_item_list;
         it; it = it->next) {
        const QString tokenString = file.tokenAt(it->value->item_name_token).spell();
        if (tokenString == QLatin1String("READ")) {
            getterName = file.textOf(it->value->expression);
            generateFlags |= GenerateGetter;
        } else if (tokenString == QLatin1String("WRITE")) {
            setterName = file.textOf(it->value->expression);
            generateFlags |= GenerateSetter;
        } else if (tokenString == QLatin1String("NOTIFY")) {
            signalName = file.textOf(it->value->expression);
            generateFlags |= GenerateSignal;
        }
    }
    QString storageName = QString("m_%1").arg(propertyName);
    generateFlags |= GenerateStorage;

    Class *c = klass->symbol;

    Overview overview;
    for (unsigned i = 0; i < c->memberCount(); ++i) {
        Symbol *member = c->memberAt(i);
        FullySpecifiedType type = member->type();
        if (member->asFunction() || (type.isValid() && type->asFunctionType())) {
            const QString name = overview(member->name());
            if (name == getterName) {
                generateFlags &= ~GenerateGetter;
            } else if (name == setterName) {
                generateFlags &= ~GenerateSetter;
            } else if (name == signalName) {
                generateFlags &= ~GenerateSignal;
            }
        } else if (member->asDeclaration()) {
            const QString name = overview(member->name());
            if (name == storageName)
                generateFlags &= ~GenerateStorage;
        }
    }

    if (getterName.isEmpty() && setterName.isEmpty() && signalName.isEmpty())
        return noResult();

    return singleResult(new Operation(state, path.size() - 1, qtPropertyDeclaration, c,
                                      generateFlags,
                                      getterName, setterName, signalName, storageName));
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:74,代码来源:cppinsertqtpropertymembers.cpp


注:本文中的FullySpecifiedType::asFunctionType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。