diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index 19dcc3f435..150745eef8 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -166,7 +166,7 @@ type struct { } -var ParserStaticData struct { +type ParserStaticData struct { once sync.Once serializedATN []int32 LiteralNames []string @@ -177,8 +177,7 @@ var ParserStaticData struct { decisionToDFA []*antlr.DFA } -func ParserInit() { - staticData := &ParserStaticData +func ParserInit(staticData *ParserStaticData) { staticData.LiteralNames = []string{ , @@ -198,10 +197,9 @@ func ParserInit() { staticData.serializedATN = deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) - atn := staticData.atn - staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + staticData.decisionToDFA = make([]*antlr.DFA, len(staticData.atn.DecisionToState)) decisionToDFA := staticData.decisionToDFA - for index, state := range atn.DecisionToState { + for index, state := range staticData.atn.DecisionToState { decisionToDFA[index] = antlr.NewDFA(state, index) } } @@ -210,17 +208,17 @@ func ParserInit() { // static state used to implement the parser is lazily initialized during the first call to // New(). You can call this function if you wish to initialize the static state ahead // of time. -func Init() { - staticData := &ParserStaticData - staticData.once.Do(ParserInit) +func Init() *ParserStaticData { + staticData := &ParserStaticData{} + ParserInit(staticData) + return staticData } // New produces a new parser instance for the optional input antlr.TokenStream. func New(input antlr.TokenStream) * { - Init() + staticData := Init() this := new() this.BaseParser = antlr.NewBaseParser(input) - staticData := &ParserStaticData this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) this.RuleNames = staticData.RuleNames this.LiteralNames = staticData.LiteralNames @@ -1494,7 +1492,7 @@ type struct { // TODO: EOF string } -var LexerStaticData struct { +type LexerStaticData struct { once sync.Once serializedATN []int32 ChannelNames []string @@ -1507,8 +1505,7 @@ var LexerStaticData struct { decisionToDFA []*antlr.DFA } -func LexerInit() { - staticData := &LexerStaticData +func LexerInit(staticData *LexerStaticData) { staticData.ChannelNames = []string{ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", "}; separator=", ", wrap>, } @@ -1534,10 +1531,9 @@ func LexerInit() { staticData.serializedATN = deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) - atn := staticData.atn - staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + staticData.decisionToDFA = make([]*antlr.DFA, len(staticData.atn.DecisionToState)) decisionToDFA := staticData.decisionToDFA - for index, state := range atn.DecisionToState { + for index, state := range staticData.atn.DecisionToState { decisionToDFA[index] = antlr.NewDFA(state, index) } } @@ -1546,17 +1542,17 @@ func LexerInit() { // static state used to implement the lexer is lazily initialized during the first call to // New(). You can call this function if you wish to initialize the static state ahead // of time. -func Init() { - staticData := &LexerStaticData - staticData.once.Do(LexerInit) +func Init() *LexerStaticData { + staticData := &LexerStaticData{} + LexerInit(staticData) + return staticData } // New produces a new lexer instance for the optional input antlr.CharStream. func New(input antlr.CharStream) * { - Init() l := new() l.BaseLexer = antlr.NewBaseLexer(input) - staticData := &LexerStaticData + staticData := Init() l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) l.channelNames = staticData.ChannelNames l.modeNames = staticData.ModeNames