From 1c37fff927bc02202c012b7faa52cbe51e4791f0 Mon Sep 17 00:00:00 2001 From: DanyaPostfactum Date: Tue, 1 Jan 2013 23:07:36 +1000 Subject: [PATCH 1/2] Add php worker --- lib/ace/mode/php.js | 16 + lib/ace/mode/php/php.js | 6817 ++++++++++++++++++++++++++++++++++++ lib/ace/mode/php_worker.js | 76 + 3 files changed, 6909 insertions(+) create mode 100644 lib/ace/mode/php/php.js create mode 100644 lib/ace/mode/php_worker.js diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index a73f3e84..549c9eba 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -37,6 +37,7 @@ var Tokenizer = require("../tokenizer").Tokenizer; var PhpHighlightRules = require("./php_highlight_rules").PhpHighlightRules; var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; var Range = require("../range").Range; +var WorkerClient = require("../worker/worker_client").WorkerClient; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var unicode = require("../unicode"); @@ -134,6 +135,21 @@ oop.inherits(Mode, TextMode); this.$outdent.autoOutdent(doc, row); }; + this.createWorker = function(session) { + var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); + worker.attachToDocument(session.getDocument()); + + worker.on("error", function(e) { + session.setAnnotations(e.data); + }); + + worker.on("ok", function() { + session.clearAnnotations(); + }); + + return worker; + }; + }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/mode/php/php.js b/lib/ace/mode/php/php.js new file mode 100644 index 00000000..5b3296f2 --- /dev/null +++ b/lib/ace/mode/php/php.js @@ -0,0 +1,6817 @@ +define(function(require, exports, module) { +/* + * @author Niklas von Hertzen + * @created 15.6.2012 + * @website http://hertzen.com + */ + + +var PHP = function( code, opts ) { + + var iniContent = opts.filesystem.readFileSync( "cfg/php.ini" ), + iniSet = opts.ini || {}; + opts.ini = PHP.ini( iniContent ); + + Object.keys( iniSet ).forEach(function(key){ + this[ key ] = iniSet[ key ]; + }, opts.ini); + + this.tokens = PHP.Lexer( code, opts.ini ); + try { + this.AST = new PHP.Parser( this.tokens ); + } catch( e ) { + this.vm = {}; + this.vm.OUTPUT_BUFFER = "Parse error: " + e.message + " in " + opts.SERVER.SCRIPT_FILENAME + " on line " + e.line; + return this; + } + + + + + + var POST = opts.POST, + RAW_POST = opts.RAW_POST, + RAW = (RAW_POST !== undefined ) ? PHP.RAWPost( RAW_POST ) : {}; + + opts.POST = ( POST !== undefined ) ? PHP.Utils.QueryString( POST ) : (RAW_POST !== undefined ) ? RAW.Post() : {}; + opts.RAW_POST = ( RAW_POST !== undefined ) ? RAW.Raw() : (POST !== undefined ) ? POST.trim() : ""; + opts.GET = ( opts.GET !== undefined ) ? PHP.Utils.QueryString( opts.GET ) : {}; + + opts.FILES = (RAW_POST !== undefined ) ? RAW.Files( opts.ini.upload_max_filesize, opts.ini.max_file_uploads, opts.ini.upload_tmp_dir ) : {}; + /* + if (RAW_POST !== undefined ) { + var rawError = RAW.Error(); + } + */ + // needs to be called after RAW.Files + if (RAW_POST !== undefined ) { + RAW.WriteFiles( opts.filesystem.writeFileSync ); + } + + + + this.compiler = new PHP.Compiler( this.AST, opts.SERVER.SCRIPT_FILENAME ); + console.log(this.compiler.src); + + if ( false ) { + var thread = new Worker("thread.js"); + + thread.postMessage({ + type: "import", + content: opts.files + }); + + thread.postMessage({ + type: "run", + content: [this.compiler.src, opts] + }) + + setTimeout(function(){ + thread.postMessage({ + type: "stop" + }) + }, opts.ini.max_execution_time); + + + thread.addEventListener('message', function(e) { + switch( e.data.type ) { + case "complete": + this.vm = e.data.content; + complete(this); + break; + default: + console.log(e.data); + } + + }, false); + + } else { + + this.vm = new PHP.VM( this.compiler.src, opts ); + + + if (RAW_POST !== undefined ) { + RAW.Error(this.vm[ PHP.Compiler.prototype.ERROR ].bind( this.vm ), opts.SERVER.SCRIPT_FILENAME); + } + + /* + if (rawError !== undefined ) { + this.vm[ PHP.Compiler.prototype.ERROR ]( rawError + " in " + opts.SERVER.SCRIPT_FILENAME, PHP.Constants.E_WARNING ); + } + */ + + this.vm.Run(); + + } + + + +}; + +PHP.Constants = {}; + +PHP.Modules = function() { + this.OUTPUT_BUFFER = ""; + + +}; + +PHP.Adapters = {}; + +PHP.Utils = {}; + + +PHP.Utils.$A = function( arr) { + return Array.prototype.slice.call( arr ); +}; + +PHP.Utils.ClassName = function( classVar ) { + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype; + if ( classVar instanceof PHP.VM.Variable ) { + if ( classVar[ VARIABLE.TYPE ] === VARIABLE.STRING ) { + return classVar[ COMPILER.VARIABLE_VALUE ] + } else { + return classVar[ COMPILER.VARIABLE_VALUE ][ COMPILER.CLASS_NAME ]; + } + } + +}; + +PHP.Utils.Merge = function(obj1, obj2) { + + Object.keys( obj2 ).forEach(function( key ){ + obj1[ key ] = obj2 [ key ]; + }); + + return obj1; +}; + +PHP.Utils.Path = function( path ) { + + path = path.substring(0, path.lastIndexOf("/")); + + return path; +}; + +PHP.Utils.Visible = function( name, objectValue, ctx ) { + + // helper function for checking whether variable/method is of type + function checkType( name, type) { + var value = objectValue[ PROPERTY_TYPE + name ]; + if (value === undefined) { + return true; + } + + if ( type === "PUBLIC") { + return ((value & PHP.VM.Class[ type ]) === PHP.VM.Class[ type ]) || (value === PHP.VM.Class.STATIC); + } else { + return ((value & PHP.VM.Class[ type ]) === PHP.VM.Class[ type ]); + } + + } + + function hasProperty( proto, prop ) { + while( proto !== undefined && proto[ PHP.VM.Class.PROPERTY + prop ] !== undefined ) { + proto = Object.getPrototypeOf( proto ); + } + + return proto; + + } + + var COMPILER = PHP.Compiler.prototype, + PROPERTY_TYPE = PHP.VM.Class.PROPERTY_TYPE, + VARIABLE = PHP.VM.Variable.prototype; + + if ( (ctx instanceof PHP.VM.ClassPrototype) && objectValue[ COMPILER.CLASS_NAME ] === ctx[ COMPILER.CLASS_NAME ] ) { + return true; + } else { + + if ( (ctx instanceof PHP.VM.ClassPrototype) && this.$Class.Inherits( objectValue, ctx[ COMPILER.CLASS_NAME ] ) && checkType( name, "PROTECTED")) { + + return true; + } else if ( (ctx instanceof PHP.VM.ClassPrototype) && this.$Class.Inherits( objectValue, ctx[ COMPILER.CLASS_NAME ] ) && checkType( name, "PRIVATE")) { + + if (hasProperty( ctx, name ) === ctx) { + return true; + } + + + } else if (checkType(name, "PUBLIC")) { + + return true; + } + } + + return false; + +}; + +PHP.Utils.ArgumentHandler = function( ENV, arg, argObject, value, index, functionName ) { + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype; + + if ( argObject[ COMPILER.PARAM_BYREF ] === true ) { + + // check that we aren't passing a constant for arg which is defined byRef + if ( ENV.FUNCTION_REFS[ functionName ] !== true && ( value[ VARIABLE.CLASS_CONSTANT ] === true || value[ VARIABLE.CONSTANT ] === true || value[ COMPILER.NAV ] === true) ) { + ENV[ PHP.Compiler.prototype.ERROR ]( "Only variables can be passed by reference", PHP.Constants.E_ERROR, true ); + } + + + // check that we aren't passing a function return value + if ( value[ VARIABLE.VARIABLE_TYPE ] === VARIABLE.FUNCTION ) { + ENV[ PHP.Compiler.prototype.ERROR ]( "Only variables should be passed by reference", PHP.Constants.E_STRICT, true ); + value[ VARIABLE.VARIABLE_TYPE ] = undefined; + value = new PHP.VM.Variable( value[ COMPILER.VARIABLE_VALUE ] ); + + } + + if (value[ VARIABLE.DEFINED ] !== true ) { + // trigger setter + value[ COMPILER.VARIABLE_VALUE ] = null; + } + + arg[ VARIABLE.REF ]( value ); + } else { + + if ( value !== undefined ) { + + if ( value instanceof PHP.VM.VariableProto) { + + if ( value[ VARIABLE.TYPE ] === VARIABLE.ARRAY ) { + // Array assignment always involves value copying. Use the reference operator to copy an array by reference. + arg[ COMPILER.VARIABLE_VALUE ] = value[ COMPILER.METHOD_CALL ]( {}, COMPILER.ARRAY_CLONE ); + + } else { + arg[ COMPILER.VARIABLE_VALUE ] = value[ COMPILER.VARIABLE_VALUE ]; + } + } else { + arg[ COMPILER.VARIABLE_VALUE ] = value; + } + + + } else { + if ( argObject[ COMPILER.PROPERTY_DEFAULT ] !== undefined ) { + arg[ COMPILER.VARIABLE_VALUE ] = argObject[ COMPILER.PROPERTY_DEFAULT ][ COMPILER.VARIABLE_VALUE ]; + } else { + arg[ COMPILER.VARIABLE_VALUE ] = (new PHP.VM.Variable())[ COMPILER.VARIABLE_VALUE ]; + } + } + } + + + + if ( argObject[ COMPILER.PROPERTY_TYPE ] !== undefined ) { + ENV[ COMPILER.TYPE_CHECK ]( arg, argObject[ COMPILER.PROPERTY_TYPE ], argObject[ COMPILER.PROPERTY_DEFAULT ], index, functionName ); + } +}; + +PHP.Utils.StaticHandler = function( staticHandler, staticVars, handler, $Global ) { + + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype; + + staticHandler[ COMPILER.FUNCTION_STATIC_SET ] = function( name, def ) { + + if ( staticVars[ name ] === undefined ) { + // store it to storage for this variable + staticVars[ name ] = { + def: def[ COMPILER.VARIABLE_VALUE ], + val: def + }; + + // assign it to current running context as well + handler( name, def ); + + } else { + if ( def [ COMPILER.VARIABLE_VALUE ] === staticVars[ name ].def ) { + handler( name, staticVars[ name ].val ); + } else { + staticVars[ name ] = { + def: def[ COMPILER.VARIABLE_VALUE ], + val: def + }; + handler( name, def ); + } + } + + + return staticHandler; + + + }; + + + // global handler + staticHandler[ COMPILER.FUNCTION_GLOBAL ] = function( vars ) { + vars.forEach(function( varName ){ + var val = $Global( varName ); + val[ VARIABLE.DEFINED ] = true; + handler( varName, val ) + }); + }; + + return staticHandler; + +}; + +PHP.Utils.CheckRef = function( ret, byRef ) { + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype; + + if ( ret instanceof PHP.VM.Variable) { + if ( byRef !== true) { + + ret[ VARIABLE.VARIABLE_TYPE ] = VARIABLE.FUNCTION; + } else if (byRef === true){ + + if (ret[ VARIABLE.REFERRING] === undefined && (ret[ VARIABLE.VARIABLE_TYPE ] === VARIABLE.NEW_VARIABLE || ret[ VARIABLE.VARIABLE_TYPE ] === VARIABLE.FUNCTION )) { + + this[ PHP.Compiler.prototype.ERROR ]( "Only variable references should be returned by reference", PHP.Constants.E_NOTICE, true ); + } + ret[ VARIABLE.VARIABLE_TYPE ] = undefined; + } + } + +}; + + +PHP.Utils.TokenName = function( token ) { + var constants = ["T_INCLUDE","T_INCLUDE_ONCE","T_EVAL","T_REQUIRE","T_REQUIRE_ONCE","T_LOGICAL_OR","T_LOGICAL_XOR","T_LOGICAL_AND","T_PRINT","T_PLUS_EQUAL","T_MINUS_EQUAL","T_MUL_EQUAL","T_DIV_EQUAL","T_CONCAT_EQUAL","T_MOD_EQUAL","T_AND_EQUAL","T_OR_EQUAL","T_XOR_EQUAL","T_SL_EQUAL","T_SR_EQUAL","T_BOOLEAN_OR","T_BOOLEAN_AND","T_IS_EQUAL","T_IS_NOT_EQUAL","T_IS_IDENTICAL","T_IS_NOT_IDENTICAL","T_IS_SMALLER_OR_EQUAL","T_IS_GREATER_OR_EQUAL","T_SL","T_SR","T_INSTANCEOF","T_INC","T_DEC","T_INT_CAST","T_DOUBLE_CAST","T_STRING_CAST","T_ARRAY_CAST","T_OBJECT_CAST","T_BOOL_CAST","T_UNSET_CAST","T_NEW","T_CLONE","T_EXIT","T_IF","T_ELSEIF","T_ELSE","T_ENDIF","T_LNUMBER","T_DNUMBER","T_STRING","T_STRING_VARNAME","T_VARIABLE","T_NUM_STRING","T_INLINE_HTML","T_CHARACTER","T_BAD_CHARACTER","T_ENCAPSED_AND_WHITESPACE","T_CONSTANT_ENCAPSED_STRING","T_ECHO","T_DO","T_WHILE","T_ENDWHILE","T_FOR","T_ENDFOR","T_FOREACH","T_ENDFOREACH","T_DECLARE","T_ENDDECLARE","T_AS","T_SWITCH","T_ENDSWITCH","T_CASE","T_DEFAULT","T_BREAK","T_CONTINUE","T_GOTO","T_FUNCTION","T_CONST","T_RETURN","T_TRY","T_CATCH","T_THROW","T_USE","T_INSTEADOF","T_GLOBAL","T_STATIC","T_ABSTRACT","T_FINAL","T_PRIVATE","T_PROTECTED","T_PUBLIC","T_VAR","T_UNSET","T_ISSET","T_EMPTY","T_HALT_COMPILER","T_CLASS","T_TRAIT","T_INTERFACE","T_EXTENDS","T_IMPLEMENTS","T_OBJECT_OPERATOR","T_DOUBLE_ARROW","T_LIST","T_ARRAY","T_CALLABLE","T_CLASS_C","T_TRAIT_C","T_METHOD_C","T_FUNC_C","T_LINE","T_FILE","T_COMMENT","T_DOC_COMMENT","T_OPEN_TAG","T_OPEN_TAG_WITH_ECHO","T_CLOSE_TAG","T_WHITESPACE","T_START_HEREDOC","T_END_HEREDOC","T_DOLLAR_OPEN_CURLY_BRACES","T_CURLY_OPEN","T_PAAMAYIM_NEKUDOTAYIM","T_DOUBLE_COLON","T_NAMESPACE","T_NS_C","T_DIR","T_NS_SEPARATOR"]; + var current = "UNKNOWN"; + constants.some(function( constant ) { + if (PHP.Constants[ constant ] === token) { + current = constant; + return true; + } else { + return false; + } + }); + + return current; +}; + +PHP.Utils.Filesize = function( size ) { + + if ( /^\d+M$/i.test( size )) { + return (size.replace(/M/g,"") - 0) * 1024 * 1024; + } else if ( /^\d+K$/i.test( size )) { + return (size.replace(/K/g,"") - 0) * 1024; + } + + return size; + +}; + +PHP.Utils.QueryString = function( str ) { + str = str.trim(); + var variables = str.split(/&/); + + var items = {}; + + // going through each variable which have been split by & + variables.forEach( function( variable ) { + + var parts = variable.split(/=/), + key = decodeURIComponent( parts[ 0 ] ), + value = (parts.length > 1 ) ? decodeURIComponent( parts[ 1 ] ) : null, + + arrayManager = function( item, parse, value ) { + + + var arraySearch = parse.match(/^\[([a-z0-9+_\-\[]*)\]/i); + // console.log(item, parse, value, arraySearch); + if ( arraySearch !== null ) { + var key = ( arraySearch[ 1 ] === undefined ) ? Object.keys( item ).length : arraySearch[ 1 ]; + + if ( key.length === 0 ) { + key = Object.keys(item).length; + + } + parse = parse.substring( arraySearch[ 0 ].length ); + + if ( parse.length > 0 ) { + if ( typeof item[ key ] !== "object" && item[ key ] !== null ) { + item[ key ] = {}; + } + + var ret = arrayManager( item[ key ], parse, value ); + + if ( ret !== undefined ) { + item[ key ] = ret; + } + + } else { + + item[ key ] = ( value !== null) ? value.replace(/\+/g," ") : null; + } + + + } else { + if ( parse === "]") { + item = value; + return value; + } + + } + + + }; + + // + + + var arraySearch = key.match(/^(.*?)((\[[a-z+0-9_\-\[\]]*\])+)$/i); + + if ( arraySearch !== null ) { + key = arraySearch[ 1 ]; + + + + if ( typeof items[ key ] !== "object" ) { + items[ key ] = {}; + + } + + arrayManager( items[ key ], arraySearch[ 2 ], value ); + + + } + else { + items[ key ] = ( value !== null) ? value.replace(/\+/g," ") : null; + } + + }, this); + + return items; + + }; + + /* +* @author Niklas von Hertzen +* @created 5.7.2012 +* @website http://hertzen.com + */ + + +PHP.Halt = function( msg, level, lineAppend, catchable ) { + + this.msg = msg; + this.level = level; + this.lineAppend = lineAppend; + this.catchable = catchable; + +}; +PHP.Compiler = function( AST, file, opts ) { + + this.file = file; + this.src = ""; + this.FOREACH_COUNT = 0; + opts = opts || {}; + + this.FUNC_NUM = 0; + this.dimVars = ""; + this.tmpDimVars = ""; + this.DEPRECATED = []; + this.dimPrev = ""; + + this.INSIDE_METHOD = (opts.INSIDE_METHOD !== undefined ) ? opts.INSIDE_METHOD : false; + + this.src += this.stmts( AST, true ); + + /* + AST.forEach( function( action ){ + if ( this.FATAL_ERROR !== undefined ) { + return; + } + this.src += this[ action.type ]( action ) + ";\n"; + }, this );*/ + + if ( this.FATAL_ERROR !== undefined ) { + this.src = 'this[ PHP.Compiler.prototype.ERROR ]("' + this.FATAL_ERROR + '", ' +(( this.ERROR_TYPE === undefined ) ? "PHP.Constants.E_ERROR" : this.ERROR_TYPE ) + ');'; + } + var tmp = ""; + this.DEPRECATED.forEach(function( error ){ + + tmp += 'this[ PHP.Compiler.prototype.ERROR ]("' + error[ 0 ] + ' in ' + this.file + ' on line ' + error[ 1 ] + '", PHP.Constants.E_DEPRECATED);'; + + }, this); + + this.src = tmp + this.src; + + + +}; + +var COMPILER = PHP.Compiler.prototype; + +COMPILER.getName = function( item ) { + var parts = item.parts; + if (Array.isArray( parts )) { + return parts[ 0 ]; + } else { + return parts; + } + +}; + +COMPILER.stmts = function( stmts, main ) { + var src = ""; + + stmts.forEach(function( stmt ){ + if ( this.FATAL_ERROR !== undefined ) { + return; + } + + var tmp = this.source( stmt ); + + if ( this.dimVars.length > 0 || this.tmpDimVars.length > 0 ) { + src += this.dimVars + this.tmpDimVars; + this.dimVars = this.tmpDimVars = ""; + } + + src += tmp; + + if ( stmt.type === "Node_Expr_New") { + // init class without assign, call destruct ( this might not be valid in all cases ) + src += "." + this.UNSET + "()"; + + } + + if ( /^Node_Expr_Post(Inc|Dec)$/.test( stmt.type ) ) { + // trigger POST_MOD + src += "." + this.VARIABLE_VALUE; + } + + src += ";\n"; + }, this); + + return src; +}; + +COMPILER.source = function( action ) { + + + + if ( action === null ) { + return "undefined"; + } + + + if (typeof action === "string") { + return action; + } else if ( action === undefined ) { + + return undefined; + } else if ( action.type === "Node_Name" ) { + return this.getName( action ); + } + + if ( Array.isArray( action )) { + return this[ action[0].type ]( action[0] ); + } + + return this[ action.type ]( action ); +}; + +COMPILER.FILE_PATH = "$FILE_PATH"; + +COMPILER.NAV = "$NaV"; // not a variable; + +COMPILER.FILESYSTEM = "$FS"; + +COMPILER.RESOURCES = "\π"; + +COMPILER.TIMER = "$Timer"; + +COMPILER.ENV = "ENV"; + +COMPILER.OUTPUT_BUFFER = "OUTPUT_BUFFER"; + +COMPILER.OUTPUT_BUFFERS = "OUTPUT_BUFFERS"; + +COMPILER.CTX = COMPILER.ENV + "."; + +COMPILER.PARAM_NAME = "n"; + +COMPILER.PARAM_BYREF = "r"; + +COMPILER.CATCH = "$Catch"; + +COMPILER.EXCEPTION = "$Exception"; + +COMPILER.SUPPRESS = "$Suppress"; + +COMPILER.CONSTANTS = "$Constants"; + +COMPILER.CONSTANT_GET = "get"; + +COMPILER.CLASS_CONSTANT_GET = "$Class.ConstantGet"; + +COMPILER.CONSTANT_SET = "set"; + +COMPILER.CONSTANT_DEFINED = "defined"; + +COMPILER.MAGIC_CONSTANTS = "$MConstants"; + +COMPILER.ASSIGN = "_"; + +COMPILER.ASSIGN_PLUS = "_Plus"; + +COMPILER.ASSIGN_MINUS = "_Minus"; + +COMPILER.ASSIGN_CONCAT = "_Concat"; + +COMPILER.NEG = "$Neg"; + +COMPILER.ADD = "$Add"; + +COMPILER.MUL = "$Mul"; + +COMPILER.MOD = "$Mod"; + +COMPILER.DIV = "$Div"; + +COMPILER.FUNCTION = "$F"; + +COMPILER.FUNCTION_HANDLER = "$FHandler"; + +COMPILER.FUNCTION_STATIC = "$Static"; + +COMPILER.FUNCTION_GLOBAL = "$Global"; + +COMPILER.FUNCTION_STATIC_SET = "$Set"; + +COMPILER.BOOLEAN_OR = "$Or"; + +COMPILER.PRE_INC = "$PreInc"; + +COMPILER.PRE_DEC = "$PreDec"; + +COMPILER.POST_INC = "$PostInc"; + +COMPILER.POST_DEC = "$PostDec"; + +COMPILER.MINUS = "$Minus"; + +COMPILER.CONCAT = "$Concat"; + +COMPILER.UNSET = "$Unset"; + +COMPILER.NOT_IDENTICAL = "$NIdentical"; + +COMPILER.IDENTICAL = "$Identical"; + +COMPILER.BOOLEAN_NOT = "$Not"; + +COMPILER.BOOLEAN_AND = "$And"; + +COMPILER.EQUAL = "$Equal"; + +COMPILER.NOT_EQUAL = "$Equal"; + +COMPILER.SMALLER = "$Smaller"; + +COMPILER.SMALLER_OR_EQUAL = "$S_Equal"; + +COMPILER.GREATER = "$Greater"; + +COMPILER.GREATER_OR_EQUAL = "$G_Equal"; + +COMPILER.LABEL = "LABEL"; + +COMPILER.LABEL_COUNT = 0; + +COMPILER.VARIABLE = "$"; + +COMPILER.VARIABLE_VALUE = "$"; + +COMPILER.CREATE_VARIABLE = "$$"; + +COMPILER.ARRAY_CLONE = "$AClone"; + +COMPILER.VARIABLE_CLONE = "$VClone"; + +COMPILER.ARRAY_GET = "offsetGet"; + +COMPILER.ARRAY_SET = "offsetSet"; + +COMPILER.METHOD_CALL = "$Call"; + +COMPILER.DIM_FETCH = "$Dim"; + +COMPILER.DIM_ISSET = "$DimIsset"; + +COMPILER.DIM_UNSET = "$DimUnset"; + +COMPILER.DIM_EMPTY = "$DimEmpty"; + +COMPILER.STATIC_CALL = "$StaticCall"; + +COMPILER.CLASS_NAME = "$Name"; + +COMPILER.INTERFACE_NEW = "$Class.INew"; + +COMPILER.CLASS_NEW = "$Class.New"; + +COMPILER.CLASS_GET = "$Class.Get"; + +COMPILER.CLASS_STORED = "$StoredIn"; + +COMPILER.CLASS_CLONE = "$CClone"; + +COMPILER.CLASS_PROPERTY_GET = "$Prop"; + +COMPILER.CLASS_PROPERTY_ISSET = "$PropIsset"; + +COMPILER.CLASS_STATIC_PROPERTY_ISSET = "$SPropIsset"; + +COMPILER.STATIC_PROPERTY_GET = "$SProp"; + +COMPILER.CLASS_METHOD = "Method"; + +COMPILER.CLASS_CONSTANT = "Constant"; + +COMPILER.CLASS_CONSTANT_FETCH = "$Constant"; + +COMPILER.PROPERTY_TYPE = "p"; + +COMPILER.PROPERTY_DEFAULT = "d"; + +COMPILER.CLASS_PROPERTY = "Variable"; + +COMPILER.CLASS_DECLARE = "Create"; + +COMPILER.CLASS_NAMES = "$CLASSNAMES"; + +COMPILER.CLASS_DESTRUCT = "$Destruct"; + +COMPILER.CLASS_TYPE = "$CType"; + +COMPILER.ARRAY_VALUE = "v"; + +COMPILER.ARRAY_KEY = "k"; + +COMPILER.ERROR = "$ERROR"; + +COMPILER.GLOBAL = "$Global"; + +COMPILER.SIGNATURE = "$SIGNATURE"; + +COMPILER.DISPLAY_HANDLER = "$DisplayHandler"; + +COMPILER.TYPE_CHECK = "$TypeCheck"; + +COMPILER.INSTANCEOF = "$InstanceOf"; + +COMPILER.fixString = function( result ) { + + + + + if ( result.match(/^("|')/) === null) { + result = '"' + result + '"'; + } + + + + if (result.match(/\r\n/) !== null) { + var quote = result.substring(0, 1); + + + + // this might have unexpected consequenses + result = result.replace(/\r\n"$/,'"'); + + result = '[' + result.split(/\r\n/).map(function( item ){ + var a = item.replace(/\r/g,"").replace(/\n/,"\\n"); + return a; + }).join( quote + "," + quote ) + '].join("\\n")'; + + } + + result = result.replace(/([^\\])\\([^\\nrt\$'"])/g, "$1\\\\$2"); + + return result; + +/* + $val = str_replace("\\", "\\\\", $val); + //$val = str_replace("\n", "\\n", $val); + //$val = str_replace("\t", "\\t", $val); + $val = str_replace('"', '\\"', $val); + //$val = str_replace('\\\\', '\\\\\\\\', $val); + + $val = str_replace("\n", "\\n", $val); + $val = str_replace("\t", "\\t", $val); +*/ + + +}/* + * @author Niklas von Hertzen + * @created 29.6.2012 + * @website http://hertzen.com + */ + +PHP.Modules.prototype[ PHP.Compiler.prototype.FUNCTION_HANDLER ] = function( ENV, functionName, funcByRef ) { + var args = [ null ], // undefined context for bind + COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype, + handler, + staticHandler = {}, + $GLOBAL = this[ COMPILER.GLOBAL ], + __FILE__ = "$__FILE__", + staticVars = {}; // static variable storage + + ENV.FUNCTION_REFS[ functionName ] = funcByRef; + + // initializer + args.push( function( args, values ) { + + handler = PHP.VM.VariableHandler( ENV ); + var vals = Array.prototype.slice.call( values, 2 ); + + + + args.forEach(function( argObject, index ){ + var arg = handler( argObject[ COMPILER.PARAM_NAME ] ); + + PHP.Utils.ArgumentHandler( ENV, arg, argObject, vals[index], index, functionName ); + + // redefine item in arguments object, to be used by func_get_arg(s) + + if ( argObject[ COMPILER.PARAM_BYREF ] === true ) { + values[ index + 2 ] = arg; + } else { + values[ index + 2 ] = new PHP.VM.Variable( arg[ COMPILER.VARIABLE_VALUE ] ); + } + }); + + handler("GLOBALS", $GLOBAL( "GLOBALS") ); + + // magic constants + handler( "$__FILE__" )[ COMPILER.VARIABLE_VALUE ] = $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ]; + + handler( "$__METHOD__")[ COMPILER.VARIABLE_VALUE ] = functionName; + handler( "$__FUNCTION__" )[ COMPILER.VARIABLE_VALUE ] = functionName; + + + // static handler, the messed up ordering of things is needed due to js execution order + PHP.Utils.StaticHandler( staticHandler, staticVars, handler, ENV[ COMPILER.GLOBAL ] ); + + + + + return handler; + } ); + + args.push( staticHandler ); + + + return args; + +}; + +PHP.Modules.prototype[ PHP.Compiler.prototype.FUNCTION ] = function( functionName, args ) { + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype, + func_num_args = "func_num_args", + message = "(): Called from the global scope - no function context", + func_get_arg = "func_get_arg", + func_get_args = "func_get_args", + ret, + item = PHP.VM.Array.arrayItem; + + if ( /^func_(get_args?|num_args)$/.test( functionName )) { + if ( args[ 2 ] instanceof PHP.VM ) { + this[ PHP.Compiler.prototype.ERROR ]( functionName + message, PHP.Constants.E_CORE_WARNING, true ); + if ( functionName === func_num_args ) { + return new PHP.VM.Variable( -1 ); + } else { + return new PHP.VM.Variable( false ); + } + } + + } + + + if ( functionName === func_num_args ) { + + + return new PHP.VM.Variable( args.length - 2 ); + + } else if ( functionName === func_get_arg ) { + + if ( !this[ COMPILER.SIGNATURE ]( Array.prototype.slice.call(arguments,2 ), func_get_arg, 1, [ VARIABLE.INT ] ) ) { + return new PHP.VM.Variable( false ); + } + + if ( arguments[ 2 ][ COMPILER.VARIABLE_VALUE ] < 0 ) { + this[ PHP.Compiler.prototype.ERROR ]( func_get_arg + "(): The argument number should be >= 0", PHP.Constants.E_WARNING, true ); + return new PHP.VM.Variable( false ); + } + + + if ( args[ arguments[ 2 ][ COMPILER.VARIABLE_VALUE ] + 2 ] === undefined ) { + this[ PHP.Compiler.prototype.ERROR ]( func_get_arg + "(): Argument " + arguments[ 2 ][ COMPILER.VARIABLE_VALUE ] + " not passed to function", PHP.Constants.E_CORE_WARNING, true ); + return new PHP.VM.Variable( false ); + } else { + return args[ arguments[ 2 ][ COMPILER.VARIABLE_VALUE ] + 2 ]; + } + + } else if ( functionName === func_get_args ) { + var props = []; + + Array.prototype.slice.call( args, 2 ).forEach(function( val, index ){ + + props.push(item( index, val )); + }); + + return this.array( props ); + } else if ( typeof functionName === "function" ) { + // anonymous lambda function + ret = functionName.apply( this, Array.prototype.slice.call( arguments, 2 ) ); + + } else if ( this[ functionName ] === undefined ) { + this[ PHP.Compiler.prototype.ERROR ]( "Call to undefined function " + functionName + "()", PHP.Constants.E_ERROR, true ); + } else { + ret = this[ functionName ].apply( this, Array.prototype.slice.call( arguments, 2 ) ); + } + + PHP.Utils.CheckRef.call( this, ret, this.FUNCTION_REFS[ functionName ] ); + + + return ret; +}; + +PHP.Modules.prototype[ PHP.Compiler.prototype.TYPE_CHECK ] = function( variable, propertyType, propertyDefault, index, name ) { + + var COMPILER = PHP.Compiler.prototype, + VARIABLE = PHP.VM.Variable.prototype, + classObj, + typeInterface = false; + + classObj = variable[ COMPILER.VARIABLE_VALUE ]; + if ( propertyDefault === undefined || (propertyDefault[ VARIABLE.TYPE ] !== VARIABLE.NULL || variable[ VARIABLE.TYPE ] !== VARIABLE.NULL ) ) { + + var argPassedTo = "Argument " + (index + 1) + " passed to " + name + "() must ", + argGiven, + variableType = variable[ VARIABLE.TYPE ], + errorMsg; + + switch ( variableType ) { + + case VARIABLE.OBJECT: + argGiven = ", instance of " + classObj[ COMPILER.CLASS_NAME ] + " given"; + break; + + case VARIABLE.INT: + argGiven = ", integer given"; + break; + + case VARIABLE.NULL: + argGiven = ", none given"; + break; + + } + + // check if we are looking for implement or instance + // do a check if it exists before getting, so we don't trigger an __autoload + if ( this.$Class.Exists( propertyType ) && this.$Class.Get( propertyType ).prototype[ COMPILER.CLASS_TYPE ] === PHP.VM.Class.INTERFACE) { + typeInterface = true; + } + + + switch( propertyType.toLowerCase() ) { + + case "array": + if ( VARIABLE.ARRAY !== variableType) { + errorMsg = argPassedTo + "be of the type array" + argGiven; + } + break; + + default: + // we are looking for an instance + if ( classObj === null) { + errorMsg = argPassedTo + "be an instance of " + propertyType + argGiven; + } + + else if ( !typeInterface && classObj[ COMPILER.CLASS_NAME ] !== propertyType ) { + // not of same class type + errorMsg = argPassedTo + "be an instance of " + propertyType + argGiven; + + } + + // we are looking for an implementation of interface + else if ( typeInterface && classObj[ PHP.VM.Class.INTERFACES ].indexOf( propertyType ) === -1) { + errorMsg = argPassedTo + "implement interface " + propertyType + argGiven; + } + + } + + + if ( errorMsg !== undefined ) { + this[ COMPILER.ERROR ]( errorMsg , PHP.Constants.E_RECOVERABLE_ERROR, false ); + } + + } + + + +}; + +PHP.Modules.prototype[ PHP.Compiler.prototype.SIGNATURE ] = function( args, name, len, types ) { + var COMPILER = PHP.Compiler.prototype, + $GLOBAL = this[ COMPILER.GLOBAL ], + __FILE__ = "$__FILE__", + VARIABLE = PHP.VM.Variable.prototype, + typeStrings = {}; + + typeStrings[ VARIABLE.NULL ] = "null"; + typeStrings[ VARIABLE.BOOL ] = "boolean"; + typeStrings[ VARIABLE.INT ] = "long"; + typeStrings[ VARIABLE.FLOAT ] = "float"; + typeStrings[ VARIABLE.STRING ] = "string"; + typeStrings[ VARIABLE.ARRAY ] = "array"; + typeStrings[ VARIABLE.OBJECT ] = "object"; + typeStrings[ VARIABLE.RESOURCE ] = "resource"; + + if ( len < 0 && args.length > -len) { + len = -len; + this[ COMPILER.ERROR ]( name + "() expects at most " + len + " parameter" + (( len !== 1 ) ? "s" : "") + ", " + args.length + " given", PHP.Constants.E_WARNING, true ); + return false; + } else if ( args.length !== len && len >= 0 ) { + + this[ COMPILER.ERROR ]( name + "() expects exactly " + len + " parameter" + (( len !== 1 ) ? "s" : "") + ", " + args.length + " given", PHP.Constants.E_WARNING, true ); + return false; + } else { + + if ( Array.isArray( types ) ) { + var fail = false; + types.forEach(function( type, paramIndex ){ + + if ( Array.isArray( type ) ) { + + if ( type.indexOf( args[ paramIndex ][ VARIABLE.TYPE ] ) === -1 ) { + if ( type.indexOf( VARIABLE.STRING ) === -1 || ( args[ paramIndex ][ VARIABLE.CAST_STRING ][ VARIABLE.TYPE ] !== VARIABLE.STRING ) ) { + + this[ COMPILER.ERROR ]( name + "() expects parameter " + ( paramIndex + 1 ) + " to be " + typeStrings[ type[ 0 ] ] + ", " + typeStrings[ args[ paramIndex ][ VARIABLE.TYPE ] ] + " given in " + + $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] + + " on line " + 0, PHP.Constants.E_CORE_WARNING ); + fail = true; + } + } + + } else { + + if ( args[ paramIndex ] !== undefined && type !== args[ paramIndex ][ VARIABLE.TYPE ] && type !== null ) { + + if ( type === VARIABLE.INT && args[ paramIndex ][ VARIABLE.TYPE ] === VARIABLE.BOOL ) { + return; + } + + + if ( type !== VARIABLE.STRING || ( typeof args[ paramIndex ][ VARIABLE.CAST_STRING ] !== "function" ) ) { + this[ COMPILER.ERROR ]( name + "() expects parameter " + ( paramIndex + 1 ) + " to be " + typeStrings[ type ] + ", " + typeStrings[ args[ paramIndex ][ VARIABLE.TYPE ] ] + " given in " + + $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] + + " on line " + 0, PHP.Constants.E_CORE_WARNING ); + fail = true; + } + } + } + + + + }, this); + if ( fail === true ) { + return false; + } + + } + + return true; + } +}; + +(function( MODULES ){ + + var COMPILER = PHP.Compiler.prototype, + lastError, + errorHandler, + reportingLevel = 32767, + shutdownFunc, + shutdownParams, + suppress = false; + + MODULES.$ErrorReset = function() { + lastError = undefined; + errorHandler = undefined; + shutdownFunc = undefined; + shutdownParams = undefined; + suppress = false; + reportingLevel = 32767; // E_ALL + }; + + MODULES.register_shutdown_function = function( func ) { + console.log("registering shutdown"); + shutdownFunc = func; + shutdownParams = Array.prototype.slice.call( arguments, 1 ); + }; + + MODULES.$shutdown = function( ) { + + this.$Class.Shutdown(); + + console.log("shutting down"); + if ( shutdownFunc !== undefined ) { + console.log("yes"); + this.call_user_func.apply( this, [ shutdownFunc ].concat( arguments ) ); + } + }; + + + MODULES[ COMPILER.SUPPRESS ] = function( expr ) { + suppress = true; + + var result = expr(); + + if ( result === undefined ) { + result = new PHP.VM.Variable(); + } + + result[ COMPILER.SUPPRESS ] = true; + + suppress = false; + return result; + }; + + MODULES[ COMPILER.EXCEPTION ] = function( variable ) { + + var methods = {}, + VARIABLE = PHP.VM.Variable.prototype, + caught = false; + + methods[ COMPILER.CATCH ] = function( name, type, $, func ) { + if ( caught ) return methods; + if ( variable[ VARIABLE.TYPE ] === VARIABLE.OBJECT ) { + + var classObj = variable[ COMPILER.VARIABLE_VALUE ]; + + if ( this.$Class.Inherits( classObj, type ) || classObj[ PHP.VM.Class.INTERFACES ].indexOf( type ) !== -1 ) { + $( name, variable ); + caught = true; + func(); + } + } else if ( variable instanceof PHP.Halt && /^Exception$/i.test( type )) { + + if ( variable.catchable !== true ) { + + $( name, new (this.$Class.Get( "Exception" ))( this, new PHP.VM.Variable( variable.msg ) ) ); + caught = true; + func(); + } else { + throw variable; + } + } + return methods; + + }.bind( this ); + + return methods; + }; + + MODULES.error_get_last = function() { + var item = PHP.VM.Array.arrayItem; + + return this.array([ + item("type", lastError.type), + item("message", lastError.message), + item("file", lastError.file), + item("line", lastError.line) + ]); + + }; + + MODULES.error_reporting = function( level ) { + reportingLevel = level[ COMPILER.VARIABLE_VALUE ]; + }; + + MODULES.set_error_handler = function( error_handler, error_types ) { + errorHandler = error_handler; + }; + + MODULES[ COMPILER.ERROR ] = function( msg, level, lineAppend, strict, catchable ) { + + var C = PHP.Constants, + $GLOBAL = this[ COMPILER.GLOBAL ], + __FILE__ = "$__FILE__"; + lastError = { + message: msg, + line: 1, + type: level, + file: $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] + }; + + function checkType( type ) { + + return ((reportingLevel & C[ type ]) === C[ type ]); + } + + if ( lineAppend === false ) { + lineAppend = ", called in " + $GLOBAL( __FILE__ )[ COMPILER.VARIABLE_VALUE ] + " on line 1 and defined in " + $GLOBAL( __FILE__ )[ COMPILER.VARIABLE_VALUE ] + " on line 1"; + } else if ( lineAppend === true ) { + if (this.EVALING === true ) { + lineAppend = " in " + $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] + "(1) : eval()'d code on line 1"; + } else { + lineAppend = " in " + $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] + " on line 1"; + } + } else { + lineAppend = ""; + } + + if ( this.$ini.track_errors == 1 || this.$ini.track_errors == "On") { + $GLOBAL("php_errormsg")[ COMPILER.VARIABLE_VALUE ] = msg; + } + + + if (reportingLevel !== 0) { + if ( suppress === false ) { + if ( errorHandler !== undefined ) { + + + this.call_user_func( + errorHandler, + new PHP.VM.Variable( level ), + new PHP.VM.Variable( msg ), + new PHP.VM.Variable( $GLOBAL(__FILE__)[ COMPILER.VARIABLE_VALUE ] ), + new PHP.VM.Variable( 1 ), + this.array([]) + ); + + } else { + switch ( level ) { + case C.E_ERROR: + this[ COMPILER.DISPLAY_HANDLER ] = false; + throw new PHP.Halt( msg, level, lineAppend, catchable ); + return; + break; + case C.E_RECOVERABLE_ERROR: + this[ COMPILER.DISPLAY_HANDLER ] = false; + // this.$ob( "\nCatchable fatal error: " + msg + lineAppend + "\n"); + + throw new PHP.Halt( msg, level, lineAppend, catchable ); + // throw new PHP.Halt( level ); + return; + break; + + case C.E_WARNING: + case C.E_CORE_WARNING: + case C.E_COMPILE_WARNING: + case C.E_USER_WARNING: + if (this.$ini.display_errors != 0 && this.$ini.display_errors != "Off") { + this.echo( new PHP.VM.Variable("\nWarning: " + msg + lineAppend + "\n")); + } + return; + break; + case C.E_PARSE: + this.echo( new PHP.VM.Variable("\nParse error: " + msg + lineAppend + "\n")); + return; + break; + case C.E_CORE_NOTICE: + case C.E_NOTICE: + if (checkType("E_NOTICE")) { + this.echo( new PHP.VM.Variable("\nNotice: " + msg + lineAppend + "\n")); + return; + } + break; + case C.E_STRICT: + if (checkType("E_STRICT")) { + if ( strict ) { + this.$strict += "Strict Standards: " + msg + lineAppend + "\n"; + } else { + this.echo( new PHP.VM.Variable("\nStrict Standards: " + msg + lineAppend + "\n")); + } + } + return; + break; + case C.E_DEPRECATED: + if (checkType("E_DEPRECATED")) { + this.echo( new PHP.VM.Variable("\nDeprecated: " + msg + lineAppend + "\n")); + return; + } + + break; + + default: + this.echo( new PHP.VM.Variable("\nDefault Warning: " + msg + lineAppend + "\n")); + return; + + + } + } + } + } + + }; + +})( PHP.Modules.prototype ) + + + + + + + + + +PHP.Constants.T_INCLUDE = 262; +PHP.Constants.T_INCLUDE_ONCE = 261; +PHP.Constants.T_EVAL = 260; +PHP.Constants.T_REQUIRE = 259; +PHP.Constants.T_REQUIRE_ONCE = 258; +PHP.Constants.T_LOGICAL_OR = 263; +PHP.Constants.T_LOGICAL_XOR = 264; +PHP.Constants.T_LOGICAL_AND = 265; +PHP.Constants.T_PRINT = 266; +PHP.Constants.T_PLUS_EQUAL = 277; +PHP.Constants.T_MINUS_EQUAL = 276; +PHP.Constants.T_MUL_EQUAL = 275; +PHP.Constants.T_DIV_EQUAL = 274; +PHP.Constants.T_CONCAT_EQUAL = 273; +PHP.Constants.T_MOD_EQUAL = 272; +PHP.Constants.T_AND_EQUAL = 271; +PHP.Constants.T_OR_EQUAL = 270; +PHP.Constants.T_XOR_EQUAL = 269; +PHP.Constants.T_SL_EQUAL = 268; +PHP.Constants.T_SR_EQUAL = 267; +PHP.Constants.T_BOOLEAN_OR = 278; +PHP.Constants.T_BOOLEAN_AND = 279; +PHP.Constants.T_IS_EQUAL = 283; +PHP.Constants.T_IS_NOT_EQUAL = 282; +PHP.Constants.T_IS_IDENTICAL = 281; +PHP.Constants.T_IS_NOT_IDENTICAL = 280; +PHP.Constants.T_IS_SMALLER_OR_EQUAL = 285; +PHP.Constants.T_IS_GREATER_OR_EQUAL = 284; +PHP.Constants.T_SL = 287; +PHP.Constants.T_SR = 286; +PHP.Constants.T_INSTANCEOF = 288; +PHP.Constants.T_INC = 297; +PHP.Constants.T_DEC = 296; +PHP.Constants.T_INT_CAST = 295; +PHP.Constants.T_DOUBLE_CAST = 294; +PHP.Constants.T_STRING_CAST = 293; +PHP.Constants.T_ARRAY_CAST = 292; +PHP.Constants.T_OBJECT_CAST = 291; +PHP.Constants.T_BOOL_CAST = 290; +PHP.Constants.T_UNSET_CAST = 289; +PHP.Constants.T_NEW = 299; +PHP.Constants.T_CLONE = 298; +PHP.Constants.T_EXIT = 300; +PHP.Constants.T_IF = 301; +PHP.Constants.T_ELSEIF = 302; +PHP.Constants.T_ELSE = 303; +PHP.Constants.T_ENDIF = 304; +PHP.Constants.T_LNUMBER = 305; +PHP.Constants.T_DNUMBER = 306; +PHP.Constants.T_STRING = 307; +PHP.Constants.T_STRING_VARNAME = 308; +PHP.Constants.T_VARIABLE = 309; +PHP.Constants.T_NUM_STRING = 310; +PHP.Constants.T_INLINE_HTML = 311; +PHP.Constants.T_CHARACTER = 312; +PHP.Constants.T_BAD_CHARACTER = 313; +PHP.Constants.T_ENCAPSED_AND_WHITESPACE = 314; +PHP.Constants.T_CONSTANT_ENCAPSED_STRING = 315; +PHP.Constants.T_ECHO = 316; +PHP.Constants.T_DO = 317; +PHP.Constants.T_WHILE = 318; +PHP.Constants.T_ENDWHILE = 319; +PHP.Constants.T_FOR = 320; +PHP.Constants.T_ENDFOR = 321; +PHP.Constants.T_FOREACH = 322; +PHP.Constants.T_ENDFOREACH = 323; +PHP.Constants.T_DECLARE = 324; +PHP.Constants.T_ENDDECLARE = 325; +PHP.Constants.T_AS = 326; +PHP.Constants.T_SWITCH = 327; +PHP.Constants.T_ENDSWITCH = 328; +PHP.Constants.T_CASE = 329; +PHP.Constants.T_DEFAULT = 330; +PHP.Constants.T_BREAK = 331; +PHP.Constants.T_CONTINUE = 332; +PHP.Constants.T_GOTO = 333; +PHP.Constants.T_FUNCTION = 334; +PHP.Constants.T_CONST = 335; +PHP.Constants.T_RETURN = 336; +PHP.Constants.T_TRY = 337; +PHP.Constants.T_CATCH = 338; +PHP.Constants.T_THROW = 339; +PHP.Constants.T_USE = 340; +//PHP.Constants.T_INSTEADOF = ; +PHP.Constants.T_GLOBAL = 341; +PHP.Constants.T_STATIC = 347; +PHP.Constants.T_ABSTRACT = 346; +PHP.Constants.T_FINAL = 345; +PHP.Constants.T_PRIVATE = 344; +PHP.Constants.T_PROTECTED = 343; +PHP.Constants.T_PUBLIC = 342; +PHP.Constants.T_VAR = 348; +PHP.Constants.T_UNSET = 349; +PHP.Constants.T_ISSET = 350; +PHP.Constants.T_EMPTY = 351; +PHP.Constants.T_HALT_COMPILER = 352; +PHP.Constants.T_CLASS = 353; +//PHP.Constants.T_TRAIT = ; +PHP.Constants.T_INTERFACE = 354; +PHP.Constants.T_EXTENDS = 355; +PHP.Constants.T_IMPLEMENTS = 356; +PHP.Constants.T_OBJECT_OPERATOR = 357; +PHP.Constants.T_DOUBLE_ARROW = 358; +PHP.Constants.T_LIST = 359; +PHP.Constants.T_ARRAY = 360; +//PHP.Constants.T_CALLABLE = ; +PHP.Constants.T_CLASS_C = 361; +PHP.Constants.T_TRAIT_C = 381; +PHP.Constants.T_METHOD_C = 362; +PHP.Constants.T_FUNC_C = 363; +PHP.Constants.T_LINE = 364; +PHP.Constants.T_FILE = 365; +PHP.Constants.T_COMMENT = 366; +PHP.Constants.T_DOC_COMMENT = 367; +PHP.Constants.T_OPEN_TAG = 368; +PHP.Constants.T_OPEN_TAG_WITH_ECHO = 369; +PHP.Constants.T_CLOSE_TAG = 370; +PHP.Constants.T_WHITESPACE = 371; +PHP.Constants.T_START_HEREDOC = 372; +PHP.Constants.T_END_HEREDOC = 373; +PHP.Constants.T_DOLLAR_OPEN_CURLY_BRACES = 374; +PHP.Constants.T_CURLY_OPEN = 375; +PHP.Constants.T_PAAMAYIM_NEKUDOTAYIM = 376; +PHP.Constants.T_DOUBLE_COLON = 376; +PHP.Constants.T_NAMESPACE = 377; +PHP.Constants.T_NS_C = 378; +PHP.Constants.T_DIR = 379; +PHP.Constants.T_NS_SEPARATOR = 380;/* +* @author Niklas von Hertzen +* @created 28.6.2012 +* @website http://hertzen.com + */ + + +PHP.Modules.prototype.token_get_all = function( code ) { + var VARIABLE = PHP.VM.Variable.prototype, + COMPILER = PHP.Compiler.prototype; + + + if ( !this[ COMPILER.SIGNATURE ]( arguments, "token_get_all", 1, [ [ VARIABLE.STRING, VARIABLE.NULL ] ] ) ) { + return new PHP.VM.Variable( null ); + } + + switch( code[ VARIABLE.TYPE ] ) { + + case VARIABLE.BOOL: + if ( code[ COMPILER.VARIABLE_VALUE ] === true ) { + return PHP.VM.Array.fromObject.call( this, PHP.Lexer( "1" )); + } else { + return PHP.VM.Array.fromObject.call( this, PHP.Lexer( null )); + } + break; + case VARIABLE.STRING: + case VARIABLE.NULL: + return PHP.VM.Array.fromObject.call( this, PHP.Lexer( code[ COMPILER.VARIABLE_VALUE ] )); + break; + + default: + return PHP.VM.Array.fromObject.call( this, PHP.Lexer( code[ VARIABLE.CAST_STRING ][ COMPILER.VARIABLE_VALUE ] )); + + } + + + +};/* +* @author Niklas von Hertzen +* @created 15.6.2012 +* @website http://hertzen.com + */ + +/* token_name — Get the symbolic name of a given PHP token + * string token_name ( int $token ) + */ + +PHP.Modules.prototype.token_name = function( token ) { + + if ( !this[ PHP.Compiler.prototype.SIGNATURE ]( arguments, "token_name", 1, [ PHP.VM.Variable.prototype.INT ] ) ) { + return new PHP.VM.Variable( null ); + } + + // TODO invert this for faster performance + var constants = {}; + constants.T_INCLUDE = 262; + constants.T_INCLUDE_ONCE = 261; + constants.T_EVAL = 260; + constants.T_REQUIRE = 259; + constants.T_REQUIRE_ONCE = 258; + constants.T_LOGICAL_OR = 263; + constants.T_LOGICAL_XOR = 264; + constants.T_LOGICAL_AND = 265; + constants.T_PRINT = 266; + constants.T_PLUS_EQUAL = 277; + constants.T_MINUS_EQUAL = 276; + constants.T_MUL_EQUAL = 275; + constants.T_DIV_EQUAL = 274; + constants.T_CONCAT_EQUAL = 273; + constants.T_MOD_EQUAL = 272; + constants.T_AND_EQUAL = 271; + constants.T_OR_EQUAL = 270; + constants.T_XOR_EQUAL = 269; + constants.T_SL_EQUAL = 268; + constants.T_SR_EQUAL = 267; + constants.T_BOOLEAN_OR = 278; + constants.T_BOOLEAN_AND = 279; + constants.T_IS_EQUAL = 283; + constants.T_IS_NOT_EQUAL = 282; + constants.T_IS_IDENTICAL = 281; + constants.T_IS_NOT_IDENTICAL = 280; + constants.T_IS_SMALLER_OR_EQUAL = 285; + constants.T_IS_GREATER_OR_EQUAL = 284; + constants.T_SL = 287; + constants.T_SR = 286; + constants.T_INSTANCEOF = 288; + constants.T_INC = 297; + constants.T_DEC = 296; + constants.T_INT_CAST = 295; + constants.T_DOUBLE_CAST = 294; + constants.T_STRING_CAST = 293; + constants.T_ARRAY_CAST = 292; + constants.T_OBJECT_CAST = 291; + constants.T_BOOL_CAST = 290; + constants.T_UNSET_CAST = 289; + constants.T_NEW = 299; + constants.T_CLONE = 298; + constants.T_EXIT = 300; + constants.T_IF = 301; + constants.T_ELSEIF = 302; + constants.T_ELSE = 303; + constants.T_ENDIF = 304; + constants.T_LNUMBER = 305; + constants.T_DNUMBER = 306; + constants.T_STRING = 307; + constants.T_STRING_VARNAME = 308; + constants.T_VARIABLE = 309; + constants.T_NUM_STRING = 310; + constants.T_INLINE_HTML = 311; + constants.T_CHARACTER = 312; + constants.T_BAD_CHARACTER = 313; + constants.T_ENCAPSED_AND_WHITESPACE = 314; + constants.T_CONSTANT_ENCAPSED_STRING = 315; + constants.T_ECHO = 316; + constants.T_DO = 317; + constants.T_WHILE = 318; + constants.T_ENDWHILE = 319; + constants.T_FOR = 320; + constants.T_ENDFOR = 321; + constants.T_FOREACH = 322; + constants.T_ENDFOREACH = 323; + constants.T_DECLARE = 324; + constants.T_ENDDECLARE = 325; + constants.T_AS = 326; + constants.T_SWITCH = 327; + constants.T_ENDSWITCH = 328; + constants.T_CASE = 329; + constants.T_DEFAULT = 330; + constants.T_BREAK = 331; + constants.T_CONTINUE = 332; + constants.T_GOTO = 333; + constants.T_FUNCTION = 334; + constants.T_CONST = 335; + constants.T_RETURN = 336; + constants.T_TRY = 337; + constants.T_CATCH = 338; + constants.T_THROW = 339; + constants.T_USE = 340; + //constants.T_INSTEADOF = ; + constants.T_GLOBAL = 341; + constants.T_STATIC = 347; + constants.T_ABSTRACT = 346; + constants.T_FINAL = 345; + constants.T_PRIVATE = 344; + constants.T_PROTECTED = 343; + constants.T_PUBLIC = 342; + constants.T_VAR = 348; + constants.T_UNSET = 349; + constants.T_ISSET = 350; + constants.T_EMPTY = 351; + constants.T_HALT_COMPILER = 352; + constants.T_CLASS = 353; + //constants.T_TRAIT = ; + constants.T_INTERFACE = 354; + constants.T_EXTENDS = 355; + constants.T_IMPLEMENTS = 356; + constants.T_OBJECT_OPERATOR = 357; + constants.T_DOUBLE_ARROW = 358; + constants.T_LIST = 359; + constants.T_ARRAY = 360; + //constants.T_CALLABLE = ; + constants.T_CLASS_C = 361; + //constants.T_TRAIT_C = ; + constants.T_METHOD_C = 362; + constants.T_FUNC_C = 363; + constants.T_LINE = 364; + constants.T_FILE = 365; + constants.T_COMMENT = 366; + constants.T_DOC_COMMENT = 367; + constants.T_OPEN_TAG = 368; + constants.T_OPEN_TAG_WITH_ECHO = 369; + constants.T_CLOSE_TAG = 370; + constants.T_WHITESPACE = 371; + constants.T_START_HEREDOC = 372; + constants.T_END_HEREDOC = 373; + constants.T_DOLLAR_OPEN_CURLY_BRACES = 374; + constants.T_CURLY_OPEN = 375; + constants.T_DOUBLE_COLON = 376; + constants.T_PAAMAYIM_NEKUDOTAYIM = 376; + constants.T_NAMESPACE = 377; + constants.T_NS_C = 378; + constants.T_DIR = 379; + constants.T_NS_SEPARATOR = 380; + + + + for (var key in constants) { + if (constants[ key ] === token[ PHP.Compiler.prototype.VARIABLE_VALUE ]) { + return new PHP.VM.Variable( key ); + } + } + + return new PHP.VM.Variable( "UNKNOWN" ); + + + + + +};PHP.Lexer = function( src, ini ) { + + + var heredoc, + lineBreaker = function( result ) { + if (result.match(/\n/) !== null) { + var quote = result.substring(0, 1); + result = '[' + result.split(/\n/).join( quote + "," + quote ) + '].join("\\n")'; + + } + + return result; + }, + prev, + + openTag = (ini === undefined || (/^(on|true|1)$/i.test(ini.short_open_tag) ) ? /(\<\?php\s|\<\?|\<\%|\