Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions runtime/Go/antlr/atn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package antlr

import (
"fmt"
"strconv"
)

type Comparable interface {
Expand Down Expand Up @@ -37,8 +36,6 @@ type ATNConfig interface {

getPrecedenceFilterSuppressed() bool
setPrecedenceFilterSuppressed(bool)

shortHash() string
}

type BaseATNConfig struct {
Expand Down Expand Up @@ -169,10 +166,6 @@ func (b *BaseATNConfig) equals(o interface{}) bool {
return nums && alts && cons && sups && equal
}

func (b *BaseATNConfig) shortHash() string {
return strconv.Itoa(b.state.GetStateNumber()) + "/" + strconv.Itoa(b.alt) + "/" + b.semanticContext.String()
}

func (b *BaseATNConfig) HashCode() int {
var c int
if b.context != nil {
Expand Down
8 changes: 1 addition & 7 deletions runtime/Go/antlr/dfa_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package antlr

import (
"fmt"
"strconv"
)

// PredPrediction maps a predicate to a predicted alternative.
Expand Down Expand Up @@ -133,12 +132,7 @@ func (d *DFAState) equals(other interface{}) bool {
}

func (d *DFAState) String() string {
return strconv.Itoa(d.stateNumber) + ":" + d.Hash()
}

func (d *DFAState) Hash() string {
var s string

if d.isAcceptState {
if d.predicates != nil {
s = "=>" + fmt.Sprint(d.predicates)
Expand All @@ -147,7 +141,7 @@ func (d *DFAState) Hash() string {
}
}

return fmt.Sprint(d.configs) + s
return fmt.Sprintf("%d:%s%s", fmt.Sprint(d.configs), s)
}

func (d *DFAState) HashCode() int {
Expand Down
49 changes: 32 additions & 17 deletions runtime/Go/antlr/lexer_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type LexerAction interface {
getActionType() int
getIsPositionDependent() bool
execute(lexer Lexer)
Hash() string
HashCode() int
equals(other LexerAction) bool
}
Expand Down Expand Up @@ -56,10 +55,6 @@ func (b *BaseLexerAction) HashCode() int {
return b.actionType
}

func (b *BaseLexerAction) Hash() string {
return strconv.Itoa(b.actionType)
}

func (b *BaseLexerAction) equals(other LexerAction) bool {
return b == other
}
Expand Down Expand Up @@ -109,8 +104,11 @@ func (l *LexerTypeAction) execute(lexer Lexer) {
lexer.setType(l.thetype)
}

func (l *LexerTypeAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.thetype)
func (l *LexerTypeAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.thetype)
return finish(h, 2)
}

func (l *LexerTypeAction) equals(other LexerAction) bool {
Expand Down Expand Up @@ -150,8 +148,11 @@ func (l *LexerPushModeAction) execute(lexer Lexer) {
lexer.pushMode(l.mode)
}

func (l *LexerPushModeAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.mode)
func (l *LexerPushModeAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.mode)
return finish(h, 2)
}

func (l *LexerPushModeAction) equals(other LexerAction) bool {
Expand Down Expand Up @@ -244,8 +245,11 @@ func (l *LexerModeAction) execute(lexer Lexer) {
lexer.setMode(l.mode)
}

func (l *LexerModeAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.mode)
func (l *LexerModeAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.mode)
return finish(h, 2)
}

func (l *LexerModeAction) equals(other LexerAction) bool {
Expand Down Expand Up @@ -299,8 +303,12 @@ func (l *LexerCustomAction) execute(lexer Lexer) {
lexer.Action(nil, l.ruleIndex, l.actionIndex)
}

func (l *LexerCustomAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.ruleIndex) + strconv.Itoa(l.actionIndex)
func (l *LexerCustomAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.ruleIndex)
h = update(h, l.actionIndex)
return finish(h, 3)
}

func (l *LexerCustomAction) equals(other LexerAction) bool {
Expand Down Expand Up @@ -336,8 +344,11 @@ func (l *LexerChannelAction) execute(lexer Lexer) {
lexer.setChannel(l.channel)
}

func (l *LexerChannelAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.channel)
func (l *LexerChannelAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.channel)
return finish(h, 2)
}

func (l *LexerChannelAction) equals(other LexerAction) bool {
Expand Down Expand Up @@ -401,8 +412,12 @@ func (l *LexerIndexedCustomAction) execute(lexer Lexer) {
l.lexerAction.execute(lexer)
}

func (l *LexerIndexedCustomAction) Hash() string {
return strconv.Itoa(l.actionType) + strconv.Itoa(l.offset) + l.lexerAction.Hash()
func (l *LexerIndexedCustomAction) HashCode() int {
h := initHash(0)
h = update(h, l.actionType)
h = update(h, l.offset)
h = update(h, l.lexerAction.HashCode())
return finish(h, 3)
}

func (l *LexerIndexedCustomAction) equals(other LexerAction) bool {
Expand Down
17 changes: 2 additions & 15 deletions runtime/Go/antlr/lexer_action_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package antlr

type LexerActionExecutor struct {
lexerActions []LexerAction
cachedHashString string
cachedHash int
}

Expand All @@ -29,16 +28,11 @@ func NewLexerActionExecutor(lexerActions []LexerAction) *LexerActionExecutor {

// Caches the result of {@link //hashCode} since the hash code is an element
// of the performance-critical {@link LexerATNConfig//hashCode} operation.

var s string
l.cachedHash = initHash(57)
for _, a := range lexerActions {
s += a.Hash()
l.cachedHash = update(l.cachedHash, a.HashCode())
}

l.cachedHashString = s // "".join([str(la) for la in

return l
}

Expand All @@ -60,10 +54,7 @@ func LexerActionExecutorappend(lexerActionExecutor *LexerActionExecutor, lexerAc
return NewLexerActionExecutor([]LexerAction{lexerAction})
}

lexerActions := append(lexerActionExecutor.lexerActions, lexerAction)

// lexerActions := lexerActionExecutor.lexerActions.concat([ lexerAction ])
return NewLexerActionExecutor(lexerActions)
return NewLexerActionExecutor(append(lexerActionExecutor.lexerActions, lexerAction))
}

// Creates a {@link LexerActionExecutor} which encodes the current offset
Expand Down Expand Up @@ -160,10 +151,6 @@ func (l *LexerActionExecutor) execute(lexer Lexer, input CharStream, startIndex
}
}

func (l *LexerActionExecutor) Hash() string {
return l.cachedHashString
}

func (l *LexerActionExecutor) HashCode() int {
if l == nil {
return 61
Expand All @@ -177,7 +164,7 @@ func (l *LexerActionExecutor) equals(other interface{}) bool {
} else if _, ok := other.(*LexerActionExecutor); !ok {
return false
} else {
return l.cachedHashString == other.(*LexerActionExecutor).cachedHashString &&
return l.cachedHash == other.(*LexerActionExecutor).cachedHash &&
&l.lexerActions == &other.(*LexerActionExecutor).lexerActions
}
}
8 changes: 0 additions & 8 deletions runtime/Go/antlr/semantic_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ func (p *Predicate) evaluate(parser Recognizer, outerContext RuleContext) bool {
return parser.Sempred(localctx, p.ruleIndex, p.predIndex)
}

func (p *Predicate) Hash() string {
return strconv.Itoa(p.ruleIndex) + "/" + strconv.Itoa(p.predIndex) + "/" + fmt.Sprint(p.isCtxDependent)
}

func (p *Predicate) equals(other interface{}) bool {
if p == other {
return true
Expand Down Expand Up @@ -147,10 +143,6 @@ func (p *PrecedencePredicate) compareTo(other *PrecedencePredicate) int {
return p.precedence - other.precedence
}

func (p *PrecedencePredicate) Hash() string {
return "31"
}

func (p *PrecedencePredicate) equals(other interface{}) bool {
if p == other {
return true
Expand Down
11 changes: 0 additions & 11 deletions runtime/Go/antlr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,9 @@ func standardHashFunction(a interface{}) int {
return h.HashCode()
}

if h, ok := a.(Hasher); ok {
s := h.Hash()
ha := fnv.New32a()
ha.Write([]byte((s)))
return int(ha.Sum32())
}

panic("Not Hasher")
}

type Hasher interface {
Hash() string
}

type HashCoder interface {
HashCode() int
}
Expand Down