[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodePro
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodeProvider.cs,NONE,1.1 CodeDomProvider.cs,NONE,1.1 CSharpCodeCompiler.cs,1.1,1.2 CodeCompiler.cs,1.1,1.2 CodeGenerator.cs,1.1,1.2 CompilerError.cs,1.1,1.2 |
Date: |
Sat, 16 Nov 2002 02:17:21 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler
In directory subversions:/tmp/cvs-serv23214/System/CodeDom/Compiler
Modified Files:
CSharpCodeCompiler.cs CodeCompiler.cs CodeGenerator.cs
CompilerError.cs
Added Files:
CSharpCodeProvider.cs CodeDomProvider.cs
Log Message:
Implement more of the C# code generation routines in "System.CodeDom.Compiler".
--- NEW FILE ---
/*
* CSharpCodeProvider.cs - Implementation of the
* Microsoft.CSharp.CSharpCodeProvider class.
*
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// This class should probably be in "System.CodeDom.Compiler",
// but Microsoft put it in "Microsoft.CSharp". We put it there
// also for compatibility sake.
namespace Microsoft.CSharp
{
#if !ECMA_COMPAT
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.ComponentModel;
public class CSharpCodeProvider : CodeDomProvider
{
// Internal state.
private CSharpCodeCompiler csharpCodeCompiler;
// Constructor.
public CSharpCodeProvider()
{
csharpCodeCompiler = new CSharpCodeCompiler();
}
// Get the file extension that is used by this provider.
public override String FileExtension
{
get
{
return "cs";
}
}
// Create a code compiler for this language.
public override ICodeCompiler CreateCompiler()
{
return csharpCodeCompiler;
}
// Create a code generator for this language.
public override ICodeGenerator CreateGenerator()
{
return csharpCodeCompiler;
}
}; // class CSharpCodeProvider
#endif // !ECMA_COMPAT
}; // namespace Microsoft.CSharp
--- NEW FILE ---
/*
* CodeDomProvider.cs - Implementation of the
* System.CodeDom.Compiler.CodeDomProvider class.
*
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.CodeDom.Compiler
{
#if !ECMA_COMPAT
using System.IO;
using System.ComponentModel;
/*[ToolboxItem(true)] -- TODO */
public abstract class CodeDomProvider /* : Component -- TODO */
{
// Constructor.
protected CodeDomProvider() {}
// Get the file extension that is used by this provider.
public virtual String FileExtension
{
get
{
return String.Empty;
}
}
// Get the language options that are supported by this provider.
public virtual LanguageOptions LanguageOptions
{
get
{
return LanguageOptions.None;
}
}
// Create a code compiler for this language.
public abstract ICodeCompiler CreateCompiler();
// Create a code generator for this language.
public abstract ICodeGenerator CreateGenerator();
public virtual ICodeGenerator CreateGenerator(String fileName)
{
return CreateGenerator();
}
public virtual ICodeGenerator CreateGenerator(TextWriter output)
{
return CreateGenerator();
}
// Create a code parser for this language.
public virtual ICodeParser CreateParser()
{
return null;
}
}; // class CodeDomProvider
#endif // !ECMA_COMPAT
}; // namespace System.CodeDom.Compiler
Index: CSharpCodeCompiler.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CSharpCodeCompiler.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CSharpCodeCompiler.cs 15 Nov 2002 13:06:45 -0000 1.1
--- CSharpCodeCompiler.cs 16 Nov 2002 07:17:17 -0000 1.2
***************
*** 32,37 ****
{
// Constructor.
! public CSharpCodeCompiler() : base() {}
// Get the name of the compiler.
--- 32,63 ----
{
+ // List of reserved words in C#.
+ private static readonly String[] reservedWords = {
+ "abstract", "__arglist", "as", "base", "bool",
+ "break", "__builtin", "byte", "case", "catch",
+ "char", "checked", "class", "const", "continue",
+ "decimal", "default", "delegate", "do",
"double",
+ "else", "enum", "event", "explicit", "extern",
+ "false", "finally", "fixed", "float", "for",
+ "foreach", "goto", "if", "implicit", "in",
"int",
+ "interface", "internal", "is", "lock", "long",
+ "__long_double", "__makeref", "__module",
"namespace",
+ "new", "null", "object", "operator", "out",
"override",
+ "params", "private", "protected", "public",
"readonly",
+ "ref", "__reftype", "__refvalue", "return",
"sbyte",
+ "sealed", "short", "sizeof", "stackalloc",
"static",
+ "string", "struct", "switch", "this", "throw",
"true",
+ "try", "typeof", "uint", "ulong", "unchecked",
"unsafe",
+ "ushort", "using", "virtual", "void",
"volatile", "while"
+ };
+
+ // Internal state.
+ private bool outputForInit;
+
// Constructor.
! public CSharpCodeCompiler() : base()
! {
! outputForInit = false;
! }
// Get the name of the compiler.
***************
*** 62,71 ****
}
// Convert compiler parameters into compiler arguments.
protected override String CmdArgsFromParameters
(CompilerParameters options)
{
! // TODO
! return null;
}
--- 88,245 ----
}
+ // Add an argument to an argument array.
+ private static void AddArgument(ref String[] args, String arg)
+ {
+ String[] newArgs = new String [args.Length + 1];
+ Array.Copy(args, newArgs, args.Length);
+ newArgs[args.Length] = arg;
+ }
+
+ // Build a list of arguments from an option string. The arguments
+ // are assumed to use the "csc" syntax, which we will convert into
+ // the "cscc" syntax within "CmdArgsFromParameters".
+ private static String[] ArgsFromOptions(String options)
+ {
+ String[] args = new String [0];
+ // TODO
+ return args;
+ }
+
+ // Determine if a string looks like a "csc" option.
+ private static bool IsOption(String opt, String name)
+ {
+ return (String.Compare(opt, name, true,
+
CultureInfo.InvariantCulture) == 0);
+ }
+
+ // Add a list of "csc" defines to a "cscc" command-line.
+ private static void AddDefines(ref String[] args, String defines)
+ {
+ if(defines != String.Empty)
+ {
+ String[] defs = defines.Split(',', ';');
+ foreach(String def in defs)
+ {
+ AddArgument(ref args, "-D" +
def);
+ }
+ }
+ }
+
// Convert compiler parameters into compiler arguments.
protected override String CmdArgsFromParameters
(CompilerParameters options)
{
! String[] args = new String [0];
! int posn, posn2;
! if(options.OutputAssembly != null)
! {
! AddArgument(ref args, "-o");
! AddArgument(ref args,
options.OutputAssembly);
! }
! if(options.IncludeDebugInformation)
! {
! AddArgument(ref args, "-g");
! }
! if(!(options.GenerateExecutable))
! {
! AddArgument(ref args, "-shared");
! }
! if(options.TreatWarningsAsErrors)
! {
! AddArgument(ref args, "-Werror");
! }
! if(options.WarningLevel >= 0)
! {
! AddArgument(ref args, "-Wall");
! }
! if(options.MainClass != null)
! {
! AddArgument(ref args, "-e");
! AddArgument(ref args,
options.MainClass);
! }
! foreach(String _refAssem in
options.ReferencedAssemblies)
! {
! // Strip ".dll" from the end of the
assembly name.
! String refAssem = _refAssem;
! if(refAssem.Length > 4 &&
! String.Compare(refAssem,
refAssem.Length - 4,
!
".dll", 0, 4, true,
!
CultureInfo.InvariantCulture) == 0)
! {
! refAssem =
refAssem.Substring(0, refAssem.Length - 4);
! }
!
! // Split the assembly into its path and
base name.
! posn = refAssem.LastIndexOf('/');
! posn2 = refAssem.LastIndexOf('\\');
! if(posn2 > posn)
! {
! posn = posn2;
! }
! if(posn != -1)
! {
! // Add "-L" and "-l" options to
the command-line.
! AddArgument(ref args,
! "-L" +
refAssem.Substring(0, posn));
! AddArgument(ref args,
! "-l" +
refAssem.Substring(posn + 1));
! }
! else
! {
! // Add just a "-l" option to
the command-line.
! AddArgument(ref args, "-l" +
refAssem);
! }
! }
! if(options.Win32Resource != null)
! {
! AddArgument(ref args,
! "-fresources=" +
options.Win32Resource);
! }
! if(options.CompilerOptions != null)
! {
! String[] cscArgs =
ArgsFromOptions(options.CompilerOptions);
! foreach(String opt in cscArgs)
! {
! if(IsOption(opt, "/optimize") ||
! IsOption(opt, "/optimize+")
||
! IsOption(opt, "/o") ||
! IsOption(opt, "/o+"))
! {
! AddArgument(ref args,
"-O2");
! }
! else if(IsOption(opt,
"/checked") ||
! IsOption(opt,
"/checked+"))
! {
! AddArgument(ref args,
"-fchecked");
! }
! else if(IsOption(opt,
"/checked-"))
! {
! AddArgument(ref args,
"-funchecked");
! }
! else if(IsOption(opt,
"/unsafe") ||
! IsOption(opt,
"/unsafe+"))
! {
! AddArgument(ref args,
"-funsafe");
! }
! else if(IsOption(opt,
"/nostdlib") ||
! IsOption(opt,
"/nostdlib+"))
! {
! AddArgument(ref args,
"-fnostdlib");
! }
! else if(String.Compare(opt, 0,
"/define:", 0, 8, true,
!
CultureInfo.InvariantCulture)
! == 0)
! {
! AddDefines(ref args,
opt.Substring(8));
! }
! else if(String.Compare(opt, 0,
"/d:", 0, 3, true,
!
CultureInfo.InvariantCulture)
! == 0)
! {
! AddDefines(ref args,
opt.Substring(3));
! }
! }
! }
! return JoinStringArray(args, " ");
}
***************
*** 89,94 ****
protected override String CreateEscapedIdentifier(String value)
{
! // TODO
! return value;
}
--- 263,274 ----
protected override String CreateEscapedIdentifier(String value)
{
! if(Array.IndexOf(reservedWords, value) != -1)
! {
! return "@" + value;
! }
! else
! {
! return value;
! }
}
***************
*** 96,101 ****
protected override String CreateValidIdentifier(String value)
{
! // TODO
! return value;
}
--- 276,310 ----
protected override String CreateValidIdentifier(String value)
{
! if(Array.IndexOf(reservedWords, value) != -1)
! {
! return "_" + value;
! }
! else
! {
! return value;
! }
! }
!
! // Normalize a type name to its keyword form.
! private String NormalizeTypeName(String type)
! {
! switch(type)
! {
! case "System.Void": type =
"void"; break;
! case "System.Byte": type =
"byte"; break;
! case "System.SByte": type = "sbyte";
break;
! case "System.Int16": type = "short";
break;
! case "System.UInt16": type =
"ushort"; break;
! case "System.Int32": type = "int";
break;
! case "System.UInt32": type = "uint";
break;
! case "System.Int64": type = "long";
break;
! case "System.UInt64": type = "ulong";
break;
! case "System.Single": type = "float";
break;
! case "System.Double": type =
"double"; break;
! case "System.Decimal": type =
"decimal"; break;
! case "System.String": type =
"string"; break;
! default:
break;
! }
! return type;
}
***************
*** 104,173 ****
(CodeArgumentReferenceExpression e)
{
! // TODO
}
protected override void GenerateArrayCreateExpression
(CodeArrayCreateExpression e)
{
! // TODO
}
protected override void GenerateArrayIndexerExpression
(CodeArrayIndexerExpression e)
{
! // TODO
}
protected override void GenerateBaseReferenceExpression
(CodeBaseReferenceExpression e)
{
! // TODO
}
protected override void GenerateCastExpression
(CodeCastExpression e)
{
! // TODO
}
protected override void GenerateDelegateCreateExpression
(CodeDelegateCreateExpression e)
{
! // TODO
}
protected override void GenerateDelegateInvokeExpression
(CodeDelegateInvokeExpression e)
{
! // TODO
! }
! protected override void GenerateDirectionExpression
! (CodeDirectionExpression e)
! {
! // TODO
}
protected override void GenerateEventReferenceExpression
(CodeEventReferenceExpression e)
{
! // TODO
}
protected override void GenerateFieldReferenceExpression
(CodeFieldReferenceExpression e)
{
! // TODO
}
protected override void GenerateIndexerExpression
(CodeIndexerExpression e)
{
! // TODO
}
protected override void GenerateMethodInvokeExpression
(CodeMethodInvokeExpression e)
{
! // TODO
}
protected override void GenerateMethodReferenceExpression
(CodeMethodReferenceExpression e)
{
! // TODO
}
protected override void GenerateObjectCreateExpression
(CodeObjectCreateExpression e)
{
! // TODO
}
protected override void GenerateParameterDeclarationExpression
--- 313,455 ----
(CodeArgumentReferenceExpression e)
{
! OutputIdentifier(e.ParameterName);
}
protected override void GenerateArrayCreateExpression
(CodeArrayCreateExpression e)
{
! Output.Write("new ");
! if(e.Initializers.Count == 0)
! {
!
Output.Write(NormalizeTypeName(e.CreateType.BaseType));
! Output.Write("[");
! if(e.SizeExpression != null)
! {
!
GenerateExpression(e.SizeExpression);
! }
! else
! {
! Output.Write(e.Size);
! }
! Output.Write("]");
! }
! else
! {
! OutputType(e.CreateType);
! if(e.CreateType.ArrayRank == 0)
! {
! Output.Write("[]");
! }
! Output.WriteLine(" {");
! Indent += 1;
! OutputExpressionList(e.Initializers,
true);
! Indent -= 1;
! Output.Write("}");
! }
}
protected override void GenerateArrayIndexerExpression
(CodeArrayIndexerExpression e)
{
! GenerateExpression(e.TargetObject);
! Output.Write("[");
! OutputExpressionList(e.Indices);
! Output.Write("]");
}
protected override void GenerateBaseReferenceExpression
(CodeBaseReferenceExpression e)
{
! Output.Write("base");
}
protected override void GenerateCastExpression
(CodeCastExpression e)
{
! // Heavily bracket the cast to prevent the
possibility
! // of ambiguity issues within the compiler.
See the
! // Portable.NET "cs_grammar.y" file for a
description of
! // the possible conflicts that may arise
without brackets.
! Output.Write("((");
! OutputType(e.TargetType);
! Output.Write(")(");
! GenerateExpression(e.Expression);
! Output.Write("))");
}
protected override void GenerateDelegateCreateExpression
(CodeDelegateCreateExpression e)
{
! Output.Write("new ");
! OutputType(e.DelegateType);
! Output.Write("(");
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! Output.Write(".");
! }
! OutputIdentifier(e.MethodName);
! Output.Write(")");
}
protected override void GenerateDelegateInvokeExpression
(CodeDelegateInvokeExpression e)
{
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! }
! Output.Write("(");
! OutputExpressionList(e.Parameters);
! Output.Write(")");
}
protected override void GenerateEventReferenceExpression
(CodeEventReferenceExpression e)
{
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! Output.Write(".");
! }
! OutputIdentifier(e.EventName);
}
protected override void GenerateFieldReferenceExpression
(CodeFieldReferenceExpression e)
{
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! Output.Write(".");
! }
! OutputIdentifier(e.FieldName);
}
protected override void GenerateIndexerExpression
(CodeIndexerExpression e)
{
! GenerateExpression(e.TargetObject);
! Output.Write("[");
! OutputExpressionList(e.Indices);
! Output.Write("]");
}
protected override void GenerateMethodInvokeExpression
(CodeMethodInvokeExpression e)
{
! GenerateMethodReferenceExpression(e.Method);
! Output.Write("(");
! OutputExpressionList(e.Parameters);
! Output.Write(")");
}
protected override void GenerateMethodReferenceExpression
(CodeMethodReferenceExpression e)
{
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! Output.Write(".");
! }
! OutputIdentifier(e.MethodName);
}
protected override void GenerateObjectCreateExpression
(CodeObjectCreateExpression e)
{
! Output.Write("new ");
! OutputType(e.CreateType);
! Output.Write("(");
! OutputExpressionList(e.Parameters);
! Output.Write(")");
}
protected override void GenerateParameterDeclarationExpression
***************
*** 179,203 ****
(CodePropertyReferenceExpression e)
{
! // TODO
}
protected override void GeneratePropertySetValueReferenceExpression
(CodePropertySetValueReferenceExpression e)
{
! // TODO
}
protected override void GenerateSnippetExpression
(CodeSnippetExpression e)
{
! // TODO
}
protected override void GenerateThisReferenceExpression
(CodeThisReferenceExpression e)
{
! // TODO
}
protected override void GenerateVariableReferenceExpression
(CodeVariableReferenceExpression e)
{
! // TODO
}
--- 461,504 ----
(CodePropertyReferenceExpression e)
{
! if(e.TargetObject != null)
! {
! GenerateExpression(e.TargetObject);
! Output.Write(".");
! }
! OutputIdentifier(e.PropertyName);
}
protected override void GeneratePropertySetValueReferenceExpression
(CodePropertySetValueReferenceExpression e)
{
! Output.Write("value");
}
protected override void GenerateSnippetExpression
(CodeSnippetExpression e)
{
! Output.Write(e.Value);
}
protected override void GenerateThisReferenceExpression
(CodeThisReferenceExpression e)
{
! Output.Write("this");
}
protected override void GenerateVariableReferenceExpression
(CodeVariableReferenceExpression e)
{
! OutputIdentifier(e.VariableName);
! }
!
! // Start a new indented block.
! private void StartBlock()
! {
! Output.WriteLine("{");
! Indent += 1;
! }
!
! // End an indented block.
! private void EndBlock()
! {
! Indent -= 1;
! Output.WriteLine("}");
}
***************
*** 206,265 ****
(CodeAssignStatement e)
{
! // TODO
}
protected override void GenerateAttachEventStatement
(CodeAttachEventStatement e)
{
! // TODO
}
protected override void GenerateConditionStatement
(CodeConditionStatement e)
{
! // TODO
}
protected override void GenerateExpressionStatement
(CodeExpressionStatement e)
{
! // TODO
}
protected override void GenerateGotoStatement
(CodeGotoStatement e)
{
! // TODO
}
protected override void GenerateIterationStatement
(CodeIterationStatement e)
{
! // TODO
}
protected override void GenerateLabeledStatement
(CodeLabeledStatement e)
{
! // TODO
}
protected override void GenerateMethodReturnStatement
(CodeMethodReturnStatement e)
{
! // TODO
}
protected override void GenerateRemoveEventStatement
(CodeRemoveEventStatement e)
{
! // TODO
}
protected override void GenerateThrowExceptionStatement
(CodeThrowExceptionStatement e)
{
! // TODO
}
protected override void GenerateTryCatchFinallyStatement
(CodeTryCatchFinallyStatement e)
{
! // TODO
}
protected override void GenerateVariableDeclarationStatement
(CodeVariableDeclarationStatement e)
{
! // TODO
}
--- 507,700 ----
(CodeAssignStatement e)
{
! GenerateExpression(e.Left);
! Output.Write(" = ");
! GenerateExpression(e.Right);
! if(!outputForInit)
! {
! Output.WriteLine(";");
! }
}
protected override void GenerateAttachEventStatement
(CodeAttachEventStatement e)
{
! GenerateExpression(e.Event);
! Output.Write(" += ");
! GenerateExpression(e.Listener);
! Output.WriteLine(";");
}
protected override void GenerateConditionStatement
(CodeConditionStatement e)
{
! Output.Write("if (");
! GenerateExpression(e.Condition);
! Output.WriteLine(")");
! StartBlock();
! GenerateStatements(e.TrueStatements);
! EndBlock();
! CodeStatementCollection stmts =
e.FalseStatements;
! if(stmts.Count > 0 || Options.ElseOnClosing)
! {
! Output.WriteLine("else");
! StartBlock();
! GenerateStatements(stmts);
! EndBlock();
! }
}
protected override void GenerateExpressionStatement
(CodeExpressionStatement e)
{
! GenerateExpression(e.Expression);
! if(!outputForInit)
! {
! Output.WriteLine(";");
! }
}
protected override void GenerateGotoStatement
(CodeGotoStatement e)
{
! Output.Write("goto ");
! Output.Write(e.Label);
! Output.WriteLine(";");
}
protected override void GenerateIterationStatement
(CodeIterationStatement e)
{
! if(e.InitStatement == null &&
! e.TestExpression != null &&
! e.IncrementStatement == null)
! {
! // Special case - output a "while"
statement.
! Output.Write("while (");
! GenerateExpression(e.TestExpression);
! Output.WriteLine(")");
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
! }
! else
! {
! // Output a "for" statement.
! Output.Write("for (");
! outputForInit = true;
! if(e.InitStatement != null)
! {
!
GenerateStatement(e.InitStatement);
! }
! Output.Write("; ");
! if(e.TestExpression != null)
! {
!
GenerateExpression(e.TestExpression);
! }
! Output.Write("; ");
! if(e.IncrementStatement != null)
! {
!
GenerateStatement(e.IncrementStatement);
! }
! outputForInit = false;
! Output.WriteLine(")");
! StartBlock();
! GenerateStatements(e.Statements);
! EndBlock();
! }
}
protected override void GenerateLabeledStatement
(CodeLabeledStatement e)
{
! Indent -= 1;
! Output.Write(e.Label);
! Output.WriteLine(":");
! Indent += 1;
! GenerateStatement(e.Statement);
}
protected override void GenerateMethodReturnStatement
(CodeMethodReturnStatement e)
{
! if(e.Expression != null)
! {
! Output.Write("return ");
! GenerateExpression(e.Expression);
! Output.WriteLine(";");
! }
! else
! {
! Output.WriteLine("return;");
! }
}
protected override void GenerateRemoveEventStatement
(CodeRemoveEventStatement e)
{
! GenerateExpression(e.Event);
! Output.Write(" -= ");
! GenerateExpression(e.Listener);
! Output.WriteLine(";");
}
protected override void GenerateThrowExceptionStatement
(CodeThrowExceptionStatement e)
{
! if(e.ToThrow != null)
! {
! Output.Write("throw ");
! GenerateExpression(e.ToThrow);
! Output.WriteLine(";");
! }
! else
! {
! Output.WriteLine("throw;");
! }
}
protected override void GenerateTryCatchFinallyStatement
(CodeTryCatchFinallyStatement e)
{
! Output.WriteLine("try");
! StartBlock();
! GenerateStatements(e.TryStatements);
! EndBlock();
! CodeCatchClauseCollection clauses =
e.CatchClauses;
! if(clauses.Count > 0)
! {
! foreach(CodeCatchClause clause in
clauses)
! {
! if(clause.CatchExceptionType !=
null)
! {
! Output.Write("catch (");
!
OutputType(clause.CatchExceptionType);
! if(clause.LocalName !=
null)
! {
! Output.Write("
");
!
OutputIdentifier(clause.LocalName);
! }
! Output.WriteLine(")");
! }
! else
! {
!
Output.WriteLine("catch");
! }
! StartBlock();
!
GenerateStatements(clause.Statements);
! EndBlock();
! }
! }
! CodeStatementCollection fin =
e.FinallyStatements;
! if(fin.Count > 0)
! {
! Output.WriteLine("finally");
! StartBlock();
! GenerateStatements(fin);
! EndBlock();
! }
}
protected override void GenerateVariableDeclarationStatement
(CodeVariableDeclarationStatement e)
{
! OutputTypeNamePair(e.Type, e.Name);
! if(e.InitExpression != null)
! {
! Output.Write(" = ");
! GenerateExpression(e.InitExpression);
! }
! if(!outputForInit)
! {
! Output.WriteLine(";");
! }
}
***************
*** 342,350 ****
protected override void GenerateLinePragmaStart(CodeLinePragma e)
{
! // TODO
}
protected override void GenerateLinePragmaEnd(CodeLinePragma e)
{
! // TODO
}
protected override String GetTypeOutput(CodeTypeReference value)
--- 777,788 ----
protected override void GenerateLinePragmaStart(CodeLinePragma e)
{
! Output.WriteLine();
! Output.WriteLine("#line {0} \"{1}\"",
! e.LineNumber,
e.FileName);
}
protected override void GenerateLinePragmaEnd(CodeLinePragma e)
{
! Output.WriteLine();
! Output.WriteLine("#line default");
}
protected override String GetTypeOutput(CodeTypeReference value)
***************
*** 364,368 ****
protected override void OutputType(CodeTypeReference typeRef)
{
! // TODO
}
--- 802,806 ----
protected override void OutputType(CodeTypeReference typeRef)
{
! Output.Write(GetTypeOutput(typeRef));
}
***************
*** 378,383 ****
protected override bool Supports(GeneratorSupport supports)
{
! // TODO
! return true;
}
--- 816,820 ----
protected override bool Supports(GeneratorSupport supports)
{
! return ((supports &
(GeneratorSupport)0x001FFFFF) == supports);
}
Index: CodeCompiler.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CodeCompiler.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CodeCompiler.cs 15 Nov 2002 13:06:45 -0000 1.1
--- CodeCompiler.cs 16 Nov 2002 07:17:17 -0000 1.2
***************
*** 28,31 ****
--- 28,32 ----
using System.Reflection;
using System.Globalization;
+ using System.Text;
public abstract class CodeCompiler : CodeGenerator, ICodeCompiler
***************
*** 38,43 ****
protected static String JoinStringArray(String[] sa, String separator)
{
! // TODO
! return null;
}
--- 39,59 ----
protected static String JoinStringArray(String[] sa, String separator)
{
! if(sa == null || sa.Length == 0)
! {
! return String.Empty;
! }
! StringBuilder sb = new StringBuilder();
! int posn;
! for(posn = 0; posn < sa.Length; ++posn)
! {
! if(posn > 0)
! {
! sb.Append(separator);
! }
! sb.Append('"');
! sb.Append(sa[posn]);
! sb.Append('"');
! }
! return sb.ToString();
}
***************
*** 56,61 ****
(CompilerParameters options, CodeCompileUnit e)
{
! // TODO
! return null;
}
--- 72,78 ----
(CompilerParameters options, CodeCompileUnit e)
{
! CodeCompileUnit[] list = new CodeCompileUnit
[1];
! list[0] = e;
! return FromDomBatch(options, list);
}
***************
*** 64,69 ****
(CompilerParameters options, CodeCompileUnit[]
ea)
{
! // TODO
! return null;
}
--- 81,111 ----
(CompilerParameters options, CodeCompileUnit[]
ea)
{
! // Write all of the CodeDom units to temporary
files.
! String[] tempFiles = new String [ea.Length];
! int src;
! Stream stream;
! StreamWriter writer;
! for(src = 0; src < ea.Length; ++src)
! {
! tempFiles[src] =
options.TempFiles.AddExtension
! (src + FileExtension);
! stream = new FileStream(tempFiles[src],
FileMode.Create,
!
FileAccess.Write, FileShare.Read);
! try
! {
! writer = new
StreamWriter(stream, Encoding.UTF8);
!
((ICodeGenerator)this).GenerateCodeFromCompileUnit
! (ea[src],
writer, Options);
! writer.Flush();
! writer.Close();
! }
! finally
! {
! stream.Close();
! }
! }
!
! // Compile the temporary files.
! return FromFileBatch(options, tempFiles);
}
***************
*** 72,77 ****
(CompilerParameters options, String fileName)
{
! // TODO
! return null;
}
--- 114,126 ----
(CompilerParameters options, String fileName)
{
! // Verify that the file can be read, throwing an
! // exception to the caller if it cannot.
! (new FileStream(fileName, FileMode.Open,
FileAccess.Read))
! .Close();
!
! // Pass the filename to "FromFileBatch".
! String[] list = new String [1];
! list[0] = fileName;
! return FromFileBatch(options, list);
}
***************
*** 88,93 ****
(CompilerParameters options, String source)
{
! // TODO
! return null;
}
--- 137,143 ----
(CompilerParameters options, String source)
{
! String[] list = new String [1];
! list[0] = source;
! return FromSourceBatch(options, list);
}
***************
*** 96,101 ****
(CompilerParameters options, String[] sources)
{
! // TODO
! return null;
}
--- 146,175 ----
(CompilerParameters options, String[] sources)
{
! // Write all of the sources to temporary files.
! String[] tempFiles = new String
[sources.Length];
! int src;
! Stream stream;
! StreamWriter writer;
! for(src = 0; src < sources.Length; ++src)
! {
! tempFiles[src] =
options.TempFiles.AddExtension
! (src + FileExtension);
! stream = new FileStream(tempFiles[src],
FileMode.Create,
!
FileAccess.Write, FileShare.Read);
! try
! {
! writer = new
StreamWriter(stream, Encoding.UTF8);
! writer.Write(sources[src]);
! writer.Flush();
! writer.Close();
! }
! finally
! {
! stream.Close();
! }
! }
!
! // Compile the temporary files.
! return FromFileBatch(options, tempFiles);
}
***************
*** 104,109 ****
(CompilerParameters options, String cmdArgs)
{
! // TODO
! return null;
}
--- 178,203 ----
(CompilerParameters options, String cmdArgs)
{
! // Get a temporary file to use for the response
file.
! String responseFile =
options.TempFiles.AddExtension("cmdline");
!
! // Write the arguments to the response file.
! Stream stream = new FileStream(responseFile,
FileMode.Create,
!
FileAccess.Write,
!
FileShare.Read);
! try
! {
! StreamWriter writer = new StreamWriter
! (stream, Encoding.UTF8);
! writer.Write(cmdArgs);
! writer.Flush();
! writer.Close();
! }
! finally
! {
! stream.Close();
! }
!
! // Build the new command-line containing the
response file.
! return "@\"" + responseFile + "\"";
}
***************
*** 116,121 ****
(CompilerParameters options, CodeCompileUnit
compilationUnit)
{
! // TODO
! return null;
}
--- 210,221 ----
(CompilerParameters options, CodeCompileUnit
compilationUnit)
{
! try
! {
! return FromDom(options,
compilationUnit);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
***************
*** 124,129 ****
(CompilerParameters options, CodeCompileUnit[]
compilationUnits)
{
! // TODO
! return null;
}
--- 224,235 ----
(CompilerParameters options, CodeCompileUnit[]
compilationUnits)
{
! try
! {
! return FromDomBatch(options,
compilationUnits);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
***************
*** 132,137 ****
(CompilerParameters options, String fileName)
{
! // TODO
! return null;
}
--- 238,249 ----
(CompilerParameters options, String fileName)
{
! try
! {
! return FromFile(options, fileName);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
***************
*** 140,145 ****
(CompilerParameters options, String[] fileNames)
{
! // TODO
! return null;
}
--- 252,263 ----
(CompilerParameters options, String[] fileNames)
{
! try
! {
! return FromFileBatch(options,
fileNames);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
***************
*** 148,153 ****
(CompilerParameters options, String source)
{
! // TODO
! return null;
}
--- 266,277 ----
(CompilerParameters options, String source)
{
! try
! {
! return FromSource(options, source);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
***************
*** 156,161 ****
(CompilerParameters options, String[] sources)
{
! // TODO
! return null;
}
--- 280,291 ----
(CompilerParameters options, String[] sources)
{
! try
! {
! return FromSourceBatch(options,
sources);
! }
! finally
! {
! options.TempFiles.Delete();
! }
}
Index: CodeGenerator.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CodeGenerator.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CodeGenerator.cs 15 Nov 2002 13:06:45 -0000 1.1
--- CodeGenerator.cs 16 Nov 2002 07:17:17 -0000 1.2
***************
*** 45,49 ****
public static bool IsValidLanguageIndependentIdentifier(String value)
{
! // TODO
return true;
}
--- 45,75 ----
public static bool IsValidLanguageIndependentIdentifier(String value)
{
! if(value == null || value.Length == 0)
! {
[...1233 lines suppressed...]
*** 583,587 ****
CodeGeneratorOptions o)
{
! // TODO
}
--- 1413,1425 ----
CodeGeneratorOptions o)
{
! bool initialized = SetupForCodeGeneration(w, o);
! try
! {
! GenerateType(e);
! }
! finally
! {
! FinalizeCodeGeneration(initialized);
! }
}
Index: CompilerError.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/System/CodeDom/Compiler/CompilerError.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CompilerError.cs 15 Nov 2002 07:46:56 -0000 1.1
--- CompilerError.cs 16 Nov 2002 07:17:17 -0000 1.2
***************
*** 127,132 ****
public override String ToString()
{
! // TODO
! return null;
}
--- 127,159 ----
public override String ToString()
{
! // Normalize the error number to deal with the
fact
! // that cscc does not use error numbers at all.
! String errorNumber = this.errorNumber;
! if(errorNumber == null || errorNumber ==
String.Empty)
! {
! if(isWarning)
! {
! errorNumber = "CS0000";
! }
! else
! {
! errorNumber = "CS0001";
! }
! }
!
! // Format the error text and return it.
! if(fileName == null || fileName == String.Empty)
! {
! return String.Format("{0} {1}: {2}",
!
(isWarning ? "warning" : "error"),
!
errorNumber, errorText);
! }
! else
! {
! return String.Format("{0} ({1},{2}) :
{3} {4}: {5}",
!
fileName, line, column,
!
(isWarning ? "warning" : "error"),
!
errorNumber, errorText);
! }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System/CodeDom/Compiler CSharpCodeProvider.cs,NONE,1.1 CodeDomProvider.cs,NONE,1.1 CSharpCodeCompiler.cs,1.1,1.2 CodeCompiler.cs,1.1,1.2 CodeGenerator.cs,1.1,1.2 CompilerError.cs,1.1,1.2,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/System Arg.txt,1.8,1.9 Invalid.txt,1.1,1.2
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1842,1.1843
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/System Arg.txt,1.8,1.9 Invalid.txt,1.1,1.2
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1842,1.1843
- Index(es):