Example #1
0
        /*
         * public imports only affect the directly superior module:
         *
         * module A:
         * import B;
         *
         * foo(); // Will fail, because foo wasn't found
         *
         * ---------------------------
         * module B:
         * import C;
         *
         * ---------------------------
         * module C:
         * public import D;
         *
         * ---------------------------
         * module D:
         * void foo() {}
         *
         * ---------------------------
         * Whereas
         * module B:
         * public import C;
         *
         * -- will compile because we have a closed import hierarchy in which all imports are public.
         *
         */

        /// <summary>
        /// Handle the node's static statements (but not the node itself)
        /// </summary>
        bool HandleDBlockNode(DBlockNode dbn, MemberFilter VisibleMembers, bool takePublicImportsOnly = false)
        {
            if (dbn != null && dbn.StaticStatements != null)
            {
                foreach (var stmt in dbn.StaticStatements)
                {
                    var dstmt = stmt as IDeclarationContainingStatement;
                    if (dstmt != null)
                    {
                        if (takePublicImportsOnly &&
                            dstmt is ImportStatement &&
                            !DAttribute.ContainsAttribute(dstmt.Attributes, DTokens.Public))
                        {
                            continue;
                        }

                        /*
                         * Mainly used for selective imports/import module aliases
                         */
                        if (dstmt.Declarations != null)
                        {
                            foreach (var d in dstmt.Declarations)
                            {
                                if (HandleItem(d))                                 //TODO: Handle visibility?
                                {
                                    return(true);
                                }
                            }
                        }

                        if (dstmt is ImportStatement)
                        {
                            var impStmt = (ImportStatement)dstmt;

                            foreach (var imp in impStmt.Imports)
                            {
                                if (string.IsNullOrEmpty(imp.ModuleAlias))
                                {
                                    if (HandleNonAliasedImport(imp, VisibleMembers))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Every module imports 'object' implicitly
            if (!takePublicImportsOnly)
            {
                if (HandleNonAliasedImport(_objectImport, VisibleMembers))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        void ApplyAttributes(IStatement n)
        {
            var attributes = new List <DAttribute>();

            foreach (var attr in BlockAttributes.ToArray())
            {
                attributes.Add(attr);
            }

            while (DeclarationAttributes.Count > 0)
            {
                var attr = DeclarationAttributes.Pop();

                // If accessor already in attribute array, remove it
                if (DTokens.VisModifiers[attr.Token])
                {
                    DAttribute.CleanupAccessorAttributes(attributes);
                }

                if (attr.IsProperty || !DAttribute.ContainsAttribute(attributes, attr.Token))
                {
                    attributes.Add(attr);
                }
            }

            n.Attributes = attributes.Count == 0 ? null : attributes.ToArray();
        }
Example #3
0
        void ApplyAttributes(DNode n)
        {
            foreach (var attr in BlockAttributes.ToArray())
            {
                n.Attributes.Add(attr);
            }

            while (DeclarationAttributes.Count > 0)
            {
                var attr = DeclarationAttributes.Pop();

                // If accessor already in attribute array, remove it
                if (DTokens.VisModifiers[attr.Token])
                {
                    DAttribute.CleanupAccessorAttributes(n.Attributes);
                }

                if (attr.IsProperty || !DAttribute.ContainsAttribute(n.Attributes.ToArray(), attr.Token))
                {
                    n.Attributes.Add(attr);
                }
            }
        }