public CodegenExpressionField AddFieldUnshared( bool isFinal, Type type, CodegenExpression assignScopedPackageInitMethod) { return NamespaceScope.AddFieldUnshared(isFinal, type, assignScopedPackageInitMethod); }
private void PushNamespace(string prefix, string ns) { var curr = _scopes.Last(); if (curr == null) { curr = new NamespaceScope(); _scopes[_scopes.Count - 1] = curr; } if (string.IsNullOrEmpty(prefix)) { curr.Default = ns; curr.DefaultWritten = true; } else { var match = curr.FirstOrDefault(n => n.Prefix == prefix); if (!string.IsNullOrEmpty(match.Ns)) { curr.Remove(match); } curr.Add(new Namespace() { IsWritten = true, Ns = ns, Prefix = prefix }); } }
public static NamespaceScope forThriftName(string name) { NamespaceScope scope = NamespaceScope.UNKNOWN; _mapping.TryGetValue(name, out scope); return(scope); }
private void CheckReferences(XName element, string value, NamespaceScope local, Styles localStyles) { XName reference = null; if (value.StartsWith("{Binding") || value.StartsWith("{TemplateBinding")) { var binding = ParseBinding(value, local); reference = binding.Converter; if (binding.Source != null) { var sourceRef = ParseResourceReference(binding.Source, local); var style = localStyles.FindStyle(element, sourceRef); if (style == null && !Whitelisted(sourceRef)) { Program.WriteError("Resource {0} not found", sourceRef.ToString()); } } } else if (value.StartsWith('{')) { reference = ParseResourceReference(value, local); } if (reference != null) { var style = localStyles.FindStyle(element, reference); if (style == null && !Whitelisted(reference)) { Program.WriteError("Resource {0} not found", reference.ToString()); } } }
/// <summary>Initializes a new instance of the <see cref="AssemblyScope"/> struct.</summary> /// <param name="filePath">The file path to the assembly.</param> /// <param name="namespaceText">The namespace text.</param> /// <param name="name">The name.</param> public AssemblyScope(string filePath, string namespaceText, string name) : this() { if (!string.IsNullOrEmpty(filePath)) { Assembly assembly = Assembly.LoadFile(filePath); Location = filePath; Root = assembly.ResolveRootNamespace(); if (string.IsNullOrEmpty(namespaceText)) { if (!Root.Equals(name)) { namespaceText = Root; } } string comboPath = NamespaceScope.CombineNamespacePaths(namespaceText, name); NamespaceInformation = new NamespaceScope(filePath, comboPath); if (NamespaceInformation.IsNamespace) { if (!string.IsNullOrEmpty(NamespaceInformation.FullPath)) { TypeInfo = assembly.GetType(NamespaceInformation.FullPath); } else { TypeInfo = null; } } } }
XName QualifyName(string name, NamespaceScope scope) { var parts = name.Split(':'); if (parts.Length == 2) { var prefix = parts[0]; var localName = parts[1]; var ns = scope.FindPrefix(prefix); if (ns != null) { if (ns.StartsWith(ClrNamespacePrefix)) { ns = ns.Substring(ClrNamespacePrefix.Length); } int i = ns.IndexOf(";assembly="); if (i > 0) { ns = ns.Substring(0, i); } return(XName.Get(localName, ns)); } } return(XName.Get(name)); }
private XName ParseTargetType(string value, NamespaceScope scope) { if (value.StartsWith("{")) { // e.g. "{x:Type c:CloseBox}" value = value.Trim(BindingChars); var parts = value.Split(WhitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var name = QualifyName(parts[0], scope); var type = QualifyName(parts[1], scope); if (name == XamlTypeName || name == XamlStaticName) { return(type); } else { Program.WriteError("Unexpected target type: {0}", value); } } return(QualifyName(parts[0], scope)); } else { return(QualifyName(value, scope)); } }
/// <summary>Initializes a new instance of the <see cref="AssemblyScope"/> struct.</summary> public AssemblyScope() { TypeInfo = null; Location = string.Empty; Root = string.Empty; Name = string.Empty; NamespaceInformation = new NamespaceScope(); }
public void IsMatching_ExactMatch_NoMatch() { var scope = NamespaceScope.Parse("mynamespace.other"); scope.IsMatching("mynamespace.othe").Should().BeFalse(); scope.IsMatching("mynamespace.other2").Should().BeFalse(); scope.IsMatching("mynamespace.other.deep").Should().BeFalse(); }
public CodegenExpressionInstanceField AddInstanceFieldUnshared( CodegenExpression instance, bool isFinal, Type type, CodegenExpression assignScopedPackageInitMethod) { return NamespaceScope.AddInstanceFieldUnshared( instance, isFinal, type, assignScopedPackageInitMethod); }
public override MemberList LookupAnonymousMembers(Identifier identifier, NamespaceScope nsScope) { // 21 June 2005 -- For now, remove functionality of finding anonyous members: too slow, // and not needed for now since we are not allowing general quantifiers in contracts // But keep commented code in case we want to go back to it. return(null); //SpecSharpCompilerOptions coptions = this.currentOptions as SpecSharpCompilerOptions; //if (coptions != null && coptions.Compatibility) return null; //return base.LookupAnonymousMembers(identifier, nsScope); }
public void Compare_All_Tests() { var ns1 = NamespaceScope.Parse("mynamespace"); var ns2 = NamespaceScope.Parse("mynamespace.other"); ns1.CompareTo(NamespaceScope.All).Should().Be(-1); ns2.CompareTo(NamespaceScope.All).Should().Be(-1); NamespaceScope.All.CompareTo(ns1).Should().Be(1); NamespaceScope.All.CompareTo(ns2).Should().Be(1); }
private void CheckStyleReferences(string filePath, XElement root, NamespaceScope scope, Styles styles) { var local = new NamespaceScope(scope); XName targetType = null; XName key = null; AddNamespaces(root, local); foreach (var a in root.Attributes()) { if (a.Name.LocalName == "TargetType") { targetType = ParseTargetType(a.Value, local); } else if (a.Name.LocalName == "Key" && a.Name.Namespace == XamlNsUri) { key = ParseTargetType(a.Value, local); } else if (a.Name.LocalName == "DataType") { // todo: check DataType references. } else if (a.Name.LocalName != "xmlns" && a.Name.Namespace != XmlNsUri) { CheckReferences(GetTargetTypeName(root, a), a.Value, local, styles); } } Styles localStyles = null; // see if this element contains local styles foreach (var e in root.Elements()) { // find any local styles. if (e.Name.LocalName.EndsWith(".Resources")) { if (localStyles == null) { localStyles = new Styles(filePath + "+" + e.Name, styles); styles = localStyles; } FindStyles(filePath, e, local, localStyles); } } // Check for any nested styles first. foreach (var e in root.Elements()) { CheckStyleReferences(filePath, e, local, styles); } if (localStyles != null) { localStyles.ReportUnreferenced(); } }
// protected UserType(UserTypeBuilder<? extends UserType, ? extends UserTypeBuilder<?, ?>> builder) { // super(builder.mixin.name()); // this.namespaces = builder.namespaces; // this.mixin = builder.mixin; // } public String getNamespaceFor(NamespaceScope n) { String ns = NamespaceScopeMapping.forThriftName(n); if (ns == null && n != NamespaceScope.ALL) { ns = NamespaceScopeMapping.forThriftName(NamespaceScope.ALL); } return(ns); }
public static string forThriftName(NamespaceScope scope) { foreach (var k in _mapping) { if (k.Value == scope) { return(k.Key); } } return(null); }
public void Parse_GeneralParsingTests() { var result = NamespaceScope.Parse("mynamespace"); result.ToString().Should().Be("mynamespace"); result = NamespaceScope.Parse("mynamespace.other"); result.ToString().Should().Be("mynamespace.other"); result = NamespaceScope.Parse("mynamespace.other.*"); result.ToString().Should().Be("mynamespace.other.*"); result = NamespaceScope.Parse("mynamespace.other+*"); result.ToString().Should().Be("mynamespace.other+*"); }
public void ParseConfig_FailureTests() { Action runParse = () => NamespaceScope.Parse("my*name"); runParse.ShouldThrow <Exception>(); runParse = () => NamespaceScope.Parse(""); runParse.ShouldThrow <Exception>().And.Message.Should().Contain("empty"); runParse = () => NamespaceScope.Parse("my.other."); runParse.ShouldThrow <Exception>(); runParse = () => NamespaceScope.Parse("my.other*"); runParse.ShouldThrow <Exception>(); }
public void Compare_Length_Tests() { var ns1 = NamespaceScope.Parse("mynamespace"); var ns2 = NamespaceScope.Parse("mynamespace.other"); var ns3 = NamespaceScope.Parse("mynamespace.other.deep"); ns1.CompareTo(ns2).Should().Be(1); ns2.CompareTo(ns1).Should().Be(-1); ns1.CompareTo(ns3).Should().Be(1); ns3.CompareTo(ns1).Should().Be(-1); ns2.CompareTo(ns3).Should().Be(1); ns3.CompareTo(ns2).Should().Be(-1); }
public void Compare_MatchType_Tests() { var ns1 = NamespaceScope.Parse("mynamespace"); var ns2 = NamespaceScope.Parse("mynamespace.*"); var ns3 = NamespaceScope.Parse("mynamespace+*"); ns1.CompareTo(ns2).Should().Be(-1); ns2.CompareTo(ns1).Should().Be(1); ns1.CompareTo(ns3).Should().Be(-1); ns3.CompareTo(ns1).Should().Be(1); ns2.CompareTo(ns3).Should().Be(-1); ns3.CompareTo(ns2).Should().Be(1); }
private void AddNamespaces(XElement e, NamespaceScope scope) { foreach (var a in e.Attributes()) { if (a.Name.LocalName == "xmlns") { scope.AddPrefix("", StripClrPrefix(a.Value)); } else if (a.Name.Namespace == XmlNsUri) { scope.AddPrefix(a.Name.LocalName, StripClrPrefix(a.Value)); } } }
private void FindStyles(string filePath, XElement root, NamespaceScope scope, Styles styles) { var local = new NamespaceScope(scope); XName targetType = null; XName key = null; AddNamespaces(root, local); foreach (var a in root.Attributes()) { if (a.Name.LocalName == "TargetType") { targetType = ParseTargetType(a.Value, local); } else if (a.Name.LocalName == "Key" && a.Name.Namespace == XamlNsUri) { key = ParseTargetType(a.Value, local); } else if (a.Name.LocalName == "DataType") { // todo: check DataType references. } } if (key != null || targetType != null) { if (root.Name.LocalName == "ControlTemplate" && targetType != null && key == null && HasParent(root, "Style")) { // If this control template is inside a <Style> then it is not an independently // addressable resource. } else { styles.AddStyle(filePath, key, targetType, root); } } // Check for any nested styles first. foreach (var e in root.Elements()) { // If we find a nested .Resources within a resource then it's styles // are not global, we will create localstyles for this one later. if (!e.Name.LocalName.EndsWith(".Resources")) { FindStyles(filePath, e, local, styles); } } }
/// <summary>Resolves the specified input to a <see cref="Type"/>.</summary> /// <param name="assembly">The assembly.</param> /// <param name="namespacePath">The namespace path.</param> /// <param name="typeName">Name of the type.</param> /// <returns>The <see cref="Type"/>.</returns> public static Type ResolveType(Assembly assembly, string namespacePath, string typeName) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException(nameof(typeName), @"The type name cannot be null or empty when resolving a Type."); } // Combine the path string fullPath = NamespaceScope.CombineNamespacePaths(namespacePath, typeName); // Resolve the type Type type = assembly.GetType(fullPath); return(type); }
public override Namespace VisitNamespace(Namespace nspace){ if (nspace == null) return null; Scope savedCurrentScope = this.currentScope; Scope outerScope = savedCurrentScope; //Insert dummy outer namespace scopes for any prefixes. Ie. if this namespace has Name == foo.bar, insert an outer //namespace scope for the "foo" prefix. string id = nspace.Name.ToString(); int firstDot = id.IndexOf('.'); while (firstDot > 0){ outerScope = new NamespaceScope(outerScope, new Namespace(Identifier.For(id.Substring(0, firstDot))), this.currentModule); firstDot = id.IndexOf('.', firstDot+1); } this.ScopeFor[nspace.UniqueKey] = this.currentScope = new NamespaceScope(outerScope, nspace, this.currentModule); nspace = base.VisitNamespace(nspace); this.currentScope = savedCurrentScope; return nspace; }
public void Sorting_NamespaceDefinitionTypeOrder() { var def1 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace"), TraceTargetVisibility.All, TraceTargetVisibility.All); var def2 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.*"), TraceTargetVisibility.All, TraceTargetVisibility.All); var def3 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace+*"), TraceTargetVisibility.All, TraceTargetVisibility.All); var list = new List <AssemblyLevelTraceDefinition>() { def1, def2, def3 }; list.Sort(new AssemblyLevelTraceDefinitionComparer()); list[0].Should().BeSameAs(def1); list[1].Should().BeSameAs(def2); list[2].Should().BeSameAs(def3); }
XName QualifyPath(string value, NamespaceScope scope) { if (value.StartsWith("(")) { value = value.Trim('(', ')').Trim(); } var pos = value.LastIndexOf('.'); if (pos >= 0) { value = value.Substring(pos + 1); } if (string.IsNullOrEmpty(value)) { return(null); } return(QualifyName(value, scope)); }
public void Sorting_TraceOnNoTraceOrder() { AssemblyLevelTraceOnDefinition def1 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace"), TraceTargetVisibility.All, TraceTargetVisibility.All); AssemblyLevelTraceOnDefinition def2 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.All); AssemblyLevelNoTraceDefinition def3 = new AssemblyLevelNoTraceDefinition(NamespaceScope.Parse("rootnamespace")); AssemblyLevelNoTraceDefinition def4 = new AssemblyLevelNoTraceDefinition(NamespaceScope.Parse("rootnamespace.other")); List <AssemblyLevelTraceDefinition> list = new List <AssemblyLevelTraceDefinition>() { def1, def2, def3, def4 }; list.Sort(new AssemblyLevelTraceDefinitionComparer()); list[0].Should().BeSameAs(def4); list[1].Should().BeSameAs(def2); list[2].Should().BeSameAs(def3); list[3].Should().BeSameAs(def1); }
// Get all namespaces in the local or scope from the last parent private IDictionary GetNamespacesInScope(NamespaceScope scope) { int i = 0; switch (scope) { case NamespaceScope.All: i = 0; break; case NamespaceScope.Local: i = _lastDecl; int lastScopeCount = _nsDeclarations[i].ScopeCount; while (_nsDeclarations[i].ScopeCount == lastScopeCount) { i--; } i++; break; } HybridDictionary dict = new HybridDictionary(_lastDecl - i + 1); for (; i < _lastDecl; i++) { string prefix = _nsDeclarations[i].Prefix; string xmlNamespace = _nsDeclarations[i].Uri; Debug.Assert(prefix != null); if (xmlNamespace.Length > 0 || prefix.Length > 0) { dict[prefix] = xmlNamespace; } else { // default namespace redeclared to "" -> remove from list dict.Remove(prefix); } } return(dict); }
private void EndNamespaceScope(XmlReader reader) { if (elementScopes.Count > 0) { NamespaceScope currentScope = elementScopes.Peek(); if (currentScope.Depth == reader.Depth && currentScope.LocalName == reader.LocalName && currentScope.NamespaceURI == reader.NamespaceURI) { // TODO: not necessary? // Remove all namespaces in scope. foreach (KeyValuePair <string, string> nsDeclaration in nsManager.GetNamespacesInScope(XmlNamespaceScope.Local)) { nsManager.RemoveNamespace(nsDeclaration.Key, nsDeclaration.Value); } nsManager.PopScope(); elementScopes.Pop(); } } }
public void Sorting_MethodVisibility() { var def1 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.All); var def2 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.InternalOrMoreVisible); var def3 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.Public); var def4 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.ProtectedOrMoreVisible); var def5 = new AssemblyLevelTraceOnDefinition(NamespaceScope.Parse("rootnamespace.other"), TraceTargetVisibility.All, TraceTargetVisibility.None); var list = new List <AssemblyLevelTraceDefinition>() { def1, def2, def3, def4, def5 }; list.Sort(new AssemblyLevelTraceDefinitionComparer()); list[0].Should().BeSameAs(def5); list[1].Should().BeSameAs(def3); list[2].Should().BeSameAs(def2); list[3].Should().BeSameAs(def4); list[4].Should().BeSameAs(def1); }
public override Namespace VisitNamespace(Namespace nspace) { if (nspace == null) { return(null); } Scope savedCurrentScope = this.currentScope; Scope outerScope = savedCurrentScope; //Insert dummy outer namespace scopes for any prefixes. Ie. if this namespace has Name == foo.bar, insert an outer //namespace scope for the "foo" prefix. string id = nspace.Name.ToString(); int firstDot = id.IndexOf('.'); while (firstDot > 0) { outerScope = new NamespaceScope(outerScope, new Namespace(Identifier.For(id.Substring(0, firstDot))), this.currentModule); firstDot = id.IndexOf('.', firstDot + 1); } this.ScopeFor[nspace.UniqueKey] = this.currentScope = new NamespaceScope(outerScope, nspace, this.currentModule); nspace = base.VisitNamespace(nspace); this.currentScope = savedCurrentScope; return(nspace); }
public void IsMatching_OnlyChildren_DeepChild_Match() { var scope = NamespaceScope.Parse("mynamespace.other.*"); scope.IsMatching("mynamespace.other.child.deep").Should().BeTrue(); }
public virtual void ExpandRootIfAnAlias(ref Expression qualOrId, NamespaceScope nsscope){ if (nsscope == null) return; if (qualOrId == null){Debug.Assert(false); return;} QualifiedIdentifier qual = qualOrId as QualifiedIdentifier; if (qual != null){this.ExpandRootIfAnAlias(ref qual.Qualifier, nsscope); return;} Identifier id = qualOrId as Identifier; if (id == null) return; NamespaceScope outerScope = nsscope.OuterScope as NamespaceScope; if (id.Prefix != null){ AliasDefinition aliasDef = nsscope.GetAliasFor(id.Prefix); if (aliasDef != null && aliasDef.AliasedAssemblies != null){ //TODO: pass it back up to the caller return; } if (outerScope == null) return; aliasDef = outerScope.GetAliasFor(id.Prefix); if (aliasDef != null){ qualOrId = new QualifiedIdentifier(aliasDef.AliasedExpression, this.GetUnprefixedIdentifier(id), id.SourceContext); return; } }else{ AliasDefinition aliasDef = nsscope.GetAliasFor(id); if (aliasDef != null && aliasDef.AliasedAssemblies != null){ //TODO: pass it back up to the caller return; } if (outerScope == null) return; aliasDef = outerScope.GetAliasFor(id); if (aliasDef != null){ qualOrId = aliasDef.AliasedExpression; return; } } }
public virtual AliasDefinition GetAliasDefinitionForRoot(Expression qualOrId, NamespaceScope nsscope){ if (nsscope == null) return null; if (qualOrId == null){Debug.Assert(false); return null;} QualifiedIdentifier qual = qualOrId as QualifiedIdentifier; if (qual != null) return this.GetAliasDefinitionForRoot(qual.Qualifier, nsscope); Identifier id = qualOrId as Identifier; if (id == null){Debug.Assert(false); return null;} NamespaceScope outerScope = nsscope.OuterScope as NamespaceScope; if (id.Prefix != null){ AliasDefinition aliasDef = nsscope.GetAliasFor(id.Prefix); if (aliasDef != null && aliasDef.AliasedAssemblies != null) return aliasDef; if (outerScope == null) return null; return outerScope.GetAliasFor(id.Prefix); }else{ AliasDefinition aliasDef = nsscope.GetAliasFor(id); if (aliasDef != null && aliasDef.AliasedAssemblies != null) return aliasDef; if (outerScope == null) return null; return outerScope.GetAliasFor(id); } }
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; }
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; }
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); }
public override MemberList LookupAnonymousMembers(Identifier identifier, NamespaceScope nsScope){ // 21 June 2005 -- For now, remove functionality of finding anonyous members: too slow, // and not needed for now since we are not allowing general quantifiers in contracts // But keep commented code in case we want to go back to it. return null; //SpecSharpCompilerOptions coptions = this.currentOptions as SpecSharpCompilerOptions; //if (coptions != null && coptions.Compatibility) return null; //return base.LookupAnonymousMembers(identifier, nsScope); }
// Get all namespaces in the local or scope from the last parent private IDictionary GetNamespacesInScope(NamespaceScope scope) { int i = 0; switch (scope) { case NamespaceScope.All: i = 0; break; case NamespaceScope.Local: i = _lastDecl; int lastScopeCount = _nsDeclarations[i].ScopeCount; while (_nsDeclarations[i].ScopeCount == lastScopeCount) i--; i++; break; } HybridDictionary dict = new HybridDictionary(_lastDecl -i + 1); for (; i < _lastDecl; i++) { string prefix = _nsDeclarations[i].Prefix; string xmlNamespace = _nsDeclarations[i].Uri; Debug.Assert(prefix != null); if (xmlNamespace.Length > 0 || prefix.Length > 0) { dict[prefix] = xmlNamespace; } else { // default namespace redeclared to "" -> remove from list dict.Remove(prefix); } } return dict; }
public override Namespace VisitNamespace(Namespace nspace) { if (nspace == null) return null; Scope savedScope = this.scope; NamespaceScope ns = new NamespaceScope(); ns.AssociatedNamespace = nspace; this.scope = ns; Namespace result = base.VisitNamespace(nspace); this.scope = savedScope; return result; }
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); }
public virtual MemberList LookupAnonymousMembers(Identifier identifier, NamespaceScope nsScope){ if (identifier == null || nsScope == null){Debug.Assert(false); return null;} MemberList result = null; Namespace nspace = nsScope.AssociatedNamespace; if (nspace == null){Debug.Assert(false); return null;} TypeNodeList anonTypes = null; if (this.anonTableForNamespace == null) this.anonTableForNamespace = new TrivialHashtable(); TrivialHashtable anonTable = (TrivialHashtable)this.anonTableForNamespace[nspace.UniqueKey]; if (anonTable == null) this.anonTableForNamespace[nspace.UniqueKey] = anonTable = new TrivialHashtable(); anonTypes = (TypeNodeList)anonTable[identifier.UniqueIdKey]; if (anonTypes == null) anonTable[identifier.UniqueIdKey] = anonTypes = new TypeNodeList(1); else if (anonTypes.Count == 0) return null; this.LookupAnonymousTypes(nspace.Name, anonTypes); UsedNamespaceList usedNamespaces = nspace.UsedNamespaces; for (int i = 0, n = usedNamespaces == null ? 0 : usedNamespaces.Count; i < n; i++){ UsedNamespace uns = usedNamespaces[i]; if (uns == null) continue; this.LookupAnonymousTypes(uns.Namespace, anonTypes); } for (int i = 0, n = anonTypes.Count; i < n; i++){ TypeNode type = anonTypes[i]; if (type == null) continue; MemberList members = this.GetTypeView(type).GetMembersNamed(identifier); for (int j = 0, m = members == null ? 0 : members.Count; j < m; j++){ Member member = members[j]; if (member == null || member is TypeNode || !member.IsStatic) continue; TypeNode dummy = this.currentType; if (Checker.NotAccessible(member, ref dummy, this.currentModule, this.currentType, this.TypeViewer)) continue; if (result == null) result = new MemberList(m-j); result.Add(member); } } return result; }