Example #1
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);
        }
Example #2
0
        //private IValue internalVisit_BoolBinaryExpression(BinaryExpressionSyntax node, string _operator)
        //{
        //    var symbolInfo = state.Context.RoslynModel.GetSymbolInfo(node);
        //    if (symbolInfo.Symbol != null)
        //        throw new NotSupportedException();

        //    var tmp = internalVisit_BinaryExpressionSyntax(node, _operator);
        //    var l = Visit(node.Left);
        //    var r = Visit(node.Right);
        //    var g = new BinaryOperatorExpression(l, r, _operator, typeof(bool), null);
        //    return g;
        //}
        private IValue InternalVisitTextIdentifier(string identifier)
        {
            var t = context.MatchTypes(identifier, 0);

            if (t.Length > 2)
            {
                throw new NotSupportedException();
            }
            if (t.Length == 1)
            {
                return(new TypeValue(t.First()));
            }

            var lv = context.Arguments.Where(i => i.Name == identifier).ToArray();

            if (lv.Length == 1)
            {
                return(new ArgumentExpression(lv.First().Name, lv.First().Type));
            }

            var lv1 = context.LocalVariables.Where(i => i.Name == identifier).ToArray();

            if (lv1.Length == 1)
            {
                return(new LocalVariableExpression(lv1.First().Name, lv1.First().Type));
            }

            if ((object)_state.CurrentType != null)
            {
                var fi = TypesUtil.ListFields(_state.CurrentType, identifier);
                if (fi.Length == 1)
                {
                    var tmp = fi[0];
                    if (tmp.IsStatic)
                    {
                        throw new NotSupportedException();
                    }
                    var a = new InstanceFieldAccessExpression(fi[0], new ThisExpression(_state.CurrentType));
                    return(Simplify(a));
                }
            }

            {
                var aaaa = _state.Context.MatchTypes(identifier, 0);
                if (aaaa.Length == 1)
                {
                    return(new TypeValue(aaaa[0]));
                }
            }
            return(new UnknownIdentifierValue(identifier, new IValue[0]));
        }
Example #3
0
        protected override IValue VisitIdentifierName(IdentifierNameSyntax node)
        {
            // var tt = context.Roslyn_GetNamedTypeSymbols(null);

            var sInfo  = ModelExtensions.GetSymbolInfo(context.RoslynModel, node);
            var tInfo2 = context.RoslynModel.GetTypeInfo2(node);
            var tInfo  = tInfo2.TypeInfo;
            //var sInfo = sInfo2.ty
            Type type = tInfo.Type == null ? null : context.Roslyn_ResolveType(tInfo.Type);

            switch (sInfo.Symbol.Kind)
            {
            case SymbolKind.Local:
                //var symbolLocal = info.Symbol as CSharp.SourceLocalSymbol;
                IValue tmp = new LocalVariableExpression(sInfo.Symbol.Name, new LangType(type));
                tmp = ImplicitConvert(tmp, tInfo2);
                return(Simplify(tmp));

            case SymbolKind.NamedType:
                // var a = sInfo.Symbol.ToDisplayString();
                var b = sInfo.Symbol.OriginalDefinition as INamedTypeSymbol;
                if (b != null)
                {
                    var c = context.Roslyn_ResolveType(b);
                    return(new TypeValue(c));
                }
                throw new NotSupportedException();

            case SymbolKind.Parameter:
#warning 'Formalnie to nie jest zmienna lokalna !!';
                tmp = new LocalVariableExpression(sInfo.Symbol.Name, new LangType(type));
                return(Simplify(tmp));

            case SymbolKind.Field:
                var ax = context.Roslyn_ResolveField(sInfo.Symbol as IFieldSymbol);
                if (ax.IsStatic)
                {
                    // throw new NotSupportedException();

                    var fieldSymbol = sInfo.Symbol as IFieldSymbol;
                    tmp = new ClassFieldAccessExpression(ax, fieldSymbol != null && fieldSymbol.IsConst);
                    return(Simplify(tmp));
                }
                tmp = new InstanceFieldAccessExpression(ax, new ThisExpression(state.CurrentType));     // niczego nie wiem o kontekście -> domyślam się, że this
                return(Simplify(tmp));

            case SymbolKind.Method:
            {
                var methodBaseInfo = context.Roslyn_ResolveMethod(sInfo.Symbol as IMethodSymbol);
                var methodInfo     = methodBaseInfo as MethodInfo;
                if (methodInfo == null)
                {
                    throw new NotSupportedException();
                }
                var result = new MethodExpression(methodInfo);
                return(Simplify(result));
            }

            case SymbolKind.Property:
            {
                var pi           = context.Roslyn_ResolveProperty(sInfo.Symbol as IPropertySymbol);
                var targetObject = new ThisExpression(state.CurrentType);
                var result       = new CsharpInstancePropertyAccessExpression(pi, targetObject);
                return(result);
            }

            default:
                throw new NotSupportedException();
            }
            //throw new NotSupportedException();
            //var m = info.Symbol;
            //var info2 = context.RoslynModel.AnalyzeDataFlow(node);
            ////var info3 = context.RoslynModel.GetDeclaredSymbol(node);
            //var mg = context.RoslynModel.GetMemberGroup(node);

            //string identifier = node.Identifier.ValueText.Trim();
            // return InternalVisitTextIdentifier(identifier);
        }