Ejemplo n.º 1
0
 /// <summary>
 /// Enqueues initializers of a class fields and constants.
 /// </summary>
 void EnqueueFieldsInitializer(SourceTypeSymbol type)
 {
     type.GetDeclaredMembers().OfType <SourceFieldSymbol>().Foreach(f =>
     {
         if (f.Initializer != null)
         {
             EnqueueExpression(
                 f.Initializer,
                 TypeRefFactory.CreateTypeRefContext(type), //the context will be lost, analysis resolves constant values only and types are temporary
                 NameUtils.GetNamingContext(type.Syntax));
         }
     });
 }
Ejemplo n.º 2
0
        public static ITypeRef CreateTypeRef(AST.TypeRef tref)
        {
            if (tref is AST.PrimitiveTypeRef)
            {
                switch (((AST.PrimitiveTypeRef)tref).PrimitiveTypeName)
                {
                case AST.PrimitiveTypeRef.PrimitiveType.@int: return(TypeRefFactory.LongTypeRef);

                case AST.PrimitiveTypeRef.PrimitiveType.@float: return(TypeRefFactory.DoubleTypeRef);

                case AST.PrimitiveTypeRef.PrimitiveType.@string: return(TypeRefFactory.StringTypeRef);

                case AST.PrimitiveTypeRef.PrimitiveType.@bool: return(TypeRefFactory.BoolTypeRef);

                //case AST.PrimitiveTypeRef.PrimitiveType.array: return TypeRefFactory.ArrayTypeRef;
                //case AST.PrimitiveTypeRef.PrimitiveType.callable: return TypeRefFactory.CallableTypeRef;
                //case AST.PrimitiveTypeRef.PrimitiveType.@void: return 0;
                //case AST.PrimitiveTypeRef.PrimitiveType.iterable: return GetArrayTypeMask() | GetTypeMask(NameUtils.SpecialNames.Traversable, true);   // array | Traversable
                case AST.PrimitiveTypeRef.PrimitiveType.@object: return(TypeRefFactory.CreateTypeRef(NameUtils.SpecialNames.System_Object));
                }
            }
            else if (tref is AST.INamedTypeRef named)
            {
                return(TypeRefFactory.CreateTypeRef(named.ClassName));
            }
            //else if (tref is AST.ReservedTypeRef) return GetTypeMaskOfReservedClassName(((AST.ReservedTypeRef)tref).QualifiedName.Value.Name);
            else if (tref is AST.GenericTypeRef generic)
            {
                return(new GenericClassTypeRef(
                           generic.QualifiedName.Value, // throw if indirect
                           generic.GenericParams.Select(CreateTypeRef).ToImmutableArray()));
            }

            //
            throw new ArgumentException();
        }