File: StringUtils.cpp

package info (click to toggle)
clazy 1.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,248 kB
  • sloc: cpp: 23,552; python: 1,450; xml: 450; sh: 237; makefile: 45
file content (52 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
    SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com
    SPDX-FileContributor: Sérgio Martins <sergio.martins@kdab.com>

    SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "StringUtils.h"

#include <string>
#include <vector>

namespace clang
{
class LangOptions;
} // namespace clang

using namespace clang;

std::string clazy::simpleArgTypeName(clang::FunctionDecl *func, unsigned int index, const clang::LangOptions &lo)
{
    if (!func || index >= func->getNumParams()) {
        return {};
    }

    ParmVarDecl *param = func->getParamDecl(index);
    return simpleTypeName(param, lo);
}

bool clazy::anyArgIsOfSimpleType(clang::FunctionDecl *func, const std::string &simpleType, const clang::LangOptions &lo)
{
    if (!func) {
        return false;
    }

    return std::ranges::any_of(Utils::functionParameters(func), [simpleType, lo](ParmVarDecl *p) {
        return simpleTypeName(p, lo) == simpleType;
    });
}

bool clazy::anyArgIsOfAnySimpleType(clang::FunctionDecl *func, const std::vector<std::string> &simpleTypes, const clang::LangOptions &lo)
{
    if (!func) {
        return false;
    }

    return std::ranges::any_of(simpleTypes, [func, lo](const std::string &simpleType) {
        return clazy::anyArgIsOfSimpleType(func, simpleType, lo);
    });
}