当前位置: 首页>>代码示例>>PHP>>正文


PHP Context::addScopeVariable方法代码示例

本文整理汇总了PHP中Phan\Language\Context::addScopeVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::addScopeVariable方法的具体用法?PHP Context::addScopeVariable怎么用?PHP Context::addScopeVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phan\Language\Context的用法示例。


在下文中一共展示了Context::addScopeVariable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: visitVar

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitVar(Node $node) : Context
 {
     $variable_name = AST::variableName($node);
     // Check to see if the variable already exists
     if ($this->context->getScope()->hasVariableWithName($variable_name)) {
         $variable = $this->context->getScope()->getVariableWithName($variable_name);
         // If we're assigning to an array element then we don't
         // know what the constitutation of the parameter is
         // outside of the scope of this assignment, so we add to
         // its union type rather than replace it.
         if ($this->is_dim_assignment) {
             $variable->getUnionType()->addUnionType($this->right_type);
         } else {
             // If the variable isn't a pass-by-reference paramter
             // we clone it so as to not disturb its previous types
             // as we replace it.
             if (!($variable instanceof Parameter && $variable->isPassByReference())) {
                 $variable = clone $variable;
             }
             $variable->setUnionType($this->right_type);
         }
         $this->context->addScopeVariable($variable);
         return $this->context;
     }
     $variable = Variable::fromNodeInContext($this->assignment_node, $this->context, $this->code_base);
     // Set that type on the variable
     $variable->getUnionType()->addUnionType($this->right_type);
     // Note that we're not creating a new scope, just
     // adding variables to the existing scope
     $this->context->addScopeVariable($variable);
     return $this->context;
 }
开发者ID:themarios,项目名称:phan,代码行数:40,代码来源:AssignmentVisitor.php

示例2: getOrCreateVariable

 /**
  * @return Variable
  * A variable in scope or a new variable
  *
  * @throws NodeException
  * An exception is thrown if we can't understand the node
  */
 public function getOrCreateVariable() : Variable
 {
     try {
         return $this->getVariable();
     } catch (IssueException $exception) {
         // Swallow it
     }
     // Create a new variable
     $variable = Variable::fromNodeInContext($this->node, $this->context, $this->code_base, false);
     $this->context->addScopeVariable($variable);
     return $variable;
 }
开发者ID:ablyler,项目名称:phan,代码行数:19,代码来源:ContextNode.php

示例3: visitStatic

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitStatic(Node $node) : Context
 {
     $variable = Variable::fromNodeInContext($node->children['var'], $this->context, $this->code_base, false);
     // If the element has a default, set its type
     // on the variable
     if (isset($node->children['default'])) {
         $default_type = UnionType::fromNode($this->context, $this->code_base, $node->children['default']);
         $variable->setUnionType($default_type);
     }
     // Note that we're not creating a new scope, just
     // adding variables to the existing scope
     $this->context->addScopeVariable($variable);
     return $this->context;
 }
开发者ID:jazzdan,项目名称:phan,代码行数:22,代码来源:BreadthFirstVisitor.php

示例4: visitVar

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitVar(Node $node) : Context
 {
     $variable_name = AST::variableName($node);
     // Check to see if the variable already exists
     if ($this->context->getScope()->hasVariableWithName($variable_name)) {
         $variable = $this->context->getScope()->getVariableWithName($variable_name);
         $variable->setUnionType($this->right_type);
         $this->context->addScopeVariable($variable);
         return $this->context;
     }
     $variable = Variable::fromNodeInContext($this->assignment_node, $this->context, $this->code_base);
     // Set that type on the variable
     $variable->getUnionType()->addUnionType($this->right_type);
     // Note that we're not creating a new scope, just
     // adding variables to the existing scope
     $this->context->addScopeVariable($variable);
     return $this->context;
 }
开发者ID:hslatman,项目名称:phan,代码行数:26,代码来源:AssignmentVisitor.php

示例5: visitInstanceof

 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitInstanceof(Node $node) : Context
 {
     // Only look at things of the form
     // `$variable instanceof ClassName`
     if ($node->children['expr']->kind !== \ast\AST_VAR) {
         return $this->context;
     }
     try {
         // Get the variable we're operating on
         $variable = (new ContextNode($this->code_base, $this->context, $node->children['expr']))->getVariable();
         // Get the type that we're checking it against
         $type = UnionType::fromNode($this->context, $this->code_base, $node->children['class']);
         // Make a copy of the variable
         $variable = clone $variable;
         // Add the type to the variable
         $variable->getUnionType()->addUnionType($type);
         // Overwrite the variable with its new type
         $this->context->addScopeVariable($variable);
     } catch (\Exception $exception) {
         // Swallow it
     }
     return $this->context;
 }
开发者ID:ablyler,项目名称:phan,代码行数:31,代码来源:ConditionVisitor.php


注:本文中的Phan\Language\Context::addScopeVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。