[svn] r7225: nemerle/trunk/tools/reflector-addon: . lib
lib/Reflector.cfg lib/Reflector.exe.config lib/rea...
pbludov
svnadmin at nemerle.org
Mon Jan 8 07:21:34 CET 2007
Log:
Initial checkin.
Author: pbludov
Date: Mon Jan 8 07:21:27 2007
New Revision: 7225
Added:
nemerle/trunk/tools/reflector-addon/
nemerle/trunk/tools/reflector-addon/lib/ (props changed)
nemerle/trunk/tools/reflector-addon/lib/Reflector.cfg
nemerle/trunk/tools/reflector-addon/lib/Reflector.exe.config
nemerle/trunk/tools/reflector-addon/lib/readme.txt
nemerle/trunk/tools/reflector-addon/reflector-addon.build
nemerle/trunk/tools/reflector-addon/reflector-addon.nproj
nemerle/trunk/tools/reflector-addon/src/
nemerle/trunk/tools/reflector-addon/src/AssemblyInfo.n
nemerle/trunk/tools/reflector-addon/src/CodeModel/
nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n
nemerle/trunk/tools/reflector-addon/src/CodeModel/VisitorBase.n
nemerle/trunk/tools/reflector-addon/src/CustomAttributeWrapper.n
nemerle/trunk/tools/reflector-addon/src/Helper.n
nemerle/trunk/tools/reflector-addon/src/Language.n
nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n
nemerle/trunk/tools/reflector-addon/src/LanguageWriterConfiguration.n
nemerle/trunk/tools/reflector-addon/src/Package.n
nemerle/trunk/tools/reflector-addon/src/UsingNamespaceVisitor.n
Added: nemerle/trunk/tools/reflector-addon/lib/Reflector.cfg
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/lib/Reflector.cfg Mon Jan 8 07:21:27 2007
@@ -0,0 +1,23 @@
+
+[AddInManager]
+"..\bin\Debug\Reflector.NemerleLanguage.dll"
+
+[AssemblyCache]
+"%SystemRoot%\Microsoft.net"
+"%ProgramFiles%\Microsoft.net"
+"%ProgramFiles%\Reference Assemblies"
+
+[AssemblyManager]
+"%SystemRoot%\Microsoft.net\Framework\v2.0.50727\mscorlib.dll"
+"%SystemRoot%\Microsoft.net\Framework\v2.0.50727\System.dll"
+"C:\work\paul\RSDN\Projects\Nemerle\tools\reflector-addon\bin\Debug\Reflector.NemerleLanguage.dll"
+
+[LanguageManager]
+ActiveLanguage="Nemerle"
+
+[WindowManager]
+X="69"
+Y="191"
+Width="480"
+Height="600"
+Pane="610"
Added: nemerle/trunk/tools/reflector-addon/lib/Reflector.exe.config
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/lib/Reflector.exe.config Mon Jan 8 07:21:27 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v2.0.50727"/> <!-- Release -->
+ </startup>
+</configuration>
Added: nemerle/trunk/tools/reflector-addon/lib/readme.txt
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/lib/readme.txt Mon Jan 8 07:21:27 2007
@@ -0,0 +1 @@
+Put reflector.exe and Nemerle.dll here.
\ No newline at end of file
Added: nemerle/trunk/tools/reflector-addon/reflector-addon.build
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/reflector-addon.build Mon Jan 8 07:21:27 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<project name="reflector-addon" default="build">
+
+ <property name='configuration' value="Debug"/>
+ <property name='build.dir' value="${path::get-full-path('bin')}/${configuration}"/>
+ <property name='lib.dir' value="${path::get-full-path('lib')}"/>
+
+ <target name="build">
+ <mkdir dir="${build.dir}" />
+ <ncc output='${build.dir}/Reflector.NemerleLanguage.dll' target='dll'>
+ <references>
+ <include name='${lib.dir}/Reflector.exe' />
+ <include name='${lib.dir}/Nemerle.dll' />
+ </references>
+ <sources basedir='src'>
+ <include name='*.n' />
+ <include name='CodeModel/*.n' />
+ </sources>
+ </ncc>
+ </target>
+
+ <target name="run" depends="build">
+ <exec program="Reflector.exe" workingdir="${lib.dir}" basedir="${lib.dir}"/>
+ </target>
+
+ <target name="clean">
+ <delete>
+ <fileset basedir='${build.dir}'>
+ <include name='**' />
+ </fileset>
+ </delete>
+ </target>
+
+</project>
Added: nemerle/trunk/tools/reflector-addon/reflector-addon.nproj
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/reflector-addon.nproj Mon Jan 8 07:21:27 2007
@@ -0,0 +1,67 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <NoStdLib>true</NoStdLib>
+ <Nemerle Condition=" '$(Nemerle)' == '' ">$(ProgramFiles)\Nemerle</Nemerle>
+ <Name>Reflector.NemerleLanguage</Name>
+ <TargetPlatform>v2</TargetPlatform>
+ </PropertyGroup>
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{c35c79b4-8107-4b5f-bc8a-64783f24726f}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>Reflector.NemerleLanguage</RootNamespace>
+ <AssemblyName>Reflector.NemerleLanguage</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <StartProgram>lib\Reflector.exe</StartProgram>
+ <WorkingDirectory>
+ </WorkingDirectory>
+ <CmdArgs>
+ </CmdArgs>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="$(Nemerle)\Nemerle.dll" />
+ <Reference Include="lib\Reflector.exe" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="src\" />
+ <Folder Include="src\CodeModel\" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\Package.n" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\Language.n" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\CodeModel\LanguageWriterBase.n" />
+ <Compile Include="src\CodeModel\VisitorBase.n" />
+ <Compile Include="src\AssemblyInfo.n" />
+ <Compile Include="src\CustomAttributeWrapper.n" />
+ <Compile Include="src\Helper.n " />
+ <Compile Include="src\LanguageWriter.n" />
+ <Compile Include="src\LanguageWriterConfiguration.n" />
+ <Compile Include="src\UsingNamespaceVisitor.n" />
+ </ItemGroup>
+ <Import Project="$(Nemerle)\Nemerle.MSBuild.targets" />
+</Project>
\ No newline at end of file
Added: nemerle/trunk/tools/reflector-addon/src/AssemblyInfo.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/AssemblyInfo.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle ("Reflector.NemerleLanguage")]
+[assembly: AssemblyDescription("Nemerle (http://nemerle.org) Language for Reflector")]
+[assembly: AssemblyCompany ("University of Wroclaw")]
+[assembly: AssemblyProduct ("Reflector.NemerleLanguage")]
+[assembly: AssemblyCopyright ("Copyright \xA9 University of Wroclaw 2003-2007.")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("4.2.0.0")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("..\\..\\..\\Nemerle.snk")]
+//[assembly: AssemblyKeyName("")]
Added: nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/CodeModel/LanguageWriterBase.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using Nemerle.Collections;
+using Nemerle.Utility;
+using System.Diagnostics;
+
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage.CodeModel
+{
+ public abstract class LanguageWritterBase : ILanguageWriter
+ {
+ private _formatter : IFormatter;
+
+ public this(formatter : IFormatter)
+ {
+ _formatter = formatter;
+ }
+
+ public abstract WriteAssembly (_ : IAssembly) : void;
+ public abstract WriteAssemblyReference (_ : IAssemblyReference) : void;
+ public abstract WriteEventDeclaration (_ : IEventDeclaration) : void;
+ public abstract WriteExpression (_ : IExpression) : void;
+ public abstract WriteFieldDeclaration (_ : IFieldDeclaration) : void;
+ public abstract WriteMethodDeclaration (_ : IMethodDeclaration) : void;
+ public abstract WriteModule (_ : IModule) : void;
+ public abstract WriteModuleReference (_ : IModuleReference) : void;
+ public abstract WriteNamespace (_ : INamespace) : void;
+ public abstract WritePropertyDeclaration(_ : IPropertyDeclaration) : void;
+ public abstract WriteResource (_ : IResource) : void;
+ public abstract WriteStatement (_ : IStatement) : void;
+ public abstract WriteTypeDeclaration (_ : ITypeDeclaration) : void;
+
+
+ #region IFormatter wrappers
+
+ public Write(value : string) : void
+ {
+ _formatter.Write(value);
+ }
+
+ public WriteComment(value : string) : void
+ {
+ _formatter.WriteComment(value);
+ }
+
+ public WriteDeclaration(name : string) : void
+ {
+ _formatter.WriteDeclaration(
+ match (SpecialMethods.Find(name))
+ {
+ | Some(alias) => EscapeKeyword(alias)
+ | None when Keywords.Contains(name) => EscapeKeyword(name)
+ | None => name
+ }
+ );
+ }
+
+ public WriteIndent() : void
+ {
+ _formatter.WriteIndent();
+ }
+
+ public WriteKeyword(value : string) : void
+ {
+ Debug.WriteLineIf(!Keywords.Contains(value) && !value.StartsWith("#"), $"'$value' is not a keyword");
+
+ _formatter.WriteKeyword(value);
+ }
+
+ public WriteLine() : void
+ {
+ _formatter.WriteLine();
+ }
+
+ public WriteLiteral(value : string) : void
+ {
+ _formatter.WriteLiteral(value);
+ }
+
+ public WriteOutdent() : void
+ {
+ _formatter.WriteOutdent();
+ }
+
+ public WriteProperty(name : string, value : string) : void
+ {
+ _formatter.WriteProperty(name, value);
+ }
+
+ public WriteReference(value : string, description : string, target : object) : void
+ {
+ _formatter.WriteReference(value, description, target);
+ }
+
+ #region Extensions
+
+ public WriteLine(value : string) : void
+ {
+ _formatter.Write(value);
+ _formatter.WriteLine();
+ }
+
+ public WriteIdentifier(name : string) : void
+ {
+ _formatter.Write(if (Keywords.Contains(name)) EscapeKeyword(name) else name);
+ }
+
+ public WriteList['a](lst : list['a], writer : 'a -> void) : void
+ {
+ WriteList(lst, null, null, ", ", writer)
+ }
+
+ public WriteList['a](lst : list['a], start : string, stop : string, writer : 'a -> void) : void
+ {
+ WriteList(lst, start, stop, ", ", writer)
+ }
+
+ public WriteList['a](lst : list['a], start : string, stop : string, delemiter : string, writer : 'a -> void) : void
+ {
+ def loop(_)
+ {
+ | x :: Nil =>
+ writer(x);
+ | x :: tail =>
+ writer(x);
+ _formatter.Write(delemiter);
+ loop(tail)
+ | [] => ()
+ }
+
+ unless (lst.IsEmpty)
+ {
+ unless (string.IsNullOrEmpty(start))
+ Write(start);
+ loop(lst);
+ unless (string.IsNullOrEmpty(stop))
+ Write(stop);
+ }
+ }
+
+ public WriteTypeReference(ty : ITypeReference, description : string, target : object) : void
+ {
+ _formatter.WriteReference(
+ match (Types.Find(ty.GetUserFriendlyName()))
+ {
+ | Some(name) => name
+ | None => ty.Name
+ }, description, target);
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Keywords
+
+ protected abstract EscapeKeyword(value : string) : string;
+
+ protected abstract GetKeywords() : Set[string];
+
+ mutable _keywords : Set[string];
+ public Keywords : Set[string]
+ {
+ get
+ {
+ when (_keywords == null)
+ {
+ _keywords = GetKeywords()
+ .AddRange(Types.Map((_key, value) => value));
+ }
+
+ _keywords;
+ }
+ }
+
+ protected abstract GetTypes() : Map[string, string];
+
+ mutable _types : Map[string, string];
+ public Types : Map[string, string]
+ {
+ get
+ {
+ when (_types == null)
+ _types = GetTypes();
+
+ _types;
+ }
+ }
+
+ protected abstract GetSpecialMethods() : Map[string, string];
+
+ mutable _specialMethods : Map[string, string];
+ public SpecialMethods : Map[string, string]
+ {
+ get
+ {
+ when (_specialMethods == null)
+ _specialMethods = GetSpecialMethods();
+
+ _specialMethods;
+ }
+ }
+
+ #endregion
+
+ }
+}
+
+
Added: nemerle/trunk/tools/reflector-addon/src/CodeModel/VisitorBase.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/CodeModel/VisitorBase.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,785 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Globalization;
+
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage.CodeModel
+{
+ public class VisitorBase
+ {
+ public virtual VisitAddressDereferenceExpression(value : IAddressDereferenceExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitAddressOfExpression(value : IAddressOfExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitAddressOutExpression(value : IAddressOutExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitAddressReferenceExpression(value : IAddressReferenceExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitArgumentListExpression(_ : IArgumentListExpression) : void
+ {
+ }
+
+ public virtual VisitArgumentReferenceExpression(_ : IArgumentReferenceExpression) : void
+ {
+ }
+
+ public virtual VisitArrayCreateExpression(value : IArrayCreateExpression) : void
+ {
+ VisitType(value.Type);
+ VisitExpression(value.Initializer);
+ VisitExpressionCollection(value.Dimensions);
+ }
+
+ public virtual VisitArrayDimension(_ : IArrayDimension) : void
+ {
+ }
+
+ public virtual VisitArrayDimensionCollection(value : IArrayDimensionCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitArrayDimension(value[i]);
+ }
+
+ public virtual VisitArrayIndexerExpression(value : IArrayIndexerExpression) : void
+ {
+ VisitExpressionCollection(value.Indices);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitArrayInitializerExpression(value : IArrayInitializerExpression) : void
+ {
+ VisitExpressionCollection(value.Expressions);
+ }
+
+ public virtual VisitArrayType(value : IArrayType) : void
+ {
+ VisitType(value.ElementType);
+ VisitArrayDimensionCollection(value.Dimensions);
+ }
+
+ public virtual VisitAssembly(value : IAssembly) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitModuleCollection(value.Modules);
+ }
+
+ public virtual VisitAssemblyReference(_ : IAssemblyReference) : void
+ {
+ }
+
+ public virtual VisitAssignExpression(value : IAssignExpression) : void
+ {
+ VisitExpression(value.Target);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitAttachEventStatement(value : IAttachEventStatement) : void
+ {
+ VisitExpression(value.Event);
+ VisitExpression(value.Listener);
+ }
+
+ public virtual VisitBaseReferenceExpression(_ : IBaseReferenceExpression) : void
+ {
+ }
+
+ public virtual VisitBinaryExpression(value : IBinaryExpression) : void
+ {
+ VisitExpression(value.Left);
+ VisitExpression(value.Right);
+ }
+
+ public virtual VisitBlockStatement(value : IBlockStatement) : void
+ {
+ VisitStatementCollection(value.Statements);
+ }
+
+ public virtual VisitBreakStatement(_ : IBreakStatement) : void
+ {
+ }
+
+ public virtual VisitCanCastExpression(value : ICanCastExpression) : void
+ {
+ VisitType(value.TargetType);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitCastExpression(value : ICastExpression) : void
+ {
+ VisitType(value.TargetType);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitCatchClause(value : ICatchClause) : void
+ {
+ VisitVariableDeclaration(value.Variable);
+ VisitExpression(value.Condition);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitCatchClauseCollection(value : ICatchClauseCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitCatchClause(value[i]);
+ }
+
+ public virtual VisitCommentStatement(_ : ICommentStatement) : void
+ {
+ }
+
+ public virtual VisitConditionCase(value : IConditionCase) : void
+ {
+ VisitExpression(value.Condition);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitConditionExpression(value : IConditionExpression) : void
+ {
+ VisitExpression(value.Condition);
+ VisitExpression(value.Then);
+ VisitExpression(value.Else);
+ }
+
+ public virtual VisitConditionStatement(value : IConditionStatement) : void
+ {
+ VisitExpression(value.Condition);
+ VisitStatement(value.Then);
+ VisitStatement(value.Else);
+ }
+
+ public virtual VisitContinueStatement(_ : IContinueStatement) : void
+ {
+ }
+
+ public virtual VisitCustomAttribute(customAttribute : ICustomAttribute) : void
+ {
+ VisitExpressionCollection(customAttribute.Arguments);
+ }
+
+ public virtual VisitCustomAttributeCollection(value : ICustomAttributeCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitCustomAttribute(value[i]);
+ }
+
+ public virtual VisitDefaultCase(value : IDefaultCase) : void
+ {
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitDelegateCreateExpression(value : IDelegateCreateExpression) : void
+ {
+ VisitType(value.DelegateType);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitDelegateInvokeExpression(value : IDelegateInvokeExpression) : void
+ {
+ VisitExpressionCollection(value.Arguments);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitDoStatement(value : IDoStatement) : void
+ {
+ VisitExpression(value.Condition);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitEmbeddedResource(_ : IEmbeddedResource) : void
+ {
+ }
+
+ public virtual VisitEventDeclaration(value : IEventDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitType(value.EventType);
+ }
+
+ public virtual VisitEventDeclarationCollection(value : IEventDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ {
+ VisitEventDeclaration(value[i]);
+ }
+ }
+
+ public virtual VisitEventReference(value : IEventReference) : void
+ {
+ VisitType(value.EventType);
+ }
+
+ public virtual VisitEventReferenceExpression(value : IEventReferenceExpression) : void
+ {
+ VisitEventReference(value.Event);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitExpression(value : IExpression) : void
+ {
+ | e is IVariableReferenceExpression => VisitVariableReferenceExpression (e)
+ | e is ILiteralExpression => VisitLiteralExpression (e)
+ | e is IFieldReferenceExpression => VisitFieldReferenceExpression (e)
+ | e is IPropertyReferenceExpression => VisitPropertyReferenceExpression (e)
+ | e is IAssignExpression => VisitAssignExpression (e)
+ | e is IBinaryExpression => VisitBinaryExpression (e)
+ | e is IThisReferenceExpression => VisitThisReferenceExpression (e)
+ | e is IMethodInvokeExpression => VisitMethodInvokeExpression (e)
+ | e is IMethodReferenceExpression => VisitMethodReferenceExpression (e)
+ | e is IArgumentReferenceExpression => VisitArgumentReferenceExpression (e)
+ | e is IVariableDeclarationExpression => VisitVariableDeclarationExpression (e)
+ | e is ITypeReferenceExpression => VisitTypeReferenceExpression (e)
+ | e is IBaseReferenceExpression => VisitBaseReferenceExpression (e)
+ | e is IUnaryExpression => VisitUnaryExpression (e)
+ | e is ITryCastExpression => VisitTryCastExpression (e)
+ | e is ICanCastExpression => VisitCanCastExpression (e)
+ | e is ICastExpression => VisitCastExpression (e)
+ | e is ITypeOfExpression => VisitTypeOfExpression (e)
+ | e is INamedArgumentExpression => VisitNamedArgumentExpression (e)
+ | e is IEventReferenceExpression => VisitEventReferenceExpression (e)
+ | e is IArgumentListExpression => VisitArgumentListExpression (e)
+ | e is IArrayCreateExpression => VisitArrayCreateExpression (e)
+ | e is IArrayInitializerExpression => VisitArrayInitializerExpression (e)
+ | e is IConditionExpression => VisitConditionExpression (e)
+ | e is INullCoalescingExpression => VisitNullCoalescingExpression (e)
+ | e is IDelegateCreateExpression => VisitDelegateCreateExpression (e)
+ | e is IPropertyIndexerExpression => VisitPropertyIndexerExpression (e)
+ | e is IArrayIndexerExpression => VisitArrayIndexerExpression (e)
+ | e is IDelegateInvokeExpression => VisitDelegateInvokeExpression (e)
+ | e is IObjectCreateExpression => VisitObjectCreateExpression (e)
+ | e is IAddressOfExpression => VisitAddressOfExpression (e)
+ | e is IAddressReferenceExpression => VisitAddressReferenceExpression (e)
+ | e is IAddressOutExpression => VisitAddressOutExpression (e)
+ | e is IAddressDereferenceExpression => VisitAddressDereferenceExpression (e)
+ | e is ISizeOfExpression => VisitSizeOfExpression (e)
+ | e is ITypedReferenceCreateExpression => VisitTypedReferenceCreateExpression (e)
+ | e is IObjectInitializeExpression => VisitObjectInitializeExpression (e)
+ | e is ITypeOfTypedReferenceExpression => VisitTypeOfTypedReferenceExpression (e)
+ | e is IValueOfTypedReferenceExpression => VisitValueOfTypedReferenceExpression(e)
+ | e is IStackAllocateExpression => VisitStackAllocateExpression (e)
+ | e is IGenericDefaultExpression => VisitGenericDefaultExpression (e)
+ | e is ISnippetExpression => VisitSnippetExpression (e)
+ | _ => throw NotSupportedException($"Invalid expression type '$(value.GetType().Name)'.");
+ }
+
+ public virtual VisitExpressionCollection(value : IExpressionCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitExpression(value[i]);
+ }
+
+ public virtual VisitExpressionStatement(value : IExpressionStatement) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitFieldDeclaration(value : IFieldDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitType(value.FieldType);
+ }
+
+ public virtual VisitFieldDeclarationCollection(value : IFieldDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitFieldDeclaration(value[i]);
+ }
+
+ public virtual VisitFieldReference(value : IFieldReference) : void
+ {
+ VisitType(value.FieldType);
+ }
+
+ public virtual VisitFieldReferenceExpression(value : IFieldReferenceExpression) : void
+ {
+ VisitFieldReference(value.Field);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitFileResource(_ : IFileResource) : void
+ {
+ }
+
+ public virtual VisitFixedStatement(value : IFixedStatement) : void
+ {
+ VisitVariableDeclaration(value.Variable);
+ VisitExpression(value.Expression);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitForEachStatement(value : IForEachStatement) : void
+ {
+ VisitVariableDeclaration(value.Variable);
+ VisitExpression(value.Expression);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitForStatement(value : IForStatement) : void
+ {
+ VisitStatement(value.Initializer);
+ VisitExpression(value.Condition);
+ VisitStatement(value.Increment);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitFunctionPointer(_ : IFunctionPointer) : void
+ {
+ }
+
+ public virtual VisitGenericArgument(_ : IGenericArgument) : void
+ {
+ }
+
+ public virtual VisitGenericDefaultExpression(_ : IGenericDefaultExpression) : void
+ {
+ }
+
+ public virtual VisitGenericParameter(_ : IGenericParameter) : void
+ {
+ }
+
+ public virtual VisitGotoStatement(_ : IGotoStatement) : void
+ {
+ }
+
+ public virtual VisitLabeledStatement(value : ILabeledStatement) : void
+ {
+ VisitStatement(value.Statement);
+ }
+
+ public virtual VisitLiteralExpression(_ : ILiteralExpression) : void
+ {
+ }
+
+ public virtual VisitLockStatement(value : ILockStatement) : void
+ {
+ VisitExpression(value.Expression);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitMemoryCopyStatement(value : IMemoryCopyStatement) : void
+ {
+ VisitExpression(value.Source);
+ VisitExpression(value.Destination);
+ VisitExpression(value.Length);
+ }
+
+ public virtual VisitMemoryInitializeStatement(value : IMemoryInitializeStatement) : void
+ {
+ VisitExpression(value.Offset);
+ VisitExpression(value.Value);
+ VisitExpression(value.Length);
+ }
+
+ public virtual VisitMethodDeclaration(value : IMethodDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitParameterDeclarationCollection(value.Parameters);
+ VisitMethodReferenceCollection(value.Overrides);
+ VisitMethodReturnType(value.ReturnType);
+ match (value.Body)
+ {
+ | block is IBlockStatement => VisitStatement(block)
+ | _ => ()
+ }
+ }
+
+ public virtual VisitMethodDeclarationCollection(value : IMethodDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitMethodDeclaration(value[i]);
+ }
+
+ public virtual VisitMethodInvokeExpression(value : IMethodInvokeExpression) : void
+ {
+ VisitExpressionCollection(value.Arguments);
+ VisitExpression(value.Method);
+ }
+
+ public virtual VisitMethodReference(value : IMethodReference) : void
+ {
+ VisitMethodReturnType(value.ReturnType);
+ }
+
+ public virtual VisitMethodReferenceCollection(value : IMethodReferenceCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitMethodReference(value[i]);
+ }
+
+ public virtual VisitMethodReferenceExpression(value : IMethodReferenceExpression) : void
+ {
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitMethodReturnStatement(value : IMethodReturnStatement) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitMethodReturnType(value : IMethodReturnType) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitType(value.Type);
+ }
+
+ public virtual VisitModule(value : IModule) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ }
+
+ public virtual VisitModuleCollection(value : IModuleCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitModule(value[i]);
+ }
+
+ public virtual VisitModuleReference(_ : IModuleReference) : void
+ {
+ }
+
+ public virtual VisitNamedArgumentExpression(value : INamedArgumentExpression) : void
+ {
+ VisitExpression(value.Value);
+ }
+
+ public virtual VisitNamespace(value : INamespace) : void
+ {
+ VisitTypeDeclarationCollection(value.Types);
+ }
+
+ public virtual VisitNullCoalescingExpression(value : INullCoalescingExpression) : void
+ {
+ VisitExpression(value.Condition);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitObjectCreateExpression(value : IObjectCreateExpression) : void
+ {
+ VisitExpressionCollection(value.Arguments);
+ }
+
+ public virtual VisitObjectInitializeExpression(value : IObjectInitializeExpression) : void
+ {
+ VisitType(value.Type);
+ }
+
+ public virtual VisitOptionalModifier(ty : IOptionalModifier) : void
+ {
+ VisitType(ty.Modifier);
+ VisitType(ty.ElementType);
+ }
+
+ public virtual VisitParameterDeclaration(value : IParameterDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitType(value.ParameterType);
+ VisitExpression(value.DefaultValue);
+ }
+
+ public virtual VisitParameterDeclarationCollection(value : IParameterDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitParameterDeclaration(value[i]);
+ }
+
+ public virtual VisitPointerType(value : IPointerType) : void
+ {
+ VisitType(value.ElementType);
+ }
+
+ public virtual VisitPropertyDeclaration(value : IPropertyDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitType(value.PropertyType);
+ }
+
+ public virtual VisitPropertyDeclarationCollection(value : IPropertyDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitPropertyDeclaration(value[i]);
+ }
+
+ public virtual VisitPropertyIndexerExpression(value : IPropertyIndexerExpression) : void
+ {
+ VisitExpressionCollection(value.Indices);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitPropertyReference(value : IPropertyReference) : void
+ {
+ VisitType(value.PropertyType);
+ }
+
+ public virtual VisitPropertyReferenceExpression(value : IPropertyReferenceExpression) : void
+ {
+ VisitPropertyReference(value.Property);
+ VisitExpression(value.Target);
+ }
+
+ public virtual VisitReferenceType(value : IReferenceType) : void
+ {
+ VisitType(value.ElementType);
+ }
+
+ public virtual VisitRemoveEventStatement(value : IRemoveEventStatement) : void
+ {
+ VisitExpression(value.Event);
+ VisitExpression(value.Listener);
+ }
+
+ public virtual VisitRequiredModifier(type_ : IRequiredModifier) : void
+ {
+ VisitType(type_.Modifier);
+ VisitType(type_.ElementType);
+ }
+
+ public virtual VisitResource(value : IResource) : void
+ {
+ | r is IEmbeddedResource => VisitEmbeddedResource(r);
+ | r is IFileResource => VisitFileResource (r);
+ | _ => throw NotSupportedException($"Invalid resource type '$(value.GetType().Name)'.");
+ }
+
+ public virtual VisitResourceCollection(value : IResourceCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitResource(value[i]);
+ }
+
+ public virtual VisitSizeOfExpression(value : ISizeOfExpression) : void
+ {
+ VisitType(value.Type);
+ }
+
+ public virtual VisitSnippetExpression(_ : ISnippetExpression) : void
+ {
+ }
+
+ public virtual VisitStackAllocateExpression(value : IStackAllocateExpression) : void
+ {
+ VisitType(value.Type);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitStatement(value : IStatement) : void
+ {
+ | e is IExpressionStatement => VisitExpressionStatement (e)
+ | e is IBlockStatement => VisitBlockStatement (e)
+ | e is IConditionStatement => VisitConditionStatement (e)
+ | e is IMethodReturnStatement => VisitMethodReturnStatement (e)
+ | e is ILabeledStatement => VisitLabeledStatement (e)
+ | e is IGotoStatement => VisitGotoStatement (e)
+ | e is IForStatement => VisitForStatement (e)
+ | e is IForEachStatement => VisitForEachStatement (e)
+ | e is IWhileStatement => VisitWhileStatement (e)
+ | e is IDoStatement => VisitDoStatement (e)
+ | e is ITryCatchFinallyStatement => VisitTryCatchFinallyStatement (e)
+ | e is IThrowExceptionStatement => VisitThrowExceptionStatement (e)
+ | e is IAttachEventStatement => VisitAttachEventStatement (e)
+ | e is IRemoveEventStatement => VisitRemoveEventStatement (e)
+ | e is ISwitchStatement => VisitSwitchStatement (e)
+ | e is IBreakStatement => VisitBreakStatement (e)
+ | e is IContinueStatement => VisitContinueStatement (e)
+ | e is ICommentStatement => VisitCommentStatement (e)
+ | e is IUsingStatement => VisitUsingStatement (e)
+ | e is IFixedStatement => VisitFixedStatement (e)
+ | e is ILockStatement => VisitLockStatement (e)
+ | e is IMemoryCopyStatement => VisitMemoryCopyStatement (e)
+ | e is IMemoryInitializeStatement => VisitMemoryInitializeStatement(e)
+ | _ => throw NotSupportedException($"Invalid statement type '$(value.GetType().Name)'.")
+ }
+
+ public virtual VisitStatementCollection(value : IStatementCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitStatement(value[i]);
+ }
+
+ public virtual VisitSwitchCase(value : ISwitchCase) : void
+ {
+ | c is IConditionCase => VisitConditionCase(c);
+ | c is IDefaultCase => VisitDefaultCase (c);
+ | _ => throw NotSupportedException($"Invalid switch case type '$(value.GetType().Name)'.");
+ }
+
+ public virtual VisitSwitchCaseCollection(value : ISwitchCaseCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitSwitchCase(value[i]);
+ }
+
+ public virtual VisitSwitchStatement(value : ISwitchStatement) : void
+ {
+ VisitExpression(value.Expression);
+ VisitSwitchCaseCollection(value.Cases);
+ }
+
+ public virtual VisitThisReferenceExpression(_ : IThisReferenceExpression) : void
+ {
+ }
+
+ public virtual VisitThrowExceptionStatement(value : IThrowExceptionStatement) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitTryCastExpression(value : ITryCastExpression) : void
+ {
+ VisitType(value.TargetType);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitTryCatchFinallyStatement(value : ITryCatchFinallyStatement) : void
+ {
+ VisitStatement(value.Try);
+ VisitCatchClauseCollection(value.CatchClauses);
+ VisitStatement(value.Finally);
+ VisitStatement(value.Fault);
+ }
+
+ public virtual VisitType(value : IType) : void
+ {
+ | t is ITypeReference => VisitTypeReference (t)
+ | t is IArrayType => VisitArrayType (t)
+ | t is IPointerType => VisitPointerType (t)
+ | t is IReferenceType => VisitReferenceType (t)
+ | t is IOptionalModifier => VisitOptionalModifier (t)
+ | t is IRequiredModifier => VisitRequiredModifier (t)
+ | t is IFunctionPointer => VisitFunctionPointer (t)
+ | t is IGenericParameter => VisitGenericParameter (t)
+ | t is IGenericArgument => VisitGenericArgument (t)
+ | _ => throw NotSupportedException($"Invalid type '$(value.GetType().Name)'.");
+ }
+
+ public virtual VisitTypeCollection(value : ITypeCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitType(value[i]);
+ }
+
+ public virtual VisitTypeDeclaration(value : ITypeDeclaration) : void
+ {
+ VisitCustomAttributeCollection(value.Attributes);
+ VisitMethodDeclarationCollection(value.Methods);
+ VisitFieldDeclarationCollection(value.Fields);
+ VisitPropertyDeclarationCollection(value.Properties);
+ VisitEventDeclarationCollection(value.Events);
+ VisitTypeDeclarationCollection(value.NestedTypes);
+ }
+
+ public virtual VisitTypeDeclarationCollection(value : ITypeDeclarationCollection) : void
+ {
+ for (mutable i = 0; i < value.Count; ++i)
+ VisitTypeDeclaration(value[i]);
+ }
+
+ public virtual VisitTypedReferenceCreateExpression(value : ITypedReferenceCreateExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitTypeOfExpression(value : ITypeOfExpression) : void
+ {
+ VisitType(value.Type);
+ }
+
+ public virtual VisitTypeOfTypedReferenceExpression(value : ITypeOfTypedReferenceExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitTypeReference(_ : ITypeReference) : void
+ {
+ }
+
+ public virtual VisitTypeReferenceExpression(value : ITypeReferenceExpression) : void
+ {
+ VisitType(value.Type);
+ }
+
+ public virtual VisitUnaryExpression(value : IUnaryExpression) : void
+ {
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitUsingStatement(value : IUsingStatement) : void
+ {
+ VisitExpression(value.Variable);
+ VisitExpression(value.Expression);
+ VisitStatement(value.Body);
+ }
+
+ public virtual VisitValueOfTypedReferenceExpression(value : IValueOfTypedReferenceExpression) : void
+ {
+ VisitType(value.TargetType);
+ VisitExpression(value.Expression);
+ }
+
+ public virtual VisitVariableDeclaration(value : IVariableDeclaration) : void
+ {
+ VisitType(value.VariableType);
+ }
+
+ public virtual VisitVariableDeclarationExpression(value : IVariableDeclarationExpression) : void
+ {
+ VisitVariableDeclaration(value.Variable);
+ }
+
+ public virtual VisitVariableReference(_ : IVariableReference) : void
+ {
+ }
+
+ public virtual VisitVariableReferenceExpression(value : IVariableReferenceExpression) : void
+ {
+ VisitVariableReference(value.Variable);
+ }
+
+ public virtual VisitWhileStatement(value : IWhileStatement) : void
+ {
+ VisitExpression(value.Condition);
+ VisitStatement(value.Body);
+ }
+ }
+}
+
+
Added: nemerle/trunk/tools/reflector-addon/src/CustomAttributeWrapper.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/CustomAttributeWrapper.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+using System.Diagnostics;
+using Nemerle.Collections;
+using Nemerle.Utility;
+
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal variant CustomAttributeWrapper
+ {
+ | Method
+ {
+ [Accessor] mutable _isExtension : bool;
+
+ public this(value : IMethodDeclaration)
+ {
+ Init(value.Attributes, attr =>
+ {
+ match (attr.Constructor.DeclaringType)
+ {
+ | t is ITypeReference =>
+ match (t.Namespace)
+ {
+ | "Nemerle.Internal" =>
+ match (t.Name)
+ {
+ | "ExtensionAttribute" => _isExtension = true
+ | other => Debug.Fail($"Attribute named '$other' was ignored")
+ }
+ true
+ | _ => false
+ }
+ | _ => false
+ }
+ }
+ );
+ }
+ }
+ | Type
+ {
+ [Accessor] mutable _isExtension : bool;
+ [Accessor] mutable _typeAlias : string;
+ [Accessor] mutable _isVariant : bool;
+ [Accessor] mutable _isVariantOption : bool;
+ [Accessor] mutable _isFlagsEnumeration : bool;
+
+ public this(value : ITypeDeclaration)
+ {
+ Init(value.Attributes, attr =>
+ {
+ match (attr.Constructor.DeclaringType)
+ {
+ | t is ITypeReference =>
+ match (t.Namespace)
+ {
+ | "Nemerle.Internal" =>
+ match (t.Name)
+ {
+ | "ExtensionAttribute" => _isExtension = true
+ | "TypeAliasAttribute"
+ when attr.Arguments.Count > 0 =>
+ match (attr.Arguments[0])
+ {
+ | literal is ILiteralExpression => _typeAlias = literal.Value.ToString()
+ | _ => Debug.Fail("TypeAliasAttribute first agrument is not a literal expression")
+ }
+ | "VariantAttribute" => _isVariant = true
+ | "ConstantVariantOptionAttribute"
+ | "VariantOptionAttribute" => _isVariantOption = true
+ | other => Debug.Fail($"Attribute named '$other' was ignored")
+ }
+ true
+ | "System" =>
+ match (t.Name)
+ {
+ | "FlagsAttribute" => _isFlagsEnumeration = true;
+ | _ => ()
+ }
+ false;
+ | _ => false
+ }
+ | _ => false
+ }
+ }
+ );
+ }
+ }
+
+ [Accessor] mutable _attributes : list[ICustomAttribute];
+
+ private Init
+ ( attributes : ICustomAttributeCollection
+ , filter : ICustomAttribute -> bool
+ ) : void
+ {
+ _attributes = [];
+
+ for (mutable i = 0; i < attributes.Count; ++i)
+ {
+ def attr = attributes[i];
+ unless (filter(attr))
+ _attributes ::= attr;
+ }
+ }
+ }
+}
\ No newline at end of file
Added: nemerle/trunk/tools/reflector-addon/src/Helper.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/Helper.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections;
+using System.IO;
+using Reflector;
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal module Helper
+ {
+ public IsConstructor(this value : IMethodReference) : bool
+ {
+ value.Name == ".ctor" || value.Name == ".cctor";
+ }
+
+ public IsInterface(this value : IType) : bool
+ {
+ | typeRef is ITypeReference =>
+ match (typeRef.Resolve())
+ {
+ | null => false;
+ | decl => decl.Interface;
+ }
+ | _ => false
+ }
+
+ public GetTypeName(this value : IType) : string * string
+ {
+ | typeRef is ITypeReference => (typeRef.Namespace, typeRef.Name)
+ | _ => (null, null)
+ }
+
+ public GetBaseTypeName(this value : ITypeReference) : string * string
+ {
+ | null => (null, null)
+ | _ =>
+ match (value.Resolve())
+ {
+ | null => (null, null)
+ | decl =>
+ GetTypeName(decl.BaseType)
+ }
+ }
+
+ public ToArray['a](this col : ICollection) : array['a]
+ {
+ | null => null
+ | _ =>
+ def ret = array(col.Count);
+ col.CopyTo(ret, 0);
+ ret;
+ }
+
+ public ToList['a](this col : ICollection) : list['a]
+ {
+ | null => null
+ | _ => Nemerle.Collections.List.FromArray(col.ToArray())
+ }
+
+ public Find['a]
+ ( this col : ICollection
+ , predicate :'a -> bool
+ ) : 'a
+ {
+ Array.Find(col.ToArray(), predicate);
+ }
+
+ public Iter['a]
+ ( this col : ICollection
+ , action :'a -> void
+ ) : void
+ {
+ Array.ForEach(col.ToArray(), action);
+ }
+
+ public GetName(this value : IType) : string
+ {
+ | typeRef is ITypeReference => GetName(typeRef);
+ | _ => null;
+ }
+
+ public GetName(this value : ITypeReference) : string
+ {
+ when (value == null)
+ throw NotSupportedException();
+
+ def genArgs = value.GenericArguments;
+ if (genArgs.Count > 0)
+ value.Name + genArgs.ToList().ToString();
+ else
+ value.Name;
+ }
+
+ public GetUserFriendlyName(this value : IType) : string
+ {
+ | typeRef is ITypeReference => GetUserFriendlyName(typeRef);
+ | _ => null;
+ }
+
+ public GetUserFriendlyName(this value : ITypeReference) : string
+ {
+ when (value == null)
+ throw NotSupportedException();
+
+ match (value.Owner)
+ {
+ | typeRef is ITypeReference =>
+ GetUserFriendlyName(typeRef) + "+" + GetName(value);
+ | _ =>
+ match (value.Namespace)
+ {
+ | null
+ | e when e.Length == 0 => GetName(value)
+ | ns => ns + "." + GetName(value)
+ }
+ }
+ }
+
+ public static GetVisibility(this value : IEventReference) : MethodVisibility
+ {
+ match (value.Resolve())
+ {
+ | null => MethodVisibility.Public
+ | decl => decl.GetVisibility();
+ }
+ }
+
+ public static GetVisibility(this value : IEventDeclaration) : MethodVisibility
+ {
+ def addMethod = if (value.AddMethod != null) value.AddMethod.Resolve() else null;
+ def removeMethod = if (value.RemoveMethod != null) value.RemoveMethod.Resolve() else null;
+ def invokeMethod = if (value.InvokeMethod != null) value.InvokeMethod.Resolve() else null;
+
+ match ((addMethod, removeMethod, invokeMethod))
+ {
+ | (null, null, null) => MethodVisibility.Public
+ | (a, null, null) => a.Visibility
+ | (null, r, null) => r.Visibility
+ | (null, null, i) => i.Visibility
+ | (a, r, null) when a.Visibility == r.Visibility => a.Visibility
+ | (a, null, i) when a.Visibility == i.Visibility => a.Visibility
+ | (null, r, i) when r.Visibility == i.Visibility => r.Visibility
+ | (a, r, i) when a.Visibility == r.Visibility
+ && r.Visibility == i.Visibility => a.Visibility
+ | _ => MethodVisibility.Public
+ }
+ }
+
+ public static GetVisibility(this value : IFieldReference) : FieldVisibility
+ {
+ match (value.Resolve())
+ {
+ | null => FieldVisibility.Public
+ | decl => decl.GetVisibility();
+ }
+ }
+
+ public static GetVisibility(this value : IFieldDeclaration) : FieldVisibility
+ {
+ value.Visibility
+ }
+
+ public static GetVisibility(this value : IMethodReference) : MethodVisibility
+ {
+ match (value.Resolve())
+ {
+ | null => MethodVisibility.Public
+ | decl => decl.GetVisibility();
+ }
+ }
+
+ public static GetVisibility(this value : IMethodDeclaration) : MethodVisibility
+ {
+ value.Visibility
+ }
+
+ public static GetVisibility(this value : IPropertyReference) : MethodVisibility
+ {
+ match (value.Resolve())
+ {
+ | null => MethodVisibility.Public
+ | decl => decl.GetVisibility();
+ }
+ }
+
+ public static GetVisibility(this value : IPropertyDeclaration) : MethodVisibility
+ {
+ def getMethod = if (value.GetMethod != null) value.GetMethod.Resolve() else null;
+ def setMethod = if (value.SetMethod != null) value.SetMethod.Resolve() else null;
+
+ match ((getMethod, setMethod))
+ {
+ | (null, null) => MethodVisibility.Public
+ | (g, null) => g.Visibility
+ | (null, s) => s.Visibility
+ | (g, s) when g.Visibility == s.Visibility => g.Visibility
+ | _ => MethodVisibility.Public
+ }
+ }
+
+ public static GetVisibility(this value : ITypeReference) : TypeVisibility
+ {
+ match (value.Resolve())
+ {
+ | null => TypeVisibility.Public
+ | decl => decl.GetVisibility();
+ }
+ }
+
+ public static GetVisibility(this value : ITypeDeclaration) : TypeVisibility
+ {
+ value.Visibility
+ }
+ }
+}
Added: nemerle/trunk/tools/reflector-addon/src/Language.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/Language.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal class Language : ILanguage
+ {
+ public GetWriter
+ ( formatter : IFormatter
+ , configuration : ILanguageWriterConfiguration
+ ) : ILanguageWriter
+ {
+ LanguageWriter(formatter, configuration);
+ }
+
+ public FileExtension : string
+ {
+ get { ".n" }
+ }
+
+ public Name : string
+ {
+ get { "Nemerle" }
+ }
+
+ public Translate : bool
+ {
+ get { false }
+ }
+ }
+}
Added: nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/LanguageWriter.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,1145 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using Nemerle.Assertions;
+using Nemerle.Collections;
+using Nemerle.Internal;
+
+using Reflector.CodeModel;
+using Reflector.CodeModel.Memory;
+using Reflector.NemerleLanguage.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal class LanguageWriter : LanguageWritterBase
+ {
+ _configuration : LanguageWriterConfiguration;
+
+ public this
+ ( formatter : IFormatter
+ , configuration : ILanguageWriterConfiguration
+ )
+ {
+ base(formatter);
+ _configuration = LanguageWriterConfiguration(configuration);
+ }
+
+ #region Module
+
+ public override WriteAssembly([NotNull] value : IAssembly) : void
+ {
+ Write("// Assembly ");
+ WriteDeclaration(value.Name);
+ when (value.Version != null)
+ Write($", Version $(value.Version)");
+
+ WriteLine();
+
+ WriteCustomAttributeList(value.Attributes.ToList(), "assembly");
+
+ WriteProperty("Location", value.Location);
+ WriteProperty("Name", value.ToString());
+ WriteProperty("Type",
+ match(value.Type)
+ {
+ | AssemblyType.Console => "Console Application"
+ | AssemblyType.Application => "Windows Application"
+ | AssemblyType.Library => "Class Library"
+ | _ => "<Unknown>"
+ }
+ );
+ }
+
+ public override WriteAssemblyReference([NotNull] value : IAssemblyReference) : void
+ {
+ Write("// Assembly Reference ");
+ WriteDeclaration(value.Name);
+ WriteLine();
+ WriteProperty("Version", value.Version.ToString());
+ WriteProperty("Name", value.ToString());
+ }
+
+ public override WriteModule([NotNull] value : IModule) : void
+ {
+ Write("// Module ");
+ WriteDeclaration(value.Name);
+ WriteLine();
+
+ WriteCustomAttributeList(value.Attributes.ToList(), "module");
+
+ WriteProperty("Version", value.Version.ToString());
+ WriteProperty("Location", value.Location);
+ def loc = Environment.ExpandEnvironmentVariables(value.Location);
+ when (File.Exists(loc))
+ WriteProperty("Size", $"$(FileInfo(loc).Length) Bytes");
+ }
+
+ public override WriteModuleReference([NotNull] value : IModuleReference) : void
+ {
+ Write("// Module reference ");
+ WriteDeclaration(value.Name);
+ WriteLine();
+ }
+
+ public override WriteNamespace([NotNull] value : INamespace) : void
+ {
+ def global = string.IsNullOrEmpty(value.Name);
+ unless (global)
+ {
+ WriteKeyword("namespace");
+ Write(" ");
+ WriteDeclaration(value.Name);
+ }
+
+ when (_configuration.ShowNamespaceBody)
+ {
+ unless (global)
+ {
+ WriteLine();
+ WriteLine("{");
+ WriteIndent();
+ }
+
+ when (_configuration.ShowNamespaceImports)
+ {
+ def visitor = UsingNamespaceVisitor();
+ visitor.VisitNamespace(value);
+
+ mutable foundAny = false;
+ visitor.Namespaces.Sort(string.Compare).Iter(ns =>
+ unless (string.IsNullOrEmpty(ns))
+ {
+ WriteKeyword("using");
+ Write(" ");
+ Write(ns);
+ WriteLine(";");
+ foundAny = true;
+ });
+
+ when (foundAny)
+ WriteLine();
+ }
+
+ mutable visibleTypes = [];
+
+ foreach (tyDecl is ITypeDeclaration in value.Types)
+ when (_configuration.IsVisible(tyDecl))
+ visibleTypes ::= tyDecl;
+
+ visibleTypes.Sort((x, y) => string.Compare(x.Name, y.Name)).Iter(ty =>
+ {
+ WriteTypeDeclaration(ty);
+ WriteLine();
+
+ // An extra line for readability
+ //
+ WriteLine();
+ });
+
+ unless (global)
+ {
+ WriteOutdent();
+ WriteLine("}");
+ }
+ }
+ }
+
+ public override WriteResource(value : IResource) : void {}
+ public override WriteStatement(value : IStatement) : void {}
+
+ #endregion
+
+ #region WriteExpression
+
+ public override WriteExpression(value : IExpression) : void
+ {
+ | expr is ILiteralExpression => WriteLiteralExpression(expr);
+ | expr is IAssignExpression => WriteAssignExpression(expr);
+ | expr is ITypeOfExpression => WriteTypeOfExpression(expr);
+ | expr is INamedArgumentExpression => WriteNamedArgumentExpression(expr);
+ | expr is ITypeReferenceExpression => WriteTypeReferenceExpression(expr);
+ | expr is IFieldReferenceExpression => WriteFieldReferenceExpression(expr);
+ | expr is IEventReferenceExpression => WriteEventReferenceExpression(expr);
+ | expr is IMethodReferenceExpression => WriteMethodReferenceExpression(expr);
+ | expr is IArgumentListExpression => WriteArgumentListExpression(expr);
+ | expr is IStackAllocateExpression => WriteStackAllocateExpression(expr);
+ | expr is IPropertyReferenceExpression => WritePropertyReferenceExpression(expr);
+ | expr is IArrayCreateExpression => WriteArrayCreateExpression(expr);
+ | expr is IArrayInitializerExpression => WriteArrayInitializerExpression(expr);
+ | expr is IBaseReferenceExpression => WriteBaseReferenceExpression(expr);
+ | expr is IUnaryExpression => WriteUnaryExpression(expr);
+ | expr is IBinaryExpression => WriteBinaryExpression(expr);
+ | expr is ITryCastExpression => WriteTryCastExpression(expr);
+ | expr is ICanCastExpression => WriteCanCastExpression(expr);
+ | expr is ICastExpression => WriteCastExpression(expr);
+ | expr is IConditionExpression => WriteConditionExpression(expr);
+ | expr is INullCoalescingExpression => WriteNullCoalescingExpression(expr);
+ | expr is IDelegateCreateExpression => WriteDelegateCreateExpression(expr);
+ | expr is IArgumentReferenceExpression => WriteArgumentReferenceExpression(expr);
+ | expr is IVariableDeclarationExpression => WriteVariableDeclarationExpression(expr);
+ | expr is IVariableReferenceExpression => WriteVariableReferenceExpression(expr);
+ | expr is IPropertyIndexerExpression => WritePropertyIndexerExpression(expr);
+ | expr is IArrayIndexerExpression => WriteArrayIndexerExpression(expr);
+ | expr is IMethodInvokeExpression => WriteMethodInvokeExpression(expr);
+ | expr is IDelegateInvokeExpression => WriteDelegateInvokeExpression(expr);
+ | expr is IObjectCreateExpression => WriteObjectCreateExpression(expr);
+ | expr is IThisReferenceExpression => WriteThisReferenceExpression(expr);
+ | expr is IAddressOfExpression => WriteAddressOfExpression(expr);
+ | expr is IAddressOutExpression => WriteAddressOutExpression(expr);
+ | expr is IAddressReferenceExpression => WriteAddressReferenceExpression(expr);
+ | expr is IAddressDereferenceExpression => WriteAddressDereferenceExpression(expr);
+ | expr is ISizeOfExpression => WriteSizeOfExpression(expr);
+ | expr is IGenericDefaultExpression => WriteGenericDefaultExpression(expr);
+ | expr is ITypeOfTypedReferenceExpression => WriteTypeOfTypedReferenceExpression(expr);
+ | expr is IValueOfTypedReferenceExpression => WriteValueOfTypedReferenceExpression(expr);
+ | expr is ITypedReferenceCreateExpression => WriteTypedReferenceCreateExpression(expr);
+ | expr is IObjectInitializeExpression => WriteObjectInitializeExpression(expr);
+ | expr is ISnippetExpression => WriteSnippetExpression(expr);
+ | null => throw ArgumentNullException("expression");
+ | _ => throw NotImplementedException();
+ }
+
+ private WriteLiteralExpression(expression : ILiteralExpression) : void
+ {
+ //TODO: escape special characters such a \r,\n,\t
+ match (expression.Value)
+ {
+ | str is string => WriteLiteral($"\"$str\"")
+ | chr is char => WriteLiteral($"'$chr'")
+ | null => WriteLiteral("null");
+ | other => WriteLiteral(Convert.ToString(other, CultureInfo.InvariantCulture))
+ }
+ }
+
+ private WriteAssignExpression(expr : IAssignExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteTypeOfExpression(expr : ITypeOfExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteNamedArgumentExpression(expr : INamedArgumentExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteTypeReferenceExpression(expr : ITypeReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteFieldReferenceExpression(expr : IFieldReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteEventReferenceExpression(expr : IEventReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteMethodReferenceExpression(expr : IMethodReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteArgumentListExpression(expr : IArgumentListExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteStackAllocateExpression(expr : IStackAllocateExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WritePropertyReferenceExpression(expr : IPropertyReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteArrayCreateExpression(expr : IArrayCreateExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteArrayInitializerExpression(expr : IArrayInitializerExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteBaseReferenceExpression(expr : IBaseReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteUnaryExpression(expr : IUnaryExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteBinaryExpression(expr : IBinaryExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteTryCastExpression(expr : ITryCastExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteCanCastExpression(expr : ICanCastExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteCastExpression(expr : ICastExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteConditionExpression(expr : IConditionExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteNullCoalescingExpression(expr : INullCoalescingExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteDelegateCreateExpression(expr : IDelegateCreateExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteArgumentReferenceExpression(expr : IArgumentReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteVariableDeclarationExpression(expr : IVariableDeclarationExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteVariableReferenceExpression(expr : IVariableReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WritePropertyIndexerExpression(expr : IPropertyIndexerExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteArrayIndexerExpression(expr : IArrayIndexerExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteMethodInvokeExpression(expr : IMethodInvokeExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteDelegateInvokeExpression(expr : IDelegateInvokeExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteObjectCreateExpression(expr : IObjectCreateExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteThisReferenceExpression(expr : IThisReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteAddressOfExpression(expr : IAddressOfExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteAddressOutExpression(expr : IAddressOutExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteAddressReferenceExpression(expr : IAddressReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteAddressDereferenceExpression(expr : IAddressDereferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteSizeOfExpression(expr : ISizeOfExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteGenericDefaultExpression(expr : IGenericDefaultExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteTypeOfTypedReferenceExpression(expr : ITypeOfTypedReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteValueOfTypedReferenceExpression(expr : IValueOfTypedReferenceExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteTypedReferenceCreateExpression(expr : ITypedReferenceCreateExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteObjectInitializeExpression(expr : IObjectInitializeExpression) : void { WriteLiteral($"$(expr.ToString())") }
+ private WriteSnippetExpression(expr : ISnippetExpression) : void { WriteLiteral($"$(expr.ToString())") }
+
+ #endregion
+
+ #region Type members
+
+ public override WriteEventDeclaration([NotNull] value : IEventDeclaration) : void
+ {
+ WriteDocumentation(value);
+ WriteCustomAttributeList(value.Attributes.ToList());
+
+ unless (value.DeclaringType.IsInterface())
+ WriteMethodVisibility(value.GetVisibility());
+
+ WriteKeyword("event");
+ Write(" ");
+ WriteDeclaration(value.Name);
+ Write(" : ");
+ WriteType(value.EventType);
+ WriteLine(";");
+ }
+
+ public override WriteFieldDeclaration(value : IFieldDeclaration) : void
+ {
+ WriteDocumentation(value);
+ WriteCustomAttributeList(value.Attributes.ToList());
+
+ match (value.GetVisibility())
+ {
+ | FieldVisibility.Private => WriteKeyword("private");
+ | FieldVisibility.PrivateScope => WriteComment("/* private scope */");
+ | FieldVisibility.FamilyAndAssembly => WriteKeyword("protected internal");
+ | FieldVisibility.Assembly => WriteKeyword("internal");
+ | FieldVisibility.Family => WriteKeyword("protected");
+ | FieldVisibility.FamilyOrAssembly => WriteKeyword("internal protected");
+ | FieldVisibility.Public => WriteKeyword("public");
+ | _ => throw NotSupportedException()
+ }
+
+ Write(" ");
+
+ when (value.Static)
+ {
+ if (value.Literal)
+ WriteKeyword("const");
+ else
+ WriteKeyword("static");
+ Write(" ");
+ }
+
+ unless (value.ReadOnly || value.Literal)
+ {
+ WriteKeyword("mutable");
+ Write(" ");
+ }
+
+ WriteDeclaration(value.Name);
+
+ Write(" : ");
+ WriteType(value.FieldType);
+
+ unless (value.Initializer == null)
+ {
+ Write(" = ");
+ WriteExpression(value.Initializer);
+ }
+
+ WriteLine(";");
+ }
+
+ public override WriteMethodDeclaration(value : IMethodDeclaration) : void
+ {
+ def wrapper = CustomAttributeWrapper.Method(value);
+ WriteDocumentation(value);
+ WriteCustomAttributeList(wrapper.Attributes);
+ WriteCustomAttributeList(value.ReturnType.Attributes.ToList(), "return");
+
+ unless (value.DeclaringType.IsInterface())
+ WriteMethodVisibility(value.GetVisibility());
+
+ when (value.Static)
+ {
+ WriteKeyword("static");
+ Write(" ");
+ }
+
+ if (value.IsConstructor())
+ {
+ WriteKeyword("this");
+ Write("(");
+ WriteList(value.Parameters.ToList(), WriteParameterDeclaration);
+ Write(")");
+ }
+ else
+ {
+ def genArgs = value.GenericArguments.ToList();
+ WriteDeclaration(value.Name);
+ WriteList(genArgs, "[", "]", WriteType);
+ Write("(");
+ when (value.Static && wrapper.IsExtension)
+ {
+ WriteKeyword("this");
+ Write(" ");
+ }
+ WriteList(value.Parameters.ToList(), WriteParameterDeclaration);
+ Write(")");
+ Write(" : ");
+ WriteType(value.ReturnType.Type);
+ WriteGenericParameterConstraintList(genArgs);
+
+ def overrides = value.Overrides.ToList();
+ unless (overrides.IsEmpty)
+ {
+ Write(" ");
+ WriteKeyword("implements");
+ Write(" ");
+ WriteList(overrides, WriteMethodReference);
+ }
+ }
+ WriteLine(";");
+ }
+
+ public override WritePropertyDeclaration(value : IPropertyDeclaration) : void
+ {
+ WriteDocumentation(value);
+ WriteCustomAttributeList(value.Attributes.ToList());
+
+ def getMethod = if (value.GetMethod != null) value.GetMethod.Resolve() else null;
+ def setMethod = if (value.SetMethod != null) value.SetMethod.Resolve() else null;
+
+ def isInterface = value.DeclaringType.IsInterface();
+ def propVisibility = value.GetVisibility();
+
+ unless (isInterface)
+ WriteMethodVisibility(propVisibility);
+
+ WriteDeclaration(value.Name);
+ WriteList(value.Parameters.ToList(), "[", "]", WriteParameterDeclaration);
+ Write(" : ");
+ WriteType(value.PropertyType);
+
+ unless (getMethod == null && setMethod == null)
+ {
+ Write(" { ");
+
+ unless (getMethod == null)
+ {
+ WriteList(getMethod.Attributes.ToList(), "[", "] ", WriteCustomAttribute);
+
+ unless (isInterface || propVisibility == getMethod.GetVisibility())
+ WriteMethodVisibility(getMethod.GetVisibility());
+
+ WriteKeyword("get");
+ Write("; ");
+ }
+
+ unless (setMethod == null)
+ {
+ WriteList(setMethod.Attributes.ToList(), "[", "] ", WriteCustomAttribute);
+
+ unless (isInterface || propVisibility == getMethod.GetVisibility())
+ WriteMethodVisibility(setMethod.GetVisibility());
+
+ WriteKeyword("set");
+ Write("; ");
+ }
+
+ Write("}");
+ }
+ WriteLine();
+ }
+
+ #endregion
+
+ #region WriteTypeDeclaration
+
+ public override WriteTypeDeclaration([NotNull] value : ITypeDeclaration) : void
+ {
+ unless (value.Namespace.Length == 0 && value.Name == "<Module>")
+ {
+ def wrapper = CustomAttributeWrapper.Type(value);
+ WriteDocumentation(value);
+ WriteCustomAttributeList(wrapper.Attributes);
+
+ // Variant options has the same access as the outer variant.
+ //
+ unless (wrapper.IsVariantOption)
+ {
+ WriteKeyword(
+ match (value.Visibility)
+ {
+ | TypeVisibility.Private
+ | TypeVisibility.NestedAssembly => "internal"
+ | TypeVisibility.Public
+ | TypeVisibility.NestedPublic => "public"
+ | TypeVisibility.NestedPrivate => "private"
+ | TypeVisibility.NestedFamily => "protected"
+ | TypeVisibility.NestedFamilyAndAssembly => "protected internal"
+ | TypeVisibility.NestedFamilyOrAssembly => "internal protected"
+ | _ => throw NotSupportedException()
+ });
+ Write(" ");
+ }
+
+ match (value.GetBaseTypeName())
+ {
+ | ("System", "Delegate")
+ | ("System", "MulticastDelegate") => WriteDelegateDeclaration(value)
+ | ("System", "Enum") => WriteEnumDeclaration(value, wrapper)
+ | ("System", "ValueType") => WriteTypeDeclaration(value, "struct")
+ | _ =>
+ if (value.Interface)
+ if (wrapper.TypeAlias != null)
+ WriteTypeAliasDeclaration(value, wrapper)
+ else
+ WriteTypeDeclaration(value, "interface")
+ else if (value.Abstract)
+ if (value.Sealed)
+ WriteTypeDeclaration(value, "module")
+ else if (wrapper.IsVariant)
+ WriteTypeDeclaration(value, "variant")
+ else
+ {
+ WriteKeyword("abstract");
+ Write(" ");
+ WriteTypeDeclaration(value, "class")
+ }
+ else if (value.Sealed)
+ if (wrapper.IsVariantOption)
+ WriteTypeDeclaration(value, "|")
+ else
+ {
+ WriteKeyword("sealed");
+ Write(" ");
+ WriteTypeDeclaration(value, "class")
+ }
+ else
+ WriteTypeDeclaration(value, "class")
+ }
+ }
+ }
+
+ private WriteDelegateDeclaration(value : ITypeDeclaration) : void
+ {
+ WriteKeyword("delegate");
+ Write(" ");
+ def decl = value.Methods.Find(m : IMethodDeclaration => m.Name == "Invoke");
+ if (decl != null)
+ {
+ def genArgs = value.GenericArguments.ToList();
+ WriteDeclaration(value.Name);
+ WriteList(genArgs, "[", "]", WriteType);
+ Write("(");
+ WriteList(decl.Parameters.ToList(), WriteParameterDeclaration);
+ Write(")");
+ Write(" : ");
+ WriteType(decl.ReturnType.Type);
+ WriteGenericParameterConstraintList(genArgs);
+ }
+ else
+ {
+ Debug.WriteLine($"Invoke method not found for delegate '$(value.GetUserFriendlyName())'");
+ WriteDeclaration(value.Name);
+ }
+
+ Write(";");
+ }
+
+ private WriteEnumDeclaration
+ ( value : ITypeDeclaration
+ , wrapper : CustomAttributeWrapper.Type
+ ) : void
+ {
+ WriteKeyword("enum");
+ Write(" ");
+ WriteDeclaration(value.Name);
+
+ // Usually, the first enum field is the enum underlying type.
+ // The rest is the enum values.
+ //
+ def underliyngTypeField = value.Fields.Find(f : IFieldDeclaration =>
+ f.SpecialName && f.RuntimeSpecialName && !f.FieldType.Equals(value));
+
+ when (underliyngTypeField != null)
+ {
+ def (ns, name) = underliyngTypeField.FieldType.GetTypeName();
+
+ // int is the default enum type. So hide them.
+ //
+ unless (ns == "System" && name == "Int32")
+ {
+ Write(" : ");
+ WriteType(underliyngTypeField.FieldType)
+ }
+ }
+
+ // Enum can contain only fields (values).
+ // No events/methods/properties.
+ //
+ when (_configuration.ShowTypeDeclarationBody)
+ {
+ WriteLine();
+ WriteLine("{");
+ WriteOptionIndent();
+
+ mutable expectedValue = 0L;
+ value.Fields.Iter(f : IFieldDeclaration =>
+ {
+ unless (f.SpecialName && f.RuntimeSpecialName && !f.FieldType.Equals(value))
+ {
+ Write("| ");
+ WriteDeclaration(f.Name);
+
+ // Initializer optimization.
+ // Do not write redundant initializers.
+ // Also [FlagsAttribute] marked enum values are written in hex.
+ //
+ def suppressInitializer =
+ match (f.Initializer)
+ {
+ | literal is ILiteralExpression =>
+ if (wrapper.IsFlagsEnumeration)
+ {
+ match (literal.Value)
+ {
+ | fmt is IFormattable =>
+ Write(" = ");
+ WriteLiteral("0x" + fmt.ToString("X2", CultureInfo.InvariantCulture));
+ true
+ | _ => false
+ }
+ }
+ else
+ {
+ match (literal.Value)
+ {
+ | cvt is IConvertible =>
+ try
+ {
+ def actualValue = cvt.ToInt64(CultureInfo.InvariantCulture);
+ def same = (actualValue == expectedValue);
+ expectedValue = actualValue + 1;
+ same
+ }
+ catch
+ {
+ | _ =>
+ // On error turn off the optimization.
+ //
+ expectedValue = 0;
+ false
+ }
+ | _ => false
+ }
+ }
+ | null => true
+ | _ => false
+ }
+
+ unless (suppressInitializer)
+ {
+ Write(" = ");
+ WriteExpression(f.Initializer);
+ }
+
+ WriteLine();
+ }
+ });
+
+ WriteOptionOutdent();
+ Write("}");
+ }
+ }
+
+ private WriteTypeAliasDeclaration
+ ( value : ITypeDeclaration
+ , wrapper : CustomAttributeWrapper.Type
+ ) : void
+ {
+ // TODO: Decode alias string to real type name and generic parameters
+ // See ncc\external\Codec.n for details
+ //
+ def alias = wrapper.TypeAlias;
+ def dotIndex = alias.LastIndexOf('.');
+ def typeRef = TypeReference();
+
+ if (dotIndex > 0)
+ {
+ typeRef.Namespace = alias.Substring(0, dotIndex);
+ typeRef.Name = alias.Substring(dotIndex + 1);
+ }
+ else
+ typeRef.Name = alias;
+
+ WriteKeyword("type");
+ Write(" ");
+
+ WriteDeclaration(value.Name);
+ Write(" = ");
+
+ WriteReference(alias, alias, typeRef);
+ Write(";");
+ }
+
+ private WriteTypeDeclaration
+ ( value : ITypeDeclaration
+ , keyword : string
+ ) : void
+ {
+ WriteKeyword(keyword);
+ Write(" ");
+
+ def genArgs = value.GenericArguments.ToList();
+ WriteDeclaration(value.Name);
+
+ // Skip variant option base type, generic arguments and constraints.
+ //
+ unless (keyword == "|")
+ {
+ WriteList(genArgs, "[", "]", WriteType);
+
+ def baseTypes =
+ match (value.GetBaseTypeName())
+ {
+ | (null, null)
+ | ("System", "Object")
+ | ("System", "ValueType") => value.Interfaces.ToList();
+ | _ => value.BaseType :: value.Interfaces.ToList();
+ }
+
+ WriteList(baseTypes, " : ", null, WriteType);
+ WriteGenericParameterConstraintList(genArgs);
+ }
+
+ when (_configuration.ShowTypeDeclarationBody)
+ {
+ WriteLine();
+ WriteLine("{");
+ WriteIndent();
+
+ def events = value.Events .ToList().Filter(e => !e.RuntimeSpecialName);
+ def fields = value.Fields .ToList().Filter(e => !e.Name.StartsWith("_N_") && !e.RuntimeSpecialName);
+ def innerTypes = value.NestedTypes.ToList().Filter(e => !e.Name.StartsWith("_N_"));
+ def properties = value.Properties .ToList().Filter(e => !e.Name.StartsWith("_N_"));
+ mutable methods = value.Methods .ToList().Filter(e => !e.Name.StartsWith("_N_"));
+
+ events.Iter(e : IEventDeclaration =>
+ {
+ unless (e.AddMethod == null)
+ methods = methods.Remove(e.AddMethod.Resolve());
+ unless (e.RemoveMethod == null)
+ methods = methods.Remove(e.RemoveMethod.Resolve());
+ unless (e.InvokeMethod == null)
+ methods = methods.Remove(e.InvokeMethod.Resolve());
+ });
+
+ properties.Iter(e : IPropertyDeclaration =>
+ {
+ unless (e.GetMethod == null)
+ methods = methods.Remove(e.GetMethod.Resolve());
+ unless (e.SetMethod == null)
+ methods = methods.Remove(e.SetMethod.Resolve());
+ });
+
+ innerTypes.Iter(t : ITypeDeclaration => WriteTypeDeclaration(t));
+
+ WriteMembersDeclaration(events, "Events", WriteEventDeclaration);
+ WriteMembersDeclaration(fields, "Fields", WriteFieldDeclaration);
+ WriteMembersDeclaration(methods, "Methods", WriteMethodDeclaration);
+ WriteMembersDeclaration(properties, "Properties", WritePropertyDeclaration);
+ }
+
+ WriteOutdent();
+ WriteLine("}");
+ }
+
+ private WriteMembersDeclaration['a](lst : list['a], name : string, writer : 'a -> void) : void
+ {
+ unless (lst.IsEmpty)
+ {
+ WriteKeyword("#region");
+ Write(" ");
+ WriteLine(name);
+ WriteLine();
+
+ lst.Iter(writer);
+
+ WriteLine();
+ WriteKeyword("#endregion");
+ WriteLine();
+ WriteLine();
+ }
+ }
+
+ #endregion
+
+ #region Helpers
+
+ private WriteMethodReference(value : IMethodReference) : void
+ {
+ def ty = value.DeclaringType;
+
+ def name =
+ if (value.IsConstructor())
+ ty.GetName();
+ else
+ ty.GetName() + "." + value.Name;
+
+ WriteReference(name, ty.GetUserFriendlyName() + "." + value.Name, value);
+ }
+
+ private WriteType(value : IType) : void
+ {
+ | typeRef is ITypeReference =>
+ match (typeRef.GetTypeName())
+ {
+ | ("Nemerle.Builtins", "Tuple") =>
+ WriteList(typeRef.GenericArguments.ToList(), "(", ")", " * ", WriteType);
+ | ("Nemerle.Builtins", "Function") =>
+ def (genArgs, retType) = typeRef.GenericArguments.ToList().DivideLast();
+ WriteList(genArgs, null, " -> ", " * ", WriteType);
+ WriteType(retType);
+ | ("Nemerle.Builtins", "FunctionVoid") =>
+ WriteList(typeRef.GenericArguments.ToList(), null, " -> ", " * ", WriteType);
+
+ // Extract the return type from the type itself.
+ // We need a reference, not a name.
+ //
+ def found =
+ match (typeRef.Resolve())
+ {
+ | null => false;
+ | d =>
+ match (d.Methods.Find(m : IMethodDeclaration => m.Name == "apply_void"))
+ {
+ | null => false;
+ | m => WriteType(m.ReturnType.Type); true;
+ }
+ }
+
+ unless (found)
+ WriteKeyword("void");
+ | _ =>
+ def name = Helper.GetUserFriendlyName(typeRef);
+ WriteTypeReference(typeRef, name, typeRef);
+ WriteList(typeRef.GenericArguments.ToList(), "[", "]", WriteType);
+ }
+
+ | arrType is IArrayType =>
+ WriteKeyword("array");
+ Write("[");
+
+ def dims = arrType.Dimensions;
+ when (dims.Count > 1)
+ {
+ WriteLiteral(dims.Count.ToString(CultureInfo.InvariantCulture));
+ Write(", ");
+ }
+
+ for (mutable i = 0; i < dims.Count; ++i)
+ {
+ def dim = dims[i];
+ when (dim.LowerBound > 0)
+ WriteComment($"/* Dim $i LowerBound = $(dim.LowerBound)*/");
+ when (dim.UpperBound != -1)
+ WriteComment($"/* Dim $i UpperBound = $(dim.UpperBound)*/");
+ }
+
+ WriteType(arrType.ElementType);
+ Write("]");
+
+ | ptrType is IPointerType =>
+ WriteType(ptrType.ElementType);
+ Write("*");
+
+ | refType is IReferenceType =>
+ WriteKeyword("ref");
+ Write(" ");
+ WriteType(refType.ElementType);
+
+ | modOpt is IOptionalModifier =>
+ WriteType(modOpt.ElementType);
+ Write(" ");
+ WriteKeyword("modopt");
+ Write("(");
+ WriteType(modOpt.Modifier);
+ Write(")");
+
+ | modReq is IRequiredModifier =>
+ match (modReq.Modifier)
+ {
+ | typeRef when typeRef != null
+ && typeRef.Namespace == "System.Runtime.CompilerServices"
+ && typeRef.Name == "IsVolatile" =>
+ WriteKeyword("volatile");
+ Write(" ");
+ WriteType(modReq.ElementType);
+ | _ =>
+ WriteType(modReq.ElementType);
+ Write(" ");
+ WriteKeyword("modreq");
+ Write("(");
+ WriteType(modReq.Modifier);
+ Write(")");
+ }
+
+ | funPtr is IFunctionPointer =>
+ WriteType(funPtr.ReturnType.Type);
+ Write(" *(");
+ for (mutable i = 0; i < funPtr.Parameters.Count; ++i)
+ {
+ when (i != 0)
+ Write(", ");
+
+ WriteType(funPtr.Parameters[i].ParameterType);
+ }
+ Write(")");
+
+ | genParm is IGenericParameter =>
+ WriteDeclaration(genParm.Name);
+
+ | genArg is IGenericArgument =>
+ match (genArg.Resolve())
+ {
+ | genParm is IGenericParameter =>
+ def name = genParm.Name + " // Generic Argument";
+ WriteReference(genParm.Name, name, null);
+ | other => WriteType(other)
+ }
+
+ | _ =>
+ throw NotSupportedException($"Unknown kind of type '$(value.GetType().Name)'.");
+ }
+
+ private WriteCustomAttribute(value : ICustomAttribute) : void
+ {
+ def ty = value.Constructor.DeclaringType;
+ def typeName = ty.GetName();
+
+ WriteReference(
+ {
+ if (typeName.EndsWith("Attribute"))
+ typeName.Substring(0, typeName.Length - 9);
+ else
+ typeName;
+ }, ty.GetUserFriendlyName(), value.Constructor);
+
+ WriteList(value.Arguments.ToList(), "(", ")", WriteExpression);
+ }
+
+ private WriteCustomAttributeList
+ ( attrs : list[ICustomAttribute]
+ ) : void
+ {
+ WriteCustomAttributeList(attrs, null)
+ }
+
+ private WriteCustomAttributeList
+ ( attrs : list[ICustomAttribute]
+ , target : string
+ ) : void
+ {
+ when (_configuration.ShowCustomAttributes && !attrs.IsEmpty)
+ {
+ if (target != null)
+ {
+ attrs.Iter(attr =>
+ {
+ Write("[");
+ WriteKeyword(target);
+ Write(": ");
+ WriteCustomAttribute(attr);
+ WriteLine("]");
+ })
+ }
+ else
+ WriteList(attrs, "[", "]", WriteCustomAttribute);
+ WriteLine();
+ }
+ }
+
+ private WriteOptionIndent() : void
+ {
+ when (_configuration.OptionIndent)
+ WriteIndent();
+ }
+
+ private WriteOptionOutdent() : void
+ {
+ when (_configuration.OptionIndent)
+ WriteOutdent();
+ }
+
+ private WriteDocumentation(value : IDocumentationProvider ) : void
+ {
+ when (_configuration.ShowDocumentation)
+ {
+ def doc = value.Documentation;
+ unless (string.IsNullOrEmpty(doc))
+ {
+ using (rdr = StringReader(doc))
+ {
+ while (rdr.Peek() != -1)
+ {
+ def line = rdr.ReadLine();
+ WriteComment("/// ");
+ WriteComment(line);
+ WriteLine();
+ }
+ }
+ }
+ }
+ }
+
+ private WriteGenericParameterConstraint(value : IType) : void
+ {
+ | _ is IDefaultConstructorConstraint =>
+ WriteKeyword("new");
+ Write("()");
+ | _ is IReferenceTypeConstraint =>
+ WriteKeyword("class");
+ | _ is IValueTypeConstraint =>
+ WriteKeyword("struct");
+ | _ =>
+ WriteType(value);
+ }
+
+ private WriteGenericParameterConstraintList(lst : list[IType]) : void
+ {
+ lst.Iter(e =>
+ {
+ | p is IGenericParameter when p.Constraints.Count != 0 =>
+ Write(" ");
+ WriteKeyword("where");
+ Write(" ");
+ Write(p.Name);
+ Write(" : ");
+
+ WriteList(p.Constraints.ToList(), WriteGenericParameterConstraint);
+ | _ => ()
+ }
+ );
+ }
+
+ private WriteParameterDeclaration(value : IParameterDeclaration ) : void
+ {
+ WriteList(value.Attributes.ToList(), "[", "] ", WriteCustomAttribute);
+ // TODO: out/ref, parms; default value
+ def name = if (value.Name.StartsWith("_N_")) "_" else value.Name;
+ WriteIdentifier(name);
+ Write(" : ");
+ WriteType(value.ParameterType);
+ }
+
+ private WriteMethodVisibility(value : MethodVisibility) : void
+ {
+ WriteKeyword(
+ match (value)
+ {
+ | MethodVisibility.Private
+ | MethodVisibility.PrivateScope => "private"
+ | MethodVisibility.FamilyAndAssembly => "protected internal"
+ | MethodVisibility.Assembly => "internal"
+ | MethodVisibility.Family => "protected"
+ | MethodVisibility.FamilyOrAssembly => "internal protected"
+ | MethodVisibility.Public => "public"
+ | _ => throw NotSupportedException()
+ });
+ Write(" ");
+ }
+
+ #endregion
+
+ #region Keywords
+
+ protected override EscapeKeyword(value : string) : string
+ {
+ "@" + value;
+ }
+
+ protected override GetKeywords() : Set[string]
+ {
+ Set(
+ [ "abort", "abstract", "and", "array", "as", "assert"
+ , "base"
+ , "catch", "class"
+ , "def", "delegate", "do"
+ , "else", "enum", "event", "extends", "extern"
+ , "false", "finally", "for", "foreach", "fun"
+ , "if", "ignore", "implements", "in", "interface", "internal"
+ , "lock"
+ , "macro", "match", "module", "mutable"
+ , "namespace", "new", "null"
+ , "out", "override"
+ , "params", "private", "protected", "public"
+ , "ref"
+ , "sealed", "static", "struct", "syntax"
+ , "this", "throw", "true", "try", "type", "typeof"
+ , "unless", "using"
+ , "variant", "virtual"
+ , "when", "where", "while"
+ ]);
+ }
+
+ protected override GetTypes() : Map[string, string]
+ {
+ Map()
+ .Add("System.Boolean", "bool")
+ .Add("System.Byte", "byte")
+ .Add("System.Char", "char")
+ .Add("System.Decimal", "decimal")
+ .Add("System.Double", "double")
+ .Add("System.Int16", "short")
+ .Add("System.Int32", "int")
+ .Add("System.Int64", "long")
+ .Add("System.Object", "object")
+ .Add("System.SByte", "sbyte")
+ .Add("System.Single", "float")
+ .Add("System.String", "string")
+ .Add("System.UInt16", "ushort")
+ .Add("System.UInt32", "uint")
+ .Add("System.UInt64", "ulong")
+ .Add("System.Void", "void")
+ ;
+ }
+
+ protected override GetSpecialMethods() : Map[string, string]
+ {
+ Map()
+ .Add("op_UnaryPlus", "+")
+ .Add("op_Addition", "+")
+ .Add("op_Increment", "++")
+ .Add("op_UnaryNegation", "-")
+ .Add("op_Subtraction", "-")
+ .Add("op_Decrement", "--")
+ .Add("op_Multiply", "*")
+ .Add("op_Division", "/")
+ .Add("op_Modulus", "%")
+ .Add("op_BitwiseAnd", "&")
+ .Add("op_BitwiseOr", "|")
+ .Add("op_ExclusiveOr", "^")
+ .Add("op_Negation", "!")
+ .Add("op_OnesComplement", "~")
+ .Add("op_LeftShift", "<<")
+ .Add("op_RightShift", ">>")
+ .Add("op_Equality", "==")
+ .Add("op_Inequality", "!=")
+ .Add("op_GreaterThanOrEqual", ">=")
+ .Add("op_LessThanOrEqual", "<=")
+ .Add("op_GreaterThan", ">")
+ .Add("op_LessThan", "<")
+ .Add("op_True", "true")
+ .Add("op_False", "false")
+ .Add("op_Implicit", "implicit")
+ .Add("op_Explicit", "explicit")
+ ;
+ }
+
+ #endregion
+
+ }
+}
Added: nemerle/trunk/tools/reflector-addon/src/LanguageWriterConfiguration.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/LanguageWriterConfiguration.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal class LanguageWriterConfiguration
+ {
+ _configuration : ILanguageWriterConfiguration;
+
+ public this(configuration : ILanguageWriterConfiguration)
+ {
+ _configuration = configuration;
+ }
+
+ public ShowCustomAttributes : bool
+ {
+ get { _configuration["ShowCustomAttributes"] == "true" }
+ }
+
+ public ShowDocumentation : bool
+ {
+ get { _configuration["ShowDocumentation"] == "true" }
+ }
+
+ public ShowNamespaceBody : bool
+ {
+ get { _configuration["ShowNamespaceBody"] == "true" }
+ }
+
+ public ShowNamespaceImports : bool
+ {
+ get { _configuration["ShowNamespaceImports"] == "true" }
+ }
+
+ public ShowTypeDeclarationBody : bool
+ {
+ get { _configuration["ShowTypeDeclarationBody"] == "true" }
+ }
+
+ public OptionIndent : bool
+ {
+ get { _configuration["OptionIndent"] == "true" }
+ }
+
+ #region IsVisible
+
+ private IsVisible(methodVisibility : MethodVisibility) : bool
+ {
+ def visibilityConfig = _configuration.Visibility;
+ match (methodVisibility)
+ {
+ | MethodVisibility.Private
+ | MethodVisibility.PrivateScope => visibilityConfig.Private
+ | MethodVisibility.FamilyAndAssembly => visibilityConfig.FamilyAndAssembly
+ | MethodVisibility.Assembly => visibilityConfig.Assembly
+ | MethodVisibility.Family => visibilityConfig.Family
+ | MethodVisibility.FamilyOrAssembly => visibilityConfig.FamilyOrAssembly
+ | MethodVisibility.Public => visibilityConfig.Public
+ | _ => throw NotSupportedException()
+ }
+ }
+
+ private IsVisible(fieldVisibility : FieldVisibility) : bool
+ {
+ def visibilityConfig = _configuration.Visibility;
+ match (fieldVisibility)
+ {
+ | FieldVisibility.Private
+ | FieldVisibility.PrivateScope => visibilityConfig.Private
+ | FieldVisibility.FamilyAndAssembly => visibilityConfig.FamilyAndAssembly
+ | FieldVisibility.Assembly => visibilityConfig.Assembly
+ | FieldVisibility.Family => visibilityConfig.Family
+ | FieldVisibility.FamilyOrAssembly => visibilityConfig.FamilyOrAssembly
+ | FieldVisibility.Public => visibilityConfig.Public
+ | _ => throw NotSupportedException()
+ }
+ }
+
+ private IsVisible(typeVisibility : TypeVisibility) : bool
+ {
+ def visibilityConfig = _configuration.Visibility;
+ match (typeVisibility)
+ {
+ | TypeVisibility.Private
+ | TypeVisibility.NestedPrivate => visibilityConfig.Private
+ | TypeVisibility.NestedFamilyAndAssembly => visibilityConfig.FamilyAndAssembly
+ | TypeVisibility.NestedAssembly => visibilityConfig.Assembly
+ | TypeVisibility.NestedFamily => visibilityConfig.Family
+ | TypeVisibility.NestedFamilyOrAssembly => visibilityConfig.FamilyOrAssembly
+ | TypeVisibility.Public
+ | TypeVisibility.NestedPublic => visibilityConfig.Public
+ | _ => throw NotSupportedException()
+ }
+ }
+
+ public IsVisible(value : IEventReference) : bool
+ {
+ IsVisible(value.DeclaringType) && IsVisible(value.GetVisibility())
+ }
+
+ public IsVisible(value : IFieldReference) : bool
+ {
+ IsVisible(value.DeclaringType) && IsVisible(value.GetVisibility())
+ }
+
+ public IsVisible(value : IMethodReference) : bool
+ {
+ IsVisible(value.DeclaringType) && IsVisible(value.GetVisibility())
+ }
+
+ public IsVisible(value : IPropertyReference) : bool
+ {
+ IsVisible(value.DeclaringType) && IsVisible(value.GetVisibility())
+ }
+
+ public IsVisible(value : IType) : bool
+ {
+ match (value)
+ {
+ | typeRef is ITypeReference =>
+ def ownerVisible =
+ match (typeRef.Owner)
+ {
+ | ownerRef is ITypeReference => IsVisible(ownerRef)
+ | _ => true
+ }
+ ownerVisible && IsVisible(typeRef.GetVisibility())
+ | _ => throw NotSupportedException();
+ }
+ }
+
+ #endregion
+
+ }
+}
\ No newline at end of file
Added: nemerle/trunk/tools/reflector-addon/src/Package.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/Package.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Reflector;
+using Reflector.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal class Package : IPackage
+ {
+ private mutable _langMgr : ILanguageManager;
+ private mutable _nemerleLang : ILanguage;
+
+ public Load(serviceProvider : IServiceProvider) : void
+ {
+ when (serviceProvider == null)
+ throw ArgumentNullException("serviceProvider");
+
+ _langMgr = serviceProvider.GetService(typeof(ILanguageManager)) :> ILanguageManager;
+
+ when (_langMgr == null)
+ throw InvalidOperationException("ILanguageManager not available");
+
+ _nemerleLang = Language();
+ _langMgr.RegisterLanguage(_nemerleLang);
+ }
+
+ public Unload() : void
+ {
+ _langMgr.UnregisterLanguage(_nemerleLang);
+ }
+ }
+}
Added: nemerle/trunk/tools/reflector-addon/src/UsingNamespaceVisitor.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/tools/reflector-addon/src/UsingNamespaceVisitor.n Mon Jan 8 07:21:27 2007
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2003-2007 The University of Wroclaw.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections;
+using Nemerle.Assertions;
+using Nemerle.Utility;
+
+using Reflector.CodeModel;
+using Reflector.NemerleLanguage.CodeModel;
+
+namespace Reflector.NemerleLanguage
+{
+ internal class UsingNamespaceVisitor : VisitorBase
+ {
+ mutable _currNamespace : INamespace;
+ [Accessor] mutable _namespaces : list[string];
+
+ public this()
+ {
+ _namespaces = []
+ }
+
+ private AddNamespace(namespaceName : string) : void
+ {
+ unless (namespaceName == _currNamespace.Name || _namespaces.Contains(namespaceName))
+ _namespaces ::= namespaceName;
+ }
+
+ public override VisitType(value : IType) : void
+ {
+ match (value)
+ {
+ | tyRef is ITypeReference =>
+ match (tyRef.Owner)
+ {
+ | ownerRef is ITypeReference => VisitType(ownerRef)
+ | _ => AddNamespace(tyRef.Namespace)
+ }
+ | _ => ()
+ }
+ base.VisitType(value);
+ }
+
+ public override VisitNamespace(namespaceDeclaration : INamespace) : void
+ {
+ _currNamespace = namespaceDeclaration;
+ base.VisitNamespace(namespaceDeclaration);
+ _currNamespace = null;
+ }
+
+ }
+}
+
More information about the svn
mailing list