[phc-internals] svn commit by john

svn at phpcompiler.org svn at phpcompiler.org
Wed Nov 30 00:16:38 GMT 2005


This transform isnt quite so easy. How do we handle 'global $fud' in functions
inside _other_ classes? (they should be re-written $this->fud rather than %MAIN%::fud).
Actually, that might be a better solution for all globals: rewrite 

global $x;

as

$x &= $this->x;

to bind the global one into scope ?

# Changed
U   phc/src/translation/variable_targets.cpp

# Diff
Modified: phc/src/translation/variable_targets.cpp
===================================================================
--- phc/src/translation/variable_targets.cpp	2005-11-29 17:45:56 UTC (rev 403)
+++ phc/src/translation/variable_targets.cpp	2005-11-30 00:16:36 UTC (rev 404)
@@ -1,8 +1,6 @@
 /*
  * phc -- the open source PHP compiler
- * Modify the 'target' attribute on variables which are pulled in
- * from the global scope so that they use the static attribute of %MAIN% of the same
- * name, and remove all 'global' statements from the AST.
+ * Modify the 'target' attribute on variables. Remove all 'global' statements.
  */
 
 #include "transform.h"
@@ -10,7 +8,6 @@
 class VariableTargets : public TreeTransform
 {
 private:
-
 	AST_class_def* main;
 	bool in_run;
 	Vector<Token_variable_name*> globals;
@@ -70,6 +67,8 @@
 
 	void pre_global_declaration(AST_global_declaration* in, AST_statement** out)
 	{
+		if(in_run) assert(false);
+	
 		Vector<AST_variable_name*>::const_iterator i;
 		for(i = in->variable_names->begin(); i != in->variable_names->end(); i++)
 		{
@@ -98,13 +97,15 @@
 		if(!in->target)
 		{
 			Token_variable_name* t = dynamic_cast<Token_variable_name*>(in->variable_name);
-			if(t && in_globals(t))
+			if(t)
 			{
-				in->target = new Token_class_name("%MAIN%");
+				if(in_run || in_globals(t))
+				{
+					in->target = new Token_class_name("%MAIN%");
+				}
 			}
 		}
 	}
-	
 };
 
 void update_variable_targets(AST_php_script* php_script)


More information about the phc-internals mailing list