/// <summary> /// 编译当前脚本 /// </summary> /// <returns>bool</returns> public bool Compile() { if (this.DebuggerForm == null || this.DebuggerForm.IsDisposed) { return(false); } if (this.m_scriptProperty == null) { this.m_scriptProperty = new ScriptProperty(); } ScriptProperty scriptProperty = this.m_scriptProperty.Clone() as ScriptProperty; scriptProperty.ScriptText = this.textEditorControl1.Text; ScriptCompiler.Instance.WorkingPath = this.DebuggerForm.WorkingPath; CompileResults results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (results.HasErrors) { this.DebuggerForm.ShowCompileErrorForm(results.Errors); return(false); } this.m_scriptProperty = scriptProperty; return(!results.HasErrors); }
private void InitElementCalculators() { this.m_lstElementCalculators.Clear(); if (GlobalMethods.Misc.IsEmptyString(this.m_szScriptSource)) { return; } ScriptProperty scriptProperty = new ScriptProperty(); scriptProperty.ScriptText = this.m_szScriptSource; CompileResults results = null; try { results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (results.HasErrors) { return; } } catch (Exception ex) { LogManager.Instance.WriteLog("ScriptTestForm.InitElementCalculators", ex); MessageBoxEx.Show("无法编译脚本,测试失败!"); return; } foreach (IElementCalculator elementCalculator in results.ElementCalculators) { elementCalculator.GetElementValueCallback = new GetElementValueCallback(this.GetElementValue); elementCalculator.SetElementValueCallback = new SetElementValueCallback(this.SetElementValue); elementCalculator.HideElementTipCallback = new HideElementTipCallback(this.HideElementTip); elementCalculator.ShowElementTipCallback = new ShowElementTipCallback(this.ShowElementTip); this.m_lstElementCalculators.Add(elementCalculator); } }
protected MappedNode(CompileResults results, LexicalInfo lexicalInfo, int length) : this(results, null, results.LocationToPoint(lexicalInfo), results.LocationToPoint(lexicalInfo.Line, lexicalInfo.Column + length)) { LexicalInfo = lexicalInfo; }
protected MappedNode(CompileResults results, Node node) : this(results, node, results.LocationToPoint(node.LexicalInfo), results.LocationToPoint(node.EndSourceLocation)) { LexicalInfo = node.LexicalInfo; }
protected MappedNode(CompileResults results, Node node, int length) : this(results, node, results.LocationToPoint(node.LexicalInfo), results.LocationToPoint(node.LexicalInfo.Line, node.LexicalInfo.Column + length)) { LexicalInfo = node.LexicalInfo; }
public BooFileNode(ProjectNode root, ProjectElement e) : base(root, e) { results = new CompileResults(() => Url, GetCompilerInput, () => GlobalServices.LanguageService.GetLanguagePreferences().TabSize); languageService = (BooLanguageService)GetService(typeof(BooLanguageService)); hidden = true; }
/// <summary> /// 显示脚本测试窗口 /// </summary> internal void ShowScriptTestForm() { if (this.m_ErrorsListForm != null && !this.m_ErrorsListForm.IsDisposed) { this.m_ErrorsListForm.Close(); } ScriptEditForm activeScriptForm = this.ActiveScriptForm; if (activeScriptForm == null || activeScriptForm.IsDisposed) { return; } ScriptProperty scriptProperty = activeScriptForm.ScriptProperty; if (scriptProperty == null) { scriptProperty = new ScriptProperty(); } ScriptCompiler.Instance.WorkingPath = this.WorkingPath; CompileResults results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (results.HasErrors) { this.ShowCompileErrorForm(results.Errors); MessageBoxEx.Show("编译失败,无法启动测试程序!"); return; } ScriptTestForm scriptTestForm = new ScriptTestForm(); scriptTestForm.ShowDialog(scriptProperty.ScriptName, scriptProperty.ScriptText); }
public BooDependentFileNode(ProjectNode root, ProjectElement e) : base(root, e) { results = new CompileResults(() => Url, GetCompilerInput, () => GlobalServices.LanguageService.GetLanguagePreferences().TabSize); languageService = (BooLanguageService)GetService(typeof(BooLanguageService)); hidden = true; this.OleServiceProvider.AddService(typeof(IVSMDCodeDomProvider), CodeDomProvider(root), false); }
protected MappedNode(CompileResults results, Node node, int length) : this(results, node, results.LocationToPoint(node.LexicalInfo), results.LocationToPoint(node.LexicalInfo.Line, node.LexicalInfo.Column + length) ) { LexicalInfo = node.LexicalInfo; }
protected MappedNode(CompileResults results, Node node) : this(results, node, results.LocationToPoint(node.LexicalInfo), results.LocationToPoint(node.EndSourceLocation) ) { LexicalInfo = node.LexicalInfo; }
protected MappedNode(CompileResults results, LexicalInfo lexicalInfo, int length) : this(results, null, results.LocationToPoint(lexicalInfo), results.LocationToPoint(lexicalInfo.Line, lexicalInfo.Column + length) ) { LexicalInfo = lexicalInfo; }
public static CompileResults TryCompile(string text) { var syntaxTree = CSharpSyntaxTree.ParseText(text); var root = syntaxTree.GetRoot(); var incompleteMemberSyntaxCollection = root.DescendantNodes().OfType <IncompleteMemberSyntax>().ToList(); var skippedTokenTriviaSyntaxCollection = root.DescendantNodes().OfType <SkippedTokensTriviaSyntax>().ToList(); var compilationResult = new CompileResults(incompleteMemberSyntaxCollection, skippedTokenTriviaSyntaxCollection); return(compilationResult); }
public static CompileResults RunCompiler(string source) { var results = new CompileResults( () => "Test", () => source, () => 4 ); CompilerManager.Compile(4, new[] { typeof(SerializableAttribute).Assembly }, new[] { results }); return(results); }
private MappedNode(CompileResults results, Node node, CompileResults.BufferPoint start, CompileResults.BufferPoint end) { CompileResults = results; Node = node; TextSpan = new TextSpan { iStartLine = start.Line, iStartIndex = start.Column, iEndLine = end.Line, iEndIndex = end.Column }; }
private void ProcessConditionalDirective(string directive, string line, CompileResults results) { string macroName = GetNextWord(ref line, true, true); if (macroName.Length == 0) { RecordError(ErrorCode.MacroNameMissing, "Expected something after '" + directive + "'"); return; } bool includeCodeBlock = true; if ((_conditionalStatements.Count > 0) && (_conditionalStatements.Peek() == false)) { includeCodeBlock = false; } else if (directive.EndsWith("def")) { includeCodeBlock = _state.Macros.Contains(macroName); if (directive == "ifndef") { includeCodeBlock = !includeCodeBlock; } } else if (directive == "ifver" || directive == "ifnver") { // Compare provided version number with the current application version try { Version appVersion = new Version(_applicationVersion); // .NET Version class requires at least first two version components, // but AGS has traditionally supported one component too. int major_test; if (macroName.IndexOf('.') < 0 && Int32.TryParse(macroName, out major_test)) { macroName = macroName + ".0"; } Version macroVersion = new Version(macroName); includeCodeBlock = appVersion.CompareTo(macroVersion) >= 0; if (directive == "ifnver") { includeCodeBlock = !includeCodeBlock; } } catch (Exception e) { RecordError(ErrorCode.InvalidVersionNumber, String.Format("Cannot parse version number: {0}", e.Message)); } } _conditionalStatements.Push(includeCodeBlock); }
public void SetCompilerResults(CompileResults newResults) { results.HideMessages(((BooProjectNode)ProjectMgr).RemoveTask); results = newResults; if (!hidden) { results.ShowMessages(((BooProjectNode)ProjectMgr).AddTask, Navigate); } if (Recompiled != null) { Recompiled(this, EventArgs.Empty); } }
private void ProcessConditionalDirective(string directive, string line, CompileResults results) { string macroName = GetNextWord(ref line, true, true); if (macroName.Length == 0) { RecordError(ErrorCode.MacroNameMissing, "Expected something after '" + directive + "'"); return; } bool includeCodeBlock = true; if ((_conditionalStatements.Count > 0) && (_conditionalStatements.Peek() == false)) { includeCodeBlock = false; } else if (directive.EndsWith("def")) { includeCodeBlock = _state.Macros.Contains(macroName); if (directive == "ifndef") { includeCodeBlock = !includeCodeBlock; } } else { if (!Char.IsDigit(macroName[0])) { RecordError(ErrorCode.InvalidVersionNumber, "Expected version number"); } else { string appVer = _applicationVersion; if (appVer.Length > macroName.Length) { // AppVer is "3.0.1.25", macroNAme might be "3.0" or "3.0.1" appVer = appVer.Substring(0, macroName.Length); } includeCodeBlock = (appVer.CompareTo(macroName) >= 0); if (directive == "ifnver") { includeCodeBlock = !includeCodeBlock; } } } _conditionalStatements.Push(includeCodeBlock); }
private void ProcessConditionalDirective(string directive, string line, CompileResults results) { string macroName = GetNextWord(ref line, true, true); if (macroName.Length == 0) { RecordError(ErrorCode.MacroNameMissing, "Expected something after '" + directive + "'"); return; } bool includeCodeBlock = true; if ((_conditionalStatements.Count > 0) && (_conditionalStatements.Peek() == false)) { includeCodeBlock = false; } else if (directive.EndsWith("def")) { includeCodeBlock = _state.Macros.Contains(macroName); if (directive == "ifndef") { includeCodeBlock = !includeCodeBlock; } } else if (directive == "ifver" || directive == "ifnver") { // Compare provided version number with the current application version try { Version appVersion = new Version(_applicationVersion); Version macroVersion = new Version(macroName); includeCodeBlock = appVersion.CompareTo(macroVersion) >= 0; if (directive == "ifnver") { includeCodeBlock = !includeCodeBlock; } } catch (Exception e) { RecordError(ErrorCode.InvalidVersionNumber, String.Format("Cannot parse version number: {0}", e.Message)); } } _conditionalStatements.Push(includeCodeBlock); }
/// <summary> /// process a file, generating the compiled output /// </summary> /// <param name="item"></param> protected void ProcessItem(OrangeJob job) { var threadedOpenCmd = new Action(() => { mainDispatcher.Invoke(new Action(() => { var openCommand = host.HostCommands.OpenFileInEditor; if (openCommand.CanExecute(job.OutputPath)) { openCommand.Execute(job.OutputPath); } })); }); try { // do the actual compilation work CompileResults results = compiler.Process(job); // show the notification bar to notify the user it happened if (!String.IsNullOrEmpty(results.Message)) { host.ShowNotification(results.Message, "Open File", threadedOpenCmd); } host.Logger.Log(TraceLevel.Info, string.Format("Success: Compiled {0} to generate {1}", job.Path, job.OutputPath)); // refresh the tree so the new file (if created) shows up if (results.IsNewFile) { mainDispatcher.Invoke(new Action(() => { var refreshCommand = host.HostCommands.GetCommand(CommonCommandIds.GroupId, (int)CommonCommandIds.Ids.Refresh); if (refreshCommand.CanExecute(null)) { refreshCommand.Execute(null); } })); } } catch (Exception ex) { Console.WriteLine(ex); host.Logger.Log(TraceLevel.Error, string.Format("Error compiling {0}: {1}", job.Path, ex.ToString())); host.ShowNotification("There was an error processing " + job.Path, "Open File", threadedOpenCmd); } }
private void TestScript() { if (this.PatVisitInfo == null) { MessageBoxEx.ShowMessage("请先选择患者"); return; } if (this.QcCheckPoint == null) { MessageBoxEx.ShowMessage("缺陷规则未初始化"); return; } if (this.m_ErrorsListForm != null && !this.m_ErrorsListForm.IsDisposed) { this.m_ErrorsListForm.Close(); } ScriptEditForm activeScriptForm = this.ActiveScriptForm; if (activeScriptForm == null || activeScriptForm.IsDisposed) { return; } ScriptProperty scriptProperty = activeScriptForm.ScriptProperty; if (scriptProperty == null) { scriptProperty = new ScriptProperty(); } ScriptCompiler.Instance.WorkingPath = this.WorkingPath; CompileResults results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (results.HasErrors) { this.ShowCompileErrorForm(results.Errors); MessageBoxEx.Show("编译失败,无法启动测试程序!"); return; } AutoCalcHandler.Instance.Start(); foreach (IElementCalculator item in results.ElementCalculators) { //item.Calculate("A"); AutoCalcHandler.Instance.CalcularTest(item, this.PatVisitInfo, this.QcCheckPoint, this.QcCheckResult); } }
private ErrorsListForm.CompileError[] GetCompileErrors(CompileResults results) { ErrorsListForm.CompileError[] errors = null; if (results == null) { return(null); } errors = new ErrorsListForm.CompileError[results.Errors.Count]; for (int index = 0; index < errors.Length; index++) { CompileError error = results.Errors[index]; errors[index] = new ErrorsListForm.CompileError(); errors[index].Line = error.Line; errors[index].Column = error.Column; errors[index].ErrorText = error.ErrorText; errors[index].FileName = error.FileName; errors[index].IsWarning = error.IsWarning; } return(errors); }
protected override void ResolveImpl(MappedToken token) { try { var type = TypeSystemServices.GetType(Node); if (type is Error) { return; } format = Formats.BooType; var prefix = "struct "; if (type.IsClass) { prefix = "class "; } if (type.IsInterface) { prefix = "interface "; } if (type.IsEnum) { prefix = "enumeration "; } quickInfoTip = prefix + type.FullName; var internalType = type as AbstractInternalType; if (internalType != null) { declaringNode = CompileResults.GetMappedNode(internalType.Node); } } catch (Exception) { return; } }
public CompletedModuleWalker(CompileResults results) { this.results = results; }
internal void ShowScriptTestForm() { DesignEditForm designForm = this.ActiveReport; ScriptEditForm scriptForm = this.ActiveScript; if (scriptForm == null && designForm == null) { return; } if (designForm != null) { scriptForm = this.GetScriptForm(designForm); } else if (scriptForm != null) { designForm = this.GetDesignForm(scriptForm); } ReportFileParser parser = new ReportFileParser(); string szScriptData = null; if (scriptForm != null) { szScriptData = scriptForm.Save(); } else { szScriptData = parser.GetScriptData(designForm.HndfFile); } string szDesignData = null; if (designForm != null) { designForm.Save(ref szDesignData); } else { szDesignData = parser.GetDesignData(scriptForm.HndfFile); } //编译脚本 ScriptProperty scriptProperty = new ScriptProperty(); scriptProperty.ScriptText = szScriptData; CompileResults results = null; results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (!results.HasErrors) { this.MainForm.ShowCompileErrorForm(null); } else { if (scriptForm == null) { this.OpenScriptEditForm(designForm); } this.MainForm.ShowCompileErrorForm(this.GetCompileErrors(results)); MessageBoxEx.Show("编译失败,无法启动测试程序!"); return; } ScriptTestForm scriptTestForm = new ScriptTestForm(); scriptTestForm.ScriptData = szScriptData; scriptTestForm.DesignData = szDesignData; scriptTestForm.ShowDialog(); }
public MappedAttribute(CompileResults results, Attribute node) : base(results, node, node.Name.Length) { }
public MappedVariableDefinition(CompileResults results, ParameterDeclaration node) : base(results, node, node.Name.Length) { }
public MappedMacroReference(CompileResults results, MacroStatement node) : base(results, node, node.Name.Length) { format = Formats.BooMacro; quickInfoTip = "macro " + node.Name; }
public MappedTypeMemberDefinition(CompileResults results, Field node) : base(results, node, node.Name.Length) { }
public MappedTypeMemberDefinition(CompileResults results, TypeMember node) : base(results, node) { }
public MappedReferenceExpression(CompileResults results, ReferenceExpression node) : base(results, node, node.Name.Length) { }
public MappedReferenceExpression(CompileResults results, SelfLiteralExpression node) : base(results, node, "self".Length) { }
public MappedTypeDefinition(CompileResults results, TypeDefinition node) : base(results, node) { TypeNode = node; }
public MappedImport(CompileResults results, Import node) : base(results, node, node.Namespace.Length) { }
protected override void ResolveImpl(MappedToken token) { switch (Node.NodeType) { case NodeType.SelfLiteralExpression: var classDefinition = Node; while (classDefinition.ParentNode != null) { if (classDefinition.NodeType != NodeType.ClassDefinition) { classDefinition = classDefinition.ParentNode; } else { varType = TypeSystemServices.GetType(classDefinition); break; } } break; case NodeType.MemberReferenceExpression: case NodeType.ReferenceExpression: var expression = (ReferenceExpression)Node; IEntity entity; try { entity = TypeSystemServices.GetEntity(expression); } catch { break; } var prefix = ""; if (entity is InternalParameter) { prefix = "(parameter) "; varType = TypeSystemServices.GetType(expression); declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter); } if (entity is InternalLocal) { prefix = "(local variable) "; varType = ((InternalLocal)entity).Type; declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local); } if (entity is InternalField) { varType = TypeSystemServices.GetType(Node); declaringType = ((InternalField)entity).DeclaringType; declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field); } if (entity is InternalMethod) { declaringType = ((InternalMethod)entity).DeclaringType; declarationNode = CompileResults.GetMappedNode(((InternalMethod)entity).Method); if (entity is InternalConstructor) { varType = ((InternalConstructor)entity).DeclaringType; } else { varType = ((InternalMethod)entity).ReturnType; } } if (entity is InternalProperty) { declaringType = ((InternalProperty)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property); } if (entity is InternalEvent) { declaringType = ((InternalEvent)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event); } if (entity is ExternalType) { varType = ((ExternalType)entity).Type; format = Formats.BooType; isTypeReference = true; } if (entity is AbstractInternalType) { varType = ((AbstractInternalType)entity).Type; format = Formats.BooType; isTypeReference = true; declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition); } if (entity is ExternalField) { varType = TypeSystemServices.GetType(Node); declaringType = ((ExternalField)entity).DeclaringType; // declarationNode = CompileResults.GetMappedNode(((ExternalField)entity).Field); } if (entity is ExternalMethod) { declaringType = ((ExternalMethod)entity).DeclaringType; // declarationNode = CompileResults.GetMappedNode(declaration); if (entity is ExternalConstructor) { varType = ((ExternalConstructor)entity).DeclaringType; } else { varType = ((ExternalMethod)entity).ReturnType; } } if (entity is ExternalProperty) { declaringType = ((ExternalProperty)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); // declarationNode = CompileResults.GetMappedNode(((ExternalProperty)entity).Property); } if (entity is ExternalEvent) { declaringType = ((ExternalEvent)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); // declarationNode = CompileResults.GetMappedNode(((ExternalEvent)entity).Event); } if (expression.ExpressionType != null) { if (declaringType != null) { prefix += declaringType.FullName + '.'; } quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName; } break; default: break; } }
public ParsedModuleWalker(CompileResults results) { this.results = results; }
public MappedTypeReference(CompileResults results, SimpleTypeReference node) : base(results, node, node.Name.Length) { }
public MappedVariableDefinition(CompileResults results, Local node) : base(results, node, node.Name.Length) { }
public CompletedModuleWalker(CompileResults result) { this.result = result; }