/// <summary> /// 生成所有屏幕名称数据 /// </summary> /// <param name="compile">编译对象</param> /// <param name="jsonWriter">JsonWriter</param> private void BuildAllScreens(CompileBase compile, JsonWriter jsonWriter) { string retrunValue = string.Empty; DojoCompile dojoCompile = (DojoCompile)compile; Dictionary <int, int> screenPermissionData = dojoCompile.ScreenPermissionData; var screenItems = dojoCompile.ProjectItems.Where(a => a.Value.DocumentType == GlobalIds.DocumentType.Screen).ToList(); foreach (var item in screenItems) { var doc = item.Value as ProjectDocument; if (doc != null) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Id"); jsonWriter.WriteValue(doc.Id); jsonWriter.WritePropertyName("Name"); jsonWriter.WriteValue(doc.Name); jsonWriter.WritePropertyName("Title"); jsonWriter.WriteValue(doc.Title); if (screenPermissionData.ContainsKey(doc.Id)) { var permissionId = (from t in screenPermissionData where t.Key == doc.Id select t.Value).FirstOrDefault(); jsonWriter.WritePropertyName("PermissionId"); jsonWriter.WriteValue(permissionId); } jsonWriter.WriteEndObject(); } } }
/// <summary> /// 获取导航属性所属的主键 /// </summary> /// <param name="def"></param> /// <param name="dojoCompile"></param> /// <param name="toEntity"></param> /// <returns></returns> public static string GetNavPrimaryContent(EntityDefinition def, CompileBase compile, string toEntity) { string navPrimaryKey = string.Empty; var navEntityItems = compile.ProjectItems.Where(a => a.Value.DocumentType == GlobalIds.DocumentType.Entity && a.Value.Name == toEntity).FirstOrDefault(); if (navEntityItems.Value != null) { //继承实体 var inheritEntityId = (from t in navEntityItems.Value.Propertys where t.Key == "InheritEntityId" select t.Value).FirstOrDefault(); if (inheritEntityId != null) { StringBuilder sbPrimary = new StringBuilder(); GetNavPrimaryString(def, compile, navEntityItems.Value.Propertys, sbPrimary); navPrimaryKey = sbPrimary.ToString(); } else { //非继承实体 var nvaDef = compile.GetDocumentBody(navEntityItems.Value) as EntityDefinition; foreach (var navPrimary in nvaDef.Members.OfType <PrimaryMember>()) { navPrimaryKey = navPrimary.Name; } } } return(navPrimaryKey); }
public override void Build(CompileBase compile, ProjectDocument doc) { IonicCompile ionicCompile = compile as IonicCompile; BuildProjectConfig(ionicCompile); BuildPlatformConfig(ionicCompile); BuildEntityDefinition(ionicCompile); }
/// <summary> /// 生成逻辑 /// </summary> /// <param name="compile">DOJO编译器</param> /// <param name="doc">文档对象模型</param> public override void Build(CompileBase compile, ProjectDocument doc) { var docBody = compile.GetDocumentBody(doc); var screenDefinition = docBody as ScreenDefinition; if (screenDefinition != null) { ControlHost controlHost = screenDefinition.Root; BuildHtml(doc.Name, controlHost, compile, screenDefinition, doc); } }
public ProjectServiceTemplate(CompileBase compile, ServiceMetadata data) { this.Data = data; this.Compiler = compile as ServiceCompile; this.Entitys = new Dictionary <ProjectDocument, ControllerConfigure>(); foreach (var entity in Compiler.ProjectItems.Values.Where(a => a.DocumentType == GlobalIds.DocumentType.Entity)) { var def = Compiler.GetDocumentBody(entity) as EntityDefinition; if (def.Controller != null) { Entitys.Add(entity, def.Controller); } } }
/// <summary> /// 生成 /// </summary> /// <param name="compile">DOJO编译器</param> /// <param name="doc">文档对象模型</param> public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { var indexPath = Path.Combine(((DojoCompile)compile).OutputPath, "Index.html"); File.WriteAllText(indexPath, new IndexTemplate().TransformText(), System.Text.UTF8Encoding.UTF8); //Error var errorPath = Path.Combine(((DojoCompile)compile).OutputPath, "Error.html"); File.WriteAllText(errorPath, new ErrorTemplate(compile).TransformText(), System.Text.UTF8Encoding.UTF8); //NoAuthorized var noAuthorizedPath = Path.Combine(((DojoCompile)compile).OutputPath, "NoAuthorized.html"); File.WriteAllText(noAuthorizedPath, new NoAuthorizedTemplate(compile).TransformText(), System.Text.UTF8Encoding.UTF8); }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { try { var serviceCompile = compile as ServiceCompile; foreach (var item in serviceCompile.Data.DataContexts.Values) { string result = new DataContextTemplate(item).TransformText(); serviceCompile.GenerateCode("", item.ClassName, result); } } catch (Exception ex) { throw new Exception("DataContextBuild:" + ex.ToString()); } }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { try { var serviceCompile = compile as ServiceCompile; if (serviceCompile != null) { string strResult = new ProjectServiceTemplate(compile, serviceCompile.Data.Service).TransformText(); serviceCompile.GenerateCode("", serviceCompile.Data.Service.Identity + "ProjectService", strResult); } } catch (Exception ex) { throw new Exception("ProjectServiceBuild:" + ex.ToString()); } }
/// <summary> /// 获取所有自定义外键 /// </summary> /// <param name="def"></param> /// <param name="compile"></param> /// <param name="sb"></param> private static void GetAllRelationForeignString(EntityDefinition def, CompileBase compile, StringBuilder sb) { foreach (var member in def.Members) { if (member.MemberType == EMemberType.Navigation) { var navigationMember = member as NavigationMember; string toEntity = (from t in compile.ProjectItems where t.Key == navigationMember.ToEntityId select t.Value).FirstOrDefault().Name; if (navigationMember.ToCardinality != EMappingCardinality.Many) { string navPrimaryKey = GetNavPrimaryContent(def, compile, toEntity); string relationForeignKey = GetRealForeignKey(navigationMember, toEntity, navPrimaryKey); sb.Append(relationForeignKey + ","); } } } }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { try { var serviceCompile = compile as ServiceCompile; if (serviceCompile != null) { var entity = serviceCompile.Data.Entitys[doc.Id]; string result = new EntityTemplate(entity).TransformText(); serviceCompile.GenerateCode("Models", entity.ProjectItem.Name, result); } } catch (Exception ex) { throw new Exception("EntityBuild:" + ex.ToString()); } }
/// <summary> /// 生成模型数据定义 /// </summary> /// <param name="compile">编译对象</param> /// <param name="jsonWriter">JsonWriter</param> private void BuildAllDefinition(CompileBase compile, JsonWriter jsonWriter) { DojoCompile dojoCompile = compile as DojoCompile; var entityItem = dojoCompile.ProjectItems.Where(a => a.Value.DocumentType == GlobalIds.DocumentType.Entity).ToList(); foreach (var item in entityItem) { //jsonWriter.WriteStartObject(); //1 jsonWriter.WritePropertyName(item.Value.Name); jsonWriter.WriteStartObject(); var def = dojoCompile.GetDocumentBody(item.Value) as EntityDefinition; #region 获取所有自定义外键 StringBuilder sbAllForeigns = new StringBuilder(); StringBuilder sbForeignKey = new StringBuilder(); BuildCommonMethod.GetAllRelationForeignContent(item.Value.Propertys, def, dojoCompile, sbForeignKey); if (sbForeignKey.ToString().Length > 0) { sbAllForeigns.Append(sbForeignKey.ToString()); } #endregion #region EntityID jsonWriter.WritePropertyName("entityId"); jsonWriter.WriteValue(item.Key); #endregion #region Primary jsonWriter.WritePropertyName("primaryKey"); jsonWriter.WriteStartObject(); BuildPrimaryContent(item.Value.Propertys, def, dojoCompile, jsonWriter); jsonWriter.WriteEndObject(); #endregion #region Fields jsonWriter.WritePropertyName("fields"); jsonWriter.WriteStartObject(); BuildItemsContent(item.Value.Propertys, def, dojoCompile, jsonWriter, sbAllForeigns.ToString()); jsonWriter.WriteEndObject(); #endregion jsonWriter.WriteEndObject(); //jsonWriter.WriteEndObject(); //1 } }
/// <summary> /// 生成CSS /// </summary> /// <param name="compile"></param> /// <param name="screenDef"></param> /// <param name="doc"></param> private void BuildCss(CompileBase compile, ScreenDefinition screenDef, ProjectDocument doc) { var ionicCompile = compile as IonicCompile; string fileName = doc.Name; string outputPath = ionicCompile.OutputPath + "\\" + fileName; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var file = Path.Combine(outputPath, fileName + ".scss"); if (File.Exists(file)) { File.Delete(file); } string content = string.Empty; //创建HTML文件 File.WriteAllText(file, content, System.Text.UTF8Encoding.UTF8); }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { try { var serviceCompile = compile as ServiceCompile; if (serviceCompile != null) { var entity = serviceCompile.GetDocumentBody(doc) as EntityDefinition; if (entity != null && entity.Controller != null && entity.Members.Count > 0) { var data = serviceCompile.Data.Controllers[doc.Id]; string result = new ControllerTemplate(data).TransformText(); serviceCompile.GenerateCode("Controllers", data.ClassName, result); } } } catch (Exception ex) { throw new Exception("DataControllterBuild:" + ex.ToString()); } }
/// <summary> /// 生成Module页面HTML /// </summary> /// <param name="compile"></param> /// <param name="doc"></param> private void BuildModuleHtml(CompileBase compile, ScreenDefinition screenDef, ProjectDocument doc) { if (doc.Name.ToLower() == "startuppage") { var ionicCompile = compile as IonicCompile; var targetDirectory = new System.IO.FileInfo(new Uri(this.GetType().Assembly.CodeBase).AbsolutePath).Directory.FullName; string outputPath = Path.Combine(targetDirectory.Replace("\\Wilmar.Service\\bin\\Extension", ""), @"Wilmar.Mobile\src\projects", ionicCompile.Project.Identity); outputPath = HttpUtility.UrlDecode(outputPath); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //Module页面 var fileModulePage = Path.Combine(outputPath, ionicCompile.Project.Identity + ".module.ts"); if (File.Exists(fileModulePage)) { File.Delete(fileModulePage); } var contentModulePage = new ModuleTemplate(ionicCompile, doc).TransformText(); File.WriteAllText(fileModulePage, contentModulePage, System.Text.UTF8Encoding.UTF8); //生成Mian页面TS var fileMainPage = Path.Combine(outputPath, ionicCompile.Project.Identity + ".ts"); if (File.Exists(fileMainPage)) { File.Delete(fileMainPage); } var contentMainPage = new PageMainTemplate(ionicCompile, screenDef, doc).TransformText(); File.WriteAllText(fileMainPage, contentMainPage, System.Text.UTF8Encoding.UTF8); //生成Mian页面CSS var fileMainCss = Path.Combine(outputPath, ionicCompile.Project.Identity + ".scss"); if (File.Exists(fileMainCss)) { File.Delete(fileMainCss); } string contentMainCss = string.Empty; File.WriteAllText(fileMainCss, contentMainCss, System.Text.UTF8Encoding.UTF8); } }
/// <summary> /// 获取导航属性所属的主键 /// </summary> /// <param name="def"></param> /// <param name="dojoCompile"></param> /// <param name="itemPropertys"></param> /// <param name="sb"></param> private static void GetNavPrimaryString(EntityDefinition def, CompileBase compile, Dictionary <string, object> itemPropertys, StringBuilder sb) { var inheritEntityId = (from t in itemPropertys where t.Key == "InheritEntityId" select t.Value).FirstOrDefault(); if (inheritEntityId != null) { var entityItems = compile.ProjectItems.Where(a => a.Value.DocumentType == GlobalIds.DocumentType.Entity && a.Key == int.Parse(inheritEntityId.ToString())).FirstOrDefault(); if (entityItems.Value != null) { var defItem = compile.GetDocumentBody(entityItems.Value) as EntityDefinition; if (defItem.Members.OfType <PrimaryMember>().Count() > 0) { foreach (var primary in defItem.Members.OfType <PrimaryMember>()) { sb.AppendFormat("{0}", primary.Name); } } //递归处理 GetNavPrimaryString(def, compile, entityItems.Value.Propertys, sb); } } }
/// <summary> /// 生成HTML /// </summary> /// <param name="name">屏幕名称</param> /// <param name="controlHost">控件基类</param> /// <param name="compile">编译基类</param> /// <param name="screenDef">屏幕定义</param> /// <param name="doc">项目文档</param> private void BuildHtml(ControlHost controlHost, CompileBase compile, ScreenDefinition screenDef, ProjectDocument doc) { using (var writer = new StringWriter()) { var ionicCompile = compile as IonicCompile; Dictionary <int, Tuple <int, string> > itemPermissionData = new Dictionary <int, Tuple <int, string> >(); var xmlWriter = new HtmlTextWriter(writer); var builder = controlHost.GetBuilder(false, screenDef, compile, doc, itemPermissionData, xmlWriter); builder.Build(); //生成文件全路径 string fileName = doc.Name; string outputPath = ionicCompile.OutputPath + "\\" + fileName; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var file = Path.Combine(outputPath, fileName + ".html"); if (File.Exists(file)) { File.Delete(file); } //创建HTML文件 File.WriteAllText(file, writer.ToString(), System.Text.UTF8Encoding.UTF8); //启动屏幕名字暂时固定 //projets/pages中启动屏幕不生成TS文件,TS文件在外部生成 if (fileName.ToLower() != "startuppage") { //生成JS this.BuildJs(compile, screenDef, doc); //生成CSS this.BuildCss(compile, screenDef, doc); } } }
public virtual void WriteLemmas(TextWriter writer, CompileBase context, List<string> visibleModules, Attributes attrs, bool loopLemmasOnly = false) { }
/// <summary> /// 生成 /// </summary> /// <param name="compile">DOJO编译器</param> /// <param name="doc">文档对象模型</param> public override void Build(CompileBase compile, ProjectDocument doc) { DojoCompile dojoCompile = (DojoCompile)compile; StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { JsonWriter jsonWriter = new JsonTextWriter(sw); jsonWriter.Formatting = Formatting.Indented; var frontConfig = dojoCompile.Project.Configures.OfType <FrontEndConfigure>().FirstOrDefault(); //创建配置对象 #region jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("ProjectId"); jsonWriter.WriteValue(compile.ProjectId); jsonWriter.WritePropertyName("Name"); jsonWriter.WriteValue(compile.Project.Identity); jsonWriter.WritePropertyName("Title"); jsonWriter.WriteValue(compile.Project.Root.Title); jsonWriter.WritePropertyName("Desc"); jsonWriter.WriteValue(compile.Project.Description); jsonWriter.WritePropertyName("Version"); jsonWriter.WriteValue("1.0.0"); jsonWriter.WritePropertyName("ServiceBaseUrl"); jsonWriter.WriteValue(frontConfig.ServerUrl); jsonWriter.WritePropertyName("AuthServiceBaseUrl"); jsonWriter.WriteValue(frontConfig.ServerUrl); jsonWriter.WritePropertyName("DefaultPage"); jsonWriter.WriteValue(frontConfig.StartupScreen == null ? "MainScreen" : frontConfig.StartupScreen); jsonWriter.WritePropertyName("LoginPage"); jsonWriter.WriteValue("Login"); jsonWriter.WritePropertyName("DefaultThemes"); jsonWriter.WriteValue(""); #endregion #region 生成报表配置节 var reportConfig = dojoCompile.Project.Configures.OfType <ReportServerConfigure>().FirstOrDefault(); if (reportConfig != null) { jsonWriter.WritePropertyName("ReportBaseUrl"); jsonWriter.WriteValue(reportConfig.Reports); jsonWriter.WritePropertyName("ReportServerBaseUrl"); jsonWriter.WriteValue(reportConfig.ReportServer); } #endregion #region 生成所有屏幕数据 jsonWriter.WritePropertyName("Screens"); jsonWriter.WriteStartArray(); this.BuildAllScreens(compile, jsonWriter); jsonWriter.WriteEndArray(); #endregion #region 生成模型数据定义 jsonWriter.WritePropertyName("Definition"); //jsonWriter.WriteStartArray(); //1 jsonWriter.WriteStartObject(); this.BuildAllDefinition(compile, jsonWriter); jsonWriter.WriteEndObject(); //jsonWriter.WriteEndArray(); //1 #endregion jsonWriter.WriteEndObject(); //获取JSON串 string output = sw.ToString(); jsonWriter.Close(); sw.Close(); //创建配置文件 var file = Path.Combine(((DojoCompile)compile).OutputPath, "Config.json"); if (File.Exists(file)) { File.Delete(file); } File.WriteAllText(file, output, System.Text.UTF8Encoding.UTF8); //全局生成 var cFile = Path.Combine(((DojoCompile)compile).OutputPath, "Common.js"); if (File.Exists(cFile)) { File.Delete(cFile); } string content = "define(function(){return {}});"; File.WriteAllText(cFile, content, System.Text.UTF8Encoding.UTF8); } }
public ErrorTemplate(CompileBase compile) { this.Compile = compile; }
/// <summary> /// 构造函数 /// </summary> /// <param name="isPreview">是否预览</param> /// <param name="controlHost">控件</param> /// <param name="compile">编译器对象</param> /// <param name="htmlWriter">htmlWriter</param> public ControlBuildBase(bool isPreview, ControlHost controlHost, ScreenDefinition screenDef, CompileBase compile, ProjectDocument doc, Dictionary <int, Tuple <int, string> > permissionData, HtmlTextWriter htmlWriter) { this.IsPreview = isPreview; this.ControlHost = controlHost; this.ScreenDefinition = screenDef; this.Compile = compile; this.ProjectDocument = doc; this.PermissionData = permissionData; this.HtmlWriter = htmlWriter; }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { var previewPath = Path.Combine(((DojoCompile)compile).OutputPath, "Preview.html"); File.WriteAllText(previewPath, new PreviewIndexTemplate().TransformText(), System.Text.UTF8Encoding.UTF8); }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { }
public virtual void WriteLemmas(TextWriter writer, CompileBase context, List <string> visibleModules, Attributes attrs, bool loopLemmasOnly = false) { }
/// <summary> /// 获取生成器 /// </summary> /// <param name="control">控件对象</param> /// <returns>返回控件对应的生成器</returns> public static ControlBuildBase GetBuilder(this ControlHost controlHost, bool isPreview, ScreenDefinition screenDef, CompileBase compile, ProjectDocument doc, Dictionary <int, Tuple <int, string> > permissionData, HtmlTextWriter htmlWriter) { //图表控件名字为空自动生成一个默认名字 var controlName = controlHost.Content.GetType().Name; if (controlName == "ChartPane" || controlName == "DropDownButton") { if (string.IsNullOrEmpty(controlHost.Name)) { controlHost.Name = controlName + ctlNumber++; } } if (!isPreview && doc != null && !string.IsNullOrEmpty(controlHost.Name)) { controlHost.Name = doc.Name + "_" + controlHost.Name; } if (controlHost.Content != null) { var assembly = Assembly.GetAssembly(typeof(ControlExtend)); string typeName = string.Format("Wilmar.Build.Core.Dojo.Default.Builders.{0}Build", controlHost.Content.GetType().Name); if (assembly.GetType(typeName) == null) { throw new Exception(string.Format("类型【{0}】没对应的生成器。", typeName)); } ControlBuildBase builder = Activator.CreateInstance(assembly.GetType(typeName), isPreview, controlHost, screenDef, compile, doc, permissionData, htmlWriter) as ControlBuildBase; return(builder); } else { return(null); } }
public override void Build(CompileBase compile, Foundation.Projects.ProjectDocument doc) { throw new NotImplementedException(); }
/// <summary> /// 生成HTML /// </summary> /// <param name="name">屏幕名称</param> /// <param name="controlHost">控件基类</param> /// <param name="compile">编译基类</param> /// <param name="screenDef">屏幕定义</param> /// <param name="doc">项目文档</param> private void BuildHtml(string name, ControlHost controlHost, CompileBase compile, ScreenDefinition screenDef, ProjectDocument doc) { using (var writer = new StringWriter()) { var dojoCompile = compile as DojoCompile; #region 写入权限操作 //序号,权限ID,权限作用 Dictionary <int, Tuple <int, string> > itemPermissionData = new Dictionary <int, Tuple <int, string> >(); var permissionConfigure = screenDef.PermissionConfigure; if (permissionConfigure != null && permissionConfigure.EnableAuth) { int permissionItemId = 1; string identity = dojoCompile.Project.Identity; var permissionItems = screenDef.PermissionConfigure.PermissionItems; foreach (var item in permissionItems) { short purpose = DojoCompile.PermissionScreen; switch (item.Purpose) { case EPermissionPurpose.Operate: purpose = DojoCompile.PermissionOperate; break; case EPermissionPurpose.Visible: purpose = DojoCompile.PermissionVisible; break; case EPermissionPurpose.Custom: purpose = DojoCompile.PermissionCustom; break; } permissionItemId = int.Parse(item.Id); string title = item.Title; string desc = doc.Title + " " + item.Description; int permissionId = dojoCompile.Permission.Write(doc.Id, purpose, item.Id, title, desc); itemPermissionData.Add(permissionItemId, new Tuple <int, string>(permissionId, item.Purpose.ToString().ToLower())); } } #endregion //根据屏幕生成HTML var xmlWriter = new HtmlTextWriter(writer); xmlWriter.AddAttribute("dojoType", "dojox/mvc/Group"); xmlWriter.AddAttribute("style", "width:100%;height:100%;position:relative;"); xmlWriter.AddAttribute("class", "groupDiv"); xmlWriter.RenderBeginTag("div"); var builder = controlHost.GetBuilder(false, screenDef, compile, doc, itemPermissionData, xmlWriter); builder.Build(); xmlWriter.RenderEndTag(); //生成屏幕JS BuildScreenJs.BuildJs(controlHost, compile, screenDef, xmlWriter, doc); //生成文件全路径 var file = Path.Combine(((DojoCompile)compile).OutputPath, name + ".html"); if (File.Exists(file)) { File.Delete(file); } //创建HTML文件 File.WriteAllText(file, writer.ToString(), System.Text.UTF8Encoding.UTF8); ControlExtend.ctlNumber = 1; } }
/// <summary> /// 执行生成 /// </summary> /// <param name="compile">编译器></param> /// <param name="doc">指定的文档对象,如果是全局生成器则为空</param> public virtual void Build(CompileBase compile, ProjectDocument doc) { }
public override void WriteLemmas(TextWriter writer, CompileBase context, List<string> visibleModules, Attributes attrs, bool loopLemmasOnly = false) { if (minVerify) { return; } if (!Attributes.Contains(attrs, "dafnycc_no_lemmas")) { foreach (var x in lemmas.Where(x => visibleModules.Contains(x.module))) { if (x.type != null && context.visibleElementType != null && x.type.ToString() != context.visibleElementType.ToString()) { continue; } if (loopLemmasOnly && !x.loopLemma) { continue; } string line = x.stmt; if (line.Contains("Seq__Append__TakeDrop")) { bool isRestricted = line.Contains("Seq__Append__TakeDrop__Restricted"); bool isConservative = Attributes.Contains(attrs, "dafnycc_conservative_seq_triggers"); if (isConservative != isRestricted) { continue; } } writer.WriteLine(" " + line); } } }
public NoAuthorizedTemplate(CompileBase compile) { this.Compile = compile; }
/// <summary> /// 获取所有自定义外键 /// </summary> /// <param name="itemPropertys"></param> /// <param name="def"></param> /// <param name="compile"></param> /// <param name="sb"></param> public static void GetAllRelationForeignContent(Dictionary <string, object> itemPropertys, EntityDefinition def, CompileBase compile, StringBuilder sb) { var inheritEntityId = (from t in itemPropertys where t.Key == "InheritEntityId" select t.Value).FirstOrDefault(); if (inheritEntityId != null) { var entityItems = compile.ProjectItems.Where(a => a.Value.DocumentType == GlobalIds.DocumentType.Entity && a.Key == int.Parse(inheritEntityId.ToString())).FirstOrDefault(); if (entityItems.Value != null) { var defItem = compile.GetDocumentBody(entityItems.Value) as EntityDefinition; GetAllRelationForeignString(defItem, compile, sb); //递归处理 GetAllRelationForeignContent(entityItems.Value.Propertys, def, compile, sb); } } else { GetAllRelationForeignString(def, compile, sb); } }
public TooltipDialogBuild(bool isPreview, ControlHost controlHost, ScreenDefinition screenDef, CompileBase compile, ProjectDocument doc, Dictionary <int, Tuple <int, string> > permissionData, HtmlTextWriter htmlWriter) : base(isPreview, controlHost, screenDef, compile, doc, permissionData, htmlWriter) { }
public List <RtlStmt> Alloc() { assigned = new List <List <string> >(new List <string> [stmts.Count]); Func <int, string> slotMem = offset => "stk.map[r.regs[ESP] + " + offset + "]"; Func <RtlExp, string> spillLoc = e => "EvalPtr(r, " + e.AsOperand() + ")"; Func <RtlExp, string> spillMem = e => "stk.map[" + spillLoc(e) + "]"; Stack <int> workList = new Stack <int>(); List <RtlStmt> newStmts = new List <RtlStmt>(); Action <string, string> move = (string dest, string src) => { if (dest != src) { newStmts.Add(new RtlInst("instr_Mov", new RtlVar[] { new RtlVar(dest, false) }, new RtlVar[0], new RtlExp[] { new RtlVar(src, false) }, false) .WithComment("regalloc_move:: " + dest + " := " + src)); } }; Action <string, RtlExp, string> sLoad = (string dest, RtlExp src, string var) => { int dbgTag = debugTag++; Util.DebugWriteLine("sLoad: dest = " + dest + " " + dbgTag); newStmts.Add(new RtlStmtComputed((inst => { var eDst = inst.args[0].e; string opPtr = inst.args[1].e.AsOperand(); string ptr = "EvalPtr(r, " + opPtr + ")"; return(IsPtr(var) ? "call r, mems := heapLoadStack(r, core_state, stk, statics, io, mems, " + "$commonVars, $gcVars, $absMem, $toAbs, $stacksFrames, objLayouts, " + eDst + ", " + opPtr + ", " + ptr + ");" + Environment.NewLine + " " + var + "__abs := frameGet($stacksFrames, " + ptr + ");" : "call r := logical_Load(r, core_state, stk, " + eDst + ", " + opPtr + ");"); }), new RtlArg[] { new RtlArg(true, false, new RtlVar(dest, false)), new RtlArg(true, false, src) }, false) .WithComment(() => "regalloc_stack_load:: " + dest + " := " + src + " // var = " + var + " " + dbgTag)); }; Action <RtlExp, string, string> sStore = (RtlExp dest, string src, string var) => { newStmts.Add(new RtlStmtComputed((inst => { string opPtr = inst.args[0].e.AsOperand(); string opVal = inst.args[1].e.AsOperand(); string ptr = "EvalPtr(r, " + opPtr + ")"; string val = "Eval(r, " + opVal + ")"; return(IsPtr(var) ? "call mems, $stacksFrames := " + "heapStoreStack(r, core_state, stk, statics, io, mems, " + "$commonVars, $gcVars, $absMem, $toAbs, $stacksFrames, objLayouts, " + opPtr + ", " + opVal + ", " + ptr + ", " + var + "__abs);" : "call stk := logical_Store(r, core_state, stk, " + opPtr + ", " + opVal + ");"); }), new RtlArg[] { new RtlArg(true, false, dest), new RtlArg(true, false, new RtlVar(src, false)) }, false) .WithComment(() => "regalloc_stack_store:: " + dest + " := " + src + " // var = " + var)); }; workList.Push(0); while (workList.Count > 0) { int i = workList.Pop(); RtlStmt stmt = stmts[i]; stmt.Uses().ForEach(x => preds[i].ForEach(p => { if (!defVars[p].Contains(x)) { throw new Exception( "variable " + x + " is used before it is assigned"); } })); Util.DebugWriteLine(i + ": " + stmt); List <string> vars = stmt.Vars(); List <string> assignment = new List <string>((i == 0) ? initAssign : preds[i].ConvertAll(p => assigned[p]).Find(a => a != null)); Util.DebugWriteLine(" " + String.Join(", ", assignment)); RtlInst inst = stmt as RtlInst; List <Tuple <string, string> > pinVars = (inst == null) ? new List <Tuple <string, string> >() : inst.args.Where(arg => arg.pinReg != null && arg.e is RtlVar) .Select(arg => Tuple.Create(((RtlVar)arg.e).x, arg.pinReg)).ToList(); for (int r = 0; r < regs.Count; r++) { string rx = assignment[r]; if (rx != null && !liveVars[i].ContainsKey(rx)) { assignment[r] = null; } if (pinVars.Exists(p => p.Item1 == rx)) { assignment[r] = null; } foreach (var p in pinVars) { if (p.Item2 == regs[r]) { assignment[r] = p.Item1; } } } if (stmt is RtlCall) { RtlCall call = (RtlCall)stmt; if (!call.ghost) { for (int r = 0; r < regs.Count; r++) { assignment[r] = null; } /* * Func<RtlExp, bool> shouldSkip = (RtlExp e) => ((e is RtlVar) && ((RtlVar)e).isGhost); * int[] outsToReg = new int[2] { regs.IndexOf("EAX"), regs.IndexOf("ESI") }; * int[] argsToReg = new int[3] { regs.IndexOf("ECX"), regs.IndexOf("EDX"), regs.IndexOf("EBX") }; * * for (int r = 0; r < regs.Count; r++) * { * string rx = assignment[r]; * if (rx != null && (call.outs.Where(v => v.ToString() == rx).Count() != 0 || call.args.Where(v => v.ToString() == rx).Count() != 0)) * { * assignment[r] = null; * } * } * for (int idx = 0; idx < 2; idx++) * { * if (call.outs.Count >= idx + 1 && !shouldSkip(call.outs[idx])) * { * int r = outsToReg[idx]; * string rx = assignment[r]; * if (rx != null) * { * sStore(Spill(rx), regs[r]); * } * assignment[r] = call.outs[idx].ToString(); * } * } * for (int idx = 0; idx < 3; idx++) * { * if (call.args.Count >= idx + 1 && !shouldSkip(call.args[idx])) * { * int r = argsToReg[idx]; * string rx = assignment[r]; * if (rx != null) * { * sStore(Spill(rx), regs[r]); * } * assignment[r] = call.args[idx].ToString(); * } * } */ } } else if (stmt is RtlReturn) { for (int r = 0; r < regs.Count; r++) { assignment[r] = null; } } else if (inst == null || !inst.ghost) { foreach (string x in vars) { Tuple <int, int> bestEvict = null; for (int r = 0; r < regs.Count; r++) { var rx = assignment[r]; if (rx == x) { goto done; } if (!vars.Contains(rx)) { int thisEvict = (rx == null) ? Int32.MaxValue : liveVars[i][rx]; if (bestEvict == null || thisEvict > bestEvict.Item2) { bestEvict = Tuple.Create(r, thisEvict); } } } string ex = assignment[bestEvict.Item1]; if (ex != null) { Spill(ex); } assignment[bestEvict.Item1] = x; done : {} } } Util.DebugWriteLine(" vars = " + String.Join(", ", vars)); Util.DebugWriteLine(" preds = " + String.Join(", ", preds[i])); Util.DebugWriteLine(" succs = " + String.Join(", ", succs[i])); Util.DebugWriteLine(" live = " + String.Join(", ", liveVars[i].Keys.Select(x => Tuple.Create(x, liveVars[i][x])))); Util.DebugWriteLine(" assign: " + String.Join(", ", assignment)); assigned[i] = assignment; succs[i].Where(s => assigned[s] == null).ToList().ForEach(workList.Push); } for (int i = 0; i < stmts.Count; i++) { RtlJump jump = stmts[i] as RtlJump; if (jump != null && jump.cond != null) { List <string> assignment1 = assigned[i]; List <string> assignment2 = assigned[labels[jump.label]]; List <string> condVars = jump.cond.Vars(); for (int r = 0; r < regs.Count; r++) { string x1 = assignment1[r]; string x2 = assignment2[r]; if (x1 != null && x2 != null && condVars.Contains(x1) && x1 != x2) { assignment2[r] = null; Spill(x2); } } } } Action <List <string>, Dictionary <string, int>, Dictionary <string, int>, Dictionary <string, string> > transition = (List <string> assignment2, Dictionary <string, int> live, Dictionary <string, int> liveAlt, Dictionary <string, string> varToReg) => { Util.DebugWriteLine("start transition"); varToReg.Keys.Where(x => x != null && !live.ContainsKey(x) && !liveAlt.ContainsKey(x)).ToList() .ForEach(x => varToReg.Remove(x)); bool done; do { done = true; for (int rx = 0; rx < regs.Count; rx++) { string x = assignment2[rx]; string reg = regs[rx]; if (x != null && varToReg.ContainsKey(x) && varToReg[x] != reg && !varToReg.ContainsValue(reg)) { Util.DebugWriteLine("move " + x + ": " + regs[rx] + " <- " + varToReg[x]); move(regs[rx], varToReg[x]); varToReg[x] = reg; done = false; } } } while (!done); List <string> toSpill = new List <string>(); foreach (var current in varToReg) { string x = current.Key; int rx = regs.IndexOf(current.Value); Util.DebugWriteLine("current = " + x + " -> " + regs[rx]); Util.DebugWriteLine("assign = " + assignment2[rx] + " -> " + regs[rx]); if (assignment2[rx] != x && (live.ContainsKey(x) || liveAlt.ContainsKey(x))) { Util.DebugWriteLine("spilling " + x + " from " + regs[rx]); toSpill.Add(x); sStore(Spill(x), regs[rx], x); } } toSpill.ForEach(x => varToReg.Remove(x)); Util.DebugWriteLine("live = " + String.Join(", ", live)); for (int rx = 0; rx < regs.Count; rx++) { string x = assignment2[rx]; if (x != null && live.ContainsKey(x)) { Util.DebugWriteLine("assign = " + x + " -> " + regs[rx]); if (varToReg.ContainsKey(x)) { Util.Assert(varToReg[x] == regs[rx]); } else { Util.DebugWriteLine("loading " + x + " to " + regs[rx]); sLoad(regs[rx], Spill(x), x); Util.DebugWriteLine("loaded " + x + " to " + regs[rx]); varToReg.Add(x, regs[rx]); } } } }; Util.DebugWriteLine("spilled: " + String.Join(", ", spillInts.Keys)); Action <string> DebugWriteLine = s => { }; if (stmts.Count > 0) { transition(assigned[0], liveVars[0], liveVars[0], new Dictionary <string, string>()); } for (int i = 0; i < stmts.Count; i++) { List <string> assignment = assigned[i]; RtlStmt stmt = stmts[i]; List <string> vars = stmt.Vars(); List <string> uses = stmt.Uses(); Dictionary <string, string> varToReg = new Dictionary <string, string>(); Util.DebugWriteLine(i + ": " + stmt); Util.DebugWriteLine(" assignment: " + String.Join(", ", assignment)); Util.DebugWriteLine(" vars:" + String.Join(", ", vars)); Util.DebugWriteLine(" uses:" + String.Join(", ", uses)); DebugWriteLine(i + ": " + stmt.GetType() + ": " + stmt); DebugWriteLine(" vars = " + String.Join(", ", vars)); DebugWriteLine(" uses = " + String.Join(", ", uses)); DebugWriteLine(" preds = " + String.Join(", ", preds[i])); DebugWriteLine(" succs = " + String.Join(", ", succs[i])); DebugWriteLine(" live = " + String.Join(", ", liveVars[i].Keys.Select(x => Tuple.Create(x, liveVars[i][x])))); DebugWriteLine(" defs = " + String.Join(", ", defVars[i])); DebugWriteLine(" assign: " + String.Join(", ", assignment)); Action <int, int> transitionTarget = (int target, int altTarget) => { Util.DebugWriteLine("transition from " + i + " to " + target); transition(assigned[target], liveVars[target], liveVars[altTarget], varToReg); }; int r; for (r = 0; r < regs.Count; r++) { string x = assignment[r]; if (x != null) { varToReg.Add(x, regs[r]); } } r = 0; foreach (string x in vars) { if (varToReg.ContainsKey(x) || stmt is RtlReturn) { continue; } int rx = assignment.IndexOf(x); if (rx < 0) { rx = assignment.IndexOf(null, r); Util.Assert(rx >= 0); Util.DebugWriteLine(i + ": MOVE(1): " + x); sLoad(regs[rx], Spill(x), x); r = rx + 1; } varToReg.Add(x, regs[rx]); } Util.DebugWriteLine("vars = " + String.Join(", ", vars)); List <string> defs = stmt.Defs(); stmt = stmt.Subst(varToReg); Dictionary <string, string> regToVar = new Dictionary <string, string>(); varToReg.ToList().ForEach(p => regToVar.Add(p.Value, p.Key)); RtlJump jump = stmt as RtlJump; RtlReturn ret = stmt as RtlReturn; RtlLabel label = stmt as RtlLabel; RtlCall call = stmt as RtlCall; RtlCallInOut inOut = stmt as RtlCallInOut; if (ret != null) { Util.DebugWriteLine("RETURN: " + outVars.Count); for (int rr = 0; rr < regs.Count; rr++) { string rx = assignment[rr]; if (rx != null) { newStmts.Add(new RtlComment("spill variable " + rx + " from register " + regs[rr])); sStore(Spill(rx), regs[rr], rx); } } } if (jump == null) { List <string> spilledArgs = new List <string>(); if (inOut != null) { string reg = ((RtlVar)(inOut.args[0].e)).getName(); string var = regToVar[reg]; bool isPtr = IsPtr(var); int offset = 4 * inOut.index; RtlExp slot = new RtlExpComputed(e => isPtr ? StackOMemPtr(offset) : StackOMem(offset)); newStmts.Add(new RtlComment(inOut.comment)); if (inOut.isRet) { if (isPtr) { callPtrRets = Math.Max(callPtrRets, inOut.index + 1); } else { callIntRets = Math.Max(callIntRets, inOut.index + 1); newStmts.Add(new RtlInst(null, new RtlVar[] { new RtlVar(var, true) }, new RtlVar[0], new RtlExp[] { new RtlLiteral( CompileMethod.IntToTyped(varTypes[var], slotMem(offset))) }, true)); } Util.DebugWriteLine(" var = " + var + " live = " + String.Join(",", liveVars[i].Keys) + " live' = " + String.Join(",", liveVars[i + 1].Keys)); if (i + 1 >= liveVars.Count || liveVars[i + 1].ContainsKey(var)) { Util.DebugWriteLine("sLoad inOut: " + reg + " " + slot + " " + var); sLoad(reg, slot, var); } } else { if (isPtr) { callPtrArgs = Math.Max(callPtrArgs, inOut.index + 1); } else { callIntArgs = Math.Max(callIntArgs, inOut.index + 1); } sStore(slot, reg, var); } } else { newStmts.Add(stmt); defs.Where(x => !IsPtr(x)).ToList() .ForEach(x => newStmts.Add(new RtlInst(null, new RtlVar[] { new RtlVar(x, true) }, new RtlVar[0], new RtlExp[] { new RtlLiteral( CompileBase.IntToTyped(varTypes[x], Reg(varToReg[x]))) }, true))); } Util.DebugWriteLine("sLoad spilled: " + String.Join(", ", spilledArgs.Select(arg => "(" + varToReg[arg] + " <- " + arg + ")"))); spilledArgs.ForEach(arg => sLoad(varToReg[arg], Spill(arg), arg)); } if (label != null && label.loop) { List <RtlExp> typeInvs = new List <RtlExp>(); newStmts.Add(new RtlComment("loop invariants")); foreach (string x in liveVars[i].Keys) { if (defVars[i].Contains(x)) { compileMethod.AddTypeWellFormed(typeInvs, x, false, varTypes[x]); string save_x = x; RtlExp loc = varToReg.ContainsKey(x) ? new RtlVar(Reg(varToReg[x]), false) : (RtlExp) new RtlExpComputed(e => spillMem(Spill(save_x))); if (IsPtr(x)) { string absData = "Abs_" + TypeString(varTypes[x]) + "(" + x + ")"; if (varToReg.ContainsKey(x)) { newStmts.Add(new RtlAssert(new RtlLiteral( "HeapAbsData(heap, " + x + "__abs) == " + absData), true)); newStmts.Add(new RtlAssert(new RtlExpComputed(e => "HeapValue(objLayouts, true, $toAbs, " + loc + ", " + save_x + "__abs)"), true)); if (IsArray(x)) { newStmts.Add(new RtlAssert(new RtlLiteral( x + "__abs == " + x + ".arrAbs"), true)); } } else { newStmts.Add(new RtlAssert(new RtlExpComputed(e => "StackAbsSlot(heap, $stacksFrames, " + spillLoc(Spill(save_x)) + ") == " + absData), true)); if (IsArray(x)) { newStmts.Add(new RtlAssert(new RtlExpComputed(e => "frameGet($stacksFrames, " + spillLoc(Spill(save_x)) + ") == " + save_x + ".arrAbs"), true)); } } } else { newStmts.Add(new RtlAssert(CompileMethod.IntEqTyped(varTypes[x], new RtlVar(x, false), new RtlExpComputed(e => loc.ToString())), true)); } } } typeInvs.ForEach(e => newStmts.Add(new RtlAssert(e, true))); } bool fallThru = (ret == null && i + 1 < stmts.Count && (jump == null || jump.cond != null)); if (jump != null) { transitionTarget(labels[jump.label], fallThru ? (i + 1) : labels[jump.label]); newStmts.Add(stmt); } if (fallThru) { transitionTarget(i + 1, i + 1); } } return(newStmts); }