mirror of
https://github.com/php/php-src.git
synced 2026-04-21 23:18:13 +02:00
d64c9d2823
- Add a test if argument was given (if it is optional) before trying to fetch a resource and a note that something should be done if it wasn't. - Some cosmetic fixes in the code generated. - Some other small fixes in the code generated, already forgotten.
182 lines
4.7 KiB
Awk
Executable File
182 lines
4.7 KiB
Awk
Executable File
#!/usr/bin/awk -f
|
|
|
|
function gobble(s, x)
|
|
{
|
|
sub(/^ /, "", line)
|
|
match(line, "^" "(" s ")")
|
|
x = substr(line, 1, RLENGTH)
|
|
line = substr(line, RLENGTH+1)
|
|
return x
|
|
}
|
|
|
|
function convert(i, j)
|
|
{
|
|
type = argtypes[i,j]
|
|
name = argnames[i,j]
|
|
opt = optionals[i,j]
|
|
x = ""
|
|
|
|
if (type == "int") {
|
|
x = "convert_to_long_ex(" name ");\n"
|
|
} else if (type == "double") {
|
|
x = "convert_to_double_ex(" name ");\n"
|
|
} else if (type == "string") {
|
|
x = "convert_to_string_ex(" name ");\n"
|
|
} else if (type == "array") {
|
|
x = "convert_to_array_ex(" name ");\n"
|
|
} else if (type == "resource") {
|
|
if (opt && i) {
|
|
resources = resources "\tif (argc < " j+1 ") {\n\t\t/* Argument not given, do something before\n\t\t trying to fetch resource " name ". */\n\t}\n\tZEND_FETCH_RESOURCE(???, ???, " name ", " name "_id, \"???\", ???G());\n"
|
|
} else {
|
|
resources = resources "\tZEND_FETCH_RESOURCE(???, ???, " name ", " name "_id, \"???\", ???G());\n"
|
|
}
|
|
funcvals = funcvals "\tint " name "_id = -1;\n"
|
|
} else {
|
|
x = "/* Write your own code here to handle argument " name ". */\n"
|
|
}
|
|
|
|
if (x) return x
|
|
}
|
|
|
|
BEGIN {
|
|
name = "[_A-Za-z][_A-Za-z0-9]*"
|
|
type = "int|double|string|bool|array|object|resource|mixed|void"
|
|
num_funcs = 0
|
|
}
|
|
|
|
{
|
|
args_max = args_min = optional = i = 0
|
|
line = $0
|
|
|
|
func_type = gobble(type);
|
|
func_name = gobble(name);
|
|
|
|
if (gobble("\\(")) {
|
|
if (gobble("\\[")) optional = 1
|
|
while (arg_type = gobble(type)) {
|
|
arg_name = gobble(name)
|
|
argtypes[num_funcs,args_max] = arg_type
|
|
argnames[num_funcs,args_max] = arg_name
|
|
|
|
args_max++
|
|
if (optional) {
|
|
optionals[num_funcs,i] = optional
|
|
if (arg_type != "resource") {
|
|
useswitch[num_funcs] = 1
|
|
}
|
|
} else {
|
|
args_min++
|
|
}
|
|
|
|
if (x = gobble("\\[")) {
|
|
optional++
|
|
}
|
|
|
|
gobble(",")
|
|
i++
|
|
}
|
|
}
|
|
|
|
funcs[num_funcs] = func_name
|
|
types[num_funcs] = func_type
|
|
maxargs[num_funcs] = args_max
|
|
minargs[num_funcs] = args_min
|
|
|
|
num_funcs++
|
|
}
|
|
|
|
END {
|
|
for (i = 0; i < num_funcs; i++) {
|
|
|
|
compareargc = maxargs[i] - minargs[i]
|
|
funcvals = resources = handleargs = closeopts = ""
|
|
|
|
proto = "/* {{{ proto " types[i] " " funcs[i] "("
|
|
|
|
if (maxargs[i]) {
|
|
zvals = "\tzval "
|
|
if (compareargc) {
|
|
funcvals = "\tint argc;\n"
|
|
if (minargs[i]) {
|
|
fetchargs = "\targc = ZEND_NUM_ARGS();\n\tif (argc < " minargs[i] " || argc > " maxargs[i] " || zend_get_parameters_ex(argc, "
|
|
} else {
|
|
fetchargs = "\targc = ZEND_NUM_ARGS();\n\tif ((argc && argc < " maxargs[i]+1 " || zend_get_parameters_ex(argc, "
|
|
}
|
|
} else {
|
|
fetchargs = "\tif (ZEND_NUM_ARGS() != " maxargs[i] " || zend_get_parameters_ex(" maxargs[i] ", "
|
|
}
|
|
}
|
|
|
|
for (j = 0; j < maxargs[i]; j++) {
|
|
|
|
if (j) {
|
|
zvals = zvals ", "
|
|
fetchargs = fetchargs ", "
|
|
}
|
|
|
|
zvals = zvals "**" argnames[i,j]
|
|
fetchargs = fetchargs "&" argnames[i,j]
|
|
|
|
if (j > minargs[i]-1) {
|
|
if (j) proto = proto " "
|
|
proto = proto "["
|
|
closeopts = closeopts "]"
|
|
}
|
|
|
|
if (j > 0) proto = proto ", "
|
|
proto = proto argtypes[i,j] " " argnames[i,j]
|
|
|
|
code = convert(i, j)
|
|
|
|
if (useswitch[i]) {
|
|
if (j > minargs[i]-1) {
|
|
if (code) {
|
|
handleargs = "\t\tcase " j+1 ":\n\t\t\t" code "\t\t\t/* Fall-through. */\n" handleargs
|
|
} else {
|
|
handleargs = "\t\tcase " j+1 ":\t/* Fall-through. */\n" handleargs
|
|
}
|
|
} else if (j >= minargs[i]-1) {
|
|
if (code) {
|
|
handleargs = "\t\tcase " j+1 ":\n\t\t\t" code handleargs
|
|
} else {
|
|
handleargs = "\t\tcase " j+1 ":\n" handleargs
|
|
}
|
|
} else {
|
|
handleargs = "\t\t\t" code handleargs
|
|
}
|
|
} else {
|
|
if (code) handleargs = handleargs "\t" code
|
|
}
|
|
}
|
|
|
|
proto = proto closeopts ")\n */\nPHP_FUNCTION(" funcs[i] ")\n{"
|
|
if (maxargs[i]) {
|
|
zvals = zvals ";"
|
|
fetchargs = fetchargs ") == FAILURE) {\n\t\tWRONG_PARAM_COUNT;\n\t}\n"
|
|
}
|
|
if (resources ) funcvals = funcvals "\t???LS_FETCH();\n"
|
|
if (useswitch[i]) handleargs = "\tswitch (argc) {\n" handleargs "\t\t\tbreak;\n\t\tdefault:\n\t\t\tWRONG_PARAM_COUNT;\n\t}"
|
|
|
|
print proto > extname "/function_stubs"
|
|
if (zvals) print zvals > extname "/function_stubs"
|
|
if (funcvals) print funcvals > extname "/function_stubs"
|
|
if (fetchargs) print fetchargs > extname "/function_stubs"
|
|
if (resources) {
|
|
print resources > extname "/function_stubs"
|
|
print "" > extname "/function_warning"
|
|
}
|
|
if (handleargs) print handleargs > extname "/function_stubs"
|
|
print "\n\tphp_error(E_WARNING, \"" funcs[i] ": not yet implemented\");" > extname "/function_stubs"
|
|
print "}\n/* }}} */\n" > extname "/function_stubs"
|
|
print "PHP_FUNCTION(" funcs[i] ");" > extname "/function_declarations"
|
|
print "\tPHP_FE(" funcs[i] ",\tNULL)" > extname "/function_entries"
|
|
}
|
|
}
|
|
|
|
#
|
|
# Local variables:
|
|
# tab-width: 2
|
|
# c-basic-offset: 2
|
|
# End:
|
|
#
|