-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathGlog.qll
More file actions
45 lines (39 loc) · 1.26 KB
/
Glog.qll
File metadata and controls
45 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Provides models of commonly used functions in the `github.com/golang/glog` and `k8s.io/klog`
* packages.
*/
overlay[local?]
module;
import go
/**
* Provides models of commonly used functions in the `github.com/golang/glog` packages and its
* forks.
*/
module Glog {
private class GlogFunction extends Function {
int firstPrintedArg;
GlogFunction() {
exists(string pkg, string fn, string level |
pkg = package(["github.com/golang/glog", "gopkg.in/glog", "k8s.io/klog"], "") and
level = ["Error", "Exit", "Fatal", "Info", "Warning"] and
(
fn = level + ["", "f", "ln"] and firstPrintedArg = 0
or
fn = level + "Depth" and firstPrintedArg = 1
)
|
this.hasQualifiedName(pkg, fn)
or
this.(Method).hasQualifiedName(pkg, "Verbose", fn)
)
}
/**
* Gets the index of the first argument that may be output, including a format string if one is present.
*/
int getFirstPrintedArg() { result = firstPrintedArg }
}
private class StringFormatter extends StringOps::Formatting::Range instanceof GlogFunction {
StringFormatter() { this.getName().matches("%f") }
override int getFormatStringIndex() { result = super.getFirstPrintedArg() }
}
}