[nem-en] [Patch] Fix codedom when using partial class and multiple
source file
Kanru Chen
ckanru at gmail.com
Fri Jan 20 15:07:16 CET 2006
I found that the example of ASP.NET at the bottom of
http://nemerle.org/ASP.NET did not run with current mono/xsp2. When
using 2.0 profile, mono will automatically generate partial class for
aspx page but old code-generator did not handle this. The second
problem is that old code-compiler did not handle addition options from
CompilerParameters.CompilerOptions. This cause compiler can't find
separate source file. The following patch should fix this problem.
And the example should modify to:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : Page
{
protected Page_Load(_ : object, _ : EventArgs) : void
{
Message.Text = $"You last accessed this page at: $(DateTime.Now)";
}
protected EnterBtn_Click(_ : object, _ : EventArgs) : void
{
Message.Text = $"Hi $(Name.Text), welcome to ASP.NET!";
}
}
Regards,
Kanru
--
~ Kanru Chen <koster at debian.org.tw>
'v' http://stu.csie.ncnu.edu.tw/~kanru.96/
// \\ GnuPG-Key ID: 365CC7A2
/( )\ Fingerprint: 3278 DFB4 BB28 6E8C 9E1F 1ECB B1B7 5B5F 365C C7A2
^`~'^
-------------- next part --------------
Index: ncc/codedom/NemerleCodeGenerator.n
===================================================================
--- ncc/codedom/NemerleCodeGenerator.n (revision 6061)
+++ ncc/codedom/NemerleCodeGenerator.n (working copy)
@@ -556,6 +556,56 @@
Output.Write("mutable ");
}
+ private OutputTypeAttributes (declaration : CodeTypeDeclaration) : void
+ {
+ def output = Output;
+ def attributes = declaration.TypeAttributes;
+
+ match (attributes & TypeAttributes.VisibilityMask) {
+ | TypeAttributes.Public
+ | TypeAttributes.NestedPublic =>
+ output.Write ("public ");
+ | TypeAttributes.NestedPrivate =>
+ output.Write ("private ");
+ | TypeAttributes.NotPublic
+ | TypeAttributes.NestedFamANDAssem
+ | TypeAttributes.NestedAssembly =>
+ output.Write ("internal ");
+ | TypeAttributes.NestedFamily =>
+ output.Write ("protected ");
+ | TypeAttributes.NestedFamORAssem =>
+ output.Write ("protected internal ");
+ | _ =>
+ ();
+ }
+
+ match (declaration) {
+ | d when d.IsStruct =>
+ when (d.IsPartial) {
+ output.Write ("partial ");
+ }
+ output.Write ("struct ");
+ | d when d.IsEnum =>
+ output.Write ("enum ");
+ | _ =>
+ if ((attributes & TypeAttributes.Interface) != 0) {
+ when (declaration.IsPartial) {
+ output.Write ("partial ");
+ }
+ output.Write ("interface ");
+ } else {
+ when ((attributes & TypeAttributes.Sealed) != 0)
+ output.Write ("sealed ");
+ when ((attributes & TypeAttributes.Abstract) != 0)
+ output.Write ("abstract ");
+ when (declaration.IsPartial) {
+ output.Write ("partial ");
+ }
+ output.Write ("class ");
+ }
+ }
+ }
+
protected override GenerateSnippetMember (member : CodeSnippetTypeMember) : void
{
Output.Write (member.Text);
@@ -749,10 +799,7 @@
when (declaration.CustomAttributes.Count > 0)
OutputAttributeDeclarations ( declaration.CustomAttributes );
- def attributes = declaration.TypeAttributes;
- OutputTypeAttributes (attributes,
- declaration.IsStruct,
- declaration.IsEnum );
+ OutputTypeAttributes (declaration);
output.Write (GetSafeName (declaration.Name));
Index: ncc/codedom/NemerleCodeCompiler.n
===================================================================
--- ncc/codedom/NemerleCodeCompiler.n (revision 6061)
+++ ncc/codedom/NemerleCodeCompiler.n (working copy)
@@ -39,6 +39,7 @@
using System.Configuration;
using System.IO;
using System.Text;
+using System.Text.RegularExpressions;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
@@ -46,6 +47,7 @@
using Nemerle.Assertions;
using Nemerle.Collections;
+using Nemerle.Utility;
namespace Nemerle.Compiler
{
@@ -125,6 +127,15 @@
err_event (true, loc, msg);
}
+ mutable files = [];
+ def opts = Options.GetCommonOptions () + [
+ Getopt.CliOption.NonOption (name = "",
+ help = "Specify file to compile",
+ handler = fun (s) { files = s :: files })
+ ];
+ Getopt.Parse (Message.Error, opts,
+ List.FromArray (Regex.Split (options.CompilerOptions, @"\s")).Filter (fun (t) {t.Length > 0}));
+
def fullOutput = System.IO.StringWriter ();
Message.InitOutput (fullOutput);
Options.ProgressBar = false;
@@ -144,7 +155,7 @@
if (fileNames.Length < 1)
Message.Error ("need at least one file to compile");
else {
- Options.Sources = List.FromArray (fileNames);
+ Options.Sources = files + List.FromArray (fileNames);
Passes.Run ();
succeeded = !failed;
}
More information about the devel-en
mailing list