Esempio n. 1
0
        internal void VisitConstant(ConstantExpression node)
        {
            string v;
            var    r = LocalTypeHelper.ConstantValue2String(node.Value, out v);

            if (!r)
            {
                if (node.Type.IsGenericType && node.Type.BaseType == typeof(ISymbol))
                {
                    v = "request";
                }
            }
            Out(v);
        }
Esempio n. 2
0
        internal void VisitMember(MemberExpression node)
        {
            string s;
            object value;

            if (_externalObjects.ContainsKey(node))
            {
                var r = LocalTypeHelper.ConstantValue2String(_externalObjects[node], out s);
                if (r)
                {
                    Out(s);
                    return;
                }
            }
            else if (GetValue(node, out value))
            {
                _externalObjects[node] = value;
                var r = LocalTypeHelper.ConstantValue2String(_externalObjects[node], out s);
                if (r)
                {
                    Out(s);
                    return;
                }
                if (node.Type.IsSymbol() || node.Type.IsSymbols())
                {
                    if (value != null)
                    {
                        Visit((value as ISymbol).Expression);
                    }
                    else
                    {
                        Out(node.Member.Name);
                    }
                    return;
                }
            }

            if (node.Expression != null)
            {
                Visit(node.Expression);
                Out(".");
            }
            Out(node.Member.Name);
        }
Esempio n. 3
0
        public override object VisitMemberAccess(MemberExpression node, int nil)
        {
            object value;

            if (ExternalObjects.ContainsKey(node))
            {
                return(null);
            }
            if (GetValue(node, out value))
            {
                ExternalObjects[node] = value;
                if (node.Type.IsInheritedTypeOf(typeof(Service)))
                {
                    // TODO: multiple instances of the same type
                    var t1 = Services.Keys.Select(k => k.Type.ToString()).Any(p => p == node.Type.ToString());
                    if (!t1)
                    {
                        Services.Add(node, value as Service);
                    }
                    return(null);
                }
                if (node.Type.IsInheritedTypeOf(typeof(Expression)))
                {
                    return(null);
                }
                if (node.Type.IsSymbol() || node.Type.IsSymbols())
                {
                    if (value == null)
                    {
                        Trace.Assert(TempSymbolsByAlias.ContainsKey(node.Member.Name), "a symbol must be first defined (e.g., using Alias operator)");
                    }
                    else
                    {
                        var kexpr = (value as ISymbol).Expression;
                        if (kexpr.NodeType == ExpressionType.Constant)
                        {
                            return(null);
                        }
                        if (!TempSymbols.ContainsKey(kexpr))
                        {
                            TempSymbols.Add(kexpr, node.Member.Name);
                        }
                    }

                    return(null);
                }

                string s;
                var    r = LocalTypeHelper.ConstantValue2String(ExternalObjects[node], out s);
                if (r)
                {
                    return(null);
                }
                throw new Exception("cannot resolve external constant expression '" + node + "'");
            }

            if (node.Expression != null)
            {
                Visit(node.Expression, nil);
            }
            return(null);
        }