public bool IsBaseAggregate(AggregateSymbol derived, AggregateSymbol @base) { Debug.Assert(!derived.IsEnum() && [email protected]()); if (derived == @base) { return(true); // identity. } // refactoring error tolerance: structs and delegates can be base classes in error scenarios so // we cannot filter on whether or not the base is marked as sealed. if (@base.IsInterface()) { // Search the direct and indirect interfaces via ifacesAll, going up the base chain... while (derived != null) { for (int i = 0; i < derived.GetIfacesAll().Count; i++) { AggregateType iface = derived.GetIfacesAll()[i].AsAggregateType(); if (iface.getAggregate() == @base) { return(true); } } derived = derived.GetBaseAgg(); } return(false); } // base is a class. Just go up the base class chain to look for it. while (derived.GetBaseClass() != null) { derived = derived.GetBaseClass().getAggregate(); if (derived == @base) { return(true); } } return(false); }
//////////////////////////////////////////////////////////////////////////////// // Given a symbol, determine its fundamental type. This is the type that // indicate how the item is stored and what instructions are used to reference // if. The fundamental types are: // one of the integral/float types (includes enums with that underlying type) // reference type // struct/value type public FUNDTYPE fundType() { switch (GetTypeKind()) { case TypeKind.TK_AggregateType: { AggregateSymbol sym = ((AggregateType)this).getAggregate(); // Treat enums like their underlying types. if (sym.IsEnum()) { sym = sym.GetUnderlyingType().getAggregate(); } if (sym.IsStruct()) { // Struct type could be predefined (int, long, etc.) or some other struct. if (sym.IsPredefined()) { return(PredefinedTypeFacts.GetFundType(sym.GetPredefType())); } return(FUNDTYPE.FT_STRUCT); } return(FUNDTYPE.FT_REF); // Interfaces, classes, delegates are reference types. } case TypeKind.TK_TypeParameterType: return(FUNDTYPE.FT_VAR); case TypeKind.TK_ArrayType: case TypeKind.TK_NullType: return(FUNDTYPE.FT_REF); case TypeKind.TK_PointerType: return(FUNDTYPE.FT_PTR); case TypeKind.TK_NullableType: return(FUNDTYPE.FT_STRUCT); default: return(FUNDTYPE.FT_NONE); } }
public bool IsBaseAggregate(AggregateSymbol derived, AggregateSymbol @base) { Debug.Assert(!derived.IsEnum() && [email protected]()); if (derived == @base) return true; // identity. // refactoring error tolerance: structs and delegates can be base classes in error scenarios so // we cannot filter on whether or not the base is marked as sealed. if (@base.IsInterface()) { // Search the direct and indirect interfaces via ifacesAll, going up the base chain... while (derived != null) { for (int i = 0; i < derived.GetIfacesAll().Size; i++) { AggregateType iface = derived.GetIfacesAll().Item(i).AsAggregateType(); if (iface.getAggregate() == @base) return true; } derived = derived.GetBaseAgg(); } return false; } // base is a class. Just go up the base class chain to look for it. while (derived.GetBaseClass() != null) { derived = derived.GetBaseClass().getAggregate(); if (derived == @base) return true; } return false; }