소스 검색

2003-06-20 Andreas Nahr <[email protected]>

	* CodeCompiler.cs: Nearly completely implemented
	* CodeDomProvider.cs: Added missing Attribute, restyled according to style guidelines
	* CodeGenerator.cs: Fixed visibilies, added missing members, implemented members, stubbed out missing member, restyled according to style guidelines
	* CodeParser.cs: Added and implemented (ok no real implementation needed ;)
	* CompilerErrorCollection.cs: Removed unneeded MonoTODOs, restyled according to style guidelines
	* CompilerParameters.cs: Fixed wrong properties, Added Initializers, restyled according to style guidelines
	* CompilerResults.cs: Added Evidence property, added initial values
	* Executor.cs: Added and partially implemented (should probably be used by CodeCompiler)

	* CompilerOptions.cs: Deleted this file (such a class does not exist)

svn path=/trunk/mcs/; revision=15992
Andreas N 22 년 전
부모
커밋
133bb5f987

+ 13 - 0
mcs/class/System/System.CodeDom.Compiler/ChangeLog

@@ -1,3 +1,16 @@
+2003-06-20  Andreas Nahr <[email protected]>
+
+	* CodeCompiler.cs: Nearly completely implemented
+	* CodeDomProvider.cs: Added missing Attribute, restyled according to style guidelines
+	* CodeGenerator.cs: Fixed visibilies, added missing members, implemented members, stubbed out missing member, restyled according to style guidelines
+	* CodeParser.cs: Added and implemented (ok no real implementation needed ;)
+	* CompilerErrorCollection.cs: Removed unneeded MonoTODOs, restyled according to style guidelines
+	* CompilerParameters.cs: Fixed wrong properties, Added Initializers, restyled according to style guidelines
+	* CompilerResults.cs: Added Evidence property, added initial values
+	* Executor.cs: Added and partially implemented (should probably be used by CodeCompiler)
+	
+	* CompilerOptions.cs: Deleted this file (such a class does not exist)
+	
 2003-05-16  Dick Porter  <[email protected]>
 
 	* TempFileCollection.cs: Implement

+ 132 - 66
mcs/class/System/System.CodeDom.Compiler/CodeCompiler.cs

@@ -1,21 +1,29 @@
 //
-// System.CodeDom.Compiler.CodeCompiler
+// System.CodeDom.Compiler.CodeCompiler.cs
 //
-// Author(s):
-//  Jackson Harper ([email protected])
+// Authors:
+//   Jackson Harper ([email protected])
+//   Andreas Nahr ([email protected])
 //
 // (C) 2002 Jackson Harper, All rights reserved
+// (C) 2003 Andreas Nahr
 //
 
+using System;
+using System.IO;
+using System.Text;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Diagnostics;
+
 namespace System.CodeDom.Compiler {
 
 	public abstract class CodeCompiler : CodeGenerator, ICodeCompiler
 	{
 
-		[MonoTODO]
 		protected CodeCompiler ()
 		{
-			throw new NotImplementedException ();
 		}
 
 		protected abstract string CompilerName {
@@ -26,112 +34,170 @@ namespace System.CodeDom.Compiler {
 			get;
 		}
 
-		protected abstract string CmdArgsFromParameters (
-			CompilerParameters options);
+		protected abstract string CmdArgsFromParameters (CompilerParameters options);
 
-		[MonoTODO]
-		protected virtual CompilerResults FromDom (
-			CompilerParameters options, CodeCompileUnit e)
+		protected virtual CompilerResults FromDom (CompilerParameters options, CodeCompileUnit e)
 		{
-			throw new NotImplementedException ();
+			return FromDomBatch (options, new CodeCompileUnit[]{e});
 		}
 	
-		[MonoTODO]
-		protected virtual CompilerResults FromDomBatch(
-			CompilerParameters options,CodeCompileUnit[] ea)
+		protected virtual CompilerResults FromDomBatch (CompilerParameters options, CodeCompileUnit[] ea)
 		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected virtual CompilerResults FromFile(
-			CompilerParameters options,string fileName)
+			string[] fileNames = new string[ea.Length];
+			int i = 0;
+			if (options == null)
+				options = new CompilerParameters ();
+			
+			StringCollection assemblies = options.ReferencedAssemblies;
+
+			foreach (CodeCompileUnit e in ea) {
+				fileNames[i] = Path.ChangeExtension (Path.GetTempFileName(), FileExtension);
+				FileStream f = new FileStream (fileNames[i], FileMode.OpenOrCreate);
+				StreamWriter s = new StreamWriter (f);
+				if (e.ReferencedAssemblies != null) {
+					foreach (string str in e.ReferencedAssemblies) {
+						if (!assemblies.Contains (str))
+							assemblies.Add (str);
+					}
+				}
+
+				((ICodeGenerator)this).GenerateCodeFromCompileUnit (e, s, new CodeGeneratorOptions());
+				s.Close();
+				f.Close();
+				i++;
+			}
+			return Compile (options, fileNames, false);
+		}
+
+		protected virtual CompilerResults FromFile (CompilerParameters options, string fileName)
 		{
-			throw new NotImplementedException ();
+			return FromFileBatch (options, new string[] {fileName});
 		}
 
-		[MonoTODO]
-		protected virtual CompilerResults FromFileBatch(
-			CompilerParameters options,string[] fileNames)
+		protected virtual CompilerResults FromFileBatch (CompilerParameters options, string[] fileNames)
 		{
-			throw new NotImplementedException ();
+			return Compile (options, fileNames, true);
 		}
 
-		[MonoTODO]
-		protected virtual CompilerResults FromSource(
-			CompilerParameters options,string source)
+		protected virtual CompilerResults FromSource (CompilerParameters options, string source)
 		{
-			throw new NotImplementedException ();
+			return FromSourceBatch(options, new string[]{source});
 		}
 
-		[MonoTODO]
-		protected virtual CompilerResults FromSourceBatch(
-			CompilerParameters options,string[] sources)
+		protected virtual CompilerResults FromSourceBatch (CompilerParameters options, string[] sources)
 		{
-			throw new NotImplementedException ();
+			string[] fileNames = new string[sources.Length];
+			int i = 0;
+			foreach (string source in sources) {
+				fileNames[i] = Path.ChangeExtension (Path.GetTempFileName(), FileExtension);
+				FileStream f = new FileStream (fileNames[i], FileMode.OpenOrCreate);
+				StreamWriter s = new StreamWriter (f);
+				s.Write (source);
+				s.Close ();
+				f.Close ();
+				i++;
+			}
+			return Compile (options, fileNames, false);
+		}
+
+		private CompilerResults Compile (CompilerParameters options, string[] fileNames, bool keepFiles)
+		{
+			if (null == options)
+				throw new ArgumentNullException ("options");
+			if (null == fileNames)
+				throw new ArgumentNullException ("fileNames");
+
+			options.TempFiles = new TempFileCollection ();
+			foreach (string file in fileNames)
+			{
+				options.TempFiles.AddFile (file, keepFiles);
+			}
+			options.TempFiles.KeepFiles = keepFiles;
+
+			CompilerResults results = new CompilerResults (new TempFileCollection());
+
+			// FIXME this should probably be done by the System.CodeDom.Compiler.Executor class
+			Process compiler = new Process();
+
+			string compiler_output;
+			string[] compiler_output_lines;
+			compiler.StartInfo.FileName = CompilerName;
+			compiler.StartInfo.Arguments = CmdArgsFromParameters (options);
+			compiler.StartInfo.CreateNoWindow = true;
+			compiler.StartInfo.UseShellExecute = false;
+			compiler.StartInfo.RedirectStandardOutput = true;
+			try {
+				compiler.Start();
+				compiler_output = compiler.StandardOutput.ReadToEnd();
+				compiler.WaitForExit();
+			} 
+			finally {
+				results.NativeCompilerReturnValue = compiler.ExitCode;
+				compiler.Close();
+			}
+
+			// END FIXME
+
+			compiler_output_lines = compiler_output.Split(
+				System.Environment.NewLine.ToCharArray());
+			foreach (string error_line in compiler_output_lines)
+				ProcessCompilerOutputLine (results, error_line);
+			if (results.Errors.Count == 0)
+				results.CompiledAssembly = Assembly.LoadFrom (options.OutputAssembly);
+			else
+				results.CompiledAssembly = null;
+			return results;
 		}
 
-
 		[MonoTODO]
-		protected virtual string GetResponseFileCmdArgs(
-			CompilerParameters options,string cmdArgs)
+		protected virtual string GetResponseFileCmdArgs (CompilerParameters options, string cmdArgs)
 		{
+			// FIXME I'm not sure what this function should do...
 			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromDom(
-			CompilerParameters options,CodeCompileUnit e)
+		CompilerResults ICodeCompiler.CompileAssemblyFromDom (CompilerParameters options, CodeCompileUnit e)
 		{
-			throw new NotImplementedException ();
+			return FromDom (options, e);
 		}
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromDomBatch(
-			CompilerParameters options,CodeCompileUnit[] ea)
+		CompilerResults ICodeCompiler.CompileAssemblyFromDomBatch (CompilerParameters options, CodeCompileUnit[] ea)
 		{
-			throw new NotImplementedException ();
+			return FromDomBatch (options, ea);
 		}
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromFile(
-			CompilerParameters options, string fileName)
+		CompilerResults ICodeCompiler.CompileAssemblyFromFile (CompilerParameters options, string fileName)
 		{
-			throw new NotImplementedException ();
+			return FromFile (options, fileName);
 		}
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromFileBatch(
-			CompilerParameters options, string[] fileNames)
+		CompilerResults ICodeCompiler.CompileAssemblyFromFileBatch (CompilerParameters options, string[] fileNames)
 		{
-			throw new NotImplementedException ();
+			return FromFileBatch (options, fileNames);
 		}
 
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromSource(
-			CompilerParameters options, string source)
+		CompilerResults ICodeCompiler.CompileAssemblyFromSource (CompilerParameters options, string source)
 		{
-			throw new NotImplementedException ();
+			return FromSource (options, source);
 		}
 
 
-		[MonoTODO]
-		CompilerResults ICodeCompiler.CompileAssemblyFromSourceBatch(
-			CompilerParameters options, string[] sources)
+		CompilerResults ICodeCompiler.CompileAssemblyFromSourceBatch (CompilerParameters options, string[] sources)
 		{
-			throw new NotImplementedException ();
+			return FromSourceBatch (options, sources);
 		}
 
-		[MonoTODO]
-		protected static string JoinStringArray(string[] sa, 
-			string separator)
+		protected static string JoinStringArray (string[] sa, string separator)
 		{
-			throw new NotImplementedException ();
+			StringBuilder sb = new StringBuilder ();
+
+			foreach (string s in sa)
+				sb.Append (s + separator);
+			return sb.ToString ();
 		}
 
-		protected abstract void ProcessCompilerOutputLine(
-			CompilerResults results, string line);
+		protected abstract void ProcessCompilerOutputLine (CompilerResults results, string line);
 
 	}
 }

+ 6 - 7
mcs/class/System/System.CodeDom.Compiler/CodeDomProvider.cs

@@ -1,5 +1,5 @@
 //
-// System.CodeDom.Compiler CodeDomProvider Class implementation
+// System.CodeDom.Compiler.CodeDomProvider.cs
 //
 // Author:
 //   Daniel Stodden ([email protected])
@@ -12,9 +12,8 @@ using System.IO;
 
 namespace System.CodeDom.Compiler
 {
-	[ToolboxItem("")]
-	public abstract class CodeDomProvider
-		: Component
+	[ToolboxItem (""), DesignerCategory ("Component")]
+	public abstract class CodeDomProvider : Component
 	{
 		//
 		// Constructors
@@ -45,12 +44,12 @@ namespace System.CodeDom.Compiler
 
 		public abstract ICodeGenerator CreateGenerator();
 		
-		public virtual ICodeGenerator CreateGenerator( string fileName )
+		public virtual ICodeGenerator CreateGenerator (string fileName)
 		{
 			return CreateGenerator();
 		}
 
-		public virtual ICodeGenerator CreateGenerator( TextWriter output )
+		public virtual ICodeGenerator CreateGenerator (TextWriter output)
 		{
 			return CreateGenerator();
 		}
@@ -60,7 +59,7 @@ namespace System.CodeDom.Compiler
 			return null;
 		}
 
-		public virtual TypeConverter GetConverter( Type type )
+		public virtual TypeConverter GetConverter (Type type)
 		{
 			return TypeDescriptor.GetConverter (type);
 		}

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 317 - 276
mcs/class/System/System.CodeDom.Compiler/CodeGenerator.cs


+ 24 - 0
mcs/class/System/System.CodeDom.Compiler/CodeParser.cs

@@ -0,0 +1,24 @@
+//
+// System.CodeDom.Compiler.CodeParser.cs
+//
+// Author:
+//   Andreas Nahr ([email protected])
+//
+// (C) 2003 Andreas Nahr
+//
+
+using System.IO;
+
+namespace System.CodeDom.Compiler 
+{
+
+	public abstract class CodeParser : ICodeParser
+	{
+
+		protected CodeParser ()
+		{
+		}
+
+		public abstract CodeCompileUnit Parse (TextReader codeStream);
+	}
+}

+ 7 - 11
mcs/class/System/System.CodeDom.Compiler/CompilerErrorCollection.cs

@@ -1,19 +1,18 @@
 //
-// System.CodeDom.Compiler CompilerErrorCollection Class implementation
+// System.CodeDom.Compiler.CompilerErrorCollection.cs
 //
 // Authors:
-// 	Daniel Stodden ([email protected])
-//	Gonzalo Paniagua Javier ([email protected])
+//   Daniel Stodden ([email protected])
+//   Gonzalo Paniagua Javier ([email protected])
 //
 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
 //
 using System.Collections;
 namespace System.CodeDom.Compiler
 {
-	[MonoTODO]
+	[Serializable ()]
 	public class CompilerErrorCollection : CollectionBase
 	{
-		[MonoTODO]
 		public CompilerErrorCollection ()
 		{
 		}
@@ -68,14 +67,12 @@ namespace System.CodeDom.Compiler
 			InnerList.Remove(value);
 		}
 
-		public CompilerError this [int index]
-		{
+		public CompilerError this [int index] {
 			get { return (CompilerError) InnerList[index]; }
 			set { InnerList[index]=value; }
 		}
 
-		public bool HasErrors
-		{
+		public bool HasErrors {
 			get {
 				foreach (CompilerError error in InnerList)
 					if (!error.IsWarning) return true;
@@ -83,8 +80,7 @@ namespace System.CodeDom.Compiler
 			}
 		}
 
-		public bool HasWarnings
-		{
+		public bool HasWarnings {
 			get {
 				foreach (CompilerError error in InnerList)
 					if (error.IsWarning) return true;

+ 48 - 31
mcs/class/System/System.CodeDom.Compiler/CompilerParameters.cs

@@ -1,30 +1,37 @@
 //
-// System.CodeDom.Compiler CompilerParameters Class implementation
+// System.CodeDom.Compiler.CompilerParameters.cs
 //
-// Author:
+// Authors:
 //   Daniel Stodden ([email protected])
+//   Andreas Nahr ([email protected])
 //
 // (C) 2002 Ximian, Inc.
 //
 
 using System.Collections.Specialized;
+using System.Security.Policy;
+using System.Runtime.InteropServices;
 
 namespace System.CodeDom.Compiler
 {
+	[ComVisible (false)]
 	public class CompilerParameters
 	{
-		private CompilerOptions compilerOptions;
-		private bool generateExecutables;
-		private bool generateInMemory;
-		private bool includeDebugInformation;
+		private string compilerOptions;
+		#if (NET_1_1)
+			private Evidence evidence;
+		#endif
+		private bool generateExecutable = false;
+		private bool generateInMemory = false;
+		private bool includeDebugInformation = false;
 		private string mainClass;
 		private string outputAssembly;
 		private StringCollection referencedAssemblies;
 		private TempFileCollection tempFiles;
-		private bool treatWarningsAsErrors;
-		private IntPtr userToken;
-		private int warningLevel;
-		private string win32Resources;
+		private bool treatWarningsAsErrors = false;
+		private IntPtr userToken = IntPtr.Zero;
+		private int warningLevel = -1;
+		private string win32Resource;
 
 		//
 		// Constructors
@@ -33,32 +40,31 @@ namespace System.CodeDom.Compiler
 		{
 		}
 		
-		public CompilerParameters( string[] assemblyNames )
+		public CompilerParameters (string[] assemblyNames)
 		{
-			referencedAssemblies=new StringCollection();
-			referencedAssemblies.AddRange(assemblyNames);
+			referencedAssemblies = new StringCollection();
+			referencedAssemblies.AddRange (assemblyNames);
 		}
 
-		public CompilerParameters( string[] assemblyNames, string output )
+		public CompilerParameters (string[] assemblyNames, string output)
 		{
-			referencedAssemblies=new StringCollection();
-			referencedAssemblies.AddRange(assemblyNames);
-			outputAssembly=output;
+			referencedAssemblies = new StringCollection();
+			referencedAssemblies.AddRange (assemblyNames);
+			outputAssembly = output;
 		}
 
-		public CompilerParameters( string[] assemblyNames, string output, bool includeDebugInfo )
+		public CompilerParameters (string[] assemblyNames, string output, bool includeDebugInfo)
 		{
-			referencedAssemblies=new StringCollection();
-			referencedAssemblies.AddRange(assemblyNames);
-			outputAssembly=output;
-			includeDebugInformation=includeDebugInfo;
+			referencedAssemblies = new StringCollection();
+			referencedAssemblies.AddRange (assemblyNames);
+			outputAssembly = output;
+			includeDebugInformation = includeDebugInfo;
 		}
 
-		
 		//
 		// Properties
 		//
-		public CompilerOptions CompilerOptions {
+		public string CompilerOptions {
 			get {
 				return compilerOptions;
 			}
@@ -67,12 +73,23 @@ namespace System.CodeDom.Compiler
 			}
 		}
 
-		public bool GenerateExecutables {
+		#if (NET_1_1)
+		public Evidence Evidence {
+			get {
+				return evidence;
+			}
+			set {
+				evidence = value;
+			}
+		}
+		#endif
+
+		public bool GenerateExecutable {
 			get {
-				return generateExecutables;
+				return generateExecutable;
 			}
 			set {
-				generateExecutables = value;
+				generateExecutable = value;
 			}
 		}
 
@@ -157,13 +174,13 @@ namespace System.CodeDom.Compiler
 			}
 		}
 		
-		public string Win32Resources {
+		public string Win32Resource {
 			get {
-				return win32Resources;
+				return win32Resource;
 			}
 			set {
-				win32Resources = value;
+				win32Resource = value;
 			}
 		}
 	}
-};
+}

+ 25 - 8
mcs/class/System/System.CodeDom.Compiler/CompilerResults.cs

@@ -1,12 +1,15 @@
 //
-// System.CodeDom.Compiler CompilerResults Class implementation
+// System.CodeDom.Compiler.CompilerResults.cs
 //
-// Author:
+// Authors:
 //   Daniel Stodden ([email protected])
+//   Andreas Nahr ([email protected])
 //
 // (C) 2002 Ximian, Inc.
 //
 
+using System.Security.Policy;
+
 namespace System.CodeDom.Compiler
 {
 	using System.Reflection;
@@ -15,16 +18,19 @@ namespace System.CodeDom.Compiler
 	public class CompilerResults
 	{
 		private Assembly compiledAssembly;
-		private CompilerErrorCollection errors;
-		private int nativeCompilerReturnValue;
-		private StringCollection output;
+		private CompilerErrorCollection errors = new CompilerErrorCollection ();
+		#if (NET_1_1)
+			private Evidence evidence;
+		#endif
+		private int nativeCompilerReturnValue = 0;
+		private StringCollection output = new StringCollection ();
 		private string pathToAssembly;
 		private TempFileCollection tempFiles;
 		
 		//
 		// Constructors
 		//
-		public CompilerResults( TempFileCollection tempFiles )
+		public CompilerResults (TempFileCollection tempFiles)
 		{
 			this.tempFiles = tempFiles;
 		}
@@ -43,12 +49,23 @@ namespace System.CodeDom.Compiler
 
 		public CompilerErrorCollection Errors {
 			get {
-				if ( errors == null )
+				if (errors == null)
 					errors = new CompilerErrorCollection();
 				return errors;
 			}
 		}
 
+		#if (NET_1_1)
+		public Evidence Evidence {
+			get {
+				return evidence;
+			}
+			set {
+				evidence = value;
+			}
+		}
+		#endif
+
 		public int NativeCompilerReturnValue {
 			get {
 				return nativeCompilerReturnValue;
@@ -60,7 +77,7 @@ namespace System.CodeDom.Compiler
 
 		public StringCollection Output {
 			get {
-				if ( output == null )
+				if (output == null)
 					output = new StringCollection();
 				return output;
 			}

+ 49 - 0
mcs/class/System/System.CodeDom.Compiler/Executor.cs

@@ -0,0 +1,49 @@
+//
+// System.CodeDom.Compiler.Executor.cs
+//
+// Author(s):
+//   Andreas Nahr ([email protected])
+//
+// (C) 2003 Andreas Nahr
+//
+
+using System;
+using System.IO;
+
+namespace System.CodeDom.Compiler
+{
+
+	public abstract class Executor
+	{
+
+		private Executor ()
+		{
+		}
+
+		public static void ExecWait (string cmd, TempFileCollection tempFiles)
+		{
+			ExecWaitWithCapture (IntPtr.Zero, cmd, Environment.CurrentDirectory, tempFiles, string.Empty, string.Empty);
+		}
+
+		[MonoTODO]
+		public static Int32 ExecWaitWithCapture (IntPtr userToken, string cmd, string currentDir, TempFileCollection tempFiles, string outputName, string errorName)
+		{
+			throw new NotImplementedException();
+		}
+
+		public static Int32 ExecWaitWithCapture (IntPtr userToken, string cmd, TempFileCollection tempFiles, string outputName, string errorName)
+		{
+			return ExecWaitWithCapture (userToken, cmd, Environment.CurrentDirectory, tempFiles, outputName, errorName);
+		}
+
+		public static Int32 ExecWaitWithCapture (string cmd, string currentDir, TempFileCollection tempFiles, string outputName, string errorName )
+		{
+			return ExecWaitWithCapture (IntPtr.Zero, cmd, currentDir, tempFiles, outputName, errorName);
+		}
+
+		public static Int32 ExecWaitWithCapture (string cmd, TempFileCollection tempFiles, string outputName, string errorName)
+		{
+			return ExecWaitWithCapture (IntPtr.Zero, cmd, Environment.CurrentDirectory, tempFiles, outputName, errorName);
+		}
+	}
+}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.