本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap类的典型用法代码示例。如果您正苦于以下问题:C# TypeMap类的具体用法?C# TypeMap怎么用?C# TypeMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeMap类属于Microsoft.CodeAnalysis.CSharp.Symbols命名空间,在下文中一共展示了TypeMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SynthesizedContainer
internal SynthesizedContainer(MethodSymbol topLevelMethod, string name, TypeKind typeKind)
{
this.typeKind = typeKind;
this.containingSymbol = topLevelMethod.ContainingType;
this.name = name;
this.TypeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out this.typeParameters);
}
开发者ID:riversky,项目名称:roslyn,代码行数:7,代码来源:SynthesizedContainer.cs
示例2: SubstitutedParameterSymbol
private SubstitutedParameterSymbol(Symbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) :
base(originalParameter)
{
Debug.Assert(originalParameter.IsDefinition);
_containingSymbol = containingSymbol;
_mapOrType = map;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:SubstitutedParameterSymbol.cs
示例3: SynthesizedContainer
protected SynthesizedContainer(string name, int parameterCount, bool returnsVoid)
{
Debug.Assert(name != null);
this.name = name;
this.typeMap = TypeMap.Empty;
this.typeParameters = CreateTypeParameters(parameterCount, returnsVoid);
}
开发者ID:pheede,项目名称:roslyn,代码行数:7,代码来源:SynthesizedContainer.cs
示例4: SynthesizedContainer
protected SynthesizedContainer(string name, int parameterCount, bool returnsVoid)
{
Debug.Assert(name != null);
_name = name;
_typeMap = TypeMap.Empty;
_typeParameters = CreateTypeParameters(parameterCount, returnsVoid);
_constructedFromTypeParameters = default(ImmutableArray<TypeParameterSymbol>);
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:8,代码来源:SynthesizedContainer.cs
示例5: SubstitutedTypeParameterSymbol
internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom)
{
_container = newContainer;
// it is important that we don't use the map here in the constructor, as the map is still being filled
// in by TypeMap.WithAlphaRename. Instead, we can use the map lazily when yielding the constraints.
_map = map;
_substitutedFrom = substitutedFrom;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:SubstitutedTypeParameterSymbol.cs
示例6: ToOtherMethod
internal override DisplayClassInstance ToOtherMethod(MethodSymbol method, TypeMap typeMap)
{
Debug.Assert(method.IsStatic);
var otherOrdinal = this.ContainingSymbol.IsStatic
? this.Parameter.Ordinal
: (this.Parameter.Ordinal + 1);
var otherParameter = method.Parameters[otherOrdinal];
return new DisplayClassInstanceFromParameter(otherParameter);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:DisplayClassInstance.cs
示例7: AssignTypeMapAndTypeParameters
protected void AssignTypeMapAndTypeParameters(TypeMap typeMap, ImmutableArray<TypeParameterSymbol> typeParameters)
{
Debug.Assert(typeMap != null);
Debug.Assert(this.TypeMap == null);
Debug.Assert(!typeParameters.IsDefault);
Debug.Assert(_typeParameters.IsDefault);
this.TypeMap = typeMap;
_typeParameters = typeParameters;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:SynthesizedMethodBaseSymbol.cs
示例8: ExpressionLambdaRewriter
private ExpressionLambdaRewriter(TypeCompilationState compilationState, TypeMap typeMap, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
Bound = new SyntheticBoundNodeFactory(null, null, node, compilationState, diagnostics);
Int32Type = Bound.SpecialType(SpecialType.System_Int32);
ObjectType = Bound.SpecialType(SpecialType.System_Object);
NullableType = Bound.SpecialType(SpecialType.System_Nullable_T);
IEnumerableType = Bound.SpecialType(SpecialType.System_Collections_Generic_IEnumerable_T);
this.typeMap = typeMap;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:ExpressionLambdaRewriter.cs
示例9: ToOtherMethod
internal static LocalSymbol ToOtherMethod(this LocalSymbol local, MethodSymbol method, TypeMap typeMap)
{
var l = local as EELocalSymbolBase;
if ((object)l != null)
{
return l.ToOtherMethod(method, typeMap);
}
var type = typeMap.SubstituteType(local.Type);
return new EELocalSymbol(method, local.Locations, local.Name, -1, local.DeclarationKind, type.Type, local.RefKind, local.IsPinned, local.IsCompilerGenerated, local.CanScheduleToStack);
}
开发者ID:noahfalk,项目名称:roslyn,代码行数:10,代码来源:EELocalSymbolBase.cs
示例10: SynthesizedContainer
protected SynthesizedContainer(string name, ImmutableArray<TypeParameterSymbol> typeParameters, TypeMap typeMap)
{
Debug.Assert(name != null);
Debug.Assert(!typeParameters.IsDefault);
Debug.Assert(typeMap != null);
Name = name;
_typeParameters = typeParameters;
TypeMap = typeMap;
}
开发者ID:jkotas,项目名称:roslyn,代码行数:10,代码来源:SynthesizedContainer.cs
示例11: SubstituteFields
private static ConsList<FieldSymbol> SubstituteFields(ConsList<FieldSymbol> fields, TypeMap typeMap)
{
if (!fields.Any())
{
return ConsList<FieldSymbol>.Empty;
}
var head = SubstituteField(fields.Head, typeMap);
var tail = SubstituteFields(fields.Tail, typeMap);
return tail.Prepend(head);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:11,代码来源:DisplayClassVariable.cs
示例12: SubstitutedTypeParameterSymbol
internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal)
{
_container = newContainer;
// it is important that we don't use the map here in the constructor, as the map is still being filled
// in by TypeMap.WithAlphaRename. Instead, we can use the map lazily when yielding the constraints.
_map = map;
_substitutedFrom = substitutedFrom;
_ordinal = ordinal;
#if DEBUG_ALPHA
_mySequence = _nextSequence++;
#endif
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:12,代码来源:SubstitutedTypeParameterSymbol.cs
示例13: SubstitutedNamedTypeSymbol
protected SubstitutedNamedTypeSymbol(Symbol newContainer, TypeMap map, NamedTypeSymbol originalDefinition, NamedTypeSymbol constructedFrom = null, bool unbound = false)
{
Debug.Assert(originalDefinition.IsDefinition);
_originalDefinition = originalDefinition;
_newContainer = newContainer;
_inputMap = map;
_unbound = unbound;
// if we're substituting to create a new unconstructed type as a member of a constructed type,
// then we must alpha rename the type parameters.
if ((object)constructedFrom != null)
{
Debug.Assert(ReferenceEquals(constructedFrom.ConstructedFrom, constructedFrom));
_lazyTypeParameters = constructedFrom.TypeParameters;
_lazyMap = map;
}
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:17,代码来源:SubstitutedNamedTypeSymbol.cs
示例14: SubstitutedMethodSymbol
protected SubstitutedMethodSymbol(NamedTypeSymbol containingSymbol, TypeMap map, MethodSymbol originalDefinition, MethodSymbol constructedFrom)
{
Debug.Assert(originalDefinition.IsDefinition);
_containingType = containingSymbol;
this.originalDefinition = originalDefinition;
_inputMap = map;
if ((object)constructedFrom != null)
{
_constructedFrom = constructedFrom;
Debug.Assert(ReferenceEquals(constructedFrom.ConstructedFrom, constructedFrom));
_lazyTypeParameters = constructedFrom.TypeParameters;
_lazyMap = map;
}
else
{
_constructedFrom = this;
}
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:18,代码来源:SubstitutedMethodSymbol.cs
示例15: InferExtensionMethodTypeArguments
/// <summary>
/// If the extension method is applicable based on the "this" argument type, return
/// the method constructed with the inferred type arguments. If the method is not an
/// unconstructed generic method, type inference is skipped. If the method is not
/// applicable, or if constraints when inferring type parameters from the "this" type
/// are not satisfied, the return value is null.
/// </summary>
public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol method, TypeSymbol thisType, Compilation compilation, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert(method.IsExtensionMethod);
Debug.Assert((object)thisType != null);
if (!method.IsGenericMethod || method != method.ConstructedFrom)
{
return method;
}
// We never resolve extension methods on a dynamic receiver.
if (thisType.IsDynamic())
{
return null;
}
var containingAssembly = method.ContainingAssembly;
var errorNamespace = containingAssembly.GlobalNamespace;
var conversions = new TypeConversions(containingAssembly.CorLibrary);
// There is absolutely no plausible syntax/tree that we could use for these
// synthesized literals. We could be speculatively binding a call to a PE method.
var syntaxTree = CSharpSyntaxTree.Dummy;
var syntax = (CSharpSyntaxNode)syntaxTree.GetRoot();
// Create an argument value for the "this" argument of specific type,
// and pass the same bad argument value for all other arguments.
var thisArgumentValue = new BoundLiteral(syntax, ConstantValue.Bad, thisType) { WasCompilerGenerated = true };
var otherArgumentType = new ExtendedErrorTypeSymbol(errorNamespace, name: string.Empty, arity: 0, errorInfo: null, unreported: false);
var otherArgumentValue = new BoundLiteral(syntax, ConstantValue.Bad, otherArgumentType) { WasCompilerGenerated = true };
var paramCount = method.ParameterCount;
var arguments = new BoundExpression[paramCount];
var argumentTypes = new TypeSymbol[paramCount];
for (int i = 0; i < paramCount; i++)
{
var argument = (i == 0) ? thisArgumentValue : otherArgumentValue;
arguments[i] = argument;
argumentTypes[i] = argument.Type;
}
var typeArgs = MethodTypeInferrer.InferTypeArgumentsFromFirstArgument(
conversions,
method,
argumentTypes.AsImmutableOrNull(),
arguments.AsImmutableOrNull(),
ref useSiteDiagnostics);
if (typeArgs.IsDefault)
{
return null;
}
int firstNullInTypeArgs = -1;
// For the purpose of constraint checks we use error type symbol in place of type arguments that we couldn't infer from the first argument.
// This prevents constraint checking from failing for corresponding type parameters.
var typeArgsForConstraintsCheck = typeArgs;
for (int i = 0; i < typeArgsForConstraintsCheck.Length; i++)
{
if ((object)typeArgsForConstraintsCheck[i] == null)
{
firstNullInTypeArgs = i;
var builder = ArrayBuilder<TypeSymbol>.GetInstance();
builder.AddRange(typeArgs, firstNullInTypeArgs);
for (; i < typeArgsForConstraintsCheck.Length; i++)
{
builder.Add(typeArgsForConstraintsCheck[i] ?? ErrorTypeSymbol.UnknownResultType);
}
typeArgsForConstraintsCheck = builder.ToImmutableAndFree();
break;
}
}
// Check constraints.
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
var typeParams = method.TypeParameters;
var substitution = new TypeMap(typeParams, typeArgsForConstraintsCheck.SelectAsArray(TypeMap.TypeSymbolAsTypeWithModifiers));
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var success = method.CheckConstraints(conversions, substitution, typeParams, typeArgsForConstraintsCheck, compilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder);
diagnosticsBuilder.Free();
if (useSiteDiagnosticsBuilder != null && useSiteDiagnosticsBuilder.Count > 0)
{
if (useSiteDiagnostics == null)
{
useSiteDiagnostics = new HashSet<DiagnosticInfo>();
}
foreach (var diag in useSiteDiagnosticsBuilder)
{
//.........这里部分代码省略.........
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:101,代码来源:MethodSymbolExtensions.cs
示例16: CheckConstraints
// See TypeBind::CheckSingleConstraint.
private static bool CheckConstraints(
Symbol containingSymbol,
ConversionsBase conversions,
TypeMap substitution,
TypeParameterSymbol typeParameter,
TypeSymbol typeArgument,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt)
{
Debug.Assert(substitution != null);
// The type parameters must be original definitions of type parameters from the containing symbol.
Debug.Assert(ReferenceEquals(typeParameter.ContainingSymbol, containingSymbol.OriginalDefinition));
if (typeArgument.IsErrorType())
{
return true;
}
if (typeArgument.IsPointerType() || typeArgument.IsRestrictedType() || typeArgument.SpecialType == SpecialType.System_Void)
{
// "The type '{0}' may not be used as a type argument"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_BadTypeArgument, typeArgument)));
return false;
}
if (typeArgument.IsStatic)
{
// "'{0}': static types cannot be used as type arguments"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_GenericArgIsStaticClass, typeArgument)));
return false;
}
if (typeParameter.HasReferenceTypeConstraint && !typeArgument.IsReferenceType)
{
// "The type '{2}' must be a reference type in order to use it as parameter '{1}' in the generic type or method '{0}'"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_RefConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument)));
return false;
}
if (typeParameter.HasValueTypeConstraint && !typeArgument.IsNonNullableValueType())
{
// "The type '{2}' must be a non-nullable value type in order to use it as parameter '{1}' in the generic type or method '{0}'"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_ValConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument)));
return false;
}
// The type parameters for a constructed type/method are the type parameters of
// the ConstructedFrom type/method, so the constraint types are not substituted.
// For instance with "class C<T, U> where T : U", the type parameter for T in "C<object, int>"
// has constraint "U", not "int". We need to substitute the constraints from the
// original definition of the type parameters using the map from the constructed symbol.
var constraintTypes = ArrayBuilder<TypeSymbol>.GetInstance();
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
substitution.SubstituteTypesDistinctWithoutModifiers(typeParameter.ConstraintTypesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), constraintTypes,
ignoreTypeConstraintsDependentOnTypeParametersOpt);
bool hasError = false;
foreach (var constraintType in constraintTypes)
{
if (SatisfiesConstraintType(conversions, typeArgument, constraintType, ref useSiteDiagnostics))
{
continue;
}
ErrorCode errorCode;
if (typeArgument.IsReferenceType)
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedRefType;
}
else if (typeArgument.IsNullableType())
{
errorCode = constraintType.IsInterfaceType() ? ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface : ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
}
else if (typeArgument.TypeKind == TypeKind.TypeParameter)
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedTyVar;
}
else
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedValType;
}
SymbolDistinguisher distinguisher = new SymbolDistinguisher(currentCompilation, constraintType, typeArgument);
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(errorCode, containingSymbol.ConstructedFrom(), distinguisher.First, typeParameter, distinguisher.Second)));
hasError = true;
}
if (AppendUseSiteDiagnostics(useSiteDiagnostics, typeParameter, ref useSiteDiagnosticsBuilder))
{
hasError = true;
}
constraintTypes.Free();
// Check the constructor constraint.
if (typeParameter.HasConstructorConstraint && !SatisfiesConstructorConstraint(typeArgument))
//.........这里部分代码省略.........
开发者ID:XieShuquan,项目名称:roslyn,代码行数:101,代码来源:ConstraintsHelper.cs
示例17: TypeMap
public void TypeMap()
{
var source = @"
struct S<T> where T : struct
{
}
";
var comp = CreateCompilationWithMscorlib(source);
comp.VerifyDiagnostics();
var intType = comp.GetSpecialType(SpecialType.System_Int32);
var customModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateOptional(intType));
var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
var typeParamType = structType.TypeParameters.Single();
var pointerType = new PointerTypeSymbol(typeParamType, customModifiers); // NOTE: We're constructing this manually, since it's illegal.
var arrayType = new ArrayTypeSymbol(comp.Assembly, typeParamType, customModifiers); // This is legal, but we're already manually constructing types.
var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create<TypeSymbol>(intType));
var substitutedPointerType = (PointerTypeSymbol)typeMap.SubstituteType(pointerType);
var substitutedArrayType = (ArrayTypeSymbol)typeMap.SubstituteType(arrayType);
// The map changed the types.
Assert.Equal(intType, substitutedPointerType.PointedAtType);
Assert.Equal(intType, substitutedArrayType.ElementType);
// The map preserved the custom modifiers.
Assert.Equal(customModifiers, substitutedPointerType.CustomModifiers);
Assert.Equal(customModifiers, substitutedArrayType.CustomModifiers);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:ModifierTests.cs
示例18: HaveSameConstraints
private static bool HaveSameConstraints(ImmutableArray<TypeParameterSymbol> candidateTypeParameters, ImmutableArray<TypeParameterSymbol> desiredTypeParameters)
{
int arity = candidateTypeParameters.Length;
if (arity != desiredTypeParameters.Length)
{
return false;
}
else if (arity == 0)
{
return true;
}
var indexedTypeParameters = IndexedTypeParameterSymbol.Take(arity);
var candidateTypeMap = new TypeMap(candidateTypeParameters, indexedTypeParameters, allowAlpha: true);
var desiredTypeMap = new TypeMap(desiredTypeParameters, indexedTypeParameters, allowAlpha: true);
return MemberSignatureComparer.HaveSameConstraints(candidateTypeParameters, candidateTypeMap, desiredTypeParameters, desiredTypeMap);
}
开发者ID:rgani,项目名称:roslyn,代码行数:18,代码来源:CompilationContext.cs
示例19: ExpressionLambdaRewriter
private ExpressionLambdaRewriter(TypeCompilationState compilationState, TypeMap typeMap, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
_bound = new SyntheticBoundNodeFactory(null, compilationState.Type, node, compilationState, diagnostics);
_ignoreAccessibility = compilationState.ModuleBuilderOpt.IgnoreAccessibility;
_int32Type = _bound.SpecialType(SpecialType.System_Int32);
_objectType = _bound.SpecialType(SpecialType.System_Object);
_nullableType = _bound.SpecialType(SpecialType.System_Nullable_T);
_IEnumerableType = _bound.SpecialType(SpecialType.System_Collections_Generic_IEnumerable_T);
_typeMap = typeMap;
}
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:11,代码来源:ExpressionLambdaRewriter.cs
示例20: RewriteLambda
internal static BoundNode RewriteLambda(BoundLambda node, TypeCompilationState compilationState, TypeMap typeMap, DiagnosticBag diagnostics)
{
try
{
var r = new ExpressionLambdaRewriter(compilationState, typeMap, node.Syntax, diagnostics);
var result = r.VisitLambdaInternal(node);
if (node.Type != result.Type)
{
diagnostics.Add(ErrorCode.ERR_MissingPredefinedMember, node.Syntax.Location, r.ExpressionType, "Lambda");
}
return result;
}
catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex)
{
diagnostics.Add(ex.Diagnostic);
return node;
}
}
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:18,代码来源:ExpressionLambdaRewriter.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论