|
16 | 16 |
|
17 | 17 | import cpp |
18 | 18 | import codingstandards.cpp.autosar |
19 | | -import codingstandards.cpp.Naming |
| 19 | +import codingstandards.cpp.StandardLibraryNames |
20 | 20 | import codingstandards.cpp.StdNamespace |
21 | 21 |
|
22 | 22 | FunctionCall nonCompliantCStdlibCalls(File f) { |
23 | 23 | result = |
24 | | - any(FunctionCall fc, string name, string qname, int qname_count | |
| 24 | + any(FunctionCall fc, Function function, string name | |
25 | 25 | f = fc.getFile() and |
26 | | - name = fc.getTarget().getName() and |
27 | | - Naming::Cpp14::hasStandardLibraryFunctionName(name) and |
28 | | - qname = Naming::Cpp14::getQualifiedStandardLibraryFunctionName(name) and |
29 | | - qname_count = count(Naming::Cpp14::getQualifiedStandardLibraryFunctionName(name)) and |
| 26 | + function = fc.getTarget() and |
| 27 | + name = function.getName() and |
| 28 | + // Has a name from the C99 library |
| 29 | + CStandardLibrary::C99::hasFunctionName(_, "", "", name, _, _, _) and |
| 30 | + // The C function is either declared in the global namespace and imported into std or vice versa |
30 | 31 | ( |
31 | | - not exists(fc.getQualifier()) and |
32 | | - ( |
33 | | - // the set `q` can contain qualified names both with and without the `std` namespace. |
34 | | - // in this case, only a call to the function within the `std` namespace is compliant. |
35 | | - qname_count > 1 and |
36 | | - not exists(NameQualifier nq | |
37 | | - nq = fc.getNameQualifier() and nq.getQualifyingElement().getName() = "std" |
38 | | - ) |
39 | | - or |
40 | | - // if the qualified standard library function name does not specify a namespace, then the |
41 | | - // standard library function is either in the global namespace (such as in C) or within |
42 | | - // the `std` namespace. therefore, ignore calls with qualifiers other than 'std'. |
43 | | - name = qname and |
44 | | - qname_count <= 1 and |
45 | | - ( |
46 | | - not exists(fc.getNameQualifier()) and |
47 | | - // also handle implicit namespace scope |
48 | | - not exists(Namespace caller_ns, Namespace callee_ns | |
49 | | - caller_ns = fc.getEnclosingFunction().getNamespace() and |
50 | | - callee_ns = fc.getTarget().getNamespace() and |
51 | | - not callee_ns instanceof GlobalNamespace and |
52 | | - caller_ns = callee_ns |
53 | | - ) |
54 | | - or |
55 | | - exists(NameQualifier nq | |
56 | | - nq = fc.getNameQualifier() and |
57 | | - ( |
58 | | - nq.getQualifyingElement() instanceof GlobalNamespace or |
59 | | - nq.getQualifyingElement() instanceof StdNS |
60 | | - ) |
61 | | - ) |
62 | | - ) |
63 | | - ) |
64 | | - ) |
| 32 | + function.getNamespace() instanceof StdNS |
| 33 | + or |
| 34 | + function.getNamespace() instanceof GlobalNamespace |
| 35 | + ) and |
| 36 | + // No function qualifier |
| 37 | + not exists(fc.getQualifier()) |
65 | 38 | | |
66 | 39 | fc |
67 | 40 | ) |
|
0 commit comments