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


C++ SyntaxTree::getChildren方法代码示例

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


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

示例1: compile

int Compiler::compile(const SyntaxTree& tree, BytecodeWriter& output, location_t target) {

   switch (tree.type) {
      case SyntaxTree::TYPE_BLOCK:
      {
         mnBlockValueStackSize.push(mNamesStack.size());

         for (list<SyntaxTree*>::const_iterator it = tree.getChildren().begin();
                 it != tree.getChildren().end();
                 ++it)
            compile(**it, output, target);

         deleteValues(mnBlockValueStackSize.top(), output, true);

         mnBlockValueStackSize.pop();

         return 0;
      }

      case SyntaxTree::TYPE_IF:
      {
         if (mDeclareOnly.top()) {
            return target;
         }
         mnBlockValueStackSize.push(mNamesStack.size());

         list<SyntaxTree*>::const_iterator it = tree.getChildren().begin();
         const SyntaxTree* pConditionTree = *it;

         target = compile(*pConditionTree, output, target);
         output << OP_JUMP_COND << target;
         size_t jumpIndex = output.getSize();
         output << (index_t) 0;

         ++it;
         const SyntaxTree* pIfBlock = *it;
         compile(*pIfBlock, output, target);

         ++it;
         if (it != tree.getChildren().end()) {//there's an if block
            output << OP_JUMP;
            size_t afterElseJumpIndex = output.getSize();
            output << (index_t) 0;

            output.set(jumpIndex, (index_t) output.getSize());

            compile(**it, output, target);

            output.set(afterElseJumpIndex, (index_t) output.getSize());

         } else
            output.set(jumpIndex, (index_t) output.getSize());

         deleteValues(mnBlockValueStackSize.top(), output, true);
         mnBlockValueStackSize.pop();
         break;
      }

      case SyntaxTree::TYPE_WHILE:
      {
         if (mDeclareOnly.top()) {
            return target;
         }

         list<SyntaxTree*>::const_iterator it = tree.getChildren().begin();

         mnBlockValueStackSize.push(mNamesStack.size());

         mDeclareOnly.push(true);
         compile(**it, output, target);
         mDeclareOnly.pop();

         index_t beginning = output.getSize();

         location_t result = compile(**it, output, target);

         output << OP_JUMP_COND << result;
         index_t jumpIndex = output.getSize();
         output << (index_t) 0;

         ++it; //block
         vector<index_t> continues;
         vector<index_t> breaks;

         mContinues.push(&continues);
         mBreaks.push(&breaks);

         mnLoopValueStackSize.push(mNamesStack.size());
         compile(**it, output, target); // compile the block
         mnLoopValueStackSize.pop();

         output << OP_JUMP << beginning;

         output.set(jumpIndex, (index_t) output.getSize());

         for (size_t i = 0; i < continues.size(); i++)
            output.set(continues[i], beginning);

         for (size_t i = 0; i < breaks.size(); i++)
            output.set(breaks[i], output.getSize());
//.........这里部分代码省略.........
开发者ID:keebus,项目名称:IonScript,代码行数:101,代码来源:Compiler.cpp


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