Beispiel #1
0
Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
{
    if (const Template *templ = symbol->asTemplate()) {
        if (Symbol *decl = templ->declaration())
            return iconTypeForSymbol(decl);
    }

    FullySpecifiedType symbolType = symbol->type();
    if (symbol->isFunction() || (symbol->isDeclaration() && symbolType &&
                                 symbolType->isFunctionType()))
    {
        const Function *function = symbol->asFunction();
        if (!function)
            function = symbol->type()->asFunctionType();

        if (function->isSlot()) {
            if (function->isPublic())
                return SlotPublicIconType;
            else if (function->isProtected())
                return SlotProtectedIconType;
            else if (function->isPrivate())
                return SlotPrivateIconType;
        } else if (function->isSignal()) {
            return SignalIconType;
        } else if (symbol->isPublic()) {
            return FuncPublicIconType;
        } else if (symbol->isProtected()) {
            return FuncProtectedIconType;
        } else if (symbol->isPrivate()) {
            return FuncPrivateIconType;
        }
    } else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) {
        return EnumeratorIconType;
    } else if (symbol->isDeclaration() || symbol->isArgument()) {
        if (symbol->isPublic())
            return VarPublicIconType;
        else if (symbol->isProtected())
            return VarProtectedIconType;
        else if (symbol->isPrivate())
            return VarPrivateIconType;
    } else if (symbol->isEnum()) {
        return EnumIconType;
    } else if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
        return ClassIconType;
    } else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) {
        return ClassIconType;
    } else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) {
        return ClassIconType;
    } else if (symbol->isObjCMethod()) {
        return FuncPublicIconType;
    } else if (symbol->isNamespace()) {
        return NamespaceIconType;
    } else if (symbol->isTypenameArgument()) {
        return ClassIconType;
    } else if (symbol->isUsingNamespaceDirective() ||
               symbol->isUsingDeclaration()) {
        // TODO: Might be nice to have a different icons for these things
        return NamespaceIconType;
    }

    return UnknownIconType;
}
Beispiel #2
0
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;
}
Beispiel #3
0
SymbolInfo::ElementType SymbolInfo::elementTypeFromSymbol( const CPlusPlus::Symbol *symbol )
{
	if (const Template *templ = symbol->asTemplate()) {
		if (Symbol *decl = templ->declaration())
			return elementTypeFromSymbol(decl);
	}

	FullySpecifiedType symbolType = symbol->type();
	if (symbol->isFunction() || (symbol->isDeclaration() && symbolType &&
		symbolType->isFunctionType()))
	{
		const CPlusPlus::Function *func = symbol->asFunction();
		if (!func)
			func = symbol->type()->asFunctionType();

		if (func->isSlot() ) {
			if (func->isPublic())
				return SymbolInfo::SlotPublic;
			else if (func->isProtected())
				return SymbolInfo::SlotProtected;
			else if (func->isPrivate())
				return SymbolInfo::SlotPrivate;
		} else if (func->isSignal()) {
			return SymbolInfo::Signal;
		} else if (symbol->isPublic()) {
			return SymbolInfo::FuncPublic;
		} else if (symbol->isProtected()) {
			return SymbolInfo::FuncProtected;
		} else if (symbol->isPrivate()) {
			return SymbolInfo::FuncPrivate;
		}
	} else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) {
		return SymbolInfo::Enumerator;
	} else if (symbol->isDeclaration() || symbol->isArgument()) {
		if (symbol->isPublic())
			return SymbolInfo::VarPublic;
		else if (symbol->isProtected())
			return SymbolInfo::VarProtected;
		else if (symbol->isPrivate())
			return SymbolInfo::VarPrivate;
	} else if (symbol->isEnum()) {
		return SymbolInfo::Enum;
	} else if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
		return SymbolInfo::Class;
	} else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) {
		return SymbolInfo::Class;
	} else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) {
		return SymbolInfo::Class;
	} else if (symbol->isObjCMethod()) {
		return SymbolInfo::FuncPublic;
	} else if (symbol->isNamespace()) {
		return SymbolInfo::Namespace;
	} else if (symbol->isTypenameArgument()) {
		return SymbolInfo::Class;
	} else if (symbol->isUsingNamespaceDirective() ||
		symbol->isUsingDeclaration()) {
			// TODO: Might be nice to have a different icons for these things
			return SymbolInfo::Namespace;
	} else if (symbol->isBlock()){
		return SymbolInfo::Block;
	}

	return SymbolInfo::Unknown;
}