Commit 37faa993 authored by daarond's avatar daarond

more debugging

parent 5e7f92ce
...@@ -48,8 +48,6 @@ Blockly.PHP.addReservedWords( ...@@ -48,8 +48,6 @@ Blockly.PHP.addReservedWords(
'__halt_compiler,abstract,and,array,as,break,callable,case,catch,class,clone,const,continue,declare,default,die,do,echo,else,elseif,empty,enddeclare,endfor,endforeach,endif,endswitch,endwhile,eval,exit,extends,final,for,foreach,function,global,goto,if,implements,include,include_once,instanceof,insteadof,interface,isset,list,namespace,new,or,print,private,protected,public,require,require_once,return,static,switch,throw,trait,try,unset,use,var,while,xor,' + '__halt_compiler,abstract,and,array,as,break,callable,case,catch,class,clone,const,continue,declare,default,die,do,echo,else,elseif,empty,enddeclare,endfor,endforeach,endif,endswitch,endwhile,eval,exit,extends,final,for,foreach,function,global,goto,if,implements,include,include_once,instanceof,insteadof,interface,isset,list,namespace,new,or,print,private,protected,public,require,require_once,return,static,switch,throw,trait,try,unset,use,var,while,xor,' +
// http://php.net/manual/en/reserved.constants.php // http://php.net/manual/en/reserved.constants.php
'PHP_VERSION,PHP_MAJOR_VERSION,PHP_MINOR_VERSION,PHP_RELEASE_VERSION,PHP_VERSION_ID,PHP_EXTRA_VERSION,PHP_ZTS,PHP_DEBUG,PHP_MAXPATHLEN,PHP_OS,PHP_SAPI,PHP_EOL,PHP_INT_MAX,PHP_INT_SIZE,DEFAULT_INCLUDE_PATH,PEAR_INSTALL_DIR,PEAR_EXTENSION_DIR,PHP_EXTENSION_DIR,PHP_PREFIX,PHP_BINDIR,PHP_BINARY,PHP_MANDIR,PHP_LIBDIR,PHP_DATADIR,PHP_SYSCONFDIR,PHP_LOCALSTATEDIR,PHP_CONFIG_FILE_PATH,PHP_CONFIG_FILE_SCAN_DIR,PHP_SHLIB_SUFFIX,E_ERROR,E_WARNING,E_PARSE,E_NOTICE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,E_USER_ERROR,E_USER_WARNING,E_USER_NOTICE,E_DEPRECATED,E_USER_DEPRECATED,E_ALL,E_STRICT,__COMPILER_HALT_OFFSET__,TRUE,FALSE,NULL,__CLASS__,__DIR__,__FILE__,__FUNCTION__,__LINE__,__METHOD__,__NAMESPACE__,__TRAIT__'); 'PHP_VERSION,PHP_MAJOR_VERSION,PHP_MINOR_VERSION,PHP_RELEASE_VERSION,PHP_VERSION_ID,PHP_EXTRA_VERSION,PHP_ZTS,PHP_DEBUG,PHP_MAXPATHLEN,PHP_OS,PHP_SAPI,PHP_EOL,PHP_INT_MAX,PHP_INT_SIZE,DEFAULT_INCLUDE_PATH,PEAR_INSTALL_DIR,PEAR_EXTENSION_DIR,PHP_EXTENSION_DIR,PHP_PREFIX,PHP_BINDIR,PHP_BINARY,PHP_MANDIR,PHP_LIBDIR,PHP_DATADIR,PHP_SYSCONFDIR,PHP_LOCALSTATEDIR,PHP_CONFIG_FILE_PATH,PHP_CONFIG_FILE_SCAN_DIR,PHP_SHLIB_SUFFIX,E_ERROR,E_WARNING,E_PARSE,E_NOTICE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,E_USER_ERROR,E_USER_WARNING,E_USER_NOTICE,E_DEPRECATED,E_USER_DEPRECATED,E_ALL,E_STRICT,__COMPILER_HALT_OFFSET__,TRUE,FALSE,NULL,__CLASS__,__DIR__,__FILE__,__FUNCTION__,__LINE__,__METHOD__,__NAMESPACE__,__TRAIT__');
// there are more than 9,000 internal functions in http://php.net/manual/en/indexes.functions.php
// do we really need to list them here?
/** /**
* Order of operation ENUMs. * Order of operation ENUMs.
...@@ -58,6 +56,7 @@ Blockly.PHP.addReservedWords( ...@@ -58,6 +56,7 @@ Blockly.PHP.addReservedWords(
Blockly.PHP.ORDER_ATOMIC = 0; // 0 "" ... Blockly.PHP.ORDER_ATOMIC = 0; // 0 "" ...
Blockly.PHP.ORDER_CLONE = 1; // clone Blockly.PHP.ORDER_CLONE = 1; // clone
Blockly.PHP.ORDER_NEW = 1; // new Blockly.PHP.ORDER_NEW = 1; // new
Blockly.PHP.ORDER_MEMBER = 2; // ()
Blockly.PHP.ORDER_FUNCTION_CALL = 2; // () Blockly.PHP.ORDER_FUNCTION_CALL = 2; // ()
Blockly.PHP.ORDER_INCREMENT = 3; // ++ Blockly.PHP.ORDER_INCREMENT = 3; // ++
Blockly.PHP.ORDER_DECREMENT = 3; // -- Blockly.PHP.ORDER_DECREMENT = 3; // --
...@@ -110,13 +109,14 @@ Blockly.PHP.init = function(workspace) { ...@@ -110,13 +109,14 @@ Blockly.PHP.init = function(workspace) {
Blockly.PHP.getDistinctName = function(name, type) { Blockly.PHP.getDistinctName = function(name, type) {
var safeName = this.variableDB_.safeName_(name); var safeName = this.variableDB_.safeName_(name);
var i = ''; var i = '';
while (this.variableDB_.dbReverse_[safeName + i] || while ((type == Blockly.Procedures.NAME_TYPE && (safeName + i) in this.variableDB_.reservedDict_)
(safeName + i) in this.variableDB_.reservedDict_) { || this.variableDB_.dbReverse_[safeName + i]) {
// Collision with existing name. Create a unique name. // Collision with existing name. Create a unique name.
i = i ? i + 1 : 2; i = i ? i + 1 : 2;
} }
safeName += i; safeName += i;
this.variableDB_.dbReverse_[safeName] = true; this.variableDB_.dbReverse_[safeName] = true;
if (type === Blockly.Procedures.NAME_TYPE) return safeName;
return '$' + safeName; return '$' + safeName;
}; };
......
...@@ -64,7 +64,7 @@ Blockly.PHP['colour_rgb'] = function(block) { ...@@ -64,7 +64,7 @@ Blockly.PHP['colour_rgb'] = function(block) {
' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);', ' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);',
' return $hex;', ' return $hex;',
'}']); '}']);
var code = functionName + '($' + red + ', $' + green + ', $' + blue + ')'; var code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
}; };
...@@ -96,6 +96,6 @@ Blockly.PHP['colour_blend'] = function(block) { ...@@ -96,6 +96,6 @@ Blockly.PHP['colour_blend'] = function(block) {
' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);', ' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);',
' return $hex;', ' return $hex;',
'}']); '}']);
var code = functionName + '($' + c1 + ', $' + c2 + ', $' + ratio + ')'; var code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
}; };
This diff is collapsed.
...@@ -199,8 +199,7 @@ Blockly.PHP['math_change'] = function(block) { ...@@ -199,8 +199,7 @@ Blockly.PHP['math_change'] = function(block) {
Blockly.PHP.ORDER_ADDITION) || '0'; Blockly.PHP.ORDER_ADDITION) || '0';
var varName = Blockly.PHP.getName( var varName = Blockly.PHP.getName(
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
return varName + ' = (typeof ' + varName + ' == \'number\' ? ' + varName + return varName + ' += ' + argument0 + ';\n';
' : 0) + ' + argument0 + ';\n';
}; };
// Rounding functions have a single operand. // Rounding functions have a single operand.
...@@ -215,17 +214,17 @@ Blockly.PHP['math_on_list'] = function(block) { ...@@ -215,17 +214,17 @@ Blockly.PHP['math_on_list'] = function(block) {
switch (func) { switch (func) {
case 'SUM': case 'SUM':
list = Blockly.PHP.valueToCode(block, 'LIST', list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_MEMBER) || 'array()'; Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'array_sum(' + list + ')'; code = 'array_sum(' + list + ')';
break; break;
case 'MIN': case 'MIN':
list = Blockly.PHP.valueToCode(block, 'LIST', list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_COMMA) || 'array()'; Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'min(' + list + ')'; code = 'min(' + list + ')';
break; break;
case 'MAX': case 'MAX':
list = Blockly.PHP.valueToCode(block, 'LIST', list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_COMMA) || 'array()'; Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'max(' + list + ')'; code = 'max(' + list + ')';
break; break;
case 'AVERAGE': case 'AVERAGE':
...@@ -328,10 +327,7 @@ Blockly.PHP['math_random_int'] = function(block) { ...@@ -328,10 +327,7 @@ Blockly.PHP['math_random_int'] = function(block) {
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'($a, $b) {', '($a, $b) {',
' if ($a > $b) {', ' if ($a > $b) {',
' // Swap a and b to ensure a is smaller.', ' return rand($b, $a);',
' $c = $a;',
' $a = $b;',
' $b = $c;',
' }', ' }',
' return rand($a, $b);', ' return rand($a, $b);',
'}']); '}']);
......
...@@ -28,7 +28,6 @@ goog.provide('Blockly.PHP.procedures'); ...@@ -28,7 +28,6 @@ goog.provide('Blockly.PHP.procedures');
goog.require('Blockly.PHP'); goog.require('Blockly.PHP');
Blockly.PHP['procedures_defreturn'] = function(block) { Blockly.PHP['procedures_defreturn'] = function(block) {
// Define a procedure with a return value. // Define a procedure with a return value.
var funcName = Blockly.PHP.getName( var funcName = Blockly.PHP.getName(
......
...@@ -69,7 +69,7 @@ Blockly.PHP['text_append'] = function(block) { ...@@ -69,7 +69,7 @@ Blockly.PHP['text_append'] = function(block) {
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\''; Blockly.PHP.ORDER_NONE) || '\'\'';
return varName + ' = ' + varName + ' . ' + argument0 + ';\n'; return varName + ' .= ' + argument0 + ';\n';
}; };
Blockly.PHP['text_length'] = function(block) { Blockly.PHP['text_length'] = function(block) {
...@@ -82,7 +82,7 @@ Blockly.PHP['text_length'] = function(block) { ...@@ -82,7 +82,7 @@ Blockly.PHP['text_length'] = function(block) {
Blockly.PHP['text_isEmpty'] = function(block) { Blockly.PHP['text_isEmpty'] = function(block) {
// Is the string null? // Is the string null?
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL];
}; };
...@@ -91,20 +91,20 @@ Blockly.PHP['text_indexOf'] = function(block) { ...@@ -91,20 +91,20 @@ Blockly.PHP['text_indexOf'] = function(block) {
var operator = block.getFieldValue('END') == 'FIRST' ? var operator = block.getFieldValue('END') == 'FIRST' ?
'strpos' : 'strrpos'; 'strpos' : 'strrpos';
var argument0 = Blockly.PHP.valueToCode(block, 'FIND', var argument0 = Blockly.PHP.valueToCode(block, 'FIND',
Blockly.PHP.ORDER_NONE) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var argument1 = Blockly.PHP.valueToCode(block, 'VALUE', var argument1 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var code = operator + '(' + argument0 + ', ' + argument1 + ') + 1'; var code = operator + '(' + argument0 + ', ' + argument1 + ') + 1';
return [code, Blockly.PHP.ORDER_MEMBER]; return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
}; };
Blockly.PHP['text_charAt'] = function(block) { Blockly.PHP['text_charAt'] = function(block) {
// Get letter at index. // Get letter at index.
var where = block.getFieldValue('WHERE') || 'FROM_START'; var where = block.getFieldValue('WHERE') || 'FROM_START';
var at = Blockly.PHP.valueToCode(block, 'AT', var at = Blockly.PHP.valueToCode(block, 'AT',
Blockly.PHP.ORDER_UNARY_NEGATION) || '1'; Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
var text = Blockly.PHP.valueToCode(block, 'VALUE', var text = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
switch (where) { switch (where) {
case 'FIRST': case 'FIRST':
var code = text + '[0]'; var code = text + '[0]';
...@@ -142,13 +142,13 @@ Blockly.PHP['text_charAt'] = function(block) { ...@@ -142,13 +142,13 @@ Blockly.PHP['text_charAt'] = function(block) {
Blockly.PHP['text_getSubstring'] = function(block) { Blockly.PHP['text_getSubstring'] = function(block) {
// Get substring. // Get substring.
var text = Blockly.PHP.valueToCode(block, 'STRING', var text = Blockly.PHP.valueToCode(block, 'STRING',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var where1 = block.getFieldValue('WHERE1'); var where1 = block.getFieldValue('WHERE1');
var where2 = block.getFieldValue('WHERE2'); var where2 = block.getFieldValue('WHERE2');
var at1 = Blockly.PHP.valueToCode(block, 'AT1', var at1 = Blockly.PHP.valueToCode(block, 'AT1',
Blockly.PHP.ORDER_NONE) || '1'; Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
var at2 = Blockly.PHP.valueToCode(block, 'AT2', var at2 = Blockly.PHP.valueToCode(block, 'AT2',
Blockly.PHP.ORDER_NONE) || '1'; Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
if (where1 == 'FIRST' && where2 == 'LAST') { if (where1 == 'FIRST' && where2 == 'LAST') {
var code = text; var code = text;
} else { } else {
...@@ -159,23 +159,20 @@ Blockly.PHP['text_getSubstring'] = function(block) { ...@@ -159,23 +159,20 @@ Blockly.PHP['text_getSubstring'] = function(block) {
' if ($where1 == \'FROM_START\') {', ' if ($where1 == \'FROM_START\') {',
' $at1--;', ' $at1--;',
' } else if ($where1 == \'FROM_END\') {', ' } else if ($where1 == \'FROM_END\') {',
' $at1 = strlen($text) - $at;', ' $at1 = strlen($text) - $at1;',
' } else if ($where1 == \'FIRST\') {', ' } else if ($where1 == \'FIRST\') {',
' $at1 = 0;', ' $at1 = 0;',
' } else if (where1 == \'LAST\') {', ' } else if ($where1 == \'LAST\') {',
' $at1 = strlen($text) - 1;', ' $at1 = strlen($text) - 1;',
' } else { $at1 = 0; }', ' } else { $at1 = 0; }',
' if ($where2 == \'FROM_START\') {', ' if ($where2 == \'FROM_START\') {',
' $at2--;',
' } else if ($where2 == \'FROM_END\') {', ' } else if ($where2 == \'FROM_END\') {',
' $at2 = strlen($text) - $at;', ' $at2 = strlen($text) - $at2;',
' } else if ($where2 == \'FIRST\') {', ' } else if ($where2 == \'FIRST\') {',
' $at2 = 0;', ' $at2 = 0;',
' } else if (where2 == \'LAST\') {', ' } else if ($where2 == \'LAST\') {',
' $at2 = strlen($text) - 1;', ' $at2 = strlen($text);',
' } else { $at2 = 0; }', ' } else { $at2 = 0; }',
' $at1 = getAt($where1, $at1);',
' $at2 = getAt($where2, $at2) + 1;',
' return substr($text, $at1, $at2);', ' return substr($text, $at1, $at2);',
'}']); '}']);
var code = functionName + '(' + text + ', \'' + var code = functionName + '(' + text + ', \'' +
...@@ -189,15 +186,15 @@ Blockly.PHP['text_changeCase'] = function(block) { ...@@ -189,15 +186,15 @@ Blockly.PHP['text_changeCase'] = function(block) {
var code; var code;
if (block.getFieldValue('CASE')=='UPPERCASE') { if (block.getFieldValue('CASE')=='UPPERCASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'strtoupper(' + argument0 + ')'; code = 'strtoupper(' + argument0 + ')';
} else if (block.getFieldValue('CASE')=='LOWERCASE') { } else if (block.getFieldValue('CASE')=='LOWERCASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'strtolower(' + argument0 + ')'; code = 'strtolower(' + argument0 + ')';
} else if (block.getFieldValue('CASE')=='TITLECASE') { } else if (block.getFieldValue('CASE')=='TITLECASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'ucwords(' + argument0 + ')'; code = 'ucwords(' + argument0 + ')';
} }
return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
...@@ -212,14 +209,14 @@ Blockly.PHP['text_trim'] = function(block) { ...@@ -212,14 +209,14 @@ Blockly.PHP['text_trim'] = function(block) {
}; };
var operator = OPERATORS[block.getFieldValue('MODE')]; var operator = OPERATORS[block.getFieldValue('MODE')];
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\''; Blockly.PHP.ORDER_ATOMIC) || '\'\'';
return [ operator + '(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL]; return [ operator + '(' + argument0 + ')', Blockly.PHP.ORDER_ATOMIC];
}; };
Blockly.PHP['text_print'] = function(block) { Blockly.PHP['text_print'] = function(block) {
// Print statement. // Print statement.
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT', var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\''; Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
return 'print(' + argument0 + ');\n'; return 'print(' + argument0 + ');\n';
}; };
...@@ -231,17 +228,17 @@ Blockly.PHP['text_prompt'] = function(block) { ...@@ -231,17 +228,17 @@ Blockly.PHP['text_prompt'] = function(block) {
if (toNumber) { if (toNumber) {
code = 'floatval(' + code + ')'; code = 'floatval(' + code + ')';
} }
return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; return [code, Blockly.PHP.ORDER_ATOMIC];
}; };
Blockly.PHP['text_prompt_ext'] = function(block) { Blockly.PHP['text_prompt_ext'] = function(block) {
// Prompt function (external message). // Prompt function (external message).
var msg = Blockly.PHP.valueToCode(block, 'TEXT', var msg = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\''; Blockly.PHP.ORDER_ATOMIC) || '\'\'';
var code = 'readline(' + msg + ')'; var code = 'readline(' + msg + ')';
var toNumber = block.getFieldValue('TYPE') == 'NUMBER'; var toNumber = block.getFieldValue('TYPE') == 'NUMBER';
if (toNumber) { if (toNumber) {
code = 'floatval(' + code + ')'; code = 'floatval(' + code + ')';
} }
return [code, Blockly.PHP.ORDER_FUNCTION_CALL]; return [code, Blockly.PHP.ORDER_ATOMIC];
}; };
...@@ -39,7 +39,7 @@ Blockly.PHP['variables_set'] = function(block) { ...@@ -39,7 +39,7 @@ Blockly.PHP['variables_set'] = function(block) {
// Variable setter. // Variable setter.
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE', var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_ASSIGNMENT) || '0'; Blockly.PHP.ORDER_ASSIGNMENT) || '0';
var varName = Blockly.PHP.variableDB_.getName( var varName = Blockly.PHP.getName(
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
return '$' + varName + ' = ' + argument0 + ';\n'; return varName + ' = ' + argument0 + ';\n';
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment