Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateTypeInstance"/> class.
        /// </summary>
        /// <param name="templateSpecialization">The user type that is either template specialization user type or declared in one.</param>
        /// <param name="factory">The user type factory.</param>
        public TemplateTypeInstance(UserType templateSpecialization, UserTypeFactory factory)
            : base(templateSpecialization)
        {
            // Get all "parent" types
            UserType        type           = templateSpecialization;
            List <UserType> declaredInList = new List <UserType>();

            while (type != null)
            {
                declaredInList.Add(type);
                type = type.DeclaredInType;
            }

            declaredInList.Reverse();
            DeclaredInTypeHierarchy = declaredInList.ToArray();

            // Extract all template types and check if we can instantiate this instance
            CanInstantiate       = true;
            SpecializedArguments = new TypeInstance[DeclaredInTypeHierarchy.Length][];
            for (int j = 0; j < DeclaredInTypeHierarchy.Length; j++)
            {
                // Check if current type in hierarchy is template type
                SpecializedTemplateUserType templateType = DeclaredInTypeHierarchy[j] as SpecializedTemplateUserType;

                if (templateType == null)
                {
                    continue;
                }

                // Try to find specialized arguments for template type
                IReadOnlyList <Symbol> arguments            = templateType.TemplateArgumentsAsSymbols;
                TypeInstance[]         specializedArguments = new TypeInstance[arguments.Count];

                for (int i = 0; i < arguments.Count; i++)
                {
                    TypeInstance ti = factory.GetSymbolTypeInstance(templateSpecialization, arguments[i]);

                    specializedArguments[i] = ti;
                    if (ti.ContainsUndefinedType())
                    {
                        CanInstantiate = false;
                    }
                }

                SpecializedArguments[j] = specializedArguments;
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PointerTypeInstance"/> class.
 /// </summary>
 /// <param name="elementType">The element type instance.</param>
 public PointerTypeInstance(TypeInstance elementType)
     : base(elementType.CodeNaming)
 {
     ElementType = elementType;
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArrayTypeInstance"/> class.
 /// </summary>
 /// <param name="elementType">The element type instance.</param>
 public ArrayTypeInstance(TypeInstance elementType)
     : base(elementType.CodeNaming)
 {
     ElementType = elementType;
 }