示例#1
0
 public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpInstancePropertyAccessExpression src)
 {
     if (src.Member.DeclaringType == typeof(MySQLi))
     {
         var n = src.Member.Name;
         if (n == "WasConnectionError" || n == "WasSuccessfulConnection")
         {
             // according to error http://www.php.net/manual/en/mysqli.construct.php
             IPhpValue getError;
             if (ctx.PhpVersion <= PhpVersions.PHP_5_3_0)
             {
                 getError = new PhpMethodCallExpression("mysqli_connect_error");
             }
             else
             {
                 getError = new PhpInstanceFieldAccessExpression("connect_error", ctx.TranslateValue(src.TargetObject), null);
             }
             var checkEmpty = new PhpMethodCallExpression("empty", getError);
             if (n == "WasSuccessfulConnection")
             {
                 return(checkEmpty);
             }
             var checkNotEmpty = new PhpUnaryOperatorExpression(checkEmpty, "!");
             return(checkNotEmpty);
         }
     }
     return(null);
 }
示例#2
0
        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);
        }
示例#3
0
 protected virtual T VisitPhpInstanceFieldAccessExpression(PhpInstanceFieldAccessExpression node)
 {
     if (ThrowNotImplementedException)
     {
         throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPhpInstanceFieldAccessExpression", this.GetType().FullName));
     }
     return(default(T));
 }
示例#4
0
 public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpInstancePropertyAccessExpression src)
 {
     if (src.Member.DeclaringType == typeof(TimeSpan))
     {
         var to = ctx.TranslateValue(src.TargetObject);
         if (src.Member.Name == "TotalDays")
         {
             var aa = new PhpInstanceFieldAccessExpression("days", to, null);
             return(aa);
         }
         throw new NotSupportedException();
     }
     return(null);
 }
示例#5
0
 protected override IPhpValue VisitPhpInstanceFieldAccessExpression(PhpInstanceFieldAccessExpression node)
 {
     return(node);
 }
示例#6
0
        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);
                }
            }
        }