Example #1
0
 private IParameterInformation CreateThisParameterInformation(ITypeInformation thisType) =>
 new ParameterInformation(
     this,
     0,
     "this__",
     thisType.IsValueType ? thisType.MakeByReference() : thisType,
     emptyCustomAttribute);
Example #2
0
        private IResourceManager GetResourceManagerFromType(ITypeInformation typeInformation)
        {
            var type = typeInformation.AsRuntimeType();

            if (type == null)
            {
                return(NullResourceManager.Instance);
            }

            var classContext = MixinConfiguration.ActiveConfiguration.GetContext(type);

            if (classContext == null)
            {
                return(NullResourceManager.Instance);
            }

            var resourceMangers = new List <IResourceManager>();

            CollectResourceManagersRecursively(classContext.Type, resourceMangers);

            if (resourceMangers.Any())
            {
                return(new ResourceManagerSet(resourceMangers));
            }

            return(NullResourceManager.Instance);
        }
Example #3
0
        public void AsRuntimeType_WithTypeAdapter_ReturnsRuntimeType()
        {
            var expectedType = typeof(TheType);
            ITypeInformation typeInformation = TypeAdapter.Create(expectedType);

            Assert.That(typeInformation.AsRuntimeType(), Is.SameAs(expectedType));
        }
Example #4
0
 public RightExpressionGivenParameter(
     ITypeInformation targetType, IVariableInformation symbolinformation, string expression = null)
 {
     this.TargetType        = targetType;
     this.SymbolInformation = symbolinformation;
     this.Expression        = expression;
 }
 private void CheckMethodInformation(
     Type expectedType, ITypeInformation expectedPropertyDeclaringType, string expectedPropertyName, IMethodInformation actualMethodInformation)
 {
     Assert.That(actualMethodInformation, Is.TypeOf(expectedType));
     Assert.That(actualMethodInformation.DeclaringType, Is.SameAs(expectedPropertyDeclaringType));
     Assert.That(actualMethodInformation.Name, Is.EqualTo(expectedPropertyName));
 }
Example #6
0
        /// <summary>
        /// Gets the localized display name of a type.
        /// </summary>
        /// <param name="typeInformation">The <see cref="ITypeInformation"/> for which to lookup the resource.</param>
        /// <param name="typeInformationForResourceResolution">The <see cref="ITypeInformation"/> providing the resources.</param>
        /// <returns>The localized display name.</returns>
        public string GetTypeDisplayName(ITypeInformation typeInformation, ITypeInformation typeInformationForResourceResolution)
        {
            ArgumentUtility.CheckNotNull("typeInformation", typeInformation);
            ArgumentUtility.CheckNotNull("typeInformationForResourceResolution", typeInformationForResourceResolution);

            return(_memberInformationGlobalizationService.GetTypeDisplayName(typeInformation, typeInformationForResourceResolution));
        }
Example #7
0
        public override Func <IExtractContext, string[]> Apply(
            ITypeInformation type, DecodeContext decodeContext)
        {
            decodeContext.SetPrefixCode();

            return(emptyFunc);
        }
Example #8
0
        private static string GetCLangaugeSafeConversionExpression(
            ITypeInformation argumentType, Type constantType, string constantExpression)
        {
            if (constantType != null)
            {
                if (Utilities.GetCLanguageTypeName(constantType) == argumentType.CLanguageTypeName)
                {
                    return(constantExpression);
                }
                else if (constantType == typeof(string))
                {
                    return(string.Format("({0})il2c_new_string({1})",
                                         argumentType.CLanguageTypeName,
                                         constantExpression));
                }
                else if (argumentType.IsObjectType && constantType.IsValueType)
                {
                    return(string.Format("(System_Object*)il2c_box(&{0}, {1})",
                                         constantExpression,
                                         Utilities.GetMangledName(constantType.FullName)));
                }
            }

            return(string.Format("({0}){1}", argumentType.CLanguageTypeName, constantExpression));
        }
Example #9
0
        public override ExpressionEmitter Prepare(
            ITypeInformation type, DecodeContext decodeContext)
        {
            decodeContext.SetPrefixCode();

            return(emptyEmitter);
        }
Example #10
0
        private static Func <IExtractContext, string[]> Apply(
            ILocalVariableInformation target,
            ITypeInformation targetType,
            DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            var codeInformation = decodeContext.CurrentCode;

            return(extractContext =>
            {
                var rightExpression = extractContext.GetRightExpression(targetType, si);
                if (rightExpression == null)
                {
                    throw new InvalidProgramSequenceException(
                        "Invalid store operation: Location={0}, StackType={1}, LocalType={2}, SymbolName={3}",
                        codeInformation.RawLocation,
                        si.TargetType.FriendlyName,
                        targetType.FriendlyName,
                        target);
                }

                return new[] { string.Format(
                                   "{0} = {1}",
                                   extractContext.GetSymbolName(target),
                                   rightExpression) };
            });
        }
Example #11
0
        public override ExpressionEmitter Prepare(
            ITypeInformation type, DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            if (si.TargetType.IsByReference == false)
            {
                throw new InvalidProgramSequenceException(
                          "Invalid type at stack: Location={0}, TokenType={1}, StackType={2}",
                          decodeContext.CurrentCode.RawLocation,
                          type.FriendlyName,
                          si.TargetType.FriendlyName);
            }

            // Register target type (at the file scope).
            decodeContext.PrepareContext.RegisterType(type, decodeContext.Method);

            return((extractContext, _) =>
            {
                // IL2C can't understand the native type size.
                // So, the expression will make calculation at the C compiler.
                var memsetExpression =
                    (si.TargetType.ElementType.NativeType != null) ?
                    "memset({0}, 0x00, sizeof *{0})" :
                    "memset({0}, 0x00, {1})";

                return new[] { string.Format(
                                   memsetExpression,
                                   extractContext.GetSymbolName(si),
                                   si.TargetType.ElementType.CLanguageStaticSizeOfExpression) };
            });
        }
Example #12
0
        public void SetUp()
        {
            _globalizationServiceMock = MockRepository.GenerateStub <IGlobalizationService>();
            _resourceManagerMock      = MockRepository.GenerateStrictMock <IResourceManager>();
            _resourceManagerMock.Stub(stub => stub.IsNull).Return(false);
            _resourceManagerMock.Stub(stub => stub.Name).Return("RM1");

            _typeInformationStub = MockRepository.GenerateStub <ITypeInformation>();
            _typeInformationStub.Stub(stub => stub.Name).Return("TypeName");

            _typeInformationForResourceResolutionStub = MockRepository.GenerateStub <ITypeInformation>();
            _typeInformationForResourceResolutionStub.Stub(stub => stub.Name).Return("TypeNameForResourceResolution");

            _propertyInformationStub = MockRepository.GenerateStub <IPropertyInformation>();
            _propertyInformationStub.Stub(stub => stub.Name).Return("PropertyName");

            _memberInformationNameResolverStub = MockRepository.GenerateStub <IMemberInformationNameResolver>();
            _memberInformationNameResolverStub.Stub(stub => stub.GetPropertyName(_propertyInformationStub)).Return("FakePropertyFullName");
            _memberInformationNameResolverStub.Stub(stub => stub.GetTypeName(_typeInformationStub)).Return("FakeTypeFullName");

            _shortPropertyResourceID = "property:PropertyName";
            _longPropertyResourceID  = "property:FakePropertyFullName";
            _shortTypeResourceID     = "type:TypeName";
            _longTypeResourceID      = "type:FakeTypeFullName";

            _service = new ResourceManagerBasedMemberInformationGlobalizationService(_globalizationServiceMock, _memberInformationNameResolverStub);
        }
        private static string BuildMessage(
            ITypeInformation type,
            IPropertyInformation property,
            string relationID,
            string messageFormat,
            params object[] args)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat(messageFormat, args);
            if (type != null)
            {
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.AppendFormat("Declaring type: {0}", type);
                if (property != null)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("Property: {0}", property.Name);
                }
                if (relationID != null)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("Relation ID: {0}", relationID);
                }
            }

            return(stringBuilder.ToString());
        }
Example #14
0
            public ILocalVariableInformation GetOrAdd(ITypeInformation targetType, IMethodInformation method, object hintInformation)
            {
                var index = typedStackInformation.
                            FindIndex(si => si.TargetType == targetType);

                if (index >= 0)
                {
                    selectedStackInformation = index;
                    return(typedStackInformation[index]);
                }

                var symbolName = string.Format(
                    "stack{0}_{1}__",
                    stackPointer,
                    typedStackInformation.Count);

                selectedStackInformation = typedStackInformation.Count;
                var stackInformation = new LocalVariableInformation(
                    method,
                    stackPointer,
                    symbolName,
                    targetType,
                    hintInformation);

                typedStackInformation.Add(stackInformation);

                return(stackInformation);
            }
Example #15
0
        public override Func <IExtractContext, string[]> Apply(
            ITypeInformation operand, DecodeContext decodeContext)
        {
            var si = decodeContext.PopStack();

            if (si.TargetType.IsValueType || si.TargetType.IsByReference || si.TargetType.IsPointer)
            {
                throw new InvalidProgramSequenceException(
                          "Invalid type at stack: Location={0}, TokenType={1}, StackType={2}",
                          decodeContext.CurrentCode.RawLocation,
                          operand.FriendlyName,
                          si.TargetType.FriendlyName);
            }

            var symbol = decodeContext.PushStack(operand);

            return(extractContext =>
            {
                return new[] { string.Format(
                                   "{0} = *il2c_unbox({1}, {2})",
                                   extractContext.GetSymbolName(symbol),
                                   extractContext.GetSymbolName(si),
                                   operand.MangledUniqueName) };
            });
        }
Example #16
0
 public static Func <IExtractContext, string[]> Apply(
     Func <ITypeInformation, bool> validateElementType,
     ITypeInformation elementType,
     DecodeContext decodeContext)
 {
     return(Apply(validateElementType, _ => elementType, decodeContext));
 }
Example #17
0
        public bool TryGetTypeDisplayName(ITypeInformation typeInformation, ITypeInformation typeInformationForResourceResolution, out string result)
        {
            ArgumentUtility.CheckNotNull("typeInformation", typeInformation);
            ArgumentUtility.CheckNotNull("typeInformationForResourceResolution", typeInformationForResourceResolution);

            return(_localizedNameForTypeInformationProvider.TryGetLocalizedNameForCurrentUICulture(typeInformation, out result));
        }
        private string GetStringOrDefault(ITypeInformation typeInformation, string shortMemberName, string longMemberName, string resourcePrefix)
        {
            var resourceManager = _globalizationService.GetResourceManager(typeInformation);

            return(resourceManager.GetStringOrDefault(resourcePrefix + longMemberName)
                   ?? resourceManager.GetStringOrDefault(resourcePrefix + shortMemberName));
        }
Example #19
0
 public Constant(string symbolName, ITypeInformation targetType, Type expressionType, string expression)
 {
     this.SymbolName     = symbolName;
     this.TargetType     = targetType;
     this.ExpressionType = expressionType;
     this.Expression     = expression;
 }
Example #20
0
        public static ExpressionEmitter Prepare(
            ITypeInformation operand, DecodeContext decodeContext, bool check)
        {
            var si = decodeContext.PopStack();

            if (si.TargetType.IsValueType || si.TargetType.IsByReference || si.TargetType.IsPointer)
            {
                throw new InvalidProgramSequenceException(
                          "Invalid {0} operation: Location={1}, StackType={2}",
                          check ? "castclass" : "isinst",
                          decodeContext.CurrentCode.RawLocation,
                          si.TargetType.FriendlyName);
            }

            // It's maybe boxed objref if operand is value type.
            var resultType = operand.IsValueType ?
                             decodeContext.PrepareContext.MetadataContext.ValueTypeType :
                             operand;
            var symbol = decodeContext.PushStack(resultType);

            // If this type can cast statically:
            if (operand.IsAssignableFrom(si.TargetType))
            {
                // To interface type
                if (operand.IsInterface)
                {
                    return((extractContext, _) =>
                    {
                        return new[] { string.Format(
                                           "{0} = il2c_cast_to_interface({1}, {2}, {3})",
                                           extractContext.GetSymbolName(symbol),
                                           operand.MangledUniqueName,
                                           si.TargetType.MangledUniqueName,
                                           extractContext.GetSymbolName(si)) };
                    });
                }
                else
                {
                    return((extractContext, _) =>
                    {
                        return new[] { string.Format(
                                           "{0} = ({1}){2}",
                                           extractContext.GetSymbolName(symbol),
                                           operand.CLanguageTypeName,
                                           extractContext.GetSymbolName(si)) };
                    });
                }
            }

            return((extractContext, _) =>
            {
                return new[] { string.Format(
                                   "{0} = {1}({2}, {3})",
                                   extractContext.GetSymbolName(symbol),
                                   check ? "il2c_castclass" : "il2c_isinst",
                                   extractContext.GetSymbolName(si),
                                   operand.MangledUniqueName) };
            });
        }
Example #21
0
 public static ExpressionEmitter Prepare(
     Func <ITypeInformation, bool> validateElementType,
     ITypeInformation elementType,
     bool isByReference,
     DecodeContext decodeContext)
 {
     return(Prepare(validateElementType, _ => elementType, isByReference, decodeContext));
 }
Example #22
0
 public bool IsAssignableFrom(ITypeInformation rhs)
 {
     // untyped type <-- Class
     // untyped type <-- Interface
     // untyped type <-- ByReference (special case: this direction is valid, but reverse direction is invalid)
     // untyped type <-- Pointer
     return(rhs.IsClass || rhs.IsInterface || rhs.IsByReference || rhs.IsPointer);
 }
Example #23
0
 public static void WriteTypePreDefinitions(
     CodeTextWriter twHeader,
     ITypeInformation targetType,
     IReadOnlyDictionary <ITypeInformation, ITypeInformation[]> typesByDeclaring)
 {
     InternalWriteTypePreDefinitions(twHeader, targetType, typesByDeclaring);
     InternalWriteVTableTypePreDefinitions(twHeader, targetType, typesByDeclaring);
 }
Example #24
0
 public override Func <IExtractContext, string[]> Apply(ITypeInformation operand, DecodeContext decodeContext)
 {
     return(LdelemConverterUtilities.Apply(
                elementType => operand.IsAssignableFrom(elementType),
                operand.MakeByReference(),
                true,
                decodeContext));
 }
Example #25
0
 private static int InternalGetStaticSizeOfValue(ITypeInformation type) =>
 // Recently, the bool type is usually defined by 1byte space type.
 (type.IsByteType || type.IsSByteType || type.IsBooleanType) ? 1 :
 (type.IsInt16Type || type.IsUInt16Type || type.IsCharType) ? 2 :
 (type.IsInt32Type || type.IsUInt32Type || type.IsSingleType) ? 4 :
 (type.IsInt64Type || type.IsUInt64Type || type.IsDoubleType || type.IsIntPtrType || type.IsUIntPtrType) ? 8 :
 type.IsEnum ? InternalGetStaticSizeOfValue(type.ElementType) : // Enum size is element (underlying) type size.
 0;                                                             // TODO: throw
        public static MappingValidationResult CreateInvalidResultForType(ITypeInformation type, string messageFormat, params object[] args)
        {
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNullOrEmpty("messageFormat", messageFormat);
            ArgumentUtility.CheckNotNull("args", args);

            return(new MappingValidationResult(false, BuildMessage(type, null, null, messageFormat, args)));
        }
Example #27
0
 public int CalculateInterfaceIndex(ITypeInformation interfaceType) =>
 ((ITypeInformation)this).
 Traverse(type => type.BaseType).
 SelectMany(type => type.InterfaceTypes).
 Distinct().         // Important operator sequence: distinct --> reverse
 Reverse().          // Because all interface types overrided by derived class type,
 Select((t, i) => new { t, i }).
 FirstOrDefault(entry => entry.t.Equals(interfaceType))?.i ?? -1;
Example #28
0
 public static TypeDesc FromInfo(ITypeInformation nfo)
 {
     if (nfo == null)
     {
         return(new TypeDesc());
     }
     return(new TypeDesc(nfo));
 }
Example #29
0
 private static string GetCLanguagePrintArgumentExpression(ITypeInformation type, string symbolName)
 {
     return(type.IsBooleanType ?
            symbolName + " ? L\"true\" : L\"false\"" :
            type.IsStringType?
            string.Format("il2c_c_str({0})", symbolName) :
                symbolName);
 }
Example #30
0
        public IParameterInformation[] GetParameters(ITypeInformation thisType)
        {
            Debug.Assert(this.Member.HasThis);

            return(new[] { this.CreateThisParameterInformation(thisType) }.
                   Concat(this.Member.Parameters.Select(this.ToParameterInformation)).
                   ToArray());
        }
    internal DynamicInterceptorManager(
        IDynamicInterceptorCollection interceptors, 
        ITargetInvocationFactory targetInvocationFactory,
        IInvocationFactory invocationFactory,
        ITypeInformation typeInformation)
    {
        this.targetInvocationFactory = targetInvocationFactory;
        this.invocationFactory = invocationFactory;
        this.typeInformation = typeInformation;
        this.interceptors = interceptors;

        this.implementationMethodTarget = null;
    }
Example #32
0
 protected SearchController( TypeChart chart, ITypeInformation info )
 {
     _chart = chart;
     _info = info;
 }