Esempio n. 1
0
        public static Tokens AsToken(this PhpMemberAttributes attributes)
        {
            switch (attributes)
            {
            case PhpMemberAttributes.Public:
                return(Tokens.T_PUBLIC);

            case PhpMemberAttributes.Private:
                return(Tokens.T_PRIVATE);

            case PhpMemberAttributes.Protected:
                return(Tokens.T_PROTECTED);

            case PhpMemberAttributes.Static:
                return(Tokens.T_STATIC);

            case PhpMemberAttributes.Abstract:
                return(Tokens.T_ABSTRACT);

            case PhpMemberAttributes.Final:
                return(Tokens.T_FINAL);

            case PhpMemberAttributes.Interface:
                return(Tokens.T_INTERFACE);

            case PhpMemberAttributes.Trait:
                return(Tokens.T_TRAIT);

            case PhpMemberAttributes.Enum:
                return(Tokens.T_ENUM);

            default:
                return(Tokens.T_ERROR);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Determines lowest accessibility of all property accessors and other member attributes.
        /// </summary>
        public static PhpMemberAttributes GetPropertyAttributes(PropertyInfo /*!*/ info)
        {
            var accessors = info.GetAccessors(true);
            PhpMemberAttributes attributes = PhpMemberAttributes.None;

            // find lowest visibility in all property accessors:
            for (int i = 0; i < accessors.Length; i++)
            {
                if (accessors[i].IsStatic)
                {
                    attributes |= PhpMemberAttributes.Static;
                }

                if (accessors[i].IsPrivate)
                {
                    attributes |= PhpMemberAttributes.Private;
                }
                else if (accessors[i].IsFamily)
                {
                    attributes |= PhpMemberAttributes.Protected;
                }
                //else if (accessors[i].IsPublic)
                //    visibility |= PhpMemberAttributes.Public;
            }

            return(attributes);
        }
Esempio n. 3
0
        public static PhpMemberAttributes GetMemberAttributes(FieldInfo /*!*/ info)
        {
            PhpMemberAttributes value = PhpMemberAttributes.None;

            if (info.IsPublic)
            {
                value |= PhpMemberAttributes.Public;
            }
            else if (info.IsFamily)
            {
                value |= PhpMemberAttributes.Protected;
            }
            else if (info.IsPrivate)
            {
                value |= PhpMemberAttributes.Private;
            }

            if (info.IsStatic)
            {
                value |= PhpMemberAttributes.Static;

                // AppStatic == Static on Silverlight
#if !SILVERLIGHT
                if (!info.IsDefined(typeof(ThreadStaticAttribute), false))
                {
                    value |= PhpMemberAttributes.AppStatic;
                }
#else
                value |= PhpMemberAttributes.AppStatic;
#endif
            }

            return(value);
        }
Esempio n. 4
0
        public FormalParam(
            Text.Span span, string /*!*/ name, Text.Span nameSpan,
            TypeRef typeHint, Flags flags,
            Expression initValue,
            PhpMemberAttributes constructorPropertyVisibility = 0)
            : base(span)
        {
            this.Name      = new VariableNameRef(nameSpan, name);
            this.TypeHint  = typeHint;
            this.InitValue = initValue;

            _flags = flags;

            if (constructorPropertyVisibility != 0)
            {
                Debug.Assert((constructorPropertyVisibility & PhpMemberAttributes.Constructor) != 0);

                _flags |= (constructorPropertyVisibility & PhpMemberAttributes.VisibilityMask) switch
                {
                    PhpMemberAttributes.Private => Flags.IsConstructorPropertyPrivate,
                    PhpMemberAttributes.Protected => Flags.IsConstructorPropertyProtected,
                    //PhpMemberAttributes.Public => Flags.IsConstructorPropertyPublic,
                    _ => Flags.IsConstructorPropertyPublic,
                };

                if (constructorPropertyVisibility.IsReadOnly())
                {
                    _flags |= Flags.IsConstructorPropertyReadOnly;
                }
            }
        }
Esempio n. 5
0
        public static FieldAttributes ToFieldAttributes(PhpMemberAttributes value)
        {
            FieldAttributes     result     = 0;
            PhpMemberAttributes visibility = value & PhpMemberAttributes.VisibilityMask;

            if (visibility == PhpMemberAttributes.Public)
            {
                result |= FieldAttributes.Public;
            }
            else if (visibility == PhpMemberAttributes.Private)
            {
                result |= FieldAttributes.Private;
            }
            else if (visibility == PhpMemberAttributes.Protected)
            {
                result |= FieldAttributes.Family;
            }

            if ((value & PhpMemberAttributes.Static) != 0)
            {
                result |= FieldAttributes.Static;
            }

            Debug.Assert((value & PhpMemberAttributes.Interface) == 0);
            Debug.Assert((value & PhpMemberAttributes.Abstract) == 0);
            Debug.Assert((value & PhpMemberAttributes.Final) == 0);

            return(result);
        }
Esempio n. 6
0
        public FunctionDecl(SourceUnit /*!*/ sourceUnit,
                            Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition,
                            bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, string /*!*/ name, NamespaceDecl ns,
                            bool aliasReturn, List <FormalParam> /*!*/ formalParams, List <FormalTypeParam> /*!*/ genericParams,
                            IList <Statement> /*!*/ body, List <CustomAttribute> attributes)
            : base(span)
        {
            Debug.Assert(genericParams != null && name != null && formalParams != null && body != null);

            this.name          = new Name(name);
            this.ns            = ns;
            this.signature     = new Signature(aliasReturn, formalParams);
            this.typeSignature = new TypeSignature(genericParams);
            if (attributes != null && attributes.Count != 0)
            {
                this.Attributes = new CustomAttributes(attributes);
            }
            this.body = body.AsArray();
            this.entireDeclarationSpan   = entireDeclarationPosition;
            this.headingEndPosition      = headingEndPosition;
            this.declarationBodyPosition = declarationBodyPosition;
            this.IsConditional           = isConditional;
            this.MemberAttributes        = memberAttributes;
            this.Scope      = scope;
            this.SourceUnit = sourceUnit;
        }
Esempio n. 7
0
 public FieldDeclList(Text.Span span, PhpMemberAttributes modifiers, List <FieldDecl> /*!*/ fields,
                      List <CustomAttribute> attributes)
     : base(span, modifiers, attributes)
 {
     Debug.Assert(fields != null);
     this.fields = fields;
 }
Esempio n. 8
0
        public static TypeAttributes ToTypeAttributes(PhpMemberAttributes attrs)
        {
            TypeAttributes result = TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit;

            result = TypeAttributes.Public;

            Debug.Assert((attrs & PhpMemberAttributes.VisibilityMask) != PhpMemberAttributes.Protected);

            if ((attrs & PhpMemberAttributes.Abstract) != 0)
            {
                result |= TypeAttributes.Abstract;
            }

            if ((attrs & PhpMemberAttributes.Interface) != 0)
            {
                result |= TypeAttributes.Interface;
            }
            else
            {
                result |= TypeAttributes.Class | TypeAttributes.Serializable;
            }

            if ((attrs & PhpMemberAttributes.Final) != 0)
            {
                result |= TypeAttributes.Sealed;
            }

            return(result);
        }
Esempio n. 9
0
 public FieldDeclList(Text.Span span, PhpMemberAttributes modifiers, IList <FieldDecl> /*!*/ fields, TypeRef type)
     : base(span, modifiers)
 {
     Debug.Assert(fields != null);
     this.Fields = fields ?? throw new ArgumentNullException(nameof(fields));
     this.Type   = type;
 }
Esempio n. 10
0
        /// <summary>
        /// Used by full-reflect (CLR).
        /// </summary>
        public ClassConstant(VariableName name, DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes)
            : base(new DConstantDesc(declaringType, memberAttributes, null))
        {
            Debug.Assert(declaringType != null);

            this.name = name;
        }
Esempio n. 11
0
		/// <summary>
		/// Parses property name used for serialization. 
		/// </summary>
		/// <param name="name">The name found in serialization stream or returned by <B>__sleep</B>.</param>
		/// <param name="typeName">Will receive the name of the declaring type or <B>null</B> if no
		/// type information is embedded in the property <paramref name="name"/>.</param>
		/// <param name="visibility">Will receive the assumed visibility of the property.</param>
		/// <returns>The bare (unmangled) property name.</returns>
		/// <remarks>
		/// Names of protected properties might be prepended with \0*\0, names of private properties might be
		/// prepended with \0declaring_class_name\0
		/// (see <A href="http://bugs.php.net/bug.php?id=26737">http://bugs.php.net/bug.php?id=26737</A>)
		/// </remarks>
		public static string/*!*/ ParsePropertyName(string/*!*/ name, out string typeName, out PhpMemberAttributes visibility)
		{
			if (name.Length >= 3 && name[0] == '\0')
			{
				if (name[1] == '*' && name[2] == '\0')
				{
					// probably a protected field
					visibility = PhpMemberAttributes.Protected;
					typeName = null;
					return name.Substring(3);
				}
				else
				{
					// probably a private property
					int index = name.IndexOf('\0', 2);
					if (index > 0)
					{
						visibility = PhpMemberAttributes.Private;
						typeName = name.Substring(1, index - 1);  // TODO
						return name.Substring(index + 1);
					}
				}
			}

			visibility = PhpMemberAttributes.Public;
			typeName = null;
			return name;
		}
Esempio n. 12
0
            public TmpMemberInfo /*!*/ Update(PhpMemberAttributes attr, object docComment)
            {
                this.attr       = attr;
                this.docComment = docComment;

                return(this);
            }
Esempio n. 13
0
        /// <summary>
        /// <para>Returns <see cref="MethodAttributes"/> that are used while emitting the method.</para>
        /// <para>NOTE: Combinations static/final and static/abstract can be returned. Such methods are
        /// not allowed in CLI, so final or abstract flag must be removed and PhpFinalAttribute or
        /// PhpAbstractAttribute added instead.</para>
        /// </summary>
        /// <returns></returns>
        public static MethodAttributes ToMethodAttributes(PhpMemberAttributes value)
        {
            MethodAttributes result = 0;
            PhpMemberAttributes visibility = value & PhpMemberAttributes.VisibilityMask;

            if (visibility == PhpMemberAttributes.Public) result |= MethodAttributes.Public;
            else if (visibility == PhpMemberAttributes.Private) result |= MethodAttributes.Private;
            else if (visibility == PhpMemberAttributes.Protected) result |= MethodAttributes.Family;

            if ((value & PhpMemberAttributes.Final) != 0)
                result |= MethodAttributes.Final;

            if ((value & PhpMemberAttributes.Static) != 0)
            {
                result |= MethodAttributes.Static;

                // abstract statics are not allowed in CLR => custom attribute is added
                // final statics as well
            }
            else
            {
                result |= MethodAttributes.Virtual;

                if ((value & PhpMemberAttributes.Abstract) != 0)
                    result |= MethodAttributes.Abstract;
            }

            Debug.Assert((value & PhpMemberAttributes.Interface) == 0);

            return result;
        }
Esempio n. 14
0
        public TypeDecl(
            Text.Span span, Text.Span headingSpan,
            bool isConditional, PhpMemberAttributes memberAttributes, bool isPartial,
            List <FormalTypeParam> /*!*/ genericParams, INamedTypeRef baseClass,
            List <INamedTypeRef> /*!*/ implementsList, List <TypeMemberDecl> /*!*/ elements, Text.Span bodySpan,
            List <CustomAttribute> attributes)
            : base(span)
        {
            Debug.Assert(genericParams != null && implementsList != null && elements != null);
            Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait");

            this.typeSignature    = new TypeSignature(genericParams);
            this.baseClass        = baseClass;
            this.MemberAttributes = memberAttributes;
            this.IsConditional    = isConditional;
            this.ImplementsList   = implementsList.AsArray();
            this.members          = elements;
            this.members.TrimExcess();

            if (attributes != null && attributes.Count != 0)
            {
                this.Attributes = new CustomAttributes(attributes);
            }
            this.headingSpan    = headingSpan;
            this.bodySpan       = bodySpan;
            this.partialKeyword = isPartial;
        }
Esempio n. 15
0
		/// <summary>
		/// Used by compiler and full-reflect.
		/// </summary>
		internal DPropertyDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes)
			: base(declaringType, memberAttributes)
		{
			Debug.Assert(declaringType != null);
			this._getterStub = null; // to be generated on demand
			this._setterStub = null; // to be generated on demand
		}
Esempio n. 16
0
        public virtual LangElement DeclList(Span span, PhpMemberAttributes attributes, IList <LangElement> /*!!*/ decls, TypeRef type)
        {
            Debug.Assert(decls.Count != 0);
            Debug.Assert(decls.All(e => e is FieldDecl) || decls.All(e => e is GlobalConstantDecl) || decls.All(e => e is ClassConstantDecl));

            if (decls[0] is FieldDecl)
            {
                Debug.Assert(decls.All(e => e is FieldDecl));
                return(new FieldDeclList(span, attributes, decls.CastToArray <FieldDecl>(), type));
            }
            else if (decls[0] is ClassConstantDecl)
            {
                Debug.Assert(decls.All(e => e is ClassConstantDecl));
                return(new ConstDeclList(span, attributes, decls.CastToArray <ClassConstantDecl>()));
            }
            else if (decls[0] is GlobalConstantDecl)
            {
                Debug.Assert(decls.All(e => e is GlobalConstantDecl));
                return(new GlobalConstDeclList(span, decls.CastToArray <GlobalConstantDecl>()));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Esempio n. 17
0
        public FunctionDecl(SourceUnit /*!*/ sourceUnit,
                            Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition,
                            bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, string /*!*/ name, NamespaceDecl ns,
                            bool aliasReturn, List <FormalParam> /*!*/ formalParams, List <FormalTypeParam> /*!*/ genericParams,
                            List <Statement> /*!*/ body, List <CustomAttribute> attributes)
            : base(position)
        {
            Debug.Assert(genericParams != null && name != null && formalParams != null && body != null);

            this.name                      = new Name(name);
            this.ns                        = ns;
            this.signature                 = new Signature(aliasReturn, formalParams);
            this.typeSignature             = new TypeSignature(genericParams);
            this.attributes                = new CustomAttributes(attributes);
            this.body                      = body;
            this.entireDeclarationPosition = entireDeclarationPosition;
            this.headingEndPosition        = headingEndPosition;
            this.declarationBodyPosition   = declarationBodyPosition;

            QualifiedName qn = (ns != null) ? new QualifiedName(this.name, ns.QualifiedName) : new QualifiedName(this.name);

            function = new PhpFunction(qn, memberAttributes, signature, typeSignature, isConditional, scope, sourceUnit, position);
            function.WriteUp(typeSignature.ToPhpRoutineSignature(function));

            function.Declaration.Node = this;
        }
Esempio n. 18
0
 public LambdaFunctionExpr(
     Text.Span span, Text.Span headingSpan,
     bool aliasReturn, PhpMemberAttributes modifiers, IList <FormalParam> /*!*/ formalParams,
     Text.Span paramSpan, IList <FormalParam> useParams,
     BlockStmt /*!*/ body, TypeRef returnType)
     : this(span, headingSpan, new Signature(aliasReturn, formalParams, paramSpan), useParams, body, returnType)
 {
 }
Esempio n. 19
0
        /// <summary>
        /// Used by all subclasses except for <see cref="GlobalTypeDesc"/>.
        /// </summary>
        protected DMemberDesc(DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes)
        {
            Debug.Assert(declaringType != null);

            this.declaringType    = declaringType;
            this.memberAttributes = memberAttributes;
            this.member           = null;   // to be filled by DMember or at run-time (if applicable)
        }
Esempio n. 20
0
 public virtual LangElement Method(Span span, bool aliasReturn, PhpMemberAttributes attributes, TypeRef returnType,
                                   Span returnTypeSpan, string name, Span nameSpan, IEnumerable <FormalTypeParam> typeParamsOpt,
                                   IEnumerable <FormalParam> formalParams, Span formalParamsSpan, IEnumerable <ActualParam> baseCtorParams, LangElement body)
 {
     return(new MethodDecl(span, new NameRef(nameSpan, name), aliasReturn, formalParams.AsArray(),
                           formalParamsSpan, typeParamsOpt.AsArray(),
                           (BlockStmt)body, attributes, baseCtorParams.AsArray(), returnType));
 }
Esempio n. 21
0
 public void VisitClassConstantDecl(ClassConstantDecl x, PhpMemberAttributes attributes)
 {
     _serializer.StartSerialize(typeof(ClassConstantDecl).Name, SerializeSpan(x.Span),
                                new NodeObj("Name", x.Name.Name.Value), new NodeObj("MemberAttributes", MemberAttributesToString(attributes)));
     SerializePHPDoc(x.PHPDoc);
     VisitElement(x.Initializer);
     _serializer.EndSerialize();
 }
Esempio n. 22
0
 public AnonymousTypeDecl(
     Text.Span span, Text.Span headingSpan,
     bool isConditional, PhpMemberAttributes memberAttributes, bool isPartial,
     IList <FormalTypeParam> /*!*/ genericParams, INamedTypeRef baseClass,
     IList <INamedTypeRef> /*!*/ implementsList, IList <TypeMemberDecl> /*!*/ elements, Text.Span bodySpan)
     : base(span, headingSpan, isConditional,
            memberAttributes, isPartial, genericParams, baseClass, implementsList, elements, bodySpan)
 {
 }
Esempio n. 23
0
 void PushClassContext(string name, TypeRef baseType, PhpMemberAttributes attrs)
 {
     ClassContexts.Push(new ClassContext()
     {
         Name       = new QualifiedName(new Name(name), namingContext.CurrentNamespace.HasValue ? namingContext.CurrentNamespace.Value.Namespaces : Name.EmptyNames),
         Base       = baseType,
         Attributes = attrs,
     });
 }
Esempio n. 24
0
 protected TypeMemberDecl(Text.Span span, PhpMemberAttributes modifiers, List <CustomAttribute> attributes)
     : base(span)
 {
     if (attributes != null && attributes.Count != 0)
     {
         this.Attributes = new CustomAttributes(attributes);
     }
     this.modifiers = modifiers;
 }
Esempio n. 25
0
        internal static void DefineCustomAttributes(PhpMemberAttributes attrs, TypeBuilder /*!*/ typeBuilder)
        {
            Debug.Assert(typeBuilder != null);

            if ((attrs & PhpMemberAttributes.Trait) != 0)
            {
                typeBuilder.SetCustomAttribute(AttributeBuilders.ImplementsTrait);
            }
            // no attributes so far
        }
Esempio n. 26
0
        /// <summary>
        /// Used by compiler.
        /// </summary>
        public ClassConstant(VariableName name, DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes,
                             SourceUnit /*!*/ sourceUnit, Text.Span position)
            : base(new DConstantDesc(declaringType, memberAttributes, null))
        {
            Debug.Assert(declaringType != null);

            this.name       = name;
            this.span       = position;
            this.sourceUnit = sourceUnit;
        }
Esempio n. 27
0
		/// <summary>
		/// Used by compiler through subclasses (<paramref name="arglessStub"/> is <B>null</B> then).
		/// Called by a declaring helper at run-time.
		/// </summary>
        /// <param name="declaringType">The declaring type. Can be null.</param>
        /// <param name="memberAttributes">Attributes of the function.</param>
        /// <param name="arglessStub">The stub to be called. Cannot be null.</param>
        /// <param name="needsIndex">True to allocate <see cref="Index"/>. Usable for preserved descs, for global functions that can be reused.</param>
		internal DRoutineDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate arglessStub, bool needsIndex)
			: base(declaringType, memberAttributes)
		{
			Debug.Assert(declaringType != null);
			this._arglessStub = arglessStub;

            // allocate an index, only for preserved descs
            if (needsIndex) // assign an index only if needed (save indexes, since they cause prealocation of larger BitArray)
                this.Index = System.Threading.Interlocked.Increment(ref LastIndex);
		}
Esempio n. 28
0
        public SourceFieldSymbol(SourceNamedTypeSymbol type, string name, PhpMemberAttributes modifiers, PHPDocBlock phpdoc, BoundExpression initializer = null)
        {
            Contract.ThrowIfNull(type);
            Contract.ThrowIfNull(name);

            _type           = type;
            _name           = name;
            _modifiers      = modifiers;
            _phpdoc         = phpdoc;
            _initializerOpt = initializer;
        }
Esempio n. 29
0
        /// <summary>
        /// Used by compiler through subclasses (<paramref name="arglessStub"/> is <B>null</B> then).
        /// Called by a declaring helper at run-time.
        /// </summary>
        /// <param name="declaringType">The declaring type. Can be null.</param>
        /// <param name="memberAttributes">Attributes of the function.</param>
        /// <param name="arglessStub">The stub to be called. Cannot be null.</param>
        /// <param name="needsIndex">True to allocate <see cref="Index"/>. Usable for preserved descs, for global functions that can be reused.</param>
        internal DRoutineDesc(DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate arglessStub, bool needsIndex)
            : base(declaringType, memberAttributes)
        {
            Debug.Assert(declaringType != null);
            this._arglessStub = arglessStub;

            // allocate an index, only for preserved descs
            if (needsIndex) // assign an index only if needed (save indexes, since they cause prealocation of larger BitArray)
            {
                this.Index = System.Threading.Interlocked.Increment(ref LastIndex);
            }
        }
Esempio n. 30
0
        public NamedTypeDecl(
            Text.Span span, Text.Span headingSpan, bool isConditional, PhpMemberAttributes memberAttributes, bool isPartial,
            NameRef className, IList <FormalTypeParam> /*!*/ genericParams, INamedTypeRef baseClass,
            IList <INamedTypeRef> /*!*/ implementsList, IList <TypeMemberDecl> /*!*/ elements, Text.Span bodySpan)
            : base(span, headingSpan, isConditional,
                   memberAttributes, isPartial, genericParams, baseClass, implementsList, elements, bodySpan)
        {
            Debug.Assert(genericParams != null && implementsList != null && elements != null);
            Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait");

            this.name = className;
        }
Esempio n. 31
0
        /// <summary>
        /// Add at runtime a constant to a type
        /// </summary>
        /// <param name="typedesc">Type to modify</param>
        /// <param name="attributes">New const attributes</param>
        /// <param name="const_name">Const name</param>
        /// <param name="value">Const value</param>
        /// <remarks>Used by PDO_MYSQL</remarks>
        public void AddConstantToType(DTypeDesc typedesc, PhpMemberAttributes attributes, string const_name, object value)
        {
            Debug.Assert(typedesc != null);

            VariableName  name       = new VariableName(const_name);
            DConstantDesc const_desc = new DConstantDesc(typedesc, attributes, value);

            if (!typedesc.Constants.ContainsKey(name))
            {
                typedesc.Constants.Add(name, const_desc);
            }
        }
Esempio n. 32
0
        private static string VisibilityString(PhpMemberAttributes attrs)
        {
            var visibility = attrs & PhpMemberAttributes.VisibilityMask;

            switch (visibility)
            {
            case PhpMemberAttributes.Public:
                return("public");

            default:
                return(visibility.ToString().ToLowerInvariant());
            }
        }
Esempio n. 33
0
        internal static void DefineCustomAttributes(PhpMemberAttributes attrs, FieldBuilder /*!*/ fieldBuilder)
        {
            Debug.Assert(fieldBuilder != null);

            // AppStatic == Static on Silverlight
#if !SILVERLIGHT
            // static but not app-static => thread static
            if ((attrs & PhpMemberAttributes.AppStatic) == PhpMemberAttributes.Static)
            {
                fieldBuilder.SetCustomAttribute(AttributeBuilders.ThreadStatic);
            }
#endif
        }
        /// <summary>
        /// Called by the Core after the library is loaded.
        /// </summary>
        protected override void Loaded(PhpLibraryAttribute assemblyAttribute, LibraryConfigStore configStore)
        {
            base.Loaded(assemblyAttribute, configStore);
            singleton = this;

            PDOSQLiteConfiguration.RegisterLegacyOptions();

            PDOLibraryDescriptor.RegisterProvider(new SQLitePDODriver());

            var tPDO = Core.Reflection.DTypeDesc.Create(typeof(PDO));
            PhpMemberAttributes att = PhpMemberAttributes.Public | PhpMemberAttributes.Static;

            ApplicationContext.Default.AddMethodToType(tPDO, att, "sqliteCreateFunction", SQLitePDODriver.PDO_sqliteCreateFunction);
        }
Esempio n. 35
0
		/// <summary>
		/// Used by all subclasses except for <see cref="GlobalTypeDesc"/>.
		/// </summary>
		protected DMemberDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes)
		{
			Debug.Assert(declaringType != null);

			this.declaringType = declaringType;
			this.memberAttributes = memberAttributes;
			this.member = null; // to be filled by DMember or at run-time (if applicable)
		}
Esempio n. 36
0
		internal static void Print(PhpMemberAttributes value, TextWriter output)
		{
			if ((value & PhpMemberAttributes.Abstract) != 0) output.Write("abstract ");
			if ((value & PhpMemberAttributes.Final) != 0) output.Write("final ");

			output.Write(VisibilityToString(value));

			if ((value & PhpMemberAttributes.AppStatic) != 0) output.Write("appstatic ");
			else if ((value & PhpMemberAttributes.Static) != 0) output.Write("static ");
		}
Esempio n. 37
0
		public static bool VisibilityEquals(PhpMemberAttributes attr1, PhpMemberAttributes attr2)
		{
			return ((attr1 & PhpMemberAttributes.VisibilityMask) == (attr2 & PhpMemberAttributes.VisibilityMask));
		}
Esempio n. 38
0
		public static string VisibilityToString(PhpMemberAttributes value)
		{
			PhpMemberAttributes visibility = value & PhpMemberAttributes.VisibilityMask;

			if (visibility == PhpMemberAttributes.Public) return "public";
			else if (visibility == PhpMemberAttributes.Protected) return "protected";
			else if (visibility == PhpMemberAttributes.Private) return "private";

			Debug.Fail();
			return null;
		}
Esempio n. 39
0
		/// <summary>
		/// Used by compiler.
		/// </summary>
		public PhpField(VariableName name, DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			bool hasInitialValue, SourceUnit/*!*/ sourceUnit, Position position)
			: base(new DPhpFieldDesc(declaringType, memberAttributes), name)
		{
			this.hasInitialValue = hasInitialValue;
			this.position = position;
			this.sourceUnit = sourceUnit;
			this.builder = new PhpFieldBuilder(this);
		}
Esempio n. 40
0
		/// <summary>
		/// Used by full reflection.
		/// </summary>
		internal DPhpFieldDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes)
			: base(declaringType, memberAttributes)
		{
			Debug.Assert(declaringType != null);

			// stubs generated on-demand as dynamic methods
		}
Esempio n. 41
0
		public static FieldAttributes ToFieldAttributes(PhpMemberAttributes value)
		{
			FieldAttributes result = 0;
			PhpMemberAttributes visibility = value & PhpMemberAttributes.VisibilityMask;

			if (visibility == PhpMemberAttributes.Public) result |= FieldAttributes.Public;
			else if (visibility == PhpMemberAttributes.Private) result |= FieldAttributes.Private;
			else if (visibility == PhpMemberAttributes.Protected) result |= FieldAttributes.Family;

			if ((value & PhpMemberAttributes.Static) != 0)
				result |= FieldAttributes.Static;

			Debug.Assert((value & PhpMemberAttributes.Interface) == 0);
			Debug.Assert((value & PhpMemberAttributes.Abstract) == 0);
			Debug.Assert((value & PhpMemberAttributes.Final) == 0);

			return result;
		}
Esempio n. 42
0
		/// <summary>
		/// Creates a descriptor for specified PHP function at run-time if argless stub delegate is available.
		/// Called by declaring helpers emitted on script or when a callback is created.
		/// </summary>
        public PhpRoutineDesc(PhpMemberAttributes memberAttributes, RoutineDelegate/*!*/ arglessStub, bool needsIndex)
            : base(UnknownModule.RuntimeModule.GlobalType.TypeDesc, memberAttributes, arglessStub, needsIndex)
		{
			Debug.Assert(arglessStub != null);
		}
Esempio n. 43
0
		/// <summary>
		/// Used by compiler for functions.
		/// </summary>
		internal PhpRoutineDesc(DModule/*!*/ declaringModule, PhpMemberAttributes memberAttributes)
			: base(declaringModule.GlobalType.TypeDesc, memberAttributes, null, false)
		{
			Debug.Assert(declaringModule != null);
			Debug.Assert((memberAttributes & PhpMemberAttributes.Static) != 0);
		}
Esempio n. 44
0
		/// <summary>
		/// Used by full-reflect.
		/// </summary>
		public ClrProperty(VariableName name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			PropertyInfo/*!*/ realProperty, bool hasGetter, bool hasSetter)
			: base(new DPropertyDesc(declaringType, memberAttributes), name)
		{
			Debug.Assert(realProperty != null);

			this.realProperty = realProperty;
			this.hasGetter = hasGetter;
			this.hasSetter = hasSetter;
		}
Esempio n. 45
0
		/// <summary>
		/// Used by full-reflect.
		/// </summary>
		public ClrField(VariableName/*!*/ name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			FieldInfo/*!*/ fieldInfo)
			: base(new DPropertyDesc(declaringType, memberAttributes), name)
		{
			this.fieldInfo = fieldInfo;
		}
Esempio n. 46
0
		/// <summary>
		/// To be used by compiler.
		/// </summary>
		internal PhpFunction(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes,
			Signature astSignature, TypeSignature astTypeSignature, bool isConditional, Scope scope,
			SourceUnit/*!*/ sourceUnit, Position position)
			: base(new PhpRoutineDesc(sourceUnit.CompilationUnit.Module, memberAttributes), astSignature, astTypeSignature)
		{
			Debug.Assert(sourceUnit != null && position.IsValid);

			this.declaration = new Declaration(sourceUnit, this, false, isConditional, scope, position);
			this.qualifiedName = qualifiedName;
			this.version = new VersionInfo();
			this.signature = null; // to be written up
		}
Esempio n. 47
0
		protected DMemberDesc()
		{
			this.declaringType = (DTypeDesc)this;
			this.memberAttributes = PhpMemberAttributes.None;
			this.member = null; // to be filled by DMember (if applicable)
		}
Esempio n. 48
0
		/// <summary>
		/// Used by full-reflect.
		/// </summary>
		public ClrGenericMethodDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes)
			: base(declaringType, memberAttributes)
		{
			Debug.Assert(declaringType != null);
		}
Esempio n. 49
0
 private static string VisibilityString(PhpMemberAttributes attrs)
 {
     var visibility = attrs & PhpMemberAttributes.VisibilityMask;
     switch (visibility)
     {
         case PhpMemberAttributes.Public:
             return "public";
         default:
             return visibility.ToString().ToLowerInvariant();
     }
 }
Esempio n. 50
0
		/// <summary>
		/// Used by full-reflect.
		/// </summary>
		public ClrMethod(Name name, DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			int estimatedOverloadCount, bool isGeneric)
			: base(isGeneric ?
				new ClrGenericMethodDesc(declaringType, memberAttributes) :
				new ClrMethodDesc(declaringType, memberAttributes))
		{
			this.name = name;
			this.overloads = new List<Overload>(estimatedOverloadCount);
		}
Esempio n. 51
0
		/// <summary>
		/// Used by compiler for methods.
		/// </summary>
		internal PhpRoutineDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes)
			: base(declaringType, memberAttributes, null, false)
		{
			Debug.Assert(declaringType != null);
		}
Esempio n. 52
0
		internal static void DefineCustomAttributes(PhpMemberAttributes attrs, TypeBuilder/*!*/ typeBuilder)
		{
			Debug.Assert(typeBuilder != null);

			// no attributes so far
		}
Esempio n. 53
0
		internal static void DefineCustomAttributes(PhpMemberAttributes attrs, FieldBuilder/*!*/ fieldBuilder)
		{
			Debug.Assert(fieldBuilder != null);

			// AppStatic == Static on Silverlight
#if !SILVERLIGHT
			// static but not app-static => thread static
			if ((attrs & PhpMemberAttributes.AppStatic) == PhpMemberAttributes.Static)
				fieldBuilder.SetCustomAttribute(AttributeBuilders.ThreadStatic);
#endif
		}
Esempio n. 54
0
		/// <summary>
		/// Used by the compiler.
		/// </summary>
		internal PhpMethod(PhpType/*!*/ declaringType, Name name, PhpMemberAttributes memberAttributes, bool hasBody,
	  Signature astSignature, TypeSignature astTypeSignature, SourceUnit/*!*/ sourceUnit, Position position)
			: base(new PhpRoutineDesc(declaringType.TypeDesc, memberAttributes), astSignature, astTypeSignature)
		{
			Debug.Assert(declaringType != null && sourceUnit != null && position.IsValid);

			this.name = name;
			this.position = position;
			this.hasBody = hasBody;
			this.sourceUnit = sourceUnit;
		}
Esempio n. 55
0
		public static TypeAttributes ToTypeAttributes(PhpMemberAttributes attrs)
		{
			TypeAttributes result = TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit;

			result = TypeAttributes.Public;

			Debug.Assert((attrs & PhpMemberAttributes.VisibilityMask) != PhpMemberAttributes.Protected);

			if ((attrs & PhpMemberAttributes.Abstract) != 0)
				result |= TypeAttributes.Abstract;

			if ((attrs & PhpMemberAttributes.Interface) != 0)
				result |= TypeAttributes.Interface;
			else
				result |= TypeAttributes.Class | TypeAttributes.Serializable;

			if ((attrs & PhpMemberAttributes.Final) != 0)
				result |= TypeAttributes.Sealed;

			return result;
		}
Esempio n. 56
0
		/// <summary>
		/// Used by full-reflect.
		/// </summary>
		public ClrEvent(VariableName name, ClrTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			EventInfo/*!*/ realEvent, bool hasAddMethod, bool hasRemoveMethod)
			: base(new DPropertyDesc(declaringType, memberAttributes), name)
		{
			this.realEvent = realEvent;
			this.hasAddMethod = hasAddMethod;
			this.hasRemoveMethod = hasRemoveMethod;
		}
Esempio n. 57
0
		internal static void DefineCustomAttributes(PhpMemberAttributes attrs, MethodInfo/*!*/ method)
		{
			Debug.Assert(method != null);

			if ((attrs & PhpMemberAttributes.Static) != 0)
			{
				if ((attrs & PhpMemberAttributes.Abstract) != 0)
					ReflectionUtils.SetCustomAttribute(method, AttributeBuilders.PhpAbstract);

				if ((attrs & PhpMemberAttributes.Final) != 0)
					ReflectionUtils.SetCustomAttribute(method, AttributeBuilders.PhpFinal);
			}
		}
Esempio n. 58
0
		public static PropertyAttributes ToPropertyAttributes(PhpMemberAttributes value)
		{
			return PropertyAttributes.None;
		}
Esempio n. 59
0
		/// <summary>
		/// Used by type population.
		/// </summary>
		internal DPhpFieldDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes,
			GetterDelegate getterStub, SetterDelegate setterStub)
			: base(declaringType, memberAttributes)
		{
			Debug.Assert(declaringType != null && (getterStub != null || setterStub != null));

			this._getterStub = getterStub;
			this._setterStub = setterStub;
		}
Esempio n. 60
0
		/// <summary>
		/// Creates a descriptor for specified PHP method at run-time if argless stub delegate is available.
		/// Called by declaring helper emitted on PHP types.
		/// </summary>
		internal PhpRoutineDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate/*!*/ arglessStub)
			: base(declaringType, memberAttributes, arglessStub, false)
		{
			Debug.Assert(arglessStub != null);
		}