diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-04-05 18:17:09 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-04-05 18:17:09 +0200 |
commit | 5d84ff5483f2db57762311714ff3c779db1e0f96 (patch) | |
tree | 0691e7395a292b152af3525b1e65a11b15bad46f | |
parent | 5973954b7428aa95ec8f0b2424b5725d2815049f (diff) |
removed zend code from the argument.h header file
-rw-r--r-- | Makefile | 50 | ||||
-rw-r--r-- | include/argument.h | 111 | ||||
-rw-r--r-- | src/argument.cpp | 171 | ||||
-rw-r--r-- | src/callable.h | 50 |
4 files changed, 161 insertions, 221 deletions
@@ -55,7 +55,8 @@ INSTALL_LIB = ${INSTALL_PREFIX}/lib # you can change that here. # -LIBRARY = libphpcpp.so +PHP_LIBRARY = libphpcpp.so +HHVM_LIBRARY = libhhvmcpp.so # @@ -84,7 +85,9 @@ LINKER = g++ # you want to leave that flag out on production servers). # -COMPILER_FLAGS = -Wall -c `php-config --includes` -g -std=c++11 -fpic -o +COMPILER_FLAGS = -Wall -c -g -std=c++11 -fpic +PHP_COMPILER_FLAGS = ${COMPILER_FLAGS} `php-config --includes` +HHVM_COMPILER_FLAGS = ${COMPILER_FLAGS} # # Linker flags @@ -96,7 +99,9 @@ COMPILER_FLAGS = -Wall -c `php-config --includes` -g -std=c++11 -fpic -o # to the linker flags # -LINKER_FLAGS = -shared `php-config --ldflags` +LINKER_FLAGS = -shared +PHP_LINKER_FLAGS = ${LINKER_FLAGS} `php-config --ldflags` +HHVM_LINKER_FLAGS = ${LINKER_FLAGS} # @@ -118,19 +123,22 @@ MKDIR = mkdir -p # src/ directory for all *.cpp files. No changes are probably necessary here # -LIBRARY_SOURCES = $(wildcard src/*.cpp) - +SOURCES = $(wildcard src/*.cpp) +PHP_SOURCES = $(wildcard src/zend/*.cpp) +HHVM_SOURCES = $(wildcard src/hhvm/*.cpp) # # The object files # # The intermediate object files are generated by the compiler right before -# the linker turns all these object files into the libphpcpp.so shared library. -# We also use a Makefile function here that takes all source files. +# the linker turns all these object files into the libphpcpp.so and +# libhhvmcpp.so shared libraries. We also use a Makefile function here that +# takes all source files. # -LIBRARY_OBJECTS = $(LIBRARY_SOURCES:%.cpp=%.o) - +OBJECTS = $(SOURCES:%.cpp=%.o) +PHP_OBJECTS = $(PHP_SOURCES:%.cpp=%.o) +HHVM_OBJECTS = $(HHVM_SOURCES:%.cpp=%.o) # # Configuration program @@ -149,25 +157,35 @@ CONFIG_FLAGS = `php-config --includes` -o # dependencies that are used by the compiler. # -all: ${LIBRARY_OBJECTS} ${LIBRARY} ${CONFIG_UTILITY} +all: ${PHP_LIBRARY} ${CONFIG_UTILITY} + +${PHP_LIBRARY}: ${OBJECTS} ${PHP_OBJECTS} + ${LINKER} ${PHP_LINKER_FLAGS} -o $@ ${OBJECTS} ${PHP_OBJECTS} -${LIBRARY}: ${LIBRARY_OBJECTS} - ${LINKER} ${LINKER_FLAGS} -o $@ ${LIBRARY_OBJECTS} +${HHVM_LIBRARY}: ${OBJECTS} ${HHVM_OBJECTS} + ${LINKER} ${HHVM_LINKER_FLAGS} -o $@ ${OBJECTS} ${HHVM_OBJECTS} ${CONFIG_UTILITY}: ${COMPILER} ${CONFIG_FLAGS} $@ ${CONFIG_SOURCES} clean: - ${RM} ${LIBRARY_OBJECTS} ${LIBRARY} ${CONFIG_UTILITY} + ${RM} ${OBJECTS} ${PHP_OBJECTS} ${HHVM_OBJECTS} ${PHP_LIBRARY} ${HHVM_LIBRARY} ${CONFIG_UTILITY} + +${OBJECTS}: + ${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} + +${PHP_OBJECTS}: + ${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} -${LIBRARY_OBJECTS}: - ${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp} +${HHVM_OBJECTS}: + ${COMPILER} ${HHVM_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} install: ${MKDIR} ${INSTALL_HEADERS}/phpcpp ${CP} phpcpp.h ${INSTALL_HEADERS} ${CP} include/*.h ${INSTALL_HEADERS}/phpcpp - ${CP} ${LIBRARY} ${INSTALL_LIB} + ${CP} ${PHP_LIBRARY} ${INSTALL_LIB} + ${CP} ${HHVM_LIBRARY} ${INSTALL_LIB} ${CONFIG_UTILITY} > ${INSTALL_HEADERS}/phpcpp/config.h test: diff --git a/include/argument.h b/include/argument.h index 68ac7df..81b1bf4 100644 --- a/include/argument.h +++ b/include/argument.h @@ -8,15 +8,10 @@ * classes instead. * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV + * @copyright 2013, 2014 Copernica BV */ /** - * Forward declaration - */ -struct _zend_arg_info; - -/** * Set up namespace */ namespace Php { @@ -28,21 +23,9 @@ class Argument { public: /** - * Copy constructor - * @param argument - */ - Argument(const Argument &argument); - - /** - * Move constructor - * @param argument - */ - Argument(Argument &&argument); - - /** * Destructor */ - virtual ~Argument(); + virtual ~Argument() {} protected: /** @@ -52,7 +35,8 @@ protected: * @param required Is this argument required? * @param byref Is this a reference argument */ - Argument(const char *name, Type type, bool required = true, bool byref = false); + Argument(const char *name, Type type, bool required = true, bool byref = false) : + _name(name), _type(type), _required(required), _byReference(byref) {} /** * Constructor @@ -62,17 +46,11 @@ protected: * @param required Is this argument required? * @param byref Is this a reference argument? */ - Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false); + Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false) : + _name(name), _type(Type::Object), _classname(classname), _nullable(nullable), _required(required), _byReference(byref) {} public: /** - * Fill an arg_info structure with data - * @param info - * @internal - */ - void fill(struct _zend_arg_info *info) const; - - /** * Is this a required argument? * @return bool * @internal @@ -81,19 +59,88 @@ public: { return _required; } - + + /** + * Name of the argument + * @return std::string + */ + const std::string &name() const + { + return _name; + } + + /** + * Type-hint for the argument + * @return Type + */ + Type type() const + { + return _type; + } + + /** + * If the type is a class, the name of the class + * @return std::string + */ + const std::string &classname() const + { + return _classname; + } + + /** + * Is it allowed to pass parameter with a null value? + * @return bool + */ + bool allowNull() const + { + return _nullable; + } + + /** + * Is this a parameter-by-reference? + * @return bool + */ + bool byReference() const + { + return _byReference; + } + private: /** - * The argument info - * @var zend_arg_info + * Name of the argument + * @var std::string */ - struct _zend_arg_info *_info; + std::string _name; /** + * Type of argument + * @var Type + */ + Type _type; + + /** + * Classname, if this is a parameter that is supposed to be an instance of a class + * @var std::string + */ + std::string _classname; + + /** + * May the parameter be null? + * @var bool + */ + bool _nullable; + + /** * Is this a required argument * @var bool */ bool _required; + + /** + * Is this a 'by-reference' parameter? + * @var bool + */ + bool _byReference; }; /** diff --git a/src/argument.cpp b/src/argument.cpp deleted file mode 100644 index a2aa8d5..0000000 --- a/src/argument.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/** - * Argument.cpp - * - * Implementation for the Argument class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - */ -#include "includes.h" - -/** - * Set up namespace - */ -namespace Php { - -/** - * Constructor - * @param name Name of the argument - * @param type Argument type - * @param required Is this argument required? - * @param byref Is this a reference argument - */ -Argument::Argument(const char *name, Type type, bool required, bool byref) -{ - // construct object - _info = new zend_arg_info; - - // fill members - _info->name = name; - _info->name_len = strlen(name); - -#if PHP_VERSION_ID >= 50400 - - // since php 5.4 there is a type-hint - _info->type_hint = (unsigned char)(type == Type::Array || type == Type::Callable ? type : Type::Null); - -# if PHP_VERSION_ID >= 50600 - - // from PHP 5.6 and onwards, an is_variadic property can be set, this - // specifies whether this argument is the first argument that specifies - // the type for a variable length list of arguments. For now we only - // support methods and functions with a fixed number of arguments. - _info->is_variadic = false; - -# endif - -#else - - // php 5.3 code - _info->array_type_hint = type == Type::Array; - _info->return_reference = false; - _info->required_num_args = 0; // @todo is this correct? - -#endif - - // this parameter is a regular type - _info->class_name = NULL; - _info->class_name_len = 0; - _info->allow_null = false; - _info->pass_by_reference = byref; - - // store if required - _required = required; -} - -/** - * Constructor - * @param name Name of the argument - * @param classname Name of the class - * @param nullable Can it be null? - * @param required Is this argument required? - * @param byref Is this a reference argument? - */ -Argument::Argument(const char *name, const char *classname, bool nullable, bool required, bool byref) -{ - // construct object - _info = new zend_arg_info; - - // fill members - _info->name = name; - _info->name_len = strlen(name); - -#if PHP_VERSION_ID >= 50400 - - // since php 5.4 there is a type hint - _info->type_hint = (unsigned char)Type::Object; - -# if PHP_VERSION_ID >= 50600 - - // from PHP 5.6 and onwards, an is_variadic property can be set, this - // specifies whether this argument is the first argument that specifies - // the type for a variable length list of arguments. For now we only - // support methods and functions with a fixed number of arguments. - _info->is_variadic = false; - -# endif - -#else - - // php 5.3 code - _info->array_type_hint = false; - _info->return_reference = false; - _info->required_num_args = 0; // @todo is this correct? - -#endif - - // the parameter is a class - _info->class_name = classname; - _info->class_name_len = strlen(classname); - _info->allow_null = nullable; - _info->pass_by_reference = byref; - - // store if required - _required = required; -} - -/** - * Copy constructor - * @param argument - */ -Argument::Argument(const Argument &argument) -{ - // construct object - _info = new zend_arg_info; - - // fill members - *_info = *argument._info; - - // store if required - _required = argument._required; -} - -/** - * Move constructor - * @param argument - */ -Argument::Argument(Argument &&argument) -{ - // copy memory pointer - _info = argument._info; - - // forget in other object - argument._info = nullptr; - - // store if required - _required = argument._required; -} - -/** - * Destructor - */ -Argument::~Argument() -{ - if (_info) delete _info; -} - -/** - * Fill an arg_info structure with data - * @param info - * @internal - */ -void Argument::fill(struct _zend_arg_info *info) const -{ - // copy all data - *info = *_info; -} - -/** - * End of namespace - */ -} diff --git a/src/callable.h b/src/callable.h index f123c8b..aef5649 100644 --- a/src/callable.h +++ b/src/callable.h @@ -43,11 +43,11 @@ public: // loop through the arguments for (auto it = arguments.begin(); it != arguments.end(); it++) { - // increment required + // increment counter with number of required parameters if (it->required()) _required++; // fill the arg info - it->fill(&_argv[i++]); + fill(&_argv[i], *it); } } @@ -140,7 +140,53 @@ protected: * @var zend_arg_info[] */ struct _zend_arg_info *_argv = nullptr; + + /** + * Private helper method to fill an argument object + * @param info object from the zend engine + * @param arg original object + */ + void fill(zend_arg_info *info, const Argument &arg) const + { + // fill members + info->name = arg.name().c_str(); + info->name_len = arg.name().size(); + +#if PHP_VERSION_ID >= 50400 + + // since php 5.4 there is a type-hint, but we only support arrays, objects and callables + switch (arg.type()) { + case Type::Array: info->type_hint = IS_ARRAY; break; + case Type::Callable: info->type_hint = IS_CALLABLE; break; + case Type::Object: info->type_hint = IS_OBJECT; break; + default: info->type_hint = IS_NULL; break; + } + +# if PHP_VERSION_ID >= 50600 + + // from PHP 5.6 and onwards, an is_variadic property can be set, this + // specifies whether this argument is the first argument that specifies + // the type for a variable length list of arguments. For now we only + // support methods and functions with a fixed number of arguments. + info->is_variadic = false; + +# endif + +#else + // php 5.3 code + info->array_type_hint = type == Type::Array; + info->return_reference = false; + info->required_num_args = 0; // @todo is this correct? + +#endif + + // this parameter is a regular type + info->class_name = arg.type() == Type::Object ? arg.classname().c_str() : nullptr; + info->class_name_len = arg.type() == Type::Object ? arg.classname().size() : 0; + info->allow_null = arg.allowNull(); + info->pass_by_reference = arg.byReference(); + } }; /** |