Пример #1
0
 private static bool IsStructWithExplicitLayout(Struct asStruct)
 {
   if (asStruct == null) return false;
   if ((asStruct.Flags & TypeFlags.ExplicitLayout) != 0) return true;
   return false;
 }
Пример #2
0
 // We create classes here because we don't want any fields etc...
 private Class CreateWrapperStruct(Struct s)
 {
   var flags = WrapperTypeFlags(s);
   var wrapper = new Class(this.assemblyBeingRewritten, null, null, flags, null, s.Name, SystemTypes.Object, null, null);
   RewriteHelper.TryAddCompilerGeneratedAttribute(wrapper);
   if (s.TemplateParameters != null)
   {
     Duplicator d = new Duplicator(this.assemblyBeingRewritten, wrapper);
     d.FindTypesToBeDuplicated(s.TemplateParameters);
     var templateParams = CopyTypeParameterList(wrapper, s, d);
     wrapper.TemplateParameters = templateParams;
     wrapper.IsGeneric = true;
   }
   return wrapper;
 }
Пример #3
0
        private static void ClearStatics()
        {
            AttributeUsageAttribute = null;
            ConditionalAttribute = null;
            DefaultMemberAttribute = null;
            InternalsVisibleToAttribute = null;
            ObsoleteAttribute = null;

            GenericICollection = null;
            GenericIEnumerable = null;
            GenericIList = null;
            ICloneable = null;
            ICollection = null;
            IEnumerable = null;
            IList = null;

            //Special attributes    
            AllowPartiallyTrustedCallersAttribute = null;
            AssemblyCompanyAttribute = null;
            AssemblyConfigurationAttribute = null;
            AssemblyCopyrightAttribute = null;
            AssemblyCultureAttribute = null;
            AssemblyDelaySignAttribute = null;
            AssemblyDescriptionAttribute = null;
            AssemblyFileVersionAttribute = null;
            AssemblyFlagsAttribute = null;
            AssemblyInformationalVersionAttribute = null;
            AssemblyKeyFileAttribute = null;
            AssemblyKeyNameAttribute = null;
            AssemblyProductAttribute = null;
            AssemblyTitleAttribute = null;
            AssemblyTrademarkAttribute = null;
            AssemblyVersionAttribute = null;
            ClassInterfaceAttribute = null;
            CLSCompliantAttribute = null;
            ComImportAttribute = null;
            ComRegisterFunctionAttribute = null;
            ComSourceInterfacesAttribute = null;
            ComUnregisterFunctionAttribute = null;
            ComVisibleAttribute = null;
            DebuggableAttribute = null;
            DebuggerHiddenAttribute = null;
            DebuggerStepThroughAttribute = null;
            DebuggingModes = null;
            DllImportAttribute = null;
            FieldOffsetAttribute = null;
            FlagsAttribute = null;
            GuidAttribute = null;
            ImportedFromTypeLibAttribute = null;
            InAttribute = null;
            IndexerNameAttribute = null;
            InterfaceTypeAttribute = null;
            MethodImplAttribute = null;
            NonSerializedAttribute = null;
            OptionalAttribute = null;
            OutAttribute = null;
            ParamArrayAttribute = null;
            RuntimeCompatibilityAttribute = null;
            SatelliteContractVersionAttribute = null;
            SerializableAttribute = null;
            SecurityAttribute = null;
            SecurityCriticalAttribute = null;
            SecurityTransparentAttribute = null;
            SecurityTreatAsSafeAttribute = null;
            STAThreadAttribute = null;
            StructLayoutAttribute = null;
            SuppressMessageAttribute = null;
            SuppressUnmanagedCodeSecurityAttribute = null;
            SecurityAction = null;

            //Classes need for System.TypeCode
            DBNull = null;
            DateTime = null;
            TimeSpan = null;

            //Classes and interfaces used by the Framework
            Activator = null;
            AppDomain = null;
            ApplicationException = null;
            ArgumentException = null;
            ArgumentNullException = null;
            ArgumentOutOfRangeException = null;
            ArrayList = null;
            AsyncCallback = null;
            Assembly = null;
            CodeAccessPermission = null;
            CollectionBase = null;
            CultureInfo = null;
            DictionaryBase = null;
            DictionaryEntry = null;
            DuplicateWaitObjectException = null;
            Environment = null;
            EventArgs = null;
            ExecutionEngineException = null;
            GenericArraySegment = null;
            GenericArrayToIEnumerableAdapter = null;
            GenericDictionary = null;
            GenericIComparable = null;
            GenericIComparer = null;
            GenericIDictionary = null;
            GenericIEnumerator = null;
            GenericKeyValuePair = null;
            GenericList = null;
            GenericNullable = null;
            GenericQueue = null;
            GenericSortedDictionary = null;
            GenericStack = null;
            GC = null;
            Guid = null;
            __HandleProtector = null;
            HandleRef = null;
            Hashtable = null;
            IASyncResult = null;
            IComparable = null;
            IDictionary = null;
            IComparer = null;
            IDisposable = null;
            IEnumerator = null;
            IFormatProvider = null;
            IHashCodeProvider = null;
            IMembershipCondition = null;
            IndexOutOfRangeException = null;
            InvalidCastException = null;
            InvalidOperationException = null;
            IPermission = null;
            ISerializable = null;
            IStackWalk = null;
            Marshal = null;
            MarshalByRefObject = null;
            MemberInfo = null;
            NativeOverlapped = null;
            Monitor = null;
            NotSupportedException = null;
            NullReferenceException = null;
            OutOfMemoryException = null;
            ParameterInfo = null;
            Queue = null;
            ReadOnlyCollectionBase = null;
            ResourceManager = null;
            ResourceSet = null;
            SerializationInfo = null;
            Stack = null;
            StackOverflowException = null;
            Stream = null;
            StreamingContext = null;
            StringBuilder = null;
            StringComparer = null;
            StringComparison = null;
            SystemException = null;
            Thread = null;
            WindowsImpersonationContext = null;
        }
        public override Struct VisitStruct(Struct Struct)
        {
            Struct = base.VisitStruct(Struct);

            Struct.Template = null;
                
            return Struct;
        }
Пример #5
0
 internal static TypeNode/*!*/ GetDummyTypeNode(AssemblyNode declaringAssembly, string/*!*/ nspace, string/*!*/ name, ElementType typeCode)
 {
     TypeNode result = null;
     switch (typeCode)
     {
         case ElementType.Object:
         case ElementType.String:
         case ElementType.Class:
             if (name.Length > 1 && name[0] == 'I' && char.IsUpper(name[1]))
                 result = new Interface();
             else if (name == "MulticastDelegate" || name == "Delegate")
                 result = new Class();
             else if (name.EndsWith("Callback") || name.EndsWith("Delegate") || name == "ThreadStart" || name == "FrameGuardGetter" || name == "GuardThreadStart")
                 result = new DelegateNode();
             else
                 result = new Class();
             break;
         default:
             if (name == "CciMemberKind")
                 result = new EnumNode();
             else
                 result = new Struct();
             break;
     }
     result.Name = Identifier.For(name);
     result.Namespace = Identifier.For(nspace);
     result.DeclaringModule = declaringAssembly;
     return result;
 }
Пример #6
0
        public static void Initialize(bool doNotLockFile, bool getDebugInfo)
        {
            if (SystemTypes.Initialized)
            {
                SystemTypes.Clear();
                CoreSystemTypes.Initialize(doNotLockFile, getDebugInfo);
            }
            else if (!CoreSystemTypes.Initialized)
            {
                CoreSystemTypes.Initialize(doNotLockFile, getDebugInfo);
            }

            if (TargetPlatform.TargetVersion == null)
            {
                TargetPlatform.TargetVersion = SystemAssembly.Version;
                if (TargetPlatform.TargetVersion == null)
                    TargetPlatform.TargetVersion = typeof(object).Module.Assembly.GetName().Version;
            }
            //TODO: throw an exception when the result is null

            AttributeUsageAttribute = (Class)GetTypeNodeFor("System", "AttributeUsageAttribute", ElementType.Class);
            ConditionalAttribute = (Class)GetTypeNodeFor("System.Diagnostics", "ConditionalAttribute", ElementType.Class);
            DefaultMemberAttribute = (Class)GetTypeNodeFor("System.Reflection", "DefaultMemberAttribute", ElementType.Class);
            InternalsVisibleToAttribute = (Class)GetTypeNodeFor("System.Runtime.CompilerServices", "InternalsVisibleToAttribute", ElementType.Class);
            ObsoleteAttribute = (Class)GetTypeNodeFor("System", "ObsoleteAttribute", ElementType.Class);

            GenericICollection = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "ICollection", 1, ElementType.Class);
            GenericIEnumerable = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IEnumerable", 1, ElementType.Class);
            GenericIList = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IList", 1, ElementType.Class);
            ICloneable = (Interface)GetTypeNodeFor("System", "ICloneable", ElementType.Class);
            ICollection = (Interface)GetTypeNodeFor("System.Collections", "ICollection", ElementType.Class);
            IEnumerable = (Interface)GetTypeNodeFor("System.Collections", "IEnumerable", ElementType.Class);
            IList = (Interface)GetTypeNodeFor("System.Collections", "IList", ElementType.Class);

            AllowPartiallyTrustedCallersAttribute = (Class)GetTypeNodeFor("System.Security", "AllowPartiallyTrustedCallersAttribute", ElementType.Class);
            AssemblyCompanyAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyCompanyAttribute", ElementType.Class);
            AssemblyConfigurationAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyConfigurationAttribute", ElementType.Class);
            AssemblyCopyrightAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyCopyrightAttribute", ElementType.Class);
            AssemblyCultureAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyCultureAttribute", ElementType.Class);
            AssemblyDelaySignAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyDelaySignAttribute", ElementType.Class);
            AssemblyDescriptionAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyDescriptionAttribute", ElementType.Class);
            AssemblyFileVersionAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyFileVersionAttribute", ElementType.Class);
            AssemblyFlagsAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyFlagsAttribute", ElementType.Class);
            AssemblyInformationalVersionAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyInformationalVersionAttribute", ElementType.Class);
            AssemblyKeyFileAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyKeyFileAttribute", ElementType.Class);
            AssemblyKeyNameAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyKeyNameAttribute", ElementType.Class);
            AssemblyProductAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyProductAttribute", ElementType.Class);
            AssemblyTitleAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyTitleAttribute", ElementType.Class);
            AssemblyTrademarkAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyTrademarkAttribute", ElementType.Class);
            AssemblyVersionAttribute = (Class)GetTypeNodeFor("System.Reflection", "AssemblyVersionAttribute", ElementType.Class);
            ClassInterfaceAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ClassInterfaceAttribute", ElementType.Class);
            CLSCompliantAttribute = (Class)GetTypeNodeFor("System", "CLSCompliantAttribute", ElementType.Class);
            ComImportAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ComImportAttribute", ElementType.Class);
            ComRegisterFunctionAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ComRegisterFunctionAttribute", ElementType.Class);
            ComSourceInterfacesAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ComSourceInterfacesAttribute", ElementType.Class);
            ComUnregisterFunctionAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ComUnregisterFunctionAttribute", ElementType.Class);
            ComVisibleAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ComVisibleAttribute", ElementType.Class);
            DebuggableAttribute = (Class)GetTypeNodeFor("System.Diagnostics", "DebuggableAttribute", ElementType.Class);
            DebuggerHiddenAttribute = (Class)GetTypeNodeFor("System.Diagnostics", "DebuggerHiddenAttribute", ElementType.Class);
            DebuggerStepThroughAttribute = (Class)GetTypeNodeFor("System.Diagnostics", "DebuggerStepThroughAttribute", ElementType.Class);
            DebuggingModes = DebuggableAttribute == null ? null : DebuggableAttribute.GetNestedType(Identifier.For("DebuggingModes")) as EnumNode;
            DllImportAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "DllImportAttribute", ElementType.Class);
            FieldOffsetAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "FieldOffsetAttribute", ElementType.Class);
            FlagsAttribute = (Class)GetTypeNodeFor("System", "FlagsAttribute", ElementType.Class);
            Guid = (Struct)GetTypeNodeFor("System", "Guid", ElementType.ValueType);
            GuidAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "GuidAttribute", ElementType.Class);
            ImportedFromTypeLibAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "ImportedFromTypeLibAttribute", ElementType.Class);
            InAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "InAttribute", ElementType.Class);
            IndexerNameAttribute = (Class)GetTypeNodeFor("System.Runtime.CompilerServices", "IndexerNameAttribute", ElementType.Class);
            InterfaceTypeAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "InterfaceTypeAttribute", ElementType.Class);
            MethodImplAttribute = (Class)GetTypeNodeFor("System.Runtime.CompilerServices", "MethodImplAttribute", ElementType.Class);
            NonSerializedAttribute = (Class)GetTypeNodeFor("System", "NonSerializedAttribute", ElementType.Class);
            OptionalAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "OptionalAttribute", ElementType.Class);
            OutAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "OutAttribute", ElementType.Class);
            ParamArrayAttribute = (Class)GetTypeNodeFor("System", "ParamArrayAttribute", ElementType.Class);
            RuntimeCompatibilityAttribute = (Class)GetTypeNodeFor("System.Runtime.CompilerServices", "RuntimeCompatibilityAttribute", ElementType.Class);
            SatelliteContractVersionAttribute = (Class)GetTypeNodeFor("System.Resources", "SatelliteContractVersionAttribute", ElementType.Class);
            SerializableAttribute = (Class)GetTypeNodeFor("System", "SerializableAttribute", ElementType.Class);
            SecurityAttribute = (Class)GetTypeNodeFor("System.Security.Permissions", "SecurityAttribute", ElementType.Class);
            SecurityCriticalAttribute = (Class)GetTypeNodeFor("System.Security", "SecurityCriticalAttribute", ElementType.Class);
            SecurityTransparentAttribute = (Class)GetTypeNodeFor("System.Security", "SecurityTransparentAttribute", ElementType.Class);
            SecurityTreatAsSafeAttribute = (Class)GetTypeNodeFor("System.Security", "SecurityTreatAsSafeAttribute", ElementType.Class);
            STAThreadAttribute = (Class)GetTypeNodeFor("System", "STAThreadAttribute", ElementType.Class);
            StructLayoutAttribute = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "StructLayoutAttribute", ElementType.Class);
            SuppressMessageAttribute = (Class)GetTypeNodeFor("System.Diagnostics.CodeAnalysis", "SuppressMessageAttribute", ElementType.Class);
            SuppressUnmanagedCodeSecurityAttribute = (Class)GetTypeNodeFor("System.Security", "SuppressUnmanagedCodeSecurityAttribute", ElementType.Class);
            SecurityAction = GetTypeNodeFor("System.Security.Permissions", "SecurityAction", ElementType.ValueType) as EnumNode;
            DBNull = (Class)GetTypeNodeFor("System", "DBNull", ElementType.Class);
            DateTime = (Struct)GetTypeNodeFor("System", "DateTime", ElementType.ValueType);
            TimeSpan = (Struct)GetTypeNodeFor("System", "TimeSpan", ElementType.ValueType);
            Activator = (Class)GetTypeNodeFor("System", "Activator", ElementType.Class);
            AppDomain = (Class)GetTypeNodeFor("System", "AppDomain", ElementType.Class);
            ApplicationException = (Class)GetTypeNodeFor("System", "ApplicationException", ElementType.Class);
            ArgumentException = (Class)GetTypeNodeFor("System", "ArgumentException", ElementType.Class);
            ArgumentNullException = (Class)GetTypeNodeFor("System", "ArgumentNullException", ElementType.Class);
            ArgumentOutOfRangeException = (Class)GetTypeNodeFor("System", "ArgumentOutOfRangeException", ElementType.Class);
            ArrayList = (Class)GetTypeNodeFor("System.Collections", "ArrayList", ElementType.Class);
            AsyncCallback = (DelegateNode)GetTypeNodeFor("System", "AsyncCallback", ElementType.Class);
            Assembly = (Class)GetTypeNodeFor("System.Reflection", "Assembly", ElementType.Class);
            CodeAccessPermission = (Class)GetTypeNodeFor("System.Security", "CodeAccessPermission", ElementType.Class);
            CollectionBase = (Class)GetTypeNodeFor("System.Collections", "CollectionBase", ElementType.Class);
            CultureInfo = (Class)GetTypeNodeFor("System.Globalization", "CultureInfo", ElementType.Class);
            DictionaryBase = (Class)GetTypeNodeFor("System.Collections", "DictionaryBase", ElementType.Class);

            // EFW - In the .NET Micro Framework this is a class not a structure.  Few if any of these are
            // actually used, this one included.  I'm loathe to remove them as they may be used to ensure
            // assemblies are loaded.  Using the as operator rather than a direct cast prevent it from failing.
            DictionaryEntry = GetTypeNodeFor("System.Collections", "DictionaryEntry", ElementType.ValueType) as Struct;

            DuplicateWaitObjectException = (Class)GetTypeNodeFor("System", "DuplicateWaitObjectException", ElementType.Class);
            Environment = (Class)GetTypeNodeFor("System", "Environment", ElementType.Class);
            EventArgs = (Class)GetTypeNodeFor("System", "EventArgs", ElementType.Class);
            ExecutionEngineException = (Class)GetTypeNodeFor("System", "ExecutionEngineException", ElementType.Class);
            GenericArraySegment = (Struct)GetGenericRuntimeTypeNodeFor("System", "ArraySegment", 1, ElementType.ValueType);
            GenericDictionary = (Class)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "Dictionary", 2, ElementType.Class);
            GenericIComparable = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IComparable", 1, ElementType.Class);
            GenericIComparer = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IComparer", 1, ElementType.Class);
            GenericIDictionary = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IDictionary", 2, ElementType.Class);
            GenericIEnumerator = (Interface)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "IEnumerator", 1, ElementType.Class);
            GenericKeyValuePair = (Struct)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "KeyValuePair", 2, ElementType.ValueType);
            GenericList = (Class)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "List", 1, ElementType.Class);
            GenericNullable = (Struct)GetGenericRuntimeTypeNodeFor("System", "Nullable", 1, ElementType.ValueType);
            GenericQueue = (Class)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "Queue", 1, ElementType.Class);
            GenericSortedDictionary = (Class)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "SortedDictionary", 2, ElementType.Class);
            GenericStack = (Class)GetGenericRuntimeTypeNodeFor("System.Collections.Generic", "Stack", 1, ElementType.Class);
            GC = (Class)GetTypeNodeFor("System", "GC", ElementType.Class);
            __HandleProtector = (Class)GetTypeNodeFor("System.Threading", "__HandleProtector", ElementType.Class);
            HandleRef = (Struct)GetTypeNodeFor("System.Runtime.InteropServices", "HandleRef", ElementType.ValueType);
            Hashtable = (Class)GetTypeNodeFor("System.Collections", "Hashtable", ElementType.Class);
            IASyncResult = (Interface)GetTypeNodeFor("System", "IAsyncResult", ElementType.Class);
            IComparable = (Interface)GetTypeNodeFor("System", "IComparable", ElementType.Class);
            IComparer = (Interface)GetTypeNodeFor("System.Collections", "IComparer", ElementType.Class);
            IDictionary = (Interface)GetTypeNodeFor("System.Collections", "IDictionary", ElementType.Class);
            IDisposable = (Interface)GetTypeNodeFor("System", "IDisposable", ElementType.Class);
            IEnumerator = (Interface)GetTypeNodeFor("System.Collections", "IEnumerator", ElementType.Class);
            IFormatProvider = (Interface)GetTypeNodeFor("System", "IFormatProvider", ElementType.Class);
            IHashCodeProvider = (Interface)GetTypeNodeFor("System.Collections", "IHashCodeProvider", ElementType.Class);
            IMembershipCondition = (Interface)GetTypeNodeFor("System.Security.Policy", "IMembershipCondition", ElementType.Class);
            IndexOutOfRangeException = (Class)GetTypeNodeFor("System", "IndexOutOfRangeException", ElementType.Class);
            InvalidCastException = (Class)GetTypeNodeFor("System", "InvalidCastException", ElementType.Class);
            InvalidOperationException = (Class)GetTypeNodeFor("System", "InvalidOperationException", ElementType.Class);
            IPermission = (Interface)GetTypeNodeFor("System.Security", "IPermission", ElementType.Class);
            ISerializable = (Interface)GetTypeNodeFor("System.Runtime.Serialization", "ISerializable", ElementType.Class);
            IStackWalk = (Interface)GetTypeNodeFor("System.Security", "IStackWalk", ElementType.Class);
            Marshal = (Class)GetTypeNodeFor("System.Runtime.InteropServices", "Marshal", ElementType.Class);
            MarshalByRefObject = (Class)GetTypeNodeFor("System", "MarshalByRefObject", ElementType.Class);
            MemberInfo = (Class)GetTypeNodeFor("System.Reflection", "MemberInfo", ElementType.Class);
            Monitor = (Class)GetTypeNodeFor("System.Threading", "Monitor", ElementType.Class);
            NativeOverlapped = (Struct)GetTypeNodeFor("System.Threading", "NativeOverlapped", ElementType.ValueType);
            NotSupportedException = (Class)GetTypeNodeFor("System", "NotSupportedException", ElementType.Class);
            NullReferenceException = (Class)GetTypeNodeFor("System", "NullReferenceException", ElementType.Class);
            OutOfMemoryException = (Class)GetTypeNodeFor("System", "OutOfMemoryException", ElementType.Class);
            ParameterInfo = (Class)GetTypeNodeFor("System.Reflection", "ParameterInfo", ElementType.Class);
            Queue = (Class)GetTypeNodeFor("System.Collections", "Queue", ElementType.Class);
            ReadOnlyCollectionBase = (Class)GetTypeNodeFor("System.Collections", "ReadOnlyCollectionBase", ElementType.Class);
            ResourceManager = (Class)GetTypeNodeFor("System.Resources", "ResourceManager", ElementType.Class);
            ResourceSet = (Class)GetTypeNodeFor("System.Resources", "ResourceSet", ElementType.Class);
            SerializationInfo = (Class)GetTypeNodeFor("System.Runtime.Serialization", "SerializationInfo", ElementType.Class);
            Stack = (Class)GetTypeNodeFor("System.Collections", "Stack", ElementType.Class);
            StackOverflowException = (Class)GetTypeNodeFor("System", "StackOverflowException", ElementType.Class);
            Stream = (Class)GetTypeNodeFor("System.IO", "Stream", ElementType.Class);
            StreamingContext = (Struct)GetTypeNodeFor("System.Runtime.Serialization", "StreamingContext", ElementType.ValueType);
            StringBuilder = (Class)GetTypeNodeFor("System.Text", "StringBuilder", ElementType.Class);
            StringComparer = (Class)GetTypeNodeFor("System", "StringComparer", ElementType.Class);
            StringComparison = GetTypeNodeFor("System", "StringComparison", ElementType.ValueType) as EnumNode;
            SystemException = (Class)GetTypeNodeFor("System", "SystemException", ElementType.Class);
            Thread = (Class)GetTypeNodeFor("System.Threading", "Thread", ElementType.Class);
            WindowsImpersonationContext = (Class)GetTypeNodeFor("System.Security.Principal", "WindowsImpersonationContext", ElementType.Class);

            SystemTypes.Initialized = true;
            object dummy = TargetPlatform.AssemblyReferenceFor; //Force selection of target platform
            if (dummy == null) return;
        }
Пример #7
0
        public static void Initialize(bool doNotLockFile, bool getDebugInfo)
        {
            if (CoreSystemTypes.Initialized) CoreSystemTypes.Clear();
            if (SystemAssembly == null)
                SystemAssembly = CoreSystemTypes.GetSystemAssembly(doNotLockFile, getDebugInfo);
            if (SystemAssembly == null) throw new InvalidOperationException(ExceptionStrings.InternalCompilerError);
            if (TargetPlatform.TargetVersion == null)
            {
                TargetPlatform.TargetVersion = SystemAssembly.Version;
                if (TargetPlatform.TargetVersion == null)
                    TargetPlatform.TargetVersion = typeof(object).Module.Assembly.GetName().Version;
            }
            if (TargetPlatform.TargetVersion != null)
            {
                if (TargetPlatform.TargetVersion.Major > 1 || TargetPlatform.TargetVersion.Minor > 1 ||
                  (TargetPlatform.TargetVersion.Minor == 1 && TargetPlatform.TargetVersion.Build == 9999))
                {
                    if (SystemAssembly.IsValidTypeName(StandardIds.System, Identifier.For("Nullable`1")))
                        TargetPlatform.GenericTypeNamesMangleChar = '`';
                    else if (SystemAssembly.IsValidTypeName(StandardIds.System, Identifier.For("Nullable!1")))
                        TargetPlatform.GenericTypeNamesMangleChar = '!';
                    else if (TargetPlatform.TargetVersion.Major == 1 && TargetPlatform.TargetVersion.Minor == 2)
                        TargetPlatform.GenericTypeNamesMangleChar = (char)0;
                }
            }
            // This must be done in the order: Object, ValueType, Char, String
            // or else some of the generic type instantiations don't get filled
            // in correctly. (String ends up implementing IEnumerable<string>
            // instead of IEnumerable<char>.)
            Object = (Class)GetTypeNodeFor("System", "Object", ElementType.Object);
            ValueType = (Class)GetTypeNodeFor("System", "ValueType", ElementType.Class);
            Char = (Struct)GetTypeNodeFor("System", "Char", ElementType.Char);
            String = (Class)GetTypeNodeFor("System", "String", ElementType.String);
            Enum = (Class)GetTypeNodeFor("System", "Enum", ElementType.Class);
            MulticastDelegate = (Class)GetTypeNodeFor("System", "MulticastDelegate", ElementType.Class);
            Array = (Class)GetTypeNodeFor("System", "Array", ElementType.Class);
            Type = (Class)GetTypeNodeFor("System", "Type", ElementType.Class);
            Boolean = (Struct)GetTypeNodeFor("System", "Boolean", ElementType.Boolean);
            Int8 = (Struct)GetTypeNodeFor("System", "SByte", ElementType.Int8);
            UInt8 = (Struct)GetTypeNodeFor("System", "Byte", ElementType.UInt8);
            Int16 = (Struct)GetTypeNodeFor("System", "Int16", ElementType.Int16);
            UInt16 = (Struct)GetTypeNodeFor("System", "UInt16", ElementType.UInt16);
            Int32 = (Struct)GetTypeNodeFor("System", "Int32", ElementType.Int32);
            UInt32 = (Struct)GetTypeNodeFor("System", "UInt32", ElementType.UInt32);
            Int64 = (Struct)GetTypeNodeFor("System", "Int64", ElementType.Int64);
            UInt64 = (Struct)GetTypeNodeFor("System", "UInt64", ElementType.UInt64);
            Single = (Struct)GetTypeNodeFor("System", "Single", ElementType.Single);
            Double = (Struct)GetTypeNodeFor("System", "Double", ElementType.Double);
            IntPtr = (Struct)GetTypeNodeFor("System", "IntPtr", ElementType.IntPtr);
            UIntPtr = (Struct)GetTypeNodeFor("System", "UIntPtr", ElementType.UIntPtr);
            DynamicallyTypedReference = (Struct)GetTypeNodeFor("System", "TypedReference", ElementType.DynamicallyTypedReference);
            Delegate = (Class)GetTypeNodeFor("System", "Delegate", ElementType.Class);
            Exception = (Class)GetTypeNodeFor("System", "Exception", ElementType.Class);
            Attribute = (Class)GetTypeNodeFor("System", "Attribute", ElementType.Class);
            DBNull = (Class)GetTypeNodeFor("System", "DBNull", ElementType.Class);
            DateTime = (Struct)GetTypeNodeFor("System", "DateTime", ElementType.ValueType);
            Decimal = (Struct)GetTypeNodeFor("System", "Decimal", ElementType.ValueType);
            ArgIterator = (Struct)GetTypeNodeFor("System", "ArgIterator", ElementType.ValueType);
            IsVolatile = (Class)GetTypeNodeFor("System.Runtime.CompilerServices", "IsVolatile", ElementType.Class);
            Void = (Struct)GetTypeNodeFor("System", "Void", ElementType.Void);
            RuntimeFieldHandle = (Struct)GetTypeNodeFor("System", "RuntimeFieldHandle", ElementType.ValueType);
            RuntimeMethodHandle = (Struct)GetTypeNodeFor("System", "RuntimeMethodHandle", ElementType.ValueType);
            RuntimeTypeHandle = (Struct)GetTypeNodeFor("System", "RuntimeTypeHandle", ElementType.ValueType);
            RuntimeArgumentHandle = (Struct)GetTypeNodeFor("System", "RuntimeArgumentHandle", ElementType.ValueType);
            SecurityAction = GetTypeNodeFor("System.Security.Permissions", "SecurityAction", ElementType.ValueType) as EnumNode;
            CoreSystemTypes.Initialized = true;
            CoreSystemTypes.InstantiateGenericInterfaces();

            object dummy = TargetPlatform.AssemblyReferenceFor; //Force selection of target platform

            if(dummy == null)
                return;
        }
Пример #8
0
        public override Struct VisitStruct(Struct Struct)
        {
            this.VisitAttributeList(Struct.Attributes);

            WriteStart("{0}struct ", GetTypeQualifiers(Struct));
            this.VisitIdentifier(Struct.Name);
            WriteFinish(string.Empty);

            if (Struct.Interfaces != null && Struct.Interfaces.Count > 0)
                throw new NotImplementedException("Struct interfaces not yet supported");

            WriteLine("{");
            In();

            this.VisitMemberList(Struct.Members);

            Out();
            WriteLine("}");

            return Struct;
        }
Пример #9
0
 private void ParseTypeDeclaration(Namespace ns, TypeNode parentType, AttributeList attributes, TokenList modifierTokens,
   SourceContextList modifierContexts, TypeFlags flags, bool isPartial, SourceContext sctx, TokenSet followers){
   if (parentType is Interface){
     this.HandleError(Error.InterfacesCannotContainTypes);
     modifierTokens = null;
   }
   TypeNode t = null;
   InvariantCt = 0;
   switch(this.currentToken){
     case Token.Class:
       Class c = new Class();
       t = c;
       if (parentType == null)
         t.DeclaringNamespace = ns;
       else
         t.DeclaringType = parentType;
       if (modifierTokens != null)
         t.Flags |= this.NestedTypeFlags(modifierTokens, modifierContexts, t, isPartial)|TypeFlags.BeforeFieldInit;
       else{
         t.IsUnsafe = this.inUnsafeCode;
         t.Flags |= flags|TypeFlags.BeforeFieldInit;
       }
       if (t.IsAbstract && t.IsSealed && t.IsSpecialName){
         c.IsAbstractSealedContainerForStatics = true;
         c.Flags &= ~TypeFlags.SpecialName;
       }
       break;
     case Token.Interface:
       t = new Interface();
       if (parentType == null)
         t.DeclaringNamespace = ns;
       else
         t.DeclaringType = parentType;
       if (modifierTokens != null)
         t.Flags |= this.NestedTypeFlags(modifierTokens, modifierContexts, t, isPartial);
       else{
         if ((flags & TypeFlags.Abstract) != 0){
           if ((flags & TypeFlags.Sealed) != 0 && (flags & TypeFlags.SpecialName) != 0){
             this.HandleError(Error.InvalidModifier, "static");
             flags &= ~(TypeFlags.Abstract|TypeFlags.Sealed|TypeFlags.SpecialName);
           }else{
             this.HandleError(Error.InvalidModifier, "abstract");
             flags &= ~TypeFlags.Abstract;
           }
         }else if ((flags & TypeFlags.Sealed) != 0){
           this.HandleError(Error.InvalidModifier, "sealed");
           flags &= ~TypeFlags.Sealed;
         }
         t.IsUnsafe = this.inUnsafeCode;
         t.Flags |= flags|TypeFlags.BeforeFieldInit;
       }
       break;
     case Token.Struct:
       t = new Struct();
       if (parentType == null)
         t.DeclaringNamespace = ns;
       else
         t.DeclaringType = parentType;
       if (modifierTokens != null)
         t.Flags |= this.NestedTypeFlags(modifierTokens, modifierContexts, t, isPartial)|TypeFlags.BeforeFieldInit;
       else{
         if ((flags & TypeFlags.Abstract) != 0){
           if ((flags & TypeFlags.Sealed) != 0 && (flags & TypeFlags.SpecialName) != 0){
             this.HandleError(Error.InvalidModifier, "static");
             flags &= ~(TypeFlags.Abstract|TypeFlags.Sealed|TypeFlags.SpecialName);
           }else{
             this.HandleError(Error.InvalidModifier, "abstract");
             flags &= ~TypeFlags.Abstract;
           }
         }else if ((flags & TypeFlags.Sealed) != 0){
           this.HandleError(Error.InvalidModifier, "sealed");
         }
         t.IsUnsafe = this.inUnsafeCode;
         t.Flags |= flags|TypeFlags.BeforeFieldInit;
       }
       break;
     default:
       Debug.Assert(false);
       break;
   }
   t.Attributes = attributes;
   t.SourceContext = sctx;
   t.DeclaringModule = this.module;
   t.Documentation = this.LastDocComment;
   this.GetNextToken();
   t.Name = this.scanner.GetIdentifier();
   if (Parser.IdentifierOrNonReservedKeyword[this.currentToken])
     this.GetNextToken();
   else{
     this.SkipIdentifierOrNonReservedKeyword();
     if (Parser.IdentifierOrNonReservedKeyword[this.currentToken]){
       t.Name = this.scanner.GetIdentifier();
       this.GetNextToken();
     }
   }
   if (this.currentToken == Token.LessThan)
     this.ParseTypeParameters(t, followers|Token.Colon|Token.LeftBrace|Token.Where);
   if (parentType != null){
     t.Namespace = Identifier.Empty;
     if (parentType.IsGeneric) t.IsGeneric = true;
   }else
     t.Namespace = ns.FullNameId;
   Identifier mangledName = t.Name;
   if (Cci.TargetPlatform.GenericTypeNamesMangleChar != 0) {
     int numPars = t.TemplateParameters == null ? 0 : t.TemplateParameters.Count;
     if (numPars > 0){
       mangledName = new Identifier(t.Name.ToString() + Cci.TargetPlatform.GenericTypeNamesMangleChar + numPars.ToString(), t.Name.SourceContext);
       t.IsGeneric = this.useGenerics;
     }
   }
   t.PartiallyDefines = this.GetCompleteType(t, mangledName, isPartial);
   if (isPartial){
     isPartial = t.PartiallyDefines != null;
     if (!isPartial)
       t.Name = new Identifier(t.Name+" "+t.UniqueKey, t.Name.SourceContext);
   }else
     isPartial = t.PartiallyDefines != null;
   if (parentType != null){
     if (!isPartial || parentType.PartiallyDefines != null)
       parentType.Members.Add(t);
   }else{
     ns.Types.Add(t);
     if (!isPartial) this.AddTypeToModule(t);
   }
   if (this.currentToken == Token.Colon){
     this.GetNextToken();
     t.Interfaces = this.ParseInterfaceList(followers|Token.LeftBrace|Token.Where, true); //The first of these might be the base class, but that is a semantic issue
   }else
     t.Interfaces = new InterfaceList(); //TODO: omit this?
   t.InterfaceExpressions = t.Interfaces;
   while (this.currentToken == Token.Where)
     this.ParseTypeParameterConstraint(t, followers|Token.LeftBrace|Token.Where);
   t.SourceContext.EndPos = this.scanner.endPos;
   SourceContext typeBodyCtx = this.scanner.CurrentSourceContext;
   this.Skip(Token.LeftBrace);
 tryAgain:
   this.ParseTypeMembers(t, followers|Token.RightBrace);
   if (this.currentToken == Token.Namespace){
     this.HandleError(Error.InvalidMemberDecl, this.scanner.CurrentSourceContext.SourceText);
     this.currentToken = Token.Class;
     goto tryAgain;
   }
   int endCol = this.scanner.endPos;
   this.ParseBracket(t.SourceContext, Token.RightBrace, followers|Token.Semicolon, Error.ExpectedRightBrace);
   t.SourceContext.EndPos = endCol;
   t.Name = mangledName;
   if (this.currentToken == Token.Semicolon)
     this.GetNextToken();
   if (this.sink != null){
     typeBodyCtx.EndPos = endCol;
     this.sink.AddCollapsibleRegion(typeBodyCtx, false);
   }
   this.SkipTo(followers|Parser.TypeMemberStart);
   if (!followers[this.currentToken])
     this.SkipTo(followers, Error.NamespaceUnexpected);
   if (isPartial) this.MergeWithCompleteType(t);
 }
Пример #10
0
 private TypeNode GetCompleteType(TypeNode partialType, Identifier mangledName, bool isPartial){
   Debug.Assert(partialType != null);
   TypeNode completeType = null;
   TypeNode declaringType = partialType.DeclaringType;
   if (declaringType == null)
     completeType = this.module.GetType(partialType.Namespace, mangledName);
   else{
     if (declaringType.PartiallyDefines != null)
       declaringType = declaringType.PartiallyDefines;
     completeType = declaringType.GetNestedType(mangledName);
     declaringType.NestedTypes = null;
   }
   if (completeType == null){
     if (!isPartial) return null;
     if (partialType is Class){
       completeType = new Class();
       ((Class)completeType).BaseClass = (Class)partialType.BaseType;
     }else if (partialType is Struct)
       completeType = new Struct();
     else{
       Debug.Assert(partialType is Interface);
       completeType = new Interface();
     }
     completeType.Attributes = new AttributeList();
     completeType.Flags = partialType.Flags;
     completeType.DeclaringModule = this.module;
     completeType.DeclaringType = declaringType;
     completeType.Interfaces = new InterfaceList();
     completeType.Name = mangledName;
     completeType.Namespace = partialType.Namespace;
     //completeType.Documentation = ; //TODO: figure out if documentation gets merged
     if (declaringType == null)
       this.AddTypeToModule(completeType);
     else
       declaringType.Members.Add(completeType);
     completeType.IsDefinedBy = new TypeNodeList();
   }else{
     if (completeType.IsDefinedBy == null){
       if (isPartial)
         this.HandleError(completeType.Name.SourceContext, Error.MissingPartial, completeType.Name.ToString());
       return null;
     }else if (!isPartial){
       this.HandleError(partialType.Name.SourceContext, Error.MissingPartial, partialType.Name.ToString());
     }else if (completeType.NodeType != partialType.NodeType)
       this.HandleError(partialType.Name.SourceContext, Error.PartialTypeKindConflict, partialType.Name.ToString());
   }
   completeType.IsDefinedBy.Add(partialType);
   return completeType;
 }
Пример #11
0
    private void CopyStructValue(ISymValue destAddr, ISymValue srcAddr, Struct type) {
      if (destAddr == null) return;

      foreach (IUniqueKey key in this.egraph.Functions(srcAddr)) {
        Field field = key as Field;
        Member member = null;
        TypeNode membertype = null;
        if (field != null) {
          member = field;
          membertype = field.Type;
        }
        else {
          Property prop = key as Property;
          if (prop == null) continue;
          member = prop;
          membertype = prop.Type;
        }
        if (member == null) continue;
        ISymValue destFld = this.egraph[member, destAddr];
        ISymValue srcFld = this.egraph[member, srcAddr];
        Struct memberStruct = type as Struct;
        if (memberStruct != null && !memberStruct.IsPrimitive) {
          // nested struct copy
          CopyStructValue(destFld, srcFld, memberStruct);
        }
        else {
          // primitive|pointer copy
          this.egraph[ValueOf, destFld] = this.egraph[ValueOf, srcFld];
        }
      }
    }
Пример #12
0
        private void collectStructAccessors(bool isGlobalVar, Struct s,
                                            Expression expPrefix,
                                            string strPrefix, Class theClass)
        {
            if (s == null)
                return;

            for (int i = 0, n = s.Members.Count; i < n; i++)
            {
                Field f = s.Members[i] as Field;

                if (f == null)
                    continue;

                string name = strPrefix + "_" + f.Name.Name;
                QualifiedIdentifier qf = new QualifiedIdentifier(expPrefix, f.Name);

                TypeNode generatedType = f.Type;
                if (GetTypeClassification(f.Type) == TypeClassification.Heap)
                    generatedType = this.ZingPtrType;
                else if (!IsPredefinedType(f.Type))
                    generatedType = new TypeExpression(new QualifiedIdentifier(
                        new Identifier("Application"), f.Type.Name), f.Type.SourceContext);

                QualifiedIdentifier localsInputsOrOutputs = isGlobalVar ?
                    new QualifiedIdentifier(new Identifier("LocType"), new Identifier("Global")) :
                    new QualifiedIdentifier(new Identifier("LocType"), new Identifier("Local"));

                Property accessor =
                    GetStructAccessorProperty(isGlobalVar ? "globalAccessor" : "localAccessor",
                                        generatedType, new Identifier("__strprops_" + name),
                                        qf, localsInputsOrOutputs);

                theClass.Members.Add(accessor);
                accessor.DeclaringType = theClass;
                if (accessor.Getter != null)
                {
                    theClass.Members.Add(accessor.Getter);
                    accessor.Getter.DeclaringType = theClass;
                }
                if (accessor.Setter != null)
                {
                    theClass.Members.Add(accessor.Setter);
                    accessor.Setter.DeclaringType = theClass;
                }

                if (f.Type is Struct && !f.Type.IsPrimitive && f.Type != SystemTypes.Decimal)
                    collectStructAccessors(isGlobalVar, (Struct)f.Type,
                                           qf, name, theClass);
            }
        }
Пример #13
0
        private void GenerateStruct(Struct structNode)
        {
            TypeNode newStruct = Templates.GetTypeTemplateByName("Struct");
            Method writer = (Method)Templates.GetMemberByName(newStruct.Members, "WriteString");

            // Replace all references to the struct name
            Replacer.Replace(newStruct, newStruct.Name, structNode.Name);

            for (int i = 0, n = structNode.Members.Count; i < n; i++)
            {
                Field f = structNode.Members[i] as Field;
                if (f != null)
                {
                    // Clone the field since we might tinker with it (see other TODO below)
                    Field newField = (Field)f.Clone();

                    if (GetTypeClassification(f.Type) == TypeClassification.Heap)
                        newField.Type = this.ZingPtrType;
                    else if (!IsPredefinedType(f.Type))
                        newField.Type = new TypeExpression(new QualifiedIdentifier(
                            new Identifier("Application"), f.Type.Name), f.Type.SourceContext);

                    newStruct.Members.Add(newField);
                    newField.DeclaringType = newStruct;

                    writer.Body.Statements.Add(GetWriterStatement("this", f.Type, newField.Name));
                }
            }

            // TODO: Add a CompareTo method to the struct (low priority)

            string s = writer.FullName;
            InstallType(newStruct);
        }
Пример #14
0
 public virtual Struct VisitStruct(Struct Struct)
 {
     return (Struct)this.VisitTypeNode(Struct);
 }
Пример #15
0
        private static void ClearStatics()
        {
            //Special base types
            Object = null;
            String = null;
            ValueType = null;
            Enum = null;
            MulticastDelegate = null;
            Array = null;
            Type = null;
            Delegate = null;
            Exception = null;
            Attribute = null;

            //primitive types
            Boolean = null;
            Char = null;
            Int8 = null;
            UInt8 = null;
            Int16 = null;
            UInt16 = null;
            Int32 = null;
            UInt32 = null;
            Int64 = null;
            UInt64 = null;
            Single = null;
            Double = null;
            IntPtr = null;
            UIntPtr = null;
            DynamicallyTypedReference = null;

            //Special types
            DBNull = null;
            DateTime = null;
            Decimal = null;
            RuntimeArgumentHandle = null;
            ArgIterator = null;
            RuntimeFieldHandle = null;
            RuntimeMethodHandle = null;
            RuntimeTypeHandle = null;
            IsVolatile = null;
            Void = null;
            SecurityAction = null;
        }
Пример #16
0
        public override Struct VisitStruct(Struct Struct)
        {
            WriteStart("struct {0}", Struct.Name.Name);

            if (this.braceOnNewLine)
            {
                WriteFinish(string.Empty);
                WriteLine("{");
            }
            else
                WriteFinish(" {");

            In();
            this.VisitMemberList(Struct.Members);
            Out();
            WriteLine("};");

            return Struct;
        }
Пример #17
0
 public EventingVisitor(Action<Struct> visitStruct) { VisitedStruct += visitStruct; } public event Action<Struct> VisitedStruct; public override Struct VisitStruct(Struct Struct) { if (VisitedStruct != null) VisitedStruct(Struct); return base.VisitStruct(Struct); }