/// <summary> /// Merges this namespace definition with <paramref name="otherScope"/>. This happens when <c>otherScope.CanBeMergedInto(this)</c> evaluates to true. /// </summary> /// <param name="otherScope">the scope to merge with</param> /// <returns>a new namespace definition from this and otherScope, or null if they couldn't be merged.</returns> public override NamedScope Merge(NamedScope otherScope) { NamespaceDefinition mergedScope = null; if(otherScope != null) { if(otherScope.CanBeMergedInto(this)) { mergedScope = new NamespaceDefinition(this); mergedScope.AddFrom(otherScope); } } return mergedScope; }
/// <summary> /// Merges this method definition with <paramref name="otherScope"/>. This happens when <c>otherScope.CanBeMergedInto(this)</c> evaluates to true. /// </summary> /// <param name="otherScope">the scope to merge with</param> /// <returns>a new method definition from this and otherScope, or null if they couldn't be merged.</returns> public override NamedScope Merge(NamedScope otherScope) { MethodDefinition mergedScope = null; if(otherScope != null) { if(otherScope.CanBeMergedInto(this)) { mergedScope = new MethodDefinition(this); mergedScope.AddFrom(otherScope); if(mergedScope.Accessibility == AccessModifier.None) { mergedScope.Accessibility = otherScope.Accessibility; } } } return mergedScope; }
/// <summary> /// Merges two NamedVariableScopes together. It works like this: /// <list type="bullet"> /// <item><description>If this is the same type or more specific than <paramref name="otherScope"/>, then create a new merged NamedScope /// from <paramref name="otherScope"/> and this.</description></item> /// <item><description>If <paramref name="otherScope"/> is more specific than this, call <c>otherScope.Merge</c></description></item> /// </list> /// </summary> /// <param name="otherScope">The scope to merge with</param> /// <returns>The new merged scope; null if they couldn't be merged</returns> public virtual NamedScope Merge(NamedScope otherScope) { NamedScope mergedScope = null; if(otherScope != null) { if(otherScope.CanBeMergedInto(this)) { // this and other scope can be merged normally // either they are the same type or // this is a subclass of NamedScope and otherScope is a NamedScope mergedScope = new NamedScope(this); mergedScope.AddFrom(otherScope); } else if(this.CanBeMergedInto(otherScope) && !otherScope.CanBeMergedInto(this)) { // this is a NamedScope and otherScope is a subclass // useful information (type, method, or namespace data) are in otherScope mergedScope = otherScope.Merge(this); } } return mergedScope; }