dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/compat CSharpCompiler.cs,1.1,1.2 com


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/compat CSharpCompiler.cs,1.1,1.2 compat.build,1.1,1.2
Date: Sun, 08 Dec 2002 20:04:03 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/compat
In directory subversions:/tmp/cvs-serv4624/compat

Modified Files:
        CSharpCompiler.cs compat.build 
Log Message:


Implement "cscompmgd" in terms of the definitions in "System.CodeDom.Compiler".


Index: CSharpCompiler.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/compat/CSharpCompiler.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CSharpCompiler.cs   9 Dec 2002 00:17:54 -0000       1.1
--- CSharpCompiler.cs   9 Dec 2002 01:04:01 -0000       1.2
***************
*** 25,28 ****
--- 25,29 ----
  using System.Text;
  using System.Collections;
+ using System.CodeDom.Compiler;
  
  // Level of error that caused a message.
***************
*** 97,102 ****
                                 String target, String[] imports, IDictionary 
options)
                        {
!                               // TODO: wrap this around 
"System.CodeDom.Compiler".
                                throw new NotImplementedException();
                        }
  
--- 98,257 ----
                                 String target, String[] imports, IDictionary 
options)
                        {
!                               // Validate the parameters.
!                               if(sourceTexts == null)
!                               {
!                                       throw new 
ArgumentNullException("sourceTexts");
!                               }
!                               if(sourceTextNames == null)
!                               {
!                                       throw new 
ArgumentNullException("sourceTextNames");
!                               }
!                               if(target == null)
!                               {
!                                       throw new 
ArgumentNullException("target");
!                               }
!                               if(sourceTexts.Length == 0)
!                               {
!                                       throw new 
ArgumentOutOfRangeException("sourceTexts");
!                               }
!                               if(sourceTexts.Length != sourceTextNames.Length)
!                               {
!                                       throw new 
ArgumentOutOfRangeException("sourceTextNames");
!                               }
! 
! #if !ECMA_COMPAT
!                               // Build the compiler parameter block.
!                               CompilerParameters paramBlock;
!                               paramBlock = new CompilerParameters
!                                       (imports, target, OptionSet(options, 
"debug"));
!                               int len = target.Length;
!                               if(len > 4 && target[len - 4] == '.' &&
!                                  (target[len - 3] == 'd' || target[len - 3] 
== 'D') &&
!                                  (target[len - 2] == 'l' || target[len - 2] 
== 'L') &&
!                                  (target[len - 1] == 'l' || target[len - 1] 
== 'L'))
!                               {
!                                       paramBlock.GenerateExecutable = false;
!                               }
!                               else
!                               {
!                                       paramBlock.GenerateExecutable = true;
!                               }
!                               if(OptionSet(options, "warnaserror"))
!                               {
!                                       paramBlock.TreatWarningsAsErrors = true;
!                               }
!                               StringBuilder opts = new StringBuilder();
!                               if(OptionSet(options, "o"))
!                               {
!                                       opts.Append(" /optimize");
!                               }
!                               if(OptionSet(options, "checked"))
!                               {
!                                       opts.Append(" /checked");
!                               }
!                               String opt = (String)(options["d"]);
!                               if(opt != null)
!                               {
!                                       opts.AppendFormat(" /define:{0}", opt);
!                               }
!                               opt = (String)(options["m"]);
!                               if(opt != null)
!                               {
!                                       opts.AppendFormat(" /m:{0}", opt);
!                               }
!                               if(OptionSet(options, "nostdlib"))
!                               {
!                                       opts.Append(" /nostdlib");
!                               }
!                               opt = (String)(options["res"]);
!                               if(opt != null)
!                               {
!                                       opts.AppendFormat(" /resource:{0}", 
opt);
!                               }
!                               opt = (String)(options["target"]);
!                               if(opt != null)
!                               {
!                                       paramBlock.GenerateExecutable = (opt != 
"library");
!                               }
!                               if(OptionSet(options, "unsafe"))
!                               {
!                                       opts.Append(" /unsafe");
!                               }
!                               paramBlock.CompilerOptions = opts.ToString();
! 
!                               // Build a new set of source texts, with the 
filename
!                               // information from "sourceTextNames" prepended.
!                               String[] sources = new String 
[sourceTexts.Length];
!                               int posn;
!                               for(posn = 0; posn < sourceTexts.Length; ++posn)
!                               {
!                                       if(sourceTextNames[posn] == null)
!                                       {
!                                               sources[posn] = 
sourceTexts[posn];
!                                       }
!                                       else
!                                       {
!                                               sources[posn] = "#line 1 \"" + 
sourceTextNames[posn] +
!                                                                               
"\"" + Environment.NewLine +
!                                                                               
sourceTexts[posn];
!                                       }
!                               }
! 
!                               // Compile the source texts.
!                               ICodeCompiler compiler =
!                                       (new 
CSharpCodeProvider()).CreateCompiler();
!                               CompilerResults results =
!                                       compiler.CompileAssemblyFromSourceBatch
!                                               (paramBlock, sources);
! 
!                               // Convert the errors into the correct format 
and return them.
!                               CompilerErrorCollection errors = results.Errors;
!                               CompilerError[] newErrors = new CompilerError 
[errors.Count];
!                               posn = 0;
!                               foreach(System.CodeDom.Compiler.CompilerError 
error in errors)
!                               {
!                                       newErrors[posn] = new CompilerError();
!                                       newErrors[posn].ErrorLevel =
!                                               (error.IsWarning ? 
ErrorLevel.Warning
!                                                                               
 : ErrorLevel.Error);
!                                       newErrors[posn].ErrorMessage = 
error.ErrorText;
!                                       if(error.ErrorNumber != null &&
!                                          error.ErrorNumber.StartsWith("CS"))
!                                       {
!                                               newErrors[posn].ErrorNumber =
!                                                       
Int32.Parse(error.ErrorNumber.Substring(2));
!                                       }
!                                       newErrors[posn].SourceColumn = 
error.Column;
!                                       newErrors[posn].SourceFile = 
error.FileName;
!                                       newErrors[posn].SourceLine = error.Line;
!                                       ++posn;
!                               }
!                               return newErrors;
! #else
!                               // We don't have the necessary API's in 
ECMA-compat mode.
                                throw new NotImplementedException();
+ #endif
+                       }
+ 
+       // Determine if a boolean option is set.
+       private static bool OptionSet(IDictionary options, String name)
+                       {
+                               Object obj = options[name];
+                               if(obj != null)
+                               {
+                                       if(obj is Boolean)
+                                       {
+                                               return (bool)obj;
+                                       }
+                                       else if(obj is String)
+                                       {
+                                               String str = (String)obj;
+                                               if(str == "true" || str == "1" 
|| str == "+")
+                                               {
+                                                       return true;
+                                               }
+                                       }
+                               }
+                               return false;
                        }
  

Index: compat.build
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/compat/compat.build,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** compat.build        9 Dec 2002 00:17:54 -0000       1.1
--- compat.build        9 Dec 2002 01:04:01 -0000       1.2
***************
*** 40,43 ****
--- 40,44 ----
  
                        <references>
+                               <file name="../System/System.dll"/>
                                <file name="../runtime/mscorlib.dll"/>
                        </references>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]