private void Tranlate_MethodOrProperty(PyCodeModule pyModule, [CanBeNull] PyClassDefinition pyClass, MethodInfo info, IStatement body, string overrideName) { _state.Principles.CurrentMethod = info; try { var mti = _state.Principles.GetOrMakeTranslationInfo(info); var pyMethod = new PyClassMethodDefinition(string.IsNullOrEmpty(overrideName) ? mti.ScriptName : overrideName); if (pyClass == null) { pyModule.Methods.Add(pyMethod); pyMethod.Kind = PyMethodKind.OutOfClass; } else { pyClass.Methods.Add(pyMethod); pyMethod.Kind = info.IsStatic ? PyMethodKind.ClassStatic : PyMethodKind.ClassInstance; } if (info.IsPublic) { pyMethod.Visibility = Visibility.Public; } else if (info.IsPrivate) { pyMethod.Visibility = Visibility.Private; } else { pyMethod.Visibility = Visibility.Protected; } { var declaredParameters = info.GetParameters(); foreach (var parameter in declaredParameters) { var pyParameter = new PyMethodArgument { Name = parameter.Name }; pyMethod.Arguments.Add(pyParameter); if (parameter.HasDefaultValue) { pyParameter.DefaultValue = new PyConstValue(parameter.DefaultValue); } } } if (body != null) { pyMethod.Statements.AddRange(TranslateStatement(body)); } } finally { _state.Principles.CurrentMethod = null; } }
private void TranslateConstructor(PyClassDefinition pyClass, ConstructorDeclaration md) { // state.Principles.CurrentMethod = md.Info; try { // MethodTranslationInfo mti = MethodTranslationInfo.FromMethodInfo(md.Info); // state.Principles.CurrentMethod = var pyMethod = new PyClassMethodDefinition("__init__"); pyClass.Methods.Add(pyMethod); if (md.Info.IsPublic) { pyMethod.Visibility = Visibility.Public; } else if (md.Info.IsPrivate) { pyMethod.Visibility = Visibility.Private; } else { pyMethod.Visibility = Visibility.Protected; } pyMethod.Kind = md.Info.IsStatic ? PyMethodKind.ClassStatic : PyMethodKind.ClassInstance; { var declaredParameters = md.Info.GetParameters(); foreach (var parameter in declaredParameters) { var pyParameter = new PyMethodArgument(); pyParameter.Name = parameter.Name; pyMethod.Arguments.Add(pyParameter); if (parameter.HasDefaultValue) { pyParameter.DefaultValue = new PyConstValue(parameter.DefaultValue); } } } if (md.Body != null) { pyMethod.Statements.AddRange(TranslateStatement(md.Body)); } } finally { _state.Principles.CurrentMethod = null; } }
protected override IPyValue VisitLambdaExpression(LambdaExpression src) { var T = new Translator(_state); var a = new PyMethodDefinition(""); a.Statements.AddRange(T.TranslateStatement(src.Body)); foreach (var p in src.Parameters) { var pyParameter = new PyMethodArgument { Name = p.Name }; a.Arguments.Add(pyParameter); } var b = new PyLambdaExpression(a); return(SimplifyPyExpression(b)); }