コード例 #1
0
        protected override IPhpValue 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 PhpConstValue(TransValue(src.Expression));
            var b   = new PhpConstValue(mmi.ScriptName);
            var o   = new PhpArrayCreateExpression(a, b);

            return(o);
        }
コード例 #2
0
ファイル: IValueVisitor.cs プロジェクト: rajeshwarn/cs2php
        protected override IValue VisitSimpleMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            // var typeInfo = state.Context.RoslynModel.GetTypeInfo(node);
            var typeInfo2 = state.Context.RoslynModel.GetTypeInfo(node.Expression);
            var tt        = state.Context.RoslynModel.GetSymbolInfo(node);

            MemberInfo member = null;

            switch (tt.Symbol.Kind)
            {
            case SymbolKind.Field:
                var fieldSymbol = tt.Symbol as IFieldSymbol;
                var fieldInfo   = context.Roslyn_ResolveField(fieldSymbol);
                if (fieldInfo.IsStatic)
                {
                    return(Simplify(new ClassFieldAccessExpression(fieldInfo, true)));
                }
                var visitedExpression = Visit(node.Expression);
                if (visitedExpression == null)
                {
                    throw new ArgumentNullException("visitedExpression");
                }
                return(Simplify(new InstanceFieldAccessExpression(fieldInfo, visitedExpression)));

            case SymbolKind.Method:
                var sss        = tt.Symbol as IMethodSymbol;
                var methodInfo = context.Roslyn_ResolveMethod(sss);
                member = methodInfo;

                break;

            case SymbolKind.Property:
                var uuu          = tt.Symbol as IPropertySymbol;
                var propertyInfo = context.Roslyn_ResolveProperty(uuu);
                member = propertyInfo;
                break;
            }
            IValue expression;
            var    fullName = _Name(node.Name);


            if (typeInfo2.Type != null)
            {
                ISymbol[] gg;
                if (fullName.IsGeneric)
                {
                    var       arity = fullName.Generics.Length;
                    ISymbol[] gg1   = typeInfo2.Type.GetMembers()
                                      .AsEnumerable()
                                      .OfType <IMethodSymbol>()
                                      .Where(i => i.Name == fullName.BaseName && i.Arity == arity)
                                      .ToArray();
                    gg = gg1;
                }
                else
                {
                    gg = typeInfo2.Type.GetMembers(fullName.GetNonGeneric()).ToArray();
                }
                if (gg.Length == 1)
                {
                    ISymbol ggg = gg.Single();
                    switch (ggg.Kind)
                    {
                    case SymbolKind.Property:
                        var propertySymbol = ggg as IPropertySymbol;
                        if (propertySymbol == null)
                        {
                            throw new Exception("propertySymbol is null");
                        }
                        var pi = context.Roslyn_ResolveProperty(propertySymbol);
                        if (propertySymbol.IsStatic)
                        {
                            var tmp = new ClassPropertyAccessExpression(pi);
                            return(Simplify(tmp));
                        }
                        else
                        {
                            expression = Visit(node.Expression);
                            var tmp = new CsharpInstancePropertyAccessExpression(pi, expression);
                            return(Simplify(tmp));
                        }
                    }
                }
            }
            // throw new NotSupportedException();
            expression = Visit(node.Expression);
            if (expression is UnknownIdentifierValue)
            {
                if (fullName.IsGeneric)
                {
                    throw new NotSupportedException();
                }
                var name = fullName.BaseName;

                var a = ((expression as UnknownIdentifierValue)).Identifier + "." + name;
                var t = context.MatchTypes(a, 0);
                if (t.Length == 1)
                {
                    return(new TypeValue(t[0]));
                }
                return(new UnknownIdentifierValue(a, new IValue[0]));
            }
            if (expression is TypeValue)
            {
                if (fullName.IsGeneric)
                {
                    throw new NotSupportedException();
                }
                var name = fullName.BaseName;
                var tmp  = new StaticMemberAccessExpression(name, new LangType((expression as TypeValue).DotnetType));
                return(Simplify(tmp));
            }
            if (expression is LocalVariableExpression || expression is ConstValue ||
                expression is ClassFieldAccessExpression || expression is InstanceFieldAccessExpression ||
                expression is ElementAccessExpression || expression is ArgumentExpression ||
                expression is CsharpMethodCallExpression || expression is CsharpInstancePropertyAccessExpression ||
                expression is ClassPropertyAccessExpression || expression is ParenthesizedExpression)
            {
                // if (fullName.IsGeneric)
                //     throw new NotSupportedException();
                var name = fullName.BaseName;
                if (member == null)
                {
                    throw new NotSupportedException();
                }
                var tmp = new InstanceMemberAccessExpression(name, expression, member);
                return(Simplify(tmp));
            }



            // ReSharper disable once InvertIf
            if (expression is ThisExpression)
            {
                if (fullName.IsGeneric)
                {
                    throw new NotSupportedException();
                }
                var name = fullName.BaseName;
                if (member == null)
                {
                    throw new NotSupportedException();
                }
                var tmp = new InstanceMemberAccessExpression(name, expression, member);
                return(Simplify(tmp));
            }

            throw new NotImplementedException("*** " + expression.GetType().FullName);
        }