[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodeCom
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodeCompiler.cs, 1.5, 1.6 CodeCompiler.cs, 1.4, 1.5 CodeGenerator.cs, 1.6, 1.7 TempFileCollection.cs, 1.3, 1.4 VBCodeCompiler.cs, 1.2, 1.3 |
Date: |
Tue, 02 Sep 2003 02:50:14 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler
In directory subversions:/tmp/cvs-serv32563/System/CodeDom/Compiler
Modified Files:
CSharpCodeCompiler.cs CodeCompiler.cs CodeGenerator.cs
TempFileCollection.cs VBCodeCompiler.cs
Log Message:
Continue the implementation of "System.CodeDom.Compiler".
Index: CSharpCodeCompiler.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CSharpCodeCompiler.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** CSharpCodeCompiler.cs 25 Jul 2003 07:48:11 -0000 1.5
--- CSharpCodeCompiler.cs 2 Sep 2003 06:50:11 -0000 1.6
***************
*** 258,262 ****
(CompilerResults results, String line)
{
! // TODO
}
--- 258,266 ----
(CompilerResults results, String line)
{
! CompilerError error =
ProcessCompilerOutputLine(line);
! if(error != null)
! {
! results.Errors.Add(error);
! }
}
***************
*** 729,757 ****
(CodeConstructor e, CodeTypeDeclaration c)
{
! // TODO
}
protected override void GenerateEntryPointMethod
(CodeEntryPointMethod e, CodeTypeDeclaration c)
{
! // TODO
}
protected override void GenerateEvent
(CodeMemberEvent e, CodeTypeDeclaration c)
{
! // TODO
}
protected override void GenerateField(CodeMemberField e)
{
! // TODO
}
protected override void GenerateMethod
(CodeMemberMethod e, CodeTypeDeclaration c)
{
! // TODO
}
protected override void GenerateProperty
(CodeMemberProperty e, CodeTypeDeclaration c)
{
! // TODO
}
protected override void GenerateNamespaceStart(CodeNamespace e)
--- 733,982 ----
(CodeConstructor e, CodeTypeDeclaration c)
{
! // Bail out if not a class or struct.
! if(!IsCurrentClass && !IsCurrentStruct)
! {
! return;
! }
!
! // Output the attributes and constructor
signature.
! OutputAttributeDeclarations(e.CustomAttributes);
! OutputMemberAccessModifier(e.Attributes);
! OutputIdentifier(CurrentTypeName);
! Output.Write("(");
! OutputParameters(e.Parameters);
! Output.Write(")");
!
! // Output the ": base" or ": this" expressions.
! if(e.BaseConstructorArgs.Count > 0)
! {
! Output.WriteLine(" : ");
! Indent += 2;
! Output.Write("base(");
!
OutputExpressionList(e.BaseConstructorArgs);
! Output.Write(")");
! Indent -= 2;
! }
! if(e.ChainedConstructorArgs.Count > 0)
! {
! Output.WriteLine(" : ");
! Indent += 2;
! Output.Write("base(");
!
OutputExpressionList(e.ChainedConstructorArgs);
! Output.Write(")");
! Indent -= 2;
! }
!
! // Output the body of the constructor.
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
}
protected override void GenerateEntryPointMethod
(CodeEntryPointMethod e, CodeTypeDeclaration c)
{
! Output.Write("public static void Main()");
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
}
protected override void GenerateEvent
(CodeMemberEvent e, CodeTypeDeclaration c)
{
! // Bail out if not a class, struct, or
interface.
! if(!IsCurrentClass && !IsCurrentStruct &&
!IsCurrentInterface)
! {
! return;
! }
!
! // Output the event definition.
! OutputAttributeDeclarations(e.CustomAttributes);
! if(e.PrivateImplementationType == null)
! {
!
OutputMemberAccessModifier(e.Attributes);
! OutputMemberScopeModifier(e.Attributes);
! Output.Write("event ");
! OutputTypeNamePair(e.Type, e.Name);
! }
! else
! {
! Output.Write("event ");
! OutputTypeNamePair
! (e.Type,
e.PrivateImplementationType + "." + e.Name);
! }
! Output.WriteLine(";");
}
protected override void GenerateField(CodeMemberField e)
{
! // Bail out if not a class, struct, or enum.
! if(!IsCurrentClass && !IsCurrentStruct &&
!IsCurrentEnum)
! {
! return;
! }
!
! // Generate information about the field.
! if(!IsCurrentEnum)
! {
!
OutputAttributeDeclarations(e.CustomAttributes);
!
OutputMemberAccessModifier(e.Attributes);
! OutputMemberScopeModifier(e.Attributes);
! OutputTypeNamePair(e.Type, e.Name);
! if(e.InitExpression != null)
! {
! Output.Write(" = ");
!
GenerateExpression(e.InitExpression);
! }
! Output.WriteLine(";");
! }
! else
! {
!
OutputAttributeDeclarations(e.CustomAttributes);
! OutputIdentifier(e.Name);
! if(e.InitExpression != null)
! {
! Output.Write(" = ");
!
GenerateExpression(e.InitExpression);
! }
! Output.WriteLine(",");
! }
}
protected override void GenerateMethod
(CodeMemberMethod e, CodeTypeDeclaration c)
{
! // Bail out if not a class, struct, or
interface.
! if(!IsCurrentClass && !IsCurrentStruct &&
!IsCurrentInterface)
! {
! return;
! }
!
! // Output the attributes and method signature.
! OutputAttributeDeclarations(e.CustomAttributes);
! if(e.ReturnTypeCustomAttributes.Count > 0)
! {
! OutputAttributeDeclarations
! ("return: ",
e.ReturnTypeCustomAttributes);
! }
! if(!IsCurrentInterface)
! {
! if(e.PrivateImplementationType == null)
! {
!
OutputMemberAccessModifier(e.Attributes);
!
OutputMemberScopeModifier(e.Attributes);
! }
! }
! else if((e.Attributes &
MemberAttributes.VTableMask)
! == MemberAttributes.New)
! {
! Output.Write("new ");
! }
! if(e.ReturnType != null)
! {
! OutputType(e.ReturnType);
! }
! else
! {
! Output.Write("void");
! }
! Output.Write(" ");
! if(e.PrivateImplementationType != null &&
!IsCurrentInterface)
! {
!
Output.Write(e.PrivateImplementationType.BaseType);
! Output.Write(".");
! }
! OutputIdentifier(e.Name);
! Output.Write("(");
! OutputParameters(e.Parameters);
! Output.Write(")");
!
! // Output the body of the method.
! if(IsCurrentInterface ||
! (e.Attributes & MemberAttributes.ScopeMask)
==
! MemberAttributes.Abstract)
! {
! Output.WriteLine(";");
! }
! else
! {
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
! }
}
protected override void GenerateProperty
(CodeMemberProperty e, CodeTypeDeclaration c)
{
! // Bail out if not a class, struct, or
interface.
! if(!IsCurrentClass && !IsCurrentStruct &&
!IsCurrentInterface)
! {
! return;
! }
!
! // Output the attributes and property signature.
! OutputAttributeDeclarations(e.CustomAttributes);
! if(!IsCurrentInterface)
! {
! if(e.PrivateImplementationType == null)
! {
!
OutputMemberAccessModifier(e.Attributes);
!
OutputMemberScopeModifier(e.Attributes);
! }
! }
! else if((e.Attributes &
MemberAttributes.VTableMask)
! == MemberAttributes.New)
! {
! Output.Write("new ");
! }
! OutputType(e.Type);
! Output.Write(" ");
! if(e.PrivateImplementationType != null &&
!IsCurrentInterface)
! {
!
Output.Write(e.PrivateImplementationType.BaseType);
! Output.Write(".");
! }
! if(e.Parameters.Count == 0)
! {
! OutputIdentifier(e.Name);
! }
! else
! {
! Output.Write("this[");
! OutputParameters(e.Parameters);
! Output.Write(")");
! }
!
! // Output the body of the property.
! StartBlock();
! if(e.HasGet)
! {
! if(IsCurrentInterface ||
! (e.Attributes &
MemberAttributes.ScopeMask)
! ==
MemberAttributes.Abstract)
! {
! Output.WriteLine("get;");
! }
! else
! {
! Output.Write("get");
! StartBlock();
!
GenerateStatements(e.GetStatements);
! EndBlock();
! }
! }
! if(e.HasSet)
! {
! if(IsCurrentInterface ||
! (e.Attributes &
MemberAttributes.ScopeMask)
! ==
MemberAttributes.Abstract)
! {
! Output.WriteLine("set;");
! }
! else
! {
! Output.Write("set");
! StartBlock();
!
GenerateStatements(e.SetStatements);
! EndBlock();
! }
! }
! EndBlock();
}
protected override void GenerateNamespaceStart(CodeNamespace e)
***************
*** 775,793 ****
protected override void GenerateNamespaceImport(CodeNamespaceImport e)
{
! // TODO
}
protected override void GenerateSnippetMember
(CodeSnippetTypeMember e)
{
! // TODO
}
protected override void GenerateTypeConstructor
(CodeTypeConstructor e)
{
! // TODO
}
protected override void GenerateTypeStart(CodeTypeDeclaration e)
{
! // TODO
}
protected override void GenerateTypeEnd(CodeTypeDeclaration e)
--- 1000,1065 ----
protected override void GenerateNamespaceImport(CodeNamespaceImport e)
{
! Output.Write("using ");
! OutputIdentifier(e.Namespace);
! Output.WriteLine(";");
}
protected override void GenerateSnippetMember
(CodeSnippetTypeMember e)
{
! Output.Write(e.Text);
}
protected override void GenerateTypeConstructor
(CodeTypeConstructor e)
{
! Output.Write("static ");
! OutputIdentifier(CurrentTypeName);
! Output.Write("()");
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
}
protected override void GenerateTypeStart(CodeTypeDeclaration e)
{
! OutputAttributeDeclarations(e.CustomAttributes);
! if(!IsCurrentDelegate)
! {
! OutputTypeAttributes
! (e.TypeAttributes,
IsCurrentStruct, IsCurrentEnum);
! OutputIdentifier(e.Name);
! String sep = " : ";
! foreach(CodeTypeReference type in
e.BaseTypes)
! {
! Output.Write(sep);
! OutputType(type);
! sep = ",";
! }
! StartBlock();
! }
! else
! {
! switch(e.TypeAttributes &
TypeAttributes.VisibilityMask)
! {
! case
TypeAttributes.NestedPrivate:
! Output.Write("private
"); break;
! case TypeAttributes.Public:
! case
TypeAttributes.NestedPublic:
! Output.Write("public
"); break;
! }
! Output.Write("delegate ");
! CodeTypeDelegate d =
(CodeTypeDelegate)e;
! if(d.ReturnType != null)
! {
! OutputType(d.ReturnType);
! }
! else
! {
! Output.Write("void");
! }
! Output.Write(" ");
! OutputIdentifier(d.Name);
! Output.Write("(");
! OutputParameters(d.Parameters);
! Output.WriteLine(");");
! }
}
protected override void GenerateTypeEnd(CodeTypeDeclaration e)
***************
*** 795,800 ****
if(!IsCurrentDelegate)
{
! --Indent;
! Output.WriteLine("}");
}
}
--- 1067,1071 ----
if(!IsCurrentDelegate)
{
! EndBlock();
}
}
Index: CodeCompiler.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CodeCompiler.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** CodeCompiler.cs 29 May 2003 01:22:39 -0000 1.4
--- CodeCompiler.cs 2 Sep 2003 06:50:11 -0000 1.5
***************
*** 191,194 ****
--- 191,371 ----
}
+ // Internal version of "ProcessCompilerOutputLine".
+ // The line may have one of the following forms:
+ //
+ // FILENAME(LINE,COLUMN): error CODE: message
+ // FILENAME(LINE,COLUMN): fatal error CODE: message
+ // FILENAME(LINE,COLUMN): warning CODE: message
+ // FILENAME:LINE: message
+ // FILENAME:LINE:COLUMN: message
+ // FILENAME:LINE: warning: message
+ // FILENAME:LINE:COLUMN: warning: message
+ //
+ internal static CompilerError ProcessCompilerOutputLine(String line)
+ {
+ CompilerError error;
+ int posn, start;
+
+ // Bail out if the line is empty.
+ if(line == null || line.Length == 0)
+ {
+ return null;
+ }
+
+ // Create the error block.
+ error = new CompilerError();
+
+ // Parse out the filename.
+ posn = 0;
+ if(line.Length >= 3 && Char.IsLetter(line[0]) &&
+ line[1] == ':' && (line[2] == '/' || line[2]
== '\\'))
+ {
+ // Filename starting with a Windows
drive specification.
+ posn += 3;
+ }
+ while(posn < line.Length && line[posn] != ':' &&
+ line[posn] != '(')
+ {
+ ++posn;
+ }
+ if(posn >= line.Length)
+ {
+ return null;
+ }
+ error.FileName = line.Substring(0, posn);
+
+ // Parse out the line and column numbers.
+ if(line[posn] == '(')
+ {
+ // (LINE,COLUMN) format.
+ ++posn;
+ start = posn;
+ while(posn < line.Length && line[posn]
!= ')' &&
+ line[posn] != ',')
+ {
+ ++posn;
+ }
+ error.Line = Int32.Parse
+ (line.Substring(start, posn -
start));
+ if(posn < line.Length && line[posn] ==
',')
+ {
+ ++posn;
+ start = posn;
+ while(posn < line.Length &&
line[posn] != ')' &&
+ line[posn] != ',')
+ {
+ ++posn;
+ }
+ error.Column = Int32.Parse
+ (line.Substring(start,
posn - start));
+ }
+ while(posn < line.Length && line[posn]
!= ')')
+ {
+ ++posn;
+ }
+ if(posn < line.Length)
+ {
+ ++posn;
+ }
+ if(posn < line.Length && line[posn] ==
':')
+ {
+ ++posn;
+ }
+ }
+ else
+ {
+ // LINE:COLUMN format.
+ ++posn;
+ start = posn;
+ while(posn < line.Length && line[posn]
!= ':')
+ {
+ ++posn;
+ }
+ error.Line = Int32.Parse
+ (line.Substring(start, posn -
start));
+ if(posn < line.Length && line[posn + 1]
!= ' ')
+ {
+ ++posn;
+ start = posn;
+ while(posn < line.Length &&
line[posn] != ':')
+ {
+ ++posn;
+ }
+ error.Column = Int32.Parse
+ (line.Substring(start,
posn - start));
+ }
+ if(posn < line.Length)
+ {
+ ++posn;
+ }
+ }
+
+ // Skip white space.
+ while(posn < line.Length && line[posn] == ' ')
+ {
+ ++posn;
+ }
+
+ // Parse the error type.
+ bool needCode = true;
+ if((line.Length - posn) >= 6 &&
+ String.CompareOrdinal("error ", 0, line,
posn, 6) == 0)
+ {
+ posn += 6;
+ }
+ else if((line.Length - posn) >= 12 &&
+ String.CompareOrdinal
+ ("fatal error ", 0,
line, posn, 12) == 0)
+ {
+ posn += 12;
+ }
+ else if((line.Length - posn) >= 8 &&
+ String.CompareOrdinal
+ ("warning ", 0, line,
posn, 8) == 0)
+ {
+ error.IsWarning = true;
+ posn += 8;
+ }
+ else if((line.Length - posn) >= 8 &&
+ String.CompareOrdinal
+ ("warning:", 0, line,
posn, 8) == 0)
+ {
+ error.IsWarning = true;
+ posn += 8;
+ needCode = false;
+ }
+ else
+ {
+ needCode = false;
+ }
+
+ // Parse the error code.
+ if(needCode)
+ {
+ start = posn;
+ while(posn < line.Length && line[posn]
!= ':')
+ {
+ ++posn;
+ }
+ error.ErrorNumber =
line.Substring(posn, posn - start);
+ if(posn < line.Length)
+ {
+ ++posn;
+ }
+ }
+
+ // Skip white space.
+ while(posn < line.Length && line[posn] == ' ')
+ {
+ ++posn;
+ }
+
+ // Extract the error text.
+ error.ErrorText = line.Substring(posn);
+
+ // Return the error block to the caller.
+ return error;
+ }
+
// Process an output line from the compiler.
protected abstract void ProcessCompilerOutputLine
Index: CodeGenerator.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CodeGenerator.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** CodeGenerator.cs 25 Jul 2003 07:48:11 -0000 1.6
--- CodeGenerator.cs 2 Sep 2003 06:50:11 -0000 1.7
***************
*** 778,781 ****
--- 778,785 ----
protected void GenerateStatements(CodeStatementCollection e)
{
+ if(e == null)
+ {
+ return;
+ }
foreach(CodeStatement stmt in e)
{
***************
*** 973,976 ****
--- 977,985 ----
(CodeAttributeDeclarationCollection attributes)
{
+ OutputAttributeDeclarations(null, attributes);
+ }
+ internal void OutputAttributeDeclarations
+ (String prefix,
CodeAttributeDeclarationCollection attributes)
+ {
if(attributes.Count == 0)
{
***************
*** 990,993 ****
--- 999,1006 ----
{
first = false;
+ }
+ if(prefix != null)
+ {
+ Output.Write(prefix);
}
Output.Write(attr.Name);
Index: TempFileCollection.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/TempFileCollection.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** TempFileCollection.cs 29 May 2003 01:22:39 -0000 1.3
--- TempFileCollection.cs 2 Sep 2003 06:50:11 -0000 1.4
***************
*** 25,29 ****
--- 25,31 ----
#if CONFIG_CODEDOM
+ using System.IO;
using System.Collections;
+ using System.Security.Cryptography;
public class TempFileCollection : ICollection, IEnumerable, IDisposable
***************
*** 31,34 ****
--- 33,37 ----
// Internal state.
private String tempDir;
+ private String basePath;
private bool keepFiles;
private Hashtable files;
***************
*** 40,43 ****
--- 43,47 ----
{
this.tempDir = tempDir;
+ this.basePath = null;
this.keepFiles = keepFiles;
this.files = new Hashtable();
***************
*** 57,67 ****
// Properties.
- [TODO]
public String BasePath
{
get
{
! // TODO
! return null;
}
}
--- 61,91 ----
// Properties.
public String BasePath
{
get
{
! // Bail out early if we already have a
base path.
! if(basePath != null)
! {
! return basePath;
! }
!
! // Get the temporary directory to be
used.
! if(tempDir == null || tempDir.Length ==
0)
! {
! tempDir = Path.GetTempPath();
! }
!
! // Create a random name in the
temporary directory.
! RandomNumberGenerator rng =
RandomNumberGenerator.Create();
! byte[] data = new byte [6];
! rng.GetBytes(data);
! String name =
Convert.ToBase64String(data);
! name = name.Replace('/', '-');
! name = "tmp" + name.Replace('+', '_');
!
! // Construct the full temporary file
base name.
! basePath = Path.Combine(tempDir, name);
! return basePath;
}
}
***************
*** 136,139 ****
--- 160,164 ----
{
Dispose(true);
+ GC.SuppressFinalize(this);
}
***************
*** 143,158 ****
return AddExtension(fileExtension, keepFiles);
}
- [TODO]
public String AddExtension(String fileExtension, bool keepFile)
{
! // TODO
! return null;
}
// Add a file to this temporary file collection.
- [TODO]
public void AddFile(String fileName, bool keepFile)
{
! // TODO
}
--- 168,197 ----
return AddExtension(fileExtension, keepFiles);
}
public String AddExtension(String fileExtension, bool keepFile)
{
! if(fileExtension == null ||
fileExtension.Length == 0)
! {
! throw new ArgumentException
!
(S._("ArgRange_StringNonEmpty"), "fileExtension");
! }
! String filename = BasePath + "." +
fileExtension;
! AddFile(filename, keepFile);
! return filename;
}
// Add a file to this temporary file collection.
public void AddFile(String fileName, bool keepFile)
{
! if(fileName == null || fileName.Length == 0)
! {
! throw new ArgumentException
!
(S._("ArgRange_StringNonEmpty"), "fileName");
! }
! if(files.Contains(fileName))
! {
! throw new ArgumentException
!
(S._("Arg_DuplicateTempFilename"), "fileName");
! }
! files.Add(fileName, keepFile);
}
***************
*** 164,171 ****
// Delete the temporary files in this collection.
- [TODO]
public void Delete()
{
! // TODO
}
--- 203,224 ----
// Delete the temporary files in this collection.
public void Delete()
{
! IDictionaryEnumerator e = files.GetEnumerator();
! while(e.MoveNext())
! {
! if(!((bool)(e.Value)))
! {
! try
! {
!
File.Delete((String)(e.Key));
! }
! catch
! {
! // Ignore exceptions
when deleting files.
! }
! }
! }
! files.Clear();
}
Index: VBCodeCompiler.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/VBCodeCompiler.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** VBCodeCompiler.cs 29 May 2003 01:22:39 -0000 1.2
--- VBCodeCompiler.cs 2 Sep 2003 06:50:11 -0000 1.3
***************
*** 99,103 ****
(CompilerResults results, String line)
{
! // TODO
}
--- 99,107 ----
(CompilerResults results, String line)
{
! CompilerError error =
ProcessCompilerOutputLine(line);
! if(error != null)
! {
! results.Errors.Add(error);
! }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodeCompiler.cs, 1.5, 1.6 CodeCompiler.cs, 1.4, 1.5 CodeGenerator.cs, 1.6, 1.7 TempFileCollection.cs, 1.3, 1.4 VBCodeCompiler.cs, 1.2, 1.3,
Rhys Weatherley <address@hidden> <=