diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arginfo.h | 10 | ||||
-rw-r--r-- | src/argument.cpp | 14 | ||||
-rw-r--r-- | src/arguments.cpp | 41 | ||||
-rw-r--r-- | src/callable.cpp | 42 | ||||
-rw-r--r-- | src/includes.h | 1 | ||||
-rw-r--r-- | src/value.cpp | 8 |
6 files changed, 112 insertions, 4 deletions
diff --git a/src/arginfo.h b/src/arginfo.h index 8ed00c8..0080667 100644 --- a/src/arginfo.h +++ b/src/arginfo.h @@ -31,11 +31,19 @@ public: /** * Constructor if this argument can be anything * @param name Name of the argument - * @param type Type hint + * @param type Type hint (arrayType or callableType) * @param ref Is this a pass-by-reference argument? */ ArgInfo(const std::string &name, Type type = nullType, bool ref = false) : _name(name), _type(type), _null(false), _ref(ref) {} + + /** + * Constructor if this argument can be anything + * @param name Name of the argument + * @param ref Is this a pass-by-reference argument? + */ + ArgInfo(const std::string &name, bool ref = false) : + _name(name), _type(nullType), _null(false), _ref(ref) {} /** * Destructor diff --git a/src/argument.cpp b/src/argument.cpp index 153da9c..fc9d720 100644 --- a/src/argument.cpp +++ b/src/argument.cpp @@ -28,8 +28,9 @@ Argument::Argument(const std::string &name, const std::string &classname, bool n /** * Constructor if the argument can be anything + * Note that only arrayType and callableType are supported type-hints * @param name Name of the argument - * @param type Type hint + * @param type Type hint (arrayType or callableType) * @param ref Is this a pass-by-reference argument? */ Argument::Argument(const std::string &name, Type type, bool ref) @@ -39,6 +40,17 @@ Argument::Argument(const std::string &name, Type type, bool ref) } /** + * Constructor if the argument can be anything + * @param name Name of the argument + * @param ref Is this a pass-by-reference argument? + */ +Argument::Argument(const std::string &name, bool ref) +{ + _refcount = new int[1]; + _info = new ArgInfo(name, ref); +} + +/** * Clean up the object */ void Argument::cleanup() diff --git a/src/arguments.cpp b/src/arguments.cpp new file mode 100644 index 0000000..e5e7ae5 --- /dev/null +++ b/src/arguments.cpp @@ -0,0 +1,41 @@ +/** + * Arguments.cpp + * + * Implementation of the arguments class + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2013 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace PhpCpp { + +/** + * Constructor + * @param argc Number of arguments + * @param tsrm_ls + */ +Arguments::Arguments(int argc TSRMLS_DC) +{ + // reserve plenty of space + reserve(argc); + + // loop through the arguments + for (int i=0; i<argc; i++) + { + // get the argument + zval **arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (argc-i)); + + // append value + push_back(Value(*arg)); + } +} + +/** + * End of namespace + */ +} + diff --git a/src/callable.cpp b/src/callable.cpp index 494e9ed..b4b1a6e 100644 --- a/src/callable.cpp +++ b/src/callable.cpp @@ -104,6 +104,13 @@ void Callable::process(const std::initializer_list<Argument> &arguments) } } +int do_test(int a, int b) +{ + std::cout << "do_test: " << a << " " << b << std::endl; + + return 77; +} + /** * Invoke the method * @param ht @@ -116,11 +123,46 @@ void Callable::process(const std::initializer_list<Argument> &arguments) */ int Callable::invoke(INTERNAL_FUNCTION_PARAMETERS) { + std::cout << "args: " << ZEND_NUM_ARGS() << std::endl; + std::cout << "required: " << _required << std::endl; + std::cout << "argc: " << _argc << std::endl; + + // number of arguments should be sufficient // @todo show error message +// if (ZEND_NUM_ARGS() < _required) return FAILURE; + // and not be too much // @todo show error message +// if (ZEND_NUM_ARGS() > _argc) return FAILURE; + // number of arguments on the stack + int arg_count = (int)(zend_uintptr_t) *(zend_vm_stack_top(TSRMLS_C) - 1); + // loop through the arguments + Arguments args(ZEND_NUM_ARGS()); + + for (auto iter = args.begin(); iter != args.end(); iter++) + { + Value val = *iter; + + val = 1234; + + std::cout << "argument: " << iter->stringValue() << std::endl; + } + + int result = do_test(args[1], args[2]); + + return SUCCESS; + + Value ret(return_value, true); + + ret = result; + + // done + return SUCCESS; } + + + /** * End of namespace */ diff --git a/src/includes.h b/src/includes.h index ae98c43..37b8b1b 100644 --- a/src/includes.h +++ b/src/includes.h @@ -35,6 +35,7 @@ #include "../include/request.h" #include "../include/argument.h" #include "../include/value.h" +#include "../include/arguments.h" #include "../include/function.h" #include "../include/extension.h" diff --git a/src/value.cpp b/src/value.cpp index 6ba67a4..3c84d9c 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -87,15 +87,19 @@ Value::Value(double value) /** * Wrap object around zval - * @param zval + * @param zval Value to wrap + * @param ref Force this to be a reference */ -Value::Value(struct _zval_struct *zval) +Value::Value(struct _zval_struct *zval, bool ref) { // just copy the zval into this object _val = zval; // we see ourselves as reference too Z_ADDREF_P(_val); + + // should this be a forced reference + if (ref) Z_SET_ISREF_P(zval); } /** |