コード例 #1
0
        protected override IPyValue VisitMethodExpression(MethodExpression src)
        {
            if (src.Method.IsStatic)
            {
                var pyClassName =
                    _state.Principles.GetPyType(src.Method.DeclaringType, true, _state.Principles.CurrentType);
                if (pyClassName.IsEmpty)
                {
                    throw new Exception("PyClassName cannot be null");
                }
                pyClassName = pyClassName.MakeAbsolute();
                var className             = new PyConstValue(pyClassName.FullName);
                var methodTranslationInfo = _state.Principles.GetOrMakeTranslationInfo(src.Method);
                if (!src.Method.IsPublic)
                {
                    WriteWarning(string.Format("Using not public method {0}.{1} as expression",
                                               src.Method.DeclaringType, src.Method.Name));
                }
                var methodName    = new PyConstValue(methodTranslationInfo.ScriptName);
                var arrayCreation = new PyArrayCreateExpression(className, methodName);
                return(SimplifyPyExpression(arrayCreation));
            }

            {
                // ryzykuję z this
                var targetObject          = new PyThisExpression();
                var methodTranslationInfo = _state.Principles.GetOrMakeTranslationInfo(src.Method);
                var methodName            = new PyConstValue(methodTranslationInfo.ScriptName);
                var arrayCreation         = new PyArrayCreateExpression(targetObject, methodName);
                return(SimplifyPyExpression(arrayCreation));
            }
        }
コード例 #2
0
 protected virtual T VisitPyArrayCreateExpression(PyArrayCreateExpression node)
 {
     if (ThrowNotImplementedException)
     {
         throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPyArrayCreateExpression", this.GetType().FullName));
     }
     return(default(T));
 }
コード例 #3
0
        protected override IPyValue VisitArrayCreateExpression(ArrayCreateExpression src)
        {
            var a = new PyArrayCreateExpression();

            if (src.Initializers != null && src.Initializers.Any())
            {
                a.Initializers = src.Initializers.Select(TransValue).ToArray();
            }
            return(SimplifyPyExpression(a));
        }
コード例 #4
0
        protected override IPyValue VisitInstanceMemberAccessExpression(InstanceMemberAccessExpression src)
        {
            if (src.Member == null)
            {
                throw new NotSupportedException();
            }
            if (!(src.Member is MethodInfo))
            {
                throw new NotSupportedException();
            }
            var mi = src.Member as MethodInfo;

            if (mi.IsStatic)
            {
                throw new Exception("Metoda nie może być statyczna");
            }
            var mmi = _state.Principles.GetOrMakeTranslationInfo(mi); // MethodTranslationInfo.FromMethodInfo(mi);
            var a   = new PyConstValue(TransValue(src.Expression));
            var b   = new PyConstValue(mmi.ScriptName);
            var o   = new PyArrayCreateExpression(a, b);

            return(o);
        }
コード例 #5
0
        protected override IPyValue VisitCallConstructor(CallConstructor src)
        {
            var tmp = _state.Principles.NodeTranslators.Translate(_state, src);

            if (tmp != null)
            {
                return(SimplifyPyExpression(tmp));
            }

            var r = new PyMethodCallExpression(PyMethodCallExpression.ConstructorMethodName);

            if (src.Info.ReflectedType != src.Info.DeclaringType)
            {
                throw new NotSupportedException();
            }

            // we can use "state.Principles.CurrentType" as third parameter if we prefer "new self()" or "new parent()" contructor calls
            r.SetClassName(
                _state.Principles.GetPyType(src.Info.ReflectedType, true, null),
                _state.Principles.GetOrMakeTranslationInfo(src.Info)
                ); // class name for constructor
            {
                // var a = src.Info.GetCustomAttribute();
            }

            var cti = _state.Principles.GetTi(src.Info.ReflectedType, true);

            if (cti.DontIncludeModuleForClassMembers)
            {
                r.DontIncludeClass = true;
            }
            if (cti.IsArray)
            {
                if (src.Initializers != null && src.Initializers.Any())
                {
                    var ggg = src.Initializers.Select(TransValue).ToArray();
                    var h   = new PyArrayCreateExpression(ggg);
                    return(SimplifyPyExpression(h));
                }
                else
                {
                    var h = new PyArrayCreateExpression();
                    return(SimplifyPyExpression(h));
                }
            }

            {
                // cti = state.Principles.GetTi(src.Info.ReflectedType);
                // if (cti.IsReflected)
                {
                    var replacer = _state.FindOneClassReplacer(src.Info.ReflectedType);
                    if (replacer != null)
                    {
                        var translationMethods = replacer.ReplaceBy
                                                 .GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
                                                 .Where(m => m.IsDefined(typeof(TranslatorAttribute))).ToArray();
                        foreach (var m in translationMethods)
                        {
                            var translated = m.Invoke(null, new object[] { _state, src });
                            if (translated is IPyValue)
                            {
                                return(translated as IPyValue);
                            }
                        }

                        //throw new Exception(string.Format("Klasa {0} nie umie przetłumaczyć konstruktora {1}",replacer.ReplaceBy.FullName, replacer.SourceType.FullName));
                    }
                }
            }
            foreach (var functionArgument in src.Arguments)
            {
                r.Arguments.Add(TransFunctionArgument(functionArgument));
            }
            return(r);
        }