Skip to content

Commit 7140b95

Browse files
author
Alvaro Muñoz
committed
improve generated files matching predicates
1 parent 50bd070 commit 7140b95

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

go/ql/lib/semmle/go/frameworks/Twirp.qll

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ module Twirp {
1212
*/
1313
class ProtobufGeneratedFile extends File {
1414
ProtobufGeneratedFile() {
15-
this.getBaseName().matches("%.pb.go") and
16-
exists(File f |
17-
this.getParentContainer() = f.getParentContainer() and
18-
this.getBaseName().splitAt(".", 0) = f.getBaseName().splitAt(".", 0) and
19-
f.getBaseName().matches("%.twirp.go")
15+
exists(string name, File t |
16+
this.getBaseName() = name + ".pb.go" and
17+
this.getParentContainer() = t.getParentContainer() and
18+
t.getBaseName() = name + ".twirp.go"
2019
)
2120
}
2221
}
@@ -27,11 +26,10 @@ module Twirp {
2726
*/
2827
class ServicesGeneratedFile extends File {
2928
ServicesGeneratedFile() {
30-
this.getBaseName().matches("%.twirp.go") and
31-
exists(File f |
32-
this.getParentContainer() = f.getParentContainer() and
33-
this.getBaseName().splitAt(".", 0) = f.getBaseName().splitAt(".", 0) and
34-
f.getBaseName().matches("%.pb.go")
29+
exists(string name, File t |
30+
this.getBaseName() = name + ".twirp.go" and
31+
this.getParentContainer() = t.getParentContainer() and
32+
t.getBaseName() = name + ".pb.go"
3533
)
3634
}
3735
}
@@ -78,10 +76,12 @@ module Twirp {
7876
*/
7977
class ServiceClientType extends NamedType {
8078
ServiceClientType() {
81-
exists(ServiceInterfaceType i, PointerType p |
79+
exists(ServiceInterfaceType i, PointerType p, TypeEntity te |
8280
p.implements(i) and
8381
this = p.getBaseType() and
84-
this.getName().toLowerCase() = i.getName().toLowerCase() + ["protobuf", "json"] + "client"
82+
this.getName().toLowerCase() = i.getName().toLowerCase() + ["protobuf", "json"] + "client" and
83+
te.getType() = this and
84+
te.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
8585
)
8686
}
8787
}
@@ -91,9 +91,11 @@ module Twirp {
9191
*/
9292
class ServiceServerType extends NamedType {
9393
ServiceServerType() {
94-
exists(ServiceInterfaceType i |
94+
exists(ServiceInterfaceType i, TypeEntity te |
9595
this.implements(i) and
96-
this.getName().toLowerCase() = i.getName().toLowerCase() + "server"
96+
this.getName().toLowerCase() = i.getName().toLowerCase() + "server" and
97+
te.getType() = this and
98+
te.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
9799
)
98100
}
99101
}
@@ -106,7 +108,8 @@ module Twirp {
106108
exists(ServiceClientType c |
107109
this.getName().toLowerCase() = "new" + c.getName().toLowerCase() and
108110
this.getParameter(0).getType() instanceof StringType and
109-
this.getParameterType(1).getName() = "HTTPClient"
111+
this.getParameterType(1).getName() = "HTTPClient" and
112+
this.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
110113
)
111114
}
112115
}
@@ -119,7 +122,8 @@ module Twirp {
119122
ServerConstructor() {
120123
exists(ServiceServerType c, ServiceInterfaceType i |
121124
this.getName().toLowerCase() = "new" + c.getName().toLowerCase() and
122-
this.getParameter(0).getType() = i.getNamedType()
125+
this.getParameter(0).getType() = i.getNamedType() and
126+
this.getDeclaration().getLocation().getFile() instanceof ServicesGeneratedFile
123127
)
124128
}
125129
}

0 commit comments

Comments
 (0)