Exemple #1
0
 public override IEnumerable <IEntity> GetMembers()
 {
     foreach (Declaration d in _declarations)
     {
         yield return(TypeSystemServices.GetEntity(d));
     }
 }
Exemple #2
0
        private void BindAllParameters()
        {
            Method entryPoint = ContextAnnotations.GetEntryPoint(Context);

            foreach (INodeWithParameters node in _parameters)
            {
                var member = (TypeMember)node;

                if (member.ContainsAnnotation(PrivateMemberNeverUsed))
                {
                    continue;
                }

                NameResolutionService.EnterNamespace((INamespace)TypeSystemServices.GetEntity(member.DeclaringType));
                CodeBuilder.BindParameterDeclarations(member.IsStatic, node);
                if (!member.IsVisible && !member.IsSynthetic)
                {
                    IExplicitMember explicitMember = member as IExplicitMember;
                    if (null != explicitMember && null != explicitMember.ExplicitInfo)
                    {
                        continue;
                    }
                    if (member == entryPoint)                     //private Main is fine
                    {
                        continue;
                    }
                    member.Annotate(PrivateMemberNeverUsed, null);
                }
            }
        }
Exemple #3
0
 override public void OnModule(Boo.Lang.Compiler.Ast.Module module)
 {
     EnterNamespace((INamespace)TypeSystemServices.GetEntity(module));
     Visit(module.Members);
     Visit(module.Globals);
     LeaveNamespace();
 }
Exemple #4
0
 public IMethod GetSetMethod()
 {
     if (_node.Setter != null)
     {
         return((IMethod)TypeSystemServices.GetEntity(_node.Setter));
     }
     return(Overriden != null?Overriden.GetSetMethod() : null);
 }
Exemple #5
0
 void BindAllParameters()
 {
     foreach (INodeWithParameters node in _parameters)
     {
         TypeMember member = (TypeMember)node;
         NameResolutionService.Restore((INamespace)TypeSystemServices.GetEntity(member.DeclaringType));
         CodeBuilder.BindParameterDeclarations(member.IsStatic, node);
     }
 }
 public IMethod GetSetMethod()
 {
     if (null != _node.Setter)
     {
         return((IMethod)TypeSystemServices.GetEntity(_node.Setter));
     }
     if (null != _override)
     {
         return(_override.GetSetMethod());
     }
     return(null);
 }
Exemple #7
0
        private void Run()
        {
            IType type = (IType)TypeSystemServices.GetEntity(_typeDefinition);

            EnterGenericParametersNamespace(type);

            List <TypeDefinition> visitedNonInterfaces = null;
            List <TypeDefinition> visitedInterfaces;

            if (_typeDefinition is InterfaceDefinition)
            {
                visitedInterfaces = _visited;
                // interfaces won't have noninterface base types so visitedNonInterfaces not necessary here
            }
            else
            {
                visitedNonInterfaces = _visited;
                visitedInterfaces    = new List <TypeDefinition>();
            }

            foreach (var baseTypeRef in _typeDefinition.BaseTypes.ToArray())
            {
                NameResolutionService.ResolveTypeReference(baseTypeRef);

                ++_index;

                AbstractInternalType baseType = baseTypeRef.Entity as AbstractInternalType;
                if (null == baseType)
                {
                    continue;
                }

                if (IsEnclosingType(baseType.TypeDefinition))
                {
                    BaseTypeError(CompilerErrorFactory.NestedTypeCannotExtendEnclosingType(baseTypeRef, type, baseType));
                    continue;
                }

                // Clone visited for siblings re https://github.com/bamboo/boo/issues/94
                if (baseType is InternalInterface)
                {
                    CheckForCycles(baseTypeRef, baseType, new List <TypeDefinition>(visitedInterfaces));
                }
                else
                {
                    CheckForCycles(baseTypeRef, baseType, new List <TypeDefinition>(visitedNonInterfaces));
                }
            }

            LeaveGenericParametersNamespace(type);
        }
 public override void OnMethod(Method node)
 {
     // If method is generic, enter its namespace
     if (node.GenericParameters.Count != 0)
     {
         EnterNamespace((INamespace)TypeSystemServices.GetEntity(node));
         base.OnMethod(node);
         LeaveNamespace();
     }
     else
     {
         base.OnMethod(node);
     }
 }
 override public void OnModule(Boo.Lang.Compiler.Ast.Module module)
 {
     EnterNamespace((INamespace)TypeSystemServices.GetEntity(module));
     try
     {
         Visit(module.Members);
         Visit(module.Globals);
         Visit(module.Attributes);
         Visit(module.AssemblyAttributes);
     }
     finally
     {
         LeaveNamespace();
     }
 }
Exemple #10
0
        private void CheckEntryPoint()
        {
            Method method = ContextAnnotations.GetEntryPoint(Context);

            if (null == method)
            {
                return;
            }

            IMethod entity = (IMethod)TypeSystemServices.GetEntity(method);

            if (IsValidEntryPointReturnType(entity.ReturnType) && IsValidEntryPointParameterList(entity.GetParameters()))
            {
                return;
            }

            Errors.Add(CompilerErrorFactory.InvalidEntryPoint(method));
        }
Exemple #11
0
        bool ResolveModuleMember(Boo.Lang.List targetList, string name, EntityType flags)
        {
            bool found = false;

            foreach (Boo.Lang.Compiler.Ast.TypeMember member in _module.Members)
            {
                if (name == member.Name)
                {
                    IEntity tag = TypeSystemServices.GetEntity(member);
                    if (NameResolutionService.IsFlagSet(flags, tag.EntityType))
                    {
                        targetList.Add(tag);
                        found = true;
                    }
                }
            }
            return(found);
        }
Exemple #12
0
        void ResolveBaseTypes(Boo.Lang.List visited, TypeDefinition node)
        {
            // If type is generic, enter a special namespace to allow
            // correct resolution of generic parameters
            IType type = (IType)TypeSystemServices.GetEntity(node);

            if (type.GenericInfo != null)
            {
                EnterNamespace(new GenericParametersNamespaceExtender(
                                   type, NameResolutionService.CurrentNamespace));
            }

            visited.Add(node);

            int removed = 0;
            int index   = 0;

            foreach (SimpleTypeReference baseType in node.BaseTypes.ToArray())
            {
                NameResolutionService.ResolveSimpleTypeReference(baseType);

                AbstractInternalType internalType = baseType.Entity as AbstractInternalType;
                if (null != internalType)
                {
                    if (visited.Contains(internalType.TypeDefinition))
                    {
                        Error(CompilerErrorFactory.InheritanceCycle(baseType, internalType.FullName));
                        node.BaseTypes.RemoveAt(index - removed);
                        ++removed;
                    }
                    else
                    {
                        ResolveBaseTypes(visited, internalType.TypeDefinition);
                    }
                }
                ++index;
            }

            // Leave special namespace if we entered it before
            if (type.GenericInfo != null)
            {
                LeaveNamespace();
            }
        }
Exemple #13
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = My <TypeSystemServices> .Instance.Map(Types.DefaultMemberAttribute);

            foreach (var attribute in _node.Attributes)
            {
                var ctor = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != ctor && defaultMemberAttribute == ctor.DeclaringType)
                {
                    var memberName = attribute.Arguments[0] as StringLiteralExpression;
                    if (null != memberName)
                    {
                        var buffer = new System.Collections.Generic.List <IEntity>();
                        Resolve(buffer, memberName.Value, EntityType.Any);
                        return(Entities.EntityFromList(buffer));
                    }
                }
            }
            return(null);
        }
        public void TransformIteration(ForStatement node)
        {
            string[]      components = new string[] { "iterator" };
            InternalLocal local      = this.CodeBuilder.DeclareLocal(this.CurrentMethod, base._context.GetUniqueName(components), this.TypeSystemServices.IEnumeratorType);

            local.IsUsed = true;
            Block newNode = new Block(node.LexicalInfo);

            newNode.Add(this.CodeBuilder.CreateAssignment(node.LexicalInfo, this.CodeBuilder.CreateReference(local), node.Iterator));
            WhileStatement stmt = new WhileStatement(node.LexicalInfo)
            {
                Condition = this.CodeBuilder.CreateMethodInvocation(this.CodeBuilder.CreateReference(local), this.IEnumerator_MoveNext)
            };
            MethodInvocationExpression rhs = this.CodeBuilder.CreateMethodInvocation(this.CodeBuilder.CreateReference(local), this.IEnumerator_get_Current);
            InternalLocal entity           = (InternalLocal)TypeSystemServices.GetEntity(node.Declarations[0]);

            stmt.Block.Add(this.CodeBuilder.CreateAssignment(node.LexicalInfo, this.CodeBuilder.CreateReference(entity), rhs));
            stmt.Block.Add(node.Block);
            new LoopVariableUpdater(this, base._context, local, entity).Visit(node);
            newNode.Add(stmt);
            node.ParentNode.Replace(node, newNode);
        }
Exemple #15
0
        public bool Resolve(Boo.Lang.List targetList, string name, EntityType flags)
        {
            if (ResolveMember(targetList, name, flags))
            {
                return(true);
            }

            if (null == _using)
            {
                _using = new INamespace[_module.Imports.Count];
                for (int i = 0; i < _using.Length; ++i)
                {
                    _using[i] = (INamespace)TypeSystemServices.GetEntity(_module.Imports[i]);
                }
            }

            bool found = false;

            foreach (INamespace ns in _using)
            {
                found |= ns.Resolve(targetList, name, flags);
            }
            return(found);
        }
Exemple #16
0
        public virtual bool Resolve(ICollection <IEntity> resultingSet, string name, EntityType typesToConsider)
        {
            if (Entities.IsFlagSet(typesToConsider, EntityType.Local))
            {
                Local local = ResolveLocal(name);
                if (null != local)
                {
                    resultingSet.Add(TypeSystemServices.GetEntity(local));
                    return(true);
                }
            }

            if (Entities.IsFlagSet(typesToConsider, EntityType.Parameter))
            {
                ParameterDeclaration parameter = ResolveParameter(name);
                if (null != parameter)
                {
                    resultingSet.Add(TypeSystemServices.GetEntity(parameter));
                    return(true);
                }
            }

            return(false);
        }
 protected IType GetEntity(TypeReference node)
 {
     return((IType)TypeSystemServices.GetEntity(node));
 }
 protected IEntity GetEntity(Node node)
 {
     return(TypeSystemServices.GetEntity(node));
 }
Exemple #19
0
 public bool IsFieldReference(Node node) =>
 (EntityType.Field == TypeSystemServices.GetEntity(node).EntityType);
Exemple #20
0
 public override IEnumerable <IEntity> GetMembers()
 {
     return(_declarations.Select(d => TypeSystemServices.GetEntity(d)));
 }
Exemple #21
0
 Assembly GetBoundAssembly(ReferenceExpression reference)
 {
     return(((AssemblyReference)TypeSystemServices.GetEntity(reference)).Assembly);
 }
Exemple #22
0
 static ICompileUnit GetBoundReference(ReferenceExpression reference)
 {
     return((ICompileUnit)TypeSystemServices.GetEntity(reference));
 }
Exemple #23
0
 override public bool EnterModule(Boo.Lang.Compiler.Ast.Module module)
 {
     EnterNamespace((INamespace)TypeSystemServices.GetEntity(module));
     return(true);
 }
        protected override void ResolveImpl(MappedToken token)
        {
            switch (Node.NodeType)
            {
            case NodeType.SelfLiteralExpression:
                var classDefinition = Node;
                while (classDefinition.ParentNode != null)
                {
                    if (classDefinition.NodeType != NodeType.ClassDefinition)
                    {
                        classDefinition = classDefinition.ParentNode;
                    }
                    else
                    {
                        varType = TypeSystemServices.GetType(classDefinition);
                        break;
                    }
                }
                break;

            case NodeType.MemberReferenceExpression:
            case NodeType.ReferenceExpression:
                var     expression = (ReferenceExpression)Node;
                IEntity entity;
                try
                {
                    entity = TypeSystemServices.GetEntity(expression);
                }
                catch
                {
                    break;
                }
                var prefix = "";
                if (entity is InternalParameter)
                {
                    prefix          = "(parameter) ";
                    varType         = TypeSystemServices.GetType(expression);
                    declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter);
                }
                if (entity is InternalLocal)
                {
                    prefix          = "(local variable) ";
                    varType         = ((InternalLocal)entity).Type;
                    declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local);
                }
                if (entity is InternalField)
                {
                    varType         = TypeSystemServices.GetType(Node);
                    declaringType   = ((InternalField)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field);
                }
                if (entity is InternalMethod)
                {
                    declaringType   = ((InternalMethod)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalMethod)entity).Method);
                    if (entity is InternalConstructor)
                    {
                        varType = ((InternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((InternalMethod)entity).ReturnType;
                    }
                }
                if (entity is InternalProperty)
                {
                    declaringType   = ((InternalProperty)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property);
                }
                if (entity is InternalEvent)
                {
                    declaringType   = ((InternalEvent)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event);
                }
                if (entity is ExternalType)
                {
                    varType         = ((ExternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                }
                if (entity is AbstractInternalType)
                {
                    varType         = ((AbstractInternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                    declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition);
                }
                if (entity is ExternalField)
                {
                    varType       = TypeSystemServices.GetType(Node);
                    declaringType = ((ExternalField)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(((ExternalField)entity).Field);
                }
                if (entity is ExternalMethod)
                {
                    declaringType = ((ExternalMethod)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(declaration);
                    if (entity is ExternalConstructor)
                    {
                        varType = ((ExternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((ExternalMethod)entity).ReturnType;
                    }
                }
                if (entity is ExternalProperty)
                {
                    declaringType = ((ExternalProperty)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalProperty)entity).Property);
                }
                if (entity is ExternalEvent)
                {
                    declaringType = ((ExternalEvent)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalEvent)entity).Event);
                }
                if (expression.ExpressionType != null)
                {
                    if (declaringType != null)
                    {
                        prefix += declaringType.FullName + '.';
                    }
                    quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName;
                }
                break;

            default:
                break;
            }
        }
 protected IMethod GetEntity(Method node)
 {
     return((IMethod)TypeSystemServices.GetEntity(node));
 }
Exemple #26
0
 public IMethod GetRaiseMethod()
 {
     return((IMethod)TypeSystemServices.GetEntity(_node.Raise));
 }
Exemple #27
0
 public static INamespace ScopeFor(Module module)
 {
     return((InternalModule)TypeSystemServices.GetEntity(module));
 }
 protected IProperty GetEntity(Property node)
 {
     return((IProperty)TypeSystemServices.GetEntity(node));
 }
Exemple #29
0
 public IMethod GetAddMethod()
 {
     return((IMethod)TypeSystemServices.GetEntity(_node.Add));
 }