clearSymbols() public method

Clears only all symbols.
public clearSymbols ( )
Example #1
0
 /**
  * Compile function to check it
  *
  * @param Context $context
  * @return bool
  */
 public function compile(Context $context)
 {
     if ($this->compiled) {
         return true;
     }
     $context->setFilepath($this->filepath);
     $this->compiled = true;
     $context->clearSymbols();
     $context->scopePointer = $this->getPointer();
     $context->setScope(null);
     if (count($this->statement->stmts) == 0) {
         return $context->notice('not-implemented-function', sprintf('Closure %s() is not implemented', $this->name), $this->statement);
     }
     if (count($this->statement->params) > 0) {
         /** @var  Node\Param $parameter */
         foreach ($this->statement->params as $parameter) {
             $type = CompiledExpression::UNKNOWN;
             if ($parameter->type) {
                 if (is_string($parameter->type)) {
                     $type = Types::getType($parameter->type);
                 } elseif ($parameter->type instanceof Node\Name) {
                     $type = CompiledExpression::OBJECT;
                 }
             }
             $context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef));
         }
     }
     foreach ($this->statement->stmts as $st) {
         \PHPSA\nodeVisitorFactory($st, $context);
     }
     return true;
 }
Example #2
0
 /**
  * Compile methods to check it
  *
  * @param Context $context
  */
 public function compile(Context $context)
 {
     $context->setScope($this);
     foreach ($this->methods as $method) {
         $context->clearSymbols();
         $method->compile($context);
         $symbols = $context->getSymbols();
         if (count($symbols) > 0) {
             foreach ($symbols as $name => $variable) {
                 /**
                  * Check if you are setting values to variable but didn't use it (mean get)
                  */
                 if ($variable->getGets() == 0 && $variable->incSets()) {
                     $context->warning('unused-variable', sprintf('Unused variable $%s in method %s()', $variable->getName(), $method->getName()));
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Compile methods to check it
  *
  * @param Context $context
  */
 public function compile(Context $context)
 {
     $context->setScope($this);
     foreach ($this->methods as $method) {
         $context->clearSymbols();
         if (!$method->isStatic()) {
             $thisPtr = new Variable('this', $this, CompiledExpression::OBJECT);
             $thisPtr->incGets();
             $context->addVariable($thisPtr);
         }
         $method->compile($context);
         $symbols = $context->getSymbols();
         if (count($symbols) > 0) {
             foreach ($symbols as $name => $variable) {
                 if ($variable->isUnused()) {
                     $context->warning('unused-variable', sprintf('Unused variable $%s in method %s()', $variable->getName(), $method->getName()));
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * @param Context $context
  * @return $this
  */
 public function compile(Context $context)
 {
     if ($this->compiled) {
         return true;
     }
     $this->compiled = true;
     $context->setFilepath($this->filepath);
     $context->setScope($this);
     $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($this->statement, $context));
     // Compile event for properties
     foreach ($this->properties as $property) {
         if (!$property->default) {
             continue;
         }
         // fire expression event for property default
         $context->getEventManager()->fire(Event\ExpressionBeforeCompile::EVENT_NAME, new Event\ExpressionBeforeCompile($property->default, $context));
     }
     // Compile event for PropertyProperty
     foreach ($this->properties as $property) {
         $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($property, $context));
     }
     // Compile event for constants
     foreach ($this->constants as $const) {
         $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($const, $context));
     }
     // Compiler event for property statements
     foreach ($this->propertyStatements as $prop) {
         $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($prop, $context));
     }
     // Compile each method
     foreach ($this->methods as $method) {
         $context->clearSymbols();
         if (!$method->isStatic()) {
             $thisPtr = new Variable('this', $this, CompiledExpression::OBJECT);
             $thisPtr->incGets();
             $context->addVariable($thisPtr);
         }
         $method->compile($context);
         $symbols = $context->getSymbols();
         if (count($symbols) > 0) {
             foreach ($symbols as $name => $variable) {
                 if ($variable->isUnused()) {
                     $context->warning('unused-' . $variable->getSymbolType(), sprintf('Unused ' . $variable->getSymbolType() . ' $%s in method %s()', $variable->getName(), $method->getName()));
                 }
             }
         }
     }
     return $this;
 }