GetEntity() public static method

public static GetEntity ( Node node ) : IEntity
node Node
return IEntity
Esempio n. 1
0
 private IEnumerable <INamespace> ImportedNamespaces()
 {
     foreach (Import import in _module.Imports)
     {
         yield return((INamespace)TypeSystemServices.GetEntity(import));
     }
 }
Esempio n. 2
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = _typeSystemServices.Map(typeof(DefaultMemberAttribute));

            foreach (Attribute attribute in _typeDefinition.Attributes)
            {
                IConstructor tag = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != tag)
                {
                    if (defaultMemberAttribute == tag.DeclaringType)
                    {
                        StringLiteralExpression memberName = attribute.Arguments[0] as StringLiteralExpression;
                        if (null != memberName)
                        {
                            List buffer = new List();
                            Resolve(buffer, memberName.Value, EntityType.Any);
                            return(NameResolutionService.GetEntityFromList(buffer));
                        }
                    }
                }
            }
            if (null != BaseType)
            {
                return(BaseType.GetDefaultMember());
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Checks if a specified type argument violates the constraints
        /// declared on a specified type paramter.
        /// </summary>
        public bool ViolatesParameterConstraints(IGenericParameter parameter, TypeReference argumentNode)
        {
            IType argument = TypeSystemServices.GetEntity(argumentNode) as IType;

            // Ensure argument is a valid type
            if (argument == null || TypeSystemServices.IsError(argument))
            {
                return(false);
            }

            bool valid = true;

            // Check type semantics constraints
            if (parameter.IsClass && !argument.IsClass)
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustBeReferenceType(ConstructionNode, parameter, argument));
                valid = false;
            }

            if (parameter.IsValueType && !argument.IsValueType)
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustBeValueType(argumentNode, parameter, argument));
                valid = false;
            }

            // Check for default constructor
            if (parameter.MustHaveDefaultConstructor && !HasDefaultConstructor(argument))
            {
                Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveDefaultConstructor(argumentNode, parameter, argument));
                valid = false;
            }

            // Check base type constraints
            IType[] baseTypes = parameter.GetTypeConstraints();
            if (baseTypes != null)
            {
                foreach (IType baseType in baseTypes)
                {
                    // Don't check for System.ValueType supertype constraint
                    // if parameter also has explicit value type constraint
                    if (baseType == _tss.ValueTypeType && parameter.IsValueType)
                    {
                        continue;
                    }

                    if (!baseType.IsAssignableFrom(argument))
                    {
                        Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveBaseType(argumentNode, parameter, argument, baseType));
                        valid = false;
                    }
                }
            }

            return(!valid);
        }
Esempio n. 4
0
 public IMethod GetSetMethod()
 {
     if (null != _property.Setter)
     {
         return((IMethod)TypeSystemServices.GetEntity(_property.Setter));
     }
     if (null != _override)
     {
         return(_override.GetSetMethod());
     }
     return(null);
 }
Esempio n. 5
0
        private static bool IsOfType(Ast.Attribute attribute, IType attributeType)
        {
            var entity = TypeSystemServices.GetEntity(attribute);

            if (entity == attributeType)
            {
                return(true);
            }

            var constructor = entity as IConstructor;

            return(constructor != null && constructor.DeclaringType == attributeType);
        }
Esempio n. 6
0
        public bool Resolve(List targetList, string name, EntityType flags)
        {
            Declaration found = _declarations[name];

            if (null != found)
            {
                IEntity element = TypeSystemServices.GetEntity(found);
                if (NameResolutionService.IsFlagSet(flags, element.EntityType))
                {
                    targetList.Add(element);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 7
0
 override public IConstructor[] GetConstructors()
 {
     if (null == _constructors)
     {
         List constructors = new List();
         foreach (TypeMember member in _typeDefinition.Members)
         {
             if (member.NodeType == NodeType.Constructor && !member.IsStatic)
             {
                 constructors.Add(TypeSystemServices.GetEntity(member));
             }
         }
         _constructors = (IConstructor[])constructors.ToArray(typeof(IConstructor));
     }
     return(_constructors);
 }
Esempio n. 8
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = _typeSystemServices.Map(Types.DefaultMemberAttribute);

            foreach (Attribute attribute in _typeDefinition.Attributes)
            {
                IConstructor tag = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != tag)
                {
                    if (defaultMemberAttribute == tag.DeclaringType)
                    {
                        StringLiteralExpression memberName = attribute.Arguments[0] as StringLiteralExpression;
                        if (null != memberName)
                        {
                            List buffer = new List();
                            Resolve(buffer, memberName.Value, EntityType.Any);
                            return(NameResolutionService.GetEntityFromList(buffer));
                        }
                    }
                }
            }
            if (_typeDefinition.BaseTypes.Count > 0)
            {
                List buffer = new List();

                foreach (TypeReference baseType in _typeDefinition.BaseTypes)
                {
                    IType   tag           = TypeSystemServices.GetType(baseType);
                    IEntity defaultMember = tag.GetDefaultMember();
                    if (defaultMember != null)
                    {
                        if (tag.IsInterface)
                        {
                            buffer.AddUnique(defaultMember);
                        }
                        else                         //non-interface base class trumps interfaces
                        {
                            return(defaultMember);
                        }
                    }
                }
                return(NameResolutionService.GetEntityFromList(buffer));
            }
            return(null);
        }
Esempio n. 9
0
 public static bool IsAttributeDefined(TypeMember member, IType attributeType)
 {
     foreach (Boo.Lang.Compiler.Ast.Attribute attr in member.Attributes)
     {
         IEntity entity = TypeSystemServices.GetEntity(attr);
         if (entity == attributeType)
         {
             return(true);                                         // pre bound attribute
         }
         IConstructor constructor = entity as IConstructor;
         if (null == constructor)
         {
             continue;
         }
         if (constructor.DeclaringType == attributeType)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        public virtual bool Resolve(List targetList, string name, EntityType flags)
        {
            if (NameResolutionService.IsFlagSet(flags, EntityType.Local))
            {
                Local local = ResolveLocal(name);
                if (null != local)
                {
                    targetList.Add(TypeSystemServices.GetEntity(local));
                    return(true);
                }
            }

            if (NameResolutionService.IsFlagSet(flags, EntityType.Parameter))
            {
                ParameterDeclaration parameter = ResolveParameter(name);
                if (null != parameter)
                {
                    targetList.Add(TypeSystemServices.GetEntity(parameter));
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 11
0
 public ReferenceExpression CreateReference(ParameterDeclaration parameter)
 {
     return(CreateReference((InternalParameter)TypeSystemServices.GetEntity(parameter)));
 }
Esempio n. 12
0
 public IMethod GetRaiseMethod()
 {
     return((IMethod)TypeSystemServices.GetEntity(_event.Raise));
 }
Esempio n. 13
0
 public IMethod GetAddMethod()
 {
     return((IMethod)TypeSystemServices.GetEntity(_event.Add));
 }