Skip to content

Commit a53b02c

Browse files
authored
Merge pull request #1016 from knewbury01/knewbury01/Linkage1
Add linkage1 package
2 parents 33c5a6d + 53f6f6c commit a53b02c

31 files changed

+315
-80
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A3-1-4` - `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql`:
2+
- `ExternalLinkageArrayWithoutExplicitSize.ql` has been renamed to `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql` to reflect shared query implementation. Additionally the query previously only detected explicit uses of `extern` to determine external linkage, and now would catch other cases that are possible where it is external linkage and an array is declared without an explicit size.

cpp/autosar/src/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.ql

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/autosar/external-linkage-array-without-explicit-size-autosar
3+
* @name A3-1-4: When an array with external linkage is declared, its size shall be stated explicitly
4+
* @description A developer can more safely access the elements of an array if the size of the array
5+
* can be explicitly determined.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/autosar/id/a3-1-4
10+
* correctness
11+
* external/autosar/allocated-target/design
12+
* external/autosar/allocated-target/implementation
13+
* external/autosar/enforcement/automated
14+
* external/autosar/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.autosar
19+
import codingstandards.cpp.rules.externallinkagearraywithoutexplicitsize.ExternalLinkageArrayWithoutExplicitSize
20+
21+
class ExternalLinkageArrayWithoutExplicitSizeAutosarQuery extends ExternalLinkageArrayWithoutExplicitSizeSharedQuery
22+
{
23+
ExternalLinkageArrayWithoutExplicitSizeAutosarQuery() {
24+
this = ScopePackage::externalLinkageArrayWithoutExplicitSizeAutosarQuery()
25+
}
26+
}

cpp/autosar/src/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.ql

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,11 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20-
import codingstandards.cpp.Linkage
21-
import codingstandards.cpp.EncapsulatingFunctions
20+
import codingstandards.cpp.rules.externallinkagenotdeclaredinheaderfile.ExternalLinkageNotDeclaredInHeaderFile
2221

23-
from DeclarationEntry de, string kind
24-
where
25-
not isExcluded(de, IncludesPackage::externalLinkageNotDeclaredInHeaderFileQuery()) and
26-
hasExternalLinkage(de.getDeclaration()) and
27-
// Exclude subobjects such as struct members or member functions
28-
de.getDeclaration().isTopLevel() and
29-
// The declaration with external linkage does not have a declaration in a header file
30-
exists(Compilation c | de.getFile() = c.getAFileCompiled()) and
31-
not exists(DeclarationEntry otherDe |
32-
de.getDeclaration() = otherDe.getDeclaration() and
33-
not de = otherDe and
34-
not otherDe.isDefinition()
35-
|
36-
otherDe.getFile() instanceof HeaderFile
37-
) and
38-
// Main functions are an exception to the rule
39-
not de.getDeclaration() instanceof MainFunction and
40-
if de.getDeclaration() instanceof Function then kind = "function" else kind = "object"
41-
select de, "Externally linked " + kind + " '" + de.getName() + "' not declared in header file."
22+
class ExternalLinkageNotDeclaredInHeaderFileQuery extends ExternalLinkageNotDeclaredInHeaderFileSharedQuery
23+
{
24+
ExternalLinkageNotDeclaredInHeaderFileQuery() {
25+
this = IncludesPackage::externalLinkageNotDeclaredInHeaderFileQuery()
26+
}
27+
}

cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.ql

cpp/autosar/test/rules/A3-1-4/test.cpp

Lines changed: 0 additions & 8 deletions
This file was deleted.

cpp/autosar/test/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/externallinkagenotdeclaredinheaderfile/ExternalLinkageNotDeclaredInHeaderFile.ql

0 commit comments

Comments
 (0)