public static void Compile(JsCompiler compiler, JsClass klass, ObjectMethodId id) { var type = klass.Type; if (!type.IsEnum) { throw new InvalidOperationException("Type is not enum."); } switch (id) { case ObjectMethodId.Equals: //TODO: implement Equals for enums here JsStruct.Compile(compiler, klass, id); break; case ObjectMethodId.GetHashCode: CompileGetHashCode(compiler, klass); break; case ObjectMethodId.ToString: CompileToString(compiler, klass); break; default: throw new ArgumentOutOfRangeException("id"); } }
internal JsClass CompileClass(IType type) { if (type == null || type.IsExcluded()) { return(null); } var klass = type.Data as JsClass; if (klass != null) { return(klass); } if (type.IsEnum && type.ValueType.IsInt64()) { CompileClass(type.ValueType); } var baseType = type.BaseType; var baseClass = CompileClass(baseType.Is(SystemTypeCode.ValueType) || type.IsEnum ? SystemTypes.Object : baseType); var ns = string.IsNullOrEmpty(type.Namespace) ? "$global" : type.Namespace; _program.DefineNamespace(ns); klass = new JsClass(type, baseType.Is(SystemTypeCode.ValueType) || type.IsString() ? null : baseClass); type.Data = klass; if (baseClass != null) { baseClass.Subclasses.Add(klass); } foreach (var iface in type.Interfaces) { JsInterface.Make(iface).Implementations.Add(klass); } _program.Add(klass); switch (type.TypeKind) { case TypeKind.Struct: JsStruct.CompileCopy(klass); break; case TypeKind.Delegate: JsDelegate.CreateInstanceImpl(klass); break; } CompileImpls(klass, type); return(klass); }
private JsClass CompileClass(IType type) { var klass = _host.CompileClass(type); _host.CompileFields(type, false); if (type.IsNullableInstance()) { JsStruct.CompileCopy(klass); } return(klass); }
private void CompileMethod(JsClass klass, ObjectMethodId id) { switch (klass.Type.TypeKind) { case TypeKind.Struct: JsStruct.Compile(this, klass, id); break; case TypeKind.Enum: JsEnum.Compile(this, klass, id); break; } }