| 2737 | } |
| 2738 | |
| 2739 | Function::Function(const Token *tok, |
| 2740 | const Scope *scope, |
| 2741 | const Token *tokDef, |
| 2742 | const Token *tokArgDef) |
| 2743 | : tokenDef(tokDef), |
| 2744 | argDef(tokArgDef), |
| 2745 | nestedIn(scope) |
| 2746 | { |
| 2747 | // operator function |
| 2748 | if (::isOperator(tokenDef)) { |
| 2749 | isOperator(true); |
| 2750 | |
| 2751 | // 'operator =' is special |
| 2752 | if (tokenDef->str() == "operator=") |
| 2753 | type = FunctionType::eOperatorEqual; |
| 2754 | } |
| 2755 | |
| 2756 | else if (tokenDef->str() == "[") { |
| 2757 | type = FunctionType::eLambda; |
| 2758 | } |
| 2759 | |
| 2760 | // class constructor/destructor |
| 2761 | else if (scope->isClassOrStructOrUnion() && |
| 2762 | ((tokenDef->str() == scope->className) || |
| 2763 | (tokenDef->str().substr(0, scope->className.size()) == scope->className && |
| 2764 | tokenDef->str().size() > scope->className.size() + 1 && |
| 2765 | tokenDef->str()[scope->className.size() + 1] == '<'))) { |
| 2766 | // destructor |
| 2767 | if (tokenDef->strAt(-1) == "~") { |
| 2768 | type = FunctionType::eDestructor; |
| 2769 | isNoExcept(true); |
| 2770 | } |
| 2771 | // constructor of any kind |
| 2772 | else |
| 2773 | type = FunctionType::eConstructor; |
| 2774 | } |
| 2775 | |
| 2776 | const Token *tok1 = setFlags(tok, scope); |
| 2777 | |
| 2778 | // find the return type |
| 2779 | if (!isConstructor() && !isDestructor()) { |
| 2780 | // @todo auto type deduction should be checked |
| 2781 | // @todo attributes and exception specification can also precede trailing return type |
| 2782 | if (isTrailingReturnType(argDef->link()->next())) { // Trailing return type |
| 2783 | hasTrailingReturnType(true); |
| 2784 | if (argDef->link()->strAt(1) == ".") |
| 2785 | retDef = argDef->link()->tokAt(2); |
| 2786 | else if (argDef->link()->strAt(2) == ".") |
| 2787 | retDef = argDef->link()->tokAt(3); |
| 2788 | else if (argDef->link()->strAt(3) == ".") |
| 2789 | retDef = argDef->link()->tokAt(4); |
| 2790 | } else if (!isLambda()) { |
| 2791 | if (tok1->str() == ">") |
| 2792 | tok1 = tok1->next(); |
| 2793 | while (Token::Match(tok1, "extern|virtual|static|friend|struct|union|enum")) |
| 2794 | tok1 = tok1->next(); |
| 2795 | retDef = tok1; |
| 2796 | } |
nothing calls this directly
no test coverage detected