public override void LeaveEvent(Event node) { if (IsInterfaceMember(node)) node.Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Abstract; else if (!node.IsVisibilitySet) node.Modifiers |= Context.Parameters.DefaultEventVisibility; LeaveMember(node); }
public override void OnEvent(AST.Event node) { DomRegion region = GetRegion(node); DefaultEvent e = new DefaultEvent(node.Name, CreateReturnType(node.Type), GetModifier(node), region, region, OuterClass); ConvertAttributes(node, e); OuterClass.Events.Add(e); }
public override void LeaveEvent(Event node) { if (!node.IsVisibilitySet) { node.Modifiers |= TypeMemberModifiers.Public; } if (IsInterface(node.DeclaringType)) { node.Modifiers |= TypeMemberModifiers.Abstract; } LeaveMember(node); }
public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) { B.Event m = new B.Event(GetLexicalInfo(eventDeclaration)); m.Name = eventDeclaration.Name; m.Modifiers = ConvertModifier(eventDeclaration, B.TypeMemberModifiers.Private); ConvertAttributes(eventDeclaration.Attributes, m.Attributes); if (currentType != null) { currentType.Members.Add(m); } m.EndSourceLocation = GetLocation(eventDeclaration.EndLocation); m.Type = ConvertTypeReference(eventDeclaration.TypeReference); if (eventDeclaration.InterfaceImplementations.Count > 0) { AddError(eventDeclaration, "Explicit interface implementation is not supported for events."); } if (eventDeclaration.Parameters.Count > 0) { AddError(eventDeclaration, "Events with parameters are not supported."); } if (eventDeclaration.HasAddRegion) { m.Add = new B.Method(GetLexicalInfo(eventDeclaration.AddRegion)); ConvertAttributes(eventDeclaration.AddRegion.Attributes, m.Add.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.AddRegion, m.Visibility); m.Add.Body = ConvertMethodBlock(eventDeclaration.AddRegion.Block); } if (eventDeclaration.HasRemoveRegion) { m.Remove = new B.Method(GetLexicalInfo(eventDeclaration.RemoveRegion)); ConvertAttributes(eventDeclaration.RemoveRegion.Attributes, m.Remove.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.RemoveRegion, m.Visibility); m.Remove.Body = ConvertMethodBlock(eventDeclaration.RemoveRegion.Block); } if (eventDeclaration.HasRaiseRegion) { m.Raise = new B.Method(GetLexicalInfo(eventDeclaration.RaiseRegion)); ConvertAttributes(eventDeclaration.RaiseRegion.Attributes, m.Raise.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.RaiseRegion, m.Visibility); m.Raise.Body = ConvertMethodBlock(eventDeclaration.RaiseRegion.Block); } return(m); }
Method CreateInterfaceEventMethod(Event node, string prefix) { Method method = CodeBuilder.CreateMethod(prefix + node.Name, TypeSystemServices.VoidType, TypeMemberModifiers.Public | TypeMemberModifiers.Virtual | TypeMemberModifiers.Abstract); method.Parameters.Add( CodeBuilder.CreateParameterDeclaration( CodeBuilder.GetFirstParameterIndex(node), "handler", GetType(node.Type))); return method; }
void BindEvent(Event node) { EnsureEntityFor(node); IType type = GetType(node.Type); IType declaringType = GetType(node.DeclaringType); bool typeIsCallable = type is ICallableType; if (!typeIsCallable) { Errors.Add( CompilerErrorFactory.EventTypeIsNotCallable(node.Type, type.ToString())); } if (declaringType.IsInterface) { BindInterfaceEvent(node); } else { BindClassEvent(node, type, typeIsCallable); } }
public override void LeaveEvent(Event node) { CheckName(node,node.Name); }
protected void event_declaration( TypeMemberCollection container ) //throws RecognitionException, TokenStreamException { IToken t = null; IToken id = null; Event e = null; TypeReference tr = null; try { // for error handling t = LT(1); match(EVENT); id = LT(1); match(ID); match(AS); tr=type_reference(); eos(); if (0==inputState.guessing) { e = new Event(ToLexicalInfo(id), id.getText(), tr); e.Modifiers = _modifiers; AddAttributes(e.Attributes); container.Add(e); } docstring(e); } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "event_declaration"); recover(ex,tokenSet_55_); } else { throw ex; } } }
public override void OnEvent(Event node) { _emitter.EmitEventAttributes(node); }
void DefineEvent(TypeBuilder typeBuilder, Event node) { EventBuilder builder = typeBuilder.DefineEvent(node.Name, EventAttributes.None, GetSystemType(node.Type)); //MethodAttributes attribs = GetPropertyMethodAttributes(node); MethodAttributes baseAttributes = MethodAttributes.SpecialName; builder.SetAddOnMethod(DefineMethod(typeBuilder, node.Add, baseAttributes|GetMethodAttributes(node.Add))); builder.SetRemoveOnMethod(DefineMethod(typeBuilder, node.Remove, baseAttributes|GetMethodAttributes(node.Remove))); if (null != node.Raise) { builder.SetRaiseMethod(DefineMethod(typeBuilder, node.Raise, baseAttributes|GetMethodAttributes(node.Raise))); } SetBuilder(node, builder); }
public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) { B.Event m = new B.Event(GetLexicalInfo(eventDeclaration)); m.Name = eventDeclaration.Name; m.Modifiers = ConvertModifier(eventDeclaration, B.TypeMemberModifiers.Private); ConvertAttributes(eventDeclaration.Attributes, m.Attributes); if (currentType != null) currentType.Members.Add(m); m.EndSourceLocation = GetLocation(eventDeclaration.EndLocation); m.Type = ConvertTypeReference(eventDeclaration.TypeReference); if (eventDeclaration.InterfaceImplementations.Count > 0) { AddError(eventDeclaration, "Explicit interface implementation is not supported for events."); } if (eventDeclaration.Parameters.Count > 0) { AddError(eventDeclaration, "Events with parameters are not supported."); } if (eventDeclaration.HasAddRegion) { m.Add = new B.Method(GetLexicalInfo(eventDeclaration.AddRegion)); ConvertAttributes(eventDeclaration.AddRegion.Attributes, m.Add.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.AddRegion, m.Visibility); m.Add.Body = ConvertMethodBlock(eventDeclaration.AddRegion.Block); } if (eventDeclaration.HasRemoveRegion) { m.Remove = new B.Method(GetLexicalInfo(eventDeclaration.RemoveRegion)); ConvertAttributes(eventDeclaration.RemoveRegion.Attributes, m.Remove.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.RemoveRegion, m.Visibility); m.Remove.Body = ConvertMethodBlock(eventDeclaration.RemoveRegion.Block); } if (eventDeclaration.HasRaiseRegion) { m.Raise = new B.Method(GetLexicalInfo(eventDeclaration.RaiseRegion)); ConvertAttributes(eventDeclaration.RaiseRegion.Attributes, m.Raise.Attributes); m.Modifiers = ConvertModifier(eventDeclaration.RaiseRegion, m.Visibility); m.Raise.Body = ConvertMethodBlock(eventDeclaration.RaiseRegion.Block); } return m; }
public override void LeaveEvent(Event node) { LeaveMember(node); }
public override void OnEvent(Event node) { _events.Add(node); }
void DefineEvent(TypeBuilder typeBuilder, Event node) { var builder = typeBuilder.DefineEvent(node.Name, EventAttributes.None, GetSystemType(node.Type)); builder.SetAddOnMethod(DefineEventMethod(typeBuilder, node.Add)); builder.SetRemoveOnMethod(DefineEventMethod(typeBuilder, node.Remove)); if (node.Raise != null) builder.SetRaiseMethod(DefineEventMethod(typeBuilder, node.Raise)); SetBuilder(node, builder); }
void EmitEventAttributes(Event node, TypeCreator knownTypes) { EventBuilder builder = (EventBuilder)GetBuilder(node); EmitAttributes(node, builder.SetCustomAttribute, knownTypes); }
public override void OnEvent(Event node) { _emitter.EmitEventAttributes(node, this._knownTypes); }
public InternalEvent(TypeSystemServices tagManager, Event event_) { _event = event_; }
Method CreateInterfaceEventRemoveMethod(Event node) { return CreateInterfaceEventMethod(node, "remove_"); }
private void BindClassEvent(Event node, IType type, bool typeIsCallable) { Field backingField = CodeBuilder.CreateField("___" + node.Name, type); if (node.IsTransient) { backingField.Modifiers |= TypeMemberModifiers.Transient; } if (node.IsStatic) { backingField.Modifiers |= TypeMemberModifiers.Static; } node.DeclaringType.Members.Add(backingField); ((InternalEvent)node.Entity).BackingField = (InternalField)backingField.Entity; if (null == node.Add) { node.Add = CreateEventAddMethod(node, backingField); } else { Visit(node.Add); } if (null == node.Remove) { node.Remove = CreateEventRemoveMethod(node, backingField); } else { Visit(node.Remove); } if (null == node.Raise) { if (typeIsCallable) { node.Raise = CreateEventRaiseMethod(node, backingField); } } else { Visit(node.Raise); } }
private void BindInterfaceEvent(Event node) { if (null == node.Add) node.Add = CreateInterfaceEventAddMethod(node); if (null == node.Remove) node.Remove = CreateInterfaceEventRemoveMethod(node); }
void BindEvent(Event node) { if (null == node.Entity) { node.Entity = new InternalEvent(TypeSystemServices, node); } IType type = GetType(node.Type); IType declaringType = GetType(node.DeclaringType); bool typeIsCallable = type is ICallableType; if (!typeIsCallable) { Errors.Add( CompilerErrorFactory.EventTypeIsNotCallable(node.Type, type.ToString())); } if (declaringType.IsInterface) { BindInterfaceEvent(node); } else { BindClassEvent(node, type, typeIsCallable); } }
private void BindInterfaceEvent(Event node) { // TODO: Add checks to ensure Add/Remove/Raise are // null before doing this. node.Add = CreateInterfaceEventAddMethod(node); node.Remove = CreateInterfaceEventRemoveMethod(node); }
public override void OnEvent(Event node) { if (node.LexicalInfo != null) results.MapParsedNode(new MappedTypeMemberDefinition(results, node)); base.OnEvent(node); }
Method CreateEventMethod(Event node, string prefix) { Method method = CodeBuilder.CreateMethod(prefix + node.Name, TypeSystemServices.VoidType, node.Modifiers); method.Parameters.Add( CodeBuilder.CreateParameterDeclaration( CodeBuilder.GetFirstParameterIndex(node), "handler", GetType(node.Type))); return method; }
void EmitEventAttributes(Event node) { EventBuilder builder = (EventBuilder)GetBuilder(node); EmitAttributes(node, builder.SetCustomAttribute); }
Method CreateEventRaiseMethod(Event node, Field backingField) { TypeMemberModifiers modifiers = RemoveAccessiblityModifiers(node.Modifiers); if (node.IsPrivate) { modifiers |= TypeMemberModifiers.Private; } else { modifiers |= TypeMemberModifiers.Protected | TypeMemberModifiers.Internal; } Method method = CodeBuilder.CreateMethod("raise_" + node.Name, TypeSystemServices.VoidType, modifiers); ICallableType type = GetEntity(node.Type) as ICallableType; if (null != type) { int index = CodeBuilder.GetFirstParameterIndex(node); foreach (IParameter parameter in type.GetSignature().Parameters) { method.Parameters.Add( CodeBuilder.CreateParameterDeclaration( index, parameter.Name, parameter.Type, parameter.IsByRef)); ++index; } } MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateReference(backingField), NameResolutionService.ResolveMethod(GetType(backingField.Type), "Invoke")); foreach (ParameterDeclaration parameter in method.Parameters) { mie.Arguments.Add(CodeBuilder.CreateReference(parameter)); } IfStatement stmt = new IfStatement(node.LexicalInfo); stmt.Condition = CodeBuilder.CreateNotNullTest( CodeBuilder.CreateReference(backingField)); stmt.TrueBlock = new Block(); stmt.TrueBlock.Add(mie); method.Body.Add(stmt); return method; }
override public object Clone() { Event clone = new Event(); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone(); clone._modifiers = _modifiers; clone._name = _name; if (null != _attributes) { clone._attributes = _attributes.Clone() as AttributeCollection; clone._attributes.InitializeParent(clone); } if (null != _add) { clone._add = _add.Clone() as Method; clone._add.InitializeParent(clone); } if (null != _remove) { clone._remove = _remove.Clone() as Method; clone._remove.InitializeParent(clone); } if (null != _raise) { clone._raise = _raise.Clone() as Method; clone._raise.InitializeParent(clone); } if (null != _type) { clone._type = _type.Clone() as TypeReference; clone._type.InitializeParent(clone); } return clone; }
Method CreateEventRemoveMethod(Event node, Field backingField) { Method m = CreateEventMethod(node, "remove_"); m.Body.Add( CodeBuilder.CreateAssignment( CodeBuilder.CreateReference(backingField), CodeBuilder.CreateMethodInvocation( Delegate_Remove, CodeBuilder.CreateReference(backingField), CodeBuilder.CreateReference(m.Parameters[0])))); return m; }
public override void LeaveEvent(Event node) { MakeStaticIfNeeded(node); CantBeMarkedPartial(node); CheckModifierCombination(node); }
Method CreateInterfaceEventAddMethod(Event node) { return CreateInterfaceEventMethod(node, "add_"); }
public Event CreateAbstractEvent(LexicalInfo lexicalInfo, IEvent baseEvent) { Event ev = new Event(lexicalInfo); ev.Name = baseEvent.Name; ev.Type = CreateTypeReference(baseEvent.Type); ev.Add = CreateAbstractMethod(lexicalInfo, baseEvent.GetAddMethod()); ev.Remove = CreateAbstractMethod(lexicalInfo, baseEvent.GetRemoveMethod()); EnsureEntityFor(ev); return ev; }
public override void OnEvent(Event node) { AddMember(node); }