Esempio n. 1
0
        /// <summary>
        /// Create the binding object (association) for the class in the global name scope (system dictionary).
        /// </summary>
        /// <param name="installer">Context within which the binding is to be created.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool CreateGlobalBinding(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Check if the name is not complete garbage ... or reserved identifier
            if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(this.Name.Value))
            {
                return(installer.ReportError(this.Name, InstallerErrors.ClassInvalidName));
            }
            if (IronSmalltalk.Common.GlobalConstants.ReservedIdentifiers.Contains(this.Name.Value))
            {
                return(installer.ReportError(this.Name, InstallerErrors.ClassReservedName));
            }
            // 2. Check if there is already a global with that name in the inner name scope
            Symbol name = installer.Runtime.GetSymbol(this.Name.Value);
            IDiscreteGlobalBinding existingBinding = installer.GetLocalGlobalBinding(name);

            if (existingBinding != null)
            {
                return(installer.ReportError(this.Name, InstallerErrors.ClassNameNotUnique));
            }
            // 3. No global defined in the inner scope, but check the scopes (inner or outer) for protected names like Object etc.
            if (installer.IsProtectedName(name))
            {
                return(installer.ReportError(this.Name, InstallerErrors.ClassNameProtected));
            }

            // 4. OK ... create a binding - so far pointing to null ... this will be set in CreateGlobalObject().
            installer.AddClassBinding(new ClassBinding(name));
            return(true);
        }