Exemple #1
0
        public static string GenerateHeader(TypeDescription type, List <TypeDescription> types, Dictionary <string, TypeGeneratedCode> allGeneratedTypeContent, Bundle bundle)
        {
            var allTopLevelTypes = Types.SortTopLevelTypesTopologically(type, types, bundle);
            var typeNamespaces   = Text.GetNamespaceFromTypeName(type.QualifiedName);
            var requiredIncludes = Types.GetRequiredTypeIncludes(type, bundle).Select(inc => $"#include \"{string.Concat(Enumerable.Repeat("../", type.QualifiedName.Count(c => c == '.')))}{inc}\"");
            var allNestedEnums   = Types.GetRecursivelyNestedEnums(type);
            var enumDefs         = allNestedEnums.Select(enumDef => EnumGenerator.GenerateEnum(Types.GetTypeClassName(enumDef.QualifiedName, bundle), enumDef, bundle).Replace($"enum {enumDef.Name}", $"class {enumDef.Name}_{enumDef.Name}"));

            var builder = new StringBuilder();

            builder.AppendLine($@"// Generated by {UnrealGenerator.GeneratorTitle}

#pragma once

#include ""CoreMinimal.h""
#include ""Utils/SchemaOption.h""
#include <WorkerSDK/improbable/c_schema.h>
#include <WorkerSDK/improbable/c_worker.h>

#include ""{string.Concat(Enumerable.Repeat("../", type.QualifiedName.Count(c => c == '.')))}{HelperFunctions.HeaderPath}""
");
            if (requiredIncludes.Count() > 0)
            {
                builder.AppendLine(string.Join(Environment.NewLine, requiredIncludes));
                builder.AppendLine();
            }

            builder.AppendLine(string.Join(Environment.NewLine, typeNamespaces.Select(t => $"namespace {t} {{")));
            builder.AppendLine();

            if (allTopLevelTypes.Count() > 1)
            {
                builder.AppendLine(string.Join(Environment.NewLine, allTopLevelTypes.Select(topLevelType => $"class {Types.GetTypeClassName(topLevelType.QualifiedName, bundle)};")));
                builder.AppendLine();
            }

            if (allNestedEnums.Count() > 0)
            {
                builder.AppendLine(string.Join(Environment.NewLine, enumDefs));
                builder.AppendLine();
            }

            builder.AppendLine($@"{string.Join(Environment.NewLine, allTopLevelTypes.Select(topLevelType => GenerateTypeClass(Types.GetTypeClassName(topLevelType.QualifiedName, bundle), types.Find(t => t.QualifiedName == topLevelType.QualifiedName), types, bundle)))}
{string.Join(Environment.NewLine, allTopLevelTypes.Select(nestedType => GenerateHashFunction(Types.GetTypeClassName(nestedType.QualifiedName, bundle))))}

{string.Join(Environment.NewLine, typeNamespaces.Reverse().Select(t => $"}} // namespace {t}"))}
");

            return(builder.ToString());
        }
        public static string GenerateSource(TypeDescription type, List <TypeDescription> types, Dictionary <string, TypeGeneratedCode> allGeneratedTypeContent, Bundle bundle)
        {
            var allNestedTypes = Types.GetRecursivelyNestedTypes(type);
            var allNestedEnums = Types.GetRecursivelyNestedEnums(type);
            var typeNamespaces = Text.GetNamespaceFromTypeName(type.QualifiedName);

            var builder = new StringBuilder();

            builder.AppendLine($@"// Generated by {UnrealGenerator.GeneratorTitle}

#include ""{type.Name}.h""
#include <set>
#include ""{string.Concat(Enumerable.Repeat("../", type.QualifiedName.Count(c => c == '.')))}{MapEquals.HeaderName}""

// Generated from {Path.GetFullPath(bundle.TypeToFileName[type.QualifiedName])}({type.SourceReference.Line},{type.SourceReference.Column})
{string.Join(Environment.NewLine, typeNamespaces.Select(t => $"namespace {t} {{"))}

{GenerateTypeFunctions(type.Name, type, bundle)}");

            if (type.ComponentId.HasValue)
            {
                builder.AppendLine(GenerateComponentUpdateFunctions(type.Name, type, bundle));
            }

            if (allNestedTypes.Count() > 0)
            {
                builder.AppendLine(string.Join(Environment.NewLine, allNestedTypes.Select(topLevelType => GenerateTypeFunctions(Types.GetTypeClassName(topLevelType.QualifiedName, bundle), types.Find(t => t.QualifiedName == topLevelType.QualifiedName), bundle))));
            }

            builder.AppendLine(GenerateHashFunction(type, bundle));

            if (allNestedTypes.Count() > 0)
            {
                builder.AppendLine(string.Join(Environment.NewLine, allNestedTypes.Select(topLevelType => GenerateHashFunction(topLevelType, bundle))));
            }
            if (allNestedEnums.Count() > 0)
            {
                builder.AppendLine(string.Join(Environment.NewLine, allNestedEnums.Select(nestedEnum => GenerateHashFunction(nestedEnum, bundle))));
            }

            builder.AppendLine(string.Join(Environment.NewLine, typeNamespaces.Reverse().Select(t => $"}} // namespace {t}")));

            return(builder.ToString());
        }