Ejemplo n.º 1
0
        private void GenerateTemplates(List <GeneratorOutput> outputs, IEnumerable <TranslationUnit> units)
        {
            foreach (var unit in units)
            {
                var includeDir = Path.GetDirectoryName(unit.FilePath);
                var templates  = Generate(new[] { unit });
                if (templates.Count == 0)
                {
                    return;
                }

                CurrentOutputNamespace = unit.Module.OutputNamespace;
                foreach (var template in templates)
                {
                    template.Process();
                }

                var output = new GeneratorOutput
                {
                    TranslationUnit = unit,
                    Templates       = templates
                };

                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 2
0
        private void GenerateTemplates(List <GeneratorOutput> outputs, IEnumerable <TranslationUnit> units)
        {
            foreach (var unit in units)
            {
                var templates = Generate(new[] { unit });
                if (templates.Count == 0)
                {
                    return;
                }

                foreach (var template in templates)
                {
                    template.Process();
                }

                var output = new GeneratorOutput
                {
                    TranslationUnit = unit,
                    Outputs         = templates
                };

                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 3
0
 private void OnUnitGenerated(GeneratorOutput output)
 {
     needsStreamInclude = false;
     foreach (var template in output.Templates)
     {
         foreach (var block in template.FindBlocks(CLIBlockKind.MethodBody))
         {
             var method = block.Declaration as Method;
             VisitMethod(method, block);
         }
         if (needsStreamInclude)
         {
             var sourcesTemplate = template as CLISources;
             if (sourcesTemplate != null)
             {
                 foreach (var block in sourcesTemplate.FindBlocks(CLIBlockKind.Includes))
                 {
                     block.WriteLine("#include <sstream>");
                     block.WriteLine("");
                     break;
                 }
                 break;
             }
         }
     }
 }
Ejemplo n.º 4
0
        public virtual GeneratorOutput GenerateModule(Module module)
        {
            var output = new GeneratorOutput
            {
                TranslationUnit = new TranslationUnit
                {
                    FilePath = $"{module.LibraryName}",
                    Module   = module
                },
                Outputs = Generate(module.Units.GetGenerated())
            };

            output.Outputs[0].Process();

            return(output);
        }
Ejemplo n.º 5
0
        private void GenerateSingleTemplate(IEnumerable <TranslationUnit> units, ICollection <GeneratorOutput> outputs)
        {
            var output = new GeneratorOutput
            {
                TranslationUnit = new TranslationUnit
                {
                    FilePath = string.Format("{0}.cs", Driver.Options.OutputNamespace ?? Driver.Options.LibraryName)
                },
                Templates = Generate(units)
            };

            output.Templates[0].Process();
            outputs.Add(output);

            OnUnitGenerated(output);
        }
Ejemplo n.º 6
0
        private GeneratorOutput GenerateModuleTemplate(Module module)
        {
            var output = new GeneratorOutput
            {
                TranslationUnit = new TranslationUnit
                {
                    FilePath = $"{module.LibraryName}.cs",
                    Module   = module
                },
                Outputs = Generate(module.Units.GetGenerated())
            };

            output.Outputs[0].Process();

            OnUnitGenerated(output);

            return(output);
        }
Ejemplo n.º 7
0
        private void GenerateSingleTemplate(ICollection <GeneratorOutput> outputs)
        {
            foreach (var module in Context.Options.Modules)
            {
                var output = new GeneratorOutput
                {
                    TranslationUnit = new TranslationUnit
                    {
                        FilePath = $"{module.LibraryName}.cs",
                        Module   = module
                    },
                    Outputs = Generate(module.Units.GetGenerated())
                };
                output.Outputs[0].Process();
                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 8
0
        private void GenerateSingleTemplate(ICollection <GeneratorOutput> outputs)
        {
            foreach (var module in Context.Options.Modules)
            {
                CurrentOutputNamespace = module.OutputNamespace;
                var output = new GeneratorOutput
                {
                    TranslationUnit = new TranslationUnit
                    {
                        FilePath = string.Format("{0}.cs", module.LibraryName),
                        Module   = module
                    },
                    Templates = Generate(module.Units.GetGenerated())
                };
                output.Templates[0].Process();
                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 9
0
 private void OnUnitGenerated(GeneratorOutput generatorOutput)
 {
     var blocks = (from template in generatorOutput.Templates
                   from block in template.FindBlocks(CSharpBlockKind.Method)
                   where this.events.Contains(block.Declaration)
                   select block).ToList();
     foreach (var block in blocks)
     {
         var method = (Function) block.Declaration;
         string @event;
         if (((Class) method.Namespace).Methods.Any(m => m != method && m.OriginalName == method.OriginalName))
         {
             @event = method.OriginalName;
         }
         else
         {
             @event = char.ToUpperInvariant(method.OriginalName[0]) + method.OriginalName.Substring(1);
         }
         var blockIndex = block.Parent.Blocks.IndexOf(block);
         var eventBlock = new Block(CSharpBlockKind.Event);
         eventBlock.WriteLine("public event global::System.Action<object, {0}> {1};",
                              method.Parameters[0].Type, @event);
         eventBlock.NewLine();
         const string eventHandler = @"__eventHandler";
         var raiseEvent = string.Format(
             @"var {0} = {1};
     if ({0} != null)
     {0}(this, {2});
     if ({2}.Handled)
     return{3};
     ",
             eventHandler, @event, method.Parameters[0].Name,
             method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : " true");
         if (block.Blocks.Count > 0 && block.Blocks[0].Kind == BlockKind.BlockComment)
         {
             eventBlock.Blocks.Add(block.Blocks[0]);
         }
         block.Parent.Blocks.Insert(blockIndex, eventBlock);
         block.Text.StringBuilder.Replace("var __slot", raiseEvent + "    var __slot");
     }
 }
Ejemplo n.º 10
0
        public virtual GeneratorOutput GenerateUnit(TranslationUnit unit)
        {
            var codeGenerators = Generate(new[] { unit });

            if (codeGenerators.Count == 0)
            {
                return(null);
            }

            foreach (var codeGen in codeGenerators)
            {
                codeGen.Process();
            }

            var output = new GeneratorOutput
            {
                TranslationUnit = unit,
                Outputs         = codeGenerators
            };

            return(output);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Generates the outputs.
        /// </summary>
        public virtual List <GeneratorOutput> Generate()
        {
            var outputs = new List <GeneratorOutput>();

            foreach (var unit in Driver.Library.TranslationUnits)
            {
                if (unit.Ignore || !unit.HasDeclarations)
                {
                    continue;
                }

                if (unit.IsSystemHeader)
                {
                    continue;
                }

                var templates = Generate(unit);
                if (templates.Count == 0)
                {
                    continue;
                }

                foreach (var template in templates)
                {
                    template.Process();
                }

                var output = new GeneratorOutput
                {
                    TranslationUnit = unit,
                    Templates       = templates
                };
                outputs.Add(output);

                OnUnitGenerated(output);
            }

            return(outputs);
        }
Ejemplo n.º 12
0
 private void OnUnitGenerated(GeneratorOutput generatorOutput)
 {
     var blocks = (from template in generatorOutput.Templates
                   from block in template.FindBlocks(CSharpBlockKind.Method)
                   where this.events.Contains(block.Declaration)
                   select block).ToList();
     foreach (var block in blocks)
     {
         var method = (Function) block.Declaration;
         var @event = char.ToUpperInvariant(method.OriginalName[0]) + method.OriginalName.Substring(1);
         var blockIndex = block.Parent.Blocks.IndexOf(block);
         var eventBlock = new Block(CSharpBlockKind.Event);
         eventBlock.WriteLine("public event global::System.Action<object, {0}> {1};",
                              method.Parameters[0].Type, @event);
         eventBlock.NewLine();
         const string eventHandler = @"__eventHandler";
         var raiseEvent = string.Format(
             @"    var {0} = {1};
     if ({0} != null)
     {0}(this, {2});
     ", eventHandler, @event, method.Parameters[0].Name);
         if (block.Blocks.Count > 0 && block.Blocks[0].Kind == BlockKind.BlockComment)
         {
             eventBlock.Blocks.Add(block.Blocks[0]);
         }
         block.Parent.Blocks.Insert(blockIndex, eventBlock);
         var stringBuilder = block.Text.StringBuilder;
         if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
         {
             stringBuilder.Insert(stringBuilder.Length - 1 - Environment.NewLine.Length, raiseEvent);
         }
         else
         {
             const string @return = "    return ";
             stringBuilder.Replace(@return, raiseEvent + @return);
         }
     }
 }
Ejemplo n.º 13
0
        public virtual GeneratorOutput GenerateModule(Module module)
        {
            var generatedUnits = module.Units.GetGenerated().ToList();

            if (generatedUnits.Count == 0)
            {
                return(null);
            }

            var output = new GeneratorOutput
            {
                TranslationUnit = new TranslationUnit
                {
                    FilePath = $"{module.LibraryName}.h",
                    Module   = module
                },
                Outputs = Generate(generatedUnits)
            };

            output.Outputs[0].Process();

            return(output);
        }
Ejemplo n.º 14
0
        private void GenerateTemplate(TranslationUnit unit, ICollection <GeneratorOutput> outputs)
        {
            var templates = Generate(new[] { unit });

            if (templates.Count == 0)
            {
                return;
            }

            foreach (var template in templates)
            {
                template.Process();
            }

            var output = new GeneratorOutput
            {
                TranslationUnit = unit,
                Templates       = templates
            };

            outputs.Add(output);

            OnUnitGenerated(output);
        }
Ejemplo n.º 15
0
        public override void VisitGeneratorOutput(GeneratorOutput output)
        {
            foreach (var template in output.Templates)
            {
                var blocks = template.FindBlocks(CLIBlockKind.MethodBody);

                foreach (var block in blocks)
                    VisitMethodBody(block);
            }
        }
 private void OnUnitGenerated(GeneratorOutput generatorOutput)
 {
     foreach (Block block in from template in generatorOutput.Templates
                             from block in template.FindBlocks(CSharpBlockKind.Event)
                             select block)
     {
         Event @event = (Event) block.Declaration;
         if (this.events.Contains(@event))
         {
             block.Text.StringBuilder.Clear();
             Class @class = (Class) @event.Namespace;
             if (!this.addedEventHandlers && @class.Name == "QObject")
             {
                 block.WriteLine("protected readonly System.Collections.Generic.List<QEventHandler> " +
                                 "eventFilters = new System.Collections.Generic.List<QEventHandler>();");
                 block.NewLine();
                 this.addedEventHandlers = true;
             }
             bool isQAbstractScrollArea = @class.Name != "QAbstractScrollArea";
             if (@event.OriginalDeclaration.Comment != null)
             {
                 block.WriteLine("/// <summary>");
                 foreach (string line in HtmlEncoder.HtmlEncode(@event.OriginalDeclaration.Comment.BriefText).Split(
                                             Environment.NewLine.ToCharArray()))
                 {
                     block.WriteLine("/// <para>{0}</para>", line);
                 }
                 block.WriteLine("/// </summary>");
             }
             block.WriteLine(@"public {0} event EventHandler<QEventArgs<{1}>> {2}
     {{
     add
     {{
     QEventArgs<{1}> qEventArgs = new QEventArgs<{1}>(new System.Collections.Generic.List<QEvent.Type> {{ {3} }});
     QEventHandler<{1}> qEventHandler = new QEventHandler<{1}>(this{4}, qEventArgs, value);
     foreach (QEventHandler eventFilter in eventFilters)
     {{
     this{4}.RemoveEventFilter(eventFilter);
     }}
     eventFilters.Add(qEventHandler);
     for (int i = eventFilters.Count - 1; i >= 0; i--)
     {{
     this{4}.InstallEventFilter(eventFilters[i]);
     }}
     }}
     remove
     {{
     for (int i = eventFilters.Count - 1; i >= 0; i--)
     {{
     QEventHandler eventFilter = eventFilters[i];
     if (eventFilter.Handler == value)
     {{
         this{4}.RemoveEventFilter(eventFilter);
         eventFilters.RemoveAt(i);
         break;
     }}
     }}
     }}
     }}",
                 isQAbstractScrollArea ? "virtual" : "override", @event.Parameters[0].Type, @event.Name,
                 this.GetEventTypes(@event), isQAbstractScrollArea ? string.Empty : ".Viewport");
         }
     }
 }
Ejemplo n.º 17
0
 public virtual void VisitGeneratorOutput(GeneratorOutput output)
 {
     
 }
Ejemplo n.º 18
0
        private void GenerateTemplates(List<GeneratorOutput> outputs, IEnumerable<TranslationUnit> units)
        {
            foreach (var unit in units)
            {
                var includeDir = Path.GetDirectoryName(unit.FilePath);
                var templates = Generate(new[] { unit });
                if (templates.Count == 0)
                    return;

                CurrentOutputNamespace = unit.Module.OutputNamespace;
                foreach (var template in templates)
                {
                    template.Process();
                }

                var output = new GeneratorOutput
                {
                    TranslationUnit = unit,
                    Templates = templates
                };

                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 19
0
        private void GenerateSignalEvents(GeneratorOutput generatorOutput)
        {
            foreach (Block block in from template in generatorOutput.Templates
                                    from block in template.FindBlocks(CSharpBlockKind.Event)
                                    select block)
            {
                Event @event = (Event) block.Declaration;
                if (this.events.Contains(@event))
                {
                    block.Text.StringBuilder.Clear();
                    Class @class = (Class) @event.Namespace;

                    int argNum = 1;
                    StringBuilder fullNameBuilder = new StringBuilder("global::System.Action");
                    foreach (Parameter parameter in @event.Parameters)
                    {
                        argNum++;
                        if (argNum == 2)
                        {
                            fullNameBuilder.Append('<');
                        }
                        fullNameBuilder.Append(parameter.Type);
                        fullNameBuilder.Append(',');
                    }
                    if (fullNameBuilder[fullNameBuilder.Length - 1] == ',')
                    {
                        fullNameBuilder[fullNameBuilder.Length - 1] = '>';
                    }
                    string signature = string.Format("{0}({1})", @event.OriginalName,
                        string.Join(", ",
                            from e in @event.Parameters
                            select GetOriginalParameterType(e)));
                    Event existing = @class.Events.FirstOrDefault(e => e.Name == @event.Name);
                    if (existing != null && existing != @event)
                    {
                        if (@event.Parameters.Count > 0)
                        {
                            @event.Name += GetSignalEventSuffix(@event);
                        }
                        else
                        {
                            existing.Name += GetSignalEventSuffix(@event);
                        }
                    }
                    else
                    {
                        if (@event.Parameters.Count > 0 &&
                            (@class.Methods.Any(m => m.IsGenerated && m.OriginalName == @event.Name) ||
                             @class.Properties.Any(p => p.IsGenerated && p.OriginalName == @event.Name)))
                        {
                            @event.Name += GetSignalEventSuffix(@event);
                        }
                    }
                    if (@event.OriginalDeclaration.Comment != null)
                    {
                        block.WriteLine("/// <summary>");
                        foreach (string line in HtmlEncoder.HtmlEncode(@event.OriginalDeclaration.Comment.BriefText).Split(
                                                    Environment.NewLine.ToCharArray()))
                        {
                            block.WriteLine("/// <para>{0}</para>", line);
                        }
                        block.WriteLine("/// </summary>");
                    }
                    var finalName = char.ToUpperInvariant(@event.Name[0]) + @event.Name.Substring(1);
                    if (@event.Namespace.Declarations.Exists(d => d != @event && d.Name == finalName))
                    {
                        finalName += "Signal";
                    }
                    block.WriteLine(string.Format(@"public event {0} {1}
            {{
            add
            {{
            ConnectDynamicSlot(this, ""{2}"", value);
            }}
            remove
            {{
            DisconnectDynamicSlot(this, ""{2}"", value);
            }}
            }}", fullNameBuilder, finalName, signature));
                }
            }
            var qtMetacall = (
                from template in generatorOutput.Templates
                from block in template.FindBlocks(CSharpBlockKind.Method)
                where block.Declaration != null && block.Declaration.Name == "QtMetacall" &&
                      block.Declaration.Namespace.Name == "QObject"
                select block).FirstOrDefault();
            if (qtMetacall != null)
            {
                qtMetacall.Text.StringBuilder.Replace("return __ret;", "return HandleQtMetacall(__ret, _0, _2);");
            }
        }
 private void OnUnitGenerated(GeneratorOutput generatorOutput)
 {
     this.GenerateSignalEvents(generatorOutput);
 }
Ejemplo n.º 21
0
        private void GenerateSingleTemplate(ICollection<GeneratorOutput> outputs)
        {
            foreach (var module in Context.Options.Modules)
            {
                CurrentOutputNamespace = module.OutputNamespace;
                var output = new GeneratorOutput
                {
                    TranslationUnit = new TranslationUnit
                    {
                        FilePath = string.Format("{0}.cs", module.LibraryName),
                        Module = module
                    },
                    Templates = Generate(module.Units.GetGenerated())
                };
                output.Templates[0].Process();
                outputs.Add(output);

                OnUnitGenerated(output);
            }
        }
Ejemplo n.º 22
0
 private void OnUnitGenerated(GeneratorOutput generatorOutput)
 {
     foreach (Block block in from template in generatorOutput.Templates
                             from block in template.FindBlocks(CSharpBlockKind.Event)
                             select block)
     {
         Event @event = (Event) block.Declaration;
         if (this.events.Contains(@event))
         {
             block.Text.StringBuilder.Clear();
             Class @class = (Class) @event.Namespace;
             if (!this.addedEventHandlers && (@class.Name == "QObject" || @class.Name == "QGraphicsItem"))
             {
                 block.WriteLine("protected readonly System.Collections.Generic.List<{0}> " +
                                 "eventFilters = new System.Collections.Generic.List<{0}>();",
                                 @class.Name == "QObject" ? "QtCore.QEventHandler" : "QtWidgets.QSceneEventHandler");
                 block.NewLine();
                 this.addedEventHandlers = true;
             }
             if (@event.OriginalDeclaration.Comment != null)
             {
                 block.WriteLine("/// <summary>");
                 foreach (string line in HtmlEncoder.HtmlEncode(@event.OriginalDeclaration.Comment.BriefText).Split(
                                             Environment.NewLine.ToCharArray()))
                 {
                     block.WriteLine("/// <para>{0}</para>", line);
                 }
                 block.WriteLine("/// </summary>");
             }
             var @base = @class.GetNonIgnoredRootBase();
             block.WriteLine(@"public virtual event EventHandler<QtCore.QEventArgs<{0}>> {1}
     {{
     add
     {{
     var qEventArgs = new QtCore.QEventArgs<{0}>(new System.Collections.Generic.List<QtCore.QEvent.Type> {{ {2} }});
     var qEventHandler = new {4}<{0}>(this, qEventArgs, value);
     foreach (var eventFilter in eventFilters)
     {{
     this.Remove{3}EventFilter(eventFilter);
     }}
     eventFilters.Add(qEventHandler);
     for (int i = eventFilters.Count - 1; i >= 0; i--)
     {{
     this.Install{3}EventFilter(eventFilters[i]);
     }}
     }}
     remove
     {{
     for (int i = eventFilters.Count - 1; i >= 0; i--)
     {{
     var eventFilter = eventFilters[i];
     if (eventFilter.Handler == value)
     {{
         this.Remove{3}EventFilter(eventFilter);
         eventFilters.RemoveAt(i);
         break;
     }}
     }}
     }}
     }}",
                 @event.Parameters[0].Type, @event.Name, this.GetEventTypes(@event),
                 @base.Name == "QObject" ? string.Empty : "Scene",
                 @base.Name == "QObject" ? "QtCore.QEventHandler" : "QtWidgets.QSceneEventHandler");
         }
     }
 }
        private void GenerateSignalEvents(GeneratorOutput generatorOutput)
        {
            foreach (Block block in from template in generatorOutput.Templates
                                    from block in template.FindBlocks(CSharpBlockKind.Event)
                                    select block)
            {
                Event @event = (Event) block.Declaration;
                if (this.events.Contains(@event))
                {
                    block.Text.StringBuilder.Clear();
                    Class @class = (Class) @event.Namespace;
                    if (!this.addedDynamicQObject && @class.Name == "QObject")
                    {
                        block.WriteLine(@"protected DynamicQObject dynamicQObject;");
                        block.NewLine();
                        block.WriteLine("protected DynamicQObject __DynamicQObject");
                        block.WriteStartBraceIndent();
                        block.WriteLine("get");
                        block.WriteStartBraceIndent();
                        block.WriteLine("if (dynamicQObject == null)");
                        block.WriteStartBraceIndent();
                        block.WriteLine("dynamicQObject = new DynamicQObject(null);");
                        block.WriteCloseBraceIndent();
                        block.WriteLine("return dynamicQObject;");
                        block.WriteCloseBraceIndent();
                        block.WriteCloseBraceIndent();
                        block.NewLine();
                        this.addedDynamicQObject = true;
                    }

                    int argNum = 1;
                    StringBuilder fullNameBuilder = new StringBuilder("Action");
                    foreach (Parameter parameter in @event.Parameters)
                    {
                        argNum++;
                        if (argNum == 2)
                        {
                            fullNameBuilder.Append('<');
                        }
                        fullNameBuilder.Append(parameter.Type);
                        fullNameBuilder.Append(',');
                    }
                    if (fullNameBuilder[fullNameBuilder.Length - 1] == ',')
                    {
                        fullNameBuilder[fullNameBuilder.Length - 1] = '>';
                    }
                    string signature = string.Format("{0}({1})", @event.OriginalName,
                        string.Join(", ",
                            from e in @event.Parameters
                            select GetOriginalParameterType(e)));
                    Event existing = @class.Events.FirstOrDefault(e => e.Name == @event.Name);
                    if (existing != null && existing != @event)
                    {
                        if (@event.Parameters.Count > 0)
                        {
                            @event.Name += GetSignalEventSuffix(@event);
                        }
                        else
                        {
                            existing.Name += GetSignalEventSuffix(@event);
                        }
                    }
                    else
                    {
                        if (@event.Parameters.Count > 0 &&
                            (@class.Methods.Any(m => m.IsGenerated && m.OriginalName == @event.Name) ||
                             @class.Properties.Any(p => p.IsGenerated && p.OriginalName == @event.Name)))
                        {
                            @event.Name += GetSignalEventSuffix(@event);
                        }
                    }
                    if (@event.OriginalDeclaration.Comment != null)
                    {
                        block.WriteLine("/// <summary>");
                        foreach (string line in HtmlEncoder.HtmlEncode(@event.OriginalDeclaration.Comment.BriefText).Split(
                                                    Environment.NewLine.ToCharArray()))
                        {
                            block.WriteLine("/// <para>{0}</para>", line);
                        }
                        block.WriteLine("/// </summary>");
                    }
                    block.WriteLine(string.Format(@"public event {0} {1}
            {{
            add
            {{
            __DynamicQObject.ConnectDynamicSlot(this, ""{2}"", value);
            }}
            remove
            {{
            __DynamicQObject.DisconnectDynamicSlot(this, ""{2}"", value);
            }}
            }}", fullNameBuilder, char.ToUpperInvariant(@event.Name[0]) + @event.Name.Substring(1), signature));
                }
            }
        }
Ejemplo n.º 24
0
 private void OnUnitGenerated(GeneratorOutput output)
 {
     foreach (var template in output.Templates)
     {
         foreach (var block in template.FindBlocks(CLIBlockKind.MethodBody))
         {
             var method = block.Declaration as Method;
             VisitMethod(method, block);
         }
     }
 }
Ejemplo n.º 25
0
        private void GenerateSingleTemplate(IEnumerable<TranslationUnit> units, ICollection<GeneratorOutput> outputs)
        {
            var output = new GeneratorOutput
            {
                TranslationUnit = new TranslationUnit
                {
                    FilePath = string.Format("{0}.cs", Driver.Options.OutputNamespace ?? Driver.Options.LibraryName)
                },
                Templates = Generate(units)
            };
            output.Templates[0].Process();
            outputs.Add(output);

            OnUnitGenerated(output);
        }
Ejemplo n.º 26
0
        private void GenerateTemplate(TranslationUnit unit, ICollection<GeneratorOutput> outputs)
        {
            var templates = Generate(new[] { unit });
            if (templates.Count == 0)
                return;

            foreach (var template in templates)
            {
                template.Process();
            }

            var output = new GeneratorOutput
            {
                TranslationUnit = unit,
                Templates = templates
            };
            outputs.Add(output);

            OnUnitGenerated(output);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Generates the outputs.
        /// </summary>
        public virtual List<GeneratorOutput> Generate()
        {
            var outputs = new List<GeneratorOutput>();

            foreach (var unit in Driver.ASTContext.TranslationUnits)
            {
                if (!unit.IsGenerated || !unit.HasDeclarations)
                    continue;

                if (unit.IsSystemHeader || !unit.IsValid)
                    continue;

                var templates = Generate(unit);
                if (templates.Count == 0)
                    continue;

                foreach (var template in templates)
                    template.Process();

                var output = new GeneratorOutput
                    {
                        TranslationUnit = unit,
                        Templates = templates
                    };
                outputs.Add(output);

                OnUnitGenerated(output);
            }

            return outputs;
        }
Ejemplo n.º 28
0
 public void ProcessUnit(GeneratorOutput output)
 {
     foreach (var template in output.Templates)
         WriteHeader(template.FindBlock(BlockKind.Header).Text);
 }