当前位置: 首页>>代码示例>>C#>>正文


C# Span.IndentSpan方法代码示例

本文整理汇总了C#中Span.IndentSpan方法的典型用法代码示例。如果您正苦于以下问题:C# Span.IndentSpan方法的具体用法?C# Span.IndentSpan怎么用?C# Span.IndentSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Span的用法示例。


在下文中一共展示了Span.IndentSpan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmitExpImpl

        private EmitValHLSL EmitExpImpl(MidLabelExp exp, Span span)
        {
            if (_labels.ContainsKey(exp.Label))
            {
                return EmitExp(exp.Body, span);
            }

            // Try to resolve this label with
            // loop nesting...

            var resultType = EmitType(exp.Type);
            var resultVar = resultType.CreateVal("__block_result");
            DeclareLocal(resultVar, span);

            Label newLabel = new BreakLabel(
                exp.Label,
                this,
                resultVar);

            _nestedLabels.Push(newLabel);
            try
            {
                span.WriteLine("do {");

                var innerSpan = span.IndentSpan();

                var bodyVal = EmitExp(exp.Body, innerSpan);
                if (bodyVal != null)
                {
                    Assign(resultVar, bodyVal, innerSpan);
                }

                span.WriteLine("} while(false);");
            }
            finally
            {
                _nestedLabels.Pop();
            }
            return resultVar;
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:40,代码来源:EmitContextHLSL.cs

示例2: GetMethod

        public string GetMethod(MidMethodDecl method)
        {
            string result;
            if (_methods.TryGetValue(method, out result))
                return result;

            var name = _shared.GenerateName(method.Name.ToString());
            result = name;
            _methods[method] = result;

            Span span = new Span();

            span.WriteLine("void {0}(",
                name);

            bool firstParam = true;

            var resultType = EmitType(method.ResultType);
            var resultVar = DeclareOutParam(
                "__result",
                resultType,
                span,
                ref firstParam);

            foreach (var p in method.Parameters)
            {
                var pName = _shared.GenerateName(p.Name.ToString());

                var pType = EmitType(p.Type);
                var pVal = DeclareParam(
                    pName,
                    pType,
                    span,
                    ref firstParam);

                _varVals[p] = pVal;
            }

            span.WriteLine(")");
            span.WriteLine("{");

            var bodySpan = span.IndentSpan();

            // Scan for a label expression
            // along the 'spine' of the method

            var bodyExp = method.Body;
            while (bodyExp is MidLetExp)
            {
                bodyExp = ((MidLetExp)bodyExp).Body;
            }

            if (bodyExp is MidLabelExp)
            {
                var labelExp = (MidLabelExp)bodyExp;

                // a 'break' to this label should be
                // emitted as a 'return':

                _labels[labelExp.Label] = new ReturnLabel(this, resultVar);

                EmitExp(method.Body, bodySpan);
            }
            else
            {
                // Otherwise, the body is an expression,
                // and we should return it if it is non-null...
                var resultExp = EmitExp(method.Body, bodySpan);

                if (method.ResultType != null
                    && !(method.ResultType is MidVoidType))
                {
                    Assign(resultVar, resultExp, span);
                }
            }

            span.WriteLine("}");

            _subroutineHeaderSpan.Add(span);
            return result;
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:81,代码来源:EmitContextHLSL.cs

示例3: GenerateConnectorType

        // Generate "connector" struct type for a particular stage
        public ConnectorTypeHLSL GenerateConnectorType(MidElementDecl element)
        {
            if (_elementTypes.ContainsKey(element) && !_connectorTypes.ContainsKey(element))
            {
                throw new NotImplementedException();
            }

            ConnectorTypeHLSL result;
            if (_connectorTypes.TryGetValue(element, out result))
                return result;

            // Actually emit the type, then...
            var name = string.Format("T_{0}", element.Name.ToString());
            result = new ConnectorTypeHLSL(name, element);
            _connectorTypes[element] = result;

            _elementTypes[element] = result;

            var span = new Span();

            span.WriteLine("struct {0}", result);
            span.WriteLine("{");
            var memberSpan = span.IndentSpan();
            foreach (var a in element.Attributes)
            {
                // Only output attributes go in the connector
                if (!a.IsOutput) continue;

                var attrName = MapName(a);
                var attrType = EmitType(a.Type);

                var rawName = a.Name.ToString();
                string semantic = "";
                switch (rawName)
                {
                    case "HS_EdgeFactors":
                        semantic = ": SV_TessFactor";
                        break;
                    case "HS_InsideFactors":
                        semantic = ": SV_InsideTessFactor";
                        break;
                    case "__RS_Position":
                        semantic = ": SV_Position";
                        break;
                    case "__RS_RenderTargetArrayIndex":
                        semantic = ": SV_RenderTargetArrayIndex";
                        break;

                    default:
                        semantic = string.Format(" : USER_{0}", attrName);
                        break;
                }

                var attrRep = DeclareConnectorFields(
                    attrType,
                    attrName,
                    semantic,
                    memberSpan.IndentSpan() );

                result.AddField(
                    attrName,
                    attrRep);
            }
            span.WriteLine("};");
            span.WriteLine();

            _typeHeaderSpan.Add(span);

            return result;
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:71,代码来源:EmitContextHLSL.cs

示例4: EmitGlobalStruct

        public IEmitVal EmitGlobalStruct(
            string name,
            IEmitVal[] members )
        {
            var span = new Span();

            name = string.Format(
                "_spark_global_{0}{1}",
                name ?? "",
                _globalCounter++ );

            span.WriteLine( "struct {" );
            var typeSpan = span.IndentSpan();
            for( int ii = 0; ii < members.Length; ++ii )
            {
                var memberType = (EmitTypeCPP) members[ii].Type;
                typeSpan.WriteLine( "{0};", memberType.Declare( string.Format( "_m{0}", ii ) ) );
            }
            span.WriteLine( "}} {0} = {{", name);
            for( int ii = 0; ii < members.Length; ++ii )
            {
                if( ii != 0 )
                    span.WriteLine( "," );
                span.Write( members[ ii ].ToString() );
            }
            span.WriteLine( " };" );

            _sourceSpan.Add( span );

            return new EmitValCPP(
                Target,
                name,
                Target.GetOpaqueType( "void" ) );
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:34,代码来源:EmitTargetCPP.cs

示例5: EmitMethodCPP

        public EmitMethodCPP(
            EmitClassCPP clazz,
            string prefix,
            string name,
            string cconv,
            IEmitType resultType,
            Span headerSpan,
            Span sourceSpan)
        {
            _class = clazz;
            _name = name;
            _cconv = cconv;
            _resultType = resultType;
            _headerSpan = headerSpan;
            _sourceSpan = sourceSpan;

            _headerSpan.Write( "static " );
            _headerParamsSpan = CreateSignatureSpan(
                _name,
                _headerSpan);
            _headerSpan.WriteLine(";");

            _fullName = prefix + _name;

            _sourceParamsSpan = CreateSignatureSpan(
                prefix + _name,
                _sourceSpan);
            _sourceSpan.WriteLine();
            _sourceSpan.WriteLine("{");
            _bodySpan = _sourceSpan.IndentSpan();
            _sourceSpan.WriteLine("}");

            _thisParameter = (EmitValCPP) AddParameter(
                Target.Pointer( clazz ),
                "self" );
            _entryBlock = new EmitBlockCPP(this, _bodySpan.InsertSpan());
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:37,代码来源:EmitTargetCPP.cs

示例6: EmitClassCPP

        public EmitClassCPP(
            EmitModuleCPP module,
            string name,
            EmitClassCPP baseClass,
            Span headerSpan,
            Span sourceSpan)
        {
            _module = module;
            _name = name;
            _base = baseClass;
            _headerSpan = headerSpan;
            _sourceSpan = sourceSpan;

            string baseClassString = "";
            if (baseClass != null)
                baseClassString = string.Format(" : public {0}", baseClass._name);

            _headerSpan.WriteLine("class {0}{1}", _name, baseClassString);
            _headerSpan.WriteLine("{");
            _headerSpan.WriteLine("public:");
            _publicSpan = _headerSpan.IndentSpan();
            _publicFieldsSpan = _publicSpan.InsertSpan();
            _headerSpan.WriteLine("protected:");
            _protectedSpan = _headerSpan.IndentSpan();
            _headerSpan.WriteLine("public:");
            _privateSpan = _headerSpan.IndentSpan();
            _headerSpan.WriteLine("};");

            _sourceSpan.WriteLine("// {0}", _name);
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:30,代码来源:EmitTargetCPP.cs


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