// Public Methods 

        public static IValue Visit(IValue src)
        {


            if (src.GetType() == typeof(StaticMemberAccessExpression))
            {
                var xx = src as StaticMemberAccessExpression;
                var fieldInfo = xx.Expression.DotnetType.GetField(xx.MemberName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (fieldInfo != null)
                {
                    throw new NotSupportedException();
                    // return Visit(new ClassFieldAccessExpression(fieldInfo));
                }
                var propertyInfo = xx.Expression.DotnetType.GetProperty(xx.MemberName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (propertyInfo != null)
                    return Visit(new CsharpInstancePropertyAccessExpression(propertyInfo, null));
                return src;
            }
            if (src.GetType() == typeof(InstanceMemberAccessExpression))
            {
                var xx = src as InstanceMemberAccessExpression;
                var t = xx.Expression.ValueType;
                var fieldInfo = t.GetField(xx.MemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (fieldInfo != null)
                    return Visit(new InstanceFieldAccessExpression(fieldInfo, xx.Expression));

                var propertyInfo = t.GetProperty(xx.MemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (propertyInfo != null)
                    return Visit(new CsharpInstancePropertyAccessExpression(propertyInfo, xx.Expression));
                return src;
            }

            if (src.GetType() == typeof(MemberAccessExpression))
            {
                var xx = src as MemberAccessExpression;
                if (xx.Expression is TypeValue)
                {
                    var yy = xx.Expression as TypeValue;
                    var tmp = new StaticMemberAccessExpression(xx.MemberName, new LangType(yy.DotnetType));
                    return Visit(tmp);

                }
                /*
                if (xx.Expression is LangType)
                {
                    var yy = xx.Expression as LangType;
                    var tmp = new StaticMemberAccessExpression(xx.MemberName, yy);
                    return Visit(tmp);
                } */
            }
            if (src is UnknownIdentifierValue)
            {

            }
            return src;
            throw new NotSupportedException();
        }
Esempio n. 2
0
        protected override IPhpValue VisitStaticMemberAccessExpression(StaticMemberAccessExpression src)
        {
            var yy  = src.Expression.DotnetType;
            var mem = yy.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).ToArray().Where(i => i.Name == src.MemberName).ToArray();

            if (mem.Length == 1)
            {
                var g = mem[0];
                if (g is FieldInfo)
                {
                    return(ConvertValueToPredefined(((FieldInfo)g).GetValue(null)));
                }
            }
            throw new NotSupportedException();
        }
        // Public Methods 

        public static IValue Visit(IValue src)
        {
            if (src.GetType() == typeof(StaticMemberAccessExpression))
            {
                var xx        = src as StaticMemberAccessExpression;
                var fieldInfo = xx.Expression.DotnetType.GetField(xx.MemberName,
                                                                  BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (fieldInfo != null)
                {
                    throw new NotSupportedException();
                }
                var propertyInfo = xx.Expression.DotnetType.GetProperty(xx.MemberName,
                                                                        BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (propertyInfo != null)
                {
                    return(Visit(new CsharpInstancePropertyAccessExpression(propertyInfo, null)));
                }
                return(src);
            }

            if (src.GetType() == typeof(InstanceMemberAccessExpression))
            {
                var xx        = src as InstanceMemberAccessExpression;
                var t         = xx.Expression.ValueType;
                var fieldInfo = t.GetField(xx.MemberName,
                                           BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (fieldInfo != null)
                {
                    return(Visit(new InstanceFieldAccessExpression(fieldInfo, xx.Expression)));
                }

                var propertyInfo = t.GetProperty(xx.MemberName,
                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (propertyInfo != null)
                {
                    return(Visit(new CsharpInstancePropertyAccessExpression(propertyInfo, xx.Expression)));
                }
                return(src);
            }

            if (src.GetType() == typeof(MemberAccessExpression))
            {
                var xx = src as MemberAccessExpression;
                if (xx.Expression is TypeValue)
                {
                    var yy  = xx.Expression as TypeValue;
                    var tmp = new StaticMemberAccessExpression(xx.MemberName, new LangType(yy.DotnetType));
                    return(Visit(tmp));
                }

                /*
                 * if (xx.Expression is LangType)
                 * {
                 *  var yy = xx.Expression as LangType;
                 *  var tmp = new StaticMemberAccessExpression(xx.MemberName, yy);
                 *  return Visit(tmp);
                 * } */
            }

            if (src is UnknownIdentifierValue)
            {
            }

            return(src);

            throw new NotSupportedException();
        }
Esempio n. 4
0
        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);
        }