protected override IPhpValue VisitInstanceFieldAccessExpression(InstanceFieldAccessExpression src) { var fti = state.Principles.GetOrMakeTranslationInfo(src.Member); var to = TransValue(src.TargetObject); if (src.Member.DeclaringType.IsDefined(typeof(AsArrayAttribute))) { switch (fti.Destination) { case FieldTranslationDestionations.NormalField: IPhpValue index; if (fti.IsScriptNamePhpEncoded) { index = PhpConstValue.FromPhpValue(fti.ScriptName); } else { index = new PhpConstValue(fti.ScriptName); } var tmp = new PhpArrayAccessExpression(to, index); return(SimplifyPhpExpression(tmp)); case FieldTranslationDestionations.DefinedConst: break; // obsłużę to dalej jak dla zwykłej klasy default: throw new NotSupportedException(); } } var a = new PhpInstanceFieldAccessExpression(fti.ScriptName, to, fti.IncludeModule); return(a); }
protected virtual T VisitPhpArrayAccessExpression(PhpArrayAccessExpression node) { if (ThrowNotImplementedException) { throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPhpArrayAccessExpression", this.GetType().FullName)); } return(default(T)); }
private static IPhpValue _WpPost(CsharpMethodCallExpression src) { if (src.MethodInfo.Name == "PostType") { var a1 = new PhpVariableExpression("$_POST", PhpVariableKind.Global); var a2 = new PhpArrayAccessExpression(a1, new PhpConstValue("post_type")); return(a2); } return(null); throw new NotSupportedException(); }
public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) { var dt = src.MethodInfo.DeclaringType; if (dt.IsGenericType) { dt = dt.GetGenericTypeDefinition(); } if (dt == typeof(Stack <>)) { var fn = src.MethodInfo.ToString(); if (fn == "System.String Peek()") { var to = ctx.TranslateValue(src.TargetObject); var cnt = new PhpMethodCallExpression("count", to); var cnt_1 = new PhpBinaryOperatorExpression("-", cnt, new PhpConstValue(1)); var ar = new PhpArrayAccessExpression(to, cnt_1); return(ar); } return(null); } return(null); }
// Protected Methods protected override IPhpValue VisitPhpArrayAccessExpression(PhpArrayAccessExpression node) { return(node); }
protected override IPhpValue VisitInstancePropertyAccessExpression(CsharpInstancePropertyAccessExpression src) { var pri = PropertyTranslationInfo.FromPropertyInfo(src.Member); var ownerInfo = state.Principles.GetOrMakeTranslationInfo(src.Member.DeclaringType); if (src.TargetObject == null) { throw new NotImplementedException("statyczny"); } var translatedByExternalNodeTranslator = state.Principles.NodeTranslators.Translate(state, src); if (translatedByExternalNodeTranslator != null) { return(SimplifyPhpExpression(translatedByExternalNodeTranslator)); } var phpTargetObject = TransValue(src.TargetObject); if (ownerInfo.IsArray) { var idx = new PhpConstValue(pri.FieldScriptName); var arrayExpr = new PhpArrayAccessExpression(phpTargetObject, idx); return(arrayExpr); } { var propertyInfo = src.Member; var classReplacer = state.FindOneClassReplacer(propertyInfo.DeclaringType); if (classReplacer != null) { var newPropertyInfo = classReplacer.ReplaceBy.GetProperty(src.Member.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (newPropertyInfo == null) { throw new Exception(string.Format("Klasa {0} nie zawiera własności {1}", classReplacer.ReplaceBy, src.Member)); } if (newPropertyInfo.GetIndexParameters().Length > 0) { throw new NotSupportedException("energetic gecko, Property with index"); } propertyInfo = newPropertyInfo; } { var ats = propertyInfo.GetCustomAttribute <DirectCallAttribute>(true); if (ats != null) { if (string.IsNullOrEmpty(ats.Name)) { var tmp = ats.MapArray; if (tmp == null || tmp.Length <= 0) { return(phpTargetObject); } if (tmp.Length > 1 || tmp[0] != DirectCallAttribute.This) { throw new NotSupportedException(string.Format( "Property {1}.{0} has invalid 'Map' parameter in DirectCallAttribute", propertyInfo.Name, propertyInfo.DeclaringType)); } return(phpTargetObject); } switch (ats.MemberToCall) { case ClassMembers.Method: if (ats.Name == "this") { return(phpTargetObject); } var method = new PhpMethodCallExpression(ats.Name); switch (ats.CallType) { case MethodCallStyles.Procedural: method.Arguments.Add(new PhpMethodInvokeValue(phpTargetObject)); return(method); // case MethodCallStyles.: // method.Arguments.Add(new PhpMethodInvokeValue(phpTargetObject)); // return method; // default: // throw new NotSupportedException(); } throw new NotImplementedException(); case ClassMembers.Field: switch (ats.CallType) { case MethodCallStyles.Instance: if (ats.Name == "this") { return(phpTargetObject); } var includeModule = ownerInfo.IncludeModule; var field = new PhpInstanceFieldAccessExpression(ats.Name, phpTargetObject, includeModule); return(field); default: throw new NotSupportedException(); } //var f = new PhpMethodCallExpression(ats.Name); //method.Arguments.Add(new PhpMethodInvokeValue(phpTargetObject)); //return method; default: throw new NotSupportedException(); } } } { var ats = propertyInfo.GetCustomAttribute <UseBinaryExpressionAttribute>(true); if (ats != null) { var left = GetValueForExpression(phpTargetObject, ats.Left); var right = GetValueForExpression(phpTargetObject, ats.Right); var method = new PhpBinaryOperatorExpression(ats.Operator, left, right); return(method); } } { pri = PropertyTranslationInfo.FromPropertyInfo(src.Member); var to = TransValue(src.TargetObject); var a = new PhpPropertyAccessExpression(pri, to); return(a); } } }