Ejemplo n.º 1
0
 public override ResolveResult Resolve(CppResolver resolver)
 {
     return(resolver.ResolveSimpleName(identifier, typeArguments.Resolve(resolver.CurrentTypeResolveContext)));
 }
Ejemplo n.º 2
0
        AstType ConvertTypeHelper(ITypeDefinition typeDef, IList <IType> typeArguments)
        {
            Debug.Assert(typeArguments.Count >= typeDef.TypeParameterCount);

            string keyword = KnownTypeReference.GetCSharpNameByTypeCode(typeDef.KnownTypeCode);

            if (keyword != null)
            {
                return(new PrimitiveType(keyword));
            }

            // The number of type parameters belonging to outer classes
            int outerTypeParameterCount;

            if (typeDef.DeclaringType != null)
            {
                outerTypeParameterCount = typeDef.DeclaringType.TypeParameterCount;
            }
            else
            {
                outerTypeParameterCount = 0;
            }

            if (resolver != null)
            {
                // Look if there's an alias to the target type
                for (ResolvedUsingScope usingScope = resolver.CurrentUsingScope; usingScope != null; usingScope = usingScope.Parent)
                {
                    foreach (var pair in usingScope.UsingAliases)
                    {
                        if (pair.Value is TypeResolveResult)
                        {
                            if (TypeMatches(pair.Value.Type, typeDef, typeArguments))
                            {
                                return(new SimpleType(pair.Key));
                            }
                        }
                    }
                }

                IList <IType> localTypeArguments;
                if (typeDef.TypeParameterCount > outerTypeParameterCount)
                {
                    localTypeArguments = new IType[typeDef.TypeParameterCount - outerTypeParameterCount];
                    for (int i = 0; i < localTypeArguments.Count; i++)
                    {
                        localTypeArguments[i] = typeArguments[outerTypeParameterCount + i];
                    }
                }
                else
                {
                    localTypeArguments = EmptyList <IType> .Instance;
                }
                TypeResolveResult trr = resolver.ResolveSimpleName(typeDef.Name, localTypeArguments) as TypeResolveResult;
                if (trr != null && !trr.IsError && TypeMatches(trr.Type, typeDef, typeArguments))
                {
                    // We can use the short type name
                    SimpleType shortResult = new SimpleType(typeDef.Name);
                    AddTypeArguments(shortResult, typeArguments, outerTypeParameterCount, typeDef.TypeParameterCount);
                    return(shortResult);
                }
            }

            if (AlwaysUseShortTypeNames)
            {
                var shortResult = new SimpleType(typeDef.Name);
                AddTypeArguments(shortResult, typeArguments, outerTypeParameterCount, typeDef.TypeParameterCount);
                return(shortResult);
            }
            MemberType result = new MemberType();

            if (typeDef.DeclaringTypeDefinition != null)
            {
                // Handle nested types
                result.Target = ConvertTypeHelper(typeDef.DeclaringTypeDefinition, typeArguments);
            }
            else
            {
                // Handle top-level types
                if (string.IsNullOrEmpty(typeDef.Namespace))
                {
                    result.Target        = new SimpleType("global");
                    result.IsDoubleColon = true;
                }
                else
                {
                    result.Target = ConvertNamespace(typeDef.Namespace);
                }
            }
            result.MemberName = typeDef.Name;
            AddTypeArguments(result, typeArguments, outerTypeParameterCount, typeDef.TypeParameterCount);
            return(result);
        }