Ejemplo n.º 1
0
        protected virtual void EmitCastType(AstType astType)
        {
            var resolveResult = this.Emitter.Resolver.ResolveNode(astType, this.Emitter);

            if (NullableType.IsNullable(resolveResult.Type))
            {
                this.Write(BridgeTypes.ToJsName(NullableType.GetUnderlyingType(resolveResult.Type), this.Emitter));
            }
            else if (resolveResult.Type.Kind == TypeKind.Delegate)
            {
                this.Write(JS.Types.FUNCTION);
            }
            else if (resolveResult.Type.Kind == TypeKind.Array)
            {
                this.EmitArray(resolveResult.Type);
            }
            else
            {
                astType.AcceptVisitor(this.Emitter);
            }
        }
Ejemplo n.º 2
0
        static string TypeToStringInternal(IType t, bool includeNamespace, bool useBuiltinTypeNames = true, ParameterModifier parameterModifier = ParameterModifier.None)
        {
            TypeSystemAstBuilder builder = new TypeSystemAstBuilder();

            builder.AlwaysUseShortTypeNames    = !includeNamespace;
            builder.UseKeywordsForBuiltinTypes = useBuiltinTypeNames;

            const ParameterModifier refInOutModifier = ParameterModifier.Ref | ParameterModifier.Out | ParameterModifier.In;

            AstType astType = builder.ConvertType(t);

            if ((parameterModifier & refInOutModifier) != 0 && astType is ComposedType ct && ct.HasRefSpecifier)
            {
                ct.HasRefSpecifier = false;
            }

            StringWriter w = new StringWriter();

            astType.AcceptVisitor(new CSharpOutputVisitor(w, TypeToStringFormattingOptions));
            string output = w.ToString();

            switch (parameterModifier)
            {
            case ParameterModifier.Ref:
                output = "ref " + output;
                break;

            case ParameterModifier.Out:
                output = "out " + output;
                break;

            case ParameterModifier.In:
                output = "in " + output;
                break;
            }

            return(output);
        }
Ejemplo n.º 3
0
        public override string TypeToString(TypeReference type, bool includeNamespace, ICustomAttributeProvider typeAttributes)
        {
            AstType astType = AstBuilder.ConvertType(type, typeAttributes);

            if (!includeNamespace)
            {
                var tre = new TypeReferenceExpression {
                    Type = astType
                };
                tre.AcceptVisitor(new RemoveNamespaceFromType(), null);
                astType = tre.Type;
            }

            StringWriter w = new StringWriter();

            if (type.IsByReference)
            {
                ParameterDefinition pd = typeAttributes as ParameterDefinition;
                if (pd != null && (!pd.IsIn && pd.IsOut))
                {
                    w.Write("out ");
                }
                else
                {
                    w.Write("ref ");
                }

                if (astType is ComposedType && ((ComposedType)astType).PointerRank > 0)
                {
                    ((ComposedType)astType).PointerRank--;
                }
            }

            astType.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
            return(w.ToString());
        }
Ejemplo n.º 4
0
		void WritePrivateImplementationType(AstType privateImplementationType)
		{
			if (!privateImplementationType.IsNull) {
				privateImplementationType.AcceptVisitor(this);
				WriteToken(Roles.Dot);
			}
		}
Ejemplo n.º 5
0
        protected virtual void EmitCastType(AstType astType)
        {
            var resolveResult = this.Emitter.Resolver.ResolveNode(astType, this.Emitter);

            if (NullableType.IsNullable(resolveResult.Type))
            {
                this.Write(BridgeTypes.ToJsName(NullableType.GetUnderlyingType(resolveResult.Type), this.Emitter));
            }
            else if (resolveResult.Type.Kind == TypeKind.Delegate)
            {
                this.Write("Function");
            }
            else if (resolveResult.Type.Kind == TypeKind.Array)
            {
                this.Write("Array");
            }
            else
            {
                astType.AcceptVisitor(this.Emitter);
            }
        }
Ejemplo n.º 6
0
        protected virtual void EmitCastType(AstType astType)
        {
            var resolveResult = this.Emitter.Resolver.ResolveNode(astType, this.Emitter);

            if (NullableType.IsNullable(resolveResult.Type))
            {
                this.Write(BridgeTypes.ToJsName(NullableType.GetUnderlyingType(resolveResult.Type), this.Emitter));
            }
            else
            {
                astType.AcceptVisitor(this.Emitter);
            }
        }
Ejemplo n.º 7
0
		protected virtual void WritePrivateImplementationType(AstType privateImplementationType)
		{
			if (!privateImplementationType.IsNull) {
				privateImplementationType.AcceptVisitor(this);
				WriteToken(Roles.Dot, BoxedTextColor.Operator);
			}
		}
Ejemplo n.º 8
0
 JsonValue GetPrivateImplementationType(AstType privateImplementationType)
 {
     if (!privateImplementationType.IsNull)
     {
         privateImplementationType.AcceptVisitor(this);
         return Pop();
     }
     return null;
 }