Ejemplo n.º 1
0
        // Builds a codedom event and attaches it to the given type.
        // It seems that there is a codedom bug: you can't make events static.
        public static void Emit(CodeTypeDeclaration codeType, Event e)
        {
            // Create the codedom event and attach to the codedom type.
            var codeEvent = new CodeMemberEvent();
            codeType.Members.Add(codeEvent);

            // Assign a name
            codeEvent.Name = e.Name;

            // Assign the type.
            codeEvent.Type = new CodeTypeReference(e.DelegateName);

            // Translate the accessibility
            MemberAttributes memberAttributes = MemberAttributes.Public;
            switch (e.Accessibility)
            {
                case Accessibility.Internal:
                    memberAttributes = MemberAttributes.FamilyAndAssembly;
                    break;
                case Accessibility.Private:
                    memberAttributes = MemberAttributes.Private;
                    break;
                case Accessibility.Protected:
                    memberAttributes = MemberAttributes.Family;
                    break;
                case Accessibility.Public:
                    memberAttributes = MemberAttributes.Public;
                    break;
            }

            // This is bugged in codedom: no effect.
            if (e.IsShared)
                memberAttributes |= MemberAttributes.Static;

            codeEvent.Attributes = memberAttributes;
        }
Ejemplo n.º 2
0
        static void InterpretModifiers(Root root, Event c, ParseTreeNode node)
        {
            bool foundPublic = false;
            bool foundInternal = false;

            bool foundShared = false;

            bool foundPrivate = false;
            bool foundProtected = false;

            foreach (var modifierNode in node.ChildNodes)
            {
                string text = modifierNode.FindTokenAndGetText();

                if (text == "public")
                {
                    if (foundPublic || foundInternal || foundPrivate || foundProtected)
                    {
                        root.CompilerErrors.Add(new MultipleAccessModifiersCompilerError("",
                            modifierNode.FindToken().Location.Line,
                            modifierNode.FindToken().Location.Position));
                    }
                    else
                    {
                        c.Accessibility = Accessibility.Public;
                        foundPublic = true;
                    }
                }

                if (text == "internal")
                {
                    if (foundInternal || foundPublic || foundPrivate || foundProtected)
                    {
                        root.CompilerErrors.Add(new MultipleAccessModifiersCompilerError("",
                            modifierNode.FindToken().Location.Line,
                            modifierNode.FindToken().Location.Position));
                    }
                    else
                    {
                        c.Accessibility = Accessibility.Internal;
                        foundInternal = true;
                    }
                }

                if (text == "protected")
                {
                    if (foundInternal || foundPublic || foundPrivate || foundProtected)
                    {
                        root.CompilerErrors.Add(new MultipleAccessModifiersCompilerError("",
                            modifierNode.FindToken().Location.Line,
                            modifierNode.FindToken().Location.Position));
                    }
                    else
                    {
                        c.Accessibility = Accessibility.Protected;
                        foundProtected = true;
                    }
                }

                if (text == "private")
                {
                    if (foundInternal || foundPublic || foundPrivate || foundProtected)
                    {
                        root.CompilerErrors.Add(new MultipleAccessModifiersCompilerError("",
                            modifierNode.FindToken().Location.Line,
                            modifierNode.FindToken().Location.Position));
                    }
                    else
                    {
                        c.Accessibility = Accessibility.Private;
                        foundPrivate = true;
                    }
                }

                if (text == "shared")
                {
                    if (foundShared)
                    {
                        root.CompilerErrors.Add(new DuplicateModifiersCompilerError("",
                            modifierNode.FindToken().Location.Line,
                            modifierNode.FindToken().Location.Position));
                    }
                    else
                    {
                        c.IsShared = true;
                        foundShared = true;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // Build an event declaration.
        public static void BuildEvent(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var e = new Event(parentExpression, currentNode.Token.Convert());
            parentExpression.ChildExpressions.Add(e);

            InterpretModifiers(root, e, currentNode.ChildNodes[0]);

            e.DelegateName = currentNode.ChildNodes[2].ChildNodes[0].FindTokenAndGetText();
            e.Name = currentNode.ChildNodes[2].ChildNodes[1].FindTokenAndGetText();
        }