protected void WriteBlock(string toReplace, CodeGenerationTypeData[] codeGenerationTypeData,
                                  Func <CodeGenerationTypeData, string> writeSingle, bool withNewline = true, Func <string, string> afterAll = null)
        {
            m_Builder.Clear();
            var length = codeGenerationTypeData.Length;

            for (var i = 0; i < length; i++)
            {
                var block = writeSingle(codeGenerationTypeData[i]);
                if (string.IsNullOrEmpty(block))
                {
                    continue;
                }

                m_Builder.Append(block);
                if (withNewline && i < length - 1)
                {
                    m_Builder.Append(NewLine);
                }
            }

            var builtString = m_Builder.ToString();

            builtString = afterAll == null ? builtString : afterAll.Invoke(builtString);

            // Capture the newline in search string to overwrite it
            toReplace     += NewLine;
            BufferContents = BufferContents.Replace(toReplace, builtString);
        }
Ejemplo n.º 2
0
        private static void FlushBuffer(
            CodeGeneratorParameters parameters,
            BufferContents contents,
            StringBuilder buffer,
            StringBuilder output,
            int lineNumber)
        {
            if (parameters.IncludeLineDirectives)
            {
                output.AppendLine($"#line {lineNumber}");
            }

            if (buffer.Length > 0)
            {
                switch (contents)
                {
                case BufferContents.Literal:
                    string literal = buffer.ToString().Replace("\"", "\"\"");
                    output.AppendLine($"_WriteLiteral(@\"{literal}\");");
                    break;

                case BufferContents.Expression:
                    output.AppendLine($"_Write({buffer.ToString()});");
                    break;
                }

                buffer.Clear();
            }
        }
 public override bool TryGenerateCode(CodeGenerationTypeData[] typeData)
 {
     WriteRateConditionsInternal(typeData);
     WriteRateConditionTypeInternal(typeData);
     BufferContents = BufferContents.Replace("{TraitCollectionClassName}", nameof(CachedTraitCollection));
     return(TryWriteToFile());
 }
        public override bool TryGenerateCode(CodeGenerationTypeData[] typeData)
        {
            WriteFindTraitsInternal(typeData);
            WriteFillRequirementType(typeData);
            WriteUpdateRequirementType(typeData);
            WriteUpdateQueryMatch(typeData);
            WriteDataPassesAllConditionsInternal(typeData);

            BufferContents = BufferContents.Replace("{TraitCollectionClassName}", nameof(CachedTraitCollection));
            return(TryWriteToFile());
        }
Ejemplo n.º 5
0
 public override bool TryGenerateCode(CodeGenerationTypeData[] typeData)
 {
     WriteBackingFields(typeData);
     WriteGetTraitProviderBlock(typeData);
     WriteStartBufferingBlock(typeData);
     WriteStopBufferingBlock(typeData);
     WriteInitializeTraitProviders(typeData);
     WriteUnloadTraitsBlock(typeData);
     WriteClearTraitsBlock(typeData);
     BufferContents = BufferContents.Replace("{TraitCollectionClassName}", nameof(CachedTraitCollection));
     return(TryWriteToFile());
 }
Ejemplo n.º 6
0
 public override bool TryGenerateCode(CodeGenerationTypeData[] codeGenerationTypeRegistry)
 {
     WriteTraitDataFields(codeGenerationTypeRegistry);
     WriteClearBlock(codeGenerationTypeRegistry);
     WriteTakeSnapshotBlock(codeGenerationTypeRegistry);
     WriteGetTraitsBlock(codeGenerationTypeRegistry);
     WriteTryGetTraitBlock(codeGenerationTypeRegistry);
     WriteGetPotentialConditionsBlock(codeGenerationTypeRegistry);
     WriteCollectPotentialRelationsBlock(codeGenerationTypeRegistry);
     WriteGetAllTraitNamesBlock(codeGenerationTypeRegistry);
     BufferContents = BufferContents.Replace("{TraitCollectionClassName}", nameof(CachedTraitCollection));
     return(TryWriteToFile());
 }
Ejemplo n.º 7
0
        private static void FlushBuffer(BufferContents state, StringBuilder buffer, StringBuilder output)
        {
            if (buffer.Length > 0)
            {
                switch (state)
                {
                    case BufferContents.Literal:
                        output.AppendLine(string.Format("WriteLiteral(@\"{0}\");", buffer.ToString().Replace("\"", "\"\"")));
                        break;

                    case BufferContents.Expression:
                        output.AppendLine(string.Format("Write({0});", buffer.ToString()));
                        break;
                }

                buffer.Clear();
            }
        }