本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol类的典型用法代码示例。如果您正苦于以下问题:C# MethodSymbol类的具体用法?C# MethodSymbol怎么用?C# MethodSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodSymbol类属于Microsoft.CodeAnalysis.CSharp.Symbols命名空间,在下文中一共展示了MethodSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analyze
public static MultiDictionary<Symbol, CSharpSyntaxNode> Analyze(CSharpCompilation compilation, MethodSymbol method, BoundNode node)
{
var emptyStructs = new CaptureWalkerEmptyStructTypeCache();
var initiallyAssignedVariables = UnassignedVariablesWalker.Analyze(compilation, method, node, emptyStructs);
var walker = new IteratorAndAsyncCaptureWalker(compilation, method, node, emptyStructs, initiallyAssignedVariables);
bool badRegion = false;
walker.Analyze(ref badRegion);
Debug.Assert(!badRegion);
var result = walker.variablesCaptured;
if (!method.IsStatic && method.ContainingType.TypeKind == TypeKind.Struct)
{
// It is possible that the enclosing method only *writes* to the enclosing struct, but in that
// case it should be considered captured anyway so that we have a proxy for it to write to.
result.Add(method.ThisParameter, node.Syntax);
}
foreach (var variable in result.Keys.ToArray()) // take a snapshot, as we are modifying the underlying multidictionary
{
var local = variable as LocalSymbol;
if ((object)local != null && local.RefKind != RefKind.None)
{
walker.AddSpillsForRef(walker.refLocalInitializers[local], result[local]);
}
}
walker.Free();
return result;
}
示例2: Rewrite
/// <summary>
/// Rewrite an async method into a state machine type.
/// </summary>
internal static BoundStatement Rewrite(
BoundStatement body,
MethodSymbol method,
int methodOrdinal,
VariableSlotAllocator slotAllocatorOpt,
TypeCompilationState compilationState,
DiagnosticBag diagnostics,
out AsyncStateMachine stateMachineType)
{
if (!method.IsAsync)
{
stateMachineType = null;
return body;
}
// The CLR doesn't support adding fields to structs, so in order to enable EnC in an async method we need to generate a class.
var typeKind = compilationState.Compilation.Options.EnableEditAndContinue ? TypeKind.Class : TypeKind.Struct;
var bodyWithAwaitLifted = AwaitExpressionSpiller.Rewrite(body, method, compilationState, diagnostics);
stateMachineType = new AsyncStateMachine(slotAllocatorOpt, compilationState, method, methodOrdinal, typeKind);
compilationState.ModuleBuilderOpt.CompilationState.SetStateMachineType(method, stateMachineType);
var rewriter = new AsyncRewriter(bodyWithAwaitLifted, method, methodOrdinal, stateMachineType, slotAllocatorOpt, compilationState, diagnostics);
if (!rewriter.VerifyPresenceOfRequiredAPIs())
{
return body;
}
return rewriter.Rewrite();
}
示例3: LocalBinderFactory
private LocalBinderFactory(MethodSymbol method, Binder enclosing)
{
Debug.Assert((object)method != null);
_map = new SmallDictionary<CSharpSyntaxNode, Binder>(ReferenceEqualityComparer.Instance);
_method = method;
_enclosing = enclosing;
}
示例4: EELocalSymbol
public EELocalSymbol(
MethodSymbol method,
ImmutableArray<Location> locations,
string nameOpt,
int ordinal,
LocalDeclarationKind declarationKind,
TypeSymbol type,
RefKind refKind,
bool isPinned,
bool isCompilerGenerated,
bool canScheduleToStack)
{
Debug.Assert(method != null);
Debug.Assert(ordinal >= -1);
Debug.Assert(!locations.IsDefault);
Debug.Assert(type != null);
_method = method;
_locations = locations;
_nameOpt = nameOpt;
_ordinal = ordinal;
_declarationKind = declarationKind;
_type = type;
_refKind = refKind;
_isPinned = isPinned;
_isCompilerGenerated = isCompilerGenerated;
_canScheduleToStack = canScheduleToStack;
}
示例5: SourceAttributeData
internal SourceAttributeData(
SyntaxReference applicationNode,
NamedTypeSymbol attributeClass,
MethodSymbol attributeConstructor,
ImmutableArray<TypedConstant> constructorArguments,
ImmutableArray<int> constructorArgumentsSourceIndices,
ImmutableArray<KeyValuePair<string, TypedConstant>> namedArguments,
bool hasErrors,
bool isConditionallyOmitted)
{
Debug.Assert(!isConditionallyOmitted || (object)attributeClass != null && attributeClass.IsConditional);
Debug.Assert(!constructorArguments.IsDefault);
Debug.Assert(!namedArguments.IsDefault);
Debug.Assert(constructorArgumentsSourceIndices.IsDefault ||
constructorArgumentsSourceIndices.Any() && constructorArgumentsSourceIndices.Length == constructorArguments.Length);
this.attributeClass = attributeClass;
this.attributeConstructor = attributeConstructor;
this.constructorArguments = constructorArguments;
this.constructorArgumentsSourceIndices = constructorArgumentsSourceIndices;
this.namedArguments = namedArguments;
this.isConditionallyOmitted = isConditionallyOmitted;
this.hasErrors = hasErrors;
this.applicationNode = applicationNode;
}
示例6: SynthesizedImplementationMethod
public SynthesizedImplementationMethod(
MethodSymbol interfaceMethod,
NamedTypeSymbol implementingType,
string name = null,
bool debuggerHidden = false,
PropertySymbol associatedProperty = null,
MethodSymbol asyncKickoffMethod = null)
{
//it does not make sense to add methods to substituted types
Debug.Assert(implementingType.IsDefinition);
this.name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null);
this.interfaceMethod = interfaceMethod;
this.implementingType = implementingType;
this.debuggerHidden = debuggerHidden;
this.associatedProperty = associatedProperty;
this.explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod);
this.asyncKickoffMethod = asyncKickoffMethod;
// alpha-rename to get the implementation's type parameters
var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;
typeMap.WithAlphaRename(interfaceMethod, this, out this.typeParameters);
var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(this.typeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
this.returnType = substitutedInterfaceMethod.ReturnType;
this.parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this);
}
示例7: Create
/// <summary>
/// Return the extension method in reduced form if the extension method
/// is applicable, and satisfies type parameter constraints, based on the
/// "this" argument type. Otherwise, returns null.
/// </summary>
public static MethodSymbol Create(MethodSymbol method, TypeSymbol receiverType, Compilation compilation)
{
Debug.Assert(method.IsExtensionMethod && method.MethodKind != MethodKind.ReducedExtension);
Debug.Assert(method.ParameterCount > 0);
Debug.Assert((object)receiverType != null);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
method = method.InferExtensionMethodTypeArguments(receiverType, compilation, ref useSiteDiagnostics);
if ((object)method == null)
{
return null;
}
var conversions = new TypeConversions(method.ContainingAssembly.CorLibrary);
var conversion = conversions.ConvertExtensionMethodThisArg(method.Parameters[0].Type, receiverType, ref useSiteDiagnostics);
if (!conversion.Exists)
{
return null;
}
if (useSiteDiagnostics != null)
{
foreach (var diag in useSiteDiagnostics)
{
if (diag.Severity == DiagnosticSeverity.Error)
{
return null;
}
}
}
return Create(method);
}
示例8: BindFieldInitializers
internal static void BindFieldInitializers(
SourceMemberContainerTypeSymbol typeSymbol,
MethodSymbol scriptCtor,
ImmutableArray<FieldInitializers> fieldInitializers,
bool generateDebugInfo,
DiagnosticBag diagnostics,
ref ProcessedFieldInitializers processedInitializers) //by ref so that we can store the results of lowering
{
DiagnosticBag diagsForInstanceInitializers = DiagnosticBag.GetInstance();
try
{
ConsList<Imports> firstDebugImports;
processedInitializers.BoundInitializers = BindFieldInitializers(typeSymbol, scriptCtor, fieldInitializers,
diagsForInstanceInitializers, generateDebugInfo, out firstDebugImports);
processedInitializers.HasErrors = diagsForInstanceInitializers.HasAnyErrors();
processedInitializers.FirstDebugImports = firstDebugImports;
}
finally
{
diagnostics.AddRange(diagsForInstanceInitializers);
diagsForInstanceInitializers.Free();
}
}
示例9: MakePropertyGetAccess
private BoundExpression MakePropertyGetAccess(
SyntaxNode syntax,
BoundExpression rewrittenReceiver,
PropertySymbol property,
ImmutableArray<BoundExpression> rewrittenArguments,
MethodSymbol getMethodOpt = null,
BoundPropertyAccess oldNodeOpt = null)
{
if (_inExpressionLambda && rewrittenArguments.IsEmpty)
{
return oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, property, LookupResultKind.Viable, property.Type) :
new BoundPropertyAccess(syntax, rewrittenReceiver, property, LookupResultKind.Viable, property.Type);
}
else
{
var getMethod = getMethodOpt ?? property.GetOwnOrInheritedGetMethod();
Debug.Assert((object)getMethod != null);
Debug.Assert(getMethod.ParameterCount == rewrittenArguments.Length);
Debug.Assert(((object)getMethodOpt == null) || ReferenceEquals(getMethod, getMethodOpt));
return BoundCall.Synthesized(
syntax,
rewrittenReceiver,
getMethod,
rewrittenArguments);
}
}
示例10: SynthesizedLambdaMethod
internal SynthesizedLambdaMethod(NamedTypeSymbol containingType, MethodSymbol topLevelMethod, BoundLambda node, bool isStatic, TypeCompilationState compilationState)
: base(containingType,
node.Symbol,
null,
node.SyntaxTree.GetReference(node.Body.Syntax),
node.Syntax.GetLocation(),
GeneratedNames.MakeLambdaMethodName(topLevelMethod.Name, compilationState.GenerateTempNumber()),
(containingType is LambdaFrame ? DeclarationModifiers.Internal : DeclarationModifiers.Private)
| (isStatic ? DeclarationModifiers.Static : 0)
| (node.Symbol.IsAsync ? DeclarationModifiers.Async : 0))
{
TypeMap typeMap;
ImmutableArray<TypeParameterSymbol> typeParameters;
LambdaFrame lambdaFrame;
if (!topLevelMethod.IsGenericMethod)
{
typeMap = TypeMap.Empty;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else if ((object)(lambdaFrame = this.ContainingType as LambdaFrame) != null)
{
typeMap = lambdaFrame.TypeMap;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out typeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, typeParameters);
}
示例11: MethodToStateMachineRewriter
public MethodToStateMachineRewriter(
SyntheticBoundNodeFactory F,
MethodSymbol originalMethod,
FieldSymbol state,
IReadOnlySet<Symbol> variablesCaptured,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
DiagnosticBag diagnostics,
bool useFinalizerBookkeeping)
: base(F.CompilationState, diagnostics)
{
Debug.Assert(F != null);
Debug.Assert(originalMethod != null);
Debug.Assert(state != null);
Debug.Assert(nonReusableLocalProxies != null);
Debug.Assert(diagnostics != null);
Debug.Assert(variablesCaptured != null);
this.F = F;
this.stateField = state;
this.cachedState = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), kind: SynthesizedLocalKind.StateMachineCachedState);
this.useFinalizerBookkeeping = useFinalizerBookkeeping;
this.hasFinalizerState = useFinalizerBookkeeping;
this.originalMethod = originalMethod;
this.variablesCaptured = variablesCaptured;
foreach (var proxy in nonReusableLocalProxies)
{
this.proxies.Add(proxy.Key, proxy.Value);
}
}
示例12: AsyncStruct
public AsyncStruct(MethodSymbol method)
: base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, SequenceNumber(method)), TypeKind.Struct)
{
// TODO: report use-site errors on these types
this.interfaces = ImmutableArray.Create<NamedTypeSymbol>(method.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine));
this.constructor = new SynthesizedInstanceConstructor(this);
}
示例13: ExecutableCodeBinder
internal ExecutableCodeBinder(CSharpSyntaxNode root, Symbol memberSymbol, Binder next, BinderFlags additionalFlags)
: base(next, (next.Flags | additionalFlags) & ~BinderFlags.AllClearedAtExecutableCodeBoundary)
{
this.memberSymbol = memberSymbol;
this.root = root;
this.owner = memberSymbol as MethodSymbol;
}
示例14: AppendImplicitReturn
// insert the implicit "return" statement at the end of the method body
// Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
// ones are going to have sequence points.
internal static BoundBlock AppendImplicitReturn(BoundStatement node, MethodSymbol method = null, CSharpSyntaxNode syntax = null)
{
if (syntax == null)
{
syntax = node.Syntax;
}
BoundStatement ret =
(object)method != null && (object)method.IteratorElementType != null
? BoundYieldBreakStatement.Synthesized(syntax) as BoundStatement
: BoundReturnStatement.Synthesized(syntax, null);
if (syntax.Kind == SyntaxKind.Block)
{
var blockSyntax = (BlockSyntax)syntax;
ret = new BoundSequencePointWithSpan(
blockSyntax,
ret,
blockSyntax.CloseBraceToken.Span)
{ WasCompilerGenerated = true };
}
switch (node.Kind)
{
case BoundKind.Block:
var block = (BoundBlock)node;
return block.Update(block.LocalsOpt, block.Statements.Add(ret));
default:
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(ret, node));
}
}
示例15: GetEquivalentNodesMap
internal static Func<SyntaxNode, SyntaxNode> GetEquivalentNodesMap(MethodSymbol method1, MethodSymbol method0)
{
var tree1 = method1.Locations[0].SourceTree;
var tree0 = method0.Locations[0].SourceTree;
Assert.NotEqual(tree1, tree0);
var locals0 = GetAllLocals(method0);
return s =>
{
var s1 = s;
Assert.Equal(s1.SyntaxTree, tree1);
foreach (var s0 in locals0)
{
if (!SyntaxFactory.AreEquivalent(s0, s1))
{
continue;
}
// Make sure the containing statements are the same.
var p0 = GetNearestStatement(s0);
var p1 = GetNearestStatement(s1);
if (SyntaxFactory.AreEquivalent(p0, p1))
{
return s0;
}
}
return null;
};
}