Exemplo n.º 1
0
 protected virtual T VisitPhpPropertyAccessExpression(PhpPropertyAccessExpression node)
 {
     if (ThrowNotImplementedException)
     {
         throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPhpPropertyAccessExpression", this.GetType().FullName));
     }
     return(default(T));
 }
Exemplo n.º 2
0
 protected override IPhpValue VisitPhpPropertyAccessExpression(PhpPropertyAccessExpression node)
 {
     return(node.Simplify(this));
 }
Exemplo n.º 3
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);
                }
            }
        }