Exemple #1
0
        override public void OnAttribute(Ast.Attribute attribute)
        {
            if (null != attribute.Entity)
            {
                return;
            }

            var entity = NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, true))
                         ?? NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, false))
                         ?? NameResolutionService.ResolveQualifiedName(attribute.Name);

            if (entity == null)
            {
                var suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, true))
                                 ?? NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, false));

                Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name, suggestion));
                return;
            }

            if (entity.IsAmbiguous())
            {
                Error(attribute, CompilerErrorFactory.AmbiguousReference(
                          attribute,
                          attribute.Name,
                          ((Ambiguous)entity).Entities));
                return;
            }

            if (EntityType.Type != entity.EntityType)
            {
                Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name, entity, null));
                return;
            }

            IType attributeType = ((ITypedEntity)entity).Type;

            if (IsAstAttribute(attributeType))
            {
                ExternalType externalType = attributeType as ExternalType;
                if (null == externalType)
                {
                    Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType));
                }
                else
                {
                    ScheduleAttributeApplication(attribute, externalType.ActualType);
                    RemoveCurrentNode();
                }
            }
            else
            {
                if (!IsSystemAttribute(attributeType))
                {
                    Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType));
                }
                else
                {
                    // remember the attribute's type
                    attribute.Name   = attributeType.FullName;
                    attribute.Entity = entity;
                    CheckAttributeParameters(attribute);
                }
            }
        }
Exemple #2
0
        override public void OnAttribute(Boo.Lang.Compiler.Ast.Attribute attribute)
        {
            if (null != attribute.Entity)
            {
                return;
            }

            _elements.Clear();

            if (!NameResolutionService.ResolveQualifiedName(_elements, BuildAttributeName(attribute.Name)))
            {
                NameResolutionService.ResolveQualifiedName(_elements, attribute.Name);
            }

            if (_elements.Count > 0)
            {
                if (_elements.Count > 1)
                {
                    Error(attribute, CompilerErrorFactory.AmbiguousReference(
                              attribute,
                              attribute.Name,
                              _elements));
                }
                else
                {
                    IEntity tag = (IEntity)_elements[0];
                    if (EntityType.Type != tag.EntityType)
                    {
                        Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name));
                    }
                    else
                    {
                        IType attributeType = ((ITypedEntity)tag).Type;
                        if (IsAstAttribute(attributeType))
                        {
                            ExternalType externalType = attributeType as ExternalType;
                            if (null == externalType)
                            {
                                Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType.FullName));
                            }
                            else
                            {
                                ScheduleAttributeApplication(attribute, externalType.ActualType);

                                RemoveCurrentNode();
                            }
                        }
                        else
                        {
                            if (!IsSystemAttribute(attributeType))
                            {
                                Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType.FullName));
                            }
                            else
                            {
                                // remember the attribute's type
                                attribute.Name   = attributeType.FullName;
                                attribute.Entity = attributeType;
                            }
                        }
                    }
                }
            }
            else
            {
                Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name));
            }
        }