protected override StringBuilder AppendArrayTypeName(StringBuilder buf, TypeReference type,
                                                             DynamicParserContext context)
        {
            buf.Append("std::Array <");

            var item = type is TypeSpecification spec ? spec.ElementType : type.GetElementType();

            _AppendTypeName(buf, item, context);
            AppendHat(buf, item);

            if (type is ArrayType arrayType)
            {
                int rank = arrayType.Rank;
                if (rank > 1)
                {
                    buf.AppendFormat(", {0}", rank);
                }
            }

            buf.Append(">");

            return(buf);
        }
        protected override StringBuilder AppendPointerTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            _AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context);
            AppendHat(buf, type);
            buf.Append(PointerModifier);
            return(buf);
        }
        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  argIndex = 0;
            int  previouslyAppliedCount = 0;
            bool insertNested           = false;

            foreach (var decl in decls)
            {
                TypeReference declDef;
                try
                {
                    declDef = decl.Resolve() ?? decl;
                }
                catch
                {
                    //Resolve() can fail as sometimes Cecil understands types as .net
                    //needs to ignore those errors
                    declDef = decl;
                }

                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;
                AppendTypeName(buf, declDef, context);
                int argumentCount      = DocUtils.GetGenericArgumentCount(declDef);
                int countLeftUnapplied = argumentCount - previouslyAppliedCount;
                previouslyAppliedCount = argumentCount;
                var lastItem = decls.Last();
                if (countLeftUnapplied > 0 &&
                    (appendGeneric
                     //this is to add generic syntax for parent classes in declaration of nested class
                     //eg, ref class MyList<T>::Helper -> needs to add <T> to MyList class
                     || decls.Count >= 2 && decl != lastItem)
                    )
                {
                    buf.Append(GenericTypeContainer[0]);
                    var origState = MemberFormatterState;
                    MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters;

                    var item = genArgs[argIndex++];
                    _AppendTypeName(buf, item, context, useTypeProjection: useTypeProjection);
                    if (declDef.GenericParameters.All(x => x.FullName != item.FullName))
                    {
                        AppendHat(buf, item, AppendHatOnReturn);
                    }

                    for (int i = 1; i < countLeftUnapplied; ++i)
                    {
                        var newItem = genArgs[argIndex++];
                        _AppendTypeName(buf.Append(", "), newItem, context);
                        if (declDef.GenericParameters.All(x => x.FullName != newItem.FullName))
                        {
                            //add hat only for non-generic types
                            AppendHat(buf, newItem);
                        }
                    }
                    MemberFormatterState = origState;
                    buf.Append(GenericTypeContainer[1]);
                }
            }
            return(buf);
        }
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            string typeFullName = type.FullName;

            if (string.IsNullOrWhiteSpace(typeFullName))
            {
                return(buf);
            }

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

            string cppType = GetCppType(typeFullName);

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

            return(base.AppendTypeName(buf, type, context));
        }
Exemple #5
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, DynamicParserContext context)
        {
            if (context != null && context.TransformFlags != null &&
                (context.TransformFlags.Count == 0 || context.TransformFlags[context.TransformIndex]))
            {
                context.TransformIndex++;
                return(buf.Append("dynamic"));
            }

            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 = GetCSharpType(t);

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

            return(base.AppendTypeName(buf, type, context));
        }
Exemple #6
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);
        }
        protected override StringBuilder AppendRefTypeName(StringBuilder buf, ByReferenceType type, DynamicParserContext context)
        {
            _AppendTypeName(buf, type.ElementType, context);
            AppendHat(buf, type);
            buf.Append(RefTypeModifier);

            return(buf);
        }
 protected override StringBuilder AppendPointerTypeName(StringBuilder buf, PointerType type, DynamicParserContext context)
 {
     _AppendTypeName(buf, type.ElementType, context);
     AppendHat(buf, type);
     buf.Append(PointerModifier);
     return(buf);
 }
        protected override StringBuilder AppendRequiredModifierType(StringBuilder buf, RequiredModifierType type, DynamicParserContext context)
        {
            // handled in AppendHat
            if (type.ModifierType.FullName == "System.Runtime.CompilerServices.IsByValue")
            {
                return(_AppendTypeName(buf, type.ElementType, context));
            }

            _AppendTypeName(buf, type.ElementType, context);
            buf.Append(" modreq(");
            _AppendTypeName(buf, type.ModifierType, context);
            buf.Append(')');

            return(buf);
        }
        protected override StringBuilder AppendArrayTypeName(StringBuilder buf, ArrayType type, DynamicParserContext context)
        {
            buf.Append("cli::array <");

            var item = type.ElementType;

            _AppendTypeName(buf, item, context);
            AppendHat(buf, item);

            int rank = type.Rank;

            if (rank > 1)
            {
                buf.AppendFormat(", {0}", rank);
            }

            buf.Append(">");

            return(buf);
        }
        protected override StringBuilder AppendOptionalModifierType(StringBuilder buf, OptionalModifierType type, DynamicParserContext context)
        {
            if (type.ModifierType.FullName == "System.Runtime.CompilerServices.IsLong" &&
                type.ElementType.FullName == "System.Int32")
            {
                return(buf.Append("long"));
            }
            if (type.ModifierType.FullName == "System.Runtime.CompilerServices.IsSignUnspecifiedByte" &&
                type.ElementType.FullName == "System.SByte")
            {
                return(buf.Append("char"));
            }
            if (type.ModifierType.FullName == "System.Runtime.CompilerServices.IsConst")
            {
                buf.Append("const ");
                _AppendTypeName(buf, type.ElementType, context);
                return(buf);
            }

            _AppendTypeName(buf, type.ElementType, context);
            buf.Append(" modopt(");
            _AppendTypeName(buf, type.ModifierType, context);
            buf.Append(')');

            return(buf);
        }
        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);
        }
        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));
        }