/* * Copyright (c) 2003-2008 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.Utility; namespace Nemerle.Compiler { /** * System.Type.FullName is null if it contains free generic parameters. * Here is replacement which doesn't return null and should be suitable. */ public module SystemTypeExtensions { public TypeFullName (this t : System.Type) : string { if (t.FullName != null) { if(!t.ContainsGenericParameters) t.FullName else // K-Liss: more detailed look for generic type names { def genericArgs = t.GetGenericArguments(); def ns = if(t.Namespace == "") "" else t.Namespace + "."; $"$ns$(t.Name)[..$(genericArgs.Map(_.Name))]"; } } else { //internal System.Type.SigToString () : string, reflected from MS mscorlib.dll def SigToString (t : System.Type) { mutable e = t; while (e.HasElementType) e = e.GetElementType (); if (e.IsNested) t.Name else { def str = t.ToString (); if (!e.IsPrimitive && !e.Equals (typeof (System.Void)) && !e.Equals (typeof (System.TypedReference))) str else str //.Substring ("System.".Length) //I think we don't need to drop System prefix } } SigToString (t); } } } } namespace Nemerle.Internal { public class NemerleAttribute : System.Attribute { } /** * Marks a volatile field */ [System.AttributeUsage (System.AttributeTargets.Field)] public sealed class VolatileModifier : NemerleAttribute { } /** * Marks an immutable field */ [System.AttributeUsage (System.AttributeTargets.Field)] public sealed class ImmutableAttribute : NemerleAttribute { } [System.AttributeUsage (System.AttributeTargets.Class|System.AttributeTargets.Method)] public sealed class ExtensionAttribute : NemerleAttribute { } /** * Used to store the Nemerle types in genereated assembly metadata */ public sealed class TypeAttribute : NemerleAttribute { public this (encoded_type : string) { _encoded_type = encoded_type } public GetEncodedType () : string { _encoded_type } public mutable _encoded_type : string; } /** * Used to store the custom operator priorities loaded as syntax extensions */ [Record] public sealed class OperatorAttribute : NemerleAttribute { public mutable env : string; public mutable name : string; public mutable IsUnary : bool; public mutable left : int; public mutable right : int; public override ToString() : string { $"OperatorAttribute: $name (env=$env, IsUnary=$IsUnary, left=$left, right=$right)" } } /** * Marks a Nemerle variant type */ public sealed class VariantAttribute : NemerleAttribute { public this () { } public this (variant_options : string) { _variant_options = variant_options } public GetVariantOptions () : string { _variant_options } public mutable _variant_options : string; public override ToString() : string { $"$(GetType().Name): $_variant_options" } } /** * Marks a Nemerle variant option */ public sealed class VariantOptionAttribute : NemerleAttribute { } /** * Marks a constant Nemerle variant option */ public sealed class ConstantVariantOptionAttribute : NemerleAttribute { } /** * Container for type aliases. */ public sealed class TypeAliasAttribute : NemerleAttribute { public this (variant_options : string) { _variant_options = variant_options } public GetAliasedType () : string { _variant_options } public _variant_options : string; public override ToString() : string { $"$(GetType().Name): $_variant_options" } } /** * Used on assembly to list contained macros. */ [System.AttributeUsage (System.AttributeTargets.Assembly, AllowMultiple = true)] public sealed class ContainsMacroAttribute : NemerleAttribute { public this (name : string) { _name = name } public GetName () : string { _name } public _name : string; public override ToString() : string { $"$(GetType().Name): $_name" } } [System.AttributeUsage (System.AttributeTargets.All)] public sealed class MacroAttribute : NemerleAttribute { public name : string; public parameters : string; public global_ctx : int; public this (name : string, ctx : int, parameters : string) { this.name = name; this.parameters = parameters; global_ctx = ctx; } public override ToString() : string { $"$(GetType().Name): $name ($parameters)" } } [System.AttributeUsage (System.AttributeTargets.Class, AllowMultiple = true)] [Record] public sealed class ExtensionPatternEncodingAttribute : NemerleAttribute { [Accessor] name : string; [Accessor] identifiers : string; [Accessor] pattern : string; public override ToString() : string { $"$(GetType().Name): $name, Pattern:($pattern), Identifiers:($identifiers)" } } } namespace Nemerle.Utility { public class Identity ['a, 'b] : Builtins.Function ['a, 'b] where 'a : 'b { public static Instance : Identity ['a, 'b] = Identity (); public override apply (x : 'a) : 'b { x } } }