diff options
author | Martijn Otto <martijn.otto@copernica.com> | 2014-02-14 16:30:23 +0100 |
---|---|---|
committer | Martijn Otto <martijn.otto@copernica.com> | 2014-02-14 16:30:23 +0100 |
commit | 06aa5fd5afaba69544b93654fb0a4f9c2651306e (patch) | |
tree | 99cd2ee120786a84531b450f9ef64e2319ef5192 /src | |
parent | 5c23fee5ce58ae66a70f3bd19a1dc2dff7220f13 (diff) |
Merged pull request #14
Diffstat (limited to 'src')
-rw-r--r-- | src/boolmember.h | 16 | ||||
-rw-r--r-- | src/classinfo.cpp | 7 | ||||
-rw-r--r-- | src/doublemember.h | 19 | ||||
-rw-r--r-- | src/flag.cpp | 114 | ||||
-rw-r--r-- | src/function.cpp | 5 | ||||
-rw-r--r-- | src/includes.h | 15 | ||||
-rw-r--r-- | src/longmember.h | 18 | ||||
-rw-r--r-- | src/member.cpp | 57 | ||||
-rw-r--r-- | src/memberinfo.h | 13 | ||||
-rw-r--r-- | src/methodmember.h | 4 | ||||
-rw-r--r-- | src/nullmember.h | 16 | ||||
-rw-r--r-- | src/stringmember.h | 16 |
12 files changed, 265 insertions, 35 deletions
diff --git a/src/boolmember.h b/src/boolmember.h index 84d7d44..84aa4e9 100644 --- a/src/boolmember.h +++ b/src/boolmember.h @@ -57,6 +57,22 @@ public: zend_declare_property_bool(entry, (char *) name, size, _value, flags); #endif } + + /** + * Virtual method to declare the class constant + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) + { +#if PHP_VERSION_ID >= 50400 + zend_declare_class_constant_bool(entry, name, size, _value); +#else + zend_declare_class_constant_bool(entry, (char *) name, size, _value); +#endif + } }; /** diff --git a/src/classinfo.cpp b/src/classinfo.cpp index 8778981..f34758e 100644 --- a/src/classinfo.cpp +++ b/src/classinfo.cpp @@ -164,6 +164,13 @@ void _ClassInfo::initialize(TSRMLS_DC) } /** + * set access types flags for class + */ +void _ClassInfo::seFlags(struct _zend_class_entry *entry, int flags) { + entry->ce_flags |= flags; +} + +/** * End of namespace */ } diff --git a/src/doublemember.h b/src/doublemember.h index e3b75eb..7c5e431 100644 --- a/src/doublemember.h +++ b/src/doublemember.h @@ -29,7 +29,7 @@ public: * Constructor * @param value */ - DoubleMember(bool value) : MemberInfo(), _value(value) {} + DoubleMember(double value) : MemberInfo(), _value(value) {} /** * Destructor @@ -57,6 +57,23 @@ public: zend_declare_property_double(entry, (char *)name, size, _value, flags); #endif } + + /** + * Virtual method to declare the class constant + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) + { +#if PHP_VERSION_ID >= 50400 + zend_declare_class_constant_double(entry, name, size, _value); +#else + zend_declare_class_constant_double(entry, (char *)name, size, _value); +#endif + } + }; /** diff --git a/src/flag.cpp b/src/flag.cpp new file mode 100644 index 0000000..4f48ee9 --- /dev/null +++ b/src/flag.cpp @@ -0,0 +1,114 @@ +/** + * flag.cpp + * + * flag clases for the safe transfer of a Zend flag to a Zend functions + * flags defined at Zend/zend_compile.h + * + * @author Valeriy_Dmitriev <ufabiz@gmail.com> + */ + +#include "includes.h" + +/** + * Namespace Php + */ +namespace Php { + + + /** + * Constructor + * @param flags instance of Zend::AccClass + */ + template <> + FlagClass::FlagTemplate(const Zend::AccClass &zflag) { + /** + * access types for classes + * (method flags) + */ + switch(zflag){ + // if a class no have specified flags + case Zend::AccClass::NOSET: + _val = 0; + break; + //ZEND_ACC_EXPLICIT_ABSTRACT_CLASS denotes that a class was explicitly defined as abstract by using the keyword. + case Zend::AccClass::ABSTRACT: + _val = ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; //0x20; + break; + case Zend::AccClass::FINAL: + _val = ZEND_ACC_FINAL_CLASS; //0x40; + break; + case Zend::AccClass::INTERFACE: + _val = ZEND_ACC_INTERFACE; //0x80; + break; + case Zend::AccClass::TRAIT: + _val = ZEND_ACC_TRAIT; //0x120; + break; + default: + _val = 0; + } + } + + /** + * Constructor + * @param flags instance of Zend::AccMemb + */ + template <> + FlagMemb::FlagTemplate(const Zend::AccMemb &zflag) { + /** + * access types for methods and propertyes (members) + * (class flags) + */ + switch(zflag){ + // method flags (visibility) + // The order of those must be kept - public < protected < private + case Zend::AccMemb::PUBLIC: + _val = ZEND_ACC_PUBLIC; //0x100 + break; + case Zend::AccMemb::PROTECTED: + _val = ZEND_ACC_PROTECTED; //0x200 + break; + case Zend::AccMemb::PRIVATE: + _val = ZEND_ACC_PRIVATE; //0x400 + break; + case Zend::AccMemb::PPP_MASK: + _val = ZEND_ACC_PPP_MASK; //(ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE) + break; + + case Zend::AccMemb::STATIC: + //_val = ZEND_ACC_STATIC; //0x01 + //_val = ZEND_ACC_ALLOW_STATIC | ZEND_ACC_PUBLIC; + _val = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC; + break; + + // Artificially entered field + case Zend::AccMemb::CONSTANT: + _val = 0; //0 + break; + + case Zend::AccMemb::ABSTRACT: + _val = ZEND_ACC_ABSTRACT; //0x02 + break; + case Zend::AccMemb::FINAL: + _val = ZEND_ACC_FINAL; //0x04 + break; + + default: + _val = ZEND_ACC_PUBLIC; + } + } + + + /** + * factory function + */ + FlagClass Flag(const Zend::AccClass &zflag) { + return FlagClass(zflag); + } + FlagMemb Flag(const Zend::AccMemb &zflag) { + return FlagMemb(zflag); + } + +/** + * End of namespace Php + */ +} diff --git a/src/function.cpp b/src/function.cpp index 376b453..3fa5fe6 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -101,7 +101,7 @@ Function::~Function() * @param classname Optional class name * @param pub Is this a public property? */ -void Function::fill(zend_function_entry *entry, const char *classname, bool pub) const +void Function::fill(zend_function_entry *entry, const char *classname, int flags) const { // fill the members of the entity, and hide a pointer to the current object in the name entry->fname = _ptr; @@ -110,7 +110,8 @@ void Function::fill(zend_function_entry *entry, const char *classname, bool pub) entry->num_args = _argc; // there are no flags like deprecated, private or protected - entry->flags = classname ? (pub ? ZEND_ACC_PUBLIC : ZEND_ACC_PROTECTED) : 0; + entry->flags = classname ? flags : 0; + // we should fill the first argument as well #if PHP_VERSION_ID >= 50400 diff --git a/src/includes.h b/src/includes.h index a0f883a..4492252 100644 --- a/src/includes.h +++ b/src/includes.h @@ -19,11 +19,21 @@ #include <set> #include <exception> + // for debug +#include <iostream> + +/** + * @todo: if ZTS defined very many errors. need debug. + */ +//#define ZTS 1 + /** * PHP includes */ #include <php.h> #include "zend_exceptions.h" +#include "zend_interfaces.h" + /** * Macro to convert results to success status */ @@ -32,6 +42,8 @@ /** * Include other files from this library */ +#include "../include/zend.h" +#include "../include/flag.h" #include "../include/type.h" #include "../include/value.h" #include "../include/array.h" @@ -48,8 +60,7 @@ #include "../include/base.h" #include "../include/method.h" #include "../include/member.h" -#include "../include/public.h" -#include "../include/protected.h" +#include "../include/membervisibility.h" #include "../include/members.h" #include "../include/class.h" #include "../include/classinfo.h" diff --git a/src/longmember.h b/src/longmember.h index b35c316..4adf59b 100644 --- a/src/longmember.h +++ b/src/longmember.h @@ -51,12 +51,28 @@ public: */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) { -#if PHP_VERSION_ID >= 50400 +#if PHP_VERSION_ID >= 50400 zend_declare_property_long(entry, name, size, _value, flags); #else zend_declare_property_long(entry, (char *) name, size, _value, flags); #endif } + + /** + * Virtual method to declare the class constant + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) + { +#if PHP_VERSION_ID >= 50400 + zend_declare_class_constant_long(entry, name, size, _value); +#else + zend_declare_class_constant_long(entry, (char *) name, size, _value); +#endif + } }; /** diff --git a/src/member.cpp b/src/member.cpp index d4f5d2d..70dec9f 100644 --- a/src/member.cpp +++ b/src/member.cpp @@ -16,9 +16,9 @@ namespace Php { /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) */ -Member::Member(const char *name, bool pub) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags) : _name(name), _accflag(flags) { // create a null member _info = new NullMember(); @@ -27,10 +27,10 @@ Member::Member(const char *name, bool pub) : _name(name), _public(pub) /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, std::nullptr_t value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, std::nullptr_t value) : _name(name), _accflag(flags) { // create a null member _info = new NullMember(); @@ -39,10 +39,10 @@ Member::Member(const char *name, bool pub, std::nullptr_t value) : _name(name), /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, int value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, int value) : _name(name), _accflag(flags) { // create a long member _info = new LongMember(value); @@ -51,10 +51,10 @@ Member::Member(const char *name, bool pub, int value) : _name(name), _public(pub /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, long value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, long value) : _name(name), _accflag(flags) { // create a long member _info = new LongMember(value); @@ -63,10 +63,10 @@ Member::Member(const char *name, bool pub, long value) : _name(name), _public(pu /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, bool value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, bool value) : _name(name), _accflag(flags) { // create a bool member _info = new BoolMember(value); @@ -75,10 +75,10 @@ Member::Member(const char *name, bool pub, bool value) : _name(name), _public(pu /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, char value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, char value) : _name(name), _accflag(flags) { // create a new string member _info = new StringMember(&value, 1); @@ -87,10 +87,10 @@ Member::Member(const char *name, bool pub, char value) : _name(name), _public(pu /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, const std::string &value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, const std::string &value) : _name(name), _accflag(flags) { // create a new string member _info = new StringMember(value); @@ -99,11 +99,11 @@ Member::Member(const char *name, bool pub, const std::string &value) : _name(nam /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add * @param size String length */ -Member::Member(const char *name, bool pub, const char *value, int size) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, const char *value, int size) : _name(name), _accflag(flags) { // create a new string member if (size < 0) size = strlen(value); @@ -113,10 +113,10 @@ Member::Member(const char *name, bool pub, const char *value, int size) : _name( /** * Constructor * @param name Name of the member - * @param pub Is this a public property (otherwise it is protected) + * @param flags Flag access to a class member (bublic, protected etc) * @param value The value to add */ -Member::Member(const char *name, bool pub, double value) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, double value) : _name(name), _accflag(flags) { // create a new double member _info = new DoubleMember(value); @@ -128,8 +128,12 @@ Member::Member(const char *name, bool pub, double value) : _name(name), _public( * @param pub Is this a public method (otherwise it is protected) * @param method The method to add */ -Member::Member(const char *name, bool pub, const _Method &method, const std::initializer_list<Argument> &arguments) : _name(name), _public(pub) +Member::Member(const char *name, const FlagMemb &&flags, const _Method &method, const std::initializer_list<Argument> &arguments) : _name(name), _accflag(flags) { + // If the flags specifies as Zend::AccMemb::CONSTANT. + // That is: if( flags == Flag(Zend::AccMemb::CONSTANT) ) ... + //XXX Flag(Zend::AccMemb::PUBLIC) -> Flag(Zend::AccMemb::STATIC) + if(!flags) _accflag = Flag(Zend::AccMemb::PUBLIC); // create method member _info = new MethodMember(name, method, arguments); } @@ -138,12 +142,12 @@ Member::Member(const char *name, bool pub, const _Method &method, const std::ini * Copy constructor * @param member The member to copy */ -Member::Member(const Member &member) +Member::Member(const Member &member) : _accflag(member._accflag) { // copy info object, and name and public members _info = member._info; _name = member._name; - _public = member._public; + //_accflag = member._accflag; // update refcount in info object _info->refcount(+1); @@ -153,12 +157,12 @@ Member::Member(const Member &member) * Move constructor * @param member The member to move */ -Member::Member(Member &&member) +Member::Member(Member &&member) : _accflag (std::move(member._accflag)) { // move info object, and name and public properties _info = member._info; _name = std::move(member._name); - _public = member._public; + //_accflag = std::move(member._accflag); // reset info in other object member._info = NULL; @@ -201,7 +205,10 @@ bool Member::isMethod() void Member::declare(struct _zend_class_entry *entry) { // let the info object handle stuff - _info->declare(entry, _name.c_str(), _name.size(), _public ? ZEND_ACC_PUBLIC : ZEND_ACC_PROTECTED TSRMLS_CC); + if(!_accflag) // That is: if( flags == Flag(Zend::AccMemb::CONSTANT) ) + _info->declareConst(entry, _name.c_str(), _name.size() TSRMLS_CC); + else + _info->declare(entry, _name.c_str(), _name.size(), _accflag TSRMLS_CC); } /** @@ -213,7 +220,7 @@ void Member::declare(struct _zend_class_entry *entry) void Member::fill(struct _zend_function_entry *entry, const char *classname) { // let the info object do this - _info->fill(entry, classname, _public); + _info->fill(entry, classname, _accflag); } /** diff --git a/src/memberinfo.h b/src/memberinfo.h index 040f0de..1c4b59d 100644 --- a/src/memberinfo.h +++ b/src/memberinfo.h @@ -68,14 +68,23 @@ public: * @param flags Additional flags */ virtual void declare(struct _zend_class_entry *entry, const char *name, int size, int flags) {}; + + /** + * Virtual method to declare the constant property + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) {}; /** * Fill a function entry object * @param entry Function entry * @param classname Name of the class - * @param pub Is this a public method? + * @param flags Is this a public method? */ - virtual void fill(struct _zend_function_entry *entry, const char *classname, bool pub) {}; + virtual void fill(struct _zend_function_entry *entry, const char *classname, int flags) {}; }; diff --git a/src/methodmember.h b/src/methodmember.h index 9d4bcd1..67b4dad 100644 --- a/src/methodmember.h +++ b/src/methodmember.h @@ -43,10 +43,10 @@ public: * @param classname Name of the class * @param pub Is this a public entry */ - virtual void fill(struct _zend_function_entry *entry, const char *classname, bool pub) + virtual void fill(struct _zend_function_entry *entry, const char *classname, int flags) { // call function object - Function::fill(entry, classname, pub); + Function::fill(entry, classname, flags); } /** diff --git a/src/nullmember.h b/src/nullmember.h index 3fdb6b3..e5fdd62 100644 --- a/src/nullmember.h +++ b/src/nullmember.h @@ -49,6 +49,22 @@ public: zend_declare_property_null(entry, (char *) name, size, flags); #endif } + + /** + * Virtual method to declare the class constant + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) + { +#if PHP_VERSION_ID >= 50400 + zend_declare_class_constant_null(entry, name, size); +#else + zend_declare_class_constant_null(entry, (char *) name, size); +#endif + }; }; /** diff --git a/src/stringmember.h b/src/stringmember.h index d5af4a5..d6ac6ea 100644 --- a/src/stringmember.h +++ b/src/stringmember.h @@ -64,6 +64,22 @@ public: zend_declare_property_stringl(entry, (char*) name, size, (char *) _value.c_str(), _value.size(), flags); #endif } + + /** + * Virtual method to declare the class constant + * @param entry Class entry + * @param name Name of the member + * @param size Size of the name + * @param flags Additional flags + */ + virtual void declareConst(struct _zend_class_entry *entry, const char *name, int size) + { +#if PHP_VERSION_ID >= 50400 + zend_declare_class_constant_stringl(entry, name, size, _value.c_str(), _value.size()); +#else + zend_declare_class_constant_stringl(entry, (char*) name, size, (char *) _value.c_str(), _value.size()); +#endif + } }; /** |