本文整理汇总了C#中Microsoft.CodeAnalysis.CodeGen.LocalDefinition类的典型用法代码示例。如果您正苦于以下问题:C# LocalDefinition类的具体用法?C# LocalDefinition怎么用?C# LocalDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalDefinition类属于Microsoft.CodeAnalysis.CodeGen命名空间,在下文中一共展示了LocalDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeclareLocalInternal
protected override LocalDefinition DeclareLocalInternal(
Microsoft.Cci.ITypeReference type,
object identity,
string name,
bool isCompilerGenerated,
LocalSlotConstraints constraints,
bool isDynamic,
ImmutableArray<TypedConstant> dynamicTransformFlags)
{
if (allLocals == null)
{
allLocals = ImmutableArray.CreateBuilder<LocalDefinition>(1);
}
var local = new LocalDefinition(
identity: identity,
name: name,
type: type,
slot: this.allLocals.Count,
isCompilerGenerated: isCompilerGenerated,
constraints: constraints,
isDynamic: isDynamic,
dynamicTransformFlags: dynamicTransformFlags);
this.allLocals.Add(local);
return local;
}
示例2: EncLocalSlotManager
public EncLocalSlotManager(ImmutableArray<EncLocalInfo> previousLocals, GetPreviousLocalSlot getPreviousLocalSlot)
{
this.allLocals = new List<LocalDefinition>();
this.getPreviousLocalSlot = getPreviousLocalSlot;
// Add placeholders for previous locals. The actual
// identities are populated if/when the locals are reused.
for (int i = 0; i < previousLocals.Length; i++)
{
var localInfo = previousLocals[i];
Debug.Assert(localInfo.Type != null);
var local = new LocalDefinition(
identity: null,
name: null,
type: localInfo.Type,
slot: i,
isCompilerGenerated: true,
// The placeholder local is marked as compiler-generated
// so it will be excluded from the PDB and debugger if not
// replaced by a valid local in DeclareLocalInternal.
constraints: localInfo.Constraints,
isDynamic: false,
dynamicTransformFlags: default(ImmutableArray<TypedConstant>));
this.allLocals.Add(local);
}
}
示例3: DeclareLocalInternal
protected override LocalDefinition DeclareLocalInternal(
Microsoft.Cci.ITypeReference type,
object identity,
string name,
bool isCompilerGenerated,
LocalSlotConstraints constraints,
bool isDynamic,
ImmutableArray<TypedConstant> dynamicTransformFlags)
{
LocalDefinition local;
if (identity != null)
{
int slot = this.getPreviousLocalSlot(identity, type, constraints);
if (slot >= 0)
{
Debug.Assert(this.allLocals[slot].Identity == null);
local = new LocalDefinition(
identity: identity,
name: name,
type: type,
slot: slot,
isCompilerGenerated: isCompilerGenerated,
constraints: constraints,
isDynamic: isDynamic,
dynamicTransformFlags: dynamicTransformFlags);
this.allLocals[slot] = local;
return local;
}
}
local = new LocalDefinition(
identity: identity,
name: name,
type: type,
slot: this.allLocals.Count,
isCompilerGenerated: isCompilerGenerated,
constraints: constraints,
isDynamic: isDynamic,
dynamicTransformFlags: dynamicTransformFlags);
this.allLocals.Add(local);
return local;
}
示例4: SwitchStringJumpTableEmitter
internal SwitchStringJumpTableEmitter(
ILBuilder builder,
LocalOrParameter key,
KeyValuePair<ConstantValue, object>[] caseLabels,
object fallThroughLabel,
LocalDefinition keyHash,
EmitStringCompareAndBranch emitStringCondBranchDelegate,
GetStringHashCode computeStringHashcodeDelegate)
{
Debug.Assert(caseLabels.Length > 0);
Debug.Assert(emitStringCondBranchDelegate != null);
_builder = builder;
_key = key;
_caseLabels = caseLabels;
_fallThroughLabel = fallThroughLabel;
_keyHash = keyHash;
_emitStringCondBranchDelegate = emitStringCondBranchDelegate;
_computeStringHashcodeDelegate = computeStringHashcodeDelegate;
}
示例5: FreeOptTemp
/// <summary>
/// Frees an optional temp.
/// </summary>
private void FreeOptTemp(LocalDefinition temp)
{
if (temp != null)
{
FreeTemp(temp);
}
}
示例6: EmitStringCompareAndBranch
/// <summary>
/// Delegate to emit string compare call and conditional branch based on the compare result.
/// </summary>
/// <param name="key">Key to compare</param>
/// <param name="syntaxNode">Node for diagnostics.</param>
/// <param name="stringConstant">Case constant to compare the key against</param>
/// <param name="targetLabel">Target label to branch to if key = stringConstant</param>
/// <param name="stringEqualityMethodRef">String equality method</param>
private void EmitStringCompareAndBranch(LocalDefinition key, SyntaxNode syntaxNode, ConstantValue stringConstant, object targetLabel, Microsoft.Cci.IReference stringEqualityMethodRef)
{
// Emit compare and branch:
// if (key == stringConstant)
// goto targetLabel;
Debug.Assert(stringEqualityMethodRef != null);
#if DEBUG
var assertDiagnostics = DiagnosticBag.GetInstance();
Debug.Assert(stringEqualityMethodRef == module.Translate((MethodSymbol)module.Compilation.GetSpecialTypeMember(SpecialMember.System_String__op_Equality), (CSharpSyntaxNode)syntaxNode, assertDiagnostics));
assertDiagnostics.Free();
#endif
// static bool String.Equals(string a, string b)
// pop 2 (a, b)
// push 1 (bool return value)
// stackAdjustment = (pushCount - popCount) = -1
builder.EmitLocalLoad(key);
builder.EmitConstantValue(stringConstant);
builder.EmitOpCode(ILOpCode.Call, stackAdjustment: -1);
builder.EmitToken(stringEqualityMethodRef, syntaxNode, diagnostics);
// Branch to targetLabel if String.Equals returned true.
builder.EmitBranch(ILOpCode.Brtrue, targetLabel, ILOpCode.Brfalse);
}
示例7: AddLocalToScope
/// <summary>
/// Puts local variable into current scope.
/// </summary>
internal void AddLocalToScope(LocalDefinition local)
{
HasDynamicLocal |= local.IsDynamic;
_scopeManager.AddLocal(local);
}
示例8: GetLocalInfo
private static EncLocalInfo GetLocalInfo(
IReadOnlyDictionary<SyntaxNode, int> declaratorToIndex,
LocalDefinition localDef)
{
// Local symbol will be null for short-lived temporaries.
var local = (LocalSymbol)localDef.Identity;
if ((object)local != null)
{
var syntaxRefs = local.DeclaringSyntaxReferences;
Debug.Assert(!syntaxRefs.IsDefault);
if (!syntaxRefs.IsDefaultOrEmpty)
{
var syntax = syntaxRefs[0].GetSyntax();
var offset = declaratorToIndex[syntax];
return new EncLocalInfo(offset, localDef.Type, localDef.Constraints, (int)local.TempKind);
}
}
return new EncLocalInfo(localDef.Type, localDef.Constraints);
}
示例9: EmitLocalAddress
internal void EmitLocalAddress(LocalDefinition local)
{
if (local.IsReference)
{
EmitLocalLoad(local);
}
else
{
int slot = local.SlotIndex;
if (slot < 0xFF)
{
EmitOpCode(ILOpCode.Ldloca_s);
EmitInt8(unchecked((sbyte)slot));
}
else
{
EmitOpCode(ILOpCode.Ldloca);
EmitInt32(slot);
}
}
}
示例10: EmitLocalLoad
// Generate a "load local" opcode with the given slot number.
internal void EmitLocalLoad(LocalDefinition local)
{
var slot = local.SlotIndex;
switch (slot)
{
case 0: EmitOpCode(ILOpCode.Ldloc_0); break;
case 1: EmitOpCode(ILOpCode.Ldloc_1); break;
case 2: EmitOpCode(ILOpCode.Ldloc_2); break;
case 3: EmitOpCode(ILOpCode.Ldloc_3); break;
default:
if (slot < 0xFF)
{
EmitOpCode(ILOpCode.Ldloc_s);
EmitInt8(unchecked((sbyte)slot));
}
else
{
EmitOpCode(ILOpCode.Ldloc);
EmitInt32(slot);
}
break;
}
// As in ILGENREC::dumpLocal
// CONSIDER: this is somewhat C# specific - it might be better to incorporate this
// into the bound tree as a conversion to int.
// VSADOV: pinned locals are used in C# to represent pointers in "fixed" statements.
// in the user's code they are used as pointers (*), however in their implementation
// they hold pinned references (O or &) to the fixed data so they need to be converted
// them to unmanaged pointer type when loaded.
if (local.IsPinned)
{
EmitOpCode(ILOpCode.Conv_i);
}
}
示例11: LocalPlace
public LocalPlace(LocalDefinition def)
{
Contract.ThrowIfNull(def);
_def = def;
}
示例12: ToLocalInfo
public static LocalInfo ToLocalInfo(LocalDefinition local)
{
// May be null for deleted locals in edit and continue.
if (local == null)
{
return default(LocalInfo);
}
return new LocalInfo(local.Name, local.Type, local.IsPinned, local.IsReference);
}
示例13: EmitStringSwitchJumpTable
/// <summary>
/// Primary method for emitting string switch jump table
/// </summary>
/// <param name="caseLabels">switch case labels</param>
/// <param name="fallThroughLabel">fall through label for the jump table</param>
/// <param name="key">Local holding the value to switch on.
/// This value has already been loaded onto the execution stack.
/// </param>
/// <param name="keyHash">Local holding the hash value of the key for emitting
/// hash table switch. Hash value has already been computed and loaded into keyHash.
/// This parameter is null if emitting non hash table switch.
/// </param>
/// <param name="emitStringCondBranchDelegate">
/// Delegate to emit string compare call and conditional branch based on the compare result.
/// </param>
/// <param name="computeStringHashcodeDelegate">
/// Delegate to compute string hash consistent with value of keyHash.
/// </param>
internal void EmitStringSwitchJumpTable(
KeyValuePair<ConstantValue, object>[] caseLabels,
object fallThroughLabel,
LocalOrParameter key,
LocalDefinition keyHash,
SwitchStringJumpTableEmitter.EmitStringCompareAndBranch emitStringCondBranchDelegate,
SwitchStringJumpTableEmitter.GetStringHashCode computeStringHashcodeDelegate)
{
Debug.Assert(caseLabels.Length > 0);
var emitter = new SwitchStringJumpTableEmitter(
this,
key,
caseLabels,
fallThroughLabel,
keyHash,
emitStringCondBranchDelegate,
computeStringHashcodeDelegate);
emitter.EmitJumpTable();
}
示例14: EmitLocalStore
// Generate a "store local" opcode with the given slot number.
internal void EmitLocalStore(LocalDefinition local)
{
var slot = local.SlotIndex;
switch (slot)
{
case 0: EmitOpCode(ILOpCode.Stloc_0); break;
case 1: EmitOpCode(ILOpCode.Stloc_1); break;
case 2: EmitOpCode(ILOpCode.Stloc_2); break;
case 3: EmitOpCode(ILOpCode.Stloc_3); break;
default:
if (slot < 0xFF)
{
EmitOpCode(ILOpCode.Stloc_s);
EmitInt8(unchecked((sbyte)slot));
}
else
{
EmitOpCode(ILOpCode.Stloc);
EmitInt32(slot);
}
break;
}
}
示例15: EmitAssignmentPostfix
private void EmitAssignmentPostfix(LocalDefinition temp)
{
if (temp != null)
{
_builder.EmitLocalLoad(temp);
FreeTemp(temp);
}
}