protected override Expression VisitConstant(ConstantExpression node) { var site = node.Value as CallSite; if (site != null) { return(RewriteCallSite(site)); } var exprSerializable = node.Value as IExpressionSerializable; if (exprSerializable != null) { return(Visit(exprSerializable.CreateExpression())); } var symbols = node.Value as SymbolId[]; if (symbols != null) { return(Expression.NewArrayInit( typeof(SymbolId), new ReadOnlyCollection <Expression>( symbols.Map(s => SymbolConstantExpression.GetExpression(s)) ) )); } return(base.VisitConstant(node)); }
protected override Expression VisitExtension(Expression node) { if (node.NodeType == ExpressionType.Dynamic) { // the node was dynamic, the dynamic nodes were removed, // we now need to rewrite any call sites. return(VisitDynamic((DynamicExpression)node)); } SymbolConstantExpression symbol = node as SymbolConstantExpression; if (symbol != null) { SymbolId id = symbol.Value; if (id == SymbolId.Empty) { return(Expression.Field(null, typeof(SymbolId).GetField("Empty"))); } FieldBuilderExpression value; if (!_indirectSymbolIds.TryGetValue(id, out value)) { // create field, emit fix-up... if (_symbolGen == null) { _symbolGen = new TypeGen(_typeGen.AssemblyGen, ((ModuleBuilder)_typeGen.TypeBuilder.Module).DefineType("Symbols" + Interlocked.Increment(ref _id))); #if SILVERLIGHT _finishedSymbolType = new StrongBox <Type>(); #endif } FieldBuilder field = _symbolGen.AddStaticField(typeof(SymbolId), FieldAttributes.Public, SymbolTable.IdToString(id)); ILGen init = _symbolGen.TypeInitializer; if (_indirectSymbolIds.Count == 0) { init.EmitType(_symbolGen.TypeBuilder); init.EmitCall(typeof(ScriptingRuntimeHelpers), "InitializeSymbols"); } #if SILVERLIGHT _indirectSymbolIds[id] = value = new FieldBuilderExpression(field, _finishedSymbolType); #else _indirectSymbolIds[id] = value = new FieldBuilderExpression(field); #endif } Debug.Assert(value != null); return(value); } return(Visit(node.Reduce())); }