private void LogError(string fileName, string format, params object[] args)
 {
     var engineHost = (ITextTemplatingEngineHost)this.TextTemplating;
     string errorText = string.Format(CultureInfo.CurrentCulture, format, args);
     var error = new CompilerError { FileName = fileName, ErrorText = errorText };
     engineHost.LogErrors(new CompilerErrorCollection(new[] { error }));
 }
 public void EmitError(System.CodeDom.Compiler.CompilerError error)
 {
     if (this.expectedAssemblyOutcomes == null)
     {
         throw new ApplicationException("got error but assembly outcomes not initialized");
     }
     else
     {
         if (this.expectedMethodOutcomes != null)
         {
             // we are inside a method
             if (!this.expectedMethodOutcomes.CheckOutcome(error))
             {
                 // show outcome
                 output.EmitError(error);
             }
         }
         else
         {
             if (!this.expectedAssemblyOutcomes.CheckOutcome(error))
             {
                 // show outcome
                 output.EmitError(error);
             }
         }
     }
 }
示例#3
0
		public void Warning (string message)
		{
			var err = new CompilerError (null, -1, -1, null, message) {
				IsWarning = true,
			};
			Errors.Add (err);
		}
		public CompilerError ParseLine(string line)
		{
			// try to match standard mono errors
			Match match = normalError.Match(line); 
			if (match.Success) {
				CompilerError error = new CompilerError();
				error.Column      = Int32.Parse(match.Result("${column}"));
				error.Line        = Int32.Parse(match.Result("${line}"));
				error.FileName    = Path.GetFullPath(match.Result("${file}"));
				error.IsWarning   = match.Result("${error}") == "warning";
				error.ErrorNumber = match.Result("${number}");
				error.ErrorText   = match.Result("${message}");
				return error;
			} else {
				match = generalError.Match(line);
				if (match.Success) {
					CompilerError error = new CompilerError();
					error.IsWarning   = match.Result("${error}") == "warning";
					error.ErrorNumber = match.Result("${number}");
					error.ErrorText   = match.Result("${message}");
					return error;
				}
			}
			return null;
		}
示例#5
0
文件: CompileY3.cs 项目: kokudori/Y3
 void LogError(CompilerError error)
 {
     if (error.IsWarning)
         Log.LogWarning(null, error.ErrorNumber, null, error.FileName, error.Line, error.Column, 0, 0, error.ErrorText);
     else
         Log.LogError(null, error.ErrorNumber, null, error.FileName, error.Line, error.Column, 0, 0, error.ErrorText);
 }
		public void TaskType_CompilerErrorIsNotWarning_ReturnsError()
		{
			var error = new CompilerError();
			var task = new CompilerErrorTask(error);
			
			Assert.AreEqual(TaskType.Error, task.TaskType);
		}
        private static void AppendError(StringBuilder message, CompilerError error, string[] lines)
        {
            message.AppendLine( error.ToString() );

            if (error.Line <= 0)
            {
                return;
            }

            var line = error.Line - 1;

            if( line - 1 > 0 )
            {
                message.AppendLine( string.Format("{0}: {1}", (line - 1).ToString( "0000", CultureInfo.CurrentUICulture ), lines[line - 1]) );
            }

            message.AppendLine( string.Format("{0}: {1}", (line - 1).ToString( "0000", CultureInfo.CurrentUICulture ), lines[line]) );

            if( line + 1 < lines.Length )
            {
                message.AppendLine( string.Format("{0}: {1}", (line + 1).ToString( "0000", CultureInfo.CurrentUICulture ), lines[line + 1]) );
            }

            message.AppendLine();
        }
示例#8
0
		CompilerError AddError (string message)
		{
			CompilerError err = new CompilerError ();
			err.Column = err.Line = -1;
			err.ErrorText = message;
			errors.Add (err);
			return err;
		}
 public CompilerError(System.CodeDom.Compiler.CompilerError error)
 {
     this.column = error.Column;
     this.file   = error.FileName;
     this.line   = error.Line;
     this.number = error.ErrorNumber;
     this.text   = error.ErrorText;
 }
 /// <devdoc>
 /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/>.</para>
 /// </devdoc>
 public void AddRange(CompilerError[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
 public CompilerConversionTestCase(Type sourceType, Type targetType, CastFlag castFlag, string codeline = null, CompilerError compilerError = null)
 {
     this.SourceType = sourceType;
     this.TargetType = targetType;
     this.Codeline = codeline;
     this.CompilerError = compilerError;
     this.CastFlag = castFlag;
 }
        public CompilerErrorTask(CompilerError error)
            : base(GetFileName(error.FileName),
				error.ErrorText,
				error.Column,
				error.Line,
				GetTaskType(error.IsWarning))
        {
        }
示例#13
0
		public void TaskType_CompilerErrorIsWarning_ReturnsWarning()
		{
			var error = new CompilerError();
			error.IsWarning = true;
			var task = new CompilerErrorTask(error);
			
			Assert.AreEqual(TaskType.Warning, task.TaskType);
		}
 private static string FormatCompilerError(CompilerError compilerError)
 {
     return string.Format(
         "{0}, Line {1}: {2}",
         compilerError.FileName,
         compilerError.Line,
         compilerError.ErrorText
         );
 }
示例#15
0
		public void FileName_CompilerErrorFileNameIsTestTxt_ReturnsTestTxt()
		{
			var error = new CompilerError();
			error.FileName = "test.txt";
			var task = new CompilerErrorTask(error);
			
			FileName expectedFileName = new FileName("test.txt");
			Assert.AreEqual(expectedFileName, task.FileName);
		}
示例#16
0
		public BuildError (CompilerError error)
		{
			FileName = error.FileName;
			Line = error.Line;
			Column = error.Column;
			ErrorNumber = error.ErrorNumber;
			ErrorText = error.ErrorText;
			IsWarning = error.IsWarning;
		}
示例#17
0
		public void Line_CompilerErrorLineIsThree_ReturnsThree()
		{
			var error = new CompilerError();
			error.FileName = "test.txt";
			error.Line = 3;
			var task = new CompilerErrorTask(error);
			
			Assert.AreEqual(3, task.Line);
		}
示例#18
0
 public ScriptCompilerError(CompilerError compilerError)
 {
     Column = compilerError.Column;
     ErrorNumber = compilerError.ErrorNumber;
     ErrorText = compilerError.ErrorText;
     FileName = compilerError.FileName;
     IsWarning = compilerError.IsWarning;
     Line = compilerError.Line;
 }
 public void EmitError(System.CodeDom.Compiler.CompilerError error)
 {
     output.EmitError(error);
     if (insideMethod)
     {
         EnsureMethodStart();
     }
     EmitOutcomeToBaseLine(error);
 }
示例#20
0
        public static ConvertionResult Convert(string code, AlgoType algotype, Model.File[] includeFiles)
        {
            string calgoCode = null;
            IEnumerable<ParsingError> parsingErrors = new ParsingError[0];
            var compilerErrors = new CompilerError[0];

            var codeBase = CodeBase.Mq4;
            if (CSharpCodeDetector.IsCSharpCode(code))
            {
                codeBase = CodeBase.CSharp;
            }
            else if (MqCodeBaseDetector.IsMq5Code(code))
            {
                codeBase = CodeBase.Mq5;
            }
            else if (!MqCodeBaseDetector.IsValidMq4Code(code))
            {
                codeBase = CodeBase.Invalid;
            }
            else
            {
                var parser = new Mq4Parser();

                var indicatorParsingResult = parser.Parse(code, algotype, includeFiles);
                var algo = indicatorParsingResult.Algo;
                parsingErrors = indicatorParsingResult.ParsingErrors;
                if (parsingErrors.All(e => e.ErrorType < ErrorType.Error))
                {
                    var presenter = CreatePresenter(algotype);
                    calgoCode = presenter.GenerateCodeFrom(algo);

                    var compiler = new CSharpCompiler();
                    var fileName = Path.GetTempFileName();
                    try
                    {
                        var codeToCompile = calgoCode;
                        var indexToInsert = codeToCompile.IndexOf("//Custom Indicators Place Holder");
                        foreach (var customIndicatorName in algo.CustomIndicators)
                        {
                            codeToCompile = codeToCompile.Insert(indexToInsert,
                                                                 CustomIndicatorTemplate.Replace("CustomIndicatorName",
                                                                                                 customIndicatorName));
                        }
                        compilerErrors = compiler.Compile(codeToCompile, fileName);

                        codeBase = MqCodeBaseDetector.GetCodeBaseFromErrors(compilerErrors);
                    }
                    finally
                    {
                        File.Delete(fileName);
                    }
                }
            }

            return new ConvertionResult(calgoCode, parsingErrors, compilerErrors, codeBase);
        }
        public void Ctor_sets_properties()
        {
            var message = "Some message";
            var errors = new CompilerError[0];

            var ex = new CompilerErrorException(message, errors);

            Assert.Equal(message, ex.Message);
            Assert.Same(errors, ex.Errors);
        }
 public CompilerExceptionListViewItem(CompilerError ce, int imgListCount)
     : base(ce.ErrorText)
 {
     this.compilerError = ce;
     //this.ImageIndex = (imgListCount / 2) - 1;
     this.ImageIndex = (imgListCount / 2);
     this.SubItems.Add(ce.Line.ToString() );
     this.SubItems.Add(ce.Column.ToString() );
     this.SubItems.Add(ce.IsWarning.ToString() );
 }
示例#23
0
		public void Column_CompilerErrorColumnIsTwo_ReturnsTwo()
		{
			var error = new CompilerError();
			error.FileName = "test.txt";
			error.Line = 1;
			error.Column = 2;
			var task = new CompilerErrorTask(error);
			
			Assert.AreEqual(2, task.Column);
		}
			public void Parse(string l)
			{
				CompilerError error = new CompilerError();
				error.ErrorNumber = String.Empty;

				char [] delim = {':'};
				string [] s = l.Split(delim, 7);
				
				try
				{
				    SetErrorType (error, s[5]);
				    if (s[6].StartsWith ("N") && s[6].Contains (": "))
				    {
				        string[] e = s[6].Split (delim, 2);
				        error.ErrorNumber = s[0];
				        error.ErrorText = s[1].Trim ();
				    }
				    else
				        error.ErrorText = s[6].Trim ();
				    error.FileName = s[0];
				    error.Line = int.Parse(s[1]);
				    error.Column = int.Parse(s[2]);
				}
				catch
				{
				    SetErrorType (error, s[0]);
				    error.ErrorText = s[1].Trim ();
				    error.FileName = "";
				    error.Line = 0;
				    error.Column = 0;
				}
				
				/*if (SetErrorType(error, s[5]))
				{
					error.ErrorText = s[6]; // l.Substring(l.IndexOf(s[0]+": ") + s[0].Length+2);
					error.FileName  = "";
					error.Line      = 0;
					error.Column    = 0;
				} else
				if ((s.Length >= 4)  && SetErrorType(error, s[3].Substring(1)))
				{
					error.ErrorText = l.Substring(l.IndexOf(s[3]+": ") + s[3].Length+2);
					error.FileName  = s[0];
					error.Line      = int.Parse(s[1]);
					error.Column    = int.Parse(s[2]);
				} else
				{
					error.ErrorText = l;
					error.FileName  = "";
					error.Line      = 0;
					error.Column    = 0;
					error.IsWarning = false;					
				}*/
				Errors.Add(error);
			}
示例#25
0
        public void AdjustErrors(System.CodeDom.Compiler.CompilerError ce)
        {
            int j = ce.Line - ExtLine - StartLineNum;

            ce.Line = j;
            if (j < 1 || j > ExtColumn.Length)
            {
                j = 1;
            }
            ce.Column -= ExtColumn[j - 1];
        }
 public void AddRange(CompilerError[] value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; i < value.Length; i++)
     {
         this.Add(value[i]);
     }
 }
示例#27
0
 public Task(Project project, CompilerError error)
 {
     this.project = project;
     type        = error.IsWarning ? error.ErrorNumber == "COMMENT" ? TaskType.Comment : TaskType.Warning : TaskType.Error;
     column      = error.Column;
     line        = error.Line;
     description = error.ErrorText;
     if (error.ErrorNumber != String.Empty)
         description += "(" + error.ErrorNumber + ")";
     fileName    = error.FileName;
 }
示例#28
0
        /// <summary>
        /// Adds a new error to the list of <see cref="Errors"/> produced by the current <see cref="Run"/>.
        /// </summary>
        /// <param name="message">
        /// Error message.
        /// </param>
        public void Error(string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            CompilerError error = new CompilerError();
            error.ErrorText = message;
            this.Errors.Add(error);
        }
 internal WorkflowCompilerError(CompilerError error)
 {
     if (error == null)
         throw new ArgumentNullException("error");
     this.Column = error.Column - 1;
     this.ErrorNumber = error.ErrorNumber;
     this.ErrorText = error.ErrorText;
     this.FileName = error.FileName;
     this.IsWarning = error.IsWarning;
     this.Line = error.Line - 1;
     this.incrementLineAndColumn = true;
 }
		public DotNetScriptError(CompilerError error, IZeusContext context)
		{
			if (context != null)
				this._fileName = context.ExecutingTemplate.FilePath + context.ExecutingTemplate.FileName;
			this._source = error.FileName;
			this._message = error.ErrorText;
			this._description = string.Empty;
			this._number = error.ErrorNumber;
			this._line = error.Line;
			this._column = error.Column;
			this._stackTrace = string.Empty;
			this._isWarning = error.IsWarning;
		}
示例#31
0
 private void CallWarningFound(Module assembly, string message)
 {
     if (ErrorFound == null)
     {
         throw new InvalidOperationException(message);
     }
     else
     {
         var error = new System.CodeDom.Compiler.CompilerError(assembly.Location, 0, 0, "", message);
         error.IsWarning = true;
         ErrorFound(error);
     }
 }
        public void HandleErrors_throws_when_errors()
        {
            var error = new CompilerError { IsWarning = false };
            var errors = new CompilerErrorCollection { error };
            var message = "Some message";

            var ex = Assert.Throws<CompilerErrorException>(
                () => errors.HandleErrors(message));

            Assert.Equal(message, ex.Message);
            Assert.NotNull(ex.Errors);
            Assert.Equal(1, ex.Errors.Count());
            Assert.Same(error, ex.Errors.Single());
        }
		public static ValidationError CreateFromCompileError(CompilerError compilerError)
		{
			var vError = new ValidationError
			{
				ErrorMessage = compilerError.ErrorText,
				ErrorNumber = compilerError.ErrorNumber,
				WarningLevel = compilerError.IsWarning ? 1 : 0,
				Severity =
					compilerError.IsWarning ? ValiationErrorSeverity.Warning : ValiationErrorSeverity.Error,
				Line = compilerError.Line - 1,
				Column = compilerError.Column - 1,
				FileName = compilerError.FileName
			};

			return vError;
		}
示例#34
0
        /// <summary>
        /// Creates an Assembly from DynamicAssembly definition
        /// </summary>
        /// <param name="assemblyDefinition">assembly description</param>
        /// <returns>result with assembly or error info</returns>
        public static CompileResult CompileDynamicAssembly(DynamicAssembly assemblyDefinition)
        {
            CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp");
            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.CompilerOptions = "/t:library /platform:anycpu /lib:" + "\"" + 
                (String.IsNullOrWhiteSpace(assemblyDefinition.ReferencesPath) ? GetCurrentPath() : assemblyDefinition.ReferencesPath) + "\"";
            compilerParameters.IncludeDebugInformation = false;
            //compilerParameters.OutputAssembly = assemblyDefinition.Name;
            compilerParameters.GenerateInMemory = true;
            compilerParameters.GenerateExecutable = false;   
            
            foreach (var item in assemblyDefinition.References)
                compilerParameters.ReferencedAssemblies.Add(item);

            List<string> codeModules = new List<string>();
            foreach (DynamicClass item in assemblyDefinition.Classes)
            {
                string code = DynamicClass.Template;
                code = DynamicClass.AddUsingsToTemplate(item, code);
                code = DynamicClass.AddInterfacesToTemplate(item, code);
                code = DynamicClass.AddNamespaceToTemplate(String.IsNullOrWhiteSpace(item.Namespace) ? assemblyDefinition.Name : item.Namespace, code);
                code = DynamicClass.AddNameToTemplate(item, code);
                code = DynamicClass.AddPropertiesToTemplate(item, code);
                code = DynamicClass.AddMethodsToTemplate(item, code);
                codeModules.Add(code);
            }

            foreach (DynamicCustomClass item in assemblyDefinition.CustomClasses)
                codeModules.Add(item.Code);

            // we dont allow empty class definitions(fun fact: its okay for the c# compiler)
            foreach (DynamicCustomClass item in assemblyDefinition.CustomClasses)
            {
                if (String.IsNullOrWhiteSpace(item.Code))
                {
                    CompilerErrorCollection collection = new CompilerErrorCollection();
                    CompilerError customError = new CompilerError("CustomClass", 0, 0, "Custom", "Unable to compile an empty code module.");
                    collection.Add(customError);
                    return new CompileResult(codeModules.ToArray(), collection, null);
                }
            }

            CompilerResults compilerResults = codeDomProvider.CompileAssemblyFromSource(compilerParameters, codeModules.ToArray());
            codeDomProvider.Dispose();

            return new CompileResult(codeModules.ToArray(), compilerResults.Errors, compilerResults.Errors.Count > 0 ? null : compilerResults.CompiledAssembly);
        }
        public void Is_serializable()
        {
            var message = "Some message";
            var errors = new CompilerError[0];
            var formatter = new BinaryFormatter();
            CompilerErrorException ex;

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, new CompilerErrorException(message, errors));
                stream.Position = 0;
                ex = (CompilerErrorException)formatter.Deserialize(stream);
            }

            Assert.Equal(message, ex.Message);
            Assert.Equal(errors, ex.Errors);
        }
示例#36
0
            internal string TransformText()
            {
                try
                {
                    return((string)_transformText.Invoke(_instance, new object[0]));
                }
                catch (TargetInvocationException e)
                {
                    Exception actual = e.InnerException != null ? e.InnerException : e;

                    System.CodeDom.Compiler.CompilerError error = new System.CodeDom.Compiler.CompilerError();
                    error.ErrorText = actual.Message;
                    error.IsWarning = false;
                    error.FileName  = SourceCsdlPath;
                    Errors.Add(error);

                    return(string.Empty);
                }
            }
示例#37
0
        public Assembly Compile(string FileName, string ReferenceRoot)
        {
            CompilerResults cr = FormulaSpace.Compile(
                "using Easychart.Finance;\r\n" +
                "using Easychart.Finance.DataProvider;\r\n" +
                GetSource(""),
                FileName,
                ReferenceRoot);

            StartLineNum = 2;

            if (cr.Errors.Count > 0)
            {
                for (int i = 0; i < cr.Errors.Count; i++)
                {
                    System.CodeDom.Compiler.CompilerError ce = cr.Errors[i];
                    AdjustErrors(ce);
                }
                throw new FormulaErrorException(null, cr.Errors);
            }
            return(cr.CompiledAssembly);
        }
 /// <devdoc>
 /// <para>Gets a value indicating whether the
 ///    <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/> contains the specified <see cref='System.CodeDom.Compiler.CompilerError'/>.</para>
 /// </devdoc>
 public bool Contains(CompilerError value)
 {
     return(List.Contains(value));
 }
 public int IndexOf(CompilerError value) => List.IndexOf(value);
 public int Add(CompilerError value) => List.Add(value);
 public bool Contains(CompilerError value) => List.Contains(value);
示例#42
0
 public void Add(CompilerError error)
 {
 }
 /// <devdoc>
 ///    <para>Adds a <see cref='System.CodeDom.Compiler.CompilerError'/> with the specified value to the
 ///    <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/> .</para>
 /// </devdoc>
 public int Add(CompilerError value)
 {
     return(List.Add(value));
 }
 /// <devdoc>
 ///    <para> Removes a specific <see cref='System.CodeDom.Compiler.CompilerError'/> from the
 ///    <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/> .</para>
 /// </devdoc>
 public void Remove(CompilerError value)
 {
     List.Remove(value);
 }
 /// <devdoc>
 ///    <para>Returns the index of a <see cref='System.CodeDom.Compiler.CompilerError'/> in
 ///       the <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/> .</para>
 /// </devdoc>
 public int IndexOf(CompilerError value)
 {
     return(List.IndexOf(value));
 }
 /// <devdoc>
 /// <para>Inserts a <see cref='System.CodeDom.Compiler.CompilerError'/> into the <see cref='System.CodeDom.Compiler.CompilerErrorCollection'/> at the specified index.</para>
 /// </devdoc>
 public void Insert(int index, CompilerError value)
 {
     List.Insert(index, value);
 }