Server IP : 103.119.228.120 / Your IP : 18.221.102.0 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/lib/mysqlsh/lib/python3.9/site-packages/antlr4/atn/ |
Upload File : |
# # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. from antlr4.PredictionContext import merge from antlr4.Utils import str_list from antlr4.atn.ATN import ATN from antlr4.atn.ATNConfig import ATNConfig from antlr4.atn.SemanticContext import SemanticContext from antlr4.error.Errors import UnsupportedOperationException, IllegalStateException from functools import reduce # # Specialized {@link Set}{@code <}{@link ATNConfig}{@code >} that can track # info about the set, with support for combining similar configurations using a # graph-structured stack. # / from io import StringIO ATNSimulator = None class ATNConfigSet(object): __slots__ = ( 'configLookup', 'fullCtx', 'readonly', 'configs', 'uniqueAlt', 'conflictingAlts', 'hasSemanticContext', 'dipsIntoOuterContext', 'cachedHashCode' ) # # The reason that we need this is because we don't want the hash map to use # the standard hash code and equals. We need all configurations with the same # {@code (s,i,_,semctx)} to be equal. Unfortunately, this key effectively doubles # the number of objects associated with ATNConfigs. The other solution is to # use a hash table that lets us specify the equals/hashcode operation. def __init__(self, fullCtx:bool=True): # All configs but hashed by (s, i, _, pi) not including context. Wiped out # when we go readonly as this set becomes a DFA state. self.configLookup = dict() # Indicates that this configuration set is part of a full context # LL prediction. It will be used to determine how to merge $. With SLL # it's a wildcard whereas it is not for LL context merge. self.fullCtx = fullCtx # Indicates that the set of configurations is read-only. Do not # allow any code to manipulate the set; DFA states will point at # the sets and they must not change. This does not protect the other # fields; in particular, conflictingAlts is set after # we've made this readonly. self.readonly = False # Track the elements as they are added to the set; supports get(i)#/ self.configs = [] # TODO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation # TODO: can we track conflicts as they are added to save scanning configs later? self.uniqueAlt = 0 self.conflictingAlts = None # Used in parser and lexer. In lexer, it indicates we hit a pred # while computing a closure operation. Don't make a DFA state from this. self.hasSemanticContext = False self.dipsIntoOuterContext = False self.cachedHashCode = -1 def __iter__(self): return self.configs.__iter__() # Adding a new config means merging contexts with existing configs for # {@code (s, i, pi, _)}, where {@code s} is the # {@link ATNConfig#state}, {@code i} is the {@link ATNConfig#alt}, and # {@code pi} is the {@link ATNConfig#semanticContext}. We use # {@code (s,i,pi)} as key. # # <p>This method updates {@link #dipsIntoOuterContext} and # {@link #hasSemanticContext} when necessary.</p> #/ def add(self, config:ATNConfig, mergeCache=None): if self.readonly: raise Exception("This set is readonly") if config.semanticContext is not SemanticContext.NONE: self.hasSemanticContext = True if config.reachesIntoOuterContext > 0: self.dipsIntoOuterContext = True existing = self.getOrAdd(config) if existing is config: self.cachedHashCode = -1 self.configs.append(config) # track order here return True # a previous (s,i,pi,_), merge with it and save result rootIsWildcard = not self.fullCtx merged = merge(existing.context, config.context, rootIsWildcard, mergeCache) # no need to check for existing.context, config.context in cache # since only way to create new graphs is "call rule" and here. # We cache at both places. existing.reachesIntoOuterContext = max(existing.reachesIntoOuterContext, config.reachesIntoOuterContext) # make sure to preserve the precedence filter suppression during the merge if config.precedenceFilterSuppressed: existing.precedenceFilterSuppressed = True existing.context = merged # replace context; no need to alt mapping return True def getOrAdd(self, config:ATNConfig): h = config.hashCodeForConfigSet() l = self.configLookup.get(h, None) if l is not None: r = next((cfg for cfg in l if config.equalsForConfigSet(cfg)), None) if r is not None: return r if l is None: l = [config] self.configLookup[h] = l else: l.append(config) return config def getStates(self): return set(c.state for c in self.configs) def getPredicates(self): return list(cfg.semanticContext for cfg in self.configs if cfg.semanticContext!=SemanticContext.NONE) def get(self, i:int): return self.configs[i] def optimizeConfigs(self, interpreter:ATNSimulator): if self.readonly: raise IllegalStateException("This set is readonly") if len(self.configs)==0: return for config in self.configs: config.context = interpreter.getCachedContext(config.context) def addAll(self, coll:list): for c in coll: self.add(c) return False def __eq__(self, other): if self is other: return True elif not isinstance(other, ATNConfigSet): return False same = self.configs is not None and \ self.configs==other.configs and \ self.fullCtx == other.fullCtx and \ self.uniqueAlt == other.uniqueAlt and \ self.conflictingAlts == other.conflictingAlts and \ self.hasSemanticContext == other.hasSemanticContext and \ self.dipsIntoOuterContext == other.dipsIntoOuterContext return same def __hash__(self): if self.readonly: if self.cachedHashCode == -1: self.cachedHashCode = self.hashConfigs() return self.cachedHashCode return self.hashConfigs() def hashConfigs(self): return reduce(lambda h, cfg: hash((h, cfg)), self.configs, 0) def __len__(self): return len(self.configs) def isEmpty(self): return len(self.configs)==0 def __contains__(self, config): if self.configLookup is None: raise UnsupportedOperationException("This method is not implemented for readonly sets.") h = config.hashCodeForConfigSet() l = self.configLookup.get(h, None) if l is not None: for c in l: if config.equalsForConfigSet(c): return True return False def clear(self): if self.readonly: raise IllegalStateException("This set is readonly") self.configs.clear() self.cachedHashCode = -1 self.configLookup.clear() def setReadonly(self, readonly:bool): self.readonly = readonly self.configLookup = None # can't mod, no need for lookup cache def __str__(self): with StringIO() as buf: buf.write(str_list(self.configs)) if self.hasSemanticContext: buf.write(",hasSemanticContext=") buf.write(str(self.hasSemanticContext).lower()) # lower() to conform to java output if self.uniqueAlt!=ATN.INVALID_ALT_NUMBER: buf.write(",uniqueAlt=") buf.write(str(self.uniqueAlt)) if self.conflictingAlts is not None: buf.write(",conflictingAlts=") buf.write(str(self.conflictingAlts)) if self.dipsIntoOuterContext: buf.write(",dipsIntoOuterContext") return buf.getvalue() class OrderedATNConfigSet(ATNConfigSet): def __init__(self): super().__init__()