internal override AST PartiallyEvaluate() { if (!(this.classob.GetParent() is GlobalScope)) { return(this); //The class has already been partially evaluated } this.baseType.PartiallyEvaluate(); IReflect ir = this.baseType.ToIReflect(); Type bt = null; if (!(ir is Type) || !Convert.IsPrimitiveIntegerType(bt = (Type)ir)) { this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum); this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null)); bt = Typeob.Int32; } if (this.customAttributes != null) { this.customAttributes.PartiallyEvaluate(); } if (this.NeedsToBeCheckedForCLSCompliance()) { if (!TypeExpression.TypeIsCLSCompliant(ir)) { this.baseType.context.HandleError(JSError.NonCLSCompliantType); } this.CheckMemberNamesForCLSCompliance(); } ScriptObject scope = this.enclosingScope; while (!(scope is GlobalScope) && !(scope is PackageScope)) { scope = scope.GetParent(); } this.classob.SetParent(new WithObject(scope, Typeob.Enum, true)); Globals.ScopeStack.Push(this.classob); try{ foreach (FieldInfo f in this.fields) { JSMemberField field = (JSMemberField)f; ((DeclaredEnumValue)field.value).CoerceToBaseType(bt, field.originalContext); } }finally{ Globals.ScopeStack.Pop(); } return(this); }
internal override AST PartiallyEvaluate() { if (base.classob.GetParent() is GlobalScope) { this.baseType.PartiallyEvaluate(); IReflect reflect = this.baseType.ToIReflect(); Type bt = null; if (!(reflect is Type) || !Microsoft.JScript.Convert.IsPrimitiveIntegerType(bt = (Type)reflect)) { this.baseType.context.HandleError(JSError.InvalidBaseTypeForEnum); this.baseType = new TypeExpression(new ConstantWrapper(Typeob.Int32, null)); bt = Typeob.Int32; } if (base.customAttributes != null) { base.customAttributes.PartiallyEvaluate(); } if (base.NeedsToBeCheckedForCLSCompliance()) { if (!TypeExpression.TypeIsCLSCompliant(reflect)) { this.baseType.context.HandleError(JSError.NonCLSCompliantType); } base.CheckMemberNamesForCLSCompliance(); } ScriptObject enclosingScope = base.enclosingScope; while (!(enclosingScope is GlobalScope) && !(enclosingScope is PackageScope)) { enclosingScope = enclosingScope.GetParent(); } base.classob.SetParent(new WithObject(enclosingScope, Typeob.Enum, true)); base.Globals.ScopeStack.Push(base.classob); try { JSMemberField[] fields = base.fields; for (int i = 0; i < fields.Length; i++) { FieldInfo info = fields[i]; JSMemberField field = (JSMemberField)info; ((DeclaredEnumValue)field.value).CoerceToBaseType(bt, field.originalContext); } } finally { base.Globals.ScopeStack.Pop(); } } return(this); }
// has to be called after partially evaluate internal bool IsCLSCompliant() { Object value = this.expression.Evaluate(); return(TypeExpression.TypeIsCLSCompliant(value)); }
internal static bool TypeIsCLSCompliant(Object type) { if (type is ClassScope) { return(((ClassScope)type).IsCLSCompliant()); } else if (type is TypedArray) { Object et = ((TypedArray)type).elementType; if (et is TypedArray || (et is Type && ((Type)et).IsArray)) { return(false); } return(TypeExpression.TypeIsCLSCompliant(et)); } else { Type t = (Type)type; if (t.IsPrimitive) { if (t == Typeob.Boolean || t == Typeob.Byte || t == Typeob.Char || t == Typeob.Double || t == Typeob.Int16 || t == Typeob.Int32 || t == Typeob.Int64 || t == Typeob.Single) { return(true); } else { return(false); } } else { if (t.IsArray) { Type et = t.GetElementType(); if (et.IsArray) { return(false); } return(TypeExpression.TypeIsCLSCompliant(t)); } Object[] attr = t.GetCustomAttributes(Typeob.CLSCompliantAttribute, false); if (attr.Length > 0) { return(((CLSCompliantAttribute)attr[0]).IsCompliant); } else { Module m = t.Module; attr = m.GetCustomAttributes(Typeob.CLSCompliantAttribute, false); if (attr.Length > 0) { return(((CLSCompliantAttribute)attr[0]).IsCompliant); } else { Assembly a = m.Assembly; attr = a.GetCustomAttributes(Typeob.CLSCompliantAttribute, false); if (attr.Length > 0) { return(((CLSCompliantAttribute)attr[0]).IsCompliant); } else { return(false); } } } } } }