| 1952 | } |
| 1953 | |
| 1954 | bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const |
| 1955 | { |
| 1956 | if (tok->varId()) |
| 1957 | return false; |
| 1958 | |
| 1959 | // function returning function pointer? '... ( ... %name% ( ... ))( ... ) {' |
| 1960 | // function returning reference to array '... ( & %name% ( ... ))[ ... ] {' |
| 1961 | // TODO: Activate this again |
| 1962 | if ((false) && tok->str() == "(" && tok->strAt(1) != "*" && // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) |
| 1963 | (tok->link()->strAt(-1) == ")" || Token::simpleMatch(tok->link()->tokAt(-2), ") const"))) { |
| 1964 | const Token* tok2 = tok->link()->next(); |
| 1965 | if (tok2 && tok2->str() == "(" && Token::Match(tok2->link()->next(), "{|;|const|=")) { |
| 1966 | const Token* argStartTok; |
| 1967 | if (tok->link()->strAt(-1) == "const") |
| 1968 | argStartTok = tok->link()->linkAt(-2); |
| 1969 | else |
| 1970 | argStartTok = tok->link()->linkAt(-1); |
| 1971 | funcStart = argStartTok->previous(); |
| 1972 | argStart = argStartTok; |
| 1973 | declEnd = Token::findmatch(tok2->link()->next(), "{|;"); |
| 1974 | return true; |
| 1975 | } |
| 1976 | if (tok2 && tok2->str() == "[") { |
| 1977 | while (tok2 && tok2->str() == "[") |
| 1978 | tok2 = tok2->link()->next(); |
| 1979 | if (Token::Match(tok2, "{|;|const|=")) { |
| 1980 | const Token* argStartTok; |
| 1981 | if (tok->link()->strAt(-1) == "const") |
| 1982 | argStartTok = tok->link()->linkAt(-2); |
| 1983 | else |
| 1984 | argStartTok = tok->link()->linkAt(-1); |
| 1985 | funcStart = argStartTok->previous(); |
| 1986 | argStart = argStartTok; |
| 1987 | declEnd = Token::findmatch(tok2, "{|;"); |
| 1988 | return true; |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | else if (!tok->isName() || !tok->next() || !tok->linkAt(1)) |
| 1994 | return false; |
| 1995 | |
| 1996 | // regular function? |
| 1997 | else if (Token::Match(tok, "%name% ( !!*") && !isReservedName(tok) && tok->previous() && |
| 1998 | (Token::Match(tok->previous(), "%name%|>|&|&&|*|::|~") || // Either a return type or scope qualifier in front of tok |
| 1999 | outerScope->isClassOrStructOrUnion())) { // or a ctor/dtor |
| 2000 | const Token* tok1 = tok->previous(); |
| 2001 | const Token* tok2 = tok->linkAt(1)->next(); |
| 2002 | |
| 2003 | if (!TokenList::isFunctionHead(tok->next(), ";:{")) |
| 2004 | return false; |
| 2005 | |
| 2006 | // skip over destructor "~" |
| 2007 | if (tok1->str() == "~") |
| 2008 | tok1 = tok1->previous(); |
| 2009 | |
| 2010 | // skip over qualification |
| 2011 | while (Token::simpleMatch(tok1, "::")) { |