import { IKeyObjectValue, IDocValue, IKeyValue } from '../../type'; import { VRuleType } from './enum'; import { ParserUtils } from './visitorUtils'; import { IError, IPosition } from "./type"; export default class ParserVisitor extends ParserUtils { private _loopCount; private _errors; private _variables; private _functions; private _methods; private _types; private _enums; private _currentBlockVars; private _currentFuncParams; private _isNeedCalc; private _blockCount; private _isInFunc; private _onlyStatementsCount; private _blockRanges; private _overloadsFuncs; private _hasMemberIndex; private _comments; private _isInLocalScop; private _hasDrawFunc; private _hasCreateOrderFunc; private _scriptType?; private _description; private _endExport; private _isEndExpr?; private _inputVarName?; private _hasRequest?; private _strategyFuncName?; private _strategyVarName?; private _isSeriesCondition?; private _importLibs; private _isMember?; private _memberErrors; constructor(props: IKeyObjectValue, comments: IKeyObjectValue[]); get overloadsFuncs(): IKeyValue[]; get errors(): IError[]; get userEnums(): Map; get userTypes(): Map; get userFunctions(): Map; get userVariables(): Map; get userMethods(): Map; get hasUseDrawFunc(): boolean; get hasUseCreateOrderFunc(): boolean; get scriptType(): string | undefined; get description(): string; get exportPositions(): any; get endExport(): IKeyObjectValue; get imports(): Map; visitProgram: (ctx: IKeyObjectValue) => Promise; visitGlobalStmt: (ctx: IKeyObjectValue) => Promise; visitBlockStmt: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitStmt: (ctx: IKeyObjectValue) => any; visitSimpleStmt: (ctx: IKeyObjectValue) => any; visitFlowStmt: (ctx: IKeyObjectValue) => { ruleType: VRuleType; value: any; }; visitBlock: (ctx: IKeyObjectValue) => any; visitBlockLine: (ctx: IKeyObjectValue) => any[] | null; private _memberErrorsHandle; visitVariableDeclarationStmt: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitDeclareAssign: (ctx: IKeyObjectValue) => IKeyObjectValue; visitAgainAssign: (ctx: IKeyObjectValue) => { ruleType: VRuleType; name: IKeyObjectValue; operator: string; type: string; value: IKeyObjectValue; } | null; private _verifyGloablVar; visitBlockSequence: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitExpressionSequence: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitExpressionBlockSequence: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitVarBlockStmt: (ctx: IKeyObjectValue) => IKeyObjectValue | { ruleType: VRuleType; name: IKeyObjectValue; operator: string; type: string; value: IKeyObjectValue; }; /** * 解析注释 * * 该方法用于解析给定行号和类型条件下的注释文本,生成一个对象,对象的键是注释的类型,值是与该类型注释相关的描述文本。 * 支持解析多行注释,并可以区分不同级别的注释键和子项。 * * @param line 当前行号,用于筛选注释行 * @param types 需要解析的注释类型数组 * @param supportMulLines 同一类型是否支持多行注释的解析,默认为false * @returns 返回一个对象,包含解析后的注释信息 */ private _commentsParser; visitVarSingle: (ctx: IKeyObjectValue) => IKeyObjectValue; visitVarMultiple: (ctx: IKeyObjectValue) => { ruleType: VRuleType; names: string[]; posList: IPosition[]; }; visitBlockExpression: (ctx: IKeyObjectValue) => any; visitParenthesizedExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; type: any; types: any; ctx: IKeyObjectValue; exprs: any; }; visitAdditiveExpression: (ctx: IKeyObjectValue) => IKeyObjectValue; visitRelationalExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; operator: string; ctx: IKeyObjectValue; type: string; exprs: IKeyObjectValue[]; }; visitEqualityExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; operator: string; ctx: IKeyObjectValue; type: string; exprs: IKeyObjectValue[]; }; visitTernaryExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; type: string; ctx: IKeyObjectValue; exprs: IKeyObjectValue[]; }; visitNameExpression: (ctx: IKeyObjectValue) => any; visitLiteralExpression: (ctx: IKeyObjectValue) => any; visitUnaryExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; operator: any; type: any; ctx: IKeyObjectValue; exprs: IKeyObjectValue[]; }; visitNotExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; ctx: IKeyObjectValue; type: string; exprs: IKeyObjectValue[]; }; visitMemberIndexExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; type: any; ctx: IKeyObjectValue; isInFunc: boolean; exprs: IKeyObjectValue[]; }; visitMethodStmt: (ctx: IKeyObjectValue) => { ruleType: VRuleType; types: any; ctx: IKeyObjectValue; type: any; exprs: any[]; }; private _inputFuncTitleVerify; visitMethodExpression: (ctx: IKeyObjectValue) => any; visitLogicalAndExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; type: string; operator: string; ctx: IKeyObjectValue; exprs: IKeyObjectValue[]; }; visitLogicalOrExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; operator: string; ctx: IKeyObjectValue; type: string; exprs: IKeyObjectValue[]; }; visitMultiplicativeExpression: (ctx: IKeyObjectValue) => { ruleType: VRuleType; operator: string; ctx: IKeyObjectValue; type: string; exprs: IKeyObjectValue[]; }; visitBrackethesized: (ctx: IKeyObjectValue) => { ruleType: VRuleType; ctx: IKeyObjectValue; exprs: any; }; visitArguments: (ctx: IKeyObjectValue) => IKeyObjectValue; visitArgument: (ctx: IKeyObjectValue) => any; visitIfStatement: (ctx: IKeyObjectValue) => IKeyObjectValue; private _verifyIf; visitForToStatement: (ctx: IKeyObjectValue) => IKeyObjectValue; private _forToNameHandle; private _verifyForTo; visitLiteral: (ctx: IKeyObjectValue) => { ruleType: VRuleType; ctx: IKeyObjectValue; type: string; value: any; }; visitMethodElement: (ctx: IKeyObjectValue) => { name: any; type: any; args: any; expr: any; }; visitMethodName: (ctx: IKeyObjectValue) => (string | IKeyObjectValue[])[]; visitArrowFunction: (ctx: IKeyObjectValue) => IKeyObjectValue; visitArrowFunctionParameters: (ctx: IKeyObjectValue) => IKeyObjectValue[]; visitFormalParameterList: (ctx: IKeyObjectValue) => IKeyObjectValue[]; private _exportArgsTypeVerify; visitAssignmentOperator: (ctx: IKeyObjectValue) => any; visitIdentifier: (ctx: IKeyObjectValue) => any; visitName: (ctx: IKeyObjectValue) => IKeyObjectValue; private _nameHandle; private _memberIndexVerify; private _setFuncParams; private _pushBlockRanges; private _againAssignHandle; private _getBuildVar; private _verifyName; private _nameCheck; private _inBlock; private _errorHandle; private _boolTypeJudge; private _calcTypeJudge; private _typeJudge; /** * 判断数组中的对象类型是否一致,支持根据操作符和指定的类型集合对类型进行动态判断和调整。 * @param arr - 用于判断类型的对象数组 * @param children - 与 arr 对应的子对象数组,用于在类型不匹配时进行错误处理 * @param operator - 当前操作符,影响类型判断的逻辑 * @param supportTypes - 支持的类型数组,会根据操作符动态调整 * @returns 返回一个数组,包含每个对象根据判断逻辑确定的类型 */ private _sameTypeJudge; private _getUserVar; private _repeatVarJudge; private _judgeVarBuildIn; private _updateUserVar; private _variablesHandle; private _checkVarMultiple; private _addVarToMap; private _setVariablesMap; private _varTypeJudge; private _getAllowTypes; private _setFunc; private _verifyFuncRepeat; private _getMethodTypes; private _globalFuncVerify; private _hasMemberIndexVerify; /** * 根据函数参数和上下文获取内置返回类型。 * @param res 函数匹配结果数组,包含返回类型、语法和参数信息。 * @param args 函数调用时的实际参数对象。 * @param name 函数名,用于错误处理时的提示。 * @param ctx 函数调用的上下文对象。 * @param fArg 函数的首个特定参数,可选,用于某些特殊场景下的类型检查。 * @param type 预期的返回类型数组,可选,用于进一步筛选返回类型。 * @returns 返回可能的返回类型数组。可能是一个确定的类型数组,或者在类型不匹配时返回[VType.UNDETERMINED]。 */ private _getBuildInReturnTypes; /** * 根据提供的函数列表和当前参数,获取匹配的函数返回类型。 * @param funcs 函数列表,每个函数包含参数信息、返回类型、函数名和this类型。 * @param currentArgs 当前调用的参数对象。 * @param ctx 当前上下文对象,包含代码位置等信息。 * @param fArg 可选,指定的首个参数,用于重载判断。 * @returns 匹配的函数返回类型,如果没有匹配则返回'UNDETERMINED'。 */ private _overloadsFuncGetTypes; private _funcArgsAddOriginName; /** * 检查函数参数数量和类型是否符合预期 * @param args 提供的参数对象,包含实际参数和参数对象 * @param originArgs 预期的参数列表 * @param name 函数名称 * @param ctx 上下文信息,用于错误定位 * @param firstArg 第一个参数的对象,用于某些特定的参数检查 * @returns 返回一个对象,包含错误信息和警告信息 */ private _overloadsCheckArgs; /** * 检查传入参数的数量和类型是否符合预期 * @param args 包含所有参数的对象 * @param originArgs 原始参数列表 * @param name 函数或方法的名称 * @param ctx 上下文信息,用于错误处理 * @param returnType 函数预期的返回类型 * @param firstArg 第一个参数的详细信息,可选 * @returns 返回一个对象,包含是否有错误和可能的类型信息 */ private _checkArgs; /** * 校验参数是否符合给定的规则。 * @param arg 需要校验的参数对象,包含参数的规则类型、表达式和名称等信息。 * @param originArg 原始参数对象,包含参数的允许类型ID、显示类型和名称等信息。 * @param name 参数的当前名称。 * @param firstArg 如果是重载函数,第一个参数的对象。 * @param ctx 参数的上下文信息,可选。 * @param isOverloads 是否为重载函数的标志,可选。 * @returns 如果参数校验通过,返回true;否则返回false。 */ private _checkArg; /** * 将键值对对象转换为检查对象,用于验证参数类型是否匹配 * @param arg 要检查的键值对对象,包含规则类型和表达式数组 * @param originArg 原始参数对象,包含参数名和允许的类型ID * @param needType 需要检查的类型数组 * @param name 操作符名称 * @param type 当前参数的类型 * @returns 如果类型不匹配,返回错误提示字符串;否则,返回undefined */ private _tupleToCheck; /** * 获取块的返回类型 * @param block 可以是单个对象或者对象数组,代表一个代码块 * @returns 返回一个类型数组,表示该代码块可能的返回类型 */ private _getBlockReturnTypes; }