Skip to content

Commit e544339

Browse files
authored
Remove dependency on gen to generate sets (#746)
1 parent 5d760fb commit e544339

12 files changed

+116
-428
lines changed

.golangci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
run:
2-
skip-files: ast/identifier_set.go
31
linters:
42
enable:
53
- stylecheck

Makefile

-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
all: install.dependencies generate generate.stdlib build.bazel test tidy
22
.PHONY: all
33

4-
# https://github.com/golang/go/issues/30515
5-
# We temporarily set GO111MODULE=off here to avoid adding these binaries to the go.mod|sum files
6-
# As they are not needed during runtime
7-
install.dependencies : export GO111MODULE=off
84
install.dependencies:
95
git submodule init
106
git submodule update
11-
go get github.com/clipperhouse/gen
12-
go get github.com/clipperhouse/set
137
.PHONY: install.dependencies
148

159
build.bazel:

README.md

-11
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,6 @@ _replace the FILTER with the name of the test you are working on_
188188
FILTER=Builtin_manifestJsonEx make benchmark
189189
```
190190

191-
## Implementation Notes
192-
193-
We are generating some helper classes on types by using http://clipperhouse.github.io/gen/. Do the following to regenerate these if necessary:
194-
195-
```bash
196-
go get github.com/clipperhouse/gen
197-
go get github.com/clipperhouse/set
198-
export PATH=$PATH:$GOPATH/bin # If you haven't already
199-
go generate
200-
```
201-
202191
## Update cpp-jsonnet sub-repo
203192

204193
This repo depends on [the original Jsonnet repo](https://github.com/google/jsonnet). Shared parts include the standard library, headers files for C API and some tests.

ast/BUILD.bazel

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ go_library(
66
"ast.go",
77
"clone.go",
88
"fodder.go",
9-
"identifier_set.go",
9+
"identifier.go",
1010
"location.go",
11-
"util.go",
1211
],
1312
importpath = "github.com/google/go-jsonnet/ast",
1413
visibility = ["//visibility:public"],

ast/ast.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ import (
2121
"fmt"
2222
)
2323

24-
// Identifier represents a variable / parameter / field name.
25-
// +gen set
26-
type Identifier string
27-
28-
// Identifiers represents an Identifier slice.
29-
type Identifiers []Identifier
30-
3124
// TODO(jbeda) implement interning of identifiers if necessary. The C++
3225
// version does so.
3326

@@ -80,7 +73,7 @@ func NewNodeBase(loc LocationRange, fodder Fodder, freeVariables Identifiers) No
8073

8174
// NewNodeBaseLoc creates a new NodeBase from an initial LocationRange.
8275
func NewNodeBaseLoc(loc LocationRange, fodder Fodder) NodeBase {
83-
return NewNodeBase(loc, fodder, []Identifier{})
76+
return NewNodeBase(loc, fodder, Identifiers{})
8477
}
8578

8679
// Loc returns a NodeBase's loc.

ast/identifier.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Copyright 2016 Google Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package ast
18+
19+
import (
20+
"sort"
21+
)
22+
23+
// Identifier represents a variable / parameter / field name.
24+
type Identifier string
25+
26+
// Identifiers represents an Identifier slice.
27+
type Identifiers []Identifier
28+
29+
// IdentifierSet represents an Identifier set.
30+
type IdentifierSet map[Identifier]struct{}
31+
32+
// NewIdentifierSet creates a new IdentifierSet.
33+
func NewIdentifierSet(idents ...Identifier) IdentifierSet {
34+
set := make(IdentifierSet)
35+
for _, ident := range idents {
36+
set[ident] = struct{}{}
37+
}
38+
return set
39+
}
40+
41+
// Add adds an Identifier to the set.
42+
func (set IdentifierSet) Add(ident Identifier) bool {
43+
if _, ok := set[ident]; ok {
44+
return false
45+
}
46+
set[ident] = struct{}{}
47+
return true
48+
}
49+
50+
// AddIdentifiers adds a slice of identifiers to the set.
51+
func (set IdentifierSet) AddIdentifiers(idents Identifiers) {
52+
for _, ident := range idents {
53+
set.Add(ident)
54+
}
55+
}
56+
57+
// Contains returns true if an Identifier is in the set.
58+
func (set IdentifierSet) Contains(ident Identifier) bool {
59+
_, ok := set[ident]
60+
return ok
61+
}
62+
63+
// Remove removes an Identifier from the set.
64+
func (set IdentifierSet) Remove(ident Identifier) {
65+
delete(set, ident)
66+
}
67+
68+
// ToSlice returns an Identifiers slice from the set.
69+
func (set IdentifierSet) ToSlice() Identifiers {
70+
idents := make(Identifiers, len(set))
71+
i := 0
72+
for ident := range set {
73+
idents[i] = ident
74+
i++
75+
}
76+
return idents
77+
}
78+
79+
// ToOrderedSlice returns the elements of the current set as an ordered slice.
80+
func (set IdentifierSet) ToOrderedSlice() []Identifier {
81+
idents := set.ToSlice()
82+
sort.Sort(identifierSorter(idents))
83+
return idents
84+
}
85+
86+
type identifierSorter []Identifier
87+
88+
func (s identifierSorter) Len() int { return len(s) }
89+
func (s identifierSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
90+
func (s identifierSorter) Less(i, j int) bool { return s[i] < s[j] }
91+
92+
// Clone returns a clone of the set.
93+
func (set IdentifierSet) Clone() IdentifierSet {
94+
newSet := make(IdentifierSet, len(set))
95+
for k, v := range set {
96+
newSet[k] = v
97+
}
98+
return newSet
99+
}

ast/identifier_set.go

-174
This file was deleted.
File renamed without changes.

ast/util.go

-46
This file was deleted.

0 commit comments

Comments
 (0)