本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.CType.AsAggregateType方法的典型用法代码示例。如果您正苦于以下问题:C# CType.AsAggregateType方法的具体用法?C# CType.AsAggregateType怎么用?C# CType.AsAggregateType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.CType
的用法示例。
在下文中一共展示了CType.AsAggregateType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserDefinedBinopArgumentType
private AggregateType GetUserDefinedBinopArgumentType(CType type)
{
for (; ;)
{
switch (type.GetTypeKind())
{
case TypeKind.TK_NullableType:
type = type.StripNubs();
break;
case TypeKind.TK_TypeParameterType:
type = type.AsTypeParameterType().GetEffectiveBaseClass();
break;
case TypeKind.TK_AggregateType:
if ((type.isClassType() || type.isStructType()) && !type.AsAggregateType().getAggregate().IsSkipUDOps())
{
return type.AsAggregateType();
}
return null;
default:
return null;
}
}
}
示例2: UpperBoundInterfaceInference
////////////////////////////////////////////////////////////////////////////////
private bool UpperBoundInterfaceInference(AggregateType pSource, CType pDest)
{
if (!pSource.isInterfaceType())
{
return false;
}
// SPEC: Otherwise, if U is an interface CType C<U1...Uk> and V is a class CType
// SPEC: or struct CType and there is a unique set V1...Vk such that V directly
// SPEC: or indirectly implements C<V1...Vk> then an exact ...
// SPEC: ... and U is an interface CType ...
if (!pDest.isStructType() && !pDest.isClassType() &&
!pDest.isInterfaceType())
{
return false;
}
var interfaces = pDest.AllPossibleInterfaces();
AggregateType pInterface = null;
foreach (AggregateType pCurrent in interfaces)
{
if (pCurrent.GetOwningAggregate() == pSource.GetOwningAggregate())
{
if (pInterface == null)
{
pInterface = pCurrent;
}
else if (pInterface != pCurrent)
{
// Not unique. Bail out.
return false;
}
}
}
if (pInterface == null)
{
return false;
}
UpperBoundTypeArgumentInference(pInterface, pDest.AsAggregateType());
return true;
}
示例3: DoesOutputTypeContain
////////////////////////////////////////////////////////////////////////////////
//
// Output types
//
private bool DoesOutputTypeContain(EXPR pSource, CType pDest,
TypeParameterType pParam)
{
// SPEC: If E is a method group or an anonymous function and T is a delegate
// SPEC: CType or expression tree CType then the return CType of T is an output CType
// SPEC: of E with CType T.
pDest = pDest.GetDelegateTypeOfPossibleExpression();
if (!pDest.isDelegateType())
{
return false;
}
if (!pSource.isUNBOUNDLAMBDA() && !pSource.isMEMGRP())
{
return false;
}
CType pDelegateReturn = pDest.AsAggregateType().GetDelegateReturnType(GetSymbolLoader());
if (pDelegateReturn == null)
{
return false;
}
return TypeManager.TypeContainsType(pDelegateReturn, pParam);
}
示例4: LowerBoundClassInference
////////////////////////////////////////////////////////////////////////////////
private bool LowerBoundClassInference(CType pSource, AggregateType pDest)
{
if (!pDest.isClassType())
{
return false;
}
// SPEC: Otherwise, if V is a class CType C<V1...Vk> and U is a class CType which
// SPEC: inherits directly or indirectly from C<U1...Uk>
// SPEC: then an exact inference is made from each Ui to the corresponding Vi.
// SPEC: Otherwise, if V is a class CType C<V1...Vk> and U is a CType parameter
// SPEC: with effective base class C<U1...Uk>
// SPEC: then an exact inference is made from each Ui to the corresponding Vi.
// SPEC: Otherwise, if V is a class CType C<V1...Vk> and U is a CType parameter
// SPEC: with an effective base class which inherits directly or indirectly from
// SPEC: C<U1...Uk> then an exact inference is made
// SPEC: from each Ui to the corresponding Vi.
AggregateType pSourceBase = null;
if (pSource.isClassType())
{
pSourceBase = pSource.AsAggregateType().GetBaseClass();
}
else if (pSource.IsTypeParameterType())
{
pSourceBase = pSource.AsTypeParameterType().GetEffectiveBaseClass();
}
while (pSourceBase != null)
{
if (pSourceBase.GetOwningAggregate() == pDest.GetOwningAggregate())
{
ExactTypeArgumentInference(pSourceBase, pDest);
return true;
}
pSourceBase = pSourceBase.GetBaseClass();
}
return false;
}
示例5: UpperBoundConstructedInference
////////////////////////////////////////////////////////////////////////////////
private bool UpperBoundConstructedInference(CType pSource, CType pDest)
{
if (!pSource.IsAggregateType())
{
return false;
}
AggregateType pConstructedSource = pSource.AsAggregateType();
TypeArray pSourceArgs = pConstructedSource.GetTypeArgsAll();
if (pSourceArgs.size == 0)
{
return false;
}
// SPEC: Otherwise, if V is a constructed CType C<V1...Vk> and U is
// SPEC: C<U1...Uk> then an exact inference,
// SPEC: lower bound inference or upper bound inference
// SPEC: is made from each Ui to the corresponding Vi.
if (pDest.IsAggregateType() &&
pConstructedSource.GetOwningAggregate() == pDest.AsAggregateType().GetOwningAggregate())
{
if (pDest.isInterfaceType() || pDest.isDelegateType())
{
UpperBoundTypeArgumentInference(pConstructedSource, pDest.AsAggregateType());
}
else
{
ExactTypeArgumentInference(pConstructedSource, pDest.AsAggregateType());
}
return true;
}
// SPEC: Otherwise, if U is a class CType C<U1...Uk> and V is a class CType which
// SPEC: inherits directly or indirectly from C<V1...Vk> then an exact ...
if (UpperBoundClassInference(pConstructedSource, pDest))
{
return true;
}
// SPEC: Otherwise, if U is an interface CType C<U1...Uk> and V is a class CType
// SPEC: or struct CType and there is a unique set V1...Vk such that V directly
// SPEC: or indirectly implements C<V1...Vk> then an exact ...
// SPEC: ... and U is an interface CType ...
if (UpperBoundInterfaceInference(pConstructedSource, pDest))
{
return true;
}
return false;
}
示例6: MethodGroupReturnTypeInference
////////////////////////////////////////////////////////////////////////////////
private bool MethodGroupReturnTypeInference(EXPR pSource, CType pType)
{
// SPEC: Otherwise, if E is a method group and T is a delegate CType or
// SPEC: expression tree CType with parameter types T1...Tk and return
// SPEC: CType Tb and overload resolution of E with the types T1...Tk
// SPEC: yields a single method with return CType U then a lower-bound
// SPEC: inference is made from U to Tb.
if (!pSource.isMEMGRP())
{
return false;
}
pType = pType.GetDelegateTypeOfPossibleExpression();
if (!pType.isDelegateType())
{
return false;
}
AggregateType pDelegateType = pType.AsAggregateType();
CType pDelegateReturnType = pDelegateType.GetDelegateReturnType(GetSymbolLoader());
if (pDelegateReturnType == null)
{
return false;
}
if (pDelegateReturnType.IsVoidType())
{
return false;
}
// At this point we are in the second phase; we know that all the input types are fixed.
TypeArray pDelegateParameters = GetFixedDelegateParameters(pDelegateType);
if (pDelegateParameters == null)
{
return false;
}
ArgInfos argInfo = new ArgInfos() { carg = pDelegateParameters.size, types = pDelegateParameters, fHasExprs = false, prgexpr = null };
var argsBinder = new ExpressionBinder.GroupToArgsBinder(_binder, 0/* flags */, pSource.asMEMGRP(), argInfo, null, false, pDelegateType);
bool success = argsBinder.Bind(false);
if (!success)
{
return false;
}
MethPropWithInst mwi = argsBinder.GetResultsOfBind().GetBestResult();
CType pMethodReturnType = GetTypeManager().SubstType(mwi.Meth().RetType,
mwi.GetType(), mwi.TypeArgs);
if (pMethodReturnType.IsVoidType())
{
return false;
}
LowerBoundInference(pMethodReturnType, pDelegateReturnType);
return true;
}
示例7: LowerBoundArrayInference
////////////////////////////////////////////////////////////////////////////////
private bool LowerBoundArrayInference(CType pSource, CType pDest)
{
// SPEC: Otherwise, if U is an array CType Ue[...] and V is either an array
// SPEC: CType Ve[...] of the same rank, or if U is a one-dimensional array
// SPEC: CType Ue[] and V is one of IEnumerable<Ve>, ICollection<Ve>,
// SPEC: IList<Ve>, IReadOnlyCollection<Ve> or IReadOnlyList<Ve> then
// SPEC: if Ue is known to be a reference CType then a lower-bound inference
// SPEC: from Ue to Ve is made.
// SPEC: otherwise an exact inference from Ue to Ve is made.
// Consider the following:
//
// abstract class B<T> { public abstract M<U>(U u) : where U : T; }
// class D : B<int[]> {
// static void M<X>(X[] x) { }
// public override M<U>(U u) { M(u); } // should infer M<int>
// }
if (pSource.IsTypeParameterType())
{
pSource = pSource.AsTypeParameterType().GetEffectiveBaseClass();
}
if (!pSource.IsArrayType())
{
return false;
}
ArrayType pArraySource = pSource.AsArrayType();
CType pElementSource = pArraySource.GetElementType();
CType pElementDest = null;
if (pDest.IsArrayType())
{
ArrayType pArrayDest = pDest.AsArrayType();
if (pArrayDest.rank != pArraySource.rank)
{
return false;
}
pElementDest = pArrayDest.GetElementType();
}
else if (pDest.isPredefType(PredefinedType.PT_G_IENUMERABLE) ||
pDest.isPredefType(PredefinedType.PT_G_ICOLLECTION) ||
pDest.isPredefType(PredefinedType.PT_G_ILIST) ||
pDest.isPredefType(PredefinedType.PT_G_IREADONLYCOLLECTION) ||
pDest.isPredefType(PredefinedType.PT_G_IREADONLYLIST))
{
if (pArraySource.rank != 1)
{
return false;
}
AggregateType pAggregateDest = pDest.AsAggregateType();
pElementDest = pAggregateDest.GetTypeArgsThis().Item(0);
}
else
{
return false;
}
if (pElementSource.IsRefType())
{
LowerBoundInference(pElementSource, pElementDest);
}
else
{
ExactInference(pElementSource, pElementDest);
}
return true;
}
示例8: FindMostDerivedMethod
/////////////////////////////////////////////////////////////////////////////////
public static MethodOrPropertySymbol FindMostDerivedMethod(
SymbolLoader symbolLoader,
MethodOrPropertySymbol pMethProp,
CType pType)
{
MethodSymbol method;
bool bIsIndexer = false;
if (pMethProp.IsMethodSymbol())
{
method = pMethProp.AsMethodSymbol();
}
else
{
PropertySymbol prop = pMethProp.AsPropertySymbol();
method = prop.methGet != null ? prop.methGet : prop.methSet;
if (method == null)
{
return null;
}
bIsIndexer = prop.isIndexer();
}
if (!method.isVirtual)
{
return method;
}
if (pType == null)
{
// This must be a static call.
return method;
}
// Now get the slot method.
if (method.swtSlot != null && method.swtSlot.Meth() != null)
{
method = method.swtSlot.Meth();
}
if (!pType.IsAggregateType())
{
// Not something that can have overrides anyway.
return method;
}
for (AggregateSymbol pAggregate = pType.AsAggregateType().GetOwningAggregate();
pAggregate != null && pAggregate.GetBaseAgg() != null;
pAggregate = pAggregate.GetBaseAgg())
{
for (MethodOrPropertySymbol meth = symbolLoader.LookupAggMember(method.name, pAggregate, symbmask_t.MASK_MethodSymbol | symbmask_t.MASK_PropertySymbol).AsMethodOrPropertySymbol();
meth != null;
meth = symbolLoader.LookupNextSym(meth, pAggregate, symbmask_t.MASK_MethodSymbol | symbmask_t.MASK_PropertySymbol).AsMethodOrPropertySymbol())
{
if (!meth.isOverride)
{
continue;
}
if (meth.swtSlot.Sym != null && meth.swtSlot.Sym == method)
{
if (bIsIndexer)
{
Debug.Assert(meth.IsMethodSymbol());
return meth.AsMethodSymbol().getProperty();
}
else
{
return meth;
}
}
}
}
// If we get here, it means we can have two cases: one is that we have
// a delegate. This is because the delegate invoke method is virtual and is
// an override, but we wont have the slots set up correctly, and will
// not find the base type in the inheritance hierarchy. The second is that
// we're calling off of the base itself.
Debug.Assert(method.parent.IsAggregateSymbol());
return method;
}
示例9: covariant
/***************************************************************************************************
There exists an explicit conversion ...
* From a generic delegate type S to generic delegate type T, provided all of the follow are true:
o Both types are constructed generic types of the same generic delegate type, D<X1,... Xk>.That is,
S is D<S1,... Sk> and T is D<T1,... Tk>.
o S is not compatible with or identical to T.
o If type parameter Xi is declared to be invariant then Si must be identical to Ti.
o If type parameter Xi is declared to be covariant ("out") then Si must be convertible
to Ti via an identify conversion, implicit reference conversion, or explicit reference conversion.
o If type parameter Xi is declared to be contravariant ("in") then either Si must be identical to Ti,
or Si and Ti must both be reference types.
***************************************************************************************************/
public static bool HasGenericDelegateExplicitReferenceConversion(SymbolLoader loader, CType pSource, CType pTarget)
{
if (!pSource.isDelegateType() ||
!pTarget.isDelegateType() ||
pSource.getAggregate() != pTarget.getAggregate() ||
loader.HasIdentityOrImplicitReferenceConversion(pSource, pTarget))
{
return false;
}
TypeArray pTypeParams = pSource.getAggregate().GetTypeVarsAll();
TypeArray pSourceArgs = pSource.AsAggregateType().GetTypeArgsAll();
TypeArray pTargetArgs = pTarget.AsAggregateType().GetTypeArgsAll();
Debug.Assert(pTypeParams.size == pSourceArgs.size);
Debug.Assert(pTypeParams.size == pTargetArgs.size);
for (int iParam = 0; iParam < pTypeParams.size; ++iParam)
{
CType pSourceArg = pSourceArgs.Item(iParam);
CType pTargetArg = pTargetArgs.Item(iParam);
// If they're identical then this one is automatically good, so skip it.
// If we have an error type, then we're in some fault tolerance. Let it through.
if (pSourceArg == pTargetArg || pTargetArg.IsErrorType() || pSourceArg.IsErrorType())
{
continue;
}
TypeParameterType pParam = pTypeParams.Item(iParam).AsTypeParameterType();
if (pParam.Invariant)
{
return false;
}
if (pParam.Covariant)
{
if (!FExpRefConv(loader, pSourceArg, pTargetArg))
{
return false;
}
}
else if (pParam.Contravariant)
{
if (!pSourceArg.IsRefType() || !pTargetArg.IsRefType())
{
return false;
}
}
}
return true;
}
示例10: CheckConstraints
// Check the constraints of any type arguments in the given Type.
public static bool CheckConstraints(CSemanticChecker checker, ErrorHandling errHandling, CType type, CheckConstraintsFlags flags)
{
type = type.GetNakedType(false);
if (type.IsNullableType())
{
CType typeT = type.AsNullableType().GetAts(checker.GetErrorContext());
if (typeT != null)
type = typeT;
else
type = type.GetNakedType(true);
}
if (!type.IsAggregateType())
return true;
AggregateType ats = type.AsAggregateType();
if (ats.GetTypeArgsAll().size == 0)
{
// Common case: there are no type vars, so there are no constraints.
ats.fConstraintsChecked = true;
ats.fConstraintError = false;
return true;
}
if (ats.fConstraintsChecked)
{
// Already checked.
if (!ats.fConstraintError || (flags & CheckConstraintsFlags.NoDupErrors) != 0)
{
// No errors or no need to report errors again.
return !ats.fConstraintError;
}
}
TypeArray typeVars = ats.getAggregate().GetTypeVars();
TypeArray typeArgsThis = ats.GetTypeArgsThis();
TypeArray typeArgsAll = ats.GetTypeArgsAll();
Debug.Assert(typeVars.size == typeArgsThis.size);
if (!ats.fConstraintsChecked)
{
ats.fConstraintsChecked = true;
ats.fConstraintError = false;
}
// Check the outer type first. If CheckConstraintsFlags.Outer is not specified and the
// outer type has already been checked then don't bother checking it.
if (ats.outerType != null && ((flags & CheckConstraintsFlags.Outer) != 0 || !ats.outerType.fConstraintsChecked))
{
CheckConstraints(checker, errHandling, ats.outerType, flags);
ats.fConstraintError |= ats.outerType.fConstraintError;
}
if (typeVars.size > 0)
ats.fConstraintError |= !CheckConstraintsCore(checker, errHandling, ats.getAggregate(), typeVars, typeArgsThis, typeArgsAll, null, (flags & CheckConstraintsFlags.NoErrors));
// Now check type args themselves.
for (int i = 0; i < typeArgsThis.size; i++)
{
CType arg = typeArgsThis.Item(i).GetNakedType(true);
if (arg.IsAggregateType() && !arg.AsAggregateType().fConstraintsChecked)
{
CheckConstraints(checker, errHandling, arg.AsAggregateType(), flags | CheckConstraintsFlags.Outer);
if (arg.AsAggregateType().fConstraintError)
ats.fConstraintError = true;
}
}
return !ats.fConstraintError;
}
示例11: DoesTypeArgumentsContainErrorSym
private bool DoesTypeArgumentsContainErrorSym(CType var)
{
if (!var.IsAggregateType())
{
return false;
}
TypeArray typeVars = var.AsAggregateType().GetTypeArgsAll();
for (int i = 0; i < typeVars.size; i++)
{
CType type = typeVars.Item(i);
if (type.IsErrorType())
{
return true;
}
else if (type.IsAggregateType())
{
// If we have an agg type sym, check if its type args have errors.
if (DoesTypeArgumentsContainErrorSym(type))
{
return true;
}
}
}
return false;
}
示例12: CheckSingleConstraint
//.........这里部分代码省略.........
for (int j = itypeMin; j < bnds.size; j++)
{
CType typeBnd = bnds.Item(j);
if (!SatisfiesBound(checker, arg, typeBnd))
{
if (fReportErrors)
{
// The bound isn't satisfied because of a constaint type. Explain to the user why not.
// There are 4 main cases, based on the type of the supplied type argument:
// - reference type, or type parameter known to be a reference type
// - nullable type, from which there is a boxing conversion to the constraint type(see below for details)
// - type varaiable
// - value type
// These cases are broken out because: a) The sets of conversions which can be used
// for constraint satisfaction is different based on the type argument supplied,
// and b) Nullable is one funky type, and user's can use all the help they can get
// when using it.
ErrorCode error;
if (arg.IsRefType())
{
// A reference type can only satisfy bounds to types
// to which they have an implicit reference conversion
error = ErrorCode.ERR_GenericConstraintNotSatisfiedRefType;
}
else if (arg.IsNullableType() && checker.GetSymbolLoader().HasBaseConversion(arg.AsNullableType().GetUnderlyingType(), typeBnd)) // This is inlining FBoxingConv
{
// nullable types do not satisfy bounds to every type that they are boxable to
// They only satisfy bounds of object and ValueType
if (typeBnd.isPredefType(PredefinedType.PT_ENUM) || arg.AsNullableType().GetUnderlyingType() == typeBnd)
{
// Nullable types don't satisfy bounds of EnumType, or the underlying type of the enum
// even though the conversion from Nullable to these types is a boxing conversion
// This is a rare case, because these bounds can never be directly stated ...
// These bounds can only occur when one type paramter is constrained to a second type parameter
// and the second type parameter is instantiated with Enum or the underlying type of the first type
// parameter
error = ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
}
else
{
// Nullable types don't satisfy the bounds of any interface type
// even when there is a boxing conversion from the Nullable type to
// the interface type. This will be a relatively common scenario
// so we cal it out separately from the previous case.
Debug.Assert(typeBnd.isInterfaceType());
error = ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface;
}
}
else if (arg.IsTypeParameterType())
{
// Type variables can satisfy bounds through boxing and type variable conversions
Debug.Assert(!arg.IsRefType());
error = ErrorCode.ERR_GenericConstraintNotSatisfiedTyVar;
}
else
{
// Value types can only satisfy bounds through boxing conversions.
// Note that the exceptional case of Nullable types and boxing is handled above.
error = ErrorCode.ERR_GenericConstraintNotSatisfiedValType;
}
errHandling.Error(error, new ErrArgRef(symErr), new ErrArg(typeBnd, ErrArgFlags.Unique), var, new ErrArgRef(arg, ErrArgFlags.Unique));
}
fError = true;
}
}
// Check the newable constraint.
if (!var.HasNewConstraint() || arg.IsValType())
{
return !fError;
}
if (arg.isClassType())
{
AggregateSymbol agg = arg.AsAggregateType().getAggregate();
// Due to late binding nature of IDE created symbols, the AggregateSymbol might not
// have all the information necessary yet, if it is not fully bound.
// by calling LookupAggMember, it will ensure that we will update all the
// information necessary at least for the given method.
checker.GetSymbolLoader().LookupAggMember(checker.GetNameManager().GetPredefName(PredefinedName.PN_CTOR), agg, symbmask_t.MASK_ALL);
if (agg.HasPubNoArgCtor() && !agg.IsAbstract())
{
return !fError;
}
}
else if (arg.IsTypeParameterType() && arg.AsTypeParameterType().HasNewConstraint())
{
return !fError;
}
if (fReportErrors)
{
errHandling.ErrorRef(ErrorCode.ERR_NewConstraintNotSatisfied, symErr, new ErrArgNoRef(var), arg);
}
return false;
}
示例13: RemapToOverride
////////////////////////////////////////////////////////////////////////////////
// For a base call we need to remap from the virtual to the specific override
// to invoke. This is also used to map a virtual on pObject (like ToString) to
// the specific override when the pObject is a simple type (int, bool, char,
// etc). In these cases it is safe to assume that any override won't later be
// removed.... We start searching from "typeObj" up the superclass hierarchy
// until we find a method with an exact signature match.
public static void RemapToOverride(SymbolLoader symbolLoader, SymWithType pswt, CType typeObj)
{
// For a property/indexer we remap the accessors, not the property/indexer.
// Since every event has both accessors we remap the event instead of the accessors.
Debug.Assert(pswt && (pswt.Sym.IsMethodSymbol() || pswt.Sym.IsEventSymbol() || pswt.Sym.IsMethodOrPropertySymbol()));
Debug.Assert(typeObj != null);
// Don't remap static or interface methods.
if (typeObj.IsNullableType())
{
typeObj = typeObj.AsNullableType().GetAts(symbolLoader.GetErrorContext());
if (typeObj == null)
{
VSFAIL("Why did GetAts return null?");
return;
}
}
// Don't remap non-virtual members
if (!typeObj.IsAggregateType() || typeObj.isInterfaceType() || !pswt.Sym.IsVirtual())
{
return;
}
symbmask_t mask = pswt.Sym.mask();
AggregateType atsObj = typeObj.AsAggregateType();
// Search for an override version of the method.
while (atsObj != null && atsObj.getAggregate() != pswt.Sym.parent)
{
for (Symbol symT = symbolLoader.LookupAggMember(pswt.Sym.name, atsObj.getAggregate(), mask);
symT != null;
symT = symbolLoader.LookupNextSym(symT, atsObj.getAggregate(), mask))
{
if (symT.IsOverride() && (symT.SymBaseVirtual() == pswt.Sym || symT.SymBaseVirtual() == pswt.Sym.SymBaseVirtual()))
{
pswt.Set(symT, atsObj);
return;
}
}
atsObj = atsObj.GetBaseClass();
}
}
示例14: GetEnumBinOpType
private AggregateType GetEnumBinOpType(ExpressionKind ek, CType argType1, CType argType2, out AggregateType ppEnumType)
{
Debug.Assert(argType1.isEnumType() || argType2.isEnumType());
AggregateType type1 = argType1.AsAggregateType();
AggregateType type2 = argType2.AsAggregateType();
AggregateType typeEnum = type1.isEnumType() ? type1 : type2;
Debug.Assert(type1 == typeEnum || type1 == typeEnum.underlyingEnumType());
Debug.Assert(type2 == typeEnum || type2 == typeEnum.underlyingEnumType());
AggregateType typeDst = typeEnum;
switch (ek)
{
case ExpressionKind.EK_BITAND:
case ExpressionKind.EK_BITOR:
case ExpressionKind.EK_BITXOR:
Debug.Assert(type1 == type2);
break;
case ExpressionKind.EK_ADD:
Debug.Assert(type1 != type2);
break;
case ExpressionKind.EK_SUB:
if (type1 == type2)
typeDst = typeEnum.underlyingEnumType();
break;
default:
Debug.Assert(ek.isRelational());
typeDst = GetReqPDT(PredefinedType.PT_BOOL);
break;
}
ppEnumType = typeEnum;
return typeDst;
}
示例15: TypeContainsTyVars
public static bool TypeContainsTyVars(CType type, TypeArray typeVars)
{
LRecurse: // Label used for "tail" recursion.
switch (type.GetTypeKind())
{
default:
Debug.Assert(false, "Bad Symbol kind in TypeContainsTyVars");
return false;
case TypeKind.TK_UnboundLambdaType:
case TypeKind.TK_BoundLambdaType:
case TypeKind.TK_NullType:
case TypeKind.TK_VoidType:
case TypeKind.TK_OpenTypePlaceholderType:
case TypeKind.TK_MethodGroupType:
return false;
case TypeKind.TK_ArrayType:
case TypeKind.TK_NullableType:
case TypeKind.TK_ParameterModifierType:
case TypeKind.TK_PointerType:
type = type.GetBaseOrParameterOrElementType();
goto LRecurse;
case TypeKind.TK_AggregateType:
{ // BLOCK
AggregateType ats = type.AsAggregateType();
for (int i = 0; i < ats.GetTypeArgsAll().Size; i++)
{
if (TypeContainsTyVars(ats.GetTypeArgsAll().Item(i), typeVars))
{
return true;
}
}
}
return false;
case TypeKind.TK_ErrorType:
if (type.AsErrorType().HasParent())
{
ErrorType err = type.AsErrorType();
Debug.Assert(err.nameText != null && err.typeArgs != null);
for (int i = 0; i < err.typeArgs.Size; i++)
{
if (TypeContainsTyVars(err.typeArgs.Item(i), typeVars))
{
return true;
}
}
if (err.HasTypeParent())
{
type = err.GetTypeParent();
goto LRecurse;
}
}
return false;
case TypeKind.TK_TypeParameterType:
if (typeVars != null && typeVars.Size > 0)
{
int ivar = type.AsTypeParameterType().GetIndexInTotalParameters();
return ivar < typeVars.Size && type == typeVars.Item(ivar);
}
return true;
}
}