Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop in phpfile causes rerunning run_ast #128

Open
pbiggar opened this issue Jun 3, 2015 · 6 comments
Open

Loop in phpfile causes rerunning run_ast #128

pbiggar opened this issue Jun 3, 2015 · 6 comments

Comments

@pbiggar
Copy link
Owner

pbiggar commented Jun 3, 2015

What steps will reproduce the problem?
1. Make a phc plugin which uses the visiter class

2. define function run_ast as described in manual:
extern "C" void run_ast (PHP_script* in, Pass_manager* pm, String* option)

3. build plugin and run on php file which uses a loop construct 

What is the expected output? What do you see instead?

The function run_ast should be executed only once, instead it is run once +
the number of loop constructs you have defined in your file.

For example if you have the following php code:

<php
while(true) {
}
?>

run_ast is executed twice, if you have:

<?php
while (true) {

}

foreach ($foo as $bar) {

}
?>

run_ast is executed three times.

However this seems only the case for a while/ do-while and foreach loop,
defining a for loop doesn't cause run_ast te be executed again.

What version of the product are you using? On what operating system?

phc version: 0.2.0.3 (14 February 2009)
os: Ubuntu 9.04 - Linux

Original issue reported on code.google.com by sandervellinga on 2010-01-15 12:58:40

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

Wow, that's pretty bizarre. Have you tried it on the svn version? A lot of work has
gone on since 0.2.0.3.

Original issue reported on code.google.com by paul.biggar on 2010-01-16 09:49:07

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

No I haven't tested it on the svn version yet. I've searched all issues for a similar
problem though. Figured if it was fixed in svn, there would be a solved issue in the
tracker...

But ofcourse using a loop construct isn't that special so I guess that if the problem
would exists in the head, others would run into the same problem... I will try to use
the svn version later and let you know if the issue is solved.

btw: I found that suppressing errors in a php file causes the same problem.

thus something like:

<?php
@foo();
?>

Original issue reported on code.google.com by sandervellinga on 2010-01-18 13:36:23

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

I see why this is happening. Try the attached patch and see if it fixes it.

The problem was the phc runs the parser at various points during compilation, for some
internal purposed. After running the parser, it runs all passes that have already been
run, which up until now included plugins. It should no longer run plugins like that
with the patch.

Original issue reported on code.google.com by paul.biggar on 2010-09-08 09:47:05


- _Attachment: [119.patch](https://storage.googleapis.com/google-code-attachments/phc/issue-119/comment-3/119.patch)_

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

I added the fix from the patch above in revision 3345. Please let me know if it solves
your problem.

Original issue reported on code.google.com by paul.biggar on 2010-09-08 10:04:16

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

Thanks! I have tried to confirm this but I am not able to compile the latest version.
When running make it fails with:

./.libs/libphc.so: undefined reference to `PHP::get_superglobals()'
./.libs/libphc.so: undefined reference to `PHP::get_string_value(MIR::Literal*)'

If you know how to solve this I would be glad to test the fix. Otherwise you can test
it yourself with the most simple phc plugin, the hello world application from the documentation
for example.

helloworld.cpp:

#include <AST.h>
#include <pass_manager/Plugin_pass.h>

extern "C" void load (Pass_manager* pm, Plugin_pass* pass)
{
        pm->add_after_named_pass (pass, new String ("ast"));
}

extern "C" void run_ast (AST::PHP_script* in, Pass_manager* pm, String* option)
{
        cout << "Hello world (I'm a phc plugin!)" << endl;
}

sometest.php:

<?php
@foo();
?>

Then run:
~/myplugins$ phc_compile_plugin helloworld.cpp
~/myplugins$ phc --run helloworld.la sometest.php

If the bug still exists "cout << "Hello world (I'm a phc plugin!)" << endl;" will be
executed twice, if not it will only be executed once.

I wanted to test it myself with both versions, one before you path and one after but
since i am stuck i'm not getting anywhere. I have to note that am not that experienced
with compiling programs on linux so maybe I did something wrong.

Original issue reported on code.google.com by sandervellinga on 2010-09-15 19:24:40

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

This error in trunk should now be fixed. Sorry for taking so long with this. Let me
know if you're still having issues.

Original issue reported on code.google.com by paul.biggar on 2010-10-26 13:23:06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant