本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap.SubstituteType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeMap.SubstituteType方法的具体用法?C# TypeMap.SubstituteType怎么用?C# TypeMap.SubstituteType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap
的用法示例。
在下文中一共展示了TypeMap.SubstituteType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: MakeHoistedLocalField
private SynthesizedFieldSymbolBase MakeHoistedLocalField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
{
Debug.Assert(local.SynthesizedLocalKind == SynthesizedLocalKind.None ||
local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass);
int index = nextLocalNumber++;
// Special Case: There's logic in the EE to recognize locals that have been captured by a lambda
// and would have been hoisted for the state machine. Basically, we just hoist the local containing
// the instance of the lambda display class and retain its original name (rather than using an
// iterator local name). See FUNCBRECEE::ImportIteratorMethodInheritedLocals.
string fieldName = (local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass)
? GeneratedNames.MakeLambdaDisplayClassStorageName(index)
: GeneratedNames.MakeHoistedLocalFieldName(local.Name, index);
return F.StateMachineField(TypeMap.SubstituteType(type), fieldName, index);
}
示例4: ToOtherMethod
internal override EELocalSymbolBase ToOtherMethod(MethodSymbol method, TypeMap typeMap)
{
var type = typeMap.SubstituteType(_type);
return new EELocalSymbol(method, _locations, _nameOpt, _ordinal, _declarationKind, type.Type, _refKind, _isPinned, _isCompilerGenerated, _canScheduleToStack);
}
示例5: SubstituteField
private static FieldSymbol SubstituteField(FieldSymbol field, TypeMap typeMap)
{
Debug.Assert(!field.IsStatic);
Debug.Assert(!field.IsReadOnly);
Debug.Assert(field.CustomModifiers.Length == 0);
// CONSIDER: Instead of digging fields out of the unsubstituted type and then performing substitution
// on each one individually, we could dig fields out of the substituted type.
return new EEDisplayClassFieldSymbol(typeMap.SubstituteNamedType(field.ContainingType), field.Name, typeMap.SubstituteType(field.Type));
}
示例6: TryCreate
internal static bool TryCreate(SyntheticBoundNodeFactory F, MethodSymbol method, TypeMap typeMap, out AsyncMethodBuilderMemberCollection collection)
{
if (method.IsVoidReturningAsync())
{
return TryCreate(
F: F,
builderType: F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncVoidMethodBuilder),
resultType: F.SpecialType(SpecialType.System_Void),
setException: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetException,
setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetResult,
awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__AwaitOnCompleted,
awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__AwaitUnsafeOnCompleted,
start: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__Start_T,
setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetStateMachine,
task: null,
collection: out collection);
}
if (method.IsTaskReturningAsync(F.Compilation))
{
NamedTypeSymbol builderType = F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder);
PropertySymbol task;
if (!TryGetWellKnownPropertyAsMember(F, WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__Task, builderType, out task))
{
collection = default(AsyncMethodBuilderMemberCollection);
return false;
}
return TryCreate(
F: F,
builderType: F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder),
resultType: F.SpecialType(SpecialType.System_Void),
setException: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetException,
setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetResult,
awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__AwaitOnCompleted,
awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__AwaitUnsafeOnCompleted,
start: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__Start_T,
setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetStateMachine,
task: task,
collection: out collection);
}
if (method.IsGenericTaskReturningAsync(F.Compilation))
{
TypeSymbol resultType = method.ReturnType.GetMemberTypeArgumentsNoUseSiteDiagnostics().Single();
if (resultType.IsDynamic())
{
resultType = F.SpecialType(SpecialType.System_Object);
}
if (typeMap != null)
{
resultType = typeMap.SubstituteType(resultType).Type;
}
NamedTypeSymbol builderType = F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T).Construct(resultType);
PropertySymbol task;
if (!TryGetWellKnownPropertyAsMember(F, WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__Task, builderType, out task))
{
collection = default(AsyncMethodBuilderMemberCollection);
return false;
}
return TryCreate(
F: F,
builderType: builderType,
resultType: resultType,
setException: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetException,
setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetResult,
awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__AwaitOnCompleted,
awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__AwaitUnsafeOnCompleted,
start: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__Start_T,
setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetStateMachine,
task: task,
collection: out collection);
}
throw ExceptionUtilities.UnexpectedValue(method);
}
示例7: ToOtherMethod
internal override EELocalSymbolBase ToOtherMethod(MethodSymbol method, TypeMap typeMap)
{
var type = typeMap.SubstituteType(_type);
return new EELocalConstantSymbol(method, _name, type, _value);
}
示例8: CreateInitialProxies
private void CreateInitialProxies(
TypeMap TypeMap,
IOrderedEnumerable<Symbol> captured,
MultiDictionary<Symbol, CSharpSyntaxNode> locations)
{
foreach (var sym in captured)
{
var local = sym as LocalSymbol;
if ((object)local != null && local.DeclarationKind != LocalDeclarationKind.CompilerGenerated)
{
Debug.Assert(local.RefKind == RefKind.None); // there are no user-declared ref variables
MakeInitialProxy(TypeMap, locations, local);
continue;
}
var parameter = sym as ParameterSymbol;
if ((object)parameter != null)
{
if (parameter.IsThis)
{
var proxyField = F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyName(), isPublic: true);
variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));
if (PreserveInitialLocals)
{
var initialThis = method.ContainingType.IsStructType() ?
F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyProxyName(), isPublic: true) : proxyField;
initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(initialThis));
}
}
else
{
var proxyField = F.StateMachineField(TypeMap.SubstituteType(parameter.Type), parameter.Name, isPublic: true);
variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));
if (PreserveInitialLocals)
{
string proxyName = GeneratedNames.IteratorParameterProxyName(parameter.Name);
initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(
F.StateMachineField(TypeMap.SubstituteType(parameter.Type), proxyName, isPublic: true)));
}
if (parameter.Type.IsRestrictedType())
{
// CS4013: Instance of type '{0}' cannot be used inside an anonymous function, query expression, iterator block or async method
diagnostics.Add(ErrorCode.ERR_SpecialByRefInLambda, parameter.Locations[0], parameter.Type);
}
}
}
}
}
示例9: MakeHoistedField
private SynthesizedFieldSymbolBase MakeHoistedField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
{
Debug.Assert(local.DeclarationKind != LocalDeclarationKind.CompilerGenerated);
int index = nextLocalNumber++;
// Special Case: There's logic in the EE to recognize locals that have been captured by a lambda
// and would have been hoisted for the state machine. Basically, we just hoist the local containing
// the instance of the lambda display class and retain its original name (rather than using an
// iterator local name). See FUNCBRECEE::ImportIteratorMethodInheritedLocals.
string fieldName = local.DeclarationKind == LocalDeclarationKind.CompilerGeneratedLambdaDisplayClassLocal
? local.Name
: GeneratedNames.MakeIteratorLocalName(local.Name, index);
return F.SynthesizeField(TypeMap.SubstituteType(type), fieldName, index, isPublic: true);
}