Ejemplo n.º 1
0
 public virtual Node LookupTypeOrNamespace(Identifier prefix, Identifier identifier, bool typeOnly, NamespaceScope nsScope, int numTemplateArgs){
   if (identifier == null || nsScope == null){Debug.Assert(false); return null;}
   if (numTemplateArgs != 0 && TargetPlatform.GenericTypeNamesMangleChar != 0)
     identifier = new Identifier(identifier.ToString()+TargetPlatform.GenericTypeNamesMangleChar+numTemplateArgs, identifier.SourceContext);
   TypeNodeList duplicates = null;
   TypeNode t = null;
   if (prefix == null){
     Node n = this.LookupTypeOrNamespace(identifier, typeOnly, nsScope, out duplicates);
     t = n as TypeNode;
     if (t == null) return n;
   }else{
     Node tOrn = this.LookupTypeOrNamespace(prefix, false, nsScope, out duplicates);
     AliasDefinition aliasDef = tOrn as AliasDefinition;
     if (aliasDef != null && aliasDef.AliasedAssemblies != null){
       //The prefix just restricts the assemblies in which to look for identifier
       t = this.LookupType(identifier, aliasDef.AliasedAssemblies, out duplicates);
       if (t != null) goto returnT;
       return identifier;
     }
     Identifier nestedNamespaceFullName = nsScope.GetNamespaceFullNameFor(prefix);
     if (nestedNamespaceFullName != null){
       if (this.IsPrefixForTheGlobalNamespace(nestedNamespaceFullName.Prefix)){
         while (nsScope.Name != Identifier.Empty && nsScope.OuterScope is NamespaceScope)
           nsScope = (NamespaceScope)nsScope.OuterScope;
       }else if (nestedNamespaceFullName.Prefix != null){
         Node n = this.LookupTypeOrNamespace(nestedNamespaceFullName.Prefix, nestedNamespaceFullName, false, 0);
         if (n is TypeNode){
           //TODO: error
           return null;
         }else{
           Identifier nestedNamespaceFullName2 = n as Identifier;
           if (nestedNamespaceFullName2 == null){
             //TODO: error
             return null;
           }else{
             nestedNamespaceFullName = nestedNamespaceFullName2;
           }
         }
       }
       t = nsScope.GetType(nestedNamespaceFullName, identifier, out duplicates);
       if (t == null && !typeOnly){
         nestedNamespaceFullName = nsScope.GetNamespaceFullNameFor(Identifier.For(nestedNamespaceFullName.Name+ "." + identifier.Name));
         if (nestedNamespaceFullName != null) return nestedNamespaceFullName;
       }
     }else{
       Identifier Uri = nsScope.GetUriFor(prefix);
       if (Uri != null){
         t = nsScope.GetType(identifier, out duplicates);
         int numDups = duplicates == null ? 0 : duplicates.Count;
         if (numDups > 1){
           t = null;
           for (int i = 0, n = numDups; i < n; i++){
             TypeNode dup = duplicates[i];
             if (dup == null){numDups--; continue;}
             Identifier dupUri = this.GetUriNamespaceFor(dup);
             if (dupUri != null && dupUri.UniqueIdKey == Uri.UniqueIdKey){
               if (t != null) t = dup;
             }else{
               numDups--;
             }
           }
         }
         if (numDups <= 1 && t != null){
           duplicates = null;
         }
       }else{
         t = this.LookupType(prefix, identifier, nsScope, out duplicates);
       }
     }
   }
   if (this.NoDuplicatesAfterOverloadingOnTemplateParameters(duplicates, numTemplateArgs, ref t))
     duplicates = null;
   if (duplicates != null && duplicates.Count > 1){
     if (t == null){Debug.Assert(false); return null;}
     bool allDuplicatesHaveTheSameName = true;
     for (int i = 0; i < duplicates.Count && allDuplicatesHaveTheSameName; i++){
       TypeNode dup = duplicates[i];
       if (dup == null) continue;
       allDuplicatesHaveTheSameName = dup.FullName == t.FullName;
     }
     if (t.DeclaringModule != this.currentModule && allDuplicatesHaveTheSameName){
       this.HandleError(identifier, Error.MultipleTypeImport, this.GetTypeName(t), t.DeclaringModule.Location);
       goto returnT;
     }
     this.HandleError(identifier, Error.AmbiguousTypeReference, identifier.ToString());
     for (int i = 0, n = duplicates.Count; i < n; i++){
       TypeNode dup = duplicates[i];
       if (dup == null) continue;
       this.HandleRelatedError(dup);
     }
     goto returnT;
   }else if (t != null){
     if (!this.TypeIsVisible(t)) goto done;
   }
   returnT:
     if (t != null){
       this.AddNodePositionAndInfo(identifier, t, IdentifierContexts.AllContext);
       return t;
     }
   done:
     if (t != null){
       if (this.alreadyReported[t.UniqueKey] != null) return t;
       this.alreadyReported[t.UniqueKey] = t;
       this.HandleError(identifier, Error.TypeNotAccessible, this.GetTypeName(t));
       return t;
     }
   return null;
 }
Ejemplo n.º 2
0
 public virtual TypeNode LookupType(Expression qualifier, Identifier name, NamespaceScope nsscope, out TypeNodeList duplicates){
   duplicates = null;
   TypeNode declarer;
   TypeNodeList declarerDups;
   AliasDefinition rootAlias = this.GetAliasDefinitionForRoot(qualifier, nsscope);
   if (rootAlias != null){
     if (rootAlias.AliasedAssemblies != null){
       qualifier = this.ReplaceRoot(qualifier, rootAlias.Alias, null);
       if (qualifier != null){
         declarer = this.LookupType(qualifier, rootAlias.AliasedAssemblies, out declarerDups);
         return this.LookupNestedType(declarer, name, out duplicates, declarerDups);
       }else
         return this.LookupType(name, rootAlias.AliasedAssemblies, out declarerDups);
     }
     if (rootAlias.AliasedType != null){
       qualifier = this.ReplaceRoot(qualifier, rootAlias.Alias, null);
       if (qualifier != null){
         declarer = this.LookupNestedType((TypeNode)rootAlias.AliasedType, qualifier, out declarerDups, null);
         return this.LookupNestedType(declarer, name, out duplicates, declarerDups);
       }else
         return this.LookupNestedType((TypeNode)rootAlias.AliasedType, name, out duplicates, null);
     }
     if (rootAlias.AliasedExpression != null){
       qualifier = this.ReplaceRoot(qualifier, rootAlias.Alias, rootAlias.AliasedExpression);
       if (qualifier != null){
         return this.LookupType(new QualifiedIdentifier(qualifier, name), nsscope, out duplicates);
       }else
         return this.LookupType(name, nsscope, out duplicates);
     }
   }
   //First try to treat qualifier as just a namespace
   Identifier ns = this.ConvertToIdentifier(qualifier);
   if (ns == null){Debug.Assert(false); return null;}
   if (this.IsPrefixForTheGlobalNamespace(ns.Prefix)){
     while (nsscope.Name != Identifier.Empty && nsscope.OuterScope is NamespaceScope)
       nsscope = (NamespaceScope)nsscope.OuterScope;
   }
   TypeNode result = nsscope.GetType(ns, name, out duplicates);
   if (result != null) return result;
   //Now try to treat qualifier as a type
   declarer = this.LookupType(qualifier, nsscope, out declarerDups);
   return this.LookupNestedType(declarer, name, out duplicates, declarerDups);
 }
Ejemplo n.º 3
0
 public virtual Node LookupTypeOrNamespace(Identifier identifier, bool typeOnly, NamespaceScope nsScope, out TypeNodeList duplicates){
   duplicates = null;
   if (identifier == null || nsScope == null){Debug.Assert(false); return null;}
   TypeNode t = nsScope.GetType(identifier, out duplicates, true);
   if (t != null && t.Name != null && t.Name.UniqueIdKey == identifier.UniqueIdKey){
     AliasDefinition aliasDef = nsScope.GetConflictingAlias(identifier);
     if (aliasDef != null) aliasDef.ConflictingType = t;
   }else if (!typeOnly){
     TrivialHashtable alreadySeenAliases = new TrivialHashtable();
     AliasDefinition aliasDef = nsScope.GetAliasFor(identifier);
     while (aliasDef != null){
       if (aliasDef.AliasedType != null) return (TypeNode)aliasDef.AliasedType;
       if (alreadySeenAliases[aliasDef.UniqueKey] != null) break; //TODO: error?
       alreadySeenAliases[aliasDef.UniqueKey] = aliasDef;
       if (aliasDef.AliasedAssemblies != null) return aliasDef;
       if (aliasDef.AliasedExpression is Identifier)
         aliasDef = nsScope.GetAliasFor(identifier = (Identifier)aliasDef.AliasedExpression);
       else if (aliasDef.AliasedExpression is QualifiedIdentifier)
         return this.LookupTypeOrNamespace(aliasDef.AliasedExpression, false);
       else
         aliasDef = null; 
     }
     Identifier ns = nsScope.GetNamespaceFullNameFor(identifier);
     if (ns != null) return ns;
   }
   return t;
 }
Ejemplo n.º 4
0
 public virtual TypeNode LookupType(Expression name, NamespaceScope nsscope, out TypeNodeList duplicates){
   duplicates = null;
   if (name == null || nsscope == null){Debug.Assert(false); return null;}
   Identifier id = name as Identifier;
   if (id != null){
     if (id.Prefix != null){
       if (this.IsPrefixForTheGlobalNamespace(id.Prefix)){
         while (nsscope.Name != Identifier.Empty && nsscope.OuterScope is NamespaceScope)
           nsscope = (NamespaceScope)nsscope.OuterScope;
         return nsscope.GetType(id, out duplicates);
       }
       return this.LookupType(id.Prefix, id, nsscope, out duplicates);
     }
     AliasDefinition rootAlias = this.GetAliasDefinitionForRoot(id, nsscope);
     if (rootAlias != null) return (TypeNode)rootAlias.AliasedType;
     return nsscope.GetType(id, out duplicates);
   }
   QualifiedIdentifier qual = name as QualifiedIdentifier;
   if (qual == null){Debug.Assert(name is TemplateInstance); return this.LookupType(name as TemplateInstance);}
   return this.LookupType(qual.Qualifier, qual.Identifier, nsscope, out duplicates);
 }