idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
8,700
public function getVariableForWrite ( $ name , CompilationContext $ compilationContext , array $ statement = null ) { if ( $ this -> globalsManager -> isSuperGlobal ( $ name ) ) { if ( ! $ this -> hasVariable ( $ name ) ) { $ superVar = new Variable ( 'variable' , $ name , $ compilationContext -> branchManager -> getCurrentBranch ( ) ) ; $ superVar -> setIsInitialized ( true , $ compilationContext ) ; $ superVar -> setDynamicTypes ( 'array' ) ; $ superVar -> increaseMutates ( ) ; $ superVar -> increaseUses ( ) ; $ superVar -> setIsExternal ( true ) ; $ superVar -> setUsed ( true , $ statement ) ; $ this -> addRawVariable ( $ superVar ) ; return $ superVar ; } } if ( ! $ this -> hasVariable ( $ name ) ) { throw new CompilerException ( "Cannot mutate variable '" . $ name . "' because it wasn't defined" , $ statement ) ; } $ variable = $ this -> getVariable ( $ name ) ; $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; if ( ! $ compilationContext -> insideCycle ) { $ variable -> setUsed ( false , $ statement ) ; } else { $ variable -> setUsed ( true , $ statement ) ; } return $ variable ; }
Return a variable in the symbol table it will be used for a write operation Some variables aren t writable themselves but their members do .
8,701
public function getTempVariable ( $ type , CompilationContext $ compilationContext ) { $ compilationContext = $ compilationContext ? : $ this -> compilationContext ; $ tempVar = $ this -> getNextTempVar ( ) ; $ variable = $ this -> addVariable ( $ type , '_' . $ tempVar , $ compilationContext ) ; $ variable -> setTemporal ( true ) ; return $ variable ; }
Returns a temporal variable .
8,702
public function getTempVariableForWrite ( $ type , CompilationContext $ context , $ init = true ) { $ variable = $ this -> reuseTempVariable ( $ type , 'heap' ) ; if ( \ is_object ( $ variable ) ) { $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; if ( $ init && ( 'variable' == $ type || 'string' == $ type || 'array' == $ type ) ) { $ variable -> initVariant ( $ context ) ; } return $ variable ; } $ tempVar = $ this -> getNextTempVar ( ) ; $ variable = $ this -> addVariable ( $ type , '_' . $ tempVar , $ context ) ; $ variable -> setIsInitialized ( true , $ context ) ; $ variable -> setTemporal ( true ) ; $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; if ( 'variable' == $ type || 'string' == $ type || 'array' == $ type ) { $ variable -> initVariant ( $ context ) ; } $ this -> registerTempVariable ( $ type , 'heap' , $ variable ) ; return $ variable ; }
Creates a temporary variable to be used in a write operation .
8,703
public function getTempNonTrackedVariable ( $ type , CompilationContext $ context , $ initNonReferenced = false ) { $ variable = $ this -> reuseTempVariable ( $ type , 'non-tracked' ) ; if ( \ is_object ( $ variable ) ) { $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; if ( $ initNonReferenced ) { $ variable -> initNonReferenced ( $ context ) ; } return $ variable ; } $ tempVar = $ this -> getNextTempVar ( ) ; $ variable = $ this -> addVariable ( $ type , '_' . $ tempVar , $ context ) ; $ variable -> setIsInitialized ( true , $ context ) ; $ variable -> setTemporal ( true ) ; $ variable -> setMemoryTracked ( false ) ; $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; $ this -> registerTempVariable ( $ type , 'non-tracked' , $ variable ) ; if ( $ initNonReferenced ) { $ variable -> initNonReferenced ( $ context ) ; } return $ variable ; }
Creates a temporary variable to be used to point to a heap variable These kind of variables MUST not be tracked by the Zephir memory manager .
8,704
public function addTemp ( $ type , CompilationContext $ context ) { $ tempVar = $ this -> getNextTempVar ( ) ; $ variable = $ this -> addVariable ( $ type , '_' . $ tempVar , $ context ) ; $ variable -> setIsInitialized ( true , $ context ) ; $ variable -> setTemporal ( true ) ; $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; return $ variable ; }
Creates a temporary variable .
8,705
public function getTempVariableForObserve ( $ type , CompilationContext $ context ) { $ variable = $ this -> reuseTempVariable ( $ type , 'observe' ) ; if ( \ is_object ( $ variable ) ) { $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; $ variable -> observeVariant ( $ context ) ; return $ variable ; } $ tempVar = $ this -> getNextTempVar ( ) ; $ variable = $ this -> addVariable ( $ type , '_' . $ tempVar , $ context ) ; $ variable -> setIsInitialized ( true , $ context ) ; $ variable -> setTemporal ( true ) ; $ variable -> increaseUses ( ) ; $ variable -> increaseMutates ( ) ; $ variable -> observeVariant ( $ context ) ; $ this -> registerTempVariable ( $ type , 'observe' , $ variable ) ; return $ variable ; }
Creates a temporary variable to be used as intermediate variable of a read operation Variables are automatically tracked by the memory manager .
8,706
public function markTemporalVariablesIdle ( CompilationContext $ compilationContext ) { $ compilationContext = $ compilationContext ? : $ this -> compilationContext ; $ branchId = $ compilationContext -> branchManager -> getCurrentBranchId ( ) ; if ( ! isset ( $ this -> branchTempVariables [ $ branchId ] ) ) { return ; } foreach ( $ this -> branchTempVariables [ $ branchId ] as $ location => $ typeVariables ) { foreach ( $ typeVariables as $ type => $ variables ) { foreach ( $ variables as $ variable ) { $ pos = strpos ( $ variable -> getName ( ) , Variable :: BRANCH_MAGIC ) ; $ otherBranchId = 1 ; if ( $ pos > - 1 ) { $ otherBranchId = ( int ) ( substr ( $ variable -> getName ( ) , $ pos + \ strlen ( Variable :: BRANCH_MAGIC ) ) ) ; } if ( $ branchId == $ otherBranchId ) { $ variable -> setIdle ( true ) ; } } } } }
Traverses temporal variables created in a specific branch marking them as idle .
8,707
protected function registerTempVariable ( $ type , $ location , Variable $ variable , CompilationContext $ compilationContext = null ) { $ compilationContext = $ compilationContext ? : $ this -> compilationContext ; $ branchId = $ compilationContext -> branchManager -> getCurrentBranchId ( ) ; if ( ! isset ( $ this -> branchTempVariables [ $ branchId ] [ $ location ] [ $ type ] ) ) { $ this -> branchTempVariables [ $ branchId ] [ $ location ] [ $ type ] = [ ] ; } $ this -> branchTempVariables [ $ branchId ] [ $ location ] [ $ type ] [ ] = $ variable ; }
Register a variable as temporal .
8,708
protected function reuseTempVariable ( $ type , $ location , CompilationContext $ compilationContext = null ) { $ compilationContext = $ compilationContext ? : $ this -> compilationContext ; $ branchId = $ compilationContext -> branchManager -> getCurrentBranchId ( ) ; if ( isset ( $ this -> branchTempVariables [ $ branchId ] [ $ location ] [ $ type ] ) ) { foreach ( $ this -> branchTempVariables [ $ branchId ] [ $ location ] [ $ type ] as $ variable ) { if ( ! $ variable -> isDoublePointer ( ) ) { if ( $ variable -> isIdle ( ) ) { $ variable -> setIdle ( false ) ; return $ variable ; } } } } return null ; }
Reuse variables marked as idle after leave a branch .
8,709
public function increaseMutations ( $ variable ) { if ( isset ( $ this -> mutations [ $ variable ] ) ) { ++ $ this -> mutations [ $ variable ] ; } else { $ this -> mutations [ $ variable ] = 1 ; } return $ this ; }
Increase the number of mutations a variable has inside a statement block .
8,710
public function passExpression ( array $ expression ) { switch ( $ expression [ 'type' ] ) { case 'bool' : case 'double' : case 'int' : case 'uint' : case 'long' : case 'ulong' : case 'string' : case 'istring' : case 'null' : case 'char' : case 'uchar' : case 'empty-array' : case 'variable' : case 'constant' : case 'static-constant-access' : case 'closure' : case 'closure-arrow' : case 'reference' : break ; case 'sub' : case 'add' : case 'div' : case 'mul' : case 'mod' : case 'and' : case 'or' : case 'concat' : case 'equals' : case 'identical' : case 'not-identical' : case 'not-equals' : case 'less' : case 'greater' : case 'greater-equal' : case 'less-equal' : case 'bitwise_and' : case 'bitwise_or' : case 'bitwise_xor' : case 'bitwise_shiftleft' : case 'bitwise_shiftright' : case 'irange' : case 'erange' : $ this -> passExpression ( $ expression [ 'left' ] ) ; $ this -> passExpression ( $ expression [ 'right' ] ) ; break ; case 'typeof' : case 'not' : $ this -> passExpression ( $ expression [ 'left' ] ) ; break ; case 'mcall' : case 'fcall' : case 'scall' : $ this -> passCall ( $ expression ) ; break ; case 'array' : $ this -> passArray ( $ expression ) ; break ; case 'new' : $ this -> passNew ( $ expression ) ; break ; case 'property-access' : case 'property-dynamic-access' : case 'property-string-access' : case 'static-property-access' : case 'array-access' : $ this -> passExpression ( $ expression [ 'left' ] ) ; break ; case 'isset' : case 'empty' : case 'instanceof' : case 'require' : case 'clone' : case 'likely' : case 'unlikely' : case 'ternary' : $ this -> passExpression ( $ expression [ 'left' ] ) ; break ; case 'fetch' : $ this -> increaseMutations ( $ expression [ 'left' ] [ 'value' ] ) ; $ this -> passExpression ( $ expression [ 'right' ] ) ; break ; case 'minus' : $ this -> passExpression ( $ expression [ 'left' ] ) ; break ; case 'list' : $ this -> passExpression ( $ expression [ 'left' ] ) ; break ; case 'cast' : case 'type-hint' : $ this -> passExpression ( $ expression [ 'right' ] ) ; break ; default : echo 'MutateGathererPassType=' , $ expression [ 'type' ] , PHP_EOL ; break ; } }
Pass expressions .
8,711
private function reslovePrototypesPath ( ) { $ prototypesPath = $ this -> prototypesPath ; if ( empty ( $ prototypesPath ) ) { $ prototypesPath = \ dirname ( __DIR__ ) . '/prototypes' ; } if ( ! is_dir ( $ prototypesPath ) || ! is_readable ( $ prototypesPath ) ) { throw new IllegalStateException ( 'Unable to resolve internal prototypes directory.' ) ; } return $ prototypesPath ; }
Resolves path to the internal prototypes .
8,712
private function resolveOptimizersPath ( ) { $ optimizersPath = $ this -> optimizersPath ; if ( empty ( $ optimizersPath ) ) { $ optimizersPath = __DIR__ . '/Optimizers' ; } if ( ! is_dir ( $ optimizersPath ) || ! is_readable ( $ optimizersPath ) ) { throw new IllegalStateException ( 'Unable to resolve internal optimizers directory.' ) ; } return $ optimizersPath ; }
Resolves path to the internal optimizers .
8,713
public function loadExternalClass ( $ className , $ location ) { $ filePath = $ location . \ DIRECTORY_SEPARATOR . strtolower ( str_replace ( '\\' , \ DIRECTORY_SEPARATOR , $ className ) ) . '.zep' ; $ className = implode ( '\\' , array_map ( 'ucfirst' , explode ( '\\' , $ className ) ) ) ; if ( isset ( $ this -> files [ $ className ] ) ) { return true ; } if ( ! file_exists ( $ filePath ) ) { return false ; } $ compilerFile = $ this -> compilerFileFactory -> create ( $ className , $ filePath ) ; $ compilerFile -> setIsExternal ( true ) ; $ compilerFile -> preCompile ( $ this ) ; $ this -> files [ $ className ] = $ compilerFile ; $ this -> definitions [ $ className ] = $ compilerFile -> getClassDefinition ( ) ; return true ; }
Loads a class definition in an external dependency .
8,714
public function isClass ( $ className ) { foreach ( $ this -> definitions as $ key => $ value ) { if ( ! strcasecmp ( $ key , $ className ) && 'class' === $ value -> getType ( ) ) { return true ; } } if ( \ count ( $ this -> externalDependencies ) ) { foreach ( $ this -> externalDependencies as $ namespace => $ location ) { if ( preg_match ( '#^' . $ namespace . '\\\\#i' , $ className ) ) { return $ this -> loadExternalClass ( $ className , $ location ) ; } } } return false ; }
Allows to check if a class is part of the compiled extension .
8,715
public function addClassDefinition ( CompilerFileAnonymous $ file , ClassDefinition $ classDefinition ) { $ this -> definitions [ $ classDefinition -> getCompleteName ( ) ] = $ classDefinition ; $ this -> anonymousFiles [ $ classDefinition -> getCompleteName ( ) ] = $ file ; }
Inserts an anonymous class definition in the compiler .
8,716
public function setExtensionGlobals ( array $ globals ) { foreach ( $ globals as $ key => $ value ) { $ this -> globals [ $ key ] = $ value ; } }
Sets extensions globals .
8,717
public function getGccFlags ( $ development = false ) { if ( is_windows ( ) ) { return '' ; } $ gccFlags = getenv ( 'CFLAGS' ) ; if ( ! \ is_string ( $ gccFlags ) ) { if ( false === $ development ) { $ gccVersion = $ this -> getGccVersion ( ) ; if ( version_compare ( $ gccVersion , '4.6.0' , '>=' ) ) { $ gccFlags = '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1' ; } else { $ gccFlags = '-O2 -fvisibility=hidden -Wparentheses -DZEPHIR_RELEASE=1' ; } } else { $ gccFlags = '-O0 -g3' ; } } return $ gccFlags ; }
Returns GCC flags for current compilation .
8,718
public function preCompileHeaders ( ) { if ( is_windows ( ) ) { return ; } $ phpIncludes = $ this -> getPhpIncludeDirs ( ) ; foreach ( new \ DirectoryIterator ( 'ext/kernel' ) as $ file ) { if ( $ file -> isDir ( ) ) { continue ; } if ( preg_match ( '/\.h$/' , $ file ) ) { $ path = $ file -> getRealPath ( ) ; $ command = sprintf ( 'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch' , $ file -> getBaseName ( ) , $ phpIncludes , $ file -> getBaseName ( ) ) ; if ( ! file_exists ( $ path . '.gch' ) || filemtime ( $ path ) > filemtime ( $ path . '.gch' ) ) { $ this -> filesystem -> system ( $ command , 'stdout' , 'compile-header' ) ; } } } }
Pre - compile headers to speed up compilation .
8,719
public function api ( array $ options = [ ] , $ fromGenerate = false ) { if ( ! $ fromGenerate ) { $ this -> generate ( ) ; } $ templatesPath = $ this -> templatesPath ; if ( null === $ templatesPath ) { $ templatesPath = \ dirname ( __DIR__ ) . '/templates' ; } $ documentator = new Documentation ( $ this -> files , $ this -> config , $ templatesPath , $ options ) ; $ documentator -> setLogger ( $ this -> logger ) ; $ this -> logger -> info ( 'Generating API into ' . $ documentator -> getOutputDirectory ( ) ) ; $ documentator -> build ( ) ; }
Generate a HTML API .
8,720
public function stubs ( $ fromGenerate = false ) { if ( ! $ fromGenerate ) { $ this -> generate ( ) ; } $ this -> logger -> info ( 'Generating stubs...' ) ; $ stubsGenerator = new Stubs \ Generator ( $ this -> files , $ this -> config ) ; $ path = $ this -> config -> get ( 'path' , 'stubs' ) ; $ path = str_replace ( '%version%' , $ this -> config -> get ( 'version' ) , $ path ) ; $ path = str_replace ( '%namespace%' , ucfirst ( $ this -> config -> get ( 'namespace' ) ) , $ path ) ; $ stubsGenerator -> generate ( $ path ) ; }
Generate IDE stubs .
8,721
public function processCodeInjection ( array $ entries , $ section = 'request' ) { $ codes = [ ] ; $ includes = [ ] ; if ( isset ( $ entries [ $ section ] ) ) { foreach ( $ entries [ $ section ] as $ entry ) { if ( isset ( $ entry [ 'code' ] ) && ! empty ( $ entry [ 'code' ] ) ) { $ codes [ ] = $ entry [ 'code' ] . ';' ; } if ( isset ( $ entry [ 'include' ] ) && ! empty ( $ entry [ 'include' ] ) ) { $ includes [ ] = '#include "' . $ entry [ 'include' ] . '"' ; } } } return [ implode ( PHP_EOL , $ includes ) , implode ( "\n\t" , $ codes ) ] ; }
Process extension code injection .
8,722
public function generatePackageDependenciesM4 ( $ contentM4 ) { $ packageDependencies = $ this -> config -> get ( 'package-dependencies' ) ; if ( \ is_array ( $ packageDependencies ) ) { $ pkgconfigM4 = $ this -> backend -> getTemplateFileContents ( 'pkg-config.m4' ) ; $ pkgconfigCheckM4 = $ this -> backend -> getTemplateFileContents ( 'pkg-config-check.m4' ) ; $ extraCFlags = '' ; foreach ( $ packageDependencies as $ pkg => $ version ) { $ pkgM4Buf = $ pkgconfigCheckM4 ; $ operator = '=' ; $ operatorCmd = '--exact-version' ; $ ar = explode ( '=' , $ version ) ; if ( 1 == \ count ( $ ar ) ) { if ( '*' == $ version ) { $ version = '0.0.0' ; $ operator = '>=' ; $ operatorCmd = '--atleast-version' ; } } else { switch ( $ ar [ 0 ] ) { case '<' : $ operator = '<=' ; $ operatorCmd = '--max-version' ; $ version = trim ( $ ar [ 1 ] ) ; break ; case '>' : $ operator = '>=' ; $ operatorCmd = '--atleast-version' ; $ version = trim ( $ ar [ 1 ] ) ; break ; default : $ version = trim ( $ ar [ 1 ] ) ; break ; } } $ toReplace = [ '%PACKAGE_LOWER%' => strtolower ( $ pkg ) , '%PACKAGE_UPPER%' => strtoupper ( $ pkg ) , '%PACKAGE_REQUESTED_VERSION%' => $ operator . ' ' . $ version , '%PACKAGE_PKG_CONFIG_COMPARE_VERSION%' => $ operatorCmd . '=' . $ version , ] ; foreach ( $ toReplace as $ mark => $ replace ) { $ pkgM4Buf = str_replace ( $ mark , $ replace , $ pkgM4Buf ) ; } $ pkgconfigM4 .= $ pkgM4Buf ; $ extraCFlags .= '$PHP_' . strtoupper ( $ pkg ) . '_INCS ' ; } $ contentM4 = str_replace ( '%PROJECT_EXTRA_CFLAGS%' , '%PROJECT_EXTRA_CFLAGS% ' . $ extraCFlags , $ contentM4 ) ; $ contentM4 = str_replace ( '%PROJECT_PACKAGE_DEPENDENCIES%' , $ pkgconfigM4 , $ contentM4 ) ; return $ contentM4 ; } $ contentM4 = str_replace ( '%PROJECT_PACKAGE_DEPENDENCIES%' , '' , $ contentM4 ) ; return $ contentM4 ; }
Generate package - dependencies config for m4 .
8,723
private function preCompile ( $ filePath ) { if ( ! $ this -> parserManager -> isAvailable ( ) ) { throw new IllegalStateException ( $ this -> parserManager -> requirements ( ) ) ; } if ( preg_match ( '#\.zep$#' , $ filePath ) ) { $ className = str_replace ( \ DIRECTORY_SEPARATOR , '\\' , $ filePath ) ; $ className = preg_replace ( '#.zep$#' , '' , $ className ) ; $ className = implode ( '\\' , array_map ( 'ucfirst' , explode ( '\\' , $ className ) ) ) ; $ compilerFile = $ this -> compilerFileFactory -> create ( $ className , $ filePath ) ; $ compilerFile -> preCompile ( $ this ) ; $ this -> files [ $ className ] = $ compilerFile ; $ this -> definitions [ $ className ] = $ compilerFile -> getClassDefinition ( ) ; } }
Pre - compiles classes creating a CompilerFile definition .
8,724
private function recursivePreCompile ( $ path ) { if ( ! is_dir ( $ path ) ) { throw new InvalidArgumentException ( sprintf ( "An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory." , getcwd ( ) , \ DIRECTORY_SEPARATOR , $ path ) ) ; } $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ path ) , \ RecursiveIteratorIterator :: SELF_FIRST ) ; $ files = [ ] ; foreach ( $ iterator as $ item ) { if ( ! $ item -> isDir ( ) ) { $ files [ ] = $ item -> getPathname ( ) ; } } sort ( $ files , SORT_STRING ) ; foreach ( $ files as $ file ) { $ this -> preCompile ( $ file ) ; } }
Recursively pre - compiles all sources found in the given path .
8,725
private function recursiveDeletePath ( $ path , $ mask ) { if ( ! file_exists ( $ path ) || ! is_dir ( $ path ) || ! is_readable ( $ path ) ) { $ this -> logger -> warning ( "Directory '{$path}' is not readable. Skip..." ) ; return ; } $ objects = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ path ) , \ RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ objects as $ name => $ object ) { if ( preg_match ( $ mask , $ name ) ) { @ unlink ( $ name ) ; } } }
Recursively deletes files in a specified location .
8,726
private function loadConstantsSources ( $ constantsSources ) { foreach ( $ constantsSources as $ constantsSource ) { if ( ! file_exists ( $ constantsSource ) ) { throw new Exception ( "File '" . $ constantsSource . "' with constants definitions" ) ; } foreach ( file ( $ constantsSource ) as $ line ) { if ( preg_match ( '/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+([0-9]+)/' , $ line , $ matches ) ) { $ this -> constants [ $ matches [ 1 ] ] = [ 'int' , $ matches [ 2 ] ] ; continue ; } if ( preg_match ( '/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+(\'(.){1}\')/' , $ line , $ matches ) ) { $ this -> constants [ $ matches [ 1 ] ] = [ 'char' , $ matches [ 3 ] ] ; } } } }
Registers C - constants as PHP constants from a C - file .
8,727
private function processAddSources ( $ sources , $ project ) { $ groupSources = [ ] ; foreach ( $ sources as $ source ) { $ dirName = str_replace ( \ DIRECTORY_SEPARATOR , '/' , \ dirname ( $ source ) ) ; if ( ! isset ( $ groupSources [ $ dirName ] ) ) { $ groupSources [ $ dirName ] = [ ] ; } $ groupSources [ $ dirName ] [ ] = basename ( $ source ) ; } $ groups = [ ] ; foreach ( $ groupSources as $ dirname => $ files ) { $ groups [ ] = 'ADD_SOURCES(configure_module_dirname + "/' . $ dirname . '", "' . implode ( ' ' , $ files ) . '", "' . $ project . '");' ; } return $ groups ; }
Process config . w32 sections .
8,728
private function assertRequiredExtensionsIsPresent ( ) { $ extensionRequires = $ this -> config -> get ( 'extensions' , 'requires' ) ; if ( true === empty ( $ extensionRequires ) ) { return ; } $ extensions = [ ] ; foreach ( $ extensionRequires as $ key => $ value ) { if ( false === \ extension_loaded ( $ value ) ) { $ extensions [ ] = $ value ; } } if ( false === empty ( $ extensions ) ) { throw new RuntimeException ( sprintf ( 'Could not load extension: %s. You must add extensions above before build this extension.' , implode ( ', ' , $ extensions ) ) ) ; } }
Ensure that required extensions is present .
8,729
private function checkKernelFile ( $ src , $ dst ) { if ( preg_match ( '#kernels/ZendEngine[2-9]/concat\.#' , $ src ) ) { return true ; } if ( ! file_exists ( $ dst ) ) { return false ; } return md5_file ( $ src ) == md5_file ( $ dst ) ; }
Checks if a file must be copied .
8,730
private function checkKernelFiles ( ) { $ kernelPath = 'ext' . \ DIRECTORY_SEPARATOR . 'kernel' ; if ( ! file_exists ( $ kernelPath ) ) { if ( ! mkdir ( $ kernelPath , 0775 , true ) ) { throw new Exception ( "Cannot create kernel directory: {$kernelPath}" ) ; } } $ kernelPath = realpath ( $ kernelPath ) ; $ sourceKernelPath = $ this -> backend -> getInternalKernelPath ( ) ; $ configured = $ this -> recursiveProcess ( $ sourceKernelPath , $ kernelPath , '@.*\.[ch]$@' , [ $ this , 'checkKernelFile' ] ) ; if ( ! $ configured ) { $ this -> logger -> info ( 'Cleaning old kernel files...' ) ; $ this -> recursiveDeletePath ( $ kernelPath , '@^.*\.[lcho]$@' ) ; @ mkdir ( $ kernelPath ) ; $ this -> logger -> info ( 'Copying new kernel files...' ) ; $ this -> recursiveProcess ( $ sourceKernelPath , $ kernelPath , '@^.*\.[ch]$@' ) ; } return ! $ configured ; }
Checks which files in the base kernel must be copied .
8,731
private function checkDirectory ( ) { $ namespace = $ this -> config -> get ( 'namespace' ) ; if ( ! $ namespace ) { throw new Exception ( 'Extension namespace cannot be loaded' ) ; } if ( ! \ is_string ( $ namespace ) ) { throw new Exception ( 'Extension namespace is invalid' ) ; } if ( ! $ this -> filesystem -> isInitialized ( ) ) { $ this -> filesystem -> initialize ( ) ; } if ( ! $ this -> filesystem -> exists ( '.' ) ) { if ( ! $ this -> checkIfPhpized ( ) ) { $ this -> logger -> info ( 'Zephir version has changed, use "zephir fullclean" to perform a full clean of the project' ) ; } $ this -> filesystem -> makeDirectory ( '.' ) ; } return $ namespace ; }
Checks if the current directory is a valid Zephir project .
8,732
private function getGccVersion ( ) { if ( is_windows ( ) ) { return '0.0.0' ; } if ( $ this -> filesystem -> exists ( 'gcc-version' ) ) { return $ this -> filesystem -> read ( 'gcc-version' ) ; } $ this -> filesystem -> system ( 'gcc -dumpversion' , 'stdout' , 'gcc-version' ) ; $ lines = $ this -> filesystem -> file ( 'gcc-version' ) ; $ lines = array_filter ( $ lines ) ; $ lastLine = $ lines [ \ count ( $ lines ) - 1 ] ; if ( preg_match ( '/\d+\.\d+\.\d+/' , $ lastLine , $ matches ) ) { return $ matches [ 0 ] ; } return '0.0.0' ; }
Returns current GCC version .
8,733
public function getFunctionCache ( ) { if ( ! $ this -> functionCache ) { $ this -> functionCache = new FunctionCache ( $ this -> gatherer ) ; } return $ this -> functionCache ; }
Creates or returns an existing function cache .
8,734
public function isAvailable ( ) { return $ this -> parser -> isAvailable ( ) && version_compare ( self :: MINIMUM_PARSER_VERSION , $ this -> parser -> getVersion ( ) , '<=' ) ; }
Check if Zephir Parser available .
8,735
public function render ( ) { if ( $ this -> richFormat && $ this -> functionLike -> isReturnTypesHintDetermined ( ) && $ this -> functionLike -> areReturnTypesCompatible ( ) ) { $ this -> richRenderStart ( ) ; if ( false == $ this -> hasParameters ( ) ) { $ this -> codePrinter -> output ( 'ZEND_END_ARG_INFO()' ) ; $ this -> codePrinter -> outputBlankLine ( ) ; } } elseif ( true == $ this -> hasParameters ( ) ) { $ this -> codePrinter -> output ( sprintf ( 'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)' , $ this -> name , ( int ) $ this -> returnByRef , $ this -> functionLike -> getNumberOfRequiredParameters ( ) ) ) ; } if ( true == $ this -> hasParameters ( ) ) { $ this -> renderEnd ( ) ; $ this -> codePrinter -> output ( 'ZEND_END_ARG_INFO()' ) ; $ this -> codePrinter -> outputBlankLine ( ) ; } }
Render argument information .
8,736
public function getReflector ( $ funcName ) { if ( ! isset ( self :: $ functionReflection [ $ funcName ] ) ) { try { $ reflectionFunction = new \ ReflectionFunction ( $ funcName ) ; } catch ( \ ReflectionException $ e ) { $ reflectionFunction = null ; } self :: $ functionReflection [ $ funcName ] = $ reflectionFunction ; $ this -> reflection = $ reflectionFunction ; return $ reflectionFunction ; } $ reflectionFunction = self :: $ functionReflection [ $ funcName ] ; $ this -> reflection = $ reflectionFunction ; return $ reflectionFunction ; }
Process the ReflectionFunction for the specified function name .
8,737
public function functionExists ( $ functionName , CompilationContext $ context ) { if ( \ function_exists ( $ functionName ) ) { return true ; } if ( $ this -> isBuiltInFunction ( $ functionName ) ) { return true ; } $ internalName = [ 'f__' . $ functionName ] ; if ( isset ( $ context -> classDefinition ) ) { $ lowerNamespace = strtolower ( $ context -> classDefinition -> getNamespace ( ) ) ; $ prefix = 'f_' . str_replace ( '\\' , '_' , $ lowerNamespace ) ; $ internalName [ ] = $ prefix . '_' . $ functionName ; } foreach ( $ internalName as $ name ) { if ( isset ( $ context -> compiler -> functionDefinitions [ $ name ] ) ) { return true ; } } return false ; }
Checks if a function exists or is a built - in Zephir function .
8,738
protected function isReadOnly ( $ funcName , array $ expression ) { if ( $ this -> isBuiltInFunction ( $ funcName ) ) { return false ; } switch ( $ funcName ) { case 'min' : case 'max' : case 'array_fill' : case 'array_pad' : case 'call_user_func' : case 'call_user_func_array' : return false ; } $ reflector = $ this -> getReflector ( $ funcName ) ; if ( ! $ reflector instanceof \ ReflectionFunction ) { return false ; } $ messageFormat = "The number of parameters passed is lesser than the number of required parameters by '%s'" ; if ( isset ( $ expression [ 'parameters' ] ) ) { $ numberParameters = \ count ( $ expression [ 'parameters' ] ) ; if ( 'unpack' == $ funcName && ( 0 == version_compare ( PHP_VERSION , '7.1.0' ) || 0 == version_compare ( PHP_VERSION , '7.1.1' ) ) ) { if ( $ numberParameters < 2 ) { throw new CompilerException ( sprintf ( $ messageFormat , $ funcName ) , $ expression ) ; } } else { if ( $ numberParameters < $ reflector -> getNumberOfRequiredParameters ( ) ) { throw new CompilerException ( sprintf ( $ messageFormat , $ funcName ) , $ expression ) ; } } } else { if ( $ reflector -> getNumberOfRequiredParameters ( ) > 0 ) { throw new CompilerException ( sprintf ( $ messageFormat , $ funcName ) , $ expression ) ; } } if ( $ reflector -> getNumberOfParameters ( ) > 0 ) { foreach ( $ reflector -> getParameters ( ) as $ parameter ) { if ( $ parameter -> isPassedByReference ( ) ) { return false ; } } } return true ; }
This method gets the reflection of a function to check if any of their parameters are passed by reference Built - in functions rarely change the parameters if they aren t passed by reference .
8,739
protected function markReferences ( $ funcName , $ parameters , CompilationContext $ compilationContext , & $ references , $ expression ) { if ( $ this -> isBuiltInFunction ( $ funcName ) ) { return ; } $ reflector = $ this -> getReflector ( $ funcName ) ; if ( $ reflector ) { $ numberParameters = \ count ( $ parameters ) ; if ( $ numberParameters > 0 ) { $ n = 1 ; $ funcParameters = $ reflector -> getParameters ( ) ; $ isZendEngine3 = $ compilationContext -> backend -> isZE3 ( ) ; foreach ( $ funcParameters as $ parameter ) { if ( $ numberParameters >= $ n ) { if ( $ parameter -> isPassedByReference ( ) ) { if ( $ isZendEngine3 && '&' == $ parameters [ $ n - 1 ] [ 0 ] ) { $ parameters [ $ n - 1 ] = substr ( $ parameters [ $ n - 1 ] , 1 ) ; } if ( ! preg_match ( '/^[a-zA-Z0-9$\_]+$/' , $ parameters [ $ n - 1 ] ) ) { $ compilationContext -> logger -> warning ( 'Cannot mark complex expression as reference' , [ 'invalid-reference' , $ expression ] ) ; continue ; } $ variable = $ compilationContext -> symbolTable -> getVariable ( $ parameters [ $ n - 1 ] ) ; if ( $ variable ) { $ variable -> setDynamicTypes ( 'undefined' ) ; $ referenceSymbol = $ compilationContext -> backend -> getVariableCode ( $ variable ) ; $ compilationContext -> codePrinter -> output ( 'ZEPHIR_MAKE_REF(' . $ referenceSymbol . ');' ) ; $ references [ ] = $ parameters [ $ n - 1 ] ; } } } ++ $ n ; } } } }
Once the function processes the parameters we should mark specific parameters to be passed by reference .
8,740
protected function optimize ( $ funcName , array $ expression , Call $ call , CompilationContext $ compilationContext ) { $ optimizer = false ; if ( ! isset ( self :: $ optimizers [ $ funcName ] ) ) { $ camelizeFunctionName = camelize ( $ funcName ) ; foreach ( self :: $ optimizerDirectories as $ directory ) { $ path = $ directory . \ DIRECTORY_SEPARATOR . $ camelizeFunctionName . 'Optimizer.php' ; $ className = 'Zephir\Optimizers\FunctionCall\\' . $ camelizeFunctionName . 'Optimizer' ; if ( file_exists ( $ path ) ) { if ( ! class_exists ( $ className , false ) ) { require_once $ path ; } if ( ! class_exists ( $ className , false ) ) { throw new Exception ( "Class {$className} cannot be loaded" ) ; } $ optimizer = new $ className ( ) ; if ( ! ( $ optimizer instanceof OptimizerAbstract ) ) { throw new Exception ( "Class {$className} must be instance of OptimizerAbstract" ) ; } break ; } } self :: $ optimizers [ $ funcName ] = $ optimizer ; } else { $ optimizer = self :: $ optimizers [ $ funcName ] ; } if ( $ optimizer ) { return $ optimizer -> optimize ( $ expression , $ call , $ compilationContext ) ; } return false ; }
Tries to find specific an specialized optimizer for function calls .
8,741
public function preOutput ( $ code ) { $ this -> lastLine = $ code ; $ this -> code = str_repeat ( "\t" , $ this -> level ) . $ code . PHP_EOL . $ this -> code ; ++ $ this -> currentPrints ; }
Add code to the output at the beginning .
8,742
public function outputNoIndent ( $ code ) { $ this -> lastLine = $ code ; $ this -> code .= $ code . PHP_EOL ; ++ $ this -> currentPrints ; }
Add code to the output without indentation .
8,743
public function output ( $ code ) { $ this -> lastLine = $ code ; $ this -> code .= str_repeat ( "\t" , $ this -> level ) . $ code . PHP_EOL ; ++ $ this -> currentPrints ; }
Add code to the output .
8,744
public function outputDocBlock ( $ docblock , $ replaceTab = true ) { $ code = '' ; $ docblock = '/' . $ docblock . '/' ; foreach ( explode ( "\n" , $ docblock ) as $ line ) { if ( $ replaceTab ) { $ code .= str_repeat ( "\t" , $ this -> level ) . preg_replace ( '/^[ \t]+/' , ' ' , $ line ) . PHP_EOL ; } else { $ code .= $ line . PHP_EOL ; } } $ this -> lastLine = $ code ; $ this -> code .= $ code ; ++ $ this -> currentPrints ; }
Adds a comment to the output with indentation level .
8,745
public function preOutputBlankLine ( $ ifPrevNotBlank = false ) { if ( ! $ ifPrevNotBlank ) { $ this -> code = PHP_EOL . $ this -> code ; $ this -> lastLine = PHP_EOL ; ++ $ this -> currentPrints ; } else { if ( trim ( $ this -> lastLine ) ) { $ this -> code = PHP_EOL . $ this -> code ; $ this -> lastLine = PHP_EOL ; ++ $ this -> currentPrints ; } } }
Adds a blank line to the output Optionally controlling if the blank link must be added if the previous line added isn t one blank line too .
8,746
public function get ( $ key , $ namespace = null ) { return null !== $ namespace ? $ this -> offsetGet ( [ $ namespace => $ key ] ) : $ this -> offsetGet ( $ key ) ; }
Retrieves a configuration setting .
8,747
protected function populate ( ) { if ( ! file_exists ( 'config.json' ) ) { return ; } $ config = json_decode ( file_get_contents ( 'config.json' ) , true ) ; if ( ! \ is_array ( $ config ) ) { throw new Exception ( 'The config.json file is not valid or there is no Zephir extension initialized in this directory.' ) ; } foreach ( $ config as $ key => $ configSection ) { $ this -> offsetSet ( $ key , $ configSection ) ; } }
Populate project configuration .
8,748
public function generate ( $ path ) { if ( 'tabs' === $ this -> config -> get ( 'indent' , 'extra' ) ) { $ indent = "\t" ; } else { $ indent = ' ' ; } $ namespace = $ this -> config -> get ( 'namespace' ) ; foreach ( $ this -> files as $ file ) { $ class = $ file -> getClassDefinition ( ) ; $ source = $ this -> buildClass ( $ class , $ indent ) ; $ filename = ucfirst ( $ class -> getName ( ) ) . '.zep.php' ; $ filePath = $ path . str_replace ( $ namespace , '' , str_replace ( $ namespace . '\\\\' , \ DIRECTORY_SEPARATOR , strtolower ( $ class -> getNamespace ( ) ) ) ) ; $ filePath = str_replace ( '\\' , \ DIRECTORY_SEPARATOR , $ filePath ) ; $ filePath = str_replace ( \ DIRECTORY_SEPARATOR . \ DIRECTORY_SEPARATOR , \ DIRECTORY_SEPARATOR , $ filePath ) ; if ( ! is_dir ( $ filePath ) ) { mkdir ( $ filePath , 0777 , true ) ; } $ filePath = realpath ( $ filePath ) . '/' ; file_put_contents ( $ filePath . $ filename , $ source ) ; } }
Generates stubs .
8,749
protected function buildClass ( ClassDefinition $ class , $ indent ) { $ source = <<<EOF<?phpnamespace {$class->getNamespace()};EOF ; $ source .= ( new DocBlock ( $ class -> getDocBlock ( ) , '' ) ) . "\n" ; if ( $ class -> isFinal ( ) ) { $ source .= 'final ' ; } elseif ( $ class -> isAbstract ( ) ) { $ source .= 'abstract ' ; } $ source .= $ class -> getType ( ) . ' ' . $ class -> getName ( ) ; if ( $ class -> getExtendsClass ( ) ) { $ extendsClassDefinition = $ class -> getExtendsClassDefinition ( ) ; if ( ! $ extendsClassDefinition ) { throw new \ RuntimeException ( 'Class "' . $ class -> getName ( ) . '" does not have a extendsClassDefinition' ) ; } $ source .= ' extends ' . ( $ extendsClassDefinition -> isBundled ( ) ? '' : '\\' ) . trim ( $ extendsClassDefinition -> getCompleteName ( ) , '\\' ) ; } if ( $ implementedInterfaces = $ class -> getImplementedInterfaces ( ) ) { $ interfaces = array_map ( function ( $ val ) { return '\\' . trim ( $ val , '\\' ) ; } , $ implementedInterfaces ) ; $ keyword = 'interface' == $ class -> getType ( ) ? ' extends ' : ' implements ' ; $ source .= $ keyword . implode ( ', ' , $ interfaces ) ; } $ source .= PHP_EOL . '{' . PHP_EOL ; foreach ( $ class -> getConstants ( ) as $ constant ) { $ source .= $ this -> buildConstant ( $ constant , $ indent ) . PHP_EOL . PHP_EOL ; } foreach ( $ class -> getProperties ( ) as $ property ) { $ source .= $ this -> buildProperty ( $ property , $ indent ) . PHP_EOL . PHP_EOL ; } $ source .= PHP_EOL ; foreach ( $ class -> getMethods ( ) as $ method ) { if ( $ method -> isInternal ( ) ) { continue ; } $ source .= $ this -> buildMethod ( $ method , 'interface' === $ class -> getType ( ) , $ indent ) . "\n\n" ; } return $ source . '}' . PHP_EOL ; }
Build class .
8,750
protected function buildProperty ( ClassProperty $ property , $ indent ) { $ visibility = 'public' ; if ( false === $ property -> isPublic ( ) ) { $ visibility = $ property -> isProtected ( ) ? 'protected' : 'private' ; } if ( $ property -> isStatic ( ) ) { $ visibility = 'static ' . $ visibility ; } $ source = $ visibility . ' $' . $ property -> getName ( ) ; $ original = $ property -> getOriginal ( ) ; if ( isset ( $ original [ 'default' ] ) ) { $ source .= ' = ' . $ this -> wrapPHPValue ( [ 'default' => $ original [ 'default' ] , ] ) ; } $ docBlock = new DocBlock ( $ property -> getDocBlock ( ) , $ indent ) ; return $ docBlock . "\n" . $ indent . $ source . ';' ; }
Build property .
8,751
protected function wrapPHPValue ( $ parameter ) { switch ( $ parameter [ 'default' ] [ 'type' ] ) { case 'null' : return 'null' ; break ; case 'string' : case 'char' : return '\'' . addslashes ( $ parameter [ 'default' ] [ 'value' ] ) . '\'' ; break ; case 'empty-array' : return 'array()' ; break ; case 'array' : $ parameters = [ ] ; foreach ( $ parameter [ 'default' ] [ 'left' ] as $ value ) { $ source = '' ; if ( isset ( $ value [ 'key' ] ) ) { $ source .= $ this -> wrapPHPValue ( [ 'default' => $ value [ 'key' ] , 'type' => $ value [ 'key' ] [ 'type' ] , ] ) . ' => ' ; } $ parameters [ ] = $ source . $ this -> wrapPHPValue ( [ 'default' => $ value [ 'value' ] , 'type' => $ value [ 'value' ] [ 'type' ] , ] ) ; } return 'array(' . implode ( ', ' , $ parameters ) . ')' ; break ; case 'static-constant-access' : return $ parameter [ 'default' ] [ 'left' ] [ 'value' ] . '::' . $ parameter [ 'default' ] [ 'right' ] [ 'value' ] ; break ; case 'int' : case 'double' : case 'bool' : return $ parameter [ 'default' ] [ 'value' ] ; break ; default : throw new Exception ( 'Stubs - value with type: ' . $ parameter [ 'default' ] [ 'type' ] . ' is not supported' ) ; break ; } }
Prepare AST default value to PHP code print .
8,752
public function markVariableIfUnknown ( $ variable , $ type ) { $ this -> variables [ $ variable ] = $ type ; $ this -> infered [ $ variable ] = $ type ; }
Marks a variable to mandatory be stored in the heap if a type has not been defined for it .
8,753
public function reduce ( ) { $ pass = false ; foreach ( $ this -> variables as $ variable => $ type ) { if ( 'variable' == $ type || 'string' == $ type || 'istring' == $ type || 'array' == $ type || 'null' == $ type || 'numeric' == $ type ) { unset ( $ this -> variables [ $ variable ] ) ; } else { $ pass = true ; $ this -> infered [ $ variable ] = $ type ; } } return $ pass ; }
Process the found infered types and schedule a new pass .
8,754
public function optimizeConstantFolding ( array $ expression , CompilationContext $ compilationContext ) { if ( 'int' != $ expression [ 'left' ] [ 'type' ] && 'double' != $ expression [ 'left' ] [ 'type' ] ) { return false ; } if ( $ compilationContext -> config -> get ( 'constant-folding' , 'optimizations' ) ) { if ( 'int' == $ expression [ 'left' ] [ 'type' ] && 'int' == $ expression [ 'right' ] [ 'type' ] ) { switch ( $ this -> operator ) { case '+' : return new CompiledExpression ( 'int' , $ expression [ 'left' ] [ 'value' ] + $ expression [ 'right' ] [ 'value' ] , $ expression ) ; case '-' : return new CompiledExpression ( 'int' , $ expression [ 'left' ] [ 'value' ] - $ expression [ 'right' ] [ 'value' ] , $ expression ) ; case '*' : return new CompiledExpression ( 'int' , $ expression [ 'left' ] [ 'value' ] * $ expression [ 'right' ] [ 'value' ] , $ expression ) ; } } if ( ( 'double' == $ expression [ 'left' ] [ 'type' ] && 'double' == $ expression [ 'right' ] [ 'type' ] ) || ( 'double' == $ expression [ 'left' ] [ 'type' ] && 'int' == $ expression [ 'right' ] [ 'type' ] ) || ( 'int' == $ expression [ 'left' ] [ 'type' ] && 'double' == $ expression [ 'right' ] [ 'type' ] ) ) { switch ( $ this -> operator ) { case '+' : return new CompiledExpression ( 'double' , $ expression [ 'left' ] [ 'value' ] + $ expression [ 'right' ] [ 'value' ] , $ expression ) ; case '-' : return new CompiledExpression ( 'double' , $ expression [ 'left' ] [ 'value' ] - $ expression [ 'right' ] [ 'value' ] , $ expression ) ; case '*' : return new CompiledExpression ( 'double' , $ expression [ 'left' ] [ 'value' ] * $ expression [ 'right' ] [ 'value' ] , $ expression ) ; } } } return false ; }
This tries to perform arithmetical operations .
8,755
private function getDynamicTypes ( Variable $ left , Variable $ right ) { if ( '/' == $ this -> operator ) { return 'double' ; } switch ( $ left -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : switch ( $ right -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : return 'int' ; } break ; } return 'double' ; }
Returns proper dynamic types .
8,756
public function listen ( $ event , $ callback ) { if ( ! isset ( $ this -> listeners [ $ event ] ) ) { $ this -> listeners [ $ event ] = [ ] ; } $ this -> listeners [ $ event ] [ ] = $ callback ; }
Attaches a listener to a specific event type .
8,757
public function dispatch ( $ event , array $ param = [ ] ) { foreach ( $ this -> listeners [ $ event ] as $ listener ) { \ call_user_func_array ( $ listener , $ param ) ; } }
Triggers an event for the specified event type .
8,758
public function assign ( $ variable , $ property , ZephirVariable $ symbolVariable , CompilationContext $ compilationContext , $ statement ) { if ( ! $ symbolVariable -> isInitialized ( ) ) { throw new CompilerException ( "Cannot mutate variable '" . $ variable . "' because it is not initialized" , $ statement ) ; } if ( $ symbolVariable -> isLocalOnly ( ) ) { throw new CompilerException ( "Cannot mutate variable '" . $ variable . "' because it is local only" , $ statement ) ; } if ( ! $ symbolVariable -> isInitialized ( ) ) { throw new CompilerException ( "Cannot mutate variable '" . $ variable . "' because it is not initialized" , $ statement ) ; } if ( ! $ symbolVariable -> isVariable ( ) ) { throw new CompilerException ( "Cannot use variable type: '" . $ symbolVariable -> getType ( ) . "' as array" , $ statement ) ; } if ( $ symbolVariable -> hasAnyDynamicType ( 'unknown' ) ) { throw new CompilerException ( 'Cannot use non-initialized variable as an object' , $ statement ) ; } if ( $ symbolVariable -> hasDifferentDynamicType ( [ 'undefined' , 'object' , 'null' ] ) ) { $ compilationContext -> logger -> warning ( 'Possible attempt to increment non-object dynamic variable' , [ 'non-object-update' , $ statement ] ) ; } if ( 'this' == $ symbolVariable -> getRealName ( ) ) { $ classDefinition = $ compilationContext -> classDefinition ; if ( ! $ classDefinition -> hasProperty ( $ property ) ) { throw new CompilerException ( "Class '" . $ classDefinition -> getCompleteName ( ) . "' does not have a property called: '" . $ property . "'" , $ statement ) ; } } else { if ( $ symbolVariable -> hasAnyDynamicType ( 'object' ) ) { $ classType = current ( $ symbolVariable -> getClassTypes ( ) ) ; $ compiler = $ compilationContext -> compiler ; if ( $ compiler -> isClass ( $ classType ) ) { $ classDefinition = $ compiler -> getClassDefinition ( $ classType ) ; if ( ! $ classDefinition ) { throw new CompilerException ( 'Cannot locate class definition for class: ' . $ classType , $ statement ) ; } if ( ! $ classDefinition -> hasProperty ( $ property ) ) { throw new CompilerException ( "Class '" . $ classType . "' does not have a property called: '" . $ property . "'" , $ statement ) ; } } } } $ compilationContext -> headersManager -> add ( 'kernel/object' ) ; $ compilationContext -> codePrinter -> output ( 'RETURN_ON_FAILURE(zephir_property_incr(' . $ symbolVariable -> getName ( ) . ', SL("' . $ property . '") TSRMLS_CC));' ) ; }
Compiles obj - > x ++ .
8,759
public function passLetStatement ( array $ statement ) { foreach ( $ statement [ 'assignments' ] as $ assignment ) { if ( isset ( $ assignment [ 'expr' ] ) ) { $ this -> passExpression ( $ assignment [ 'expr' ] ) ; } $ this -> increaseMutations ( $ assignment [ 'variable' ] ) ; if ( self :: DETECT_VALUE_IN_ASSIGNMENT == ( $ this -> detectionFlags & self :: DETECT_VALUE_IN_ASSIGNMENT ) ) { if ( isset ( $ assignment [ 'expr' ] ) ) { if ( 'variable' == $ assignment [ 'expr' ] [ 'type' ] ) { $ this -> increaseMutations ( $ assignment [ 'expr' ] [ 'value' ] ) ; break ; } } } } }
Pass let statements .
8,760
public function passArray ( array $ expression ) { foreach ( $ expression [ 'left' ] as $ item ) { $ usePass = self :: DETECT_ARRAY_USE == ( $ this -> detectionFlags & self :: DETECT_ARRAY_USE ) ; if ( $ usePass && 'variable' == $ item [ 'value' ] [ 'type' ] ) { $ this -> increaseMutations ( $ item [ 'value' ] [ 'value' ] ) ; } else { $ this -> passExpression ( $ item [ 'value' ] ) ; } } }
Pass array expressions .
8,761
public function passNew ( array $ expression ) { if ( isset ( $ expression [ 'parameters' ] ) ) { foreach ( $ expression [ 'parameters' ] as $ parameter ) { $ usePass = self :: DETECT_PARAM_PASS == ( $ this -> detectionFlags & self :: DETECT_PARAM_PASS ) ; if ( $ usePass && 'variable' == $ parameter [ 'parameter' ] [ 'type' ] ) { $ this -> increaseMutations ( $ parameter [ 'parameter' ] [ 'value' ] ) ; } else { $ this -> passExpression ( $ parameter [ 'parameter' ] ) ; } } } }
Pass new expressions .
8,762
public function declareVariables ( array $ statement ) { if ( isset ( $ statement [ 'data-type' ] ) ) { if ( 'variable' != $ statement [ 'data-type' ] ) { return ; } } foreach ( $ statement [ 'variables' ] as $ variable ) { if ( isset ( $ variable [ 'expr' ] ) ) { if ( 'string' == $ variable [ 'expr' ] [ 'type' ] || 'empty-array' == $ variable [ 'expr' ] [ 'type' ] || 'array' == $ variable [ 'expr' ] [ 'type' ] ) { continue ; } } $ this -> increaseMutations ( $ variable [ 'variable' ] ) ; } }
Pass declare statement .
8,763
public function getExpectedNonLiteral ( CompilationContext $ compilationContext , $ expression , $ init = true ) { $ isExpecting = $ this -> expecting ; $ symbolVariable = $ this -> expectingVariable ; if ( $ isExpecting ) { if ( \ is_object ( $ symbolVariable ) ) { if ( 'variable' == $ symbolVariable -> getType ( ) && ! $ symbolVariable -> isLocalOnly ( ) ) { if ( ! $ init ) { return $ symbolVariable ; } $ symbolVariable -> initVariant ( $ compilationContext ) ; } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } return $ symbolVariable ; }
Returns the expected variable for assignment or creates a temporary variable to store the result . This method returns a variable that is always stored in the heap .
8,764
public function getExpected ( CompilationContext $ compilationContext , $ expression , $ init = true ) { $ isExpecting = $ this -> expecting ; $ symbolVariable = $ this -> expectingVariable ; if ( $ isExpecting ) { if ( \ is_object ( $ symbolVariable ) ) { if ( 'variable' == $ symbolVariable -> getType ( ) ) { if ( ! $ init ) { return $ symbolVariable ; } $ symbolVariable -> initVariant ( $ compilationContext ) ; } else { if ( ! $ this -> readOnly ) { if ( ! $ this -> literalOnly ) { $ symbolVariable = $ compilationContext -> symbolTable -> getTempVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempComplexLiteralVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempLocalVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } } else { if ( ! $ this -> readOnly ) { if ( ! $ this -> literalOnly ) { $ symbolVariable = $ compilationContext -> symbolTable -> getTempVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempComplexLiteralVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempLocalVariableForWrite ( 'variable' , $ compilationContext , $ expression ) ; } } } return $ symbolVariable ; }
Returns the expected variable for assignment or creates a temporary variable to store the result .
8,765
public function getExpectedComplexLiteral ( CompilationContext $ compilationContext , $ expression , $ type = 'variable' ) { $ isExpecting = $ this -> expecting ; $ symbolVariable = $ this -> expectingVariable ; if ( $ isExpecting ) { if ( \ is_object ( $ symbolVariable ) ) { if ( $ symbolVariable -> getType ( ) == $ type || 'return_value' == $ symbolVariable -> getName ( ) ) { $ symbolVariable -> initVariant ( $ compilationContext ) ; } else { if ( ! $ this -> readOnly ) { $ symbolVariable = $ compilationContext -> symbolTable -> getTempComplexLiteralVariableForWrite ( $ type , $ compilationContext , $ expression ) ; } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempLocalVariableForWrite ( $ type , $ compilationContext , $ expression ) ; } } } else { if ( ! $ this -> readOnly ) { $ symbolVariable = $ compilationContext -> symbolTable -> getTempComplexLiteralVariableForWrite ( $ type , $ compilationContext , $ expression ) ; } else { $ symbolVariable = $ compilationContext -> symbolTable -> getTempLocalVariableForWrite ( $ type , $ compilationContext , $ expression ) ; } } } return $ symbolVariable ; }
Returns the expected variable for assignment or creates a temporary variable to store the result if a temporary variable is created it use whose body is only freed on every iteration .
8,766
public function compile ( array $ expression , CompilationContext $ compilationContext ) { if ( ! isset ( $ expression [ 'parameters' ] ) ) { throw new CompilerException ( "Invalid 'parameters' for new-type" , $ expression ) ; } switch ( $ expression [ 'internal-type' ] ) { case 'array' : $ compilationContext -> headersManager -> add ( 'kernel/array' ) ; $ functionName = 'create_array' ; break ; case 'string' : $ compilationContext -> headersManager -> add ( 'kernel/string' ) ; $ functionName = 'create_string' ; break ; default : throw new CompilerException ( 'Cannot build instance of type' , $ expression ) ; } $ builder = new FunctionCallBuilder ( $ functionName , $ expression [ 'parameters' ] , 1 , $ expression [ 'file' ] , $ expression [ 'line' ] , $ expression [ 'char' ] ) ; $ castBuilder = new CastOperatorBuilder ( $ expression [ 'internal-type' ] , $ builder ) ; $ expression = new Expression ( $ castBuilder -> get ( ) ) ; $ expression -> setReadOnly ( $ this -> readOnly ) ; try { return $ expression -> compile ( $ compilationContext ) ; } catch ( Exception $ e ) { throw new CompilerException ( $ e -> getMessage ( ) , $ expression , $ e -> getCode ( ) , $ e ) ; } }
Executes the operator .
8,767
public function compile ( array $ expression , CompilationContext $ compilationContext ) { $ expr = new Expression ( $ expression [ 'right' ] ) ; $ expr -> setReadOnly ( true ) ; $ resolved = $ expr -> compile ( $ compilationContext ) ; if ( 'variable' != $ resolved -> getType ( ) ) { throw new CompilerException ( 'Type-Hints only can be applied to dynamic variables.' , $ expression ) ; } $ symbolVariable = $ compilationContext -> symbolTable -> getVariableForRead ( $ resolved -> getCode ( ) , $ compilationContext , $ expression ) ; if ( ! $ symbolVariable -> isVariable ( ) ) { throw new CompilerException ( 'Type-Hints only can be applied to dynamic variables.' , $ expression ) ; } $ symbolVariable -> setDynamicTypes ( 'object' ) ; $ symbolVariable -> setClassTypes ( $ compilationContext -> getFullName ( $ expression [ 'left' ] [ 'value' ] ) ) ; return $ resolved ; }
Performs type - hint compilation .
8,768
public function themeOption ( $ name ) { return isset ( $ this -> themeOptions [ $ name ] ) ? $ this -> themeOptions [ $ name ] : null ; }
find the value of an option of the theme .
8,769
public function url ( $ url ) { if ( \ is_string ( $ url ) ) { if ( '/' == $ url [ 0 ] ) { return $ this -> getPathToRoot ( ) . ltrim ( $ url , '/' ) ; } elseif ( \ is_string ( $ url ) ) { return $ url ; } } elseif ( $ url instanceof ClassDefinition ) { return $ this -> url ( Documentation :: classUrl ( $ url ) ) ; } elseif ( $ url instanceof CompilerFile ) { return $ this -> url ( Documentation :: classUrl ( $ url -> getClassDefinition ( ) ) ) ; } return '' ; }
Generate an url relative to the current directory .
8,770
private function isClassCacheable ( $ classDefinition ) { if ( $ classDefinition instanceof ClassDefinition ) { return true ; } if ( $ classDefinition instanceof \ ReflectionClass ) { if ( $ classDefinition -> isInternal ( ) && $ classDefinition -> isInstantiable ( ) ) { $ extension = $ classDefinition -> getExtension ( ) ; switch ( $ extension -> getName ( ) ) { case 'Reflection' : case 'Core' : case 'SPL' : return true ; } } } return false ; }
Checks if the class is suitable for caching .
8,771
public static function getFunctionSlot ( $ functionName ) { if ( isset ( self :: $ cacheFunctionSlots [ $ functionName ] ) ) { return self :: $ cacheFunctionSlots [ $ functionName ] ; } $ slot = self :: $ slot ++ ; if ( $ slot >= self :: MAX_SLOTS_NUMBER ) { return 0 ; } self :: $ cacheFunctionSlots [ $ functionName ] = $ slot ; return $ slot ; }
Returns or creates a cache slot for a function .
8,772
public static function getMethodSlot ( ClassMethod $ method ) { $ className = $ method -> getClassDefinition ( ) -> getCompleteName ( ) ; $ methodName = $ method -> getName ( ) ; if ( isset ( self :: $ cacheMethodSlots [ $ className ] [ $ methodName ] ) ) { return self :: $ cacheMethodSlots [ $ className ] [ $ methodName ] ; } $ slot = self :: $ slot ++ ; if ( $ slot >= self :: MAX_SLOTS_NUMBER ) { return 0 ; } self :: $ cacheMethodSlots [ $ className ] [ $ methodName ] = $ slot ; return $ slot ; }
Returns or creates a cache slot for a method .
8,773
public static function getExistingMethodSlot ( ClassMethod $ method ) { $ className = $ method -> getClassDefinition ( ) -> getCompleteName ( ) ; $ methodName = $ method -> getName ( ) ; if ( isset ( self :: $ cacheMethodSlots [ $ className ] [ $ methodName ] ) ) { return self :: $ cacheMethodSlots [ $ className ] [ $ methodName ] ; } return 0 ; }
Returns a cache slot for a method .
8,774
public function invokeMethod ( $ methodName , $ caller , CompilationContext $ compilationContext , Call $ call , array $ expression ) { if ( method_exists ( $ this , $ methodName ) ) { return $ this -> { $ methodName } ( $ caller , $ compilationContext , $ call , $ expression ) ; } if ( isset ( $ this -> methodMap [ $ methodName ] ) ) { $ paramNumber = $ this -> getNumberParam ( $ methodName ) ; if ( 0 == $ paramNumber ) { if ( isset ( $ expression [ 'parameters' ] ) ) { $ parameters = $ expression [ 'parameters' ] ; array_unshift ( $ parameters , [ 'parameter' => $ caller ] ) ; } else { $ parameters = [ [ 'parameter' => $ caller ] ] ; } } else { if ( isset ( $ expression [ 'parameters' ] ) ) { $ parameters = [ ] ; foreach ( $ expression [ 'parameters' ] as $ number => $ parameter ) { if ( $ number == $ paramNumber ) { $ parameters [ ] = null ; } $ parameters [ ] = $ parameter ; } $ parameters [ $ paramNumber ] = [ 'parameter' => $ caller ] ; } else { $ parameters = [ [ 'parameter' => $ caller ] ] ; } } $ functionCall = BuilderFactory :: getInstance ( ) -> statements ( ) -> functionCall ( $ this -> methodMap [ $ methodName ] , $ parameters ) -> setFile ( $ expression [ 'file' ] ) -> setLine ( $ expression [ 'line' ] ) -> setChar ( $ expression [ 'char' ] ) ; $ expression = new Expression ( $ functionCall -> build ( ) ) ; return $ expression -> compile ( $ compilationContext ) ; } throw new CompilerException ( sprintf ( 'Method "%s" is not a built-in method of type "%s"' , $ methodName , $ this -> getTypeName ( ) ) , $ expression ) ; }
Intercepts calls to built - in methods .
8,775
public function compile ( $ expression , CompilationContext $ compilationContext ) { if ( ! isset ( $ expression [ 'left' ] ) ) { throw new CompilerException ( 'Missing left part of the expression' ) ; } $ leftExpr = new Expression ( $ expression [ 'left' ] ) ; $ leftExpr -> setReadOnly ( $ this -> readOnly ) ; $ left = $ leftExpr -> compile ( $ compilationContext ) ; switch ( $ left -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : case 'double' : return new CompiledExpression ( $ left -> getType ( ) , '-' . $ left -> getCode ( ) , $ expression ) ; case 'variable' : $ variable = $ compilationContext -> symbolTable -> getVariable ( $ left -> getCode ( ) ) ; switch ( $ variable -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : case 'double' : return new CompiledExpression ( $ variable -> getType ( ) , '-' . $ variable -> getName ( ) , $ expression ) ; case 'variable' : $ compilationContext -> headersManager -> add ( 'kernel/operators' ) ; $ compilationContext -> codePrinter -> output ( 'zephir_negate(' . $ compilationContext -> backend -> getVariableCode ( $ variable ) . ' TSRMLS_CC);' ) ; return new CompiledExpression ( 'variable' , $ variable -> getName ( ) , $ expression ) ; default : throw new CompilerException ( "Cannot operate minus with variable of '" . $ left -> getType ( ) . "' type" ) ; } break ; default : throw new CompilerException ( "Cannot operate minus with '" . $ left -> getType ( ) . "' type" ) ; } }
Compile expression .
8,776
public function add ( $ path , $ position = 0 ) { if ( ! \ is_string ( $ path ) ) { throw new \ InvalidArgumentException ( '$path must be only string type' ) ; } if ( ! $ position ) { $ this -> headers [ $ path ] = $ path ; } else { switch ( $ position ) { case self :: POSITION_FIRST : $ this -> headersFirst [ $ path ] = $ path ; break ; case self :: POSITION_LAST : $ this -> headersLast [ $ path ] = $ path ; break ; default : break ; } } }
Adds a header path to the manager .
8,777
public function processValue ( CompilationContext $ compilationContext ) { if ( 'constant' == $ this -> value [ 'type' ] ) { $ constant = new Constants ( ) ; $ compiledExpression = $ constant -> compile ( $ this -> value , $ compilationContext ) ; $ this -> value = [ 'type' => $ compiledExpression -> getType ( ) , 'value' => $ compiledExpression -> getCode ( ) , ] ; return ; } if ( 'static-constant-access' == $ this -> value [ 'type' ] ) { $ staticConstantAccess = new StaticConstantAccess ( ) ; $ compiledExpression = $ staticConstantAccess -> compile ( $ this -> value , $ compilationContext ) ; $ this -> value = [ 'type' => $ compiledExpression -> getType ( ) , 'value' => $ compiledExpression -> getCode ( ) , ] ; return ; } }
Process the value of the class constant if needed .
8,778
public function compile ( CompilationContext $ compilationContext ) { $ this -> processValue ( $ compilationContext ) ; $ constanValue = isset ( $ this -> value [ 'value' ] ) ? $ this -> value [ 'value' ] : null ; $ compilationContext -> backend -> declareConstant ( $ this -> value [ 'type' ] , $ this -> getName ( ) , $ constanValue , $ compilationContext ) ; }
Produce the code to register a class constant .
8,779
protected function isDevelopmentModeEnabled ( InputInterface $ input ) { if ( false == $ input -> getOption ( 'no-dev' ) ) { return $ input -> getOption ( 'dev' ) || PHP_DEBUG ; } return false ; }
Checks if the development mode is enabled .
8,780
public function add ( array $ useStatement ) { foreach ( $ useStatement [ 'aliases' ] as $ alias ) { if ( isset ( $ alias [ 'alias' ] ) ) { $ this -> aliases [ $ alias [ 'alias' ] ] = $ alias [ 'name' ] ; } else { $ parts = explode ( '\\' , $ alias [ 'name' ] ) ; $ implicitAlias = $ parts [ \ count ( $ parts ) - 1 ] ; $ this -> aliases [ $ implicitAlias ] = $ alias [ 'name' ] ; } } }
Adds a renaming in a use to the alias manager .
8,781
public function getVisibilityAccessor ( ) { $ modifiers = [ ] ; foreach ( $ this -> visibility as $ visibility ) { switch ( $ visibility ) { case 'protected' : $ modifiers [ 'ZEND_ACC_PROTECTED' ] = true ; break ; case 'private' : $ modifiers [ 'ZEND_ACC_PRIVATE' ] = true ; break ; case 'public' : $ modifiers [ 'ZEND_ACC_PUBLIC' ] = true ; break ; case 'static' : $ modifiers [ 'ZEND_ACC_STATIC' ] = true ; break ; default : throw new Exception ( 'Unknown modifier ' . $ visibility ) ; } } return implode ( '|' , array_keys ( $ modifiers ) ) ; }
Returns the C - visibility accessors for the model .
8,782
public function compile ( CompilationContext $ compilationContext ) { switch ( $ this -> defaultValue [ 'type' ] ) { case 'long' : case 'int' : case 'string' : case 'double' : case 'bool' : $ this -> declareProperty ( $ compilationContext , $ this -> defaultValue [ 'type' ] , $ this -> defaultValue [ 'value' ] ) ; break ; case 'array' : case 'empty-array' : $ this -> initializeArray ( $ compilationContext ) ; case 'null' : $ this -> declareProperty ( $ compilationContext , $ this -> defaultValue [ 'type' ] , null ) ; break ; case 'static-constant-access' : $ expression = new Expression ( $ this -> defaultValue ) ; $ compiledExpression = $ expression -> compile ( $ compilationContext ) ; $ this -> declareProperty ( $ compilationContext , $ compiledExpression -> getType ( ) , $ compiledExpression -> getCode ( ) ) ; break ; default : throw new CompilerException ( 'Unknown default type: ' . $ this -> defaultValue [ 'type' ] , $ this -> original ) ; } }
Produce the code to register a property .
8,783
protected function removeInitializationStatements ( & $ statements ) { foreach ( $ statements as $ index => $ statement ) { if ( ! $ this -> isStatic ( ) ) { if ( $ statement [ 'expr' ] [ 'left' ] [ 'right' ] [ 'value' ] == $ this -> name ) { unset ( $ statements [ $ index ] ) ; } } else { if ( $ statement [ 'assignments' ] [ 0 ] [ 'property' ] == $ this -> name ) { unset ( $ statements [ $ index ] ) ; } } } }
Removes all initialization statements related to this property .
8,784
protected function declareProperty ( CompilationContext $ compilationContext , $ type , $ value ) { $ codePrinter = $ compilationContext -> codePrinter ; if ( \ is_object ( $ value ) ) { return ; } $ classEntry = $ compilationContext -> classDefinition -> getClassEntry ( ) ; switch ( $ type ) { case 'long' : case 'int' : $ codePrinter -> output ( 'zend_declare_property_long(' . $ classEntry . ', SL("' . $ this -> getName ( ) . '"), ' . $ value . ', ' . $ this -> getVisibilityAccessor ( ) . ' TSRMLS_CC);' ) ; break ; case 'double' : $ codePrinter -> output ( 'zend_declare_property_double(' . $ classEntry . ', SL("' . $ this -> getName ( ) . '"), ' . $ value . ', ' . $ this -> getVisibilityAccessor ( ) . ' TSRMLS_CC);' ) ; break ; case 'bool' : $ codePrinter -> output ( 'zend_declare_property_bool(' . $ classEntry . ', SL("' . $ this -> getName ( ) . '"), ' . $ this -> getBooleanCode ( $ value ) . ', ' . $ this -> getVisibilityAccessor ( ) . ' TSRMLS_CC);' ) ; break ; case Types :: T_CHAR : case Types :: T_STRING : $ codePrinter -> output ( sprintf ( 'zend_declare_property_string(%s, SL("%s"), "%s", %s TSRMLS_CC);' , $ classEntry , $ this -> getName ( ) , add_slashes ( $ value ) , $ this -> getVisibilityAccessor ( ) ) ) ; break ; case 'array' : case 'empty-array' : case 'null' : $ codePrinter -> output ( 'zend_declare_property_null(' . $ classEntry . ', SL("' . $ this -> getName ( ) . '"), ' . $ this -> getVisibilityAccessor ( ) . ' TSRMLS_CC);' ) ; break ; default : throw new CompilerException ( 'Unknown default type: ' . $ type , $ this -> original ) ; } }
Declare class property with default value .
8,785
public function assignZval ( Variable $ variable , $ code , CompilationContext $ context ) { $ code = $ this -> resolveValue ( $ code , $ context ) ; if ( ! $ variable -> isDoublePointer ( ) ) { $ context -> symbolTable -> mustGrownStack ( true ) ; $ symbolVariable = $ this -> getVariableCode ( $ variable ) ; $ context -> codePrinter -> output ( 'ZEPHIR_OBS_COPY_OR_DUP(' . $ symbolVariable . ', ' . $ code . ');' ) ; } else { $ context -> codePrinter -> output ( $ variable -> getName ( ) . ' = ' . $ code . ';' ) ; } }
Assigns a zval to another .
8,786
public function getTypesBySpecification ( SpecificationInterface $ spec ) { $ types = [ ] ; foreach ( $ this as $ type ) { if ( $ spec -> isSatisfiedBy ( $ type ) ) { $ types [ ] = $ type ; } } return $ types ; }
Gets all return types satisfied by specification .
8,787
public function onlySpecial ( ) { if ( 0 == $ this -> count ( ) ) { return false ; } $ found = $ this -> getTypesBySpecification ( new Specification \ IsSpecial ( ) ) ; return \ count ( $ found ) == $ this -> count ( ) ; }
Checks if the collection has only special types .
8,788
public function areReturnTypesWellKnown ( ) { if ( 0 == $ this -> count ( ) || $ this -> isSatisfiedByTypeSpec ( new Specification \ IsSpecial ( ) ) ) { return false ; } $ spec = ( new Specification \ ObjectLike ( ) ) -> either ( new Specification \ ArrayCompatible ( ) ) -> either ( new Specification \ IntCompatible ( ) ) -> either ( new Specification \ StringCompatible ( ) ) -> either ( new Specification \ IsBool ( ) ) -> either ( new Specification \ IsDouble ( ) ) -> either ( new Specification \ IsNull ( ) ) -> either ( new Specification \ IsVoid ( ) ) ; $ found = $ this -> getTypesBySpecification ( $ spec ) ; return \ count ( $ found ) == $ this -> count ( ) ; }
Checks whether all return types hint are well known .
8,789
public function areReturnTypesCompatible ( ) { $ numberOfReturnTypes = $ this -> count ( ) ; if ( 0 == $ numberOfReturnTypes || 1 == $ numberOfReturnTypes ) { return true ; } $ classes = $ this -> getObjectLikeReturnTypes ( ) ; $ collections = $ this -> getTypesBySpecification ( new Specification \ IsCollection ( ) ) ; if ( \ count ( $ collections ) > 0 && $ this -> areReturnTypesObjectCompatible ( ) ) { return false ; } $ summ = ( int ) $ this -> areReturnTypesArrayCompatible ( ) + ( int ) $ this -> areReturnTypesIntCompatible ( ) + ( int ) $ this -> areReturnTypesBoolCompatible ( ) + ( int ) $ this -> areReturnTypesStringCompatible ( ) + ( int ) $ this -> areReturnTypesDoubleCompatible ( ) ; if ( $ summ > 1 ) { return false ; } if ( $ this -> areReturnTypesObjectCompatible ( ) && $ summ > 0 ) { return false ; } $ null = ( int ) $ this -> areReturnTypesNullCompatible ( ) ; if ( 1 == $ null && 2 == $ this -> count ( ) ) { return true ; } if ( 1 == $ null && $ null + $ summ != $ this -> count ( ) ) { return false ; } return 1 == $ summ ; }
Checks if the collection have compatible return types .
8,790
private function doArrayAssignment ( CodePrinter $ codePrinter , CompiledExpression $ resolvedExpr , ZephirVariable $ symbolVariable , $ variable , array $ statement , CompilationContext $ compilationContext ) { switch ( $ resolvedExpr -> getType ( ) ) { case 'variable' : case 'array' : switch ( $ statement [ 'operator' ] ) { case 'assign' : if ( $ variable != $ resolvedExpr -> getCode ( ) ) { $ symbolVariable -> setMustInitNull ( true ) ; $ compilationContext -> symbolTable -> mustGrownStack ( true ) ; $ symbolVariable -> setDynamicTypes ( 'array' ) ; $ symbolVariable -> increaseVariantIfNull ( ) ; $ symbol = $ compilationContext -> backend -> getVariableCode ( $ symbolVariable ) ; $ codePrinter -> output ( 'ZEPHIR_CPY_WRT(' . $ symbol . ', ' . $ compilationContext -> backend -> resolveValue ( $ resolvedExpr , $ compilationContext ) . ');' ) ; } break ; default : throw new IllegalOperationException ( $ statement , $ resolvedExpr , $ resolvedExpr -> getOriginal ( ) ) ; } break ; default : throw new CompilerException ( "Cannot '" . $ statement [ 'operator' ] . "' " . $ resolvedExpr -> getType ( ) . ' for array type' , $ resolvedExpr -> getOriginal ( ) ) ; } }
Performs array assignment .
8,791
public function getTypeofCondition ( Variable $ variableVariable , $ operator , $ value , CompilationContext $ context ) { $ variableName = $ this -> getVariableCode ( $ variableVariable ) ; switch ( $ value ) { case 'array' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_ARRAY' ; break ; case 'object' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_OBJECT' ; break ; case 'null' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_NULL' ; break ; case 'string' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_STRING' ; break ; case 'int' : case 'long' : case 'integer' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_LONG' ; break ; case 'double' : case 'float' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_DOUBLE' ; break ; case 'boolean' : case 'bool' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_BOOL' ; break ; case 'resource' : $ condition = 'Z_TYPE_P(' . $ variableName . ') ' . $ operator . ' IS_RESOURCE' ; break ; case 'callable' : $ condition = 'zephir_is_callable(' . $ variableName . ' TSRMLS_CC) ' . $ operator . ' 1' ; break ; default : throw new CompilerException ( sprintf ( 'Unknown type: "%s" in typeof comparison' , $ value ) ) ; } return $ condition ; }
Checks the type of a variable using the ZendEngine constants .
8,792
public function getInternalSignature ( ClassMethod $ method , CompilationContext $ context ) { if ( $ method -> isInitializer ( ) && ! $ method -> isStatic ( ) ) { return 'zend_object_value ' . $ method -> getName ( ) . '(zend_class_entry *class_type TSRMLS_DC)' ; } if ( $ method -> isInitializer ( ) && $ method -> isStatic ( ) ) { return 'void ' . $ method -> getName ( ) . '(TSRMLS_D)' ; } $ signatureParameters = [ ] ; $ parameters = $ method -> getParameters ( ) ; if ( \ is_object ( $ parameters ) ) { foreach ( $ parameters -> getParameters ( ) as $ parameter ) { switch ( $ parameter [ 'data-type' ] ) { case 'int' : case 'uint' : case 'long' : case 'double' : case 'bool' : case 'char' : case 'uchar' : case 'string' : case 'array' : $ signatureParameters [ ] = 'zval *' . $ parameter [ 'name' ] . '_param_ext' ; break ; default : $ signatureParameters [ ] = 'zval *' . $ parameter [ 'name' ] . '_ext' ; break ; } } } if ( \ count ( $ signatureParameters ) ) { return 'void ' . $ method -> getInternalName ( ) . '(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used, ' . implode ( ', ' , $ signatureParameters ) . ' TSRMLS_DC)' ; } return 'void ' . $ method -> getInternalName ( ) . '(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC)' ; }
Returns the signature of an internal method .
8,793
private function resolveOffsetExprs ( $ offsetExprs , CompilationContext $ compilationContext ) { $ keys = '' ; $ offsetItems = [ ] ; $ numberParams = 0 ; foreach ( $ offsetExprs as $ offsetExpr ) { if ( 'a' == $ offsetExpr ) { $ keys .= 'a' ; ++ $ numberParams ; continue ; } switch ( $ offsetExpr -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : $ keys .= 'l' ; $ offsetItems [ ] = $ offsetExpr -> getCode ( ) ; ++ $ numberParams ; break ; case 'string' : $ keys .= 's' ; $ offsetItems [ ] = 'SL("' . $ offsetExpr -> getCode ( ) . '")' ; $ numberParams += 2 ; break ; case 'variable' : $ variableIndex = $ compilationContext -> symbolTable -> getVariableForRead ( $ offsetExpr -> getCode ( ) , $ compilationContext , null ) ; switch ( $ variableIndex -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : $ keys .= 'l' ; $ offsetItems [ ] = $ this -> getVariableCode ( $ variableIndex ) ; ++ $ numberParams ; break ; case 'string' : case 'variable' : $ keys .= 'z' ; $ offsetItems [ ] = $ this -> getVariableCode ( $ variableIndex ) ; ++ $ numberParams ; break ; default : throw new CompilerException ( sprintf ( 'Variable: %s cannot be used as array index' , $ variableIndex -> getType ( ) ) , $ offsetExpr -> getOriginal ( ) ) ; } break ; default : throw new CompilerException ( sprintf ( 'Value: %s cannot be used as array index' , $ offsetExpr -> getType ( ) ) , $ offsetExpr -> getOriginal ( ) ) ; } } return [ $ keys , $ offsetItems , $ numberParams ] ; }
Resolve expressions .
8,794
public function getLastLine ( ) { if ( ! $ this -> lastStatement ) { $ this -> lastStatement = $ this -> statements [ \ count ( $ this -> statements ) - 1 ] ; } }
Returns the last line in the last statement .
8,795
public function setImplementsInterfaces ( array $ implementedInterfaces ) { $ interfaces = [ ] ; foreach ( $ implementedInterfaces as $ implementedInterface ) { $ interfaces [ ] = $ implementedInterface [ 'value' ] ; } $ this -> interfaces = $ interfaces ; }
Sets the implemented interfaces .
8,796
public function getExtendsClassDefinition ( ) { if ( ! $ this -> extendsClassDefinition && $ this -> extendsClass ) { if ( $ this -> compiler ) { $ this -> setExtendsClassDefinition ( $ this -> compiler -> getClassDefinition ( $ this -> extendsClass ) ) ; } } return $ this -> extendsClassDefinition ; }
Returns the class definition related to the extended class .
8,797
public function getDependencies ( ) { $ dependencies = [ ] ; if ( $ this -> extendsClassDefinition && $ this -> extendsClassDefinition instanceof self ) { $ dependencies [ ] = $ this -> extendsClassDefinition ; } foreach ( $ this -> implementedInterfaceDefinitions as $ interfaceDefinition ) { if ( $ interfaceDefinition instanceof self ) { $ dependencies [ ] = $ interfaceDefinition ; } } return $ dependencies ; }
Calculate the dependency rank of the class based on its dependencies .
8,798
public function getParsedDocBlock ( ) { if ( ! $ this -> parsedDocblock ) { if ( \ strlen ( $ this -> docBlock ) > 0 ) { $ parser = new DocblockParser ( '/' . $ this -> docBlock . '/' ) ; $ this -> parsedDocblock = $ parser -> parse ( ) ; } else { return null ; } } return $ this -> parsedDocblock ; }
Returns the parsed docBlock .
8,799
public function addProperty ( ClassProperty $ property ) { if ( isset ( $ this -> properties [ $ property -> getName ( ) ] ) ) { throw new CompilerException ( "Property '" . $ property -> getName ( ) . "' was defined more than one time" , $ property -> getOriginal ( ) ) ; } $ this -> properties [ $ property -> getName ( ) ] = $ property ; }
Adds a property to the definition .