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);
 }
예제 #2
0
        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);
 }
예제 #5
0
 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;
 }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public override void LeaveEvent(Event node)
 {
     CheckName(node,node.Name);
 }
예제 #8
0
	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;
			}
		}
	}
예제 #9
0
 public override void OnEvent(Event node)
 {
     _emitter.EmitEventAttributes(node);
 }
예제 #10
0
        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;
		}
예제 #12
0
 public override void LeaveEvent(Event node)
 {
     LeaveMember(node);
 }
예제 #13
0
 public override void OnEvent(Event node)
 {
     _events.Add(node);
 }
예제 #14
0
파일: EmitAssembly.cs 프로젝트: hlizard/boo
		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);
		}
예제 #15
0
파일: EmitAssembly.cs 프로젝트: hlizard/boo
		void EmitEventAttributes(Event node, TypeCreator knownTypes)
		{
			EventBuilder builder = (EventBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
예제 #16
0
파일: EmitAssembly.cs 프로젝트: hlizard/boo
			public override void OnEvent(Event node)
			{
				_emitter.EmitEventAttributes(node, this._knownTypes);
			}
예제 #17
0
 public InternalEvent(TypeSystemServices tagManager, Event event_)
 {
     _event = event_;
 }
예제 #18
0
 Method CreateInterfaceEventRemoveMethod(Event node)
 {
     return CreateInterfaceEventMethod(node, "remove_");
 }
예제 #19
0
        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);
            }
        }
예제 #20
0
 private void BindInterfaceEvent(Event node)
 {
     if (null == node.Add)
         node.Add = CreateInterfaceEventAddMethod(node);
     if (null == node.Remove)
         node.Remove = CreateInterfaceEventRemoveMethod(node);
 }
예제 #21
0
        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);
            }
        }
예제 #22
0
 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);
 }
예제 #23
0
 public override void OnEvent(Event node)
 {
     if (node.LexicalInfo != null)
         results.MapParsedNode(new MappedTypeMemberDefinition(results, node));
     base.OnEvent(node);
 }
예제 #24
0
 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;
 }
예제 #25
0
 void EmitEventAttributes(Event node)
 {
     EventBuilder builder = (EventBuilder)GetBuilder(node);
     EmitAttributes(node, builder.SetCustomAttribute);
 }
예제 #26
0
        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;
        }
예제 #27
0
파일: EventImpl.cs 프로젝트: Rfvgyhn/boo
		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;


		}
예제 #28
0
 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;
 }
예제 #29
0
 public override void LeaveEvent(Event node)
 {
     MakeStaticIfNeeded(node);
     CantBeMarkedPartial(node);
     CheckModifierCombination(node);
 }
예제 #30
0
 Method CreateInterfaceEventAddMethod(Event node)
 {
     return CreateInterfaceEventMethod(node, "add_");
 }
예제 #31
0
 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;
 }
예제 #32
0
 public override void OnEvent(Event node)
 {
     AddMember(node);
 }