• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CodeGen.LocalDefinition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.CodeGen.LocalDefinition的典型用法代码示例。如果您正苦于以下问题:C# LocalDefinition类的具体用法?C# LocalDefinition怎么用?C# LocalDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LocalDefinition类属于Microsoft.CodeAnalysis.CodeGen命名空间,在下文中一共展示了LocalDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:27,代码来源:FullLocalSlotManager.cs


示例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);
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:26,代码来源:EncLocalSlotManager.cs


示例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;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:44,代码来源:EncLocalSlotManager.cs


示例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;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:20,代码来源:SwitchStringJumpTableEmitter.cs


示例5: FreeOptTemp

 /// <summary>
 /// Frees an optional temp.
 /// </summary>
 private void FreeOptTemp(LocalDefinition temp)
 {
     if (temp != null)
     {
         FreeTemp(temp);
     }
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:10,代码来源:EmitStatement.cs


示例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);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:37,代码来源:EmitStatement.cs


示例7: AddLocalToScope

 /// <summary>
 /// Puts local variable into current scope.
 /// </summary>
 internal void AddLocalToScope(LocalDefinition local)
 {
     HasDynamicLocal |= local.IsDynamic;
     _scopeManager.AddLocal(local);
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:8,代码来源:ILBuilder.cs


示例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);
        }
开发者ID:pheede,项目名称:roslyn,代码行数:21,代码来源:CSharpDefinitionMap.cs


示例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);
                }
            }
        }
开发者ID:kangkot,项目名称:roslyn,代码行数:22,代码来源:ILBuilderEmit.cs


示例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);
            }
        }
开发者ID:kangkot,项目名称:roslyn,代码行数:36,代码来源:ILBuilderEmit.cs


示例11: LocalPlace

 public LocalPlace(LocalDefinition def)
 {
     Contract.ThrowIfNull(def);
     _def = def;
 }
开发者ID:iolevel,项目名称:peachpie,代码行数:5,代码来源:Places.cs


示例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);
 }
开发者ID:riversky,项目名称:roslyn,代码行数:9,代码来源:ILBuilderVisualizer.cs


示例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();
        }
开发者ID:kangkot,项目名称:roslyn,代码行数:39,代码来源:ILBuilderEmit.cs


示例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;
     }
 }
开发者ID:kangkot,项目名称:roslyn,代码行数:24,代码来源:ILBuilderEmit.cs


示例15: EmitAssignmentPostfix

 private void EmitAssignmentPostfix(LocalDefinition temp)
 {
     if (temp != null)
     {
         _builder.EmitLocalLoad(temp);
         FreeTemp(temp);
     }
 }
开发者ID:rgani,项目名称:roslyn,代码行数:8,代码来源:EmitExpression.cs


示例16: EmitIntegerSwitchJumpTable

        /// <summary>
        /// Primary method for emitting integer switch jump table
        /// </summary>
        /// <param name="caseLabels">switch case labels</param>
        /// <param name="fallThroughLabel">fall through label for the jump table</param>
        /// <param name="keyLocal">Local holding the value to switch on.
        /// This value has already been loaded onto the execution stack.
        /// </param>
        /// <param name="keyTypeCode">Primitive type code of switch key</param>
        internal void EmitIntegerSwitchJumpTable(
            KeyValuePair<ConstantValue, object>[] caseLabels,
            object fallThroughLabel,
            LocalDefinition keyLocal,
            Microsoft.Cci.PrimitiveTypeCode keyTypeCode)
        {
            Debug.Assert(caseLabels.Length > 0);
            Debug.Assert(keyTypeCode != Microsoft.Cci.PrimitiveTypeCode.String);

            // CONSIDER: SwitchIntegralJumpTableEmitter will modify the caseLabels array by sorting it.
            // CONSIDER: Currently, only purpose of creating this caseLabels array is for Emitting the jump table.
            // CONSIDER: If this requirement changes, we may want to pass in ArrayBuilder<KeyValuePair<ConstantValue, object>> instead.

            var emitter = new SwitchIntegralJumpTableEmitter(this, caseLabels, fallThroughLabel, keyTypeCode, keyLocal, -1);
            emitter.EmitJumpTable();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:25,代码来源:ILBuilderEmit.cs


示例17: PossiblyDefinedOutsideOfTry

 internal bool PossiblyDefinedOutsideOfTry(LocalDefinition local)
     => _scopeManager.PossiblyDefinedOutsideOfTry(local);
开发者ID:GloryChou,项目名称:roslyn,代码行数:2,代码来源:ILBuilder.cs


示例18: LocalOrParameter

 private LocalOrParameter(LocalDefinition local, int parameterIndex)
 {
     this.Local = local;
     this.ParameterIndex = parameterIndex;
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:5,代码来源:LocalOrParameter.cs


示例19: EmitStringSwitchJumpTable

        private void EmitStringSwitchJumpTable(
            BoundSwitchStatement switchStatement,
            KeyValuePair<ConstantValue, object>[] switchCaseLabels,
            LabelSymbol fallThroughLabel,
            LocalDefinition key,
            CSharpSyntaxNode syntaxNode)
        {
            LocalDefinition keyHash = null;

            // Condition is necessary, but not sufficient (e.g. might be missing a special or well-known member).
            if (SwitchStringJumpTableEmitter.ShouldGenerateHashTableSwitch(this.module, switchCaseLabels.Length))
            {
                Debug.Assert(this.module.SupportsPrivateImplClass);

                var privateImplClass = this.module.GetPrivateImplClass(syntaxNode, diagnostics);
                Microsoft.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.EmitLocalLoad(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);
                }
            }

            Microsoft.Cci.IReference stringEqualityMethodRef = module.Translate(switchStatement.StringEquality, syntaxNode, diagnostics);

            Microsoft.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.EmitLocalLoad(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.EmitLocalLoad(keyArg);
                        builder.EmitBranch(ILOpCode.Brfalse, skipToNext, ILOpCode.Brtrue);

                        builder.EmitLocalLoad(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);
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:97,代码来源:EmitStatement.cs


示例20: ReturnTemporaryLocal

 /// <summary>
 /// Returns a <see cref="LocalDefinition"/> previously obtained from <see cref="GetTemporaryLocal(TypeSymbol,bool)"/> to the
 /// pool of locals available for reuse.
 /// </summary>
 /// <param name="definition">The <see cref="LocalDefinition"/> to return to the pool.</param>
 public void ReturnTemporaryLocal(LocalDefinition/*!*/ definition)
 {
     _il.LocalSlotManager.FreeSlot(definition);
 }
开发者ID:iolevel,项目名称:peachpie,代码行数:9,代码来源:CodeGenerator.Locals.cs



注:本文中的Microsoft.CodeAnalysis.CodeGen.LocalDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeGeneration.CodeGenerationOptions类代码示例发布时间:2022-05-26
下一篇:
C# CodeGen.ILBuilder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap