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

                if ((rr = simpleType.Annotation <TypeResolveResult>()) == null)
                {
                    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;
                    }
                }
                if (simpleType.Parent is Syntax.Attribute)
                {
                    simpleType.ReplaceWith(astBuilder.ConvertAttributeType(rr.Type));
                }
                else
                {
                    simpleType.ReplaceWith(astBuilder.ConvertType(rr.Type));
                }
            }
示例#2
0
 // steamworks got a refactor, so DispatchDelegate<T> is now Callback<T>.DispatchDelegate
 // APIDispatchDelegate<T> is now CallResult<T>.APIDispatchDelegate
 public override void VisitSimpleType(SimpleType simpleType)
 {
     base.VisitSimpleType(simpleType);
     // the types have to be mapped to DispatchDelegate and APIDispatchDelegate or it won't compile anyways
     // just don't map anything to those
     if (simpleType.TypeArguments.Count() == 1)
     {
         // the types have to be mapped to DispatchDelegate and APIDispatchDelegate or it won't compile anyways
         // just don't map anything to those
         if (simpleType.Identifier.Equals("DispatchDelegate"))
         {
             simpleType.ReplaceWith(new MemberType(new SimpleType("Callback", simpleType.TypeArguments.First().Clone()), "DispatchDelegate"));
         }
         else if (simpleType.Identifier.Equals("APIDispatchDelegate"))
         {
             simpleType.ReplaceWith(new MemberType(new SimpleType("CallResult", simpleType.TypeArguments.First().Clone()), "APIDispatchDelegate"));
         }
     }
 }
            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)
            {
                // 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);
            }
示例#5
0
文件: CsToTs.cs 项目: RReverser/Netjs
			public override void VisitSimpleType (SimpleType simpleType)
			{
				base.VisitSimpleType (simpleType);

				var td = GetTypeDef (simpleType);

				if (td == null || !IsDelegate (td)) {
					return;
				}

				var subs = new Dictionary<string, AstType> ();

				var invoke = td.Methods.First (x => x.Name == "Invoke");

				if (simpleType.TypeArguments.Count > 0) {

					var ps = td.GenericParameters;
					var i = 0;
					foreach (var a in simpleType.TypeArguments) {

						subs [ps [i].Name] = a;

						i++;
					}
				}

				var nt = new FunctionType ();

				foreach (var p in invoke.Parameters) {

					var pt = p.ParameterType.IsGenericParameter ? subs [p.ParameterType.Name] : GetTsType (p.ParameterType);

					nt.Parameters.Add (new ParameterDeclaration (pt.Clone (), p.Name));
				}

				nt.ReturnType = invoke.ReturnType.IsGenericParameter ? subs [invoke.ReturnType.Name] : GetTsType (invoke.ReturnType);

				if (nt.ReturnType is PrimitiveType) {
					nt.ReturnType = MakePrimitiveTypesJsTypes.GetPrimitiveTypeReplacement ((PrimitiveType)nt.ReturnType);
				}
				foreach (var p in nt.Parameters) {
					if (p.Type is PrimitiveType) {
						p.Type = MakePrimitiveTypesJsTypes.GetPrimitiveTypeReplacement ((PrimitiveType)p.Type);
					}
				}

				nt.AddAnnotation (td);

				simpleType.ReplaceWith (nt);
			}
示例#6
0
文件: CsToTs.cs 项目: RReverser/Netjs
			public override void VisitSimpleType (SimpleType simpleType)
			{
				base.VisitSimpleType (simpleType);

				if (simpleType.Identifier == "IntPtr") {
					simpleType.ReplaceWith (new PrimitiveType ("number"));
				}
			}