public void Remove(T @delegate) { // pass the call to the real remove accessor method if (removeMethod != null) { removeMethod(@delegate); } else { // addMethod is surely non-null PhpException.Throw(PhpError.Error, CoreResources.GetString("event_has_no_remove_accessor", DTypeDesc.Create(addMethod.Method.DeclaringType).MakeFullName(), eventName)); } }
/// <summary> /// Used by CLR modules and PHP pure modules. /// </summary> internal static void ReflectTypes(Assembly /*!*/ realAssembly, Dictionary <string, DTypeDesc> /*!*/ types) { // types: foreach (Type type in realAssembly.GetTypes()) { if (type.IsVisible) { // skip PHP types that were declared conditionally: if (PhpType.IsPhpRealType(type) && PhpType.IsRealConditionalDefinition(type)) { continue; } // converts CLR namespaces and nested types to PHP namespaces: string full_name = ClrNotationUtils.FromClrNotation(type.FullName, true).ToString(); DTypeDesc existing; if (types.TryGetValue(full_name, out existing)) { ClrTypeDesc existing_clr = existing as ClrTypeDesc; if (existing_clr != null && (existing_clr.GenericOverloads.Count > 0 || type.IsGenericTypeDefinition)) { ClrTypeDesc new_clr = DTypeDesc.Create(type) as ClrTypeDesc; if (new_clr != null) { // type is overloaded by the number of generic parameters: existing_clr.AddGenericOverload(new_clr); } else { // do not add, just mark existing with the flag: existing.MemberAttributes |= PhpMemberAttributes.Ambiguous; } } else { // do not add, just mark existing with the flag: existing.MemberAttributes |= PhpMemberAttributes.Ambiguous; } } else { types[full_name] = DTypeDesc.Create(type); } } } }
/// <summary> /// Traces the calling stack to discover current PHP class context. /// </summary> /// <returns><see cref="Type"/> of the PHP class that represents current class context for this thread or /// <B>null</B> if this thread is executing in a function or startup Main context.</returns> public static DTypeDesc GetClassContext() { // SILVERLIGHT: Todo Todo .. ? what to do here ? #if !SILVERLIGHT StackTrace stack_trace = new StackTrace(1); int frame_count = stack_trace.FrameCount; for (int i = 0; i < frame_count; i++) { StackFrame stack_frame = stack_trace.GetFrame(i); MethodBase method = stack_frame.GetMethod(); Type type = method.DeclaringType; if (type != null) { if (PhpType.IsPhpRealType(type)) { return(DTypeDesc.Create(type)); } MethodInfo minfo = method as MethodInfo; if (minfo != null) { ParameterInfo[] parameters = minfo.GetParameters(); if (!PhpFunctionUtils.IsArglessStub(minfo, parameters) && PhpScript.IsScriptType(minfo.DeclaringType) && !PhpScript.IsMainHelper(minfo, parameters)) { return(null); } // if the method is a helper method (Main, an arg-less overload, a constructor, etc.), // continue with the trace } } } #endif return(null); }
/// <summary> /// Reflect PHP classes declared statically in the given script <c>type</c>. /// </summary> /// <param name="scriptType">Script type to reflect.</param> /// <param name="types">List of types to reflect to.</param> private static void ReflectScriptTypeClasses(Type scriptType, Dictionary <string, DTypeDesc> /*!*/ types) { ScriptDeclaresAttribute script_declares = ScriptDeclaresAttribute.Reflect(scriptType); if (script_declares == null) { return; } var module = scriptType.Module; foreach (var typeToken in script_declares.DeclaredTypes) { Type type = module.ResolveType(typeToken); // reflect PHP class, skip PHP types that were declared conditionally if (PhpType.IsPhpRealType(type) && !PhpType.IsRealConditionalDefinition(type)) { // converts CLR namespaces and nested types to PHP namespaces: string full_name = QualifiedName.FromClrNotation(type.FullName, true).ToString(); // Creating PhpTypeDesc with cache lookup since this type can be in the cache already: // Also force PHP type, because we already checked PhpType.IsPhpRealType(type) PhpTypeDesc phpType = (PhpTypeDesc)DTypeDesc.Create(type.TypeHandle); DTypeDesc existing; if (types.TryGetValue(full_name, out existing)) { // TODO (TP): can be generic overload!! existing.MemberAttributes |= PhpMemberAttributes.Ambiguous; } types.Add(full_name, phpType); } } }
public virtual object isIterateable(ScriptContext /*!*/ context) { var iteratordesc = DTypeDesc.Create(typeof(SPL.Iterator)); return(this.typedesc != null && iteratordesc.IsAssignableFrom(this.typedesc)); }
public void DeclareType(RuntimeTypeHandle /*!*/ typeHandle, string /*!*/ fullName) { types[fullName] = DTypeDesc.Create(typeHandle); }
private void PopulateTables() { // primitive types (prefixed by '@' to prevent ambiguities with identifiers, e.g. i'Array'): types.Add("@" + QualifiedName.Integer.Name.Value, DTypeDesc.IntegerTypeDesc); types.Add("@" + QualifiedName.Boolean.Name.Value, DTypeDesc.BooleanTypeDesc); types.Add("@" + QualifiedName.LongInteger.Name.Value, DTypeDesc.LongIntegerTypeDesc); types.Add("@" + QualifiedName.Double.Name.Value, DTypeDesc.DoubleTypeDesc); types.Add("@" + QualifiedName.String.Name.Value, DTypeDesc.StringTypeDesc); types.Add("@" + QualifiedName.Resource.Name.Value, DTypeDesc.ResourceTypeDesc); types.Add("@" + QualifiedName.Array.Name.Value, DTypeDesc.ArrayTypeDesc); types.Add("@" + QualifiedName.Object.Name.Value, DTypeDesc.ObjectTypeDesc); // types implemented in Core Func <Type, DTypeDesc> addType = (x) => { var typedesc = DTypeDesc.Create(x); types.Add(x.Name, typedesc); return(typedesc); }; addType(typeof(Library.stdClass)); addType(typeof(Library.__PHP_Incomplete_Class)); addType(typeof(Library.EventClass <>)); addType(typeof(Library.SPL.Countable)); addType(typeof(Library.SPL.ArrayAccess)); addType(typeof(Library.SPL.SplFixedArray)); addType(typeof(Library.SPL.ArrayObject)); addType(typeof(Library.SPL.Serializable)); addType(typeof(Library.SPL.SplObjectStorage)); addType(typeof(Library.SPL.SplObserver)); addType(typeof(Library.SPL.SplSubject)); addType(typeof(Library.SPL.Closure)); // Reflection: AddExportMethod(addType(typeof(Library.SPL.Reflector))); addType(typeof(Library.SPL.Reflection)); addType(typeof(Library.SPL.ReflectionClass)); addType(typeof(Library.SPL.ReflectionFunctionAbstract)); addType(typeof(Library.SPL.ReflectionFunction)); addType(typeof(Library.SPL.ReflectionMethod)); addType(typeof(Library.SPL.ReflectionProperty)); addType(typeof(Library.SPL.ReflectionException)); // Iterators: addType(typeof(Library.SPL.Traversable)); addType(typeof(Library.SPL.Iterator)); addType(typeof(Library.SPL.IteratorAggregate)); addType(typeof(Library.SPL.SeekableIterator)); addType(typeof(Library.SPL.OuterIterator)); addType(typeof(Library.SPL.RecursiveIterator)); addType(typeof(Library.SPL.ArrayIterator)); addType(typeof(Library.SPL.EmptyIterator)); addType(typeof(Library.SPL.IteratorIterator)); addType(typeof(Library.SPL.AppendIterator)); addType(typeof(Library.SPL.FilterIterator)); addType(typeof(Library.SPL.RecursiveArrayIterator)); addType(typeof(Library.SPL.RecursiveIteratorIterator)); // Exception: addType(typeof(Library.SPL.Exception)); addType(typeof(Library.SPL.RuntimeException)); addType(typeof(Library.SPL.ErrorException)); addType(typeof(Library.SPL.LogicException)); addType(typeof(Library.SPL.InvalidArgumentException)); addType(typeof(Library.SPL.OutOfRangeException)); addType(typeof(Library.SPL.BadFunctionCallException)); addType(typeof(Library.SPL.BadMethodCallException)); addType(typeof(Library.SPL.LengthException)); addType(typeof(Library.SPL.RangeException)); addType(typeof(Library.SPL.OutOfBoundsException)); addType(typeof(Library.SPL.OverflowException)); addType(typeof(Library.SPL.UnderflowException)); addType(typeof(Library.SPL.UnexpectedValueException)); addType(typeof(Library.SPL.DomainException)); // primitive constants constants.Add("TRUE", GlobalConstant.True.ConstantDesc, true); constants.Add("FALSE", GlobalConstant.False.ConstantDesc, true); constants.Add("NULL", GlobalConstant.Null.ConstantDesc, true); // the constants are same for all platforms (Phalanger use Int32 for integers in PHP): constants.Add("PHP_INT_SIZE", GlobalConstant.PhpIntSize.ConstantDesc, false); constants.Add("PHP_INT_MAX", GlobalConstant.PhpIntMax.ConstantDesc, false); }