Commit Graph

286 Commits

Author SHA1 Message Date
Nikita Popov
ef9e003b0c Small cleanup in class name resolution of compiler
* The fetch_type and check_ns_name parameters of
   zend_resolve_class_name were unused and are now removed.
 * ZEND_FETCH_CLASS_GLOBAL is no longer used (no code actually
   checking for it).
 * The checks for usage of "namespace" as class name were
   unnecessary as that situation can't occur anyways.
2013-09-13 12:18:39 +02:00
Xinchen Hui
975d26667b Fixed bug #64503 (Compilation fails with error: conflicting types for 'zendparse'). 2013-03-25 23:48:21 +08:00
Lars Strojny
8991ed016f Class Name Resolution As Scalar Via "class" Keyword 2013-01-19 01:00:47 +01:00
Dmitry Stogov
c3ebd6305e Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4:
  Fixed compilator bug that might cause jump depended on unitialized value
2013-01-09 17:52:48 +04:00
Dmitry Stogov
625000ab44 Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3:
  Fixed compilator bug that might cause jump depended on unitialized value
2013-01-09 17:36:44 +04:00
Dmitry Stogov
d4650c5d69 Fixed compilator bug that might cause jump depended on unitialized value 2013-01-09 17:16:47 +04:00
Xinchen Hui
a666285bc2 Happy New Year 2013-01-01 16:37:09 +08:00
Xinchen Hui
0a7395e009 Happy New Year 2013-01-01 16:28:54 +08:00
Xinchen Hui
831fbcf385 Happy New Year 2013-01-01 16:23:31 +08:00
Dmitry Stogov
b8c719c068 Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4:
  Traits refactoring
2012-12-25 10:33:01 +04:00
Dmitry Stogov
3f8c729e69 Traits refactoring 2012-12-25 10:23:08 +04:00
Nikita Popov
2768315856 Add missing zend_do_free call
This is a followup to d53f1bf8ab. When the yield *statement* is used its
return value still needs to be freed.
2012-12-19 15:21:34 +01:00
Nikita Popov
d60e3c6ef5 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
Conflicts:
	Zend/zend_language_parser.y
	Zend/zend_vm_execute.skl
2012-08-26 13:03:55 +02:00
Nikita Popov
bd70d15588 Remove implementation stubs for yield delegation
I decided to leave out yield delegation for an initial proposal, so remove
the stubs for it too.
2012-08-25 19:03:23 +02:00
Xinchen Hui
35951d4be0 Support list in foreach
RFC: https://wiki.php.net/rfc/foreachlist
2012-08-25 22:23:57 +08:00
Nikita Popov
1823b16fa1 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
Merging master to fix Windows build

Conflicts:
	Zend/zend_language_scanner.c
	Zend/zend_language_scanner_defs.h
	Zend/zend_vm_def.h
2012-08-20 13:37:53 +02:00
Stanislav Malyshev
3336e1e78c Merge branch 'pull-request/31'
* pull-request/31:
  Fix lexing of nested heredoc strings in token_get_all()
2012-08-19 21:43:04 -07:00
Xinchen Hui
c64f4e736c Add functions declarations, use tabs 2012-08-14 08:59:40 +08:00
Nikita Popov
f4ce364628 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
This is just an intial merge. It does not yet make generators and finally
work together.

Conflicts:
	Zend/zend_language_scanner.c
	Zend/zend_language_scanner_defs.h
	Zend/zend_vm_def.h
	Zend/zend_vm_execute.h
	Zend/zend_vm_execute.skl
	Zend/zend_vm_opcodes.h
2012-08-13 16:54:53 +02:00
Xinchen Hui
80d5ae3cea Implemented 'finally' keywords for php
RFC: https://wiki.php.net/rfc/finally
FR: https://bugs.php.net/bug.php?id=32100
and I have got some improvment ideas(performance), will implemented
later. thanks
2012-08-13 21:48:39 +08:00
Xinchen Hui
ba568aaebb Fixed invalid read in CONST_STRING dereference, reported by Nikic 2012-07-26 00:29:39 +08:00
Nikita Popov
de80e3ce4b Remove reference restrictions from foreach
foreach only allowed variables to be traversed by reference. This never
really made sense because

    a) Expressions like array(&$a, &$b) can be meaningfully iterated by-ref
    b) Function calls can return by-ref (so they can also be meaningfully
       iterated)
    c) Iterators could at least in theory also be iterated by-ref (not
       sure if any iterator makes use of this)

With by-ref generators the restriction makes even less sense, so I removed
it altogether.
2012-07-22 14:33:25 +02:00
Nikita Popov
80748631aa Require parenthesis around yield expressions
If yield is used in an expression context parenthesis are now required.
This ensures that the code is unambiguos.

Yield statements can still be used without parenthesis (which should be
the most common case).

Also yield expressions without value can be used without parenthesis,
too (this should be the most common case for coroutines).

If the yield expression is used in a context where parenthesis are required
anyway, no additional parenthesis have to be inserted.

Examples:

    // Statements don't need parenthesis
    yield $foo;
    yield $foo => $bar;

    // Yield without value doesn't need parenthesis either
    $data = yield;

    // Parentheses don't have to be duplicated
    foo(yield $bar);
    if (yield $bar) { ... }

    // But we have to use parentheses here
    $foo = (yield $bar);

This commit also fixes an issue with by-ref passing of $foo[0] like
variables. They previously weren't properly fetched for write.

Additionally this fixes valgrind warnings which were caused by access to
uninitialized memory in zend_is_function_or_method_call().
2012-07-22 01:22:22 +02:00
Nikita Popov
c9709bfbd7 Remove asterix modifier (*) for generators
Generators are now automatically detected by the presence of a `yield`
expression in their body.

This removes the ZEND_SUSPEND_AND_RETURN_GENERATOR opcode. Instead
additional checks for ZEND_ACC_GENERATOR are added to the fcall_common
helper and zend_call_function.

This also adds a new function zend_generator_create_zval, which handles
the actual creation of the generator zval from an op array.

I feel like I should deglobalize the zend_create_execute_data_from_op_array
code a bit. It currently changes EG(current_execute_data) and
EG(opline_ptr) which is somewhat confusing (given the name).
2012-07-20 16:09:06 +02:00
Xinchen Hui
a027ba3afe Merge branch 'PHP-5.4'
* PHP-5.4:
  Fixed bug #62357 (compile failure: (S) Arguments missing for built-in function __memcmp).
2012-06-26 18:50:52 +08:00
Xinchen Hui
a44a1dc194 Fixed bug #62357 (compile failure: (S) Arguments missing for built-in function __memcmp).
Any C library function may be a macro, We should avoid using ZEND_STRS(L) as their arguments
2012-06-26 18:42:33 +08:00
Nikita Popov
d939d2dee5 Add sceleton for yield* expression
This does not yet actually implement any delegation.
2012-06-19 00:37:31 +02:00
Nikita Popov
bc08c2cf94 Add support for yielding keys
Keys are yielded using the

    yield $key => $value

syntax. Currently this is implemented as a statement only and not as an
expression, because conflicts arise considering nesting and use in arrays:

    yield yield $a => $b;
    // could be either
    yield (yield $a) => $b;
    // or
    yield (yield $a => $b);

Once I find some way to resolve these conflicts this should be available
as an expression too.

Also the key yielding code is rather copy-and-past-y for the value yielding
code, so that should be factored out.
2012-05-30 02:44:06 +02:00
Nikita Popov
ad525c288a Allow to use yield without value
If the generator is used as a coroutine it often doesn't make sense to yield
anything. In this case one can simply receive values using

    $value = yield;

The yield here will simply yield NULL.
2012-05-29 17:53:11 +02:00
Nikita Popov
3600914ced Add support for $generator->send()
Yield now is an expression and the return value is the value passed to
$generator->send(). By default (i.e. if ->next() is called) the value is
NULL.

Unlike in Python ->send() can be run without priming the generator with a
->next() call first.
2012-05-29 17:34:33 +02:00
Nikita Popov
e14cfafcbf Add zend_do_suspend_if_generator calls
The execution of generator functions will be suspended right after the
arguments were RECVed. This will be done in zend_do_suspend_if_generator.
2012-05-19 20:19:45 +02:00
Nikita Popov
252f623464 Add flag for generator functions
Generator functions have to specify the * (asterix) modifier after the
function keyword. If they do so the ZEND_ACC_GENERATOR flag is added to
the fn_flags.
2012-05-19 14:18:20 +02:00
Nikita Popov
9b101ac8b3 Add T_YIELD "yield" keyword 2012-05-15 18:30:48 +02:00
Nikita Popov
ec061a93c5 Allow arbitrary expressions for empty()
This change is as per RFC https://wiki.php.net/rfc/empty_isset_exprs.

The change allows passing the result of function calls and other
expressions to the empty() language construct. This is accomplished by
simply rewriting empty(expr) to !expr.

The change does not affect the suppression of errors when using empty()
on variables. empty($undefinedVar) will continue not to throw errors.
When an expression is used inside empty() on the other hand, errors will
not be suppressed. Thus empty($undefinedVar + $somethingElse) *will*
throw a notice.

The change also does not make empty() into a real function, so using
'empty' as a callback is still not possible.

In addition to the empty() changes the commit adds nicer error messages
when isset() is used on function call results or other expressions.
2012-05-13 14:56:51 +02:00
Xinchen Hui
565892d4c0 Implement const array/string dereference
RFC:https://wiki.php.net/rfc/constdereference
2012-04-17 10:06:17 +08:00
Nikita Popov
4cf90e06c9 Fix lexing of nested heredoc strings in token_get_all()
This fixes bug #60097.

Before two global variables CG(heredoc) and CG(heredoc_len) were used to
track the current heredoc label. In order to support nested heredoc
strings the *previous* heredoc label was assigned as the token value of
T_START_HEREDOC and the language_parser.y assigned that to CG(heredoc).

This created a dependency of the lexer on the parser. Thus the
token_get_all() function, which accesses the lexer directly without
also running the parser, was not able to tokenize nested heredoc strings
(and leaked memory). Same applies for the source-code highlighting
functions.

The new approach is to maintain a heredoc_label_stack in the lexer, which
contains all active heredoc labels.

As it is no longer required, T_START_HEREDOC and T_END_HEREDOC now don't
carry a token value anymore.

In order to make the work with zend_ptr_stack in this context more
convenient I added a new function zend_ptr_stack_top(), which retrieves the
top element of the stack (similar to zend_stack_top()).
2012-03-31 21:53:30 +02:00
Dmitry Stogov
b515bfbdfb Improved traits implementation. Now to support __CLASS__ constant in traits php doesn't have to copy the complete compiled method, but can reuse the same code. The resolution of __CLASS__ constants in methods defined in traits are delayed till run-time. This approach also made possible to use __CLASS__ constant as default value for traits properties and method arguments. 2012-01-17 08:09:13 +00:00
Dmitry Stogov
032d140fd6 Improved traits implementation. Now to support __CLASS__ constant in traits php doesn't have to copy the complete compiled method, but can reuse the same code. The resolution of __CLASS__ constants in methods defined in traits are delayed till run-time. This approach also made possible to use __CLASS__ constant as default value for traits properties and method arguments. 2012-01-17 08:09:13 +00:00
Felipe Pena
e4ca0ed09f - Year++ 2012-01-01 13:15:04 +00:00
Felipe Pena
8775a37559 - Year++ 2012-01-01 13:15:04 +00:00
Felipe Pena
4e19825281 - Year++ 2012-01-01 13:15:04 +00:00
Felipe Pena
eebaaf423f - Added class member access on instantiation (e.g. (new foo)->bar()) support 2011-11-06 13:25:45 +00:00
Felipe Pena
ff48763f4b - Added class member access on instantiation (e.g. (new foo)->bar()) support 2011-11-06 13:25:45 +00:00
Felipe Pena
8db63e8874 - Drop T_SCALAR_CAST 2011-08-16 12:13:35 +00:00
Felipe Pena
17abf879ed - Drop T_SCALAR_CAST 2011-08-16 12:13:35 +00:00
Hannes Magnusson
306c42023e Callable typehint following the rules of is_callable($arg, false); 2011-08-16 10:44:47 +00:00
Hannes Magnusson
550980cfe5 Callable typehint following the rules of is_callable($arg, false); 2011-08-16 10:44:47 +00:00
Dmitry Stogov
ad4d6d1ce3 Added support for Class::{expr}() syntax (Pierrick) 2011-08-01 12:08:44 +00:00
Dmitry Stogov
74f68932b7 Added support for Class::{expr}() syntax (Pierrick) 2011-08-01 12:08:44 +00:00
Stefan Marr
0158804a15 Added __TRAIT__ magic constant [TRAITS] [DOC]
# __TRAIT__ behaves like __CLASS__ more or less but is constraint to traits.
# Since traits are not types, there are not many valid use cases, and trying
# to use __TRAIT__ to make traits more like classes is discouraged.
2011-07-31 17:39:30 +00:00