mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
C++: Improve parameter naming
This commit is contained in:
@@ -73,7 +73,8 @@ class Parameter extends LocalScopeVariable, @parameter {
|
||||
}
|
||||
|
||||
private VariableDeclarationEntry getANamedDeclarationEntry() {
|
||||
result = this.getAnEffectiveDeclarationEntry() and result.getName() != ""
|
||||
result = this.getAnEffectiveDeclarationEntry() and
|
||||
exists(string name | var_decls(unresolveElement(result), _, _, name, _) | name != "")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -241,6 +241,10 @@ class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
|
||||
name != "" and result = name
|
||||
or
|
||||
name = "" and result = this.getVariable().(LocalVariable).getName()
|
||||
or
|
||||
name = "" and
|
||||
not this instanceof ParameterDeclarationEntry and
|
||||
result = this.getVariable().(Parameter).getName()
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -295,19 +299,11 @@ class ParameterDeclarationEntry extends VariableDeclarationEntry {
|
||||
|
||||
private string getAnonymousParameterDescription() {
|
||||
not exists(this.getName()) and
|
||||
exists(string idx |
|
||||
idx =
|
||||
((this.getIndex() + 1).toString() + "th")
|
||||
.replaceAll("1th", "1st")
|
||||
.replaceAll("2th", "2nd")
|
||||
.replaceAll("3th", "3rd")
|
||||
.replaceAll("11st", "11th")
|
||||
.replaceAll("12nd", "12th")
|
||||
.replaceAll("13rd", "13th") and
|
||||
exists(string anon |
|
||||
anon = "(unnamed parameter " + this.getIndex().toString() + ")" and
|
||||
if exists(this.getCanonicalName())
|
||||
then
|
||||
result = "declaration of " + this.getCanonicalName() + " as anonymous " + idx + " parameter"
|
||||
else result = "declaration of " + idx + " parameter"
|
||||
then result = "declaration of " + this.getCanonicalName() + " as " + anon
|
||||
else result = "declaration of " + anon
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
| declarationEntry.cpp:39:7:39:7 | declaration of operator= | declarationEntry.cpp:39:7:39:7 | operator= | yes |
|
||||
| declarationEntry.cpp:39:7:39:13 | definition of myClass | declarationEntry.cpp:39:7:39:13 | myClass | yes |
|
||||
| declarationEntry.cpp:42:6:42:21 | definition of myMemberVariable | declarationEntry.cpp:42:6:42:21 | myMemberVariable | yes |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter | file://:0:0:0:0 | (unnamed parameter 0) | yes |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter | file://:0:0:0:0 | (unnamed parameter 0) | yes |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) | file://:0:0:0:0 | (unnamed parameter 0) | yes |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) | file://:0:0:0:0 | (unnamed parameter 0) | yes |
|
||||
| file://:0:0:0:0 | definition of fp_offset | file://:0:0:0:0 | fp_offset | yes |
|
||||
| file://:0:0:0:0 | definition of gp_offset | file://:0:0:0:0 | gp_offset | yes |
|
||||
| file://:0:0:0:0 | definition of overflow_arg_area | file://:0:0:0:0 | overflow_arg_area | yes |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
| file://:0:0:0:0 | declaration of 1st parameter |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) |
|
||||
| file://:0:0:0:0 | definition of fp_offset |
|
||||
| file://:0:0:0:0 | definition of gp_offset |
|
||||
| file://:0:0:0:0 | definition of overflow_arg_area |
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
| test.c:2:8:2:10 | declaration of 1st parameter |
|
||||
| test.c:2:13:2:15 | declaration of 2nd parameter |
|
||||
| test.c:2:18:2:20 | declaration of 3rd parameter |
|
||||
| test.c:2:23:2:25 | declaration of 4th parameter |
|
||||
| test.c:3:8:3:10 | declaration of y1 as anonymous 1st parameter |
|
||||
| test.c:3:13:3:15 | declaration of y2 as anonymous 2nd parameter |
|
||||
| test.c:3:18:3:20 | declaration of y3 as anonymous 3rd parameter |
|
||||
| test.c:3:23:3:25 | declaration of y4 as anonymous 4th parameter |
|
||||
| test.c:2:8:2:10 | declaration of (unnamed parameter 0) |
|
||||
| test.c:2:13:2:15 | declaration of (unnamed parameter 1) |
|
||||
| test.c:2:18:2:20 | declaration of (unnamed parameter 2) |
|
||||
| test.c:2:23:2:25 | declaration of (unnamed parameter 3) |
|
||||
| test.c:3:8:3:10 | declaration of y1 as (unnamed parameter 0) |
|
||||
| test.c:3:13:3:15 | declaration of y2 as (unnamed parameter 1) |
|
||||
| test.c:3:18:3:20 | declaration of y3 as (unnamed parameter 2) |
|
||||
| test.c:3:23:3:25 | declaration of y4 as (unnamed parameter 3) |
|
||||
| test.c:4:12:4:13 | declaration of x1 |
|
||||
| test.c:4:20:4:21 | declaration of x2 |
|
||||
| test.c:4:28:4:29 | declaration of x3 |
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
| file://:0:0:0:0 | declaration of 1st parameter | LibB/libb_internal.h:5:8:5:12 | thing |
|
||||
| file://:0:0:0:0 | declaration of 1st parameter | LibB/libb_internal.h:5:8:5:12 | thing |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) | LibB/libb_internal.h:5:8:5:12 | thing |
|
||||
| file://:0:0:0:0 | declaration of (unnamed parameter 0) | LibB/libb_internal.h:5:8:5:12 | thing |
|
||||
| include.h:3:25:3:33 | num | LibD/libd.h:5:12:5:14 | num |
|
||||
| main.cpp:8:31:8:31 | call to container | LibC/libc.h:9:3:9:3 | container |
|
||||
| main.cpp:8:31:8:31 | definition of x | LibB/libb_internal.h:5:8:5:12 | thing |
|
||||
|
||||
Reference in New Issue
Block a user