public EventAccessorDefinition(MemberFlags flags, string name, AstNode children, TokenPosition position) : base(children, position) { SetName(name); this.flags = flags; this.eventVariable = null; this.function = null; this.selfLocal = null; this.valueLocal = null; }
public EventDefinition(MemberFlags flags, Expression eventType, string name, AstNode accessors, TokenPosition position) : base(position) { SetName(name); this.flags = flags; this.eventType = eventType; this.eventVariable = null; this.accessors = accessors; this.delegateType = null; }
public void SetEvent(EventVariable eventVariable) { this.eventVariable = eventVariable; }
private void CreateSimplifiedEventFunction(AstNode node, EventVariable eventVariable, FunctionType functionType, bool isAdd) { // Create the function name. string functionName = (isAdd ? "add_" : "remove_") + eventVariable.GetName(); // Create the function. Function function; if(functionType.GetArgumentCount() > 1) function = new Method(functionName, eventVariable.GetFlags(), currentContainer); else function = new Function(functionName, eventVariable.GetFlags(), currentContainer); // Set the function type. function.SetFunctionType(functionType); // Set the function position. function.Position = node.GetPosition(); // Store the function in the event. if(isAdd) eventVariable.AddModifier = function; else eventVariable.RemoveModifier = function; // Store the function in his container. if(currentContainer.IsStructure() || currentContainer.IsClass() || currentContainer.IsInterface()) { Structure building = (Structure)currentContainer; building.AddFunction(functionName, function); } else if(currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddMember(function); } else { Error(node, "an event cannot be declared here."); } }
public override AstNode Visit(EventDefinition node) { // Find an existing event. ScopeMember oldEvent = currentContainer.FindMember(node.GetName()); if(oldEvent != null) { if(oldEvent.IsEvent()) Error(node, "trying to redefine an event."); else Error(node, "trying to override something with an event."); } // Visit the type expression. Expression typeExpr = node.GetEventType(); typeExpr.Accept(this); // Extract the meta type. IChelaType eventType = typeExpr.GetNodeType(); eventType = ExtractActualType(typeExpr, eventType); // Make sure the event type is a class.. if(!eventType.IsClass()) Error(typeExpr, "event types must be delegates."); // Store the delegate type. Class delegateType = (Class)eventType; node.SetDelegateType(delegateType); // The actual event type is a reference. eventType = ReferenceType.Create(eventType); // Create the event. EventVariable eventVariable = new EventVariable(node.GetName(), node.GetFlags(), eventType, currentContainer); // Add it into the current scope. if(currentContainer.IsNamespace()) { Namespace space = (Namespace) currentContainer; space.AddMember(eventVariable); } else if(currentContainer.IsClass() || currentContainer.IsStructure() || currentContainer.IsInterface()) { Structure building = (Structure) currentContainer; building.AddEvent(eventVariable); } else Error(node, "an event cannot be defined here."); // Set the event variable in the accessors. node.SetEvent(eventVariable); if(node.AddAccessor != null) node.AddAccessor.SetEvent(eventVariable); if(node.RemoveAccessor != null) node.RemoveAccessor.SetEvent(eventVariable); // Visit the accessors. VisitList(node.GetAccessors()); // Declare simplified event. if(node.GetAccessors() == null) DeclareSimplifiedEvent(node); return node; }