Skip to content

Commit 7c94c8c

Browse files
committed
Migrate A17-1-1 to use StandardLibraryNames
1 parent a821de9 commit 7c94c8c

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

cpp/autosar/src/rules/A17-1-1/CStandardLibraryFunctionCalls.ql

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,25 @@
1616

1717
import cpp
1818
import codingstandards.cpp.autosar
19-
import codingstandards.cpp.Naming
19+
import codingstandards.cpp.StandardLibraryNames
2020
import codingstandards.cpp.StdNamespace
2121

2222
FunctionCall nonCompliantCStdlibCalls(File f) {
2323
result =
24-
any(FunctionCall fc, string name, string qname, int qname_count |
24+
any(FunctionCall fc, Function function, string name |
2525
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
3031
(
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())
6538
|
6639
fc
6740
)

0 commit comments

Comments
 (0)