Exemple #1
0
        /// <summary>
        /// Strip off *, &amp;, and [].
        /// </summary>
        private static ITypeReference UnwrapTypeReference(ITypeReference typeReference, EmitContext context)
        {
            while (true)
            {
                IArrayTypeReference arrType = typeReference as IArrayTypeReference;
                if (arrType != null)
                {
                    typeReference = arrType.GetElementType(context);
                    continue;
                }

                IPointerTypeReference pointer = typeReference as IPointerTypeReference;
                if (pointer != null)
                {
                    typeReference = pointer.GetTargetType(context);
                    continue;
                }

                IManagedPointerTypeReference reference = typeReference as IManagedPointerTypeReference;
                if (reference != null)
                {
                    typeReference = reference.GetTargetType(context);
                    continue;
                }

                return(typeReference);
            }
        }
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     if (Process(managedPointerTypeReference))
     {
         visitor.Visit(managedPointerTypeReference);
     }
     base.Visit(managedPointerTypeReference);
 }
Exemple #3
0
        public override void TraverseChildren(IAddressDereference addressDereference)
        {
            base.TraverseChildren(addressDereference);
            IPointerTypeReference /*?*/ pointerTypeReference = addressDereference.Address.Type as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                if (!(pointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = pointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, pointerTypeReference.TargetType))
                    {
                        var targetPointerType = Immutable.PointerType.GetPointerType(addressDereference.Type, this.host.InternFactory);
                        ((AddressDereference)addressDereference).Address = new Conversion()
                        {
                            ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                        };
                    }
                    return;
                }
            }
            IManagedPointerTypeReference /*?*/ managedPointerTypeReference = addressDereference.Address.Type as IManagedPointerTypeReference;

            if (managedPointerTypeReference != null)
            {
                if (!(managedPointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, managedPointerTypeReference.TargetType))
                    {
                        if (managedPointerTypeReference.TargetType.TypeCode == PrimitiveTypeCode.Boolean && addressDereference.Type.TypeCode == PrimitiveTypeCode.Int8)
                        {
                            ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                        }
                        else
                        {
                            var targetPointerType = Immutable.ManagedPointerType.GetManagedPointerType(addressDereference.Type, this.host.InternFactory);
                            ((AddressDereference)addressDereference).Address = new Conversion()
                            {
                                ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                            };
                        }
                    }
                    return;
                }
            }
        }
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference) {
   managedPointerTypeReference.TargetType.ResolvedType.Dispatch(this);
   int h = this.hash;
   h = (h << 5 + h) ^ 1;
   this.hash = h;
 }
Exemple #5
0
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     this.result = this.mapper.GetType(managedPointerTypeReference.TargetType).MakeByRefType();
 }
Exemple #6
0
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference) {
   this.result = this.mapper.GetType(managedPointerTypeReference.TargetType).MakeByRefType();
 }
Exemple #7
0
 public override void TraverseChildren(IManagedPointerTypeReference managedPointerTypeReference)
 {
     MethodEnter(managedPointerTypeReference);
     base.TraverseChildren(managedPointerTypeReference);
     MethodExit();
 }
 public override void TraverseChildren(IManagedPointerTypeReference managedPointerTypeReference) {
   base.TraverseChildren(managedPointerTypeReference);
 }
Exemple #9
0
 /// <summary>
 /// Performs some computation with the given managed pointer type reference.
 /// </summary>
 public void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     this.Visit((ITypeReference)managedPointerTypeReference);
 }
Exemple #10
0
        internal static string GetSerializedTypeName(this ITypeReference typeReference, EmitContext context, ref bool isAssemblyQualified)
        {
            var                 pooled  = PooledStringBuilder.GetInstance();
            StringBuilder       sb      = pooled.Builder;
            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                typeReference = arrType.GetElementType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                if (arrType.IsVector)
                {
                    sb.Append("[]");
                }
                else
                {
                    sb.Append('[');
                    if (arrType.Rank == 1)
                    {
                        sb.Append('*');
                    }

                    sb.Append(',', (int)arrType.Rank - 1);

                    sb.Append(']');
                }

                goto done;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                typeReference = pointer.GetTargetType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                sb.Append('*');
                goto done;
            }

            IManagedPointerTypeReference reference = typeReference as IManagedPointerTypeReference;

            if (reference != null)
            {
                typeReference = reference.GetTargetType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                sb.Append('&');
                goto done;
            }

            INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                if (namespaceType.NamespaceName.Length != 0)
                {
                    sb.Append(namespaceType.NamespaceName);
                    sb.Append('.');
                }

                sb.Append(GetMangledAndEscapedName(namespaceType));
                goto done;
            }

            if (typeReference.IsTypeSpecification())
            {
                ITypeReference uninstantiatedTypeReference = typeReference.GetUninstantiatedGenericType();

                ArrayBuilder <ITypeReference> consolidatedTypeArguments = ArrayBuilder <ITypeReference> .GetInstance();

                typeReference.GetConsolidatedTypeArguments(consolidatedTypeArguments, context);

                bool uninstantiatedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(uninstantiatedTypeReference, context, ref uninstantiatedTypeIsAssemblyQualified));
                sb.Append('[');
                bool first = true;
                foreach (ITypeReference argument in consolidatedTypeArguments)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }

                    bool isAssemQual = true;
                    AppendSerializedTypeName(sb, argument, ref isAssemQual, context);
                }
                consolidatedTypeArguments.Free();

                sb.Append(']');
                goto done;
            }

            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                bool nestedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(nestedType.GetContainingType(context), context, ref nestedTypeIsAssemblyQualified));
                sb.Append('+');
                sb.Append(GetMangledAndEscapedName(nestedType));
                goto done;
            }

            // TODO: error
done:
            if (isAssemblyQualified)
            {
                AppendAssemblyQualifierIfNecessary(sb, UnwrapTypeReference(typeReference, context), out isAssemblyQualified, context);
            }

            return(pooled.ToStringAndFree());
        }
Exemple #11
0
 /// <summary>
 /// Traverses the managed pointer type reference.
 /// </summary>
 public void Traverse(IManagedPointerTypeReference managedPointerTypeReference)
 {
     Contract.Requires(managedPointerTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(managedPointerTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(managedPointerTypeReference);
       if (this.stopTraversal) return;
       this.TraverseChildren(managedPointerTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(managedPointerTypeReference);
 }
 /// <summary>
 /// Rewrites the given managed pointer type reference.
 /// </summary>
 public virtual IManagedPointerTypeReference Rewrite(IManagedPointerTypeReference managedPointerTypeReference)
 {
     return managedPointerTypeReference;
 }
Exemple #13
0
        private static void AppendAssemblyQualifierIfNecessary(StringBuilder sb, ITypeReference typeReference, out bool isAssemQualified, EmitContext context)
        {
            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, nestedType.GetContainingType(context), out isAssemQualified, context);
                return;
            }

            IGenericTypeInstanceReference genInst = typeReference.AsGenericTypeInstanceReference;

            if (genInst != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, genInst.GenericType, out isAssemQualified, context);
                return;
            }

            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, arrType.GetElementType(context), out isAssemQualified, context);
                return;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context);
                return;
            }

            IManagedPointerTypeReference reference = typeReference as IManagedPointerTypeReference;

            if (reference != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context);
                return;
            }

            isAssemQualified = false;
            IAssemblyReference      referencedAssembly = null;
            INamespaceTypeReference namespaceType      = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                referencedAssembly = namespaceType.GetUnit(context) as IAssemblyReference;
            }

            if (referencedAssembly != null)
            {
                var containingAssembly = context.Module.GetContainingAssembly(context);

                if (containingAssembly == null || !ReferenceEquals(referencedAssembly, containingAssembly))
                {
                    sb.Append(", ");
                    sb.Append(MetadataWriter.StrongName(referencedAssembly));
                    isAssemQualified = true;
                }
            }
        }
 private void EmitTypeLoadingCallsFor(IManagedPointerTypeReference managedPointerType, string mangledName, SetOfUints alreadyLoadedTypes) {
   Contract.Requires(managedPointerType != null);
   Contract.Requires(mangledName != null);
   Contract.Requires(alreadyLoadedTypes != null);
   //TODO: implement this
   this.EmitSetTypeAndSetBaseClass((ITypeReference)managedPointerType, mangledName, alreadyLoadedTypes);
 }
Exemple #15
0
        public override string GetTypeName(ITypeReference type, NameFormattingOptions formattingOptions)
        {
            Contract.Requires(type != null);
            Contract.Ensures(Contract.Result <string>() != null);

            if (type is Dummy)
            {
                return("Microsoft.Cci.DummyTypeReference");
            }
            if ((formattingOptions & NameFormattingOptions.UseTypeKeywords) != 0)
            {
                switch (type.TypeCode)
                {
                case PrimitiveTypeCode.Boolean: return("Boolean");

                case PrimitiveTypeCode.Char: return("Char");

                case PrimitiveTypeCode.Float32: return("Float");

                case PrimitiveTypeCode.Float64: return("Double");

                case PrimitiveTypeCode.Int16: return("Short");

                case PrimitiveTypeCode.Int32: return("Integer");

                case PrimitiveTypeCode.Int64: return("Long");

                case PrimitiveTypeCode.Int8: return("SByte");

                case PrimitiveTypeCode.String: return("String");

                case PrimitiveTypeCode.UInt16: return("UShort");

                case PrimitiveTypeCode.UInt32: return("UInteger");

                case PrimitiveTypeCode.UInt64: return("ULong");

                case PrimitiveTypeCode.UInt8: return("Byte");

                case PrimitiveTypeCode.Void: { Contract.Assert(false); throw new InvalidOperationException(); }

                case PrimitiveTypeCode.NotPrimitive:
                    if (TypeHelper.TypesAreEquivalent(type, type.PlatformType.SystemDecimal))
                    {
                        return("Decimal");
                    }
                    if (TypeHelper.TypesAreEquivalent(type, type.PlatformType.SystemObject))
                    {
                        return("Object");
                    }
                    break;
                }
            }
            IArrayTypeReference /*?*/ arrayType = type as IArrayTypeReference;

            if (arrayType != null)
            {
                return(this.GetArrayTypeName(arrayType, formattingOptions));
            }
            IFunctionPointerTypeReference /*?*/ functionPointerType = type as IFunctionPointerTypeReference;

            if (functionPointerType != null)
            {
                return(this.GetFunctionPointerTypeName(functionPointerType, formattingOptions));
            }
            IGenericTypeParameterReference /*?*/ genericTypeParam = type as IGenericTypeParameterReference;

            if (genericTypeParam != null)
            {
                return(this.GetGenericTypeParameterName(genericTypeParam, formattingOptions));
            }
            IGenericMethodParameterReference /*?*/ genericMethodParam = type as IGenericMethodParameterReference;

            if (genericMethodParam != null)
            {
                return(this.GetGenericMethodParameterName(genericMethodParam, formattingOptions));
            }
            IGenericTypeInstanceReference /*?*/ genericInstance = type as IGenericTypeInstanceReference;

            if (genericInstance != null)
            {
                return(this.GetGenericTypeInstanceName(genericInstance, formattingOptions));
            }
            INestedTypeReference /*?*/ ntTypeDef = type as INestedTypeReference;

            if (ntTypeDef != null)
            {
                return(this.GetNestedTypeName(ntTypeDef, formattingOptions));
            }
            INamespaceTypeReference /*?*/ nsTypeDef = type as INamespaceTypeReference;

            if (nsTypeDef != null)
            {
                return(this.GetNamespaceTypeName(nsTypeDef, formattingOptions));
            }
            IPointerTypeReference /*?*/ pointerType = type as IPointerTypeReference;

            if (pointerType != null)
            {
                return(this.GetPointerTypeName(pointerType, formattingOptions));
            }
            IManagedPointerTypeReference /*?*/ managedPointerType = type as IManagedPointerTypeReference;

            if (managedPointerType != null)
            {
                return(this.GetManagedPointerTypeName(managedPointerType, formattingOptions));
            }
            IModifiedTypeReference /*?*/ modifiedType = type as IModifiedTypeReference;

            if (modifiedType != null)
            {
                return(this.GetModifiedTypeName(modifiedType, formattingOptions));
            }
            if (type.ResolvedType != type && !(type.ResolvedType is Dummy))
            {
                return(this.GetTypeName(type.ResolvedType, formattingOptions));
            }
            return("unknown type: " + type.GetType().ToString());
        }
Exemple #16
0
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     allElements.Add(new InvokInfo(Traverser, "IManagedPointerTypeReference", managedPointerTypeReference));
 }
Exemple #17
0
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     Debug.Assert(false, "Unexpected ref type!");
 }
Exemple #18
0
 public void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     this.traverser.Traverse(managedPointerTypeReference);
 }
Exemple #19
0
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     Debug.Assert(false, "Unexpected ref type!");
 }
 public override void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     if(Process(managedPointerTypeReference)){visitor.Visit(managedPointerTypeReference);}
     base.Visit(managedPointerTypeReference);
 }
Exemple #21
0
 /// <summary>
 /// Traverses the children of the managed pointer type reference.
 /// </summary>
 public virtual void TraverseChildren(IManagedPointerTypeReference managedPointerTypeReference)
 {
     Contract.Requires(managedPointerTypeReference != null);
       this.TraverseChildren((ITypeReference)managedPointerTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(managedPointerTypeReference.TargetType);
 }
Exemple #22
0
 /// <summary>
 /// Performs some computation with the given managed pointer type reference.
 /// </summary>
 /// <param name="managedPointerTypeReference"></param>
 public virtual void Visit(IManagedPointerTypeReference managedPointerTypeReference)
   //^ ensures this.path.Count == old(this.path.Count);
 {
 }
Exemple #23
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given managed pointer type reference.
 /// </summary>
 /// <param name="managedPointerTypeReference"></param>
 public virtual void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
 }
Exemple #24
0
 public virtual void onMetadataElement(IManagedPointerTypeReference managedPointerTypeReference)
 {
 }
Exemple #25
0
 public virtual void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
 }
        public override void TraverseChildren(IManagedPointerTypeReference managedPointerTypeReference)
{ MethodEnter(managedPointerTypeReference);
            base.TraverseChildren(managedPointerTypeReference);
     MethodExit();   }
 public virtual void onMetadataElement(IManagedPointerTypeReference managedPointerTypeReference) { }
Exemple #28
0
 public void Visit(IManagedPointerTypeReference managedPointerTypeReference)
 {
     throw new NotImplementedException();
 }
        private static void WriteType(ITypeReference type, TextWriter writer, bool omitOutermostTypeFormals)
        {
            Contract.Requires(type != null);
            Contract.Requires(writer != null);

            IArrayType array = type as IArrayType;

            if (array != null)
            {
                Contract.Assume(array.ElementType != null, "lack of CCI2 contracts");

                WriteType(array.ElementType, writer);
                writer.Write("[");
                if (array.Rank > 1)
                {
                    for (int i = 0; i < array.Rank; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(",");
                        }
                        writer.Write("0:");
                    }
                }
                writer.Write("]");
                return;
            }

            IManagedPointerTypeReference reference = type as IManagedPointerTypeReference;;

            if (reference != null)
            {
                Contract.Assume(reference.TargetType != null, "lack of CCI2 contracts");

                var referencedType = reference.TargetType;
                WriteType(referencedType, writer);
                writer.Write("@");
                return;
            }

            IPointerTypeReference pointer = type as IPointerTypeReference;

            if (pointer != null)
            {
                Contract.Assume(pointer.TargetType != null, "lack of CCI2 contracts");

                WriteType(pointer.TargetType, writer);
                writer.Write("*");
                return;
            }

            IModifiedTypeReference modref = type as IModifiedTypeReference;

            if (modref != null)
            {
                Contract.Assume(modref.UnmodifiedType != null, "lack of CCI2 contracts");
                Contract.Assume(modref.CustomModifiers != null, "lack of CCI2 contracts");

                WriteType(modref.UnmodifiedType, writer);
                foreach (var modifier in modref.CustomModifiers)
                {
                    Contract.Assume(modifier != null, "lack of collection contracts and CCI2 contracts");
                    Contract.Assume(modifier.Modifier != null, "lack of CCI2 contracts");

                    if (modifier.IsOptional)
                    {
                        writer.Write("!");
                    }
                    else
                    {
                        writer.Write("|");
                    }
                    WriteType(modifier.Modifier, writer);
                }
                return;
            }

            IGenericTypeParameterReference gtp = type as IGenericTypeParameterReference;

            if (gtp != null)
            {
                writer.Write("`");
                writer.Write(gtp.Index);
                return;
            }
            IGenericMethodParameterReference gmp = type as IGenericMethodParameterReference;

            if (gmp != null)
            {
                writer.Write("``");
                writer.Write(gmp.Index);
                return;
            }

            IGenericTypeInstanceReference instance = type as IGenericTypeInstanceReference;

            if (instance != null)
            {
                Contract.Assume(instance.GenericType != null, "lack of CCI2 contracts");
                Contract.Assume(instance.GenericArguments != null, "lack of CCI2 contracts");

                WriteType(instance.GenericType, writer, true);
                writer.Write("{");
                var first = true;
                foreach (var arg in instance.GenericArguments)
                {
                    Contract.Assume(arg != null, "lack of collection and CCI2 contracts");

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(",");
                    }
                    WriteType(arg, writer);
                }
                writer.Write("}");
                return;
            }

            // namespace or nested
            INamedTypeReference  named  = (INamedTypeReference)type;
            INestedTypeReference nested = type as INestedTypeReference;

            if (nested != null)
            {
                Contract.Assume(nested.ContainingType != null, "lack of CCI2 contracts");

                // names of nested types begin with outer type name
                WriteType(nested.ContainingType, writer);
                writer.Write(".");
                // continue to write type sig
            }

            INamespaceTypeReference nt = type as INamespaceTypeReference;

            if (nt != null)
            {
                Contract.Assume(nt.ContainingUnitNamespace != null, "lack of CCI2 contracts");

                WriteNamespaceAndSeparator(nt.ContainingUnitNamespace, writer);
                // continue to write type sig
            }
            // name
            writer.Write(named.Name.Value);
            // generic parameters
            if (omitOutermostTypeFormals)
            {
                return;
            }

            if (named.GenericParameterCount > 0)
            {
                writer.Write("`{0}", named.GenericParameterCount);
            }
        }
 /// <summary>
 /// Traverses the children of the managed pointer type reference.
 /// </summary>
 public virtual void TraverseChildren(IManagedPointerTypeReference managedPointerTypeReference)
 {
     this.TraverseChildren((ITypeReference)managedPointerTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(managedPointerTypeReference.TargetType);
 }