public override object VisitMethodCallExpression([NotNull] DoshikParser.MethodCallExpressionContext context)
        {
            SetWholeExpression(context);
            VisitChildren(context);
            _compilationContext.SetParsingAntlrContext(context);

            var node = new MethodCallExpressionNode(context);

            GetMethodCallData(context.methodCall(), node.MethodCallData);

            Sequence.Sequence.Add(node);

            return(null);
        }
示例#2
0
        private IExpression HandleMethodCallExpressionNode(MethodCallExpressionNode node)
        {
            // Встроенные функции:

            if (node.MethodCallData.Name == "GetThis" && node.MethodCallData.TypeArguments.Count == 1 && node.MethodCallData.Parameters.Count == 0)
            {
                // Если это вызов GetThis<T>() - возвращаем константу this типа T

                var type = node.MethodCallData.TypeArguments[0];

                // UdonBehaviour -> private bool ResolveUdonHeapReference(IUdonHeap heap, uint symbolAddress, UdonBaseHeapReference udonBaseHeapReference)
                if (
                    type != _compilationContext.TypeLibrary.FindTypeByCodeNameString("UnityEngine::GameObject").DataType&&
                    type != _compilationContext.TypeLibrary.FindTypeByCodeNameString("UnityEngine::Transform").DataType&&
                    type != _compilationContext.TypeLibrary.FindTypeByCodeNameString("VRCUdon::UdonBehaviour").DataType
                    )
                {
                    throw _compilationContext.ThrowCompilationError("Type argument for GetThis<T>() must be UnityEngine::GameObject, UnityEngine::Transform, or VRCUdon::UdonBehaviour");
                }

                var result = new ConstantValueExpression();

                result.ValueType = type;

                result.IsThis = true;

                _compilationContext.CompilationUnit.AddConstant(Constant.CreateAsThis(type));

                // Определяем выходное значение
                result.ReturnOutputSlot = new ExpressionSlot(result.ValueType, result);

                return(result);
            }

            // Если не нашло во встроенных, ищем в определенных юзером
            // (ToDo: когда я реализую юзерские функции, возможно надо будет сначала искать в них, а если
            // не нашло то искать во встроенных)

            throw _compilationContext.ThrowCompilationError("user defined method calls are not supported yet");
        }