Skip to content

Commit

Permalink
Remove dependency on gen to generate sets (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny authored Jun 9, 2024
1 parent 5d760fb commit e544339
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 428 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
run:
skip-files: ast/identifier_set.go
linters:
enable:
- stylecheck
Expand Down
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
all: install.dependencies generate generate.stdlib build.bazel test tidy
.PHONY: all

# https://github.com/golang/go/issues/30515
# We temporarily set GO111MODULE=off here to avoid adding these binaries to the go.mod|sum files
# As they are not needed during runtime
install.dependencies : export GO111MODULE=off
install.dependencies:
git submodule init
git submodule update
go get github.com/clipperhouse/gen
go get github.com/clipperhouse/set
.PHONY: install.dependencies

build.bazel:
Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ _replace the FILTER with the name of the test you are working on_
FILTER=Builtin_manifestJsonEx make benchmark
```

## Implementation Notes

We are generating some helper classes on types by using http://clipperhouse.github.io/gen/. Do the following to regenerate these if necessary:

```bash
go get github.com/clipperhouse/gen
go get github.com/clipperhouse/set
export PATH=$PATH:$GOPATH/bin # If you haven't already
go generate
```

## Update cpp-jsonnet sub-repo

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.
Expand Down
3 changes: 1 addition & 2 deletions ast/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ go_library(
"ast.go",
"clone.go",
"fodder.go",
"identifier_set.go",
"identifier.go",
"location.go",
"util.go",
],
importpath = "github.com/google/go-jsonnet/ast",
visibility = ["//visibility:public"],
Expand Down
9 changes: 1 addition & 8 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import (
"fmt"
)

// Identifier represents a variable / parameter / field name.
// +gen set
type Identifier string

// Identifiers represents an Identifier slice.
type Identifiers []Identifier

// TODO(jbeda) implement interning of identifiers if necessary. The C++
// version does so.

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

// NewNodeBaseLoc creates a new NodeBase from an initial LocationRange.
func NewNodeBaseLoc(loc LocationRange, fodder Fodder) NodeBase {
return NewNodeBase(loc, fodder, []Identifier{})
return NewNodeBase(loc, fodder, Identifiers{})
}

// Loc returns a NodeBase's loc.
Expand Down
99 changes: 99 additions & 0 deletions ast/identifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ast

import (
"sort"
)

// Identifier represents a variable / parameter / field name.
type Identifier string

// Identifiers represents an Identifier slice.
type Identifiers []Identifier

// IdentifierSet represents an Identifier set.
type IdentifierSet map[Identifier]struct{}

// NewIdentifierSet creates a new IdentifierSet.
func NewIdentifierSet(idents ...Identifier) IdentifierSet {
set := make(IdentifierSet)
for _, ident := range idents {
set[ident] = struct{}{}
}
return set
}

// Add adds an Identifier to the set.
func (set IdentifierSet) Add(ident Identifier) bool {
if _, ok := set[ident]; ok {
return false
}
set[ident] = struct{}{}
return true
}

// AddIdentifiers adds a slice of identifiers to the set.
func (set IdentifierSet) AddIdentifiers(idents Identifiers) {
for _, ident := range idents {
set.Add(ident)
}
}

// Contains returns true if an Identifier is in the set.
func (set IdentifierSet) Contains(ident Identifier) bool {
_, ok := set[ident]
return ok
}

// Remove removes an Identifier from the set.
func (set IdentifierSet) Remove(ident Identifier) {
delete(set, ident)
}

// ToSlice returns an Identifiers slice from the set.
func (set IdentifierSet) ToSlice() Identifiers {
idents := make(Identifiers, len(set))
i := 0
for ident := range set {
idents[i] = ident
i++
}
return idents
}

// ToOrderedSlice returns the elements of the current set as an ordered slice.
func (set IdentifierSet) ToOrderedSlice() []Identifier {
idents := set.ToSlice()
sort.Sort(identifierSorter(idents))
return idents
}

type identifierSorter []Identifier

func (s identifierSorter) Len() int { return len(s) }
func (s identifierSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s identifierSorter) Less(i, j int) bool { return s[i] < s[j] }

// Clone returns a clone of the set.
func (set IdentifierSet) Clone() IdentifierSet {
newSet := make(IdentifierSet, len(set))
for k, v := range set {
newSet[k] = v
}
return newSet
}
174 changes: 0 additions & 174 deletions ast/identifier_set.go

This file was deleted.

File renamed without changes.
46 changes: 0 additions & 46 deletions ast/util.go

This file was deleted.

Loading

0 comments on commit e544339

Please sign in to comment.