//------------------------------------------------------------ // MetaDataHelper.GetExplicitImplTypeName // /// <summary></summary> /// <param name="typeSym"></param> /// <param name="strBuilder"></param> //------------------------------------------------------------ public void GetExplicitImplTypeName(TYPESYM typeSym, StringBuilder strBuilder) { #if DEBUG if (!(typeSym != null)) { ; } #endif DebugUtil.Assert(typeSym != null); TYPESYM nakedTypeSym = typeSym.GetNakedType(false); TypeArray typeArgs = null; switch (nakedTypeSym.Kind) { default: DebugUtil.Assert(false, "Unhandled type in GetExplicitImplTypeName"); return; case SYMKIND.TYVARSYM: strBuilder.Append(nakedTypeSym.Name); break; case SYMKIND.NUBSYM: nakedTypeSym = (nakedTypeSym as NUBSYM).GetAggTypeSym(); if (nakedTypeSym == null) { DebugUtil.Assert(false, "Why did GetAts return null?"); return; } // Fall through. goto case SYMKIND.AGGTYPESYM; case SYMKIND.AGGTYPESYM: { AGGTYPESYM outerAggTypeSym = (nakedTypeSym as AGGTYPESYM).OuterTypeSym; AGGSYM aggSym = nakedTypeSym.GetAggregate(); if (outerAggTypeSym != null) { GetExplicitImplTypeName(outerAggTypeSym, strBuilder); strBuilder.Append('.'); } else { DebugUtil.Assert(aggSym.ParentBagSym != null && !aggSym.ParentBagSym.IsAGGSYM); int cch = strBuilder.Length; GetFullName(aggSym.ParentBagSym, strBuilder, aggSym); if (cch < strBuilder.Length) { strBuilder.Append('.'); } } strBuilder.Append(aggSym.Name); typeArgs = (nakedTypeSym as AGGTYPESYM).TypeArguments; } break; case SYMKIND.ERRORSYM: { ERRORSYM errSym = nakedTypeSym as ERRORSYM; SYM parentSym = errSym.ParentSym; if (parentSym != null && parentSym.IsTYPESYM) { GetExplicitImplTypeName(parentSym as TYPESYM, strBuilder); strBuilder.Append('.'); } else if (parentSym != null && parentSym.IsNSAIDSYM) { parentSym = (parentSym as NSAIDSYM).NamespaceSym; int cch = strBuilder.Length; GetFullName(parentSym, strBuilder, errSym); if (cch < strBuilder.Length) { strBuilder.Append('.'); } } strBuilder.Append(errSym.ErrorName); typeArgs = errSym.TypeArguments; } break; } if (typeArgs != null && typeArgs.Count > 0) { strBuilder.Append('<'); for (int i = 0; i < typeArgs.Count; ++i) { if (i > 0) { strBuilder.Append(','); } GetExplicitImplTypeName(typeArgs[i], strBuilder); } strBuilder.Append('>'); } // Add ptr and array modifiers AddTypeModifiers(typeSym, strBuilder); }
//------------------------------------------------------------ // MetaDataHelper.GetExplicitImplName // /// <summary> /// Get a synthesized name for explicit interface implementations. /// The name we use is: "InterfaceName.MethodName", where InterfaceName is the fully qualified name /// of the interface containing the implemented method. /// This name has a '.' in it, so it can't conflict with any "real" name or be confused with one. /// </summary> /// <remarks> /// Returns true if the buffer had enough space for the name. /// If not enough space, then adds as much of name as possible to buffer. /// Always NULL terminates buffer. /// </remarks> /// <param name="sym"></param> /// <param name="strBuilder"></param> //------------------------------------------------------------ public void GetExplicitImplName(SYM sym, StringBuilder strBuilder) { DebugUtil.Assert(sym.IsEVENTSYM || sym.IsMETHPROPSYM); SymWithType swtImpl = new SymWithType(); ERRORSYM errSym = null; string implName = null; string aliasName = null; switch (sym.Kind) { case SYMKIND.EVENTSYM: EVENTSYM eventSym = sym as EVENTSYM; DebugUtil.Assert(eventSym.IsExpImpl); swtImpl = eventSym.SlotEventWithType; errSym = eventSym.ExpImplErrorSym; break; case SYMKIND.METHSYM: case SYMKIND.PROPSYM: { METHPROPSYM mpSym = sym as METHPROPSYM; DebugUtil.Assert(mpSym.IsExplicitImplementation); swtImpl = mpSym.SlotSymWithType; errSym = mpSym.ExpImplErrorSym; BASENODE nameNode = null; if (sym.IsMETHSYM && (sym as METHSYM).ParseTreeNode != null && (sym as METHSYM).ParseTreeNode.Kind == NODEKIND.METHOD) { nameNode = ((sym as METHSYM).ParseTreeNode as METHODNODE).NameNode; } else if ( sym.IsPROPSYM && (sym as PROPSYM).ParseTreeNode != null && (sym as PROPSYM).ParseTreeNode.Kind == NODEKIND.PROPERTY) { nameNode = ((sym as PROPSYM).ParseTreeNode as PROPERTYNODE).NameNode; } while (nameNode != null && nameNode.Kind == NODEKIND.DOT) { nameNode = nameNode.AsDOT.Operand1; } if (nameNode != null && nameNode.Kind == NODEKIND.ALIASNAME) { aliasName = nameNode.AsANYNAME.Name; } if (!sym.IsPROPSYM || !(sym as PROPSYM).IsIndexer) { break; } implName = (swtImpl != null ? (swtImpl.Sym as PROPSYM).GetRealName() : "Item"); // fish out any user specified alias break; } default: // gcc -Wall (all warnings enabled) complains if all cases // aren't handled, so we explicitly handle default and assert DebugUtil.Assert(false); break; } DebugUtil.Assert(swtImpl != null || errSym != null); if (aliasName != null) { strBuilder.Append(aliasName); strBuilder.Append("::"); } if (swtImpl != null) { GetExplicitImplTypeName(swtImpl.AggTypeSym, strBuilder); if (implName == null) { implName = swtImpl.Sym.Name; } } else { GetExplicitImplTypeName(errSym, strBuilder); } if (implName != null) { // Add dot seperator. strBuilder.Append('.'); strBuilder.Append(implName); } }