ARudik / phc

Automatically exported from code.google.com/p/phc
0 stars 0 forks source link

Loop in phpfile causes rerunning run_ast #119

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 sanderve...@gmail.com on 15 Jan 2010 at 12:58

GoogleCodeExporter commented 9 years ago
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 comment by paul.biggar on 16 Jan 2010 at 9:49

GoogleCodeExporter commented 9 years ago
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 comment by sanderve...@gmail.com on 18 Jan 2010 at 1:36

GoogleCodeExporter commented 9 years ago
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 comment by paul.biggar on 8 Sep 2010 at 9:47

Attachments:

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

Original comment by paul.biggar on 8 Sep 2010 at 10:04

GoogleCodeExporter commented 9 years ago
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 comment by sanderve...@gmail.com on 15 Sep 2010 at 7:24

GoogleCodeExporter commented 9 years ago
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 comment by paul.biggar on 26 Oct 2010 at 1:23