Skip to content

Commit 1c44315

Browse files
Implement naming package, new IdentifierIntroduction.qll, unicode funcs.
1 parent 0f7154e commit 1c44315

File tree

17 files changed

+288941
-1
lines changed

17 files changed

+288941
-1
lines changed

cpp/common/src/codingstandards/cpp/Identifiers.qll

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.

cpp/common/src/codingstandards/cpp/Macro.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class FunctionLikeMacro extends Macro {
88

99
string getParameter(int i) {
1010
result =
11-
this.getHead().regexpCapture("[_a-zA-Z0-9]+\\s*\\(([^\\)]*)\\)", 1).splitAt(",", i).trim()
11+
this.getHead()
12+
.regexpCapture("[_a-zA-Z0-9]+\\s*\\(([^\\)]*)\\)", 1)
13+
.splitAt(",", i)
14+
.trim()
15+
.replaceAll("...", "")
1216
}
1317

1418
string getAParameter() { result = getParameter(_) }
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import codeql.util.Numbers
2+
3+
/**
4+
* Provides properties of a Unicode code point, where the property is of 'enumeration', 'catalog',
5+
* or 'string-valued' type, however, the only supported property is `NFC_QC`.
6+
*
7+
* For example, `Block` is an enumeration property, `Line_Break` is a catalog property, and
8+
* `Uppercase_Mapping` is a string-valued property.
9+
*
10+
* For boolean properties, see `unicodeHasBooleanProperty`, and for numeric properties, see
11+
* `unicodeHasNumericProperty`.
12+
*/
13+
extensible predicate unicodeHasProperty(int codePoint, string propertyName, string propertyValue);
14+
15+
/**
16+
* Holds when the Unicode code point's boolean property of the given name is true.
17+
*
18+
* For example, `Alphabetic` is a boolean property that can be true or false for a code point.
19+
*
20+
* For other types of properties, see `unicodeHasProperty`.
21+
*/
22+
extensible predicate unicodeHasBooleanProperty(int codePoint, string propertyName);
23+
24+
bindingset[input]
25+
int unescapedCodePointAt(string input, int index) {
26+
exists(string match |
27+
match = input.regexpFind("(\\\\u[0-9a-fA-F]{4}|.)", index, _) and
28+
if match.matches("\\u%")
29+
then result = parseHexInt(match.substring(2, match.length()))
30+
else result = match.codePointAt(0)
31+
)
32+
}
33+
34+
bindingset[input]
35+
string unescapeUnicode(string input) {
36+
result =
37+
concat(int code, int idx |
38+
code = unescapedCodePointAt(input, idx)
39+
|
40+
code.toUnicode() order by idx
41+
)
42+
}
43+
44+
bindingset[id]
45+
predicate nonUax44IdentifierCodepoint(string id, int index) {
46+
exists(int codePoint |
47+
codePoint = id.codePointAt(index) and
48+
(
49+
not unicodeHasBooleanProperty(codePoint, "XID_Start") and
50+
not unicodeHasBooleanProperty(codePoint, "XID_Continue")
51+
or
52+
index = 0 and
53+
not unicodeHasBooleanProperty(codePoint, "XID_Start")
54+
)
55+
)
56+
}
57+
58+
bindingset[id]
59+
predicate nonNfcNormalizedCodepoint(string id, int index, string noOrMaybe) {
60+
exists(int codePoint |
61+
codePoint = id.codePointAt(index) and
62+
unicodeHasProperty(codePoint, "NFC_QC", noOrMaybe) and
63+
noOrMaybe = ["N", "M"]
64+
)
65+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Naming2Query = TPoorlyFormedIdentifierQuery()
7+
8+
predicate isNaming2QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `poorlyFormedIdentifier` query
11+
Naming2Package::poorlyFormedIdentifierQuery() and
12+
queryId =
13+
// `@id` for the `poorlyFormedIdentifier` query
14+
"cpp/misra/poorly-formed-identifier" and
15+
ruleId = "RULE-5-10-1" and
16+
category = "required"
17+
}
18+
19+
module Naming2Package {
20+
Query poorlyFormedIdentifierQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `poorlyFormedIdentifier` query
24+
TQueryCPP(TNaming2PackageQuery(TPoorlyFormedIdentifierQuery()))
25+
}
26+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Loops
3535
import Macros
3636
import MoveForward
3737
import Naming
38+
import Naming2
3839
import Null
3940
import OperatorInvariants
4041
import Operators
@@ -90,6 +91,7 @@ newtype TCPPQuery =
9091
TMacrosPackageQuery(MacrosQuery q) or
9192
TMoveForwardPackageQuery(MoveForwardQuery q) or
9293
TNamingPackageQuery(NamingQuery q) or
94+
TNaming2PackageQuery(Naming2Query q) or
9395
TNullPackageQuery(NullQuery q) or
9496
TOperatorInvariantsPackageQuery(OperatorInvariantsQuery q) or
9597
TOperatorsPackageQuery(OperatorsQuery q) or
@@ -145,6 +147,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
145147
isMacrosQueryMetadata(query, queryId, ruleId, category) or
146148
isMoveForwardQueryMetadata(query, queryId, ruleId, category) or
147149
isNamingQueryMetadata(query, queryId, ruleId, category) or
150+
isNaming2QueryMetadata(query, queryId, ruleId, category) or
148151
isNullQueryMetadata(query, queryId, ruleId, category) or
149152
isOperatorInvariantsQueryMetadata(query, queryId, ruleId, category) or
150153
isOperatorsQueryMetadata(query, queryId, ruleId, category) or

0 commit comments

Comments
 (0)