Exemplo n.º 1
0
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            _writer = context.CreateCodeWriter();

            string prefix = context.BuildCodeString(
                cw => cw.WriteHelperHeaderPrefix(context.Host.GeneratedClassContext.TemplateTypeName, context.Host.StaticHelpers));

            _writer.WriteLinePragma(
                context.GenerateLinePragma(Signature.Location, prefix.Length, Signature.Value.Length));
            _writer.WriteSnippet(prefix);
            _writer.WriteSnippet(Signature);
            if (HeaderComplete)
            {
                _writer.WriteHelperHeaderSuffix(context.Host.GeneratedClassContext.TemplateTypeName);
            }
            _writer.WriteLinePragma(null);
            if (HeaderComplete)
            {
                _writer.WriteReturn();
                _writer.WriteStartConstructor(context.Host.GeneratedClassContext.TemplateTypeName);
                _writer.WriteStartLambdaDelegate(HelperWriterName);
            }

            _statementCollectorToken = context.ChangeStatementCollector(AddStatementToHelper);
            _oldWriter = context.TargetWriterName;
            context.TargetWriterName = HelperWriterName;
        }
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            _writer = context.CreateCodeWriter();

            string prefix = context.BuildCodeString(
                cw => cw.WriteHelperHeaderPrefix(context.Host.GeneratedClassContext.TemplateTypeName, context.Host.StaticHelpers));

            _writer.WriteLinePragma(
                context.GenerateLinePragma(Signature.Location, prefix.Length, Signature.Value.Length));
            _writer.WriteSnippet(prefix);
            _writer.WriteSnippet(Signature);
            if (HeaderComplete)
            {
                _writer.WriteHelperHeaderSuffix(context.Host.GeneratedClassContext.TemplateTypeName);
            }
            _writer.WriteLinePragma(null);
            if (HeaderComplete)
            {
                _writer.WriteReturn();
                _writer.WriteStartConstructor(context.Host.GeneratedClassContext.TemplateTypeName);
                _writer.WriteStartLambdaDelegate(HelperWriterName);
            }

            _statementCollectorToken = context.ChangeStatementCollector(AddStatementToHelper);
            _oldWriter = context.TargetWriterName;
            context.TargetWriterName = HelperWriterName;
        }
Exemplo n.º 3
0
 public static void WriteLocationTaggedString(this CodeWriter writer, LocationTagged <string> value)
 {
     writer.WriteStartMethodInvoke("Tuple.Create");
     writer.WriteStringLiteral(value.Value);
     writer.WriteParameterSeparator();
     writer.WriteSnippet(value.Location.AbsoluteIndex.ToString(CultureInfo.CurrentCulture));
     writer.WriteEndMethodInvoke();
 }
Exemplo n.º 4
0
        public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
        {
            _statementCollectorToken.Dispose();
            if (HeaderComplete)
            {
                _writer.WriteEndLambdaDelegate();
                _writer.WriteEndConstructor();
                _writer.WriteEndStatement();
            }
            if (Footer != null && !String.IsNullOrEmpty(Footer.Value))
            {
                _writer.WriteLinePragma(
                    context.GenerateLinePragma(Footer.Location, 0, Footer.Value.Length));
                _writer.WriteSnippet(Footer);
                _writer.WriteLinePragma();
            }
            _writer.WriteHelperTrailer();

            context.GeneratedClass.Members.Add(new CodeSnippetTypeMember(_writer.Content));
            context.TargetWriterName = _oldWriter;
        }
Exemplo n.º 5
0
        private void WriteBlockToHelperContent(BlockContext block)
        {
            Debug.Assert(InHelper);

            // Create a code writer
            CodeWriter writer = CreateCodeWriter();

            // Build the block content
            string content = block.Writer.Content;

            if (block.SourceCodeStart != null && block.BlockType != BlockType.Markup)
            {
                content = PadContent(block, content);
            }

            // Generate the line pragma
            bool writePragma = false;
            int  lineNumber  = 0;

            if (block.WriteLinePragma)
            {
                writePragma = GenerateLinePragmas && block.SourceCodeStart != null && block.BlockType != BlockType.Markup;
                if (writePragma)
                {
                    lineNumber = block.SourceCodeStart.Value.LineIndex + 1;
                    if (DesignTimeMode)
                    {
                        lineNumber = _nextDesignTimeLinePragma++;
                    }
                    writer.WriteLinePragma(lineNumber, SourceFileName);
                }
            }

            // Write the block content
            writer.WriteSnippet(content);
            if (writePragma)
            {
                writer.WriteLinePragma(null, SourceFileName);
            }

            // Write this out to the helper content
            CurrentHelper.Content.AppendLine(writer.Content);

            // Configure the design-time pragma
            if (writePragma && DesignTimeMode)
            {
                Debug.Assert(block.GeneratedCodeLength != null);
                AddCodeMapping(lineNumber, block.SourceCodeStart.Value, block.GeneratedCodeStart, block.GeneratedCodeLength.Value);
            }
        }