Esempio n. 1
0
        private IDictionary <string, string> GenerateBases(CodeGenerationInfo generationInfo)
        {
            var codes    = new Dictionary <string, string>();
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var ns       = string.Join(".", assembly.GetName().Name, "reader");
            var files    = assembly.GetManifestResourceNames().Where(item => item.StartsWith(ns) && (item.EndsWith(".h") || item.EndsWith(".cpp"))).ToArray();

            foreach (var item in files)
            {
                var value     = this.GetResourceString(item);
                var extension = Path.GetExtension(item).Replace(".", "[.]");
                var key       = Regex.Replace(item, "(^" + this.GetType().Namespace + @"[.])(\S+)" + extension, "$2").Replace('.', Path.DirectorySeparatorChar);
                //var name = item.Replace("Ntreev.Crema.Runtime.Generation.NativeC.", string.Empty);

                //var stream = new StreamReader(assembly.GetManifestResourceStream(item));
                //var text = stream.ReadToEnd();
                //stream.Dispose();

                value = this.ChangeReadNamespace(value, generationInfo);
                codes.Add(key + Path.GetExtension(item), value);
            }

            var cremaBase    = this.GenerateBaseHeader(generationInfo);
            var cremaBaseCpp = this.GenerateBaseCpp(generationInfo);

            codes.Add("crema_base.h", cremaBase);
            codes.Add("crema_base.cpp", cremaBaseCpp);

            return(codes);
        }
Esempio n. 2
0
 public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetTables())
     {
         Create(codeNamespace, item, generationInfo);
     }
 }
Esempio n. 3
0
        public IDictionary <string, string> Generate(CodeGenerationInfo generationInfo)
        {
            var codes           = new Dictionary <string, string>();
            var codeDomProvider = new CodeDom.NativeCCodeProvider();
            var options         = new CodeGeneratorOptions();

            options.BlankLinesBetweenMembers = generationInfo.BlankLinesBetweenMembers;
            options.BracingStyle             = "C";
            options.ElseOnClosing            = false;
            options.IndentString             = IndentedTextWriter.DefaultTabString;
            options["CustomGeneratorOptionStringExampleID"] = "BuildFlags: /A /B /C /D /E";

            ColumnInfoExtensions.TypeNamespace = generationInfo.Namespace;

            var cremaTypes  = GenerateTypes(codeDomProvider, options, generationInfo);
            var cremaTables = GenerateTables(codeDomProvider, options, generationInfo);

            string cremaTypesHeader, cremaTypesCpp;
            string cremaTablesHeader, cremaTablesCpp;

            SplitCode(cremaTypes, $"{generationInfo.Prefix}types{generationInfo.Postfix}.h", out cremaTypesHeader, out cremaTypesCpp);
            SplitCode(cremaTables, $"{generationInfo.Prefix}tables{generationInfo.Postfix}.h", out cremaTablesHeader, out cremaTablesCpp);

            codes.Add($"{generationInfo.Prefix}types{generationInfo.Postfix}.h", cremaTypesHeader);
            codes.Add($"{generationInfo.Prefix}types{generationInfo.Postfix}.cpp", cremaTypesCpp);
            codes.Add($"{generationInfo.Prefix}tables{generationInfo.Postfix}.h", cremaTablesHeader);
            codes.Add($"{generationInfo.Prefix}tables{generationInfo.Postfix}.cpp", cremaTablesCpp);

            return(codes);
        }
Esempio n. 4
0
        private static CodeTypeDeclaration CreateCore(TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration();

            classType.Name    = tableInfo.GetClassName();
            classType.IsClass = true;
            classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaTable", tableInfo.GetRowCodeType(CodeType.None));
            if (generationInfo.NoComment == false)
            {
                classType.Comments.AddSummary(tableInfo.Comment);
            }

            if (generationInfo.NoChanges == false)
            {
                classType.Comments.Add(CremaSchema.Creator, tableInfo.CreationInfo.ID);
                classType.Comments.Add(CremaSchema.CreatedDateTime, tableInfo.CreationInfo.DateTime);
                classType.Comments.Add(CremaSchema.Modifier, tableInfo.ModificationInfo.ID);
                classType.Comments.Add(CremaSchema.ModifiedDateTime, tableInfo.ModificationInfo.DateTime);
                classType.Comments.Add(CremaSchema.ContentsModifier, tableInfo.ContentsInfo.ID);
                classType.Comments.Add(CremaSchema.ContentsModifiedDateTime, tableInfo.ContentsInfo.DateTime);
            }

            CreateCreateRowInstanceMethod(classType, tableInfo, generationInfo);
            CreateFields(classType, tableInfo, generationInfo);
            CreateConstructor(classType, tableInfo, generationInfo);
            CreateConstructorFromTable(classType, tableInfo, generationInfo);
            CreateConstructorFromRows(classType, tableInfo);
            CreateDestructor(classType, tableInfo, generationInfo);
            CreateFindMethod(classType, tableInfo, generationInfo);

            return(classType);
        }
Esempio n. 5
0
        private static void CreateLoadFromFile(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeMemberMethod();

            cc.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            cc.Name       = "Load";

            var codeTypeRef = new CodeTypeReference(typeof(string));

            codeTypeRef.SetCodeType(CodeType.Reference | CodeType.Const);
            cc.Parameters.Add(codeTypeRef, "filename");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            var paramExp        = new CodeVariableReferenceExpression("filename");
            var readerTypeRef   = new CodeTypeReferenceExpression(string.Join("::", generationInfo.ReaderNamespace, "CremaReader"));
            var readerInvokeExp = new CodeMethodInvokeExpression(readerTypeRef, "ReadFromFile", paramExp);

            var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", readerInvokeExp, new CodeVariableReferenceExpression("verifyRevision"));

            cc.Statements.Add(methodInvokeExp);
            //cc.ChainedConstructorArgs.Add(methodInvokeExp);
            //cc.ChainedConstructorArgs.Add(new CodeVariableReferenceExpression("verifyRevision"));

            classType.Members.Add(cc);
        }
Esempio n. 6
0
        private string GenerateBaseCpp(CodeGenerationInfo generationInfo)
        {
            var assembly     = System.Reflection.Assembly.GetExecutingAssembly();
            var resourceName = string.Join(".", assembly.GetName().Name, "code", "crema_base.cpp");
            var code         = this.GetResourceString(resourceName);

            return(this.ChangeBaseNamespace(code, generationInfo));
        }
Esempio n. 7
0
        private static void CreateTagsField(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmf = new CodeMemberField();

            cmf.Attributes = MemberAttributes.Private;
            cmf.Name       = "_tags";
            cmf.Type       = new CodeTypeReference(typeof(string));

            classType.Members.Add(cmf);
        }
Esempio n. 8
0
 private static void CreateFieldsTable(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetTables(true))
     {
         var cmf = new CodeMemberField();
         cmf.Attributes = MemberAttributes.Public;
         cmf.Name       = item.Name;
         cmf.Type       = item.GetCodeType(CodeType.Pointer | CodeType.Const);
         classType.Members.Add(cmf);
     }
 }
Esempio n. 9
0
        private static void CreateTagsMethod(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            cmm.Name       = "tags";
            cmm.ReturnType = new CodeTypeReference(typeof(string));
            cmm.Statements.AddMethodReturn(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_tags"));

            classType.Members.Add(cmm);
        }
Esempio n. 10
0
        private string ChangeBaseNamespace(string text, CodeGenerationInfo generationInfo)
        {
            var segments       = generationInfo.BaseNamespace.Split(new string[] { "::", }, StringSplitOptions.RemoveEmptyEntries);
            var firstNamespace = string.Join(" { ", segments.Select(item => "namespace " + item));
            var lastNamespace  = string.Join(" ", segments.Select(item => "} /*namespace " + item + "*/"));

            var first = "namespace CremaCode";
            var last  = "} /*namespace CremaCode*/";

            text = text.Replace(last, lastNamespace);
            text = text.Replace(first, firstNamespace);
            return(text);
        }
Esempio n. 11
0
        private static void CreateDestructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeDestructor();

            cc.Attributes = MemberAttributes.Public | MemberAttributes.Override;

            foreach (var item in generationInfo.GetTables())
            {
                var field  = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                var delete = new CodeObjectDeleteExpression(field);

                cc.Statements.Add(delete);
            }

            classType.Members.Add(cc);
        }
Esempio n. 12
0
        public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings)
        {
            var generationInfo = new CodeGenerationInfo(metaData, settings)
            {
                RelativePath = string.Empty,
            };

            if (settings.BasePath != string.Empty)
            {
                var relativePath = UriUtility.MakeRelativeOfDirectory(new DirectoryInfo(outputPath).FullName, DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath));
                generationInfo.RelativePath = relativePath + "/";
            }

            {
                var codes    = this.Generate(generationInfo);
                var dirInfo  = new DirectoryInfo(outputPath);
                var rootPath = generationInfo.Namespace.Replace('.', Path.DirectorySeparatorChar);
                foreach (var item in codes)
                {
                    var ext      = Path.GetExtension(item.Key);
                    var filename = FileUtility.RemoveExtension(item.Key).Replace('.', Path.DirectorySeparatorChar) + ext;
                    filename = Path.Combine(dirInfo.FullName, filename);
                    FileUtility.Prepare(filename);

                    using (StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8))
                    {
                        sw.WriteLine(item.Value);
                        this.PrintResult(filename);
                    }
                }
            }

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false)
            {
                var codes     = this.GenerateBases(generationInfo);
                var codesPath = DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath);
                foreach (var item in codes)
                {
                    var codePath = FileUtility.Prepare(codesPath, item.Key);
                    using (var writer = new StreamWriter(codePath, false, Encoding.UTF8))
                    {
                        writer.WriteLine(item.Value);
                        this.PrintResult(codePath);
                    }
                }
            }
        }
Esempio n. 13
0
        public static void Create(CodeNamespace codeNamespace, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                if (item.TemplatedParent != string.Empty)
                {
                    continue;
                }

                Create(codeNamespace, item, generationInfo);
            }

            CremaRowClassCreator.Create(codeNamespace, tableInfo, generationInfo);
            var classType = CreateCore(tableInfo, generationInfo);

            codeNamespace.Types.Add(classType);
        }
Esempio n. 14
0
        public static void Create(CodeNamespace codeNamespace, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration();

            codeNamespace.Types.Add(classType);

            classType.IsClass = true;
            classType.Name    = tableInfo.GetRowClassName();
            classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaRow");

            CreateColumnFields(classType, tableInfo, generationInfo);
            CreateTableField(classType, tableInfo);
            CreateChildFields(classType, tableInfo, generationInfo);
            CreateStaticChildEmptyFields(classType, tableInfo, generationInfo);
            CreateParentField(classType, tableInfo);
            CreateConstructor(classType, tableInfo, generationInfo);
            CreateSetChildsMethod(classType, tableInfo, generationInfo);
        }
Esempio n. 15
0
        public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
        {
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"dataBase: {generationInfo.DataBaseName}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"revision: {generationInfo.Revision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"requested revision: {generationInfo.RequestedRevision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"devmode: {generationInfo.IsDevmode}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"hash value: {generationInfo.TypesHashValue}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));

            foreach (var item in generationInfo.Types)
            {
                CreateDataType(codeNamespace, item, generationInfo);
            }

            //if (NoCpp == false)
            //    codeNamespace.AddHeaderStatement("void register_enums();");
        }
Esempio n. 16
0
        private static void CreateConstructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor();

            cc.Attributes = MemberAttributes.Public;
            cc.Parameters.Add(generationInfo.ReaderNamespace, "idataset&", "dataSet");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            foreach (var item in generationInfo.GetTables(true))
            {
                var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                cc.Statements.AddAssign(field, new CodePrimitiveExpression(null));
            }

            var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", new CodeVariableReferenceExpression("dataSet"), new CodeVariableReferenceExpression("verifyRevision"));

            cc.Statements.Add(methodInvokeExp);

            classType.Members.Add(cc);
        }
Esempio n. 17
0
        public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
        {
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"dataBase: {generationInfo.DataBaseName}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"revision: {generationInfo.Revision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"requested revision: {generationInfo.RequestedRevision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"devmode: {generationInfo.IsDevmode}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"hash value: {generationInfo.TablesHashValue}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));

            foreach (var item in generationInfo.GetTables())
            {
                CremaTableClassCreator.Create(codeNamespace, item, generationInfo);
            }

            var classType = new CodeTypeDeclaration();

            codeNamespace.Types.Add(classType);
            classType.Name    = generationInfo.ClassName;
            classType.IsClass = true;
            classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaData");

            CreateNameField(classType, generationInfo);
            CreateRevisionField(classType, generationInfo);
            CreateTypesHashValueField(classType, generationInfo);
            CreateTablesHashValueField(classType, generationInfo);
            CreateTagsField(classType, generationInfo);
            CreateNameMethod(classType, generationInfo);
            CreateRevisionMethod(classType, generationInfo);
            CreateTypesHashValueMethod(classType, generationInfo);
            CreateTablesHashValueMethod(classType, generationInfo);
            CreateTagsMethod(classType, generationInfo);
            CreateFieldsTable(classType, generationInfo);
            CreateConstructor(classType, generationInfo);
            CreateConstructorFromFile(classType, generationInfo);
            CreateLoadFromFile(classType, generationInfo);
            CreateLoad(classType, generationInfo);
            CreateDestructor(classType, generationInfo);
        }
Esempio n. 18
0
        private static void CreateColumnProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in tableInfo.Columns)
            {
                var cmp = new CodeMemberProperty();
                cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                cmp.Name       = item.Name;
                cmp.Type       = item.GetPropertyType();

                if (generationInfo.NoComment == false)
                {
                    cmp.Comments.AddSummary(item.Comment);
                }
                if (generationInfo.NoChanges == false)
                {
                    cmp.Comments.Add(CremaSchema.Creator, item.CreationInfo.ID);
                    cmp.Comments.Add(CremaSchema.CreatedDateTime, item.CreationInfo.DateTime);
                    cmp.Comments.Add(CremaSchema.Modifier, item.ModificationInfo.ID);
                    cmp.Comments.Add(CremaSchema.ModifiedDateTime, item.ModificationInfo.DateTime);
                }
                cmp.HasGet = true;
                cmp.HasSet = false;

                // return field;
                {
                    var field = item.GetFieldExpression();
                    cmp.GetStatements.AddMethodReturn(field);
                }

                classType.Members.Add(cmp);
            }
        }
Esempio n. 19
0
        private static void CreateColumnFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in tableInfo.Columns)
            {
                var cmf = new CodeMemberField();
                cmf.Attributes = MemberAttributes.Public;
                cmf.Name       = item.Name;
                cmf.Type       = item.GetCodeType(CodeType.None);

                cmf.InitExpression = item.GetInitExpression();

                if (generationInfo.NoComment == false)
                {
                    cmf.Comments.AddSummary(item.Comment);
                }
                if (generationInfo.NoChanges == false)
                {
                    cmf.Comments.Add(CremaSchema.Creator, item.CreationInfo.ID);
                    cmf.Comments.Add(CremaSchema.CreatedDateTime, item.CreationInfo.DateTime);
                    cmf.Comments.Add(CremaSchema.Modifier, item.ModificationInfo.ID);
                    cmf.Comments.Add(CremaSchema.ModifiedDateTime, item.ModificationInfo.DateTime);
                }
                classType.Members.Add(cmf);
            }
        }
Esempio n. 20
0
        private static CodeStatement CreateCompareTypeStatement(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var table   = new CodeVariableReferenceExpression("table");
            var version = new CodeMethodInvokeExpression(table, "hash_value");

            var state = new CodeConditionStatement();

            state.Condition = new CodeBinaryOperatorExpression(version, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(tableInfo.HashValue));

            var message   = string.Format("{0} 테이블과 데이터의 형식이 맞지 않습니다.", tableInfo.Name);
            var exception = new CodeObjectCreateExpression("std::exception", new CodePrimitiveExpression(message));

            state.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(state);
        }
Esempio n. 21
0
        private static void CreateDataTypeRegisterMethod(CodeNamespace codeNamespace, TypeInfo dataTypeInfo, CodeGenerationInfo generationInfo)
        {
            using (IndentedTextWriter tw = new IndentedTextWriter(new StringWriter()))
            {
                tw.WriteLine("void register_{0}()", dataTypeInfo.Name);
                tw.WriteLine("{");
                tw.Indent++;
                tw.WriteLine("static ntreev::crema::enum_info enumData({0});", dataTypeInfo.IsFlag.ToString().ToLower());
                tw.WriteLine("if(ntreev::crema::enum_util::contains(typeid({0})) == true)", dataTypeInfo.Name);
                tw.Indent++;
                tw.WriteLine("return;");
                tw.Indent--;

                foreach (var item in dataTypeInfo.Members)
                {
                    tw.WriteLine("enumData.add(\"{0}_{1}\", {0}_{1});", dataTypeInfo.Name, item.Name);
                }

                tw.WriteLine("ntreev::crema::enum_util::add(typeid({0}), &enumData);", dataTypeInfo.Name);
                tw.Indent--;
                tw.Write("}");
                tw.Flush();

                codeNamespace.AddCppStatement(tw.InnerWriter.ToString());
            }
        }
Esempio n. 22
0
        private static void CreateCreateRowInstanceMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            cmm.Name       = "CreateRow";
            cmm.ReturnType = new CodeTypeReference(typeof(object));
            cmm.Parameters.Add(generationInfo.ReaderNamespace, "irow&", "row");
            cmm.Parameters.Add(typeof(object), "table");

            // statement
            {
                var row      = new CodeVariableReferenceExpression("row");
                var tablePtr = new CodeVariableReferenceExpression("table");
                var table    = new CodeCastExpression(tableInfo.GetCodeType(CodeType.Pointer), tablePtr);
                var instance = new CodeObjectCreateExpression(tableInfo.GetRowCodeType(CodeType.None), row, table);

                cmm.Statements.AddMethodReturn(instance);
            }

            classType.Members.Add(cmm);
        }
Esempio n. 23
0
        private static void CreateFindMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            cmm.Name       = "Find";
            cmm.ReturnType = tableInfo.GetRowCodeType(CodeType.Pointer | CodeType.Const);
            cmm.Parameters.Add(tableInfo.Columns.Where(item => item.IsKey));
            cmm.IsConst(true);

            // invoke base.FindRow
            {
                var query = from item in tableInfo.Columns
                            where item.IsKey
                            select new CodeVariableReferenceExpression(item.Name);

                var invokeFindRow = new CodeMethodInvokeExpression(thisRef, "FindRow", query.ToArray());

                cmm.Statements.AddMethodReturn(invokeFindRow);
            }

            classType.Members.Add(cmm);
        }
Esempio n. 24
0
        private static void CreateConstructorFromTable(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor();

            cc.Attributes = MemberAttributes.Public;
            cc.Name       = tableInfo.TableName;
            cc.Parameters.Add(generationInfo.ReaderNamespace, "itable&", "table");
            //cc.BaseConstructorArgs.Add("table");

            //cc.AddConstructorStatement(string.Format("{0}(table)", CodeGenerationInfo.CremaTableName));

            // verify hashValue
            {
                var css = CreateCompareTypeStatement(classType, tableInfo, generationInfo);
                var tst = CremaDataClassCreator.CreateTryCatchStatement(classType, css, generationInfo);
                cc.Statements.Add(css);
            }

            {
                var table   = new CodeVariableReferenceExpression("table");
                var dataSet = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(table, "dataset"));
                var tables  = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tables"));

                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var tableName  = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(table, "name"));
                    var childName  = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));
                    var childTable = new CodeIndexerExpression(tables, childName);
                    var childField = new CodeFieldReferenceExpression(thisRef, item.TableName);
                    var instance   = new CodeObjectCreateExpression(item.GetCodeType(CodeType.None), childTable);

                    cc.Statements.AddAssign(childField, instance);
                    //cc.AddConstructorStatement(string.Format("{0}(table.dataset().tables()[\"{1}\"])", item.GetFieldName(), item.GetUniqueName()));
                }
            }


            {
                var table        = new CodeVariableReferenceExpression("table");
                var readFromFile = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "ReadFromTable");
                var methodInvoke = new CodeMethodInvokeExpression(readFromFile, table);

                cc.Statements.Add(methodInvoke);
            }

            // SetRelations
            {
                var table = new CodeVariableReferenceExpression("table");
                foreach (var item in generationInfo.GetChilds(tableInfo))
                {
                    var setRelations   = new CodeMethodReferenceExpression(thisRef, "SetRelations");
                    var field          = new CodeFieldPointerExpression(thisRef, item.TableName);
                    var rows           = new CodePropertyReferenceExpression(field, "Rows");
                    var codeTypeRef    = new CodeTypeReferenceExpression(tableInfo.GetRowCodeType(CodeType.None));
                    var setChildAction = new CodePropertyReferenceExpression(null, tableInfo.TableName + "Set" + item.TableName);
                    var tableName      = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(table, "name"));
                    var childName      = new CodeBinaryOperatorExpression(tableName, CodeBinaryOperatorType.Add, new CodePrimitiveExpression("." + item.TableName));

                    var setRelationsInvoke = new CodeMethodInvokeExpression(setRelations, childName, rows, setChildAction);
                    cc.Statements.Add(setRelationsInvoke);
                }
            }


            classType.Members.Add(cc);
        }
Esempio n. 25
0
        private static void CreateConstructor(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor();

            cc.Attributes = MemberAttributes.Public;
            classType.Members.Add(cc);
        }
Esempio n. 26
0
        private static void CreateSetChildsMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmm = new CodeMemberMethod();
                cmm.Attributes = MemberAttributes.FamilyAndAssembly | MemberAttributes.Static;
                cmm.Name       = tableInfo.TableName + "Set" + item.TableName;
                cmm.Parameters.Add(tableInfo.GetRowCodeType(CodeType.Pointer), "target");
                var arrayType = new CodeTypeReference(item.GetRowCodeType(CodeType.Pointer), 1);
                arrayType.SetCodeType(CodeType.Const | CodeType.Reference);
                var childNameType = new CodeTypeReference(typeof(string));
                childNameType.SetCodeType(CodeType.Const | CodeType.Reference);
                cmm.Parameters.Add(childNameType, "childName");
                cmm.Parameters.Add(arrayType, "childs");

                {
                    var methodRefExp = new CodeMethodReferenceExpression(null, "SetParent");
                    //methodRefExp.TypeArguments.Add(tableInfo.GetRowCodeType());
                    //methodRefExp.TypeArguments.Add(item.GetRowCodeType());

                    var methodInvokeExp = new CodeMethodInvokeExpression(methodRefExp, new CodeVariableReferenceExpression("target"), new CodeVariableReferenceExpression("childs"));

                    cmm.Statements.AddExpression(methodInvokeExp);
                }

                {
                    var target         = new CodeVariablePointerExpression("target");
                    var childName      = new CodeVariablePointerExpression("childName");
                    var childs         = new CodeVariableReferenceExpression("childs");
                    var targetField    = item.GetFieldExpression(target);
                    var targetInstance = new CodeObjectCreateExpression(item.GetCodeType(CodeType.None), childName, childs);
                    cmm.Statements.AddAssign(targetField, targetInstance);
                }

                classType.Members.Add(cmm);
            }
        }
Esempio n. 27
0
        private static void CreateStaticChildEmptyFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmf = new CodeMemberField();
                cmf.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                cmf.Name       = item.GetFieldName() + "Empty";
                cmf.Type       = item.GetCodeType(CodeType.None);
                //cmf.InitExpression = new CodeObjectCreateExpression(item.GetCodeType(CodeType.None));

                classType.Members.Add(cmf);
            }
        }
Esempio n. 28
0
        private static void CreateDataTypeRegisterMethods(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.Types)
            {
                CreateDataTypeRegisterMethod(codeNamespace, item, generationInfo);
            }

            using (var tw = new IndentedTextWriter(new StringWriter()))
            {
                tw.WriteLine("void register_enums()");
                tw.WriteLine("{");

                tw.Indent++;
                foreach (var item in generationInfo.Types)
                {
                    tw.WriteLine("register_{0}();", item.Name);
                }
                tw.Indent--;

                tw.Write("}");
                tw.Flush();
                codeNamespace.AddCppStatement(tw.InnerWriter.ToString());
            }
        }
Esempio n. 29
0
        private static void CreateConstructor(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor();

            cc.Attributes = MemberAttributes.Public;
            cc.Parameters.Add(generationInfo.ReaderNamespace, "irow&", "row");
            cc.Parameters.Add(tableInfo.GetCodeType(CodeType.Pointer), "table");

            cc.AddConstructorStatement(string.Format("{0}(row)", CodeGenerationInfo.CremaRowName));
            //cc.AddConstructorStatement("Table(*table)");

            //foreach (var item in tableInfo.Columns)
            //{
            //    CodeBinaryOperatorExpression cbor = new CodeBinaryOperatorExpression();
            //    cbor.Left = new CodeVariableReferenceExpression("propertyName");
            //    cbor.Operator = CodeBinaryOperatorType.ValueEquality;
            //    cbor.Right = new CodePrimitiveExpression(item.Name);

            //    CodeConditionStatement ccs = new CodeConditionStatement(item.GetHasValueMethodExpression());

            //    CodeAssignStatement cas = new CodeAssignStatement();
            //    cas.Left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
            //    cas.Right = item.GetGetValueMethodExpression();

            //    ccs.TrueStatements.Add(cas);

            //    cc.Statements.Add(ccs);
            //}

            //var query = from item in tableInfo.Columns
            //            where item.IsKey
            //            select item;

            ////method.AddStatement(string.Format("cremarow::initialize(row, iniutil::generate_hash({0}, {1}));", query.Count(), string.Join(", ", query)));

            //CodeMethodInvokeExpression generate_hashExp = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("iniutil"), "generate_hash");
            //foreach (var item in query)
            //{
            //    CodeFieldReferenceExpression fieldExp = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
            //    if (item.IsCustomType() == false)
            //        generate_hashExp.Parameters.Add(fieldExp);
            //    else
            //        generate_hashExp.Parameters.Add(new CodeCastExpression(new CodeTypeReference(typeof(int)), fieldExp));
            //}

            // assign table
            {
                var tableField = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "Table");
                var tableVar   = new CodeVariableReferenceExpression("table");
                cc.Statements.AddAssign(tableField, tableVar);
            }

            // assign fields
            {
                int index = 0;
                foreach (var item in tableInfo.Columns)
                {
                    var cas = new CodeAssignStatement();
                    cas.Left  = item.GetFieldExpression();
                    cas.Right = item.GetGetValueMethodExpression(index, false);

                    if (item.IsKey == false)
                    {
                        var ccs = new CodeConditionStatement(item.GetHasValueMethodExpression(index, false));
                        ccs.TrueStatements.Add(cas);
                        cc.Statements.Add(ccs);
                    }
                    else
                    {
                        cc.Statements.Add(cas);
                    }
                    index++;
                }
            }

            //CodeMethodInvokeExpression methodExp = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("cremarow"), "initialize");

            //methodExp.Parameters.Add(new CodeVariableReferenceExpression("row"));
            //methodExp.Parameters.Add(generate_hashExp);

            //cc.Statements.Add(new CodeExpressionStatement(methodExp));

            //var query = from item in columns
            //            where item.IsKey
            //            select item.Name;

            //method.AddStatement(string.Format("cremarow::initialize(row, iniutil::generate_hash({0}, {1}));", query.Count(), string.Join(", ", query)));

            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                // check null and return defaultField
                {
                    var state     = new CodeConditionStatement();
                    var condition = new CodeBinaryOperatorExpression(item.GetFieldExpression(), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));
                    state.Condition = condition;

                    var codeTypeRef = new CodeTypeReferenceExpression(tableInfo.GetRowCodeType(CodeType.None));
                    var staticField = new CodeFieldReferenceExpression(codeTypeRef, item.GetFieldName() + "Empty");
                    state.TrueStatements.AddAssignReference(item.GetFieldExpression(), staticField);

                    cc.Statements.Add(state);
                }

                // return field;
                //{
                //    var fieldExp = item.GetFieldExpression();
                //    cmp.GetStatements.AddMethodReturn(fieldExp, CodeType.None);
                //}

                //classType.Members.Add(cmp);
            }

            // invoke SetKey method
            {
                var methodRefExp    = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "SetKey");
                var methodInvokeExp = new CodeMethodInvokeExpression(methodRefExp);

                foreach (var item in tableInfo.Columns)
                {
                    if (item.IsKey == true)
                    {
                        methodInvokeExp.Parameters.Add(item.GetFieldExpression());
                    }
                }
                cc.Statements.Add(methodInvokeExp);
            }

            classType.Members.Add(cc);
        }
Esempio n. 30
0
        private static void CreateDataType(CodeNamespace codeNamespace, TypeInfo dataTypeInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration(dataTypeInfo.Name);

            classType.Attributes = MemberAttributes.Public;
            classType.IsEnum     = true;

            if (dataTypeInfo.IsFlag == true)
            {
                CodeAttributeDeclaration cad = new CodeAttributeDeclaration(new CodeTypeReference(typeof(FlagsAttribute)));

                classType.CustomAttributes.Add(cad);
            }

            if (generationInfo.NoComment == false)
            {
                classType.Comments.AddSummary(dataTypeInfo.Comment);
            }

            if (generationInfo.NoChanges == false)
            {
                classType.Comments.Add(CremaSchema.Creator, dataTypeInfo.CreationInfo.ID);
                classType.Comments.Add(CremaSchema.CreatedDateTime, dataTypeInfo.CreationInfo.DateTime);
                classType.Comments.Add(CremaSchema.Modifier, dataTypeInfo.ModificationInfo.ID);
                classType.Comments.Add(CremaSchema.ModifiedDateTime, dataTypeInfo.ModificationInfo.DateTime);
            }

            foreach (var item in dataTypeInfo.Members)
            {
                CreateDataMember(classType, item, generationInfo);
            }
            //CreateEnumRegisterMethod(enum1, isFlag);
            codeNamespace.Types.Add(classType);
        }