├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── docs ├── codegen │ └── README.md ├── fronted │ └── ASTVisitor.md ├── llvm_ir_manual.md ├── optimizer │ └── dag.md └── structure │ ├── baseclass.md │ ├── inst.md │ ├── ir.md │ ├── symtable.md │ └── value.md ├── potential_bugs.md ├── src ├── codegen │ └── armv8 │ │ ├── codegen.hh │ │ ├── liveness_info.cpp │ │ ├── liveness_info.hh │ │ ├── register_allocation.hh │ │ └── sdiv_smod_bit_operation.hh ├── common.cpp ├── common.hh ├── dbg.h ├── frontend │ ├── ASTVisitor.cpp │ ├── ASTVisitor.hh │ ├── SysY.g4 │ ├── SysY.interp │ ├── SysY.tokens │ ├── SysYBaseVisitor.cpp │ ├── SysYBaseVisitor.h │ ├── SysYLexer.cpp │ ├── SysYLexer.h │ ├── SysYLexer.interp │ ├── SysYLexer.tokens │ ├── SysYParser.cpp │ ├── SysYParser.h │ ├── SysYToken.g4 │ ├── SysYVisitor.cpp │ └── SysYVisitor.h ├── main.cpp ├── optimizer │ ├── branch_opt.hh │ ├── constant_propagation.cpp │ ├── constant_propagation.hh │ ├── dead_code_elim.cpp │ ├── dead_code_elim.hh │ ├── function_inline.cpp │ ├── function_inline.hh │ ├── global_var_const.cpp │ ├── global_var_const.hh │ ├── gvn_gcm.hh │ ├── gvn_gvm.cpp │ ├── inst_combine.cpp │ ├── inst_combine.hh │ ├── load_store_reordering.cpp │ ├── load_store_reordering.hh │ ├── mem2reg.cpp │ ├── mem2reg.hh │ ├── memaccess_opt.cpp │ ├── memaccess_opt.hh │ ├── pass_manager.cpp │ ├── pass_manager.hh │ ├── reg2mem.cpp │ └── reg2mem.hh └── structure │ ├── baseclass.hh │ ├── ir.cpp │ ├── ir.hh │ ├── llir.cpp │ ├── llir.hh │ ├── symtable.cpp │ ├── symtable.hh │ ├── value.cpp │ └── value.hh ├── sylib.c ├── sylib.h └── third_party └── antlr4-runtime ├── ANTLRErrorListener.cpp ├── ANTLRErrorListener.h ├── ANTLRErrorStrategy.cpp ├── ANTLRErrorStrategy.h ├── ANTLRFileStream.cpp ├── ANTLRFileStream.h ├── ANTLRInputStream.cpp ├── ANTLRInputStream.h ├── BailErrorStrategy.cpp ├── BailErrorStrategy.h ├── BaseErrorListener.cpp ├── BaseErrorListener.h ├── BufferedTokenStream.cpp ├── BufferedTokenStream.h ├── CharStream.cpp ├── CharStream.h ├── CommonToken.cpp ├── CommonToken.h ├── CommonTokenFactory.cpp ├── CommonTokenFactory.h ├── CommonTokenStream.cpp ├── CommonTokenStream.h ├── ConsoleErrorListener.cpp ├── ConsoleErrorListener.h ├── DefaultErrorStrategy.cpp ├── DefaultErrorStrategy.h ├── DiagnosticErrorListener.cpp ├── DiagnosticErrorListener.h ├── Exceptions.cpp ├── Exceptions.h ├── FailedPredicateException.cpp ├── FailedPredicateException.h ├── InputMismatchException.cpp ├── InputMismatchException.h ├── IntStream.cpp ├── IntStream.h ├── InterpreterRuleContext.cpp ├── InterpreterRuleContext.h ├── Lexer.cpp ├── Lexer.h ├── LexerInterpreter.cpp ├── LexerInterpreter.h ├── LexerNoViableAltException.cpp ├── LexerNoViableAltException.h ├── ListTokenSource.cpp ├── ListTokenSource.h ├── NoViableAltException.cpp ├── NoViableAltException.h ├── Parser.cpp ├── Parser.h ├── ParserInterpreter.cpp ├── ParserInterpreter.h ├── ParserRuleContext.cpp ├── ParserRuleContext.h ├── ProxyErrorListener.cpp ├── ProxyErrorListener.h ├── RecognitionException.cpp ├── RecognitionException.h ├── Recognizer.cpp ├── Recognizer.h ├── RuleContext.cpp ├── RuleContext.h ├── RuleContextWithAltNum.cpp ├── RuleContextWithAltNum.h ├── RuntimeMetaData.cpp ├── RuntimeMetaData.h ├── Token.cpp ├── Token.h ├── TokenFactory.h ├── TokenSource.cpp ├── TokenSource.h ├── TokenStream.cpp ├── TokenStream.h ├── TokenStreamRewriter.cpp ├── TokenStreamRewriter.h ├── UnbufferedCharStream.cpp ├── UnbufferedCharStream.h ├── UnbufferedTokenStream.cpp ├── UnbufferedTokenStream.h ├── Vocabulary.cpp ├── Vocabulary.h ├── WritableToken.cpp ├── WritableToken.h ├── antlr4-common.h ├── antlr4-runtime.h ├── atn ├── ATN.cpp ├── ATN.h ├── ATNConfig.cpp ├── ATNConfig.h ├── ATNConfigSet.cpp ├── ATNConfigSet.h ├── ATNDeserializationOptions.cpp ├── ATNDeserializationOptions.h ├── ATNDeserializer.cpp ├── ATNDeserializer.h ├── ATNSerializer.cpp ├── ATNSerializer.h ├── ATNSimulator.cpp ├── ATNSimulator.h ├── ATNState.cpp ├── ATNState.h ├── ATNType.h ├── AbstractPredicateTransition.cpp ├── AbstractPredicateTransition.h ├── ActionTransition.cpp ├── ActionTransition.h ├── AmbiguityInfo.cpp ├── AmbiguityInfo.h ├── ArrayPredictionContext.cpp ├── ArrayPredictionContext.h ├── AtomTransition.cpp ├── AtomTransition.h ├── BasicBlockStartState.cpp ├── BasicBlockStartState.h ├── BasicState.cpp ├── BasicState.h ├── BlockEndState.cpp ├── BlockEndState.h ├── BlockStartState.cpp ├── BlockStartState.h ├── ContextSensitivityInfo.cpp ├── ContextSensitivityInfo.h ├── DecisionEventInfo.cpp ├── DecisionEventInfo.h ├── DecisionInfo.cpp ├── DecisionInfo.h ├── DecisionState.cpp ├── DecisionState.h ├── EmptyPredictionContext.cpp ├── EmptyPredictionContext.h ├── EpsilonTransition.cpp ├── EpsilonTransition.h ├── ErrorInfo.cpp ├── ErrorInfo.h ├── LL1Analyzer.cpp ├── LL1Analyzer.h ├── LexerATNConfig.cpp ├── LexerATNConfig.h ├── LexerATNSimulator.cpp ├── LexerATNSimulator.h ├── LexerAction.cpp ├── LexerAction.h ├── LexerActionExecutor.cpp ├── LexerActionExecutor.h ├── LexerActionType.h ├── LexerChannelAction.cpp ├── LexerChannelAction.h ├── LexerCustomAction.cpp ├── LexerCustomAction.h ├── LexerIndexedCustomAction.cpp ├── LexerIndexedCustomAction.h ├── LexerModeAction.cpp ├── LexerModeAction.h ├── LexerMoreAction.cpp ├── LexerMoreAction.h ├── LexerPopModeAction.cpp ├── LexerPopModeAction.h ├── LexerPushModeAction.cpp ├── LexerPushModeAction.h ├── LexerSkipAction.cpp ├── LexerSkipAction.h ├── LexerTypeAction.cpp ├── LexerTypeAction.h ├── LookaheadEventInfo.cpp ├── LookaheadEventInfo.h ├── LoopEndState.cpp ├── LoopEndState.h ├── Makefile ├── NotSetTransition.cpp ├── NotSetTransition.h ├── OrderedATNConfigSet.cpp ├── OrderedATNConfigSet.h ├── ParseInfo.cpp ├── ParseInfo.h ├── ParserATNSimulator.cpp ├── ParserATNSimulator.h ├── PlusBlockStartState.cpp ├── PlusBlockStartState.h ├── PlusLoopbackState.cpp ├── PlusLoopbackState.h ├── PrecedencePredicateTransition.cpp ├── PrecedencePredicateTransition.h ├── PredicateEvalInfo.cpp ├── PredicateEvalInfo.h ├── PredicateTransition.cpp ├── PredicateTransition.h ├── PredictionContext.cpp ├── PredictionContext.h ├── PredictionMode.cpp ├── PredictionMode.h ├── ProfilingATNSimulator.cpp ├── ProfilingATNSimulator.h ├── RangeTransition.cpp ├── RangeTransition.h ├── RuleStartState.cpp ├── RuleStartState.h ├── RuleStopState.cpp ├── RuleStopState.h ├── RuleTransition.cpp ├── RuleTransition.h ├── SemanticContext.cpp ├── SemanticContext.h ├── SetTransition.cpp ├── SetTransition.h ├── SingletonPredictionContext.cpp ├── SingletonPredictionContext.h ├── StarBlockStartState.cpp ├── StarBlockStartState.h ├── StarLoopEntryState.cpp ├── StarLoopEntryState.h ├── StarLoopbackState.cpp ├── StarLoopbackState.h ├── TokensStartState.cpp ├── TokensStartState.h ├── Transition.cpp ├── Transition.h ├── WildcardTransition.cpp └── WildcardTransition.h ├── dfa ├── DFA.cpp ├── DFA.h ├── DFASerializer.cpp ├── DFASerializer.h ├── DFAState.cpp ├── DFAState.h ├── LexerDFASerializer.cpp └── LexerDFASerializer.h ├── misc ├── InterpreterDataReader.cpp ├── InterpreterDataReader.h ├── Interval.cpp ├── Interval.h ├── IntervalSet.cpp ├── IntervalSet.h ├── MurmurHash.cpp ├── MurmurHash.h ├── Predicate.cpp └── Predicate.h ├── support ├── Any.cpp ├── Any.h ├── Arrays.cpp ├── Arrays.h ├── BitSet.h ├── CPPUtils.cpp ├── CPPUtils.h ├── Declarations.h ├── StringUtils.cpp ├── StringUtils.h ├── guid.cpp └── guid.h └── tree ├── AbstractParseTreeVisitor.h ├── ErrorNode.cpp ├── ErrorNode.h ├── ErrorNodeImpl.cpp ├── ErrorNodeImpl.h ├── IterativeParseTreeWalker.cpp ├── IterativeParseTreeWalker.h ├── ParseTree.cpp ├── ParseTree.h ├── ParseTreeListener.cpp ├── ParseTreeListener.h ├── ParseTreeProperty.h ├── ParseTreeVisitor.cpp ├── ParseTreeVisitor.h ├── ParseTreeWalker.cpp ├── ParseTreeWalker.h ├── TerminalNode.cpp ├── TerminalNode.h ├── TerminalNodeImpl.cpp ├── TerminalNodeImpl.h ├── Trees.cpp ├── Trees.h ├── pattern ├── Chunk.cpp ├── Chunk.h ├── ParseTreeMatch.cpp ├── ParseTreeMatch.h ├── ParseTreePattern.cpp ├── ParseTreePattern.h ├── ParseTreePatternMatcher.cpp ├── ParseTreePatternMatcher.h ├── RuleTagToken.cpp ├── RuleTagToken.h ├── TagChunk.cpp ├── TagChunk.h ├── TextChunk.cpp ├── TextChunk.h ├── TokenTagToken.cpp └── TokenTagToken.h └── xpath ├── XPath.cpp ├── XPath.h ├── XPathElement.cpp ├── XPathElement.h ├── XPathLexer.cpp ├── XPathLexer.g4 ├── XPathLexer.h ├── XPathLexer.tokens ├── XPathLexerErrorListener.cpp ├── XPathLexerErrorListener.h ├── XPathRuleAnywhereElement.cpp ├── XPathRuleAnywhereElement.h ├── XPathRuleElement.cpp ├── XPathRuleElement.h ├── XPathTokenAnywhereElement.cpp ├── XPathTokenAnywhereElement.h ├── XPathTokenElement.cpp ├── XPathTokenElement.h ├── XPathWildcardAnywhereElement.cpp ├── XPathWildcardAnywhereElement.h ├── XPathWildcardElement.cpp └── XPathWildcardElement.h /.gitignore: -------------------------------------------------------------------------------- 1 | # build dir 2 | cmake-*/ 3 | build/ 4 | *.sy 5 | 6 | # log file 7 | *.log 8 | *.res 9 | 10 | # IDE 11 | .idea/ 12 | .vscode/ 13 | 14 | # java 15 | src/frontend/.antlr/ 16 | 17 | # macos 18 | *.DS_Store 19 | 20 | # codegen 21 | *.s 22 | *.o 23 | *.asm 24 | *.ll 25 | exec 26 | 27 | #compiler2022 28 | compiler2022/* 29 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "compiler2022"] 2 | path = compiler2022 3 | url = https://gitlab.eduxiji.net/nscscc/compiler2022.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | set(project_name compiler) 3 | project(${project_name} CXX) 4 | set(CMAKE_CXX_STANDARD 17) 5 | 6 | file(GLOB_RECURSE source_files "src/*.cpp") 7 | file(GLOB_RECURSE source_lib "third_party/*.cpp") 8 | add_compile_options(-g -std=c++17 -O2) 9 | include_directories(src) 10 | include_directories(src/structure) 11 | include_directories(src/frontend) 12 | include_directories(src/optimizer) 13 | include_directories(src/codegen/armv8) 14 | include_directories(third_party/antlr4-runtime) 15 | add_executable(compiler ${source_files} ${source_lib}) -------------------------------------------------------------------------------- /docs/codegen/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocodery/SysYCompiler/3b6793766e0a95e159edc7a3ae7b799e31196148/docs/codegen/README.md -------------------------------------------------------------------------------- /docs/llvm_ir_manual.md: -------------------------------------------------------------------------------- 1 | * `ret` 2 | * `br` 3 | * `add` 4 | * `fadd` 5 | * `sub` 6 | * `fsub` 7 | * `mul` 8 | * `fmul` 9 | * `sdiv` 10 | * `fdiv` 11 | * `srem` 12 | * `frem` 13 | * `alloca` 14 | * `load` 15 | * `store` 16 | * `getelementptr` 17 | * `icmp` 18 | * `fcmp` 19 | * `phi` 20 | * `call` 21 | * `zext .. to` 22 | * `fpext .. to` 23 | * `sitofp .. to` 24 | * `fptosi .. to` -------------------------------------------------------------------------------- /docs/structure/baseclass.md: -------------------------------------------------------------------------------- 1 | ## BaseClass 2 | 3 | #### Info 4 | ```cpp 5 | class Info { 6 | public: 7 | virtual ~Info() { } 8 | }; 9 | ``` 10 | `Info`基类, 主要用于派生`BasicBlock`和`Scope` 11 | 12 | #### Inst 13 | ```cpp 14 | class Inst: public Info { 15 | public: 16 | virtual ~Inst() { } 17 | }; 18 | ``` 19 | `Inst`基类, 主要用于派生各种指令类 20 | 21 | #### VirtReg 22 | ```cpp 23 | class VirtReg: public Info { 24 | public: 25 | int32_t reg_id; 26 | }; 27 | ``` 28 | 虚拟寄存器, 目前用于记录寄存器号 29 | -------------------------------------------------------------------------------- /docs/structure/ir.md: -------------------------------------------------------------------------------- 1 | ## IR 2 | 3 | #### BasicBlock 4 | ```cpp 5 | class BasicBlock: public Info { 6 | public: 7 | int32_t bb_idx; 8 | vector basic_block; 9 | vector parants; 10 | vector childrens; 11 | }; 12 | ``` 13 | `BasicBlock`顾名思义就是基本块 14 | 它用来记录当前基本块的块号和块内指令 15 | 有`parents`和`children`记录前驱和后继 16 | 17 | #### Scode 18 | ```cpp 19 | class Scope: public Info { 20 | public: 21 | int32_t sp_idx; 22 | VariableTable *local_table; 23 | vector *elements; // `Info` -> `Scope` or `BasicBlock` 24 | Scope* parent; 25 | }; 26 | ``` 27 | ``Scope``用于保存一个作用域内的内容 28 | 当前作用域的符号表`local_table`, 作用域下的内容`elements`, 父作用域`parent` 29 | 当前作用域下的符号表的意义就不需要多说了 30 | 作用域下的内容, 即基本块或者子作用域, 我们的代码保证这里不会出现其他类型 31 | 父作用域主要用来查询父作用域的符号表来对本作用域使用的变量进行定位 32 | 33 | #### Function 34 | ```cpp 35 | class Function { 36 | public: 37 | FunctionInfo func_info; 38 | Scope *main_scope; 39 | }; 40 | ``` 41 | 有了前面的数据结构基础 42 | 对函数的定义就比较简单了 43 | 函数只需要`FunctionInfo`记录函数名和参数, `Scope`记录函数体的内容即可 44 | 45 | #### LibFunction 46 | ```cpp 47 | class LibFunction { 48 | public: 49 | FunctionInfo libfunc_info; 50 | bool is_used; 51 | }; 52 | ``` 53 | 这里记录了`SysY`的库函数的函数名和参数, 以及该函数是否被使用 54 | 55 | #### CompUnit 56 | ```cpp 57 | class CompUnit: public Info { 58 | public: 59 | Scope *global_scope; 60 | vector functions; 61 | LibFunction lib_functions[11]; 62 | }; 63 | ``` 64 | `CompUnit`则是整个文件的变量, 函数相关信息 65 | `global_scope`仅会记录全局符号表, 将函数的父作用域设置为它 66 | 若不设置成`Scope`而是`VariableTable`则会对访问全局符号表造成一些不必要的麻烦 67 | `functions`和`lib_functions`就不在此赘述了 68 | -------------------------------------------------------------------------------- /docs/structure/symtable.md: -------------------------------------------------------------------------------- 1 | ## Symtable 2 | 3 | #### VarType 4 | ```cpp 5 | class VarType { 6 | public: 7 | bool is_const; 8 | bool is_array; 9 | bool is_args; 10 | vector array_dims; 11 | DeclType decl_type; 12 | }; 13 | ``` 14 | 很明显的可以看出, `VarType`是用于记录某个变量在声明时的相关信息 15 | is const ? is array ? is argument ? 16 | if it is array tpye, `array_dims` will record related infomation 17 | and also its decl type 18 | 19 | #### Variable 20 | ```cpp 21 | class Variable { 22 | public: 23 | int var_idx; 24 | VarType type; 25 | int32_t int_scalar; 26 | float float_scalar; 27 | vector int_list; 28 | vector float_list; 29 | }; 30 | ``` 31 | `Variable`记录了某个声明的变量的类型和编号 32 | if it is array tpye, `array_dims` will record related infomation 33 | if the variable is inited, the init value is store in `int_scalar` or `float_scalar` or `int_list` or `float_list` 34 | 这个编号可能有用可能没用, 后期的相关优化有可能会使用 35 | 36 | #### VariableTable 37 | ```cpp 38 | using VarPair = pair; 39 | class VariableTable { 40 | public: 41 | vector var_table; 42 | } 43 | ``` 44 | `VarPair`用于封装变量名和变量的信息 45 | 这将为后续在符号表中对变量进行查询提供便利 46 | 我们设计了`findInCurTable`和`getInCurTable`用于判断查询的变量是否在符号表中和从符号表中取出变量 47 | 48 | #### FunctionInfo 49 | ```cpp 50 | class FunctionInfo { 51 | public: 52 | string func_name; 53 | DeclType return_type; 54 | vector func_args; 55 | }; 56 | ``` 57 | `FunctionInfo`用于记录函数名, 返回类型, 参数列表的信息 58 | 这将后续与`Function`结合使用 -------------------------------------------------------------------------------- /docs/structure/value.md: -------------------------------------------------------------------------------- 1 | ## Value 2 | 3 | #### CTValue 4 | ```cpp 5 | class CTValue { 6 | public: 7 | DeclType type; 8 | int32_t int_value; 9 | float float_value; 10 | }; 11 | 12 | CTValue operator + (CTValue lhs, CTValue rhs); 13 | CTValue operator - (CTValue lhs, CTValue rhs); 14 | CTValue operator * (CTValue lhs, CTValue rhs); 15 | CTValue operator / (CTValue lhs, CTValue rhs); 16 | CTValue operator % (CTValue lhs, CTValue rhs); 17 | CTValue operator - (CTValue rhs); 18 | ``` 19 | 编译期可以计算出来的值, 例如数字 / 用常量声明的常量等 20 | 并对运算符进行重载, 可以自动进行类型转换 21 | 22 | #### IRValue 23 | ```cpp 24 | class IRValue { 25 | public: 26 | VarType type; 27 | VirtReg reg; 28 | bool is_left_value; 29 | }; 30 | ``` 31 | 编译期不能计算的值, 例如表达式计算出来的值 32 | 用于记录该值的类型, 存储的虚拟寄存器号, 是否作为左值 33 | 并可以判断是否可以被赋值 34 | -------------------------------------------------------------------------------- /potential_bugs.md: -------------------------------------------------------------------------------- 1 | - CodeGen 2 | # TODO: 3 | 1. 把浮点的inst改一下,如果是sreg则就地操作,不必移动至s0和s1 4 | 2. 除法、模运算换成二进制 5 | 3. pattern recognition (crypto-rotate/or/and) 6 | 4. sub (-1, reg) 7 | 8 | 注意事项:数组全是指针,标量全是变量 9 | 10 | 1. LiveUse生成:如果一个函数的参数没有在函数体内被使用,可能会出问题(因为LiveUse和LiveDef中都没有它,但是传参的时候要用到) 11 | 2. 减法取负优化 - 浮点可能出问题 12 | 3. 暂时没有考虑函数参数超过四个的情况 13 | 4. cmp指令没有交换,后期或许可以优化 14 | 5. fcmp指令返回值没分配寄存器,可能是个坑 15 | 6. mov整数的方式或许可以优化 (灵活的操作数2): 16 | ``` 17 | https://developer.arm.com/documentation/dui0068/b/ARM-Instruction-Reference/ARM-general-data-processing-instructions/Flexible-second-operand?lang=en 18 | ``` 19 | 7. param中的str长度(128) 20 | 8. mod 21 | 9. ltorg 22 | 10. borrow逻辑:得找没有被当前语句使用的寄存器才行 23 | 11. 以下内容可根据参数个数和返回值的情况进行优化 24 | ```c 25 | #define LOCAL_VARS_SAVE_MEMCPY_REGISTERS {r0, r1, r2, lr} 26 | #define LOCAL_VARS_LOAD_MEMCPY_REGISTERS {r0, lr} 27 | ``` 28 | 12. call时候的寄存器压栈:有些寄存器里存的变量已经在LiveInterval的末期,不用压栈 29 | 13. call时候移动参数:有时候没有冲突,不用交换 30 | 14. 改变了AddSub的逻辑,现在dst和src大多数情况下可以相同 31 | 15. Operand2可以优化,比如-(-1)可以优化成+1 32 | - IR 33 | 1. LLIR_RET指令:对于如下代码段 34 | ```c 35 | float main(){ 36 | return 3.0; 37 | } 38 | ``` 39 | 生成的LLIR_RET指令中,`ret_inst->ret_value.ctv->int_value`的值是3,但`ret_inst->ret_value.ctv->float_value`的值是0 40 | - 前端 41 | 1. 非const全局变量初始化优化 42 | 2. 常量传播可以节省后面寄存器分配,一定要做 43 | -------------------------------------------------------------------------------- /src/codegen/armv8/liveness_info.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocodery/SysYCompiler/3b6793766e0a95e159edc7a3ae7b799e31196148/src/codegen/armv8/liveness_info.cpp -------------------------------------------------------------------------------- /src/frontend/SysY.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | Int=3 4 | Void=4 5 | Const=5 6 | Return=6 7 | If=7 8 | Else=8 9 | While=9 10 | For=10 11 | Do=11 12 | Break=12 13 | Continue=13 14 | Lparen=14 15 | Rparen=15 16 | Lbrkt=16 17 | Rbrkt=17 18 | Lbrace=18 19 | Rbrace=19 20 | Comma=20 21 | Semicolon=21 22 | Minus=22 23 | Addition=23 24 | Exclamation=24 25 | Multiplication=25 26 | Division=26 27 | Modulo=27 28 | LAND=28 29 | LOR=29 30 | EQ=30 31 | NEQ=31 32 | LT=32 33 | LE=33 34 | GT=34 35 | GE=35 36 | IntLiteral=36 37 | FloatLiteral=37 38 | Identifier=38 39 | WS=39 40 | LINE_COMMENT=40 41 | COMMENT=41 42 | 'float'=1 43 | '='=2 44 | 'int'=3 45 | 'void'=4 46 | 'const'=5 47 | 'return'=6 48 | 'if'=7 49 | 'else'=8 50 | 'while'=9 51 | 'for'=10 52 | 'do'=11 53 | 'break'=12 54 | 'continue'=13 55 | '('=14 56 | ')'=15 57 | '['=16 58 | ']'=17 59 | '{'=18 60 | '}'=19 61 | ','=20 62 | ';'=21 63 | '-'=22 64 | '+'=23 65 | '!'=24 66 | '*'=25 67 | '/'=26 68 | '%'=27 69 | '&&'=28 70 | '||'=29 71 | '=='=30 72 | '!='=31 73 | '<'=32 74 | '<='=33 75 | '>'=34 76 | '>='=35 77 | -------------------------------------------------------------------------------- /src/frontend/SysYBaseVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYBaseVisitor.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/frontend/SysYLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | Int=3 4 | Void=4 5 | Const=5 6 | Return=6 7 | If=7 8 | Else=8 9 | While=9 10 | For=10 11 | Do=11 12 | Break=12 13 | Continue=13 14 | Lparen=14 15 | Rparen=15 16 | Lbrkt=16 17 | Rbrkt=17 18 | Lbrace=18 19 | Rbrace=19 20 | Comma=20 21 | Semicolon=21 22 | Minus=22 23 | Addition=23 24 | Exclamation=24 25 | Multiplication=25 26 | Division=26 27 | Modulo=27 28 | LAND=28 29 | LOR=29 30 | EQ=30 31 | NEQ=31 32 | LT=32 33 | LE=33 34 | GT=34 35 | GE=35 36 | IntLiteral=36 37 | FloatLiteral=37 38 | Identifier=38 39 | WS=39 40 | LINE_COMMENT=40 41 | COMMENT=41 42 | 'float'=1 43 | '='=2 44 | 'int'=3 45 | 'void'=4 46 | 'const'=5 47 | 'return'=6 48 | 'if'=7 49 | 'else'=8 50 | 'while'=9 51 | 'for'=10 52 | 'do'=11 53 | 'break'=12 54 | 'continue'=13 55 | '('=14 56 | ')'=15 57 | '['=16 58 | ']'=17 59 | '{'=18 60 | '}'=19 61 | ','=20 62 | ';'=21 63 | '-'=22 64 | '+'=23 65 | '!'=24 66 | '*'=25 67 | '/'=26 68 | '%'=27 69 | '&&'=28 70 | '||'=29 71 | '=='=30 72 | '!='=31 73 | '<'=32 74 | '<='=33 75 | '>'=34 76 | '>='=35 77 | -------------------------------------------------------------------------------- /src/frontend/SysYToken.g4: -------------------------------------------------------------------------------- 1 | lexer grammar SysYToken; 2 | 3 | // keyword 4 | Int : 'int'; 5 | Void: 'void'; 6 | Const: 'const'; 7 | Return : 'return'; 8 | If : 'if'; 9 | Else : 'else'; 10 | While : 'while'; 11 | For : 'for'; 12 | Do : 'do'; 13 | Break : 'break'; 14 | Continue : 'continue'; 15 | 16 | 17 | // operator 18 | Lparen : '(' ; 19 | Rparen : ')' ; 20 | Lbrkt : '[' ; 21 | Rbrkt : ']' ; 22 | Lbrace : '{' ; 23 | Rbrace : '}' ; 24 | Comma : ',' ; 25 | Semicolon : ';'; 26 | 27 | Minus : '-'; 28 | Addition : '+'; 29 | Exclamation : '!'; 30 | Multiplication : '*'; 31 | Division : '/'; 32 | Modulo : '%'; 33 | LAND : '&&'; 34 | LOR : '||'; 35 | EQ : '=='; 36 | NEQ : '!='; 37 | LT : '<'; 38 | LE : '<='; 39 | GT : '>'; 40 | GE : '>='; 41 | 42 | // integer, identifier 43 | IntLiteral 44 | : [0-9]+ 45 | | ('0x'|'0X')[0-9a-fA-F]+ 46 | ; 47 | 48 | FloatLiteral 49 | : ([0-9]+|[0-9]*'.'[0-9]*)([eE]('+'|'-')?[0-9]+)?[fFlL]? 50 | | ('0x'|'0X')([0-9a-fA-F]*'.'[0-9a-fA-F]*)([pP]('+'|'-')?[0-9]+)?[fFlL]? 51 | ; 52 | 53 | 54 | Identifier 55 | : [a-zA-Z_][a-zA-Z_0-9]* 56 | ; 57 | 58 | WS : 59 | [ \t\r\n] -> skip 60 | ; 61 | 62 | LINE_COMMENT : '//' ~ [\r\n]* -> skip; 63 | COMMENT :'/*'.*?'*/'-> skip ; -------------------------------------------------------------------------------- /src/frontend/SysYVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYVisitor.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/optimizer/constant_propagation.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | 6 | class ConstantProg { 7 | public: 8 | Function *function; 9 | public: 10 | ConstantProg(Function *func) : function(func) { } 11 | void runConstantProp(); 12 | void processInBlock(BasicBlock *blcok); 13 | }; 14 | -------------------------------------------------------------------------------- /src/optimizer/dead_code_elim.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | 6 | class Dce { 7 | public: 8 | Function *function; 9 | 10 | set> usefulRegSet; 11 | set uselessInstSet; 12 | vector dceAccessQueue; 13 | 14 | vector> reverseOrder; 15 | public: 16 | Dce(Function *func) : function(func) { 17 | usefulRegSet.clear(); 18 | dceAccessQueue.clear(); 19 | } 20 | void insertToSet(VirtReg *reg); 21 | bool checkInSet(VirtReg *reg); 22 | void dfsReverseOrder(list list, BasicBlock *block); 23 | void buildUsefulRegSet(Function *); 24 | void removeUselessInst(); 25 | void runDeadCodeElim(); 26 | }; 27 | -------------------------------------------------------------------------------- /src/optimizer/function_inline.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | 6 | using FuncMap = map; 7 | 8 | class FuncInline { 9 | public: 10 | Function *function; 11 | 12 | map, SRC> inlineMap; 13 | public: 14 | FuncInline(Function *func) : function(func) { } 15 | 16 | static bool isRecursive(FunctionInfo *, FunctionInfo *, set &); 17 | static bool sideEffect(Function *); 18 | 19 | bool inLinable(string func_name, FuncMap &func_map); 20 | void initInlineMap(vector caller_args, vector> callee_args); 21 | SRC findInMap(SRC src); 22 | list insertBlock(BasicBlock *block, SRC &dst); 23 | void simpleInline(BasicBlock *block, Function *func); 24 | void excuteFuncInline(BasicBlock *block, vector &all_block, Function *func); 25 | void runFuncInline(FuncMap &func_map); 26 | }; 27 | -------------------------------------------------------------------------------- /src/optimizer/global_var_const.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hh" 4 | #include "ir.hh" 5 | 6 | class GlobalVarConst 7 | { 8 | public: 9 | Scope *global_scope; 10 | vector &functions; 11 | public: 12 | GlobalVarConst(Scope *glb_scope, vector &funcs) : global_scope(glb_scope), functions(funcs) { } 13 | void runGlobalVarConst(); 14 | }; 15 | -------------------------------------------------------------------------------- /src/optimizer/gvn_gcm.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | 6 | #include "dead_code_elim.hh" 7 | 8 | using twoSrcs = pair>; 9 | using phiSrcs = vector>; 10 | using funcRel = pair>; 11 | 12 | struct localValueTable { 13 | map bin2src; 14 | map phi2src; 15 | map fun2src; 16 | }; 17 | 18 | class GvnGcm { 19 | public: 20 | Function *function; 21 | 22 | map idxMap; 23 | vector globalValueTable; 24 | public: 25 | GvnGcm(Function *func) : function(func) { 26 | auto &&all_blocks = function->all_blocks; 27 | for (int32_t idx = 0; idx < function->all_blocks.size(); ++idx) { 28 | idxMap.insert({all_blocks[idx]->bb_idx, idx}); 29 | globalValueTable.push_back(localValueTable()); 30 | } 31 | } 32 | 33 | void moveCtv2Rhs(); 34 | void runGVN(); 35 | void runGvnOnBlock(BasicBlock *block); 36 | 37 | SRC lookupOrAdd(int32_t idx, LLIR_BIN *bin_inst); 38 | SRC lookupOrAdd(int32_t idx, LLIR_FBIN *fbin_inst); 39 | SRC lookupOrAdd(int32_t idx, LLIR_GEP *gep_inst); 40 | SRC lookupOrAdd(int32_t idx, LLIR_PHI *bin_inst); 41 | SRC lookupOrAdd(int32_t idx, LLIR_CALL *bin_inst); 42 | 43 | void runGCM(); 44 | void runGvnGcm(); 45 | }; 46 | -------------------------------------------------------------------------------- /src/optimizer/inst_combine.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hh" 4 | #include "ir.hh" 5 | 6 | class InstCombine { 7 | public: 8 | Function *function; 9 | public: 10 | InstCombine(Function *func) : function(func) { } 11 | void moveCtv2Rhs(); 12 | void runInstCombine(); 13 | }; 14 | -------------------------------------------------------------------------------- /src/optimizer/load_store_reordering.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hh" 4 | #include "ir.hh" 5 | 6 | class LoadStoreReordering 7 | { 8 | public: 9 | map void_call_map; 10 | public: 11 | LoadStoreReordering(Function *function); 12 | int GetDstRegId(Inst* instPtr); // returns dst_regid 13 | }; 14 | -------------------------------------------------------------------------------- /src/optimizer/mem2reg.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | #include 6 | 7 | using std::stack; 8 | 9 | class Mem2Reg { 10 | public: 11 | Function *function; 12 | 13 | vector> defBlocks; 14 | vector allocaInsts; 15 | map allocaLoopup; 16 | map phi2AllocaMap; 17 | public: 18 | Mem2Reg(Function *func) : function(func) { 19 | defBlocks.clear(); 20 | allocaInsts.clear(); 21 | allocaLoopup.clear(); 22 | phi2AllocaMap.clear(); 23 | } 24 | set> initDelVarSet(); 25 | void removeUsedVar(set> &del_variable); 26 | LLIR_ALLOCA *getAllocaInst(VirtReg *reg); 27 | bool inDefBlocks(int32_t index ,BasicBlock *block); 28 | void runMem2Reg(); 29 | }; 30 | 31 | class RenameData { 32 | public: 33 | BasicBlock *block; 34 | BasicBlock *pred; 35 | vector values; 36 | public: 37 | RenameData(BasicBlock *_bb, BasicBlock *_pred, vector _v) 38 | : block(_bb), pred(_pred), values(_v) { } 39 | }; 40 | -------------------------------------------------------------------------------- /src/optimizer/memaccess_opt.cpp: -------------------------------------------------------------------------------- 1 | #include "memaccess_opt.hh" 2 | 3 | void MemAccessOpt::runMemAccessOpt() { 4 | auto &&all_blocks = function->all_blocks; 5 | int32_t idx = 0; 6 | for (auto &&block : all_blocks) { 7 | bbIdx2MapIdx.insert({block->bb_idx, idx++}); 8 | addr2Value.push_back(map, SRC>()); 9 | } 10 | 11 | for (auto &&block : all_blocks) { 12 | auto &&bb_list = list(block->basic_block.begin(), block->basic_block.end()); 13 | int32_t index = bbIdx2MapIdx[block->bb_idx]; 14 | auto &&localMap = addr2Value[index]; 15 | for (auto &&iter = bb_list.begin(); iter != bb_list.end(); ) { 16 | auto &&inst = *iter; 17 | Case (LLIR_STORE, store_inst, inst) { 18 | auto &&store_dst = store_inst->dst.reg; 19 | auto &&store_src = store_inst->src; 20 | assert(store_dst != nullptr); 21 | localMap[{store_dst->reg_id, store_dst->global}] = store_src; 22 | } 23 | else Case (LLIR_LOAD, load_inst, inst) { 24 | auto &&load_src = load_inst->src.reg; 25 | assert(load_src != nullptr); 26 | if (localMap.find({load_src->reg_id, load_src->global}) != localMap.end()) { 27 | block->replaceSRC(load_inst->dst.reg, localMap[{load_src->reg_id, load_src->global}]); 28 | iter = bb_list.erase(iter); 29 | continue; 30 | } else { 31 | auto &&load_dst = load_inst->dst; 32 | localMap[{load_src->reg_id, load_src->global}] = load_dst; 33 | } 34 | } else Case (LLIR_CALL, call_inst, inst) { 35 | auto &&func_info = call_inst->func_info; 36 | if (func_info->side_effect) { 37 | localMap.clear(); 38 | } 39 | } 40 | ++iter; 41 | } 42 | block->basic_block = vector(bb_list.begin(), bb_list.end()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/optimizer/memaccess_opt.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | 6 | class MemAccessOpt { 7 | public: 8 | Function *function; 9 | 10 | map bbIdx2MapIdx; 11 | vector, SRC>> addr2Value; 12 | public: 13 | MemAccessOpt(Function *func) : function(func) { } 14 | void runMemAccessOpt(); 15 | }; 16 | -------------------------------------------------------------------------------- /src/optimizer/reg2mem.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "../structure/ir.hh" 5 | #include "mem2reg.hh" 6 | 7 | class Reg2Mem { 8 | public: 9 | Function *function; 10 | 11 | vector allocaInsts; 12 | map phi2AllocaMap; 13 | public: 14 | Reg2Mem(Function *func, Mem2Reg &mem2reg) : function(func) { 15 | allocaInsts = mem2reg.allocaInsts; 16 | phi2AllocaMap = mem2reg.phi2AllocaMap; 17 | } 18 | void runReg2Mem(); 19 | }; 20 | -------------------------------------------------------------------------------- /src/structure/baseclass.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hh" 4 | #include "symtable.hh" 5 | 6 | static int32_t reg_idx = 0; 7 | 8 | class Info { 9 | public: 10 | virtual ~Info() { } 11 | }; 12 | 13 | class Inst: public Info { 14 | public: 15 | CLAIM_AVAIL_REGS 16 | public: 17 | REGs GetNthUnusedRRegister(int n) const { 18 | int skipped_cnt = 0; 19 | for (auto &&r : availRegs) { 20 | if (skipped_cnt < n - 1) { 21 | ++skipped_cnt; 22 | continue; 23 | } 24 | if (r < s0) return r; 25 | else return SPILL; 26 | } 27 | return SPILL; 28 | } 29 | REGs GetFirstUnusedRRegister() const { 30 | return GetNthUnusedRRegister(1); 31 | } 32 | REGs GetSecondUnusedRRegister() const { 33 | return GetNthUnusedRRegister(2); 34 | } 35 | REGs GetThirdUnusedRRegister() const { 36 | return GetNthUnusedRRegister(3); 37 | } 38 | virtual ~Inst() { } 39 | }; 40 | 41 | class VirtReg: public Info { 42 | public: 43 | int32_t reg_id; 44 | VarType type; 45 | bool global; 46 | bool assign; 47 | 48 | // codegen 49 | bool is_from_gep = false; 50 | public: 51 | VirtReg(int32_t _idx, VarType _type = VarType(TypeVoid), bool _glb = false, bool _assign = true) 52 | : reg_id(_idx), type(_type), global(_glb), assign(_assign) { } 53 | string ToString() { 54 | std::stringstream ss; 55 | if (global) ss << "@_" << reg_id; 56 | else ss << "%r" << reg_id; 57 | return ss.str(); 58 | } 59 | bool operator == (const VirtReg &rhs) const { 60 | return (reg_id == rhs.reg_id) && (global == rhs.global) && (type == rhs.type); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /src/structure/value.cpp: -------------------------------------------------------------------------------- 1 | #include "value.hh" 2 | 3 | #pragma clang diagnostic push 4 | #pragma clang diagnostic ignored "-Wreturn-type" 5 | 6 | CTValue::CTValue(DeclType t, int32_t iv, float fv): type(t), int_value(iv), float_value(fv) { } 7 | 8 | string CTValue::ToString() { 9 | std::stringstream ss; 10 | if (type == TypeInt) { 11 | ss << int_value; 12 | } else if (type == TypeFloat) { 13 | uint64_t uint64_value = reinterpret_cast(float_value); 14 | ss << "0x" << std::hex << uint64_value; 15 | } else if (type == TypeBool) { 16 | ss << int_value; 17 | } else if (type == TypeByte) { 18 | ss << int_value; 19 | } else { 20 | // dbg("UnExpected DeclType"); 21 | } 22 | return ss.str(); 23 | } 24 | 25 | #pragma clang diagnostic pop 26 | -------------------------------------------------------------------------------- /src/structure/value.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../common.hh" 6 | #include "symtable.hh" 7 | #include "baseclass.hh" 8 | 9 | using std::cout; 10 | using std::endl; 11 | 12 | class CTValue: public Info { 13 | public: 14 | DeclType type; 15 | int32_t int_value; 16 | double float_value; 17 | public: 18 | CTValue(DeclType t = TypeVoid, int32_t iv = 0, float fv = 0); 19 | string ToString(); 20 | bool operator == (const CTValue &ctv) const { 21 | if (type == TypeInt || type == TypeBool) return int_value == ctv.int_value; 22 | else if (type == TypeFloat) return float_value == ctv.float_value; 23 | else return false; 24 | } 25 | bool operator < (const CTValue &other) const { 26 | if (type == other.type) 27 | return (type == TypeInt) ? (int_value < other.int_value) : (float_value < other.float_value); 28 | else 29 | return type < other.type; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /sylib.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYLIB_H_ 2 | #define __SYLIB_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | void imemset(int a[], int c, int size); 9 | void fmemset(float a[], float c, int size); 10 | /* Input & output functions */ 11 | int getint(),getch(),getarray(int a[]); 12 | float getfloat(); 13 | int getfarray(float a[]); 14 | 15 | void putint(int a),putch(int a),putarray(int n,int a[]); 16 | void putfloat(float a); 17 | void putfarray(int n, float a[]); 18 | 19 | void putf(char a[], ...); 20 | 21 | /* Timing function implementation */ 22 | struct timeval _sysy_start,_sysy_end; 23 | #define starttime() _sysy_starttime(__LINE__) 24 | #define stoptime() _sysy_stoptime(__LINE__) 25 | #define _SYSY_N 1024 26 | int _sysy_l1[_SYSY_N],_sysy_l2[_SYSY_N]; 27 | int _sysy_h[_SYSY_N], _sysy_m[_SYSY_N],_sysy_s[_SYSY_N],_sysy_us[_SYSY_N]; 28 | int _sysy_idx; 29 | __attribute((constructor)) void before_main(); 30 | __attribute((destructor)) void after_main(); 31 | void _sysy_starttime(int lineno); 32 | void _sysy_stoptime(int lineno); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorListener.h" 7 | 8 | antlr4::ANTLRErrorListener::~ANTLRErrorListener() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorStrategy.h" 7 | 8 | antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRFileStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | #include "ANTLRFileStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | ANTLRFileStream::ANTLRFileStream(const std::string &fileName) { 13 | _fileName = fileName; 14 | loadFromFile(fileName); 15 | } 16 | 17 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 18 | _fileName = fileName; 19 | if (_fileName.empty()) { 20 | return; 21 | } 22 | 23 | #ifdef _MSC_VER 24 | std::ifstream stream(antlrcpp::s2ws(fileName), std::ios::binary); 25 | #else 26 | std::ifstream stream(fileName, std::ios::binary); 27 | #endif 28 | 29 | ANTLRInputStream::load(stream); 30 | } 31 | 32 | std::string ANTLRFileStream::getSourceName() const { 33 | return _fileName; 34 | } 35 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRFileStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRInputStream.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// This is an ANTLRInputStream that is loaded from a file all at once 13 | /// when you construct the object (or call load()). 14 | // TODO: this class needs testing. 15 | class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { 16 | protected: 17 | std::string _fileName; // UTF-8 encoded file name. 18 | 19 | public: 20 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 21 | ANTLRFileStream(const std::string &fileName); 22 | 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | }; 26 | 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/BailErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "ParserRuleContext.h" 8 | #include "InputMismatchException.h" 9 | #include "Parser.h" 10 | 11 | #include "BailErrorStrategy.h" 12 | 13 | using namespace antlr4; 14 | 15 | void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) { 16 | ParserRuleContext *context = recognizer->getContext(); 17 | do { 18 | context->exception = e; 19 | if (context->parent == nullptr) 20 | break; 21 | context = static_cast(context->parent); 22 | } while (true); 23 | 24 | try { 25 | std::rethrow_exception(e); // Throw the exception to be able to catch and rethrow nested. 26 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 27 | } catch (RecognitionException &inner) { 28 | throw ParseCancellationException(inner.what()); 29 | #else 30 | } catch (RecognitionException & /*inner*/) { 31 | std::throw_with_nested(ParseCancellationException()); 32 | #endif 33 | } 34 | } 35 | 36 | Token* BailErrorStrategy::recoverInline(Parser *recognizer) { 37 | InputMismatchException e(recognizer); 38 | std::exception_ptr exception = std::make_exception_ptr(e); 39 | 40 | ParserRuleContext *context = recognizer->getContext(); 41 | do { 42 | context->exception = exception; 43 | if (context->parent == nullptr) 44 | break; 45 | context = static_cast(context->parent); 46 | } while (true); 47 | 48 | try { 49 | throw e; 50 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 51 | } catch (InputMismatchException &inner) { 52 | throw ParseCancellationException(inner.what()); 53 | #else 54 | } catch (InputMismatchException & /*inner*/) { 55 | std::throw_with_nested(ParseCancellationException()); 56 | #endif 57 | } 58 | } 59 | 60 | void BailErrorStrategy::sync(Parser * /*recognizer*/) { 61 | } 62 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/BaseErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BaseErrorListener.h" 7 | #include "RecognitionException.h" 8 | 9 | using namespace antlr4; 10 | 11 | void BaseErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, size_t /*line*/, 12 | size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | 15 | void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 16 | size_t /*stopIndex*/, bool /*exact*/, const antlrcpp::BitSet &/*ambigAlts*/, atn::ATNConfigSet * /*configs*/) { 17 | } 18 | 19 | void BaseErrorListener::reportAttemptingFullContext(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 20 | size_t /*stopIndex*/, const antlrcpp::BitSet &/*conflictingAlts*/, atn::ATNConfigSet * /*configs*/) { 21 | } 22 | 23 | void BaseErrorListener::reportContextSensitivity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 24 | size_t /*stopIndex*/, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) { 25 | } 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/BaseErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | 10 | namespace antlrcpp { 11 | class BitSet; 12 | } 13 | 14 | namespace antlr4 { 15 | 16 | /** 17 | * Provides an empty default implementation of {@link ANTLRErrorListener}. The 18 | * default implementation of each method does nothing, but can be overridden as 19 | * necessary. 20 | */ 21 | class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener { 22 | 23 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 24 | const std::string &msg, std::exception_ptr e) override; 25 | 26 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 27 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 28 | 29 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 30 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 31 | 32 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 33 | size_t prediction, atn::ATNConfigSet *configs) override; 34 | }; 35 | 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/CharStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "CharStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | CharStream::~CharStream() { 11 | } 12 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/CharStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "IntStream.h" 9 | #include "misc/Interval.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// A source of characters for an ANTLR lexer. 14 | class ANTLR4CPP_PUBLIC CharStream : public IntStream { 15 | public: 16 | virtual ~CharStream(); 17 | 18 | /// This method returns the text for a range of characters within this input 19 | /// stream. This method is guaranteed to not throw an exception if the 20 | /// specified interval lies entirely within a marked range. For more 21 | /// information about marked ranges, see IntStream::mark. 22 | /// 23 | /// an interval within the stream 24 | /// the text of the specified interval 25 | /// 26 | /// if {@code interval} is {@code null} 27 | /// if {@code interval.a < 0}, or if 28 | /// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or 29 | /// past the end of the stream 30 | /// if the stream does not support 31 | /// getting the text of the specified interval 32 | virtual std::string getText(const misc::Interval &interval) = 0; 33 | 34 | virtual std::string toString() const = 0; 35 | }; 36 | 37 | } // namespace antlr4 38 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/CommonTokenFactory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "CommonToken.h" 8 | #include "CharStream.h" 9 | 10 | #include "CommonTokenFactory.h" 11 | 12 | using namespace antlr4; 13 | 14 | const Ref> CommonTokenFactory::DEFAULT = std::make_shared(); 15 | 16 | CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) { 17 | } 18 | 19 | CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) { 20 | } 21 | 22 | std::unique_ptr CommonTokenFactory::create(std::pair source, size_t type, 23 | const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) { 24 | 25 | std::unique_ptr t(new CommonToken(source, type, channel, start, stop)); 26 | t->setLine(line); 27 | t->setCharPositionInLine(charPositionInLine); 28 | if (text != "") { 29 | t->setText(text); 30 | } else if (copyText && source.second != nullptr) { 31 | t->setText(source.second->getText(misc::Interval(start, stop))); 32 | } 33 | 34 | return t; 35 | } 36 | 37 | std::unique_ptr CommonTokenFactory::create(size_t type, const std::string &text) { 38 | return std::unique_ptr(new CommonToken(type, text)); 39 | } 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/CommonTokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | #include "CommonTokenStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : CommonTokenStream(tokenSource, Token::DEFAULT_CHANNEL) { 13 | } 14 | 15 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel_) 16 | : BufferedTokenStream(tokenSource), channel(channel_) { 17 | } 18 | 19 | ssize_t CommonTokenStream::adjustSeekIndex(size_t i) { 20 | return nextTokenOnChannel(i, channel); 21 | } 22 | 23 | Token* CommonTokenStream::LB(size_t k) { 24 | if (k == 0 || k > _p) { 25 | return nullptr; 26 | } 27 | 28 | ssize_t i = static_cast(_p); 29 | size_t n = 1; 30 | // find k good tokens looking backwards 31 | while (n <= k) { 32 | // skip off-channel tokens 33 | i = previousTokenOnChannel(i - 1, channel); 34 | n++; 35 | } 36 | if (i < 0) { 37 | return nullptr; 38 | } 39 | 40 | return _tokens[i].get(); 41 | } 42 | 43 | Token* CommonTokenStream::LT(ssize_t k) { 44 | lazyInit(); 45 | if (k == 0) { 46 | return nullptr; 47 | } 48 | if (k < 0) { 49 | return LB(static_cast(-k)); 50 | } 51 | size_t i = _p; 52 | ssize_t n = 1; // we know tokens[p] is a good one 53 | // find k good tokens 54 | while (n < k) { 55 | // skip off-channel tokens, but make sure to not look past EOF 56 | if (sync(i + 1)) { 57 | i = nextTokenOnChannel(i + 1, channel); 58 | } 59 | n++; 60 | } 61 | 62 | return _tokens[i].get(); 63 | } 64 | 65 | int CommonTokenStream::getNumberOfOnChannelTokens() { 66 | int n = 0; 67 | fill(); 68 | for (size_t i = 0; i < _tokens.size(); i++) { 69 | Token *t = _tokens[i].get(); 70 | if (t->getChannel() == channel) { 71 | n++; 72 | } 73 | if (t->getType() == Token::EOF) { 74 | break; 75 | } 76 | } 77 | return n; 78 | } 79 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ConsoleErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ConsoleErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | ConsoleErrorListener ConsoleErrorListener::INSTANCE; 11 | 12 | void ConsoleErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 13 | size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) { 14 | std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ConsoleErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC ConsoleErrorListener : public BaseErrorListener { 13 | public: 14 | /** 15 | * Provides a default instance of {@link ConsoleErrorListener}. 16 | */ 17 | static ConsoleErrorListener INSTANCE; 18 | 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

23 | * This implementation prints messages to {@link System#err} containing the 24 | * values of {@code line}, {@code charPositionInLine}, and {@code msg} using 25 | * the following format.

26 | * 27 | *
28 |      * line line:charPositionInLine msg
29 |      * 
30 | */ 31 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 32 | const std::string &msg, std::exception_ptr e) override; 33 | }; 34 | 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/FailedPredicateException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ParserATNSimulator.h" 7 | #include "Parser.h" 8 | #include "atn/PredicateTransition.h" 9 | #include "atn/ATN.h" 10 | #include "atn/ATNState.h" 11 | #include "support/CPPUtils.h" 12 | 13 | #include "FailedPredicateException.h" 14 | 15 | using namespace antlr4; 16 | using namespace antlrcpp; 17 | 18 | FailedPredicateException::FailedPredicateException(Parser *recognizer) : FailedPredicateException(recognizer, "", "") { 19 | } 20 | 21 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate): FailedPredicateException(recognizer, predicate, "") { 22 | } 23 | 24 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message) 25 | : RecognitionException(!message.empty() ? message : "failed predicate: " + predicate + "?", recognizer, 26 | recognizer->getInputStream(), recognizer->getContext(), recognizer->getCurrentToken()) { 27 | 28 | atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()]; 29 | atn::Transition *transition = s->transitions[0]; 30 | if (is(transition)) { 31 | _ruleIndex = static_cast(transition)->ruleIndex; 32 | _predicateIndex = static_cast(transition)->predIndex; 33 | } else { 34 | _ruleIndex = 0; 35 | _predicateIndex = 0; 36 | } 37 | 38 | _predicate = predicate; 39 | } 40 | 41 | size_t FailedPredicateException::getRuleIndex() { 42 | return _ruleIndex; 43 | } 44 | 45 | size_t FailedPredicateException::getPredIndex() { 46 | return _predicateIndex; 47 | } 48 | 49 | std::string FailedPredicateException::getPredicate() { 50 | return _predicate; 51 | } 52 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/FailedPredicateException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A semantic predicate failed during validation. Validation of predicates 13 | /// occurs when normally parsing the alternative just like matching a token. 14 | /// Disambiguating predicate evaluation occurs when we test a predicate during 15 | /// prediction. 16 | class ANTLR4CPP_PUBLIC FailedPredicateException : public RecognitionException { 17 | public: 18 | FailedPredicateException(Parser *recognizer); 19 | FailedPredicateException(Parser *recognizer, const std::string &predicate); 20 | FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message); 21 | 22 | virtual size_t getRuleIndex(); 23 | virtual size_t getPredIndex(); 24 | virtual std::string getPredicate(); 25 | 26 | private: 27 | size_t _ruleIndex; 28 | size_t _predicateIndex; 29 | std::string _predicate; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InputMismatchException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "InputMismatchException.h" 9 | 10 | using namespace antlr4; 11 | 12 | InputMismatchException::InputMismatchException(Parser *recognizer) 13 | : RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(), 14 | recognizer->getCurrentToken()) { 15 | } 16 | 17 | InputMismatchException::~InputMismatchException() { 18 | } 19 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InputMismatchException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// 13 | /// This signifies any kind of mismatched input exceptions such as 14 | /// when the current input does not match the expected token. 15 | /// 16 | class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException { 17 | public: 18 | InputMismatchException(Parser *recognizer); 19 | InputMismatchException(InputMismatchException const&) = default; 20 | ~InputMismatchException(); 21 | InputMismatchException& operator=(InputMismatchException const&) = default; 22 | }; 23 | 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/IntStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "IntStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | const std::string IntStream::UNKNOWN_SOURCE_NAME = ""; 11 | 12 | IntStream::~IntStream() = default; 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InterpreterRuleContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "InterpreterRuleContext.h" 7 | 8 | using namespace antlr4; 9 | 10 | InterpreterRuleContext::InterpreterRuleContext() : ParserRuleContext() { 11 | } 12 | 13 | InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex) 14 | : ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) { 15 | } 16 | 17 | size_t InterpreterRuleContext::getRuleIndex() const { 18 | return _ruleIndex; 19 | } 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InterpreterRuleContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /** 13 | * This class extends {@link ParserRuleContext} by allowing the value of 14 | * {@link #getRuleIndex} to be explicitly set for the context. 15 | * 16 | *

17 | * {@link ParserRuleContext} does not include field storage for the rule index 18 | * since the context classes created by the code generator override the 19 | * {@link #getRuleIndex} method to return the correct value for that context. 20 | * Since the parser interpreter does not use the context classes generated for a 21 | * parser, this class (with slightly more memory overhead per node) is used to 22 | * provide equivalent functionality.

23 | */ 24 | class ANTLR4CPP_PUBLIC InterpreterRuleContext : public ParserRuleContext { 25 | public: 26 | InterpreterRuleContext(); 27 | 28 | /** 29 | * Constructs a new {@link InterpreterRuleContext} with the specified 30 | * parent, invoking state, and rule index. 31 | * 32 | * @param parent The parent context. 33 | * @param invokingStateNumber The invoking state number. 34 | * @param ruleIndex The rule index for the current context. 35 | */ 36 | InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex); 37 | 38 | virtual size_t getRuleIndex() const override; 39 | 40 | protected: 41 | /** This is the backing field for {@link #getRuleIndex}. */ 42 | const size_t _ruleIndex = INVALID_INDEX; 43 | }; 44 | 45 | } // namespace antlr4 46 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/LexerNoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "support/CPPUtils.h" 8 | #include "CharStream.h" 9 | #include "Lexer.h" 10 | 11 | #include "LexerNoViableAltException.h" 12 | 13 | using namespace antlr4; 14 | 15 | LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs) 17 | : RecognitionException(lexer, input, nullptr, nullptr), _startIndex(startIndex), _deadEndConfigs(deadEndConfigs) { 18 | } 19 | 20 | size_t LexerNoViableAltException::getStartIndex() { 21 | return _startIndex; 22 | } 23 | 24 | atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() { 25 | return _deadEndConfigs; 26 | } 27 | 28 | std::string LexerNoViableAltException::toString() { 29 | std::string symbol; 30 | if (_startIndex < getInputStream()->size()) { 31 | symbol = static_cast(getInputStream())->getText(misc::Interval(_startIndex, _startIndex)); 32 | symbol = antlrcpp::escapeWhitespace(symbol, false); 33 | } 34 | std::string format = "LexerNoViableAltException('" + symbol + "')"; 35 | return format; 36 | } 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/LexerNoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "atn/ATNConfigSet.h" 10 | 11 | namespace antlr4 { 12 | 13 | class ANTLR4CPP_PUBLIC LexerNoViableAltException : public RecognitionException { 14 | public: 15 | LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs); 17 | 18 | virtual size_t getStartIndex(); 19 | virtual atn::ATNConfigSet* getDeadEndConfigs(); 20 | virtual std::string toString(); 21 | 22 | private: 23 | /// Matching attempted at what input index? 24 | const size_t _startIndex; 25 | 26 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 27 | atn::ATNConfigSet *_deadEndConfigs; 28 | 29 | }; 30 | 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/NoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "NoViableAltException.h" 9 | 10 | using namespace antlr4; 11 | 12 | namespace { 13 | 14 | // Create a normal shared pointer if the configurations are to be deleted. If not, then 15 | // the shared pointer is created with a deleter that does nothing. 16 | Ref buildConfigsRef(atn::ATNConfigSet *configs, bool deleteConfigs) { 17 | if (deleteConfigs) { 18 | return Ref(configs); 19 | } else { 20 | return Ref(configs, [](atn::ATNConfigSet *){}); 21 | } 22 | } 23 | 24 | } 25 | 26 | NoViableAltException::NoViableAltException(Parser *recognizer) 27 | : NoViableAltException(recognizer, recognizer->getTokenStream(), recognizer->getCurrentToken(), 28 | recognizer->getCurrentToken(), nullptr, recognizer->getContext(), false) { 29 | } 30 | 31 | NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 32 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs) 33 | : RecognitionException("No viable alternative", recognizer, input, ctx, offendingToken), 34 | _deadEndConfigs(buildConfigsRef(deadEndConfigs, deleteConfigs)), _startToken(startToken) { 35 | } 36 | 37 | NoViableAltException::~NoViableAltException() { 38 | } 39 | 40 | Token* NoViableAltException::getStartToken() const { 41 | return _startToken; 42 | } 43 | 44 | atn::ATNConfigSet* NoViableAltException::getDeadEndConfigs() const { 45 | return _deadEndConfigs.get(); 46 | } 47 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/NoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "Token.h" 10 | #include "atn/ATNConfigSet.h" 11 | 12 | namespace antlr4 { 13 | 14 | /// Indicates that the parser could not decide which of two or more paths 15 | /// to take based upon the remaining input. It tracks the starting token 16 | /// of the offending input and also knows where the parser was 17 | /// in the various paths when the error. Reported by reportNoViableAlternative() 18 | class ANTLR4CPP_PUBLIC NoViableAltException : public RecognitionException { 19 | public: 20 | NoViableAltException(Parser *recognizer); // LL(1) error 21 | NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 22 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs); 23 | ~NoViableAltException(); 24 | 25 | virtual Token* getStartToken() const; 26 | virtual atn::ATNConfigSet* getDeadEndConfigs() const; 27 | 28 | private: 29 | /// Which configurations did we try at input.index() that couldn't match input.LT(1)? 30 | /// Shared pointer that conditionally deletes the configurations (based on flag 31 | /// passed during construction) 32 | Ref _deadEndConfigs; 33 | 34 | /// The token object at the start index; the input stream might 35 | /// not be buffering tokens so get a reference to it. (At the 36 | /// time the error occurred, of course the stream needs to keep a 37 | /// buffer all of the tokens but later we might not have access to those.) 38 | Token *_startToken; 39 | 40 | }; 41 | 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ProxyErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | #include "Exceptions.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// This implementation of ANTLRErrorListener dispatches all calls to a 14 | /// collection of delegate listeners. This reduces the effort required to support multiple 15 | /// listeners. 16 | class ANTLR4CPP_PUBLIC ProxyErrorListener : public ANTLRErrorListener { 17 | private: 18 | std::set _delegates; // Not owned. 19 | 20 | public: 21 | void addErrorListener(ANTLRErrorListener *listener); 22 | void removeErrorListener(ANTLRErrorListener *listener); 23 | void removeErrorListeners(); 24 | 25 | void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, size_t charPositionInLine, 26 | const std::string &msg, std::exception_ptr e) override; 27 | 28 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 29 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 30 | 31 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 32 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 33 | 34 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 35 | size_t prediction, atn::ATNConfigSet *configs) override; 36 | }; 37 | 38 | } // namespace antlr4 39 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/RuleContextWithAltNum.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATN.h" 7 | 8 | #include "RuleContextWithAltNum.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { 14 | altNum = ATN::INVALID_ALT_NUMBER; 15 | } 16 | 17 | RuleContextWithAltNum::RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber) 18 | : ParserRuleContext(parent, invokingStateNumber) { 19 | } 20 | 21 | size_t RuleContextWithAltNum::getAltNumber() const { 22 | return altNum; 23 | } 24 | 25 | void RuleContextWithAltNum::setAltNumber(size_t number) { 26 | altNum = number; 27 | } 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/RuleContextWithAltNum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A handy class for use with 13 | /// 14 | /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} 15 | /// 16 | /// that provides a backing field / impl for the outer alternative number 17 | /// matched for an internal parse tree node. 18 | /// 19 | /// I'm only putting into Java runtime as I'm certain I'm the only one that 20 | /// will really every use this. 21 | class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { 22 | public: 23 | size_t altNum = 0; 24 | 25 | RuleContextWithAltNum(); 26 | RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber); 27 | 28 | virtual size_t getAltNumber() const override; 29 | virtual void setAltNumber(size_t altNum) override; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/Token.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | antlr4::Token::~Token() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/TokenFactory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// The default mechanism for creating tokens. It's used by default in Lexer and 13 | /// the error handling strategy (to create missing tokens). Notifying the parser 14 | /// of a new factory means that it notifies it's token source and error strategy. 15 | template 16 | class ANTLR4CPP_PUBLIC TokenFactory { 17 | public: 18 | virtual ~TokenFactory() {} 19 | 20 | /// This is the method used to create tokens in the lexer and in the 21 | /// error handling strategy. If text!=null, than the start and stop positions 22 | /// are wiped to -1 in the text override is set in the CommonToken. 23 | virtual std::unique_ptr create(std::pair source, size_t type, const std::string &text, 24 | size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) = 0; 25 | 26 | /// Generically useful 27 | virtual std::unique_ptr create(size_t type, const std::string &text) = 0; 28 | }; 29 | 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/TokenSource.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenSource.h" 7 | 8 | antlr4::TokenSource::~TokenSource() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/TokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | TokenStream::~TokenStream() { 11 | } 12 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/WritableToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "WritableToken.h" 7 | 8 | antlr4::WritableToken::~WritableToken() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/WritableToken.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Token.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC WritableToken : public Token { 13 | public: 14 | virtual ~WritableToken(); 15 | virtual void setText(const std::string &text) = 0; 16 | virtual void setType(size_t ttype) = 0; 17 | virtual void setLine(size_t line) = 0; 18 | virtual void setCharPositionInLine(size_t pos) = 0; 19 | virtual void setChannel(size_t channel) = 0; 20 | virtual void setTokenIndex(size_t index) = 0; 21 | }; 22 | 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ATNDeserializationOptions.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNDeserializationOptions.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ATNDeserializationOptions ATNDeserializationOptions::defaultOptions; 11 | 12 | ATNDeserializationOptions::ATNDeserializationOptions() { 13 | InitializeInstanceFields(); 14 | } 15 | 16 | ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) : ATNDeserializationOptions() { 17 | this->verifyATN = options->verifyATN; 18 | this->generateRuleBypassTransitions = options->generateRuleBypassTransitions; 19 | } 20 | 21 | ATNDeserializationOptions::~ATNDeserializationOptions() { 22 | } 23 | 24 | const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { 25 | return defaultOptions; 26 | } 27 | 28 | bool ATNDeserializationOptions::isReadOnly() { 29 | return readOnly; 30 | } 31 | 32 | void ATNDeserializationOptions::makeReadOnly() { 33 | readOnly = true; 34 | } 35 | 36 | bool ATNDeserializationOptions::isVerifyATN() { 37 | return verifyATN; 38 | } 39 | 40 | void ATNDeserializationOptions::setVerifyATN(bool verify) { 41 | throwIfReadOnly(); 42 | verifyATN = verify; 43 | } 44 | 45 | bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() { 46 | return generateRuleBypassTransitions; 47 | } 48 | 49 | void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) { 50 | throwIfReadOnly(); 51 | generateRuleBypassTransitions = generate; 52 | } 53 | 54 | void ATNDeserializationOptions::throwIfReadOnly() { 55 | if (isReadOnly()) { 56 | throw "The object is read only."; 57 | } 58 | } 59 | 60 | void ATNDeserializationOptions::InitializeInstanceFields() { 61 | readOnly = false; 62 | verifyATN = true; 63 | generateRuleBypassTransitions = false; 64 | } 65 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ATNDeserializationOptions.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ATNDeserializationOptions { 14 | private: 15 | static ATNDeserializationOptions defaultOptions; 16 | 17 | bool readOnly; 18 | bool verifyATN; 19 | bool generateRuleBypassTransitions; 20 | 21 | public: 22 | ATNDeserializationOptions(); 23 | ATNDeserializationOptions(ATNDeserializationOptions *options); 24 | ATNDeserializationOptions(ATNDeserializationOptions const&) = default; 25 | virtual ~ATNDeserializationOptions(); 26 | ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default; 27 | 28 | static const ATNDeserializationOptions& getDefaultOptions(); 29 | 30 | bool isReadOnly(); 31 | 32 | void makeReadOnly(); 33 | 34 | bool isVerifyATN(); 35 | 36 | void setVerifyATN(bool verify); 37 | 38 | bool isGenerateRuleBypassTransitions(); 39 | 40 | void setGenerateRuleBypassTransitions(bool generate); 41 | 42 | protected: 43 | virtual void throwIfReadOnly(); 44 | 45 | private: 46 | void InitializeInstanceFields(); 47 | }; 48 | 49 | } // namespace atn 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ATNType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Represents the type of recognizer an ATN applies to. 14 | enum class ATNType { 15 | LEXER = 0, 16 | PARSER = 1, 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AbstractPredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AbstractPredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { 11 | } 12 | 13 | AbstractPredicateTransition::~AbstractPredicateTransition() { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AbstractPredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTState; 14 | 15 | class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { 16 | 17 | public: 18 | AbstractPredicateTransition(ATNState *target); 19 | ~AbstractPredicateTransition(); 20 | 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ActionTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ActionTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex) 11 | : Transition(target), ruleIndex(ruleIndex), actionIndex(INVALID_INDEX), isCtxDependent(false) { 12 | } 13 | 14 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent) 15 | : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) { 16 | } 17 | 18 | Transition::SerializationType ActionTransition::getSerializationType() const { 19 | return ACTION; 20 | } 21 | 22 | bool ActionTransition::isEpsilon() const { 23 | return true; // we are to be ignored by analysis 'cept for predicates 24 | } 25 | 26 | bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return false; 28 | } 29 | 30 | std::string ActionTransition::toString() const { 31 | return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " + 32 | std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 33 | } 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ActionTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ActionTransition final : public Transition { 14 | public: 15 | const size_t ruleIndex; 16 | const size_t actionIndex; 17 | const bool isCtxDependent; // e.g., $i ref in action 18 | 19 | ActionTransition(ATNState *target, size_t ruleIndex); 20 | 21 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 22 | 23 | virtual SerializationType getSerializationType() const override; 24 | 25 | virtual bool isEpsilon() const override; 26 | 27 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 28 | 29 | virtual std::string toString() const override; 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AmbiguityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AmbiguityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->ambigAlts = ambigAlts; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ArrayPredictionContext.h: -------------------------------------------------------------------------------- 1 |  2 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | * Use of this file is governed by the BSD 3-clause license that 4 | * can be found in the LICENSE.txt file in the project root. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "atn/PredictionContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class SingletonPredictionContext; 15 | 16 | class ANTLR4CPP_PUBLIC ArrayPredictionContext : public PredictionContext { 17 | public: 18 | /// Parent can be empty only if full ctx mode and we make an array 19 | /// from EMPTY and non-empty. We merge EMPTY by using null parent and 20 | /// returnState == EMPTY_RETURN_STATE. 21 | // Also here: we use a strong reference to our parents to avoid having them freed prematurely. 22 | // See also SinglePredictionContext. 23 | const std::vector> parents; 24 | 25 | /// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last. 26 | const std::vector returnStates; 27 | 28 | ArrayPredictionContext(Ref const& a); 29 | ArrayPredictionContext(std::vector> const& parents_, std::vector const& returnStates); 30 | virtual ~ArrayPredictionContext(); 31 | 32 | virtual bool isEmpty() const override; 33 | virtual size_t size() const override; 34 | virtual Ref getParent(size_t index) const override; 35 | virtual size_t getReturnState(size_t index) const override; 36 | bool operator == (const PredictionContext &o) const override; 37 | 38 | virtual std::string toString() const override; 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | 44 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AtomTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/AtomTransition.h" 10 | 11 | using namespace antlr4::misc; 12 | using namespace antlr4::atn; 13 | 14 | AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) { 15 | } 16 | 17 | Transition::SerializationType AtomTransition::getSerializationType() const { 18 | return ATOM; 19 | } 20 | 21 | IntervalSet AtomTransition::label() const { 22 | return IntervalSet::of((int)_label); 23 | } 24 | 25 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return _label == symbol; 27 | } 28 | 29 | std::string AtomTransition::toString() const { 30 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AtomTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// TODO: make all transitions sets? no, should remove set edges. 14 | class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { 15 | public: 16 | /// The token type or character value; or, signifies special label. 17 | const size_t _label; 18 | 19 | AtomTransition(ATNState *target, size_t label); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicBlockStartState::getStateType() { 11 | return BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | #include "atn/BlockStartState.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC BasicBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicState::getStateType() { 11 | return BASIC; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC BasicState final : public ATNState { 14 | 15 | public: 16 | virtual size_t getStateType() override; 17 | 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BlockEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | BlockEndState::BlockEndState() : startState(nullptr) { 11 | } 12 | 13 | size_t BlockEndState::getStateType() { 14 | return BLOCK_END; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Terminal node of a simple {@code (a|b|c)} block. 14 | class ANTLR4CPP_PUBLIC BlockEndState final : public ATNState { 15 | public: 16 | BlockStartState *startState = nullptr; 17 | 18 | BlockEndState(); 19 | 20 | virtual size_t getStateType() override; 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BlockStartState.h" 7 | 8 | antlr4::atn::BlockStartState::~BlockStartState() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The start of a regular {@code (...)} block. 14 | class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { 15 | public: 16 | ~BlockStartState(); 17 | BlockEndState *endState = nullptr; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ContextSensitivityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ContextSensitivityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, 12 | size_t startIndex, size_t stopIndex) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, 12 | size_t stopIndex, bool fullCtx) 13 | : decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ErrorInfo.h" 7 | #include "atn/LookaheadEventInfo.h" 8 | 9 | #include "atn/DecisionInfo.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | DecisionInfo::DecisionInfo(size_t decision) : decision(decision) { 14 | } 15 | 16 | std::string DecisionInfo::toString() const { 17 | std::stringstream ss; 18 | 19 | ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors="; 20 | ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook; 21 | ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions; 22 | ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}'; 23 | 24 | return ss.str(); 25 | } 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | void DecisionState::InitializeInstanceFields() { 11 | decision = -1; 12 | nonGreedy = false; 13 | } 14 | 15 | std::string DecisionState::toString() const { 16 | return "DECISION " + ATNState::toString(); 17 | } 18 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC DecisionState : public ATNState { 14 | public: 15 | int decision; 16 | bool nonGreedy; 17 | 18 | private: 19 | void InitializeInstanceFields(); 20 | 21 | public: 22 | DecisionState() { 23 | InitializeInstanceFields(); 24 | } 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EmptyPredictionContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EmptyPredictionContext.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) { 11 | } 12 | 13 | bool EmptyPredictionContext::isEmpty() const { 14 | return true; 15 | } 16 | 17 | size_t EmptyPredictionContext::size() const { 18 | return 1; 19 | } 20 | 21 | Ref EmptyPredictionContext::getParent(size_t /*index*/) const { 22 | return nullptr; 23 | } 24 | 25 | size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { 26 | return returnState; 27 | } 28 | 29 | bool EmptyPredictionContext::operator == (const PredictionContext &o) const { 30 | return this == &o; 31 | } 32 | 33 | std::string EmptyPredictionContext::toString() const { 34 | return "$"; 35 | } 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EmptyPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SingletonPredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EmptyPredictionContext : public SingletonPredictionContext { 14 | public: 15 | EmptyPredictionContext(); 16 | 17 | virtual bool isEmpty() const override; 18 | virtual size_t size() const override; 19 | virtual Ref getParent(size_t index) const override; 20 | virtual size_t getReturnState(size_t index) const override; 21 | virtual std::string toString() const override; 22 | 23 | virtual bool operator == (const PredictionContext &o) const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EpsilonTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EpsilonTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, INVALID_INDEX) { 11 | } 12 | 13 | EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn) 14 | : Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { 15 | } 16 | 17 | size_t EpsilonTransition::outermostPrecedenceReturn() { 18 | return _outermostPrecedenceReturn; 19 | } 20 | 21 | Transition::SerializationType EpsilonTransition::getSerializationType() const { 22 | return EPSILON; 23 | } 24 | 25 | bool EpsilonTransition::isEpsilon() const { 26 | return true; 27 | } 28 | 29 | bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 30 | return false; 31 | } 32 | 33 | std::string EpsilonTransition::toString() const { 34 | return "EPSILON " + Transition::toString() + " {}"; 35 | } 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EpsilonTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition { 14 | public: 15 | EpsilonTransition(ATNState *target); 16 | EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); 17 | 18 | /** 19 | * @return the rule index of a precedence rule for which this transition is 20 | * returning from, where the precedence value is 0; otherwise, INVALID_INDEX. 21 | * 22 | * @see ATNConfig#isPrecedenceFilterSuppressed() 23 | * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) 24 | * @since 4.4.1 25 | */ 26 | size_t outermostPrecedenceReturn(); 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | virtual std::string toString() const override; 33 | 34 | private: 35 | const size_t _outermostPrecedenceReturn; // A rule index. 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ErrorInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNConfigSet.h" 7 | 8 | #include "atn/ErrorInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 14 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ErrorInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// This class represents profiling event information for a syntax error 15 | /// identified during prediction. Syntax errors occur when the prediction 16 | /// algorithm is unable to identify an alternative which would lead to a 17 | /// successful parse. 18 | /// 19 | /// 20 | /// 23 | class ANTLR4CPP_PUBLIC ErrorInfo : public DecisionEventInfo { 24 | public: 25 | /// 26 | /// Constructs a new instance of the class with the 27 | /// specified detailed syntax error information. 28 | /// 29 | /// The decision number 30 | /// The final configuration set reached during prediction 31 | /// prior to reaching the state 32 | /// The input token stream 33 | /// The start index for the current prediction 34 | /// The index at which the syntax error was identified 35 | /// {@code true} if the syntax error was identified during LL 36 | /// prediction; otherwise, {@code false} if the syntax error was identified 37 | /// during SLL prediction 38 | ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, 39 | bool fullCtx); 40 | }; 41 | 42 | } // namespace atn 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerATNConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfig.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC LexerATNConfig : public ATNConfig { 14 | public: 15 | LexerATNConfig(ATNState *state, int alt, Ref const& context); 16 | LexerATNConfig(ATNState *state, int alt, Ref const& context, Ref const& lexerActionExecutor); 17 | 18 | LexerATNConfig(Ref const& c, ATNState *state); 19 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& lexerActionExecutor); 20 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& context); 21 | 22 | /** 23 | * Gets the {@link LexerActionExecutor} capable of executing the embedded 24 | * action(s) for the current configuration. 25 | */ 26 | Ref getLexerActionExecutor() const; 27 | bool hasPassedThroughNonGreedyDecision(); 28 | 29 | virtual size_t hashCode() const override; 30 | 31 | bool operator == (const LexerATNConfig& other) const; 32 | 33 | private: 34 | /** 35 | * This is the backing field for {@link #getLexerActionExecutor}. 36 | */ 37 | const Ref _lexerActionExecutor; 38 | const bool _passedThroughNonGreedyDecision; 39 | 40 | static bool checkNonGreedyDecision(Ref const& source, ATNState *target); 41 | }; 42 | 43 | } // namespace atn 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "LexerAction.h" 7 | 8 | antlr4::atn::LexerAction::~LexerAction() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerActionType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// Represents the serialization type of a . 15 | /// 16 | /// @author Sam Harwell 17 | /// @since 4.2 18 | /// 19 | enum class LexerActionType : size_t { 20 | /// 21 | /// The type of a action. 22 | /// 23 | CHANNEL, 24 | /// 25 | /// The type of a action. 26 | /// 27 | CUSTOM, 28 | /// 29 | /// The type of a action. 30 | /// 31 | MODE, 32 | /// 33 | /// The type of a action. 34 | /// 35 | MORE, 36 | /// 37 | /// The type of a action. 38 | /// 39 | POP_MODE, 40 | /// 41 | /// The type of a action. 42 | /// 43 | PUSH_MODE, 44 | /// 45 | /// The type of a action. 46 | /// 47 | SKIP, 48 | /// 49 | /// The type of a action. 50 | /// 51 | TYPE, 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerChannelAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerChannelAction.h" 10 | 11 | using namespace antlr4::atn; 12 | using namespace antlr4::misc; 13 | 14 | LexerChannelAction::LexerChannelAction(int channel) : _channel(channel) { 15 | } 16 | 17 | int LexerChannelAction::getChannel() const { 18 | return _channel; 19 | } 20 | 21 | LexerActionType LexerChannelAction::getActionType() const { 22 | return LexerActionType::CHANNEL; 23 | } 24 | 25 | bool LexerChannelAction::isPositionDependent() const { 26 | return false; 27 | } 28 | 29 | void LexerChannelAction::execute(Lexer *lexer) { 30 | lexer->setChannel(_channel); 31 | } 32 | 33 | size_t LexerChannelAction::hashCode() const { 34 | size_t hash = MurmurHash::initialize(); 35 | hash = MurmurHash::update(hash, static_cast(getActionType())); 36 | hash = MurmurHash::update(hash, _channel); 37 | return MurmurHash::finish(hash, 2); 38 | } 39 | 40 | bool LexerChannelAction::operator == (const LexerAction &obj) const { 41 | if (&obj == this) { 42 | return true; 43 | } 44 | 45 | const LexerChannelAction *action = dynamic_cast(&obj); 46 | if (action == nullptr) { 47 | return false; 48 | } 49 | 50 | return _channel == action->_channel; 51 | } 52 | 53 | std::string LexerChannelAction::toString() const { 54 | return "channel(" + std::to_string(_channel) + ")"; 55 | } 56 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "support/CPPUtils.h" 8 | #include "Lexer.h" 9 | 10 | #include "atn/LexerCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) : _ruleIndex(ruleIndex), _actionIndex(actionIndex) { 17 | } 18 | 19 | size_t LexerCustomAction::getRuleIndex() const { 20 | return _ruleIndex; 21 | } 22 | 23 | size_t LexerCustomAction::getActionIndex() const { 24 | return _actionIndex; 25 | } 26 | 27 | LexerActionType LexerCustomAction::getActionType() const { 28 | return LexerActionType::CUSTOM; 29 | } 30 | 31 | bool LexerCustomAction::isPositionDependent() const { 32 | return true; 33 | } 34 | 35 | void LexerCustomAction::execute(Lexer *lexer) { 36 | lexer->action(nullptr, _ruleIndex, _actionIndex); 37 | } 38 | 39 | size_t LexerCustomAction::hashCode() const { 40 | size_t hash = MurmurHash::initialize(); 41 | hash = MurmurHash::update(hash, static_cast(getActionType())); 42 | hash = MurmurHash::update(hash, _ruleIndex); 43 | hash = MurmurHash::update(hash, _actionIndex); 44 | return MurmurHash::finish(hash, 3); 45 | } 46 | 47 | bool LexerCustomAction::operator == (const LexerAction &obj) const { 48 | if (&obj == this) { 49 | return true; 50 | } 51 | 52 | const LexerCustomAction *action = dynamic_cast(&obj); 53 | if (action == nullptr) { 54 | return false; 55 | } 56 | 57 | return _ruleIndex == action->_ruleIndex && _actionIndex == action->_actionIndex; 58 | } 59 | 60 | std::string LexerCustomAction::toString() const { 61 | return antlrcpp::toString(this); 62 | } 63 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerIndexedCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | #include "support/CPPUtils.h" 9 | 10 | #include "atn/LexerIndexedCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref const& action) 17 | : _offset(offset), _action(action) { 18 | } 19 | 20 | int LexerIndexedCustomAction::getOffset() const { 21 | return _offset; 22 | } 23 | 24 | Ref LexerIndexedCustomAction::getAction() const { 25 | return _action; 26 | } 27 | 28 | LexerActionType LexerIndexedCustomAction::getActionType() const { 29 | return _action->getActionType(); 30 | } 31 | 32 | bool LexerIndexedCustomAction::isPositionDependent() const { 33 | return true; 34 | } 35 | 36 | void LexerIndexedCustomAction::execute(Lexer *lexer) { 37 | // assume the input stream position was properly set by the calling code 38 | _action->execute(lexer); 39 | } 40 | 41 | size_t LexerIndexedCustomAction::hashCode() const { 42 | size_t hash = MurmurHash::initialize(); 43 | hash = MurmurHash::update(hash, _offset); 44 | hash = MurmurHash::update(hash, _action); 45 | return MurmurHash::finish(hash, 2); 46 | } 47 | 48 | bool LexerIndexedCustomAction::operator == (const LexerAction &obj) const { 49 | if (&obj == this) { 50 | return true; 51 | } 52 | 53 | const LexerIndexedCustomAction *action = dynamic_cast(&obj); 54 | if (action == nullptr) { 55 | return false; 56 | } 57 | 58 | return _offset == action->_offset && *_action == *action->_action; 59 | } 60 | 61 | std::string LexerIndexedCustomAction::toString() const { 62 | return antlrcpp::toString(this); 63 | } 64 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerModeAction::LexerModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerModeAction::getMode() { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerModeAction::getActionType() const { 23 | return LexerActionType::MODE; 24 | } 25 | 26 | bool LexerModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerModeAction::execute(Lexer *lexer) { 31 | lexer->setMode(_mode); 32 | } 33 | 34 | size_t LexerModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerModeAction::toString() const { 55 | return "mode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerMoreAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerMoreAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerMoreAction::getInstance() { 16 | static Ref instance(new LexerMoreAction()); 17 | return instance; 18 | } 19 | 20 | LexerMoreAction::LexerMoreAction() { 21 | } 22 | 23 | LexerActionType LexerMoreAction::getActionType() const { 24 | return LexerActionType::MORE; 25 | } 26 | 27 | bool LexerMoreAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerMoreAction::execute(Lexer *lexer) { 32 | lexer->more(); 33 | } 34 | 35 | size_t LexerMoreAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerMoreAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerMoreAction::toString() const { 46 | return "more"; 47 | } 48 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerMoreAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code more} lexer action by calling . 16 | /// 17 | /// The {@code more} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerMoreAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code more} command. 53 | LexerMoreAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerPopModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPopModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerPopModeAction::getInstance() { 16 | static Ref instance(new LexerPopModeAction()); 17 | return instance; 18 | } 19 | 20 | LexerPopModeAction::LexerPopModeAction() { 21 | } 22 | 23 | LexerActionType LexerPopModeAction::getActionType() const { 24 | return LexerActionType::POP_MODE; 25 | } 26 | 27 | bool LexerPopModeAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerPopModeAction::execute(Lexer *lexer) { 32 | lexer->popMode(); 33 | } 34 | 35 | size_t LexerPopModeAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerPopModeAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerPopModeAction::toString() const { 46 | return "popMode"; 47 | } 48 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerPopModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code popMode} lexer action by calling . 16 | /// 17 | /// The {@code popMode} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerPopModeAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code popMode} command. 53 | LexerPopModeAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerPushModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPushModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerPushModeAction::LexerPushModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerPushModeAction::getMode() const { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerPushModeAction::getActionType() const { 23 | return LexerActionType::PUSH_MODE; 24 | } 25 | 26 | bool LexerPushModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerPushModeAction::execute(Lexer *lexer) { 31 | lexer->pushMode(_mode); 32 | } 33 | 34 | size_t LexerPushModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerPushModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerPushModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerPushModeAction::toString() const { 55 | return "pushMode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerSkipAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerSkipAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerSkipAction::getInstance() { 16 | static Ref instance(new LexerSkipAction()); 17 | return instance; 18 | } 19 | 20 | LexerSkipAction::LexerSkipAction() { 21 | } 22 | 23 | LexerActionType LexerSkipAction::getActionType() const { 24 | return LexerActionType::SKIP; 25 | } 26 | 27 | bool LexerSkipAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerSkipAction::execute(Lexer *lexer) { 32 | lexer->skip(); 33 | } 34 | 35 | size_t LexerSkipAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerSkipAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerSkipAction::toString() const { 46 | return "skip"; 47 | } 48 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerSkipAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code skip} lexer action by calling . 16 | /// 17 | /// The {@code skip} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction { 24 | public: 25 | /// Provides a singleton instance of this parameterless lexer action. 26 | static const Ref getInstance(); 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling . 42 | /// 43 | virtual void execute(Lexer *lexer) override; 44 | 45 | virtual size_t hashCode() const override; 46 | virtual bool operator == (const LexerAction &obj) const override; 47 | virtual std::string toString() const override; 48 | 49 | private: 50 | /// Constructs the singleton instance of the lexer {@code skip} command. 51 | LexerSkipAction(); 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerTypeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerTypeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerTypeAction::LexerTypeAction(int type) : _type(type) { 16 | } 17 | 18 | int LexerTypeAction::getType() const { 19 | return _type; 20 | } 21 | 22 | LexerActionType LexerTypeAction::getActionType() const { 23 | return LexerActionType::TYPE; 24 | } 25 | 26 | bool LexerTypeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerTypeAction::execute(Lexer *lexer) { 31 | lexer->setType(_type); 32 | } 33 | 34 | size_t LexerTypeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _type); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerTypeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerTypeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _type == action->_type; 52 | } 53 | 54 | std::string LexerTypeAction::toString() const { 55 | return "type(" + std::to_string(_type) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerTypeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerActionType.h" 9 | #include "atn/LexerAction.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// Implements the {@code type} lexer action by calling 15 | /// with the assigned type. 16 | class ANTLR4CPP_PUBLIC LexerTypeAction : public LexerAction { 17 | public: 18 | /// 19 | /// Constructs a new {@code type} action with the specified token type value. 20 | /// The type to assign to the token using . 21 | LexerTypeAction(int type); 22 | 23 | /// 24 | /// Gets the type to assign to a token created by the lexer. 25 | /// The type to assign to a token created by the lexer. 26 | virtual int getType() const; 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling with the 42 | /// value provided by . 43 | /// 44 | virtual void execute(Lexer *lexer) override; 45 | 46 | virtual size_t hashCode() const override; 47 | virtual bool operator == (const LexerAction &obj) const override; 48 | virtual std::string toString() const override; 49 | 50 | private: 51 | const int _type; 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LookaheadEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LookaheadEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | LookaheadEventInfo::LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->predictedAlt = predictedAlt; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LookaheadEventInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// This class represents profiling event information for tracking the lookahead 14 | /// depth required in order to make a prediction. 15 | class ANTLR4CPP_PUBLIC LookaheadEventInfo : public DecisionEventInfo { 16 | public: 17 | /// The alternative chosen by adaptivePredict(), not necessarily 18 | /// the outermost alt shown for a rule; left-recursive rules have 19 | /// user-level alts that differ from the rewritten rule with a (...) block 20 | /// and a (..)* loop. 21 | size_t predictedAlt = 0; 22 | 23 | /// 24 | /// Constructs a new instance of the class with 25 | /// the specified detailed lookahead information. 26 | /// 27 | /// The decision number 28 | /// The final configuration set containing the necessary 29 | /// information to determine the result of a prediction, or {@code null} if 30 | /// the final configuration set is not available 31 | /// The input token stream 32 | /// The start index for the current prediction 33 | /// The index at which the prediction was finally made 34 | /// {@code true} if the current lookahead is part of an LL 35 | /// prediction; otherwise, {@code false} if the current lookahead is part of 36 | /// an SLL prediction 37 | LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, TokenStream *input, size_t startIndex, 38 | size_t stopIndex, bool fullCtx); 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LoopEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LoopEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t LoopEndState::getStateType() { 11 | return LOOP_END; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LoopEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Mark the end of a * or + loop. 14 | class ANTLR4CPP_PUBLIC LoopEndState final : public ATNState { 15 | public: 16 | ATNState *loopBackState = nullptr; 17 | 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CXXFLAGS += -g -std=c++0x -Wall #-Wextra 3 | CXXFLAGS += -I. -I../ -I../misc/ -I../tree/ -I../dfa/ \ 4 | -I../../../../../antlrcpp/ 5 | 6 | #TODO LDFLAGS += ? 7 | 8 | ALL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) 9 | ALL_LDFLAGS = $(LDFLAGS) 10 | 11 | # Escote's files 12 | SRCS = \ 13 | AbstractPredicateTransition.cpp \ 14 | ActionTransition.cpp \ 15 | ArrayPredictionContext.cpp \ 16 | ATNDeserializationOptions.cpp \ 17 | ATNDeserializer.cpp \ 18 | ATNState.cpp \ 19 | ATNType.cpp \ 20 | AtomTransition.cpp \ 21 | BasicBlockStartState.cpp \ 22 | BasicState.cpp \ 23 | BlockEndState.cpp \ 24 | BlockStartState.cpp \ 25 | DecisionState.cpp \ 26 | EmptyPredictionContext.cpp \ 27 | EpsilonTransition.cpp \ 28 | LexerATNConfig.cpp \ 29 | LoopEndState.cpp 30 | # Escote's TODO: LL1Analyzer.cpp LexerATNSimulator.cpp ATNSimulator.cpp \ 31 | ATNSerializer.cpp ATNConfigSet.cpp ATNConfig.cpp \ 32 | ATN.cpp 33 | 34 | # Alejandro's files 35 | SRCS += \ 36 | NotSetTransition.cpp \ 37 | OrderedATNConfigSet.cpp \ 38 | PlusBlockStartState.cpp \ 39 | PlusLoopbackState.cpp \ 40 | PredicateTransition.cpp \ 41 | PredictionMode.cpp \ 42 | RangeTransition.cpp \ 43 | RuleStartState.cpp \ 44 | RuleStopState.cpp \ 45 | RuleTransition.cpp \ 46 | SemanticContext.cpp \ 47 | SetTransition.cpp \ 48 | SingletonPredictionContext.cpp \ 49 | StarBlockStartState.cpp \ 50 | StarLoopbackState.cpp \ 51 | StarLoopEntryState.cpp \ 52 | TokensStartState.cpp \ 53 | Transition.cpp \ 54 | WildcardTransition.cpp 55 | # Alejandro's TODO: PredictionContext.cpp PredictionContextCache.cpp \ 56 | PrecedencePredicateTransition.cpp ParserATNSimulator.cpp 57 | 58 | OBJS = $(SRCS:.cpp=.o) 59 | 60 | all: $(OBJS) 61 | 62 | %.o: %.cpp 63 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 64 | 65 | clean: 66 | $(RM) $(OBJS) 67 | 68 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/NotSetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/NotSetTransition.h" 7 | #include "atn/ATNState.h" 8 | #include "misc/IntervalSet.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { 14 | } 15 | 16 | Transition::SerializationType NotSetTransition::getSerializationType() const { 17 | return NOT_SET; 18 | } 19 | 20 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 21 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 22 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 23 | } 24 | 25 | std::string NotSetTransition::toString() const { 26 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/NotSetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SetTransition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { 14 | public: 15 | NotSetTransition(ATNState *target, const misc::IntervalSet &set); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/OrderedATNConfigSet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/OrderedATNConfigSet.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t OrderedATNConfigSet::getHash(ATNConfig *c) { 11 | return c->hashCode(); 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/OrderedATNConfigSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNConfig.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { 15 | protected: 16 | virtual size_t getHash(ATNConfig *c) override; 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusBlockStartState::getStateType() { 11 | return PLUS_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Start of {@code (A|B|...)+} loop. Technically a decision state, but 14 | /// we don't use for code generation; somebody might need it, so I'm defining 15 | /// it for completeness. In reality, the node is the 16 | /// real decision-making note for {@code A+}. 17 | class ANTLR4CPP_PUBLIC PlusBlockStartState final : public BlockStartState { 18 | public: 19 | PlusLoopbackState *loopBackState = nullptr; 20 | 21 | virtual size_t getStateType() override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusLoopbackState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusLoopbackState::getStateType() { 11 | return PLUS_LOOP_BACK; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: 14 | /// one to the loop back to start of the block and one to exit. 15 | class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { 16 | 17 | public: 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PrecedencePredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PrecedencePredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) 11 | : AbstractPredicateTransition(target), precedence(precedence) { 12 | } 13 | 14 | Transition::SerializationType PrecedencePredicateTransition::getSerializationType() const { 15 | return PRECEDENCE; 16 | } 17 | 18 | bool PrecedencePredicateTransition::isEpsilon() const { 19 | return true; 20 | } 21 | 22 | bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return false; 24 | } 25 | 26 | Ref PrecedencePredicateTransition::getPredicate() const { 27 | return std::make_shared(precedence); 28 | } 29 | 30 | std::string PrecedencePredicateTransition::toString() const { 31 | return "PRECEDENCE " + Transition::toString() + " { precedence: " + std::to_string(precedence) + " }"; 32 | } 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PrecedencePredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public AbstractPredicateTransition { 15 | public: 16 | const int precedence; 17 | 18 | PrecedencePredicateTransition(ATNState *target, int precedence); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | virtual bool isEpsilon() const override; 22 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 23 | Ref getPredicate() const; 24 | virtual std::string toString() const override; 25 | 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PredicateEvalInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "SemanticContext.h" 7 | 8 | #include "atn/PredicateEvalInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, 14 | Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PredicateTransition::PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) { 11 | } 12 | 13 | Transition::SerializationType PredicateTransition::getSerializationType() const { 14 | return PREDICATE; 15 | } 16 | 17 | bool PredicateTransition::isEpsilon() const { 18 | return true; 19 | } 20 | 21 | bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 22 | return false; 23 | } 24 | 25 | Ref PredicateTransition::getPredicate() const { 26 | return std::make_shared(ruleIndex, predIndex, isCtxDependent); 27 | } 28 | 29 | std::string PredicateTransition::toString() const { 30 | return "PREDICATE " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + 31 | ", predIndex: " + std::to_string(predIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 32 | 33 | // Generate and add a predicate context here? 34 | } 35 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// TODO: this is old comment: 15 | /// A tree of semantic predicates from the grammar AST if label==SEMPRED. 16 | /// In the ATN, labels will always be exactly one predicate, but the DFA 17 | /// may have to combine a bunch of them as it collects predicates from 18 | /// multiple ATN configurations into a single DFA state. 19 | class ANTLR4CPP_PUBLIC PredicateTransition final : public AbstractPredicateTransition { 20 | public: 21 | const size_t ruleIndex; 22 | const size_t predIndex; 23 | const bool isCtxDependent; // e.g., $i ref in pred 24 | 25 | PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent); 26 | 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | Ref getPredicate() const; 33 | 34 | virtual std::string toString() const override; 35 | 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RangeTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | 8 | #include "atn/RangeTransition.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) { 14 | } 15 | 16 | Transition::SerializationType RangeTransition::getSerializationType() const { 17 | return RANGE; 18 | } 19 | 20 | misc::IntervalSet RangeTransition::label() const { 21 | return misc::IntervalSet::of((int)from, (int)to); 22 | } 23 | 24 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return symbol >= from && symbol <= to; 26 | } 27 | 28 | std::string RangeTransition::toString() const { 29 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RangeTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RangeTransition final : public Transition { 14 | public: 15 | const size_t from; 16 | const size_t to; 17 | 18 | RangeTransition(ATNState *target, size_t from, size_t to); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | 22 | virtual misc::IntervalSet label() const override; 23 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 24 | 25 | virtual std::string toString() const override; 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | RuleStartState::RuleStartState() { 11 | isLeftRecursiveRule = false; 12 | } 13 | 14 | size_t RuleStartState::getStateType() { 15 | return RULE_START; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { 14 | public: 15 | RuleStartState(); 16 | 17 | RuleStopState *stopState = nullptr; 18 | bool isLeftRecursiveRule = false; 19 | 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStopState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStopState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t RuleStopState::getStateType() { 11 | return RULE_STOP; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStopState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 14 | /// In that case, there is one transition to EOF. Later, we might encode 15 | /// references to all calls to this rule to compute FOLLOW sets for 16 | /// error handling. 17 | class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { 18 | 19 | public: 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | #include "atn/RuleTransition.h" 8 | 9 | using namespace antlr4::atn; 10 | 11 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState) 12 | : RuleTransition(ruleStart, ruleIndex, 0, followState) { 13 | } 14 | 15 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState) 16 | : Transition(ruleStart), ruleIndex(ruleIndex), precedence(precedence) { 17 | this->followState = followState; 18 | } 19 | 20 | Transition::SerializationType RuleTransition::getSerializationType() const { 21 | return RULE; 22 | } 23 | 24 | bool RuleTransition::isEpsilon() const { 25 | return true; 26 | } 27 | 28 | bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 29 | return false; 30 | } 31 | 32 | std::string RuleTransition::toString() const { 33 | std::stringstream ss; 34 | ss << "RULE " << Transition::toString() << " { ruleIndex: " << ruleIndex << ", precedence: " << precedence << 35 | ", followState: " << std::hex << followState << " }"; 36 | return ss.str(); 37 | } 38 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleTransition : public Transition { 14 | public: 15 | /// Ptr to the rule definition object for this rule ref. 16 | const size_t ruleIndex; // no Rule object at runtime 17 | 18 | const int precedence; 19 | 20 | /// What node to begin computations following ref to rule. 21 | ATNState *followState; 22 | 23 | /// @deprecated Use 24 | /// instead. 25 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState); 26 | 27 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState); 28 | RuleTransition(RuleTransition const&) = delete; 29 | RuleTransition& operator=(RuleTransition const&) = delete; 30 | 31 | virtual SerializationType getSerializationType() const override; 32 | 33 | virtual bool isEpsilon() const override; 34 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 35 | 36 | virtual std::string toString() const override; 37 | }; 38 | 39 | } // namespace atn 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/SetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | #include "misc/IntervalSet.h" 8 | 9 | #include "atn/SetTransition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) 15 | : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { 16 | } 17 | 18 | Transition::SerializationType SetTransition::getSerializationType() const { 19 | return SET; 20 | } 21 | 22 | misc::IntervalSet SetTransition::label() const { 23 | return set; 24 | } 25 | 26 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return set.contains(symbol); 28 | } 29 | 30 | std::string SetTransition::toString() const { 31 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 32 | } 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/SetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// A transition containing a set of values. 15 | class ANTLR4CPP_PUBLIC SetTransition : public Transition { 16 | public: 17 | const misc::IntervalSet set; 18 | 19 | SetTransition(ATNState *target, const misc::IntervalSet &set); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/SingletonPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/PredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC SingletonPredictionContext : public PredictionContext { 14 | public: 15 | // Usually a parent is linked via a weak ptr. Not so here as we have kinda reverse reference chain. 16 | // There are no child contexts stored here and often the parent context is left dangling when it's 17 | // owning ATNState is released. In order to avoid having this context released as well (leaving all other contexts 18 | // which got this one as parent with a null reference) we use a shared_ptr here instead, to keep those left alone 19 | // parent contexts alive. 20 | const Ref parent; 21 | const size_t returnState; 22 | 23 | SingletonPredictionContext(Ref const& parent, size_t returnState); 24 | virtual ~SingletonPredictionContext(); 25 | 26 | static Ref create(Ref const& parent, size_t returnState); 27 | 28 | virtual size_t size() const override; 29 | virtual Ref getParent(size_t index) const override; 30 | virtual size_t getReturnState(size_t index) const override; 31 | virtual bool operator == (const PredictionContext &o) const override; 32 | virtual std::string toString() const override; 33 | }; 34 | 35 | } // namespace atn 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t StarBlockStartState::getStateType() { 11 | return STAR_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The block that begins a closure loop. 14 | class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopEntryState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { 11 | } 12 | 13 | size_t StarLoopEntryState::getStateType() { 14 | return STAR_LOOP_ENTRY; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopEntryState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { 14 | public: 15 | StarLoopEntryState(); 16 | 17 | /** 18 | * Indicates whether this state can benefit from a precedence DFA during SLL 19 | * decision making. 20 | * 21 | *

This is a computed property that is calculated during ATN deserialization 22 | * and stored for use in {@link ParserATNSimulator} and 23 | * {@link ParserInterpreter}.

24 | * 25 | * @see DFA#isPrecedenceDfa() 26 | */ 27 | bool isPrecedenceDecision = false; 28 | 29 | StarLoopbackState *loopBackState = nullptr; 30 | 31 | virtual size_t getStateType() override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/StarLoopbackState.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() { 14 | return dynamic_cast(transitions[0]->target); 15 | } 16 | 17 | size_t StarLoopbackState::getStateType() { 18 | return STAR_LOOP_BACK; 19 | } 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { 14 | public: 15 | StarLoopEntryState *getLoopEntryState(); 16 | 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/TokensStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/TokensStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t TokensStartState::getStateType() { 11 | return TOKEN_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/TokensStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The Tokens rule start state linking to each lexer rule start state. 14 | class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/Transition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "support/Arrays.h" 8 | 9 | #include "atn/Transition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | using namespace antlrcpp; 15 | 16 | const std::vector Transition::serializationNames = { 17 | "INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION", "SET", "NOT_SET", "WILDCARD", "PRECEDENCE" 18 | }; 19 | 20 | Transition::Transition(ATNState *target) { 21 | if (target == nullptr) { 22 | throw NullPointerException("target cannot be null."); 23 | } 24 | 25 | this->target = target; 26 | } 27 | 28 | Transition::~Transition() { 29 | } 30 | 31 | bool Transition::isEpsilon() const { 32 | return false; 33 | } 34 | 35 | misc::IntervalSet Transition::label() const { 36 | return misc::IntervalSet::EMPTY_SET; 37 | } 38 | 39 | std::string Transition::toString() const { 40 | std::stringstream ss; 41 | ss << "(Transition " << std::hex << this << ", target: " << std::hex << target << ')'; 42 | 43 | return ss.str(); 44 | } 45 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/WildcardTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNState.h" 7 | 8 | #include "atn/WildcardTransition.h" 9 | 10 | using namespace antlr4::atn; 11 | 12 | WildcardTransition::WildcardTransition(ATNState *target) : Transition(target) { 13 | } 14 | 15 | Transition::SerializationType WildcardTransition::getSerializationType() const { 16 | return WILDCARD; 17 | } 18 | 19 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 21 | } 22 | 23 | std::string WildcardTransition::toString() const { 24 | return "WILDCARD " + Transition::toString() + " {}"; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/WildcardTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { 14 | public: 15 | WildcardTransition(ATNState *target); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/DFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Vocabulary.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | /// A DFA walker that knows how to dump them to serialized strings. 14 | class ANTLR4CPP_PUBLIC DFASerializer { 15 | public: 16 | DFASerializer(const DFA *dfa, const std::vector& tnames); 17 | DFASerializer(const DFA *dfa, const Vocabulary &vocabulary); 18 | virtual ~DFASerializer(); 19 | 20 | virtual std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | virtual std::string getStateString(DFAState *s) const; 25 | 26 | private: 27 | const DFA *_dfa; 28 | const Vocabulary &_vocabulary; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/LexerDFASerializer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Vocabulary.h" 7 | 8 | #include "dfa/LexerDFASerializer.h" 9 | 10 | using namespace antlr4::dfa; 11 | 12 | LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, Vocabulary::EMPTY_VOCABULARY) { 13 | } 14 | 15 | LexerDFASerializer::~LexerDFASerializer() { 16 | } 17 | 18 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 19 | return std::string("'") + static_cast(i) + "'"; 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/LexerDFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "dfa/DFASerializer.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | class ANTLR4CPP_PUBLIC LexerDFASerializer : public DFASerializer { 14 | public: 15 | LexerDFASerializer(DFA *dfa); 16 | virtual ~LexerDFASerializer(); 17 | 18 | protected: 19 | virtual std::string getEdgeLabel(size_t i) const override; 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/InterpreterDataReader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | struct InterpreterData { 14 | atn::ATN atn; 15 | dfa::Vocabulary vocabulary; 16 | std::vector ruleNames; 17 | std::vector channels; // Only valid for lexer grammars. 18 | std::vector modes; // ditto 19 | 20 | InterpreterData() {}; // For invalid content. 21 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 22 | }; 23 | 24 | // A class to read plain text interpreter data produced by ANTLR. 25 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 26 | public: 27 | static InterpreterData parseFile(std::string const& fileName); 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/Predicate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | class ANTLR4CPP_PUBLIC Predicate { 14 | public: 15 | virtual ~Predicate(); 16 | 17 | virtual bool test(tree::ParseTree *t) = 0; 18 | }; 19 | 20 | } // namespace tree 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/Any.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Any.h" 7 | 8 | using namespace antlrcpp; 9 | 10 | Any::~Any() 11 | { 12 | delete _ptr; 13 | } 14 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/BitSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | class ANTLR4CPP_PUBLIC BitSet : public std::bitset<2048> { 13 | public: 14 | size_t nextSetBit(size_t pos) const { 15 | for (size_t i = pos; i < size(); i++){ 16 | if (test(i)) { 17 | return i; 18 | } 19 | } 20 | 21 | return INVALID_INDEX; 22 | } 23 | 24 | // Prints a list of every index for which the bitset contains a bit in true. 25 | friend std::wostream& operator << (std::wostream& os, const BitSet& obj) 26 | { 27 | os << "{"; 28 | size_t total = obj.count(); 29 | for (size_t i = 0; i < obj.size(); i++){ 30 | if (obj.test(i)){ 31 | os << i; 32 | --total; 33 | if (total > 1){ 34 | os << ", "; 35 | } 36 | } 37 | } 38 | 39 | os << "}"; 40 | return os; 41 | } 42 | 43 | static std::string subStringRepresentation(const std::vector::iterator &begin, 44 | const std::vector::iterator &end) { 45 | std::string result; 46 | std::vector::iterator vectorIterator; 47 | 48 | for (vectorIterator = begin; vectorIterator != end; vectorIterator++) { 49 | result += vectorIterator->toString(); 50 | } 51 | // Grab the end 52 | result += end->toString(); 53 | 54 | return result; 55 | } 56 | 57 | std::string toString(){ 58 | std::stringstream stream; 59 | stream << "{"; 60 | bool valueAdded = false; 61 | for (size_t i = 0; i < size(); ++i){ 62 | if (test(i)){ 63 | if (valueAdded) { 64 | stream << ", "; 65 | } 66 | stream << i; 67 | valueAdded = true; 68 | } 69 | } 70 | 71 | stream << "}"; 72 | return stream.str(); 73 | } 74 | 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | namespace antlrcpp { 9 | 10 | void replaceAll(std::string& str, std::string const& from, std::string const& to) 11 | { 12 | if (from.empty()) 13 | return; 14 | 15 | size_t start_pos = 0; 16 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) { 17 | str.replace(start_pos, from.length(), to); 18 | start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'. 19 | } 20 | } 21 | 22 | std::string ws2s(std::wstring const& wstr) { 23 | std::wstring_convert> converter; 24 | std::string narrow = converter.to_bytes(wstr); 25 | 26 | return narrow; 27 | } 28 | 29 | std::wstring s2ws(const std::string &str) { 30 | std::wstring_convert> converter; 31 | std::wstring wide = converter.from_bytes(str); 32 | 33 | return wide; 34 | } 35 | 36 | } // namespace antrlcpp 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/StringUtils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | // For all conversions utf8 <-> utf32. 13 | // VS 2015 and VS 2017 have different bugs in std::codecvt_utf8 (VS 2013 works fine). 14 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 15 | typedef std::wstring_convert, __int32> UTF32Converter; 16 | #else 17 | typedef std::wstring_convert, char32_t> UTF32Converter; 18 | #endif 19 | 20 | // The conversion functions fails in VS2017, so we explicitly use a workaround. 21 | template 22 | inline std::string utf32_to_utf8(T const& data) 23 | { 24 | // Don't make the converter static or we have to serialize access to it. 25 | thread_local UTF32Converter converter; 26 | 27 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 28 | auto p = reinterpret_cast(data.data()); 29 | return converter.to_bytes(p, p + data.size()); 30 | #else 31 | return converter.to_bytes(data); 32 | #endif 33 | } 34 | 35 | inline UTF32String utf8_to_utf32(const char* first, const char* last) 36 | { 37 | thread_local UTF32Converter converter; 38 | 39 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 40 | auto r = converter.from_bytes(first, last); 41 | i32string s = reinterpret_cast(r.data()); 42 | #else 43 | std::u32string s = converter.from_bytes(first, last); 44 | #endif 45 | 46 | return s; 47 | } 48 | 49 | void replaceAll(std::string &str, std::string const& from, std::string const& to); 50 | 51 | // string <-> wstring conversion (UTF-16), e.g. for use with Window's wide APIs. 52 | ANTLR4CPP_PUBLIC std::string ws2s(std::wstring const& wstr); 53 | ANTLR4CPP_PUBLIC std::wstring s2ws(std::string const& str); 54 | } 55 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | 8 | antlr4::tree::ErrorNode::~ErrorNode() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ErrorNode : public virtual TerminalNode { 14 | public: 15 | ~ErrorNode() override; 16 | }; 17 | 18 | } // namespace tree 19 | } // namespace antlr4 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "tree/ParseTreeVisitor.h" 8 | 9 | #include "tree/ErrorNodeImpl.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::misc; 13 | using namespace antlr4::tree; 14 | 15 | ErrorNodeImpl::ErrorNodeImpl(Token *token) : TerminalNodeImpl(token) { 16 | } 17 | 18 | ErrorNodeImpl::~ErrorNodeImpl() { 19 | } 20 | 21 | antlrcpp::Any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 22 | return visitor->visitErrorNode(this); 23 | } 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ErrorNode.h" 9 | #include "tree/TerminalNodeImpl.h" 10 | #include "misc/Interval.h" 11 | 12 | #include "support/Any.h" 13 | 14 | namespace antlr4 { 15 | namespace tree { 16 | 17 | /// 18 | /// Represents a token that was consumed during resynchronization 19 | /// rather than during a valid match operation. For example, 20 | /// we will create this kind of a node during single token insertion 21 | /// and deletion as well as during "consume until error recovery set" 22 | /// upon no viable alternative exceptions. 23 | /// 24 | class ANTLR4CPP_PUBLIC ErrorNodeImpl : public virtual TerminalNodeImpl, public virtual ErrorNode { 25 | public: 26 | ErrorNodeImpl(Token *token); 27 | ~ErrorNodeImpl() override; 28 | 29 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | 8 | using namespace antlr4::tree; 9 | 10 | ParseTree::ParseTree() : parent(nullptr) { 11 | } 12 | 13 | bool ParseTree::operator == (const ParseTree &other) const { 14 | return &other == this; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeListener.h" 7 | 8 | antlr4::tree::ParseTreeListener::~ParseTreeListener() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /** This interface describes the minimal core of methods triggered 14 | * by {@link ParseTreeWalker}. E.g., 15 | * 16 | * ParseTreeWalker walker = new ParseTreeWalker(); 17 | * walker.walk(myParseTreeListener, myParseTree); <-- triggers events in your listener 18 | * 19 | * If you want to trigger events in multiple listeners during a single 20 | * tree walk, you can use the ParseTreeDispatcher object available at 21 | * 22 | * https://github.com/antlr/antlr4/issues/841 23 | */ 24 | class ANTLR4CPP_PUBLIC ParseTreeListener { 25 | public: 26 | virtual ~ParseTreeListener(); 27 | 28 | virtual void visitTerminal(TerminalNode *node) = 0; 29 | virtual void visitErrorNode(ErrorNode *node) = 0; 30 | virtual void enterEveryRule(ParserRuleContext *ctx) = 0; 31 | virtual void exitEveryRule(ParserRuleContext *ctx) = 0; 32 | 33 | bool operator == (const ParseTreeListener &other) { 34 | return this == &other; 35 | } 36 | }; 37 | 38 | } // namespace tree 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeProperty.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /// 14 | /// Associate a property with a parse tree node. Useful with parse tree listeners 15 | /// that need to associate values with particular tree nodes, kind of like 16 | /// specifying a return value for the listener event method that visited a 17 | /// particular node. Example: 18 | /// 19 | ///
20 |   /// ParseTreeProperty<Integer> values = new ParseTreeProperty<Integer>();
21 |   /// values.put(tree, 36);
22 |   /// int x = values.get(tree);
23 |   /// values.removeFrom(tree);
24 |   /// 
25 | /// 26 | /// You would make one decl (values here) in the listener and use lots of times 27 | /// in your event methods. 28 | ///
29 | template 30 | class ANTLR4CPP_PUBLIC ParseTreeProperty { 31 | public: 32 | virtual ~ParseTreeProperty() {} 33 | virtual V get(ParseTree *node) { 34 | return _annotations[node]; 35 | } 36 | virtual void put(ParseTree *node, V value) { 37 | _annotations[node] = value; 38 | } 39 | virtual V removeFrom(ParseTree *node) { 40 | auto value = _annotations[node]; 41 | _annotations.erase(node); 42 | return value; 43 | } 44 | 45 | protected: 46 | std::map _annotations; 47 | }; 48 | 49 | } // namespace tree 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeVisitor.h" 7 | 8 | antlr4::tree::ParseTreeVisitor::~ParseTreeVisitor() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeWalker.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | #include "ParserRuleContext.h" 8 | #include "tree/ParseTreeListener.h" 9 | #include "support/CPPUtils.h" 10 | 11 | #include "tree/IterativeParseTreeWalker.h" 12 | #include "tree/ParseTreeWalker.h" 13 | 14 | using namespace antlr4::tree; 15 | using namespace antlrcpp; 16 | 17 | static IterativeParseTreeWalker defaultWalker; 18 | ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker; 19 | 20 | ParseTreeWalker::~ParseTreeWalker() { 21 | } 22 | 23 | void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const { 24 | if (is(t)) { 25 | listener->visitErrorNode(dynamic_cast(t)); 26 | return; 27 | } else if (is(t)) { 28 | listener->visitTerminal(dynamic_cast(t)); 29 | return; 30 | } 31 | 32 | enterRule(listener, t); 33 | for (auto &child : t->children) { 34 | walk(listener, child); 35 | } 36 | exitRule(listener, t); 37 | } 38 | 39 | void ParseTreeWalker::enterRule(ParseTreeListener *listener, ParseTree *r) const { 40 | ParserRuleContext *ctx = dynamic_cast(r); 41 | listener->enterEveryRule(ctx); 42 | ctx->enterRule(listener); 43 | } 44 | 45 | void ParseTreeWalker::exitRule(ParseTreeListener *listener, ParseTree *r) const { 46 | ParserRuleContext *ctx = dynamic_cast(r); 47 | ctx->exitRule(listener); 48 | listener->exitEveryRule(ctx); 49 | } 50 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeWalker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ParseTreeWalker { 14 | public: 15 | static ParseTreeWalker &DEFAULT; 16 | 17 | virtual ~ParseTreeWalker(); 18 | 19 | virtual void walk(ParseTreeListener *listener, ParseTree *t) const; 20 | 21 | protected: 22 | /// The discovery of a rule node, involves sending two events: the generic 23 | /// and a 24 | /// -specific event. First we trigger the generic and then 25 | /// the rule specific. We do them in reverse order upon finishing the node. 26 | virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const; 27 | virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const; 28 | }; 29 | 30 | } // namespace tree 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/TerminalNode.h" 7 | 8 | antlr4::tree::TerminalNode::~TerminalNode() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ParseTree.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNode : public ParseTree { 14 | public: 15 | ~TerminalNode() override; 16 | 17 | virtual Token* getSymbol() = 0; 18 | 19 | /** Set the parent for this leaf node. 20 | * 21 | * Technically, this is not backward compatible as it changes 22 | * the interface but no one was able to create custom 23 | * TerminalNodes anyway so I'm adding as it improves internal 24 | * code quality. 25 | * 26 | * @since 4.7 27 | */ 28 | virtual void setParent(RuleContext *parent) = 0; 29 | }; 30 | 31 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "Token.h" 8 | #include "RuleContext.h" 9 | #include "tree/ParseTreeVisitor.h" 10 | 11 | #include "tree/TerminalNodeImpl.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | 16 | TerminalNodeImpl::TerminalNodeImpl(Token *symbol_) : symbol(symbol_) { 17 | } 18 | 19 | Token* TerminalNodeImpl::getSymbol() { 20 | return symbol; 21 | } 22 | 23 | void TerminalNodeImpl::setParent(RuleContext *parent_) { 24 | this->parent = parent_; 25 | } 26 | 27 | misc::Interval TerminalNodeImpl::getSourceInterval() { 28 | if (symbol == nullptr) { 29 | return misc::Interval::INVALID; 30 | } 31 | 32 | size_t tokenIndex = symbol->getTokenIndex(); 33 | return misc::Interval(tokenIndex, tokenIndex); 34 | } 35 | 36 | antlrcpp::Any TerminalNodeImpl::accept(ParseTreeVisitor *visitor) { 37 | return visitor->visitTerminal(this); 38 | } 39 | 40 | std::string TerminalNodeImpl::getText() { 41 | return symbol->getText(); 42 | } 43 | 44 | std::string TerminalNodeImpl::toStringTree(Parser * /*parser*/, bool /*pretty*/) { 45 | return toString(); 46 | } 47 | 48 | std::string TerminalNodeImpl::toString() { 49 | if (symbol->getType() == Token::EOF) { 50 | return ""; 51 | } 52 | return symbol->getText(); 53 | } 54 | 55 | std::string TerminalNodeImpl::toStringTree(bool /*pretty*/) { 56 | return toString(); 57 | } 58 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNodeImpl : public virtual TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | TerminalNodeImpl(Token *symbol); 18 | 19 | virtual Token* getSymbol() override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 24 | 25 | virtual std::string getText() override; 26 | virtual std::string toStringTree(Parser *parser, bool pretty = false) override; 27 | virtual std::string toString() override; 28 | virtual std::string toStringTree(bool pretty = false) override; 29 | 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/Chunk.h" 7 | 8 | antlr4::tree::pattern::Chunk::~Chunk() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/Chunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// A chunk is either a token tag, a rule tag, or a span of literal text within a 16 | /// tree pattern. 17 | ///

18 | /// The method returns a list of 19 | /// chunks in preparation for creating a token stream by 20 | /// . From there, we get a parse 21 | /// tree from with . These 22 | /// chunks are converted to , , or the 23 | /// regular tokens of the text surrounding the tags. 24 | ///

25 | class ANTLR4CPP_PUBLIC Chunk { 26 | public: 27 | Chunk() = default; 28 | Chunk(Chunk const&) = default; 29 | virtual ~Chunk(); 30 | 31 | Chunk& operator=(Chunk const&) = default; 32 | 33 | /// This method returns a text representation of the tag chunk. Labeled tags 34 | /// are returned in the form {@code label:tag}, and unlabeled tags are 35 | /// returned as just the tag name. 36 | virtual std::string toString() { 37 | std::string str; 38 | return str; 39 | } 40 | }; 41 | 42 | } // namespace pattern 43 | } // namespace tree 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/ParseTreePattern.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/pattern/ParseTreePatternMatcher.h" 8 | #include "tree/pattern/ParseTreeMatch.h" 9 | 10 | #include "tree/xpath/XPath.h" 11 | #include "tree/xpath/XPathElement.h" 12 | 13 | #include "tree/pattern/ParseTreePattern.h" 14 | 15 | using namespace antlr4::tree; 16 | using namespace antlr4::tree::pattern; 17 | 18 | using namespace antlrcpp; 19 | 20 | ParseTreePattern::ParseTreePattern(ParseTreePatternMatcher *matcher, const std::string &pattern, int patternRuleIndex_, 21 | ParseTree *patternTree) 22 | : patternRuleIndex(patternRuleIndex_), _pattern(pattern), _patternTree(patternTree), _matcher(matcher) { 23 | } 24 | 25 | ParseTreePattern::~ParseTreePattern() { 26 | } 27 | 28 | ParseTreeMatch ParseTreePattern::match(ParseTree *tree) { 29 | return _matcher->match(tree, *this); 30 | } 31 | 32 | bool ParseTreePattern::matches(ParseTree *tree) { 33 | return _matcher->match(tree, *this).succeeded(); 34 | } 35 | 36 | std::vector ParseTreePattern::findAll(ParseTree *tree, const std::string &xpath) { 37 | xpath::XPath finder(_matcher->getParser(), xpath); 38 | std::vector subtrees = finder.evaluate(tree); 39 | std::vector matches; 40 | for (auto t : subtrees) { 41 | ParseTreeMatch aMatch = match(t); 42 | if (aMatch.succeeded()) { 43 | matches.push_back(aMatch); 44 | } 45 | } 46 | return matches; 47 | } 48 | 49 | 50 | ParseTreePatternMatcher *ParseTreePattern::getMatcher() const { 51 | return _matcher; 52 | } 53 | 54 | std::string ParseTreePattern::getPattern() const { 55 | return _pattern; 56 | } 57 | 58 | int ParseTreePattern::getPatternRuleIndex() const { 59 | return patternRuleIndex; 60 | } 61 | 62 | ParseTree* ParseTreePattern::getPatternTree() const { 63 | return _patternTree; 64 | } 65 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/RuleTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/RuleTagToken.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | RuleTagToken::RuleTagToken(const std::string &/*ruleName*/, int _bypassTokenType) : bypassTokenType(_bypassTokenType) { 13 | } 14 | 15 | RuleTagToken::RuleTagToken(const std::string &ruleName, size_t bypassTokenType, const std::string &label) 16 | : ruleName(ruleName), bypassTokenType(bypassTokenType), label(label) { 17 | if (ruleName.empty()) { 18 | throw IllegalArgumentException("ruleName cannot be null or empty."); 19 | } 20 | 21 | } 22 | 23 | std::string RuleTagToken::getRuleName() const { 24 | return ruleName; 25 | } 26 | 27 | std::string RuleTagToken::getLabel() const { 28 | return label; 29 | } 30 | 31 | size_t RuleTagToken::getChannel() const { 32 | return DEFAULT_CHANNEL; 33 | } 34 | 35 | std::string RuleTagToken::getText() const { 36 | if (label != "") { 37 | return std::string("<") + label + std::string(":") + ruleName + std::string(">"); 38 | } 39 | 40 | return std::string("<") + ruleName + std::string(">"); 41 | } 42 | 43 | size_t RuleTagToken::getType() const { 44 | return bypassTokenType; 45 | } 46 | 47 | size_t RuleTagToken::getLine() const { 48 | return 0; 49 | } 50 | 51 | size_t RuleTagToken::getCharPositionInLine() const { 52 | return INVALID_INDEX; 53 | } 54 | 55 | size_t RuleTagToken::getTokenIndex() const { 56 | return INVALID_INDEX; 57 | } 58 | 59 | size_t RuleTagToken::getStartIndex() const { 60 | return INVALID_INDEX; 61 | } 62 | 63 | size_t RuleTagToken::getStopIndex() const { 64 | return INVALID_INDEX; 65 | } 66 | 67 | antlr4::TokenSource *RuleTagToken::getTokenSource() const { 68 | return nullptr; 69 | } 70 | 71 | antlr4::CharStream *RuleTagToken::getInputStream() const { 72 | return nullptr; 73 | } 74 | 75 | std::string RuleTagToken::toString() const { 76 | return ruleName + ":" + std::to_string(bypassTokenType); 77 | } 78 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TagChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TagChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TagChunk::TagChunk(const std::string &tag) : TagChunk("", tag) { 13 | } 14 | 15 | TagChunk::TagChunk(const std::string &label, const std::string &tag) : _tag(tag), _label(label) { 16 | if (tag.empty()) { 17 | throw IllegalArgumentException("tag cannot be null or empty"); 18 | } 19 | 20 | } 21 | 22 | TagChunk::~TagChunk() { 23 | } 24 | 25 | std::string TagChunk::getTag() { 26 | return _tag; 27 | } 28 | 29 | std::string TagChunk::getLabel() { 30 | return _label; 31 | } 32 | 33 | std::string TagChunk::toString() { 34 | if (!_label.empty()) { 35 | return _label + ":" + _tag; 36 | } 37 | 38 | return _tag; 39 | } 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TextChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TextChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TextChunk::TextChunk(const std::string &text) : text(text) { 13 | if (text == "") { 14 | throw IllegalArgumentException("text cannot be nul"); 15 | } 16 | 17 | } 18 | 19 | TextChunk::~TextChunk() { 20 | } 21 | 22 | std::string TextChunk::getText() { 23 | return text; 24 | } 25 | 26 | std::string TextChunk::toString() { 27 | return std::string("'") + text + std::string("'"); 28 | } 29 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TextChunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Chunk.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// Represents a span of raw text (concrete syntax) between tags in a tree 16 | /// pattern string. 17 | /// 18 | class ANTLR4CPP_PUBLIC TextChunk : public Chunk { 19 | private: 20 | /// 21 | /// This is the backing field for . 22 | /// 23 | const std::string text; 24 | 25 | /// 26 | /// Constructs a new instance of with the specified text. 27 | /// 28 | /// The text of this chunk. 29 | /// if {@code text} is {@code null}. 30 | public: 31 | TextChunk(const std::string &text); 32 | virtual ~TextChunk(); 33 | 34 | /// 35 | /// Gets the raw text of this chunk. 36 | /// 37 | /// The text of the chunk. 38 | std::string getText(); 39 | 40 | /// 41 | /// {@inheritDoc} 42 | ///

43 | /// The implementation for returns the result of 44 | /// in single quotes. 45 | ///

46 | virtual std::string toString() override; 47 | }; 48 | 49 | } // namespace pattern 50 | } // namespace tree 51 | } // namespace antlr4 52 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TokenTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/TokenTagToken.h" 7 | 8 | using namespace antlr4::tree::pattern; 9 | 10 | TokenTagToken::TokenTagToken(const std::string &/*tokenName*/, int type) 11 | : CommonToken(type), tokenName(""), label("") { 12 | } 13 | 14 | TokenTagToken::TokenTagToken(const std::string &tokenName, int type, const std::string &label) 15 | : CommonToken(type), tokenName(tokenName), label(label) { 16 | } 17 | 18 | std::string TokenTagToken::getTokenName() const { 19 | return tokenName; 20 | } 21 | 22 | std::string TokenTagToken::getLabel() const { 23 | return label; 24 | } 25 | 26 | std::string TokenTagToken::getText() const { 27 | if (!label.empty()) { 28 | return "<" + label + ":" + tokenName + ">"; 29 | } 30 | 31 | return "<" + tokenName + ">"; 32 | } 33 | 34 | std::string TokenTagToken::toString() const { 35 | return tokenName + ":" + std::to_string(_type); 36 | } 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/CPPUtils.h" 7 | 8 | #include "XPathElement.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::xpath; 12 | 13 | XPathElement::XPathElement(const std::string &nodeName) { 14 | _nodeName = nodeName; 15 | } 16 | 17 | XPathElement::~XPathElement() { 18 | } 19 | 20 | std::vector XPathElement::evaluate(ParseTree * /*t*/) { 21 | return {}; 22 | } 23 | 24 | std::string XPathElement::toString() const { 25 | std::string inv = _invert ? "!" : ""; 26 | return antlrcpp::toString(*this) + "[" + inv + _nodeName + "]"; 27 | } 28 | 29 | void XPathElement::setInvert(bool value) { 30 | _invert = value; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | class ParseTree; 13 | 14 | namespace xpath { 15 | 16 | class ANTLR4CPP_PUBLIC XPathElement { 17 | public: 18 | /// Construct element like {@code /ID} or {@code ID} or {@code /*} etc... 19 | /// op is null if just node 20 | XPathElement(const std::string &nodeName); 21 | XPathElement(XPathElement const&) = default; 22 | virtual ~XPathElement(); 23 | 24 | XPathElement& operator=(XPathElement const&) = default; 25 | 26 | /// Given tree rooted at {@code t} return all nodes matched by this path 27 | /// element. 28 | virtual std::vector evaluate(ParseTree *t); 29 | virtual std::string toString() const; 30 | 31 | void setInvert(bool value); 32 | 33 | protected: 34 | std::string _nodeName; 35 | bool _invert = false; 36 | }; 37 | 38 | } // namespace xpath 39 | } // namespace tree 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar XPathLexer; 2 | 3 | tokens { TOKEN_REF, RULE_REF } 4 | 5 | /* 6 | path : separator? word (separator word)* EOF ; 7 | 8 | separator 9 | : '/' '!' 10 | | '//' '!' 11 | | '/' 12 | | '//' 13 | ; 14 | 15 | word: TOKEN_REF 16 | | RULE_REF 17 | | STRING 18 | | '*' 19 | ; 20 | */ 21 | 22 | ANYWHERE : '//' ; 23 | ROOT : '/' ; 24 | WILDCARD : '*' ; 25 | BANG : '!' ; 26 | 27 | ID : NameStartChar NameChar* 28 | { 29 | if (isupper(getText()[0])) 30 | setType(TOKEN_REF); 31 | else 32 | setType(RULE_REF); 33 | } 34 | ; 35 | 36 | fragment 37 | NameChar : NameStartChar 38 | | '0'..'9' 39 | | '_' 40 | | '\u00B7' 41 | | '\u0300'..'\u036F' 42 | | '\u203F'..'\u2040' 43 | ; 44 | 45 | fragment 46 | NameStartChar 47 | : 'A'..'Z' | 'a'..'z' 48 | | '\u00C0'..'\u00D6' 49 | | '\u00D8'..'\u00F6' 50 | | '\u00F8'..'\u02FF' 51 | | '\u0370'..'\u037D' 52 | | '\u037F'..'\u1FFF' 53 | | '\u200C'..'\u200D' 54 | | '\u2070'..'\u218F' 55 | | '\u2C00'..'\u2FEF' 56 | | '\u3001'..'\uD7FF' 57 | | '\uF900'..'\uFDCF' 58 | | '\uFDF0'..'\uFFFF' // implicitly includes ['\u10000-'\uEFFFF] 59 | ; 60 | 61 | STRING : '\'' .*? '\''; 62 | 63 | //WS : [ \t\r\n]+ -> skip ; 64 | 65 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "antlr4-runtime.h" 5 | 6 | 7 | 8 | 9 | class XPathLexer : public antlr4::Lexer { 10 | public: 11 | enum { 12 | TOKEN_REF = 1, RULE_REF = 2, ANYWHERE = 3, ROOT = 4, WILDCARD = 5, BANG = 6, 13 | ID = 7, STRING = 8 14 | }; 15 | 16 | XPathLexer(antlr4::CharStream *input); 17 | ~XPathLexer(); 18 | 19 | virtual std::string getGrammarFileName() const override; 20 | virtual const std::vector& getRuleNames() const override; 21 | 22 | virtual const std::vector& getChannelNames() const override; 23 | virtual const std::vector& getModeNames() const override; 24 | virtual const std::vector& getTokenNames() const override; // deprecated, use vocabulary instead 25 | virtual antlr4::dfa::Vocabulary& getVocabulary() const override; 26 | 27 | virtual const std::vector getSerializedATN() const override; 28 | virtual const antlr4::atn::ATN& getATN() const override; 29 | 30 | virtual void action(antlr4::RuleContext *context, size_t ruleIndex, size_t actionIndex) override; 31 | private: 32 | static std::vector _decisionToDFA; 33 | static antlr4::atn::PredictionContextCache _sharedContextCache; 34 | static std::vector _ruleNames; 35 | static std::vector _tokenNames; 36 | static std::vector _channelNames; 37 | static std::vector _modeNames; 38 | 39 | static std::vector _literalNames; 40 | static std::vector _symbolicNames; 41 | static antlr4::dfa::Vocabulary _vocabulary; 42 | static antlr4::atn::ATN _atn; 43 | static std::vector _serializedATN; 44 | 45 | 46 | // Individual action functions triggered by action() above. 47 | void IDAction(antlr4::RuleContext *context, size_t actionIndex); 48 | 49 | // Individual semantic predicate functions triggered by sempred() above. 50 | 51 | struct Initializer { 52 | Initializer(); 53 | }; 54 | static Initializer _init; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexer.tokens: -------------------------------------------------------------------------------- 1 | TOKEN_REF=1 2 | RULE_REF=2 3 | ANYWHERE=3 4 | ROOT=4 5 | WILDCARD=5 6 | BANG=6 7 | ID=7 8 | STRING=8 9 | '//'=3 10 | '/'=4 11 | '*'=5 12 | '!'=6 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexerErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPathLexerErrorListener.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::tree::xpath; 10 | 11 | void XPathLexerErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 12 | size_t /*line*/, size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexerErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathLexerErrorListener : public BaseErrorListener { 15 | public: 16 | virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 17 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; 18 | }; 19 | 20 | } // namespace xpath 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "tree/xpath/XPathRuleAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleAnywhereElement::XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllRuleNodes(t, _ruleIndex); 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | /// Either {@code ID} at start of path or {@code ...//ID} in middle of path. 15 | class ANTLR4CPP_PUBLIC XPathRuleAnywhereElement : public XPathElement { 16 | public: 17 | XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex); 18 | 19 | virtual std::vector evaluate(ParseTree *t) override; 20 | 21 | protected: 22 | int _ruleIndex = 0; 23 | }; 24 | 25 | } // namespace xpath 26 | } // namespace tree 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathRuleElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleElement::evaluate(ParseTree *t) { 19 | // return all children of t that match nodeName 20 | std::vector nodes; 21 | for (auto c : t->children) { 22 | if (antlrcpp::is(c)) { 23 | ParserRuleContext *ctx = dynamic_cast(c); 24 | if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) { 25 | nodes.push_back(ctx); 26 | } 27 | } 28 | } 29 | return nodes; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathRuleElement : public XPathElement { 15 | public: 16 | XPathRuleElement(const std::string &ruleName, size_t ruleIndex); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _ruleIndex = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathTokenAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathTokenAnywhereElement::XPathTokenAnywhereElement(const std::string &tokenName, int tokenType) : XPathElement(tokenName) { 15 | this->tokenType = tokenType; 16 | } 17 | 18 | std::vector XPathTokenAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllTokenNodes(t, tokenType); 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenAnywhereElement : public XPathElement { 15 | protected: 16 | int tokenType = 0; 17 | public: 18 | XPathTokenAnywhereElement(const std::string &tokenName, int tokenType); 19 | 20 | virtual std::vector evaluate(ParseTree *t) override; 21 | }; 22 | 23 | } // namespace xpath 24 | } // namespace tree 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | #include "support/CPPUtils.h" 9 | #include "Token.h" 10 | 11 | #include "XPathTokenElement.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | using namespace antlr4::tree::xpath; 16 | 17 | XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) { 18 | _tokenType = tokenType; 19 | } 20 | 21 | std::vector XPathTokenElement::evaluate(ParseTree *t) { 22 | // return all children of t that match nodeName 23 | std::vector nodes; 24 | for (auto c : t->children) { 25 | if (antlrcpp::is(c)) { 26 | TerminalNode *tnode = dynamic_cast(c); 27 | if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) { 28 | nodes.push_back(tnode); 29 | } 30 | } 31 | } 32 | return nodes; 33 | } 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenElement : public XPathElement { 15 | public: 16 | XPathTokenElement(const std::string &tokenName, size_t tokenType); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _tokenType = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardAnywhereElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardAnywhereElement::XPathWildcardAnywhereElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardAnywhereElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | return Trees::getDescendants(t); 23 | } 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardAnywhereElement : public XPathElement { 15 | public: 16 | XPathWildcardAnywhereElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardElement::XPathWildcardElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | 23 | return t->children; 24 | } 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardElement : public XPathElement { 15 | public: 16 | XPathWildcardElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | --------------------------------------------------------------------------------