Exemple #1
0
        private IEntity ResolveImportOnParentNamespace(Import import)
        {
            var        current         = NameResolutionService.CurrentNamespace;
            INamespace parentNamespace = NameResolutionService.CurrentNamespace.ParentNamespace;

            if (parentNamespace != null)
            {
                IEntity result;
                if (!RetrieveCachedNamespace(parentNamespace, import.Namespace, out result))
                {
                    NameResolutionService.EnterNamespace(parentNamespace);
                    try
                    {
                        result = NameResolutionService.ResolveQualifiedName(import.Namespace);
                        AddCachedNamespace(parentNamespace, import.Namespace, result);
                    }
                    finally
                    {
                        NameResolutionService.EnterNamespace(current);
                    }
                }
                return(result);
            }
            return(null);
        }
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);
                }
            }
        }
 private void EnterGenericParametersNamespace(IType type)
 {
     if (type.GenericInfo != null)
     {
         NameResolutionService.EnterNamespace(new GenericParametersNamespaceExtender(
                                                  type, NameResolutionService.CurrentNamespace));
     }
 }
        public BaseTypeResolution(CompilerContext context, TypeDefinition typeDefinition, List <TypeDefinition> visited) : base(context)
        {
            _typeDefinition = typeDefinition;
            _visited        = visited;
            _visited.Add(_typeDefinition);

            _removed = 0;
            _index   = -1;

            NameResolutionService nameResolution = NameResolutionService;
            INamespace            previous       = nameResolution.CurrentNamespace;

            nameResolution.EnterNamespace(ParentNamespaceOf(_typeDefinition));
            try
            {
                Run();
            }
            finally
            {
                nameResolution.EnterNamespace(previous);
            }
        }
Exemple #5
0
        private IEntity ResolveImportOnParentNamespace(Import import)
        {
            INamespace current = NameResolutionService.CurrentNamespace;

            try
            {
                INamespace parentNamespace = NameResolutionService.CurrentNamespace.ParentNamespace;
                if (parentNamespace != null)
                {
                    NameResolutionService.EnterNamespace(parentNamespace);
                    return(NameResolutionService.ResolveQualifiedName(import.Namespace));
                }
            }
            finally
            {
                NameResolutionService.EnterNamespace(current);
            }
            return(null);
        }
        private void BindImport(Import import)
        {
            var previous = NameResolutionService.CurrentNamespace;

            try
            {
                NameResolutionService.Reset();

                var namespaceBinder = new ResolveImports();
                namespaceBinder.Initialize(CompilerContext.Current);
                import.Accept(namespaceBinder);
            }
            catch (Exception x)
            {
                throw new CompilerError(_node, "Error expanding " + import.ToCodeString(), x);
            }
            finally
            {
                NameResolutionService.EnterNamespace(previous);
            }
        }
Exemple #7
0
        public override void OnImport(Boo.Lang.Compiler.Ast.Import import)
        {
            INamespace oldns  = NameResolutionService.CurrentNamespace;
            IEntity    entity = null;

            try
            {
                NameResolutionService.EnterNamespace(NameResolutionService.CurrentNamespace.ParentNamespace);
                entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
            }
            finally
            {
                NameResolutionService.EnterNamespace(oldns);
            }

            if (null == entity)
            {
                entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
            }

            //if 'import X', try 'import X from X'
            //comment out next if block if this is not wanted
            if (null == entity && null == import.AssemblyReference)
            {
                if (TryAutoAddAssemblyReference(import))
                {
                    entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
                }
            }

            if (null == entity)
            {
                Errors.Add(CompilerErrorFactory.InvalidNamespace(import));
                entity = TypeSystemServices.ErrorEntity;
            }
            else
            {
                if (!IsValidNamespace(entity))
                {
                    Errors.Add(CompilerErrorFactory.NotANamespace(import, entity.FullName));
                    entity = TypeSystemServices.ErrorEntity;
                }
                else
                {
                    string name = entity.FullName;
                    if (null != import.AssemblyReference)
                    {
                        NamespaceEntity nsInfo = entity as NamespaceEntity;
                        if (null != nsInfo)
                        {
                            entity = new AssemblyQualifiedNamespaceEntity(GetBoundAssembly(import.AssemblyReference), nsInfo);
                        }
                    }

                    if (null != import.Alias)
                    {
                        entity = new AliasedNamespace(import.Alias.Name, entity);
                        import.Alias.Entity = entity;
                        name = entity.Name;                         //use alias name instead of namespace name
                    }

                    //only add unique namespaces
                    Import cachedImport = nameSpaces[name] as Import;
                    if (cachedImport == null)
                    {
                        nameSpaces[name] = import;
                    }
                    else
                    {
                        //ignore for partial classes in separate files
                        if (cachedImport.LexicalInfo.FileName == import.LexicalInfo.FileName)
                        {
                            Warnings.Add(CompilerWarningFactory.DuplicateNamespace(
                                             import, import.Namespace));
                        }
                        RemoveCurrentNode();
                        return;
                    }
                }
            }

            _context.TraceInfo("{1}: import reference '{0}' bound to {2}.", import, import.LexicalInfo, entity.FullName);
            import.Entity = entity;
        }
Exemple #8
0
 protected void EnterNamespace(INamespace ns)
 {
     NameResolutionService.EnterNamespace(ns);
 }
 public TypeMember Reify(TypeMember member)
 {
     NameResolutionService.EnterNamespace((INamespace)GetEntity(member.DeclaringType));
     Visit(member);
     return(member);
 }