Пример #1
0
        private StringBuilder AppendType(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(type);
            bool insertNested          = false;
            int  prevParamCount        = 0;

            foreach (var decl in decls)
            {
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;
                base.AppendTypeName(buf, decl, context);
                int argCount = DocUtils.GetGenericArgumentCount(decl);
                int numArgs  = argCount - prevParamCount;
                prevParamCount = argCount;
                if (numArgs > 0)
                {
                    buf.Append('`').Append(numArgs);
                }
            }
            return(buf);
        }
Пример #2
0
 protected virtual StringBuilder AppendFullTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
 {
     if (type.DeclaringType != null)
     {
         AppendFullTypeName(buf, type.DeclaringType, context).Append(NestedTypeSeparator);
     }
     return(AppendTypeName(buf, type, context));
 }
Пример #3
0
        protected StringBuilder _AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true)
        {
            if (type is ArrayType)
            {
                return(AppendArrayTypeName(buf, type, context));
            }
            if (type is ByReferenceType)
            {
                return(AppendRefTypeName(buf, type, context));
            }
            if (type is PointerType)
            {
                return(AppendPointerTypeName(buf, type, context));
            }
            if (type is GenericParameter)
            {
                return(AppendTypeName(buf, type, context));
            }
            AppendNamespace(buf, type);
            GenericInstanceType genInst = type as GenericInstanceType;

            if (type.GenericParameters.Count == 0 &&
                (genInst == null ? true : genInst.GenericArguments.Count == 0))
            {
                return(AppendFullTypeName(buf, type, context));
            }
            return(AppendGenericType(buf, type, context, appendGeneric));
        }
Пример #4
0
        protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            ByReferenceType reftype = type as ByReferenceType;

            return(AppendTypeName(buf, reftype?.ElementType, context));
        }
Пример #5
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true, bool useTypeProjection = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIdx = 0;
            int  displayedInParentArguments = 0;
            bool insertNested = false;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;

                AppendTypeName(buf, declDef, context);

                int argumentCount            = DocUtils.GetGenericArgumentCount(declDef);
                int notYetDisplayedArguments = argumentCount - displayedInParentArguments;
                displayedInParentArguments = argumentCount;// nested TypeReferences have parents' generic arguments, but we shouldn't display them
                if (notYetDisplayedArguments > 0)
                {
                    buf.Append(GenericTypeContainer[0]);
                    var origState = MemberFormatterState;
                    MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters;
                    for (int i = 0; i < notYetDisplayedArguments; ++i)
                    {
                        if (i > 0)
                        {
                            buf.Append(", ");
                        }
                        var genArg = genArgs[argIdx++];
                        _AppendTypeName(buf, genArg, context, useTypeProjection: useTypeProjection);
                        var genericParameter = genArg as GenericParameter;
                        if (genericParameter != null)
                        {
                            AppendConstraints(buf, genericParameter);
                        }
                    }
                    MemberFormatterState = origState;
                    buf.Append(GenericTypeContainer[1]);
                }
            }
            return(buf);
        }
        protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            return(_AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context).Append(RefTypeModifier));
        }
Пример #7
0
 protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
 {
     if (type is GenericParameter)
     {
         int l = buf.Length;
         if (genDeclType != null)
         {
             IList <GenericParameter> genArgs = genDeclType.GenericParameters;
             for (int i = 0; i < genArgs.Count; ++i)
             {
                 if (genArgs[i].Name == type.Name)
                 {
                     buf.Append('`').Append(i);
                     break;
                 }
             }
         }
         if (genDeclMethod != null)
         {
             IList <GenericParameter> genArgs = null;
             if (genDeclMethod.IsGenericMethod())
             {
                 genArgs = genDeclMethod.GenericParameters;
                 for (int i = 0; i < genArgs.Count; ++i)
                 {
                     if (genArgs[i].Name == type.Name)
                     {
                         buf.Append("``").Append(i);
                         break;
                     }
                 }
             }
         }
         if (genDeclType == null && genDeclMethod == null)
         {
             // Probably from within an explicitly implemented interface member,
             // where CSC uses parameter names instead of indices (why?), e.g.
             // MyList`2.Mono#DocTest#Generic#IFoo{A}#Method``1(`0,``0) instead of
             // MyList`2.Mono#DocTest#Generic#IFoo{`0}#Method``1(`0,``0).
             buf.Append(type.Name);
         }
         if (buf.Length == l)
         {
             throw new Exception(string.Format(
                                     "Unable to translate generic parameter {0}; genDeclType={1}, genDeclMethod={2}",
                                     type.Name, genDeclType, genDeclMethod));
         }
     }
     else
     {
         base.AppendTypeName(buf, type, context);
         if (AddTypeCount)
         {
             int numArgs = type.GenericParameters.Count;
             if (type.DeclaringType != null)
             {
                 numArgs -= type.GenericParameters.Count;
             }
             if (numArgs > 0)
             {
                 buf.Append('`').Append(numArgs);
             }
         }
     }
     return(buf);
 }
Пример #8
0
 protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true)
 {
     if (!AddTypeCount)
     {
         base.AppendGenericType(buf, type, context);
     }
     else
     {
         AppendType(buf, type, context);
     }
     return(buf);
 }
Пример #9
0
        protected override StringBuilder AppendPointerTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            buf.Append("nativeptr<");
            _AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context);
            buf.Append(">");
            return(buf);
        }
 protected override StringBuilder AppendRefTypeName(
     StringBuilder buf, ByReferenceType type, DynamicParserContext context)
 {
     buf.Append("ref ");
     return(base.AppendRefTypeName(buf, type, context));
 }
Пример #11
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true, bool useTypeProjection = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            bool first = true;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (!first)
                {
                    buf.Append(NestedTypeSeparator);
                }
                first = false;
                AppendTypeName(buf, declDef, context);
            }
            buf.Append('<');
            first = true;
            foreach (TypeReference arg in GetGenericArguments(type))
            {
                if (!first)
                {
                    buf.Append(", ");
                }
                first = false;
                _AppendTypeName(buf, arg, context);
            }
            buf.Append('>');
            return(buf);
        }
Пример #12
0
        protected override StringBuilder AppendOptionalModifierType(StringBuilder buf, OptionalModifierType type, DynamicParserContext context)
        {
            _AppendTypeName(buf, type.ElementType, context);
            buf.Append(" modopt(");
            _AppendTypeName(buf, type.ModifierType, context);
            buf.Append(')');

            return(buf);
        }
Пример #13
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            if (type is GenericParameter)
            {
                AppendGenericParameterConstraints(buf, (GenericParameter)type).Append(type.Name);
                return(buf);
            }

            string s = GetBuiltinType(type.FullName);

            if (s != null)
            {
                return(buf.Append(s));
            }
            return(base.AppendTypeName(buf, type, context));
        }
 protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
 {
     return(base.AppendRefTypeName(buf, type, context).Append(RefTypeModifier));
 }
Пример #15
0
        protected StringBuilder _AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true)
        {
            if (type == null)
            {
                return(buf);
            }

            if (type is ArrayType)
            {
                return(AppendArrayTypeName(buf, type, context));
            }
            if (type is ByReferenceType)
            {
                return(AppendRefTypeName(buf, type, context));
            }
            if (type is PointerType)
            {
                return(AppendPointerTypeName(buf, type, context));
            }
            if (type is GenericParameter)
            {
                return(AppendTypeName(buf, type, context));
            }
            AppendNamespace(buf, type);
            GenericInstanceType genInst = type as GenericInstanceType;

            if (type.IsRequiredModifier)
            {
                try
                {
                    var rtype = type.Resolve();
                    if (rtype != null)
                    {
                        type = rtype;
                    }
                }
                catch (Exception)
                {
                    // Suppress resolving error for UWP libraries.
                    // It seems, they never have `type.IsRequiredModifier == true`, but just in case.
                }
            }


            if (type.GenericParameters.Count == 0 &&
                (genInst == null ? true : genInst.GenericArguments.Count == 0))
            {
                return(AppendFullTypeName(buf, type, context));
            }
            return(AppendGenericType(buf, type, context, appendGeneric));
        }
Пример #16
0
 protected virtual StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
 {
     if (context != null)
     {
         context.TransformIndex++;
     }
     return(AppendTypeName(buf, type.Name));
 }
Пример #17
0
        protected virtual StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIdx       = 0;
            int  prev         = 0;
            bool insertNested = false;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;
                AppendTypeName(buf, declDef, context);
                int ac = DocUtils.GetGenericArgumentCount(declDef);
                int c  = ac - prev;
                prev = ac;
                if (appendGeneric && c > 0)
                {
                    buf.Append(GenericTypeContainer[0]);
                    var origState = MemberFormatterState;
                    MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters;
                    _AppendTypeName(buf, genArgs[argIdx++], context);
                    for (int i = 1; i < c; ++i)
                    {
                        _AppendTypeName(buf.Append(","), genArgs[argIdx++], context);
                    }
                    MemberFormatterState = origState;
                    buf.Append(GenericTypeContainer[1]);
                }
            }
            return(buf);
        }
Пример #18
0
 protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
 {
     return(buf);
 }
Пример #19
0
 protected override StringBuilder AppendPointerTypeName(StringBuilder buf, PointerType type, DynamicParserContext context)
 {
     buf.Append("nativeptr<");
     _AppendTypeName(buf, type.ElementType, context);
     buf.Append(">");
     return(buf);
 }
Пример #20
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            if (type == null)
            {
                return(buf);
            }

            string fSharpType = GetFSharpType(type);

            if (fSharpType != null)
            {
                return(buf.Append(fSharpType));
            }

            if (type.IsGenericParameter)
            {
                return(buf.Append(GetGenericName(type.Name)));
            }

            return(base.AppendTypeName(buf, type, context));
        }
Пример #21
0
 protected override StringBuilder AppendRefTypeName(StringBuilder buf, ByReferenceType type, DynamicParserContext context)
 {
     return(_AppendTypeName(buf, type.ElementType, context).Append(RefTypeModifier));
 }
Пример #22
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, DynamicParserContext context, bool appendGeneric = true, bool useTypeProjection = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIdx = 0;
            int  displayedInParentArguments = 0;
            bool insertNested = false;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;

                bool isTuple = IsTuple(type)
                               // If this is a declaration of `Tuple` type
                               // treat it as an ordinary type
                               && !(type is TypeDefinition);
                bool isFSharpFunction = IsFSharpFunction(type);
                if (!isTuple && !isFSharpFunction)
                {
                    AppendTypeName(buf, declDef, context);
                }

                int argumentCount            = DocUtils.GetGenericArgumentCount(declDef);
                int notYetDisplayedArguments = argumentCount - displayedInParentArguments;
                displayedInParentArguments = argumentCount;// nested TypeReferences have parents' generic arguments, but we shouldn't display them
                if (notYetDisplayedArguments > 0)
                {
                    if (!isTuple && !isFSharpFunction)
                    {
                        buf.Append(GenericTypeContainer[0]);
                    }
                    if (isFSharpFunction && genericParameterState == GenericParameterState.WithinTuple)
                    {
                        buf.Append("(");
                    }
                    var origState = MemberFormatterState;
                    var genericParameterStateOrigState = genericParameterState;
                    MemberFormatterState  = MemberFormatterState.WithinGenericTypeParameters;
                    genericParameterState = isTuple ? GenericParameterState.WithinTuple : GenericParameterState.None;

                    for (int i = 0; i < notYetDisplayedArguments; ++i)
                    {
                        if (i > 0)
                        {
                            buf.Append(isTuple ? " * " : isFSharpFunction ? " -> " : ", ");
                        }
                        var genArg           = genArgs[argIdx++];
                        var genericParameter = genArg as GenericParameter;
                        if (genericParameter != null && IsFlexibleType(genericParameter))
                        {
                            buf.Append("#");// replace genericParameter which is a flexible type with its constraint type
#if NEW_CECIL
                            _AppendTypeName(buf, genericParameter.Constraints[0].ConstraintType, context, useTypeProjection: useTypeProjection);
#else
                            _AppendTypeName(buf, genericParameter.Constraints[0], context, useTypeProjection: useTypeProjection);
#endif
                        }
                        else
                        {
                            _AppendTypeName(buf, genArg, context);
                        }
                    }
                    MemberFormatterState  = origState;
                    genericParameterState = genericParameterStateOrigState;

                    if (MemberFormatterState == MemberFormatterState.None)
                    {
                        AppendConstraints(buf,
                                          genArgs.GetRange(0, notYetDisplayedArguments)
                                          .SafeCast <GenericParameter>()
                                          .ToList());
                    }
                    if (!isTuple && !isFSharpFunction)
                    {
                        buf.Append(GenericTypeContainer[1]);
                    }
                    if (isFSharpFunction && genericParameterState == GenericParameterState.WithinTuple)
                    {
                        buf.Append(")");
                    }
                }
            }
            return(buf);
        }
Пример #23
0
        private StringBuilder AppendGenericParameterConstraints(StringBuilder buf, GenericParameter type, DynamicParserContext context)
        {
            if (MemberFormatterState != MemberFormatterState.WithinGenericTypeParameters)
            {
                return(buf);
            }
            GenericParameterAttributes attrs = type.Attributes;
            bool isout = (attrs & GenericParameterAttributes.Covariant) != 0;
            bool isin  = (attrs & GenericParameterAttributes.Contravariant) != 0;

            if (isin)
            {
                buf.Append("In ");
            }
            else if (isout)
            {
                buf.Append("Out ");
            }
            return(buf);
        }
Пример #24
0
        protected virtual StringBuilder AppendArrayTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            _AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context);
            return(AppendArrayModifiers(buf, (ArrayType)type));
        }
Пример #25
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            if (type is GenericParameter)
            {
                return(AppendGenericParameterConstraints(buf, (GenericParameter)type, context).Append(type.Name));
            }
            string t = type.FullName;

            if (!t.StartsWith("System."))
            {
                return(base.AppendTypeName(buf, type, context));
            }

            string s = GetVBType(t);

            if (s != null)
            {
                if (context != null)
                {
                    context.TransformIndex++;
                }
                return(buf.Append(s));
            }

            return(base.AppendTypeName(buf, type, context));
        }
Пример #26
0
        protected StringBuilder _AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            if (type is ArrayType)
            {
                TypeSpecification spec = type as TypeSpecification;
                _AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context);
                return(AppendArrayModifiers(buf, (ArrayType)type));
            }
            if (type is ByReferenceType)
            {
                return(AppendRefTypeName(buf, type, context));
            }
            if (type is PointerType)
            {
                return(AppendPointerTypeName(buf, type, context));
            }
            if (type is GenericParameter)
            {
                return(AppendTypeName(buf, type, context));
            }
            AppendNamespace(buf, type);
            GenericInstanceType genInst = type as GenericInstanceType;

            if (type.GenericParameters.Count == 0 &&
                (genInst == null ? true : genInst.GenericArguments.Count == 0))
            {
                return(AppendFullTypeName(buf, type, context));
            }
            return(AppendGenericType(buf, type, context));
        }