private string TransformLocal(LocalSymbol localSymbol) { int depth = 0; AnonymousMethodSymbol parentMethod = localSymbol.Parent as AnonymousMethodSymbol; if (parentMethod != null) { // If an anonymous method contains a local variable with the // same name as a variable in the containing method, they will // conflict at runtime, i.e. the value in the inner method // will override the value of the outer method when it is run. // Note that right now we aren't seeing if there is actually a conflict. // We're always qualifying the inner variable with a depth prefix. // REVIEW: Should we try to optimize when we qualify? depth = parentMethod.Depth; } string transformedName = GenerateName(_count, depth); _count++; return(transformedName); }
public virtual void AddAnonymousMethod(AnonymousMethodSymbol anonymousMethod) { Debug.Assert(anonymousMethod != null); if (_anonymousMethods == null) { _anonymousMethods = new List<AnonymousMethodSymbol>(); } _anonymousMethods.Add(anonymousMethod); }
public virtual void AddAnonymousMethod(AnonymousMethodSymbol anonymousMethod) { Debug.Assert(anonymousMethod != null); if (_anonymousMethods == null) { _anonymousMethods = new List <AnonymousMethodSymbol>(); } _anonymousMethods.Add(anonymousMethod); }
public SymbolImplementation BuildMethod(AnonymousMethodSymbol methodSymbol) { BlockStatementNode methodBody = ((AnonymousMethodNode)methodSymbol.ParseContext).Implementation; return BuildImplementation(methodSymbol.StackContext, methodSymbol, methodBody, /* addAllParameters */ true); }
public override void AddAnonymousMethod(AnonymousMethodSymbol anonymousMethod) { _containingMember.AddAnonymousMethod(anonymousMethod); }
public static void GenerateScript(ScriptGenerator generator, AnonymousMethodSymbol symbol) { GenerateImplementationScript(generator, symbol, symbol.Implementation); }
private Expression ProcessAnonymousMethodNode(AnonymousMethodNode node) { TypeSymbol voidType = _symbolSet.ResolveIntrinsicType(IntrinsicType.Void); Debug.Assert(voidType != null); bool createStaticDelegate = (_memberContext.Visibility & MemberVisibility.Static) != 0; AnonymousMethodSymbol methodSymbol = new AnonymousMethodSymbol(_memberContext, _symbolTable, voidType, createStaticDelegate); methodSymbol.SetParseContext(node); if ((node.Parameters != null) && (node.Parameters.Count != 0)) { foreach (ParameterNode parameterNode in node.Parameters) { TypeSymbol parameterType = _symbolSet.ResolveType(parameterNode.Type, _symbolTable, _symbolContext); Debug.Assert(parameterType != null); ParameterSymbol paramSymbol = new ParameterSymbol(parameterNode.Name, methodSymbol, parameterType, ParameterMode.In); if (paramSymbol != null) { paramSymbol.SetParseContext(parameterNode); methodSymbol.AddParameter(paramSymbol); } } } ImplementationBuilder implBuilder = new ImplementationBuilder(_options, _errorHandler); SymbolImplementation implementation = implBuilder.BuildMethod(methodSymbol); methodSymbol.AddImplementation(implementation); if ((createStaticDelegate == false) && (implementation.RequiresThisContext == false)) { methodSymbol.SetVisibility(methodSymbol.Visibility | MemberVisibility.Static); createStaticDelegate = true; } Expression objectExpression; if (createStaticDelegate) { TypeSymbol objectType = _symbolSet.ResolveIntrinsicType(IntrinsicType.Object); Debug.Assert(objectType != null); objectExpression = new LiteralExpression(objectType, null); } else { objectExpression = new ThisExpression(_classContext, /* explicitReference */ true); } return new DelegateExpression(objectExpression, methodSymbol); }