Beispiel #1
0
        private EventSymbol BuildEvent(EventDeclarationNode eventNode, TypeSymbol typeSymbol) {
            TypeSymbol handlerType = typeSymbol.SymbolSet.ResolveType(eventNode.Type, _symbolTable, typeSymbol);
            Debug.Assert(handlerType != null);

            if (handlerType != null) {
                EventSymbol eventSymbol = new EventSymbol(eventNode.Name, typeSymbol, handlerType);
                BuildMemberDetails(eventSymbol, typeSymbol, eventNode, eventNode.Attributes);

                if (eventNode.IsField) {
                    eventSymbol.SetImplementationState(SymbolImplementationFlags.Generated);
                }
                else {
                    if ((eventNode.Modifiers & Modifiers.Abstract) != 0) {
                        eventSymbol.SetImplementationState(SymbolImplementationFlags.Abstract);
                    }
                    else if ((eventNode.Modifiers & Modifiers.Override) != 0) {
                        eventSymbol.SetImplementationState(SymbolImplementationFlags.Override);
                    }
                }

                return eventSymbol;
            }

            return null;
        }
        public SymbolImplementation BuildEventRemove(EventSymbol eventSymbol)
        {
            AccessorNode removeNode = ((EventDeclarationNode)eventSymbol.ParseContext).Property.GetAccessor;
            BlockStatementNode accessorBody = removeNode.Implementation;

            return BuildImplementation((ISymbolTable)eventSymbol.Parent,
                                       eventSymbol, accessorBody, /* addParameters */ true);
        }
Beispiel #3
0
 public static void GenerateScript(ScriptGenerator generator, EventSymbol symbol, bool add) {
     SymbolImplementation accessorImpl;
     if (add) {
         accessorImpl = symbol.AdderImplementation;
     }
     else {
         accessorImpl = symbol.RemoverImplementation;
     }
     GenerateImplementationScript(generator, symbol, accessorImpl);
 }
Beispiel #4
0
        private static void GenerateEvent(ScriptGenerator generator, string typeName, EventSymbol eventSymbol) {
            ScriptTextWriter writer = generator.Writer;

            ParameterSymbol valueParameter = eventSymbol.Parameters[0];
            if (generator.Options.Minimize) {
                bool obfuscateParams = !eventSymbol.IsPublic;
                if (obfuscateParams) {
                    valueParameter.SetTransformedName("$p0");
                }
            }

            string eventName = eventSymbol.GeneratedName;
            string fieldName = eventName;
            if (eventSymbol.DefaultImplementation) {
                fieldName = "__" + Utility.CreateCamelCaseName(eventSymbol.Name);

                Debug.Assert(eventSymbol.Parent.Type == SymbolType.Class);

                Symbol fieldSymbol = ((ClassSymbol)eventSymbol.Parent).GetMember(fieldName);
                Debug.Assert((fieldSymbol != null) && (fieldSymbol.Type == SymbolType.Field));

                fieldName = fieldSymbol.GeneratedName;
            }

            string fieldReference;
            if ((eventSymbol.Visibility & MemberVisibility.Static) == 0) {
                fieldReference = "this.";
            }
            else {
                fieldReference = typeName + ".";
            }
            fieldReference += fieldName;

            bool instanceMember = true;
            if ((eventSymbol.Visibility & MemberVisibility.Static) != 0) {
                instanceMember = false;
                writer.Write(typeName);
                writer.Write(".");
            }

            writer.Write("add_");
            writer.Write(eventName);
            if (instanceMember) {
                writer.WriteTrimmed(": ");
            }
            else {
                writer.WriteTrimmed(" = ");
            }
            writer.Write("function");
            if (generator.Options.DebugFlavor) {
                writer.Write(" ");
                writer.Write(typeName.Replace(".", "_"));
                writer.Write("$add_");
                writer.Write(eventName);
            }
            writer.Write("(");
            writer.Write(valueParameter.GeneratedName);
            writer.Write(")");
            writer.WriteTrimmed(" {");
            writer.WriteNewLine();
            writer.Indent++;

            if (generator.Options.EnableDocComments) {
                DocCommentGenerator.GenerateComment(generator, eventSymbol);
            }

            if (eventSymbol.DefaultImplementation) {
                writer.Write(fieldReference);
                writer.WriteTrimmed(" = ");
                writer.Write("ss.Delegate.combine(");
                writer.Write(fieldReference);
                writer.WriteTrimmed(", ");
                writer.Write(valueParameter.GeneratedName);
                writer.Write(");");
                writer.WriteNewLine();
            }
            else {
                CodeGenerator.GenerateScript(generator, eventSymbol, /* add */ true);
            }
            writer.Indent--;
            writer.Write("}");

            if (instanceMember == false) {
                writer.WriteSignificantNewLine();
            }

            if (instanceMember) {
                writer.Write(",");
                writer.WriteNewLine();
            }
            else {
                writer.Write(typeName);
                writer.Write(".");
            }
            writer.Write("remove_");
            writer.Write(eventName);
            if (instanceMember) {
                writer.WriteTrimmed(": ");
            }
            else {
                writer.WriteTrimmed(" = ");
            }
            writer.Write("function");
            if (generator.Options.DebugFlavor) {
                writer.Write(" ");
                writer.Write(typeName.Replace(".", "_"));
                writer.Write("$remove_");
                writer.Write(eventName);
            }
            writer.Write("(");
            writer.Write(valueParameter.GeneratedName);
            writer.Write(")");
            writer.WriteTrimmed(" {");
            writer.WriteNewLine();
            writer.Indent++;

            if (generator.Options.EnableDocComments) {
                DocCommentGenerator.GenerateComment(generator, eventSymbol);
            }

            if (eventSymbol.DefaultImplementation) {
                writer.Write(fieldReference);
                writer.WriteTrimmed(" = ");
                writer.Write("ss.Delegate.remove(");
                writer.Write(fieldReference);
                writer.WriteTrimmed(", ");
                writer.Write(valueParameter.GeneratedName);
                writer.Write(");");
                writer.WriteNewLine();
            }
            else {
                CodeGenerator.GenerateScript(generator, eventSymbol, /* add */ false);
            }
            writer.Indent--;
            writer.Write("}");

            if (instanceMember == false) {
                writer.WriteSignificantNewLine();
            }
        }
        private static void GenerateEventComment(ScriptTextWriter writer, EventSymbol eventSymbol) {
            GenerateSummaryComment(writer, eventSymbol);

            writer.WriteLine("/// <param name=\"{0}\" type=\"Function\" />", eventSymbol.Parameters[0].Name);
        }
Beispiel #6
0
        private void BuildCode(EventSymbol eventSymbol)
        {
            if (eventSymbol.IsAbstract || eventSymbol.DefaultImplementation) {
                return;
            }

            ImplementationBuilder implBuilder = new ImplementationBuilder(_options, _errorHandler);

            eventSymbol.AddImplementation(implBuilder.BuildEventAdd(eventSymbol), /* adder */ true);
            eventSymbol.AddImplementation(implBuilder.BuildEventRemove(eventSymbol), /* adder */ false);

            _implementations.Add(eventSymbol.AdderImplementation);
            _implementations.Add(eventSymbol.RemoverImplementation);

            if (eventSymbol.AnonymousMethods != null) {
                foreach (AnonymousMethodSymbol anonymousMethod in eventSymbol.AnonymousMethods) {
                    Debug.Assert(anonymousMethod.Implementation != null);

                    _implementations.Add(anonymousMethod.Implementation);
                }
            }
        }
Beispiel #7
0
 public EventExpression(Expression objectReference, EventSymbol eventSymbol, bool add)
     : base((add ? ExpressionType.EventAdd : ExpressionType.EventRemove), eventSymbol.AssociatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers)
 {
     _event           = eventSymbol;
     _objectReference = objectReference;
 }
        private void ImportEvents(TypeSymbol typeSymbol)
        {
            TypeDefinition type = (TypeDefinition)typeSymbol.MetadataReference;

            foreach (EventDefinition eventDef in type.Events) {
                if (eventDef.IsSpecialName) {
                    continue;
                }
                if ((eventDef.AddMethod == null) || (eventDef.RemoveMethod == null)) {
                    continue;
                }
                if (eventDef.AddMethod.IsPrivate || eventDef.AddMethod.IsAssembly || eventDef.AddMethod.IsFamilyAndAssembly) {
                    continue;
                }

                string eventName = eventDef.Name;

                TypeSymbol eventHandlerType = ResolveType(eventDef.EventType);
                if (eventHandlerType == null) {
                    continue;
                }

                EventSymbol eventSymbol = new EventSymbol(eventName, typeSymbol, eventHandlerType);
                ImportMemberDetails(eventSymbol, eventDef.AddMethod, eventDef);

                typeSymbol.AddMember(eventSymbol);
            }
        }
Beispiel #9
0
 public EventExpression(Expression objectReference, EventSymbol eventSymbol, bool add)
     : base((add ? ExpressionType.EventAdd : ExpressionType.EventRemove), eventSymbol.AssociatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers) {
     _event = eventSymbol;
     _objectReference = objectReference;
 }
Beispiel #10
0
 private void DumpEvent(EventSymbol eventSymbol)
 {
 }
 private void DumpEvent(EventSymbol eventSymbol)
 {
 }