[svn] r7393: nemerle/trunk/tools/reflector-addon:
reflectorAddon.nproj reflectorAddon.sln src/CodeModel/La...
pbludov
svnadmin at nemerle.org
Wed Feb 7 05:21:42 CET 2007
Log:
reflector-addon: special handling for constructors; generic args for type aliases.
Author: pbludov
Date: Wed Feb 7 05:21:37 2007
New Revision: 7393
Removed:
nemerle/trunk/tools/reflector-addon/reflectorAddon.nproj
nemerle/trunk/tools/reflector-addon/reflectorAddon.sln
Modified:
nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n
nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n
Modified: nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n
==============================================================================
--- nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n (original)
+++ nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n Wed Feb 7 05:21:37 2007
@@ -106,9 +106,9 @@
_formatter.WriteProperty(name, value);
}
- public WriteReference(name : string, description : string, target : object) : void
+ public WriteReference(name : string, description : string, target : object, check : bool = true) : void
{
- _formatter.WriteReference(if (Keywords.Contains(name)) EscapeKeyword(name) else name, description, target);
+ _formatter.WriteReference(if (check && Keywords.Contains(name)) EscapeKeyword(name) else name, description, target);
}
#region Extensions
Modified: nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n
==============================================================================
--- nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n (original)
+++ nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n Wed Feb 7 05:21:37 2007
@@ -747,27 +747,19 @@
{
match (expr.Operator)
{
- | UnaryOperator.Negate =>
- Write("-");
+ | UnaryOperator.Negate with op = "-"
+ | UnaryOperator.BooleanNot with op = "!"
+ | UnaryOperator.BitwiseNot with op = "~"
+ | UnaryOperator.PreIncrement with op = "++"
+ | UnaryOperator.PreDecrement with op = "--" =>
+ Write(op);
WriteExpression(expr.Expression);
- | UnaryOperator.BooleanNot =>
- Write("!");
- WriteExpression(expr.Expression);
- | UnaryOperator.BitwiseNot =>
- Write("~");
- WriteExpression(expr.Expression);
- | UnaryOperator.PreIncrement =>
- Write("++");
- WriteExpression(expr.Expression);
- | UnaryOperator.PreDecrement =>
- Write("--");
- WriteExpression(expr.Expression);
- | UnaryOperator.PostIncrement =>
- WriteExpression(expr.Expression);
- Write("++");
- | UnaryOperator.PostDecrement =>
+
+ | UnaryOperator.PostIncrement with op = "++"
+ | UnaryOperator.PostDecrement with op = "--" =>
WriteExpression(expr.Expression);
- Write("--");
+ Write(op);
+
| _ =>
throw NotSupportedException(expr.Operator.ToString());
}
@@ -1010,7 +1002,7 @@
WriteKeyword("event");
Write(" ");
- WriteDeclaration(value.Name.Replace('.', '\'').Replace('<', '_').Replace('>', '_'));
+ WriteMemberName(value.Name);
Write(" : ");
WriteType(value.EventType);
Write(";");
@@ -1053,7 +1045,7 @@
Write(" ");
}
- WriteDeclaration(value.Name);
+ WriteMemberName(value.Name);
Write(" : ");
WriteType(value.FieldType);
@@ -1098,15 +1090,68 @@
Write("(");
WriteList(value.Parameters.ToList(), WriteParameterDeclaration);
Write(")");
+
+ // Constructor body is broken by the translator for some unknown reason.
+ //
+ when (_configuration.ShowMethodDeclarationBody)
+ {
+ BeginBlock();
+ match (value)
+ {
+ | cd is IConstructorDeclaration when cd.Initializer != null =>
+ match (cd.Initializer.Method)
+ {
+ | mRef is IMethodReferenceExpression when mRef.Method.IsConstructor() =>
+ unless (cd.Initializer.Arguments.Count == 0)
+ {
+ match (mRef.Target)
+ {
+ | _ is IBaseReferenceExpression with name = "base"
+ | _ is IThisReferenceExpression with name = "this" =>
+ WriteReference(name, mRef.Method.GetUserFriendlyName(), mRef.Method, false);
+ Write("(");
+ WriteList(cd.Initializer.Arguments.ToList(), WriteExpression);
+ Write(")");
+ | _ => WriteMethodInvokeExpression(cd.Initializer);
+ }
+ Write(";");
+ WriteLine();
+ }
+ | _ =>
+ WriteMethodInvokeExpression(cd.Initializer);
+ Write(";");
+ WriteLine();
+ }
+ | _ => {}
+ }
+
+ match (value.Body)
+ {
+ | b is IBlockStatement =>
+ b.Statements.Iter(s =>
+ {
+ WriteStatement(s);
+ when (IsSingleLineStatement(s))
+ {
+ Write(";");
+ WriteLine();
+ }
+ });
+ | s is IStatement =>
+ WriteStatement(s);
+ Write(";");
+ WriteLine();
+ | _ => {}
+ }
+
+ EndBlock();
+ }
}
else
{
def genArgs = value.GenericArguments.ToList();
- // Convert a c#-style name of explicit implementation method
- // to the Nemerle style. F.e. System.Cloneable becomes System'Cloneable
- //
- WriteDeclaration(value.Name.Replace('.', '\'').Replace('<', '_').Replace('>', '_'));
+ WriteMemberName(value.Name);
WriteList(genArgs, "[", "]", WriteType);
Write("(");
@@ -1134,9 +1179,9 @@
WriteMethodReference(m);
});
}
- }
WriteMethodBody(value.Body);
+ }
unless (_configuration.ShowTypeDeclarationBody)
WriteDeclaringTypeProperties(value.DeclaringType :> ITypeReference);
@@ -1165,10 +1210,7 @@
WriteMethodAttributes(setMethod);
}
- // Convert a c#-style name of explicit interface implementation method
- // to the Nemerle style.
- //
- WriteDeclaration(value.Name.Replace('.', '\'').Replace('<', '_').Replace('>', '_'));
+ WriteMemberName(value.Name);
WriteList(value.Parameters.ToList(), "[", "]", WriteParameterDeclaration);
Write(" : ");
@@ -1419,6 +1461,7 @@
// TODO: Decode alias string to real type name and generic parameters
// See ncc\external\Codec.n for details
//
+ def genArgs = value.GenericArguments.ToList();
def alias = wrapper.TypeAlias;
def dotIndex = alias.LastIndexOf('.');
def typeRef = TypeReference();
@@ -1435,6 +1478,8 @@
Write(" ");
WriteDeclaration(value.Name);
+ WriteList(genArgs, "[", "]", WriteType);
+ WriteGenericParameterConstraintList(genArgs);
Write(" = ");
WriteReference(alias, alias, typeRef);
@@ -1942,6 +1987,14 @@
}
}
+ private WriteMemberName(name : string) : void
+ {
+ // Convert a c#-style name of explicit implementation member
+ // to the Nemerle style. F.e. System.Cloneable becomes System'Cloneable
+ //
+ WriteDeclaration(name.Replace('.', '\'').Replace('<', '_').Replace('>', '_'));
+ }
+
private WriteDeclaringTypeProperties(value : ITypeReference) : void
{
WriteProperty("Declaring Type", value.GetUserFriendlyName());
More information about the svn
mailing list