Sort FreeVariables slice (#148)

* sort FreeVariables slice

* regenerate the standard library AST
This commit is contained in:
Liang Mingqiang 2017-11-09 22:55:36 +09:00 committed by Dave Cunningham
parent b04e73e163
commit ce84685fb0
3 changed files with 2174 additions and 2140 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,41 @@
/*
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 package ast
import "sort"
func (i *IdentifierSet) Append(idents Identifiers) { func (i *IdentifierSet) Append(idents Identifiers) {
for _, ident := range idents { for _, ident := range idents {
i.Add(ident) i.Add(ident)
} }
} }
// ToOrderedSlice returns the elements of the current set as a ordered slice
func (set IdentifierSet) ToOrderedSlice() []Identifier {
var s []Identifier
for v := range set {
s = append(s, v)
}
sort.Sort(identifierSorter(s))
return s
}
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] }

View File

@ -145,7 +145,7 @@ func analyzeVisit(a ast.Node, inObject bool, vars ast.IdentifierSet) error {
default: default:
panic(fmt.Sprintf("Unexpected node %#v", a)) panic(fmt.Sprintf("Unexpected node %#v", a))
} }
a.SetFreeVariables(s.freeVars.ToSlice()) a.SetFreeVariables(s.freeVars.ToOrderedSlice())
return s.err return s.err
} }