本文整理汇总了C#中LabelSymbol类的典型用法代码示例。如果您正苦于以下问题:C# LabelSymbol类的具体用法?C# LabelSymbol怎么用?C# LabelSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LabelSymbol类属于命名空间,在下文中一共展示了LabelSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertIsLabeledStatementWithLabel
internal static void AssertIsLabeledStatementWithLabel(this BoundStatement node, LabelSymbol label)
{
Debug.Assert(node != null);
switch (node.Kind)
{
case BoundKind.LabelStatement:
Debug.Assert(((BoundLabelStatement)node).Label == label);
break;
case BoundKind.LabeledStatement:
Debug.Assert(((BoundLabeledStatement)node).Label == label);
break;
case BoundKind.SwitchSection:
foreach (var boundSwitchLabel in ((BoundSwitchSection)node).BoundSwitchLabels)
{
if (boundSwitchLabel.Label == label)
{
return;
}
}
throw ExceptionUtilities.Unreachable;
default:
throw ExceptionUtilities.UnexpectedValue(node.Kind);
}
}
示例2: AssertIsLabeledStatementWithLabel
internal static void AssertIsLabeledStatementWithLabel(this BoundStatement node, LabelSymbol label)
{
Debug.Assert(node != null);
switch (node.Kind)
{
case BoundKind.LabelStatement:
Debug.Assert(((BoundLabelStatement)node).Label == label);
break;
case BoundKind.LabeledStatement:
Debug.Assert(((BoundLabeledStatement)node).Label == label);
break;
case BoundKind.SwitchSection:
foreach (var boundSwitchLabel in ((BoundSwitchSection)node).BoundSwitchLabels)
{
if (boundSwitchLabel.Label == label)
{
return;
}
}
Debug.Assert(false);
break;
default:
Debug.Assert(false);
break;
}
}
示例3: ResolveBranch
protected override void ResolveBranch(PendingBranch pending, LabelSymbol label, BoundStatement target, ref bool labelStateChanged)
{
// branches into a region are considered entry points
if (IsInside && pending.Branch != null && !RegionContains(pending.Branch.Syntax.Span))
{
pending.State = pending.State.Reachable ? ReachableState() : UnreachableState();
}
base.ResolveBranch(pending, label, target, ref labelStateChanged);
}
示例4: MakeSwitchStatement
private BoundStatement MakeSwitchStatement(
CSharpSyntaxNode syntax,
BoundExpression rewrittenExpression,
ImmutableArray<BoundSwitchSection> rewrittenSections,
LabelSymbol constantTargetOpt,
ImmutableArray<LocalSymbol> locals,
GeneratedLabelSymbol breakLabel,
BoundSwitchStatement oldNode)
{
Debug.Assert(oldNode != null);
Debug.Assert((object)rewrittenExpression.Type != null);
return rewrittenExpression.Type.IsNullableType() ?
MakeSwitchStatementWithNullableExpression(syntax, rewrittenExpression, rewrittenSections, constantTargetOpt, locals, breakLabel, oldNode) :
MakeSwitchStatementWithNonNullableExpression(syntax, null, rewrittenExpression, rewrittenSections, constantTargetOpt, locals, breakLabel, oldNode);
}
示例5: EmitStringSwitchJumpTable
private void EmitStringSwitchJumpTable(
BoundSwitchStatement switchStatement,
KeyValuePair<ConstantValue, object>[] switchCaseLabels,
LabelSymbol fallThroughLabel,
LocalOrParameter key,
SyntaxNode syntaxNode)
{
LocalDefinition keyHash = null;
// Condition is necessary, but not sufficient (e.g. might be missing a special or well-known member).
if (SwitchStringJumpTableEmitter.ShouldGenerateHashTableSwitch(_module, switchCaseLabels.Length))
{
Debug.Assert(_module.SupportsPrivateImplClass);
var privateImplClass = _module.GetPrivateImplClass(syntaxNode, _diagnostics);
Cci.IReference stringHashMethodRef = privateImplClass.GetMethod(PrivateImplementationDetails.SynthesizedStringHashFunctionName);
// Heuristics and well-known member availability determine the existence
// of this helper. Rather than reproduce that (language-specific) logic here,
// we simply check for the information we really want - whether the helper is
// available.
if (stringHashMethodRef != null)
{
// static uint ComputeStringHash(string s)
// pop 1 (s)
// push 1 (uint return value)
// stackAdjustment = (pushCount - popCount) = 0
_builder.EmitLoad(key);
_builder.EmitOpCode(ILOpCode.Call, stackAdjustment: 0);
_builder.EmitToken(stringHashMethodRef, syntaxNode, _diagnostics);
var UInt32Type = _module.Compilation.GetSpecialType(SpecialType.System_UInt32);
keyHash = AllocateTemp(UInt32Type, syntaxNode);
_builder.EmitLocalStore(keyHash);
}
}
Cci.IReference stringEqualityMethodRef = _module.Translate(switchStatement.StringEquality, syntaxNode, _diagnostics);
Cci.IMethodReference stringLengthRef = null;
var stringLengthMethod = _module.Compilation.GetSpecialTypeMember(SpecialMember.System_String__Length) as MethodSymbol;
if (stringLengthMethod != null && !stringLengthMethod.HasUseSiteError)
{
stringLengthRef = _module.Translate(stringLengthMethod, syntaxNode, _diagnostics);
}
SwitchStringJumpTableEmitter.EmitStringCompareAndBranch emitStringCondBranchDelegate =
(keyArg, stringConstant, targetLabel) =>
{
if (stringConstant == ConstantValue.Null)
{
// if (key == null)
// goto targetLabel
_builder.EmitLoad(keyArg);
_builder.EmitBranch(ILOpCode.Brfalse, targetLabel, ILOpCode.Brtrue);
}
else if (stringConstant.StringValue.Length == 0 && stringLengthRef != null)
{
// if (key != null && key.Length == 0)
// goto targetLabel
object skipToNext = new object();
_builder.EmitLoad(keyArg);
_builder.EmitBranch(ILOpCode.Brfalse, skipToNext, ILOpCode.Brtrue);
_builder.EmitLoad(keyArg);
// Stack: key --> length
_builder.EmitOpCode(ILOpCode.Call, 0);
var diag = DiagnosticBag.GetInstance();
_builder.EmitToken(stringLengthRef, null, diag);
Debug.Assert(diag.IsEmptyWithoutResolution);
diag.Free();
_builder.EmitBranch(ILOpCode.Brfalse, targetLabel, ILOpCode.Brtrue);
_builder.MarkLabel(skipToNext);
}
else
{
this.EmitStringCompareAndBranch(key, syntaxNode, stringConstant, targetLabel, stringEqualityMethodRef);
}
};
_builder.EmitStringSwitchJumpTable(
caseLabels: switchCaseLabels,
fallThroughLabel: fallThroughLabel,
key: key,
keyHash: keyHash,
emitStringCondBranchDelegate: emitStringCondBranchDelegate,
computeStringHashcodeDelegate: SynthesizedStringSwitchHashMethod.ComputeStringHash);
if (keyHash != null)
{
FreeTemp(keyHash);
}
}
示例6: EmitSwitchHeader
private void EmitSwitchHeader(
BoundSwitchStatement switchStatement,
BoundExpression expression,
KeyValuePair<ConstantValue, object>[] switchCaseLabels,
LabelSymbol fallThroughLabel)
{
Debug.Assert(expression.ConstantValue == null);
Debug.Assert((object)expression.Type != null &&
expression.Type.IsValidV6SwitchGoverningType());
Debug.Assert(switchCaseLabels.Length > 0);
Debug.Assert(switchCaseLabels != null);
LocalDefinition temp = null;
LocalOrParameter key;
BoundSequence sequence = null;
if (expression.Kind == BoundKind.Sequence)
{
sequence = (BoundSequence)expression;
DefineLocals(sequence);
EmitSideEffects(sequence);
expression = sequence.Value;
}
if (expression.Kind == BoundKind.SequencePointExpression)
{
var sequencePointExpression = (BoundSequencePointExpression)expression;
EmitSequencePoint(sequencePointExpression);
expression = sequencePointExpression.Expression;
}
switch (expression.Kind)
{
case BoundKind.Local:
var local = ((BoundLocal)expression).LocalSymbol;
if (local.RefKind == RefKind.None && !IsStackLocal(local))
{
key = this.GetLocal(local);
break;
}
goto default;
case BoundKind.Parameter:
var parameter = (BoundParameter)expression;
if (parameter.ParameterSymbol.RefKind == RefKind.None)
{
key = ParameterSlot(parameter);
break;
}
goto default;
default:
EmitExpression(expression, true);
temp = AllocateTemp(expression.Type, expression.Syntax);
_builder.EmitLocalStore(temp);
key = temp;
break;
}
// Emit switch jump table
if (expression.Type.SpecialType != SpecialType.System_String)
{
_builder.EmitIntegerSwitchJumpTable(switchCaseLabels, fallThroughLabel, key, expression.Type.EnumUnderlyingType().PrimitiveTypeCode);
}
else
{
this.EmitStringSwitchJumpTable(switchStatement, switchCaseLabels, fallThroughLabel, key, expression.Syntax);
}
if (temp != null)
{
FreeTemp(temp);
}
if (sequence != null)
{
FreeLocals(sequence, doNotRelease: null);
}
}
示例7: EmitConstantSwitchHeader
private void EmitConstantSwitchHeader(BoundExpression expression, LabelSymbol target)
{
EmitExpression(expression, false);
_builder.EmitBranch(ILOpCode.Br, target);
}
示例8: GetSwitchCaseLabels
private static KeyValuePair<ConstantValue, object>[] GetSwitchCaseLabels(ImmutableArray<BoundSwitchSection> sections, ref LabelSymbol fallThroughLabel)
{
var labelsBuilder = ArrayBuilder<KeyValuePair<ConstantValue, object>>.GetInstance();
foreach (var section in sections)
{
foreach (BoundSwitchLabel boundLabel in section.SwitchLabels)
{
var label = boundLabel.Label;
if (boundLabel.ConstantValueOpt == null)
{
fallThroughLabel = label;
}
else
{
var value = boundLabel.ConstantValueOpt;
Debug.Assert(value != null
&& SwitchConstantValueHelper.IsValidSwitchCaseLabelConstant(value));
labelsBuilder.Add(new KeyValuePair<ConstantValue, object>(value, label));
}
}
}
return labelsBuilder.ToArrayAndFree();
}
示例9: PendBranches
private BoundBlock PendBranches(
AwaitFinallyFrame frame,
LocalSymbol pendingBranchVar,
LabelSymbol finallyLabel)
{
var bodyStatements = ArrayBuilder<BoundStatement>.GetInstance();
// handle proxy labels if have any
var proxiedLabels = frame.proxiedLabels;
var proxyLabels = frame.proxyLabels;
// skip 0 - it means we took no explicit branches
int i = 1;
if (proxiedLabels != null)
{
for (int cnt = proxiedLabels.Count; i <= cnt; i++)
{
var proxied = proxiedLabels[i - 1];
var proxy = proxyLabels[proxied];
PendBranch(bodyStatements, proxy, i, pendingBranchVar, finallyLabel);
}
}
var returnProxy = frame.returnProxyLabel;
if (returnProxy != null)
{
PendBranch(bodyStatements, returnProxy, i, pendingBranchVar, finallyLabel);
}
return _F.Block(bodyStatements.ToImmutableAndFree());
}
示例10: MakeSwitchStatementWithNullableExpression
private BoundStatement MakeSwitchStatementWithNullableExpression(
CSharpSyntaxNode syntax,
BoundExpression rewrittenExpression,
ImmutableArray<BoundSwitchSection> rewrittenSections,
LabelSymbol constantTargetOpt,
ImmutableArray<LocalSymbol> locals,
GeneratedLabelSymbol breakLabel,
BoundSwitchStatement oldNode)
{
Debug.Assert(rewrittenExpression.Type.IsNullableType());
var exprSyntax = rewrittenExpression.Syntax;
var exprNullableType = rewrittenExpression.Type;
var statementBuilder = ArrayBuilder<BoundStatement>.GetInstance();
// Rewrite the nullable expression to a temp as we might have a user defined conversion from source expression to switch governing type.
// We can avoid generating the temp if the expression is a bound local.
LocalSymbol tempLocal;
if (rewrittenExpression.Kind != BoundKind.Local)
{
BoundAssignmentOperator assignmentToTemp;
BoundLocal boundTemp = _factory.StoreToTemp(rewrittenExpression, out assignmentToTemp);
var tempAssignment = new BoundExpressionStatement(exprSyntax, assignmentToTemp);
statementBuilder.Add(tempAssignment);
tempLocal = boundTemp.LocalSymbol;
rewrittenExpression = boundTemp;
}
else
{
tempLocal = null;
}
// Generate a BoundConditionalGoto with null check as the conditional expression and appropriate switch label as the target: null, default or exit label.
BoundStatement condGotoNullValueTargetLabel = new BoundConditionalGoto(
exprSyntax,
condition: MakeNullCheck(exprSyntax, rewrittenExpression, BinaryOperatorKind.NullableNullEqual),
jumpIfTrue: true,
label: GetNullValueTargetSwitchLabel(rewrittenSections, breakLabel));
// Rewrite the switch statement using nullable expression's underlying value as the switch expression.
// rewrittenExpression.GetValueOrDefault()
MethodSymbol getValueOrDefault = GetNullableMethod(syntax, exprNullableType, SpecialMember.System_Nullable_T_GetValueOrDefault);
BoundCall callGetValueOrDefault = BoundCall.Synthesized(exprSyntax, rewrittenExpression, getValueOrDefault);
rewrittenExpression = callGetValueOrDefault;
// rewrite switch statement
BoundStatement rewrittenSwitchStatement = MakeSwitchStatementWithNonNullableExpression(
syntax,
condGotoNullValueTargetLabel,
rewrittenExpression,
rewrittenSections,
constantTargetOpt,
locals,
breakLabel,
oldNode);
statementBuilder.Add(rewrittenSwitchStatement);
return new BoundBlock(syntax, locals: (object)tempLocal == null ? ImmutableArray<LocalSymbol>.Empty : ImmutableArray.Create<LocalSymbol>(tempLocal), statements: statementBuilder.ToImmutableAndFree());
}
示例11: RecordBranch
// called on branches and labels
private void RecordBranch(LabelSymbol label)
{
DummyLocal dummy;
if (_dummyVariables.TryGetValue(label, out dummy))
{
RecordVarRead(dummy);
}
else
{
// create a dummy and start tracing it
dummy = new DummyLocal();
_dummyVariables.Add(label, dummy);
_locals.Add(dummy, new LocalDefUseInfo(StackDepth()));
RecordVarWrite(dummy);
}
}
示例12: MakeSwitchStatementWithNonNullableExpression
private BoundStatement MakeSwitchStatementWithNonNullableExpression(
CSharpSyntaxNode syntax,
BoundStatement preambleOpt,
BoundExpression rewrittenExpression,
ImmutableArray<BoundSwitchSection> rewrittenSections,
LabelSymbol constantTargetOpt,
ImmutableArray<LocalSymbol> locals,
GeneratedLabelSymbol breakLabel,
BoundSwitchStatement oldNode)
{
Debug.Assert(!rewrittenExpression.Type.IsNullableType());
Debug.Assert((object)oldNode.StringEquality == null);
// If we are emitting a hash table based string switch,
// we need to generate a helper method for computing
// string hash value in <PrivateImplementationDetails> class.
MethodSymbol stringEquality = null;
if (rewrittenExpression.Type.SpecialType == SpecialType.System_String)
{
EnsureStringHashFunction(rewrittenSections, syntax);
stringEquality = GetSpecialTypeMethod(syntax, SpecialMember.System_String__op_Equality);
}
return oldNode.Update(
loweredPreambleOpt: preambleOpt,
boundExpression: rewrittenExpression,
constantTargetOpt: constantTargetOpt,
innerLocals: locals,
switchSections: rewrittenSections,
breakLabel: breakLabel,
stringEquality: stringEquality);
}
示例13: BindSwitchSectionLabel
private BoundSwitchLabel BindSwitchSectionLabel(SwitchLabelSyntax node, Binder sectionBinder, LabelSymbol label, DiagnosticBag diagnostics)
{
var switchGoverningType = SwitchGoverningType;
BoundExpression boundLabelExpressionOpt = null;
ConstantValue labelExpressionConstant = null;
// Prevent cascading diagnostics
bool hasErrors = node.HasErrors;
switch (node.Kind())
{
case SyntaxKind.CaseSwitchLabel:
var caseLabelSyntax = (CaseSwitchLabelSyntax)node;
// Bind the label case expression
boundLabelExpressionOpt = sectionBinder.BindValue(caseLabelSyntax.Value, diagnostics, BindValueKind.RValue);
boundLabelExpressionOpt = ConvertCaseExpression(caseLabelSyntax, boundLabelExpressionOpt, sectionBinder, ref labelExpressionConstant, diagnostics);
// Check for bind errors
hasErrors = hasErrors || boundLabelExpressionOpt.HasAnyErrors;
// SPEC: The constant expression of each case label must denote a value that
// SPEC: is implicitly convertible (§6.1) to the governing type of the switch statement.
if (!hasErrors && labelExpressionConstant == null)
{
diagnostics.Add(ErrorCode.ERR_ConstantExpected, caseLabelSyntax.Value.Location);
hasErrors = true;
}
if (!hasErrors && (object)labelExpressionConstant != null && FindMatchingSwitchCaseLabel(labelExpressionConstant, caseLabelSyntax) != label)
{
diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, labelExpressionConstant?.GetValueToDisplay() ?? label.Name);
hasErrors = true;
}
// LabelSymbols for all the switch case labels are created by BuildLabels().
// Fetch the matching switch case label symbols
break;
case SyntaxKind.CasePatternSwitchLabel:
if (!node.HasErrors)
{
// This should not occur, because it would have been a syntax error
throw ExceptionUtilities.UnexpectedValue(node.Kind());
}
break;
case SyntaxKind.DefaultSwitchLabel:
if (GetDefaultLabel() != label)
{
diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, label.Name);
hasErrors = true;
}
break;
default:
throw ExceptionUtilities.UnexpectedValue(node.Kind());
}
return new BoundSwitchLabel(
syntax: node,
label: label,
expressionOpt: boundLabelExpressionOpt,
constantValueOpt: labelExpressionConstant,
hasErrors: hasErrors);
}
示例14: BindPatternSwitchSectionLabel
private BoundPatternSwitchLabel BindPatternSwitchSectionLabel(
Binder sectionBinder, BoundExpression boundSwitchExpression, SwitchLabelSyntax node, LabelSymbol label, ref BoundPatternSwitchLabel defaultLabel, DiagnosticBag diagnostics)
{
switch (node.Kind())
{
case SyntaxKind.CaseSwitchLabel:
{
var caseLabelSyntax = (CaseSwitchLabelSyntax)node;
bool wasExpression;
var pattern = sectionBinder.BindConstantPattern(
node, boundSwitchExpression, boundSwitchExpression.Type, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression, wasSwitchCase: true);
bool hasErrors = pattern.HasErrors;
var constantValue = pattern.ConstantValue;
if (!hasErrors &&
(object)constantValue != null &&
pattern.Value.Type == SwitchGoverningType &&
this.FindMatchingSwitchCaseLabel(constantValue, caseLabelSyntax) != label)
{
diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, pattern.ConstantValue.GetValueToDisplay() ?? label.Name);
hasErrors = true;
}
// Until we've determined whether or not the switch label is reachable, we assume it
// is. The caller updates isReachable after determining if the label is subsumed.
const bool isReachable = true;
return new BoundPatternSwitchLabel(node, label, pattern, null, isReachable, hasErrors);
}
case SyntaxKind.DefaultSwitchLabel:
{
var defaultLabelSyntax = (DefaultSwitchLabelSyntax)node;
var pattern = new BoundWildcardPattern(node);
bool hasErrors = pattern.HasErrors;
if (defaultLabel != null)
{
diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, label.Name);
hasErrors = true;
}
// We always treat the default label as reachable, even if the switch is complete.
const bool isReachable = true;
// Note that this is semantically last! The caller will place it in the decision tree
// in the final position.
defaultLabel = new BoundPatternSwitchLabel(node, label, pattern, null, isReachable, hasErrors);
return defaultLabel;
}
case SyntaxKind.CasePatternSwitchLabel:
{
var matchLabelSyntax = (CasePatternSwitchLabelSyntax)node;
var pattern = sectionBinder.BindPattern(
matchLabelSyntax.Pattern, boundSwitchExpression, boundSwitchExpression.Type, node.HasErrors, diagnostics, wasSwitchCase: true);
return new BoundPatternSwitchLabel(node, label, pattern,
matchLabelSyntax.WhenClause != null ? sectionBinder.BindBooleanExpression(matchLabelSyntax.WhenClause.Condition, diagnostics) : null,
true, node.HasErrors);
}
default:
throw ExceptionUtilities.UnexpectedValue(node);
}
}
示例15: BoundSwitchLabel
public BoundSwitchLabel(CSharpSyntaxNode syntax, LabelSymbol label, bool hasErrors = false)
: this(syntax, label, expressionOpt: null, hasErrors: hasErrors)
{
}