-
Notifications
You must be signed in to change notification settings - Fork 81
/
gocloc.go
73 lines (64 loc) · 1.63 KB
/
gocloc.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gocloc
// Processor is gocloc analyzing processor.
type Processor struct {
langs *DefinedLanguages
opts *ClocOptions
}
// Result defined processing result.
type Result struct {
Total *Language
Files map[string]*ClocFile
Languages map[string]*Language
MaxPathLength int
}
// NewProcessor returns Processor.
func NewProcessor(langs *DefinedLanguages, options *ClocOptions) *Processor {
return &Processor{
langs: langs,
opts: options,
}
}
// Analyze executes gocloc parsing for the directory of the paths argument and returns the result.
func (p *Processor) Analyze(paths []string) (*Result, error) {
total := NewLanguage("TOTAL", []string{}, [][]string{{"", ""}})
languages, err := getAllFiles(paths, p.langs, p.opts)
if err != nil {
return nil, err
}
maxPathLen := 0
num := 0
for _, lang := range languages {
num += len(lang.Files)
for _, file := range lang.Files {
l := len(file)
if maxPathLen < l {
maxPathLen = l
}
}
}
clocFiles := make(map[string]*ClocFile, num)
for _, language := range languages {
for _, file := range language.Files {
cf := AnalyzeFile(file, language, p.opts)
cf.Lang = language.Name
language.Code += cf.Code
language.Comments += cf.Comments
language.Blanks += cf.Blanks
clocFiles[file] = cf
}
files := int32(len(language.Files))
if len(language.Files) <= 0 {
continue
}
total.Total += files
total.Blanks += language.Blanks
total.Comments += language.Comments
total.Code += language.Code
}
return &Result{
Total: total,
Files: clocFiles,
Languages: languages,
MaxPathLength: maxPathLen,
}, nil
}