예제 #1
0
 public override void VisitArrayTypeReference <TTypeReference>(IArrayTypeReference <TTypeReference> arrayTypeReference)
 {
     Value = new TypeReference()
     {
         ArrayTypeReference = new ArrayTypeReferenceFactory(arrayTypeReference).Value
     };
 }
예제 #2
0
 internal ArrayExpression(
   IArrayTypeReference vectorType,
   EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> elements
 ) {
   this.VectorType = vectorType;
   this.Elements = elements;
 }
예제 #3
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);
            }
        }
예제 #4
0
        private static void InitializeArrayCreateInstruction(Instruction instruction, Stack <Instruction> stack, IOperation currentOperation)
        {
            Contract.Requires(instruction != null);
            Contract.Requires(stack != null);
            Contract.Requires(currentOperation != null);
            IArrayTypeReference arrayType = (IArrayTypeReference)currentOperation.Value;

            Contract.Assume(arrayType != null); //This is an informally specified property of the Metadata model.
            var rank = arrayType.Rank;

            if (rank > 0)
            {
                if (currentOperation.OperationCode == OperationCode.Array_Create_WithLowerBound)
                {
                    rank *= 2;
                }
                rank--;
                if (rank > 0)
                {
                    var indices = new Instruction[rank];
                    instruction.Operand2 = indices;
                    for (var i = rank; i > 0; i--)
                    {
                        indices[i - 1] = stack.Pop();
                    }
                }
                instruction.Operand1 = stack.Pop();
            }
            stack.Push(instruction);
        }
예제 #5
0
        // Array and pointer types might cause deep recursions; visit them iteratively
        // rather than recursively.
        public override void Visit(IArrayTypeReference arrayTypeReference)
        {
            // We don't visit the current array type; it has already been visited.
            // We go straight to the element type and visit it.
            ITypeReference current = arrayTypeReference.GetElementType(Context);

            while (true)
            {
                bool mustVisitChildren = VisitTypeReference(current);
                if (!mustVisitChildren)
                {
                    return;
                }
                else if (current is IArrayTypeReference)
                {
                    // The element type is itself an array type, and we must visit *its* element type.
                    // Iterate rather than recursing.
                    current = ((IArrayTypeReference)current).GetElementType(Context);
                    continue;
                }
                else
                {
                    // The element type is not an array type and we must visit its children.
                    // Dispatch the type in order to visit its children.
                    DispatchAsReference(current);
                    return;
                }
            }
        }
예제 #6
0
        private void InitializeArrayCreateInstruction(Instruction instruction, LocalsAndOperands <V> state, IOperation currentOperation)
        {
            /* Contract.Requires(instruction != null);
             * Contract.Requires(stack != null);
             * Contract.Requires(currentOperation != null);
             * IArrayTypeReference arrayType = (IArrayTypeReference)currentOperation.Value;
             * Contract.Assume(arrayType != null); //This is an informally specified property of the Metadata model.
             * var rank = arrayType.Rank;
             * if (currentOperation.OperationCode == OperationCode.Array_Create_WithLowerBound) rank *= 2;
             * var indices = new Instruction[rank];
             * instruction.Operand2 = indices;
             * for (var i = rank; i > 0; i--)
             * indices[i - 1] = stack.Pop();
             * stack.Push(instruction);
             */

            IArrayTypeReference arrayType = (IArrayTypeReference)currentOperation.Value;

            Contract.Assume(arrayType != null); //This is an informally specified property of the Metadata model.
            var rank = arrayType.Rank;

            if (currentOperation.OperationCode == OperationCode.Array_Create_WithLowerBound)
            {
                rank *= 2;
            }
            for (var i = rank; i > 0; i--)
            {
                state.Pop();
            }
            state.Push(ValueAbstraction.Top); // can be smarter than Top
        }
 public override void Visit(IArrayTypeReference arrayTypeReference)
 {
     if (Process(arrayTypeReference))
     {
         visitor.Visit(arrayTypeReference);
     }
     base.Visit(arrayTypeReference);
 }
예제 #8
0
        private static void VisitTypeReference(ITypeReference typeReference, EmitContext context)
        {
            Debug.Assert(typeReference != null);

            IArrayTypeReference arrayType = typeReference as IArrayTypeReference;

            if (arrayType != null)
            {
                VisitTypeReference(arrayType.GetElementType(context), context);
                return;
            }

            IPointerTypeReference pointerType = typeReference as IPointerTypeReference;

            if (pointerType != null)
            {
                VisitTypeReference(pointerType.GetTargetType(context), context);
                return;
            }

            //IManagedPointerTypeReference managedPointerType = typeReference as IManagedPointerTypeReference;
            //if (managedPointerType != null)
            //{
            //    VisitTypeReference(managedPointerType.GetTargetType(this.context));
            //    return;
            //}

            IModifiedTypeReference modifiedType = typeReference as IModifiedTypeReference;

            if (modifiedType != null)
            {
                foreach (var custModifier in modifiedType.CustomModifiers)
                {
                    VisitTypeReference(custModifier.GetModifier(context), context);
                }
                VisitTypeReference(modifiedType.UnmodifiedType, context);
                return;
            }

            // Visit containing type
            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                VisitTypeReference(nestedType.GetContainingType(context), context);
            }

            // Visit generic arguments
            IGenericTypeInstanceReference genericInstance = typeReference.AsGenericTypeInstanceReference;

            if (genericInstance != null)
            {
                foreach (var arg in genericInstance.GetGenericArguments(context))
                {
                    VisitTypeReference(arg, context);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Appends a C#-like specific string of the dimensions of the given array type reference to the given StringBuilder.
        /// <example>For example, this appends the "[][,]" part of an array like "int[][,]".</example>
        /// </summary>
        protected override void AppendArrayDimensions(IArrayTypeReference arrayType, StringBuilder sb, NameFormattingOptions formattingOptions)
        {
            Contract.Requires(arrayType != null);
            Contract.Requires(sb != null);

            IArrayTypeReference /*?*/ elementArrayType = arrayType.ElementType as IArrayTypeReference;
            bool formattingForDocumentationId          = (formattingOptions & NameFormattingOptions.FormattingForDocumentationId) != 0;

            if (formattingForDocumentationId && elementArrayType != null) //Append the outer dimensions of the array first
            {
                this.AppendArrayDimensions(elementArrayType, sb, formattingOptions);
            }
            sb.Append("(");
            if (!arrayType.IsVector)
            {
                if (formattingForDocumentationId)
                {
                    bool first = true;
                    IEnumerator <int>   lowerBounds = arrayType.LowerBounds.GetEnumerator();
                    IEnumerator <ulong> sizes       = arrayType.Sizes.GetEnumerator();
                    for (int i = 0; i < arrayType.Rank; i++)
                    {
                        if (!first)
                        {
                            sb.Append(",");
                        }
                        first = false;
                        if (lowerBounds.MoveNext())
                        {
                            sb.Append(lowerBounds.Current);
                            sb.Append(":");
                            if (sizes.MoveNext())
                            {
                                sb.Append(sizes.Current);
                            }
                        }
                        else
                        {
                            if (sizes.MoveNext())
                            {
                                sb.Append("0:" + sizes.Current);
                            }
                        }
                    }
                }
                else
                {
                    sb.Append(',', (int)arrayType.Rank - 1);
                }
            }
            sb.Append(")");
            if (!formattingForDocumentationId && elementArrayType != null) //Append the inner dimensions of the array first
            {
                this.AppendArrayDimensions(elementArrayType, sb, formattingOptions);
            }
        }
        private bool IsStringArray(ITypeReference typeReference)
        {
            IArrayTypeReference atr = typeReference as IArrayTypeReference;

            if (atr == null)
            {
                return(false);
            }
            return(TypeHelper.TypesAreEquivalent(atr.ElementType, this.host.PlatformType.SystemString));
        }
예제 #11
0
 /// <summary>
 /// Performs some computation with the given array type reference.
 /// </summary>
 /// <param name="arrayTypeReference"></param>
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
   //^ ensures this.path.Count == old(this.path.Count);
 {
   if (this.stopTraversal) return;
   //^ int oldCount = this.path.Count;
   this.path.Push(arrayTypeReference);
   this.Visit(arrayTypeReference.ElementType);
   //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
   this.path.Pop();
 }
예제 #12
0
    public override void TraverseChildren(IArrayTypeReference arrayTypeReference)
    {
        var typ = arrayTypeReference.ResolvedType;

        if (typ == Dummy.Type)
        {
            this.EmitError(arrayTypeReference, ErrorCode.NamespaceTypeResolution);
        }
        base.TraverseChildren(arrayTypeReference);
    }
예제 #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.GetGenericType(context), 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;
            }

            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;
                }
            }
        }
예제 #14
0
        internal MethodInfo GetArrayCreateWithLowerBoundsMethod(IArrayTypeReference arrayTypeReference, ModuleBuilder moduleBuilder)
        {
            var type           = this.GetType(arrayTypeReference);
            var parameterTypes = new Type[arrayTypeReference.Rank * 2];

            for (int i = 0; i < arrayTypeReference.Rank * 2; i++)
            {
                parameterTypes[i] = typeof(int);
            }
            return(moduleBuilder.GetArrayMethod(type, ".ctor", CallingConventions.HasThis, typeof(void), parameterTypes));
        }
예제 #15
0
 public override void Visit(IArrayTypeReference arrayTypeReference)
 {
     if (arrayTypeReference.IsVector)
     {
         this.result = this.mapper.GetType(arrayTypeReference.ElementType).MakeArrayType();
     }
     else
     {
         this.result = this.mapper.GetType(arrayTypeReference.ElementType).MakeArrayType((int)arrayTypeReference.Rank);
     }
 }
예제 #16
0
        internal MethodInfo GetArrayGetMethod(IArrayTypeReference arrayTypeReference, ModuleBuilder moduleBuilder)
        {
            var type           = this.GetType(arrayTypeReference);
            var parameterTypes = new Type[arrayTypeReference.Rank];

            for (int i = 0; i < arrayTypeReference.Rank; i++)
            {
                parameterTypes[i] = typeof(int);
            }
            return(moduleBuilder.GetArrayMethod(type, "Get", CallingConventions.HasThis, type.GetElementType(), parameterTypes));
        }
예제 #17
0
        public override void TraverseChildren(IArrayIndexer arrayIndexer)
        {
            base.TraverseChildren(arrayIndexer);
            IArrayTypeReference /*?*/ arrayType = arrayIndexer.IndexedObject.Type as IArrayTypeReference;

            if (arrayType == null)
            {
                return;
            }
            ((ArrayIndexer)arrayIndexer).Type = arrayType.ElementType;
        }
예제 #18
0
        public static INamedTypeReference CanonicalizeTypeReference(ITypeReference type)
        {
            while (type != null)
            {
                IModifiedTypeReference          modifiedType = type as IModifiedTypeReference;
                IPointerTypeReference           ptrType      = type as IPointerTypeReference;
                IManagedPointerType             refType      = type as IManagedPointerType;
                IArrayTypeReference             arrType      = type as IArrayTypeReference;
                IGenericTypeInstanceReference   genType      = type as IGenericTypeInstanceReference;
                ISpecializedNestedTypeReference nestedType   = type as ISpecializedNestedTypeReference;
                // TODO: Why doesn't ISpecializedNestedTypeDefinition derive from ISpecializedNestedTypeReference?
                ISpecializedNestedTypeDefinition nestedTypeDef = type as ISpecializedNestedTypeDefinition;

                if (modifiedType != null)
                {
                    type = modifiedType.UnmodifiedType;
                }
                else if (ptrType != null)
                {
                    type = ptrType.TargetType;
                }
                else if (refType != null)
                {
                    type = refType.TargetType;
                }
                else if (arrType != null)
                {
                    type = arrType.ElementType;
                }
                else if (genType != null)
                {
                    type = genType.GenericType;
                }
                else if (nestedType != null)
                {
                    type = nestedType.UnspecializedVersion;
                }
                else if (nestedTypeDef != null)
                {
                    type = nestedTypeDef.UnspecializedVersion;
                }
                else /* ITypeDefinition */
                {
                    break;
                }
            }

            return(type as INamedTypeReference);
        }
예제 #19
0
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference ||
                            reference is IManagedPointerType,
                            string.Format("Unexpected type reference that we may need to unwrap {0}", (reference != null ? reference.GetType().FullName : "null")));

            return(reference);
        }
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference,
                            string.Format(CultureInfo.CurrentCulture, LocalizedStrings.UnexpectedTypeReference, (reference?.GetType()?.FullName ?? "null")));

            return(reference);
        }
예제 #21
0
        private static ArrayMethod MakeArrayMethod(IArrayTypeReference arrayType, ArrayMethodKind id)
        {
            switch (id)
            {
            case ArrayMethodKind.CTOR:
                return(new ArrayConstructor(arrayType));

            case ArrayMethodKind.GET:
                return(new ArrayGet(arrayType));

            case ArrayMethodKind.SET:
                return(new ArraySet(arrayType));

            case ArrayMethodKind.ADDRESS:
                return(new ArrayAddress(arrayType));
            }

            throw ExceptionUtilities.UnexpectedValue(id);
        }
예제 #22
0
        /// <summary>
        /// lazily fetches or creates a new array method.
        /// </summary>
        private ArrayMethod GetArrayMethod(IArrayTypeReference arrayType, ArrayMethodKind id)
        {
            var         key = new KeyValuePair <byte, IArrayTypeReference>((byte)id, arrayType);
            ArrayMethod result;

            var dict = _dict;

            if (!dict.TryGetValue(key, out result))
            {
                result = MakeArrayMethod(arrayType, id);
                if (dict.ContainsKey(key))
                {
                    result = dict[key];
                }
                else
                {
                    dict.Add(key, result);
                }
            }

            return(result);
        }
예제 #23
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.IsSZArray)
                {
                    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;
            }

            INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference;

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

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


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

                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());
        }
예제 #24
0
 internal MethodInfo GetArrayCreateWithLowerBoundsMethod(IArrayTypeReference arrayTypeReference, ModuleBuilder moduleBuilder) {
   var type = this.GetType(arrayTypeReference);
   var parameterTypes = new Type[arrayTypeReference.Rank*2];
   for (int i = 0; i < arrayTypeReference.Rank*2; i++) parameterTypes[i] = typeof(int);
   return moduleBuilder.GetArrayMethod(type, ".ctor", CallingConventions.HasThis, typeof(void), parameterTypes);
 }
예제 #25
0
    private void EmitTypeLoadingCallsFor(IArrayTypeReference arrayType, string typeObjectName, SetOfUints alreadyLoadedTypes) {
      Contract.Requires(arrayType != null);
      Contract.Requires(typeObjectName != null);
      Contract.Requires(alreadyLoadedTypes != null);

      var elementTypeObjectName = this.GetMangledTypeName(arrayType.ElementType)+"_typeObject";
      this.EmitTypeLoadingCallsFor(arrayType.ElementType, elementTypeObjectName, alreadyLoadedTypes);
      if (arrayType.IsVector) {
        this.sourceEmitter.EmitString("GetVectorType(");
        this.sourceEmitter.EmitString(elementTypeObjectName);
      } else {
        this.sourceEmitter.EmitString("GetMatrixType(");
        this.sourceEmitter.EmitString(elementTypeObjectName);
        this.sourceEmitter.EmitString(", "+arrayType.Rank);
      }
      this.sourceEmitter.EmitString(", (uintptr_t)&");
      this.sourceEmitter.EmitString(typeObjectName);
      this.sourceEmitter.EmitString(");");
      this.sourceEmitter.EmitNewLine();
    }
예제 #26
0
 public override void Visit(IArrayTypeReference arrayTypeReference) {
   arrayTypeReference.ElementType.Dispatch(this);
   int h = this.hash;
   h = (h << 5 + h) ^ ((int)arrayTypeReference.Rank+4);
   this.hash = h;
 }
예제 #27
0
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
 {
     this.Visit(arrayTypeReference.GetElementType(Context));
 }
예제 #28
0
 /// <summary>
 /// Traverses the array type reference.
 /// </summary>
 public void Traverse(IArrayTypeReference arrayTypeReference)
 {
     Contract.Requires(arrayTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(arrayTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(arrayTypeReference); //No need to dispatch. This call is already type specific.
       if (this.stopTraversal) return;
       this.TraverseChildren(arrayTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(arrayTypeReference);
 }
예제 #29
0
        private static void InitializeArraySetInstruction(Instruction instruction, Stack <Instruction> stack, IArrayTypeReference arrayType)
        {
            Contract.Requires(instruction != null);
            Contract.Requires(stack != null);
            Contract.Requires(arrayType != null);
            var rank    = arrayType.Rank;
            var indices = new Instruction[rank + 1];

            instruction.Operand2 = indices;
            for (var i = rank + 1; i > 0; i--)
            {
                indices[i - 1] = stack.Pop();
            }
            instruction.Operand1 = stack.Pop();
        }
예제 #30
0
파일: Visitor.cs 프로젝트: riverar/devtools
 private void StoreInitializers(ICreateArray createArray, IArrayTypeReference arrayType)
 {
     var initializers = new List<IExpression>(createArray.Initializers);
       if (initializers.Count > 0) {
     var sizes = new List<IExpression>(createArray.Sizes);
     // Used to do the "reverse" mapping from offset (linear index into
     // initializer list) to the d-dimensional coordinates, where d is
     // the rank of the array.
     ulong[] dimensionStride = new ulong[sizes.Count];
     dimensionStride[sizes.Count - 1] = 1;
     for (int i = sizes.Count - 2; 0 <= i; i--) {
       var size = ((IConvertible)((ICompileTimeConstant)sizes[i + 1]).Value).ToUInt64(null);
       dimensionStride[i] = size * dimensionStride[i + 1];
     }
     for (int i = 0; i < initializers.Count; i++) {
       this.generator.Emit(OperationCode.Dup);
       this.StackSize++;
       ulong n = (ulong)i; // compute the indices that map to the offset n
       for (uint d = 0; d < createArray.Rank; d++) {
     var divisor = dimensionStride[d];
     var indexInThisDimension = n / divisor;
     n = n % divisor;
     this.EmitConstant((int)indexInThisDimension);
       }
       this.Traverse(initializers[i]);
       this.generator.Emit(OperationCode.Array_Set, arrayType);
       this.StackSize -= (ushort)(createArray.Rank + 2);
     }
       }
 }
예제 #31
0
 public void Visit(IArrayTypeReference arrayTypeReference)
 {
     this.traverser.Traverse(arrayTypeReference);
 }
예제 #32
0
 internal MethodInfo GetArraySetMethod(IArrayTypeReference arrayTypeReference, ModuleBuilder moduleBuilder) {
   var type = this.GetType(arrayTypeReference);
   var parameterTypes = new Type[arrayTypeReference.Rank+1];
   for (int i = 0; i < arrayTypeReference.Rank; i++) parameterTypes[i] = typeof(int);
   parameterTypes[arrayTypeReference.Rank] = type.GetElementType();
   return moduleBuilder.GetArrayMethod(type, "Set", CallingConventions.HasThis, typeof(void), parameterTypes);
 }
예제 #33
0
 /// <summary>
 /// Performs some computation with the given array type reference.
 /// </summary>
 public void Visit(IArrayTypeReference arrayTypeReference)
 {
     this.Visit((ITypeReference)arrayTypeReference);
     if (arrayTypeReference.ElementType is Dummy)
       this.ReportError(MetadataError.IncompleteNode, arrayTypeReference, "ElementType");
 }
예제 #34
0
 public override void TraverseChildren(IArrayTypeReference arrayTypeReference)
 {
     MethodEnter(arrayTypeReference);
     base.TraverseChildren(arrayTypeReference);
     MethodExit();
 }
예제 #35
0
 public override void Visit(IArrayTypeReference arrayTypeReference) {
   if (arrayTypeReference.IsVector)
     this.result = this.mapper.GetType(arrayTypeReference.ElementType).MakeArrayType();
   else
     this.result = this.mapper.GetType(arrayTypeReference.ElementType).MakeArrayType((int)arrayTypeReference.Rank);
 }
예제 #36
0
        /// <summary>
        /// Use this routine, rather than ITypeReference.Dispatch, to call the appropriate derived overload of an ITypeReference.
        /// The former routine will call Visit(INamespaceTypeDefinition) rather than Visit(INamespaceTypeReference), etc.,
        /// in the case where a definition is used as a reference to itself.
        /// </summary>
        /// <param name="typeReference">A reference to a type definition. Note that a type definition can serve as a reference to itself.</param>
        protected void DispatchAsReference(ITypeReference typeReference)
        {
            INamespaceTypeReference namespaceTypeReference = typeReference.AsNamespaceTypeReference;

            if (namespaceTypeReference != null)
            {
                this.Visit(namespaceTypeReference);
                return;
            }

            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                this.Visit(genericTypeInstanceReference);
                return;
            }

            INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;

            if (nestedTypeReference != null)
            {
                this.Visit(nestedTypeReference);
                return;
            }

            IArrayTypeReference arrayTypeReference = typeReference as IArrayTypeReference;

            if (arrayTypeReference != null)
            {
                this.Visit(arrayTypeReference);
                return;
            }

            IGenericTypeParameterReference genericTypeParameterReference = typeReference.AsGenericTypeParameterReference;

            if (genericTypeParameterReference != null)
            {
                this.Visit(genericTypeParameterReference);
                return;
            }

            IGenericMethodParameterReference genericMethodParameterReference = typeReference.AsGenericMethodParameterReference;

            if (genericMethodParameterReference != null)
            {
                this.Visit(genericMethodParameterReference);
                return;
            }

            IPointerTypeReference pointerTypeReference = typeReference as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                this.Visit(pointerTypeReference);
                return;
            }

            IModifiedTypeReference modifiedTypeReference = typeReference as IModifiedTypeReference;

            if (modifiedTypeReference != null)
            {
                this.Visit(modifiedTypeReference);
                return;
            }
        }
예제 #37
0
 // Array and pointer types might cause deep recursions; visit them iteratively
 // rather than recursively.
 public override void Visit(IArrayTypeReference arrayTypeReference)
 {
     // We don't visit the current array type; it has already been visited.
     // We go straight to the element type and visit it.
     ITypeReference current = arrayTypeReference.GetElementType(Context);
     while (true)
     {
         bool mustVisitChildren = VisitTypeReference(current);
         if (!mustVisitChildren)
         {
             return;
         }
         else if (current is IArrayTypeReference)
         {
             // The element type is itself an array type, and we must visit *its* element type.
             // Iterate rather than recursing.
             current = ((IArrayTypeReference)current).GetElementType(Context);
             continue;
         }
         else
         {
             // The element type is not an array type and we must visit its children.
             // Dispatch the type in order to visit its children.
             DispatchAsReference(current);
             return;
         }
     }
 }
 /// <summary>
 /// Performs some computation with the given array type reference.
 /// </summary>
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
 {
 }
예제 #39
0
 /// <summary>
 /// Performs some computation with the given array type reference.
 /// </summary>
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
 {
 }
 /// <summary>
 /// Rewrites the array type reference.
 /// </summary>
 public virtual IArrayTypeReference Rewrite(IArrayTypeReference arrayTypeReference)
 {
     return arrayTypeReference;
 }
예제 #41
0
 /// <summary>
 /// Traverses the children of the array type reference.
 /// </summary>
 public virtual void TraverseChildren(IArrayTypeReference arrayTypeReference)
 {
     Contract.Requires(arrayTypeReference != null);
       this.TraverseChildren((ITypeReference)arrayTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(arrayTypeReference.ElementType);
 }
 public override void Visit(IArrayTypeReference arrayTypeReference)
 {
     if(Process(arrayTypeReference)){visitor.Visit(arrayTypeReference);}
     base.Visit(arrayTypeReference);
 }
예제 #43
0
 /// <summary>
 /// Performs some computation with the given array type reference.
 /// </summary>
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
 {
     this.Visit((ITypeReference)arrayTypeReference);
 }
예제 #44
0
파일: Visitor.cs 프로젝트: riverar/devtools
        /// <summary>
        /// Generates IL code for the given for each statement for the special case where the collection is known
        /// to be vector type.
        /// </summary>
        /// <param name="forEachStatement">The foreach statement to visit.</param>
        /// <param name="arrayType">The vector type of the collection.</param>
        public virtual void VisitForeachArrayElement(IForEachStatement forEachStatement, IArrayTypeReference arrayType)
        {
            Contract.Requires(arrayType.IsVector);
              ILGeneratorLabel savedCurrentBreakTarget = this.currentBreakTarget;
              ILGeneratorLabel savedCurrentContinueTarget = this.currentContinueTarget;
              this.currentBreakTarget = new ILGeneratorLabel();
              this.currentContinueTarget = new ILGeneratorLabel();
              if (this.currentTryCatch != null) {
            this.mostNestedTryCatchFor.Add(this.currentBreakTarget, this.currentTryCatch);
            this.mostNestedTryCatchFor.Add(this.currentContinueTarget, this.currentTryCatch);
              }
              ILGeneratorLabel conditionCheck = new ILGeneratorLabel();
              ILGeneratorLabel loopStart = new ILGeneratorLabel();

              this.EmitSequencePoint(forEachStatement.Variable.Locations);
              this.Traverse(forEachStatement.Collection);
              this.generator.Emit(OperationCode.Dup);
              var array = new TemporaryVariable(arrayType, this.method);
              this.VisitAssignmentTo(array);
              var length = new TemporaryVariable(this.host.PlatformType.SystemInt32, this.method);
              this.generator.Emit(OperationCode.Ldlen);
              this.generator.Emit(OperationCode.Conv_I4);
              this.VisitAssignmentTo(length);
              var counter = new TemporaryVariable(this.host.PlatformType.SystemInt32, this.method);
              this.generator.Emit(OperationCode.Ldc_I4_0);
              this.StackSize++;
              this.VisitAssignmentTo(counter);
              this.generator.Emit(OperationCode.Br, conditionCheck);
              this.generator.MarkLabel(loopStart);
              this.LoadLocal(array);
              this.LoadLocal(counter);
              this.LoadVectorElement(arrayType.ElementType);
              this.VisitAssignmentTo(forEachStatement.Variable);
              this.Traverse(forEachStatement.Body);
              this.generator.MarkLabel(this.currentContinueTarget);
              this.LoadLocal(counter);
              this.generator.Emit(OperationCode.Ldc_I4_1);
              this.StackSize++;
              this.generator.Emit(OperationCode.Add);
              this.StackSize--;
              this.VisitAssignmentTo(counter);
              this.generator.MarkLabel(conditionCheck);
              this.EmitSequencePoint(forEachStatement.Collection.Locations);
              this.LoadLocal(counter);
              this.LoadLocal(length);
              this.generator.Emit(OperationCode.Blt, loopStart);
              this.generator.MarkLabel(this.currentBreakTarget);

              this.currentBreakTarget = savedCurrentBreakTarget;
              this.currentContinueTarget = savedCurrentContinueTarget;
        }
예제 #45
0
        private void InitializeArrayIndexerInstruction(Instruction instruction, LocalsAndOperands <V> state, IArrayTypeReference arrayType)
        {
            // Copied from Cci's DataFlowInferencer.cs

            /* Contract.Requires(instruction != null);
             * Contract.Requires(stack != null);
             * Contract.Requires(arrayType != null);
             * var rank = arrayType.Rank;
             * var indices = new Instruction[rank];
             * instruction.Operand2 = indices;
             * for (var i = rank; i > 0; i--)
             * indices[i - 1] = stack.Pop();
             * instruction.Operand1 = stack.Pop();
             * stack.Push(instruction);
             */

            var rank = arrayType.Rank;

            for (var i = rank; i > 0; i--)
            {
                state.Pop();
            }

            state.Pop();

            state.Push(ValueAbstraction.Top); // need to be smarter about top
        }
예제 #46
0
 public override void VisitArrayTypeReference <TTypeReference>(IArrayTypeReference <TTypeReference> arrayTypeReference)
 {
     TypeReference = new ArrayTypeReferenceWrapper(arrayTypeReference);
 }
예제 #47
0
 public virtual void Visit(IArrayTypeReference arrayTypeReference)
 {
     this.Visit(arrayTypeReference.GetElementType(Context));
 }
예제 #48
0
 public void Visit(IArrayTypeReference arrayTypeReference)
 {
     throw new NotImplementedException();
 }
 public override void TraverseChildren(IArrayTypeReference arrayTypeReference) {
   base.TraverseChildren(arrayTypeReference);
 }
예제 #50
0
 // Each plugged translator may choose to implement some action on each metadata / AST element
 public virtual void onMetadataElement(IArrayTypeReference arrayTypeReference)
 {
 }
예제 #51
0
 // Each plugged translator may choose to implement some action on each metadata / AST element
 public virtual void onMetadataElement(IArrayTypeReference arrayTypeReference) { }
예제 #52
0
        public override void TraverseChildren(IArrayTypeReference arrayTypeReference)
{ MethodEnter(arrayTypeReference);
            base.TraverseChildren(arrayTypeReference);
     MethodExit();   }
예제 #53
0
 public override void VisitArrayTypeReference <TTypeReference>(IArrayTypeReference <TTypeReference> arrayTypeReference)
 {
     visitor.VisitArrayTypeReferenceWithReflection((ArrayTypeReferenceWithReflection)(object)arrayTypeReference);
 }
예제 #54
0
 /// <summary>
 /// Traverses the children of the array type reference.
 /// </summary>
 public virtual void TraverseChildren(IArrayTypeReference arrayTypeReference)
 {
     this.TraverseChildren((ITypeReference)arrayTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(arrayTypeReference.ElementType);
 }