public override void VisitSimpleType(SimpleType simpleType)
            {
                TypeResolveResult rr;

                if ((rr = simpleType.Annotation <TypeResolveResult>()) == null)
                {
                    base.VisitSimpleType(simpleType);
                    return;
                }
                // HACK : ignore type names in attributes (TypeSystemAstBuilder doesn't handle them correctly)
                if (simpleType.Parent is Syntax.Attribute)
                {
                    base.VisitSimpleType(simpleType);
                    return;
                }
                astBuilder.NameLookupMode = simpleType.GetNameLookupMode();
                if (astBuilder.NameLookupMode == NameLookupMode.Type)
                {
                    AstType outermostType = simpleType;
                    while (outermostType.Parent is AstType)
                    {
                        outermostType = (AstType)outermostType.Parent;
                    }
                    if (outermostType.Parent is TypeReferenceExpression)
                    {
                        // ILSpy uses TypeReferenceExpression in expression context even when the C# parser
                        // wouldn't know that it's a type reference.
                        // Fall back to expression-mode lookup in these cases:
                        astBuilder.NameLookupMode = NameLookupMode.Expression;
                    }
                }
                simpleType.ReplaceWith(astBuilder.ConvertType(rr.Type));
            }
Example #2
0
        /// <summary>
        ///     Translates a simple data type, e.g. "float4".
        /// </summary>
        public override StringBuilder VisitSimpleType(SimpleType simpleType)
        {
            var sysType    = simpleType.Annotation <TypeReference>().ToType();
            var mappedType = MapDataTypeIfValid(simpleType, sysType);

            return(mappedType == null
                ? new StringBuilder(simpleType.ToString())
                : new StringBuilder(mappedType));
        }
Example #3
0
            public override object VisitSimpleType(SimpleType simpleType, object data)
            {
                ITypeDefOrRef tr = simpleType.Annotation <ITypeDefOrRef>();

                if (tr != null && !IsParentOfCurrentNamespace(tr.Namespace))
                {
                    transform.importedNamespaces.Add(tr.Namespace);
                }
                return(base.VisitSimpleType(simpleType, data));                // also visit type arguments
            }
        public override object VisitSimpleType(SimpleType simpleType, object data)
        {
            TypeReference tr = simpleType.Annotation <TypeReference>();

            if (tr != null && !IsParentOfCurrentNamespace(tr.Namespace))
            {
                importedNamespaces.Add(tr.Namespace);
            }
            return(base.VisitSimpleType(simpleType, data));            // also visit type arguments
        }
            public override void VisitSimpleType(SimpleType simpleType)
            {
                var trr = simpleType.Annotation <TypeResolveResult>();

                if (trr != null && !IsParentOfCurrentNamespace(trr.Type.Namespace))
                {
                    ImportedNamespaces.Add(trr.Type.Namespace);
                }
                base.VisitSimpleType(simpleType);                 // also visit type arguments
            }
            public override object VisitSimpleType(SimpleType simpleType, object data)
            {
                // Handle type arguments first, so that the fixed-up type arguments get moved over to the MemberType,
                // if we're also creating one here.
                base.VisitSimpleType(simpleType, data);
                ITypeDefOrRef tr = simpleType.Annotation <ITypeDefOrRef>();

                // Fully qualify any ambiguous type names.
                if (tr == null)
                {
                    return(null);
                }
                var nss = GetNamespace(tr).ToString();

                if (IsAmbiguous(nss, null, GetName(tr)))
                {
                    AstType ns;
                    if (string.IsNullOrEmpty(nss))
                    {
                        ns = new SimpleType("global").WithAnnotation(TextTokenKind.Keyword);
                    }
                    else
                    {
                        string[] parts = nss.Split('.');
                        if (IsAmbiguous(string.Empty, parts[0], null))
                        {
                            // conflict between namespace and type name/member name
                            ns = new MemberType {
                                Target = new SimpleType("global").WithAnnotation(TextTokenKind.Keyword), IsDoubleColon = true, MemberNameToken = Identifier.Create(parts[0]).WithAnnotation(TextTokenKind.NamespacePart)
                            }.WithAnnotation(TextTokenKind.NamespacePart);
                        }
                        else
                        {
                            ns = new SimpleType(parts[0]).WithAnnotation(TextTokenKind.NamespacePart);
                        }
                        for (int i = 1; i < parts.Length; i++)
                        {
                            ns = new MemberType {
                                Target = ns, MemberNameToken = Identifier.Create(parts[i]).WithAnnotation(TextTokenKind.NamespacePart)
                            }.WithAnnotation(TextTokenKind.NamespacePart);
                        }
                    }
                    MemberType mt = new MemberType();
                    mt.Target          = ns;
                    mt.IsDoubleColon   = string.IsNullOrEmpty(nss);
                    mt.MemberNameToken = (Identifier)simpleType.IdentifierToken.Clone();
                    mt.CopyAnnotationsFrom(simpleType);
                    simpleType.TypeArguments.MoveTo(mt.TypeArguments);
                    simpleType.ReplaceWith(mt);
                }
                return(null);
            }
            public override object VisitSimpleType(SimpleType simpleType, object data)
            {
                ITypeDefOrRef tr = simpleType.Annotation <ITypeDefOrRef>();

                if (tr != null)
                {
                    var sb = GetNamespace(tr);
                    if (!IsParentOfCurrentNamespace(sb))
                    {
                        string ns = sb.ToString();
                        transform.importedNamespaces.Add(ns);
                        transform.importedOrDeclaredNamespaces.Add(ns);
                    }
                }
                return(base.VisitSimpleType(simpleType, data));                // also visit type arguments
            }
            public override object VisitSimpleType(SimpleType simpleType, object data)
            {
                // Handle type arguments first, so that the fixed-up type arguments get moved over to the MemberType,
                // if we're also creating one here.
                base.VisitSimpleType(simpleType, data);
                TypeReference tr = simpleType.Annotation <TypeReference>();

                // Fully qualify any ambiguous type names.
                if (tr != null && IsAmbiguous(tr.Namespace, tr.Name))
                {
                    AstType ns;
                    if (string.IsNullOrEmpty(tr.Namespace))
                    {
                        ns = new SimpleType("global");
                    }
                    else
                    {
                        string[] parts = tr.Namespace.Split('.');
                        if (IsAmbiguous(string.Empty, parts[0]))
                        {
                            // conflict between namespace and type name/member name
                            ns = new MemberType {
                                Target = new SimpleType("global"), IsDoubleColon = true, MemberName = parts[0]
                            };
                        }
                        else
                        {
                            ns = new SimpleType(parts[0]);
                        }
                        for (int i = 1; i < parts.Length; i++)
                        {
                            ns = new MemberType {
                                Target = ns, MemberName = parts[i]
                            };
                        }
                    }
                    MemberType mt = new MemberType();
                    mt.Target        = ns;
                    mt.IsDoubleColon = string.IsNullOrEmpty(tr.Namespace);
                    mt.MemberName    = simpleType.Identifier;
                    mt.CopyAnnotationsFrom(simpleType);
                    simpleType.TypeArguments.MoveTo(mt.TypeArguments);
                    simpleType.ReplaceWith(mt);
                }
                return(null);
            }
Example #9
0
        public override void VisitSimpleType(SimpleType simpleType)
        {
            base.VisitSimpleType(simpleType);

            var tr = simpleType.Annotation <TypeReference>();

            //fully qualify everything, because the decompiler is really bad at correct qualification
            if (tr != null)
            {
                simpleType.Identifier = "global::" + tr.FullName.Replace('/', '.');
                var idx = simpleType.Identifier.IndexOf('`');
                if (idx > 0)
                {
                    simpleType.Identifier = simpleType.Identifier.Substring(0, idx);
                }
            }
        }
Example #10
0
        public override AstNode VisitSimpleType(SimpleType simpleType, ICecilArgumentsResolver argumentsResolver)
        {
            Type type          = null;
            var  typeReference = simpleType.Annotation <TypeReference>();

            if (typeReference != null)
            {
                bool   hasTypes = false;
                Type[] types    = new Type[simpleType.TypeArguments.Count];

                if (typeReference.HasGenericParameters)
                {
                    simpleType.TypeArguments
                    .ForEach((a, i) => {
                        type = a.GetActualType() ?? argumentsResolver.ResolveType(a.ToString());

                        if (type != null)
                        {
                            types[i] = type;
                            hasTypes = true;
                        }
                    });

                    if (hasTypes)
                    {
                        type = typeReference.GetActualType()
                               .MakeGenericType(types);

                        simpleType.RemoveAnnotations <TypeReference>();
                        typeReference = new TypeReference(string.Empty, type.FullName, typeReference.Module, typeReference.Scope);
                        simpleType.AddAnnotation(typeReference);
                    }
                }
            }
            else
            {
                var pair = argumentsResolver.ResolvePair(simpleType.Identifier);

                type          = pair.Type;
                typeReference = pair.TypeReference;
                simpleType.AddAnnotation(typeReference);
                simpleType.Identifier = pair.Type.FullName;
            }

            return(simpleType);
        }
Example #11
0
 public override StringBuilder VisitSimpleType(SimpleType simpleType, int data)
 {
     // this cast might not work for all cases...
     ValidateType((TypeReference)simpleType.Annotation<MemberReference>());
     return new StringBuilder(simpleType.ToString());
 }
Example #12
0
 public override StringBuilder VisitSimpleType(SimpleType simpleType, int data)
 {
     // this cast might not work for all cases...
     ValidateType((TypeReference)simpleType.Annotation <MemberReference>());
     return(new StringBuilder(simpleType.ToString()));
 }
Example #13
0
		public virtual void VisitSimpleType(SimpleType simpleType)
		{
			StartNode(simpleType);
			if (simpleType.Identifier.Length == 0 && SimpleType.DummyTypeGenericParam.Equals(simpleType.Annotation<string>(), StringComparison.Ordinal)) {
				// It's the empty string. Don't call WriteIdentifier() since it will write "<<EMPTY_NAME>>"
			}
			else
				WriteIdentifier(simpleType.IdentifierToken, CSharpMetadataTextColorProvider.Instance.GetColor(simpleType.IdentifierToken.Annotation<object>() ?? simpleType.Annotation<object>()));
			WriteTypeArguments(simpleType.TypeArguments, CodeBracesRangeFlags.AngleBrackets);
			EndNode(simpleType);
		}
		public virtual void VisitSimpleType(SimpleType simpleType)
		{
			StartNode(simpleType);
			if (simpleType.Identifier.Length == 0 && SimpleType.DummyTypeGenericParam.Equals(simpleType.Annotation<string>(), StringComparison.Ordinal)) {
				// It's the empty string. Don't call WriteIdentifier() since it will write "<<EMPTY_NAME>>"
			}
			else
				WriteIdentifier(simpleType.IdentifierToken, TextTokenHelper.GetTextTokenType(simpleType.IdentifierToken.Annotation<object>() ?? simpleType.Annotation<object>()));
			WriteTypeArguments(simpleType.TypeArguments);
			EndNode(simpleType);
		}