Ejemplo n.º 1
0
void LessParser::handleMixin(BlockNode* blockNode) {

    //cerr << "MIXIN_START: " << blockNode->FullSelectors << endl;

    for(auto it = blockNode->Children.begin(); it != blockNode->Children.end(); ++it) {

        if((*it)->Type == ParseNodeType::Mixin) {

            MixinNode* mixin = (MixinNode*) *it;

            BlockNode* node = blockNode;
            while((node = (BlockNode*) node->Parent) != 0) {

                for(auto jt = node->Children.begin(); jt != node->Children.end(); ++jt) {

                    if((*jt)->Type == ParseNodeType::Block) {

                        BlockNode* block = (BlockNode*) *jt;

                        if(block->Selectors == mixin->Anchor) {

                            mixin->LinkedBlock = block->Copy();
                            mixin->LinkedBlock->Parent = node;

                            string fullSelectors(mixin->LinkedBlock->Selectors);
                            if(!node->IsRoot) fullSelectors.insert(0, " ").insert(0, node->FullSelectors);
                            mixin->LinkedBlock->FullSelectors = fullSelectors;

                            if(mixin->Arguments != "") mixin->LinkedBlock->FillArguments(mixin->Arguments);

                            goto MIXIN_ONE_DONE;

                        }

                    }

                }

            }

            FATAL("ERROR_MIXIN_LINK_FAILED");

            MIXIN_ONE_DONE:
                //cerr << "MIXIN_LINK: " << mixin->Anchor << " -> " << mixin->LinkedBlock->FullSelectors << endl;
                cout;

        }
        else if((*it)->Type == ParseNodeType::Block) {

            BlockNode* block = (BlockNode*) *it;
            handleMixin(block);

        }

    }

    //cerr << "MIXIN_END: " << blockNode->FullSelectors << endl;

}
Ejemplo n.º 2
0
void CDisassembler::ParseProgram(Program *prog)
{
	prog->EntryAddr = EntryAddr;

	int functioni;
	for( functioni = 1; functioni < FunctionList.GetNumEntries(); functioni++ )
	{
		int section = FunctionList[functioni].Section;
		uint64_t func_start_offset = FunctionList[functioni].Start;
		uint64_t func_end_offset = FunctionList[functioni].End;
		uint64_t section_addr = Sections[section].SectionAddress;

		if((Sections[section].Type & 0xFF) == 1)
		{
			FunctionNode func;
			func.StartAddress = section_addr + func_start_offset;
			func.EndAddress = section_addr + func_end_offset;

			vector<Instruction> insns;
			uint64_t start_addr, end_addr;
			SetFunctionDescriptor(func.StartAddress);
			while( GetBlockInFunction( &insns, &start_addr, &end_addr ) != -1 )
			{
				if(insns.size() == 0)
					fprintf(stderr, "[error] can't get block assembly\n");

				BlockNode node;
				node.Init( insns, start_addr, end_addr );
				func.Insert( node );
				insns.clear();
			}
			//flow_graph1.PrintAllPath();

			prog->Insert(func);
		}
	}

	uint32_t sym_num = Symbols.GetNumEntries();
	for(int i = 0; i < sym_num; i++)
	{
		if(Symbols[i].Name)
		{
			int section = Symbols[i].Section;
			uint64_t section_addr = Sections[section].SectionAddress;
			uint64_t sym_addr = section_addr + Symbols[i].Offset;
			const char *sym_name = Symbols.GetName(i);
			if(sym_name[0] != '?')
				prog->AddSymbol(sym_addr, sym_name);
		}
	}
}
Ejemplo n.º 3
0
 virtual void deleteAll() {
     ifStmt->deleteAll();
     elifStmts->deleteAll();
     if (elseStmt) {
         elseStmt->deleteAll();
     }
 }
Ejemplo n.º 4
0
void
XmlRenderer::renderNode(const BlockNode& node)
{
  // StringBuffer attrs;

  // if (fShowNodeType && node.type().isDef())
  //   attrs << " ty='" << xmlEncode(node.type().typeId()) << "'";

  // displayOpenTagAttrs("block", StrHelper(attrs.toString()));
  // displayNodeList(nullptr, node.children());
  // displayCloseTag("block");
  displayNodeList("block", node.children());
}
Ejemplo n.º 5
0
void AstPrinter::printFunction(AstFunction *function) {
    print("function ");
    print(typeToName(function->returnType()));
    print(" ");
    print(function->name());
    print("(");
    for(uint32_t i  = 0; i < function->parametersNumber(); i++) {
        if (i != 0)
            print(", ");
        print(typeToName(function->parameterType(i)));
        print(" ");
        print(function->parameterName(i));
    }
    print(") ");
    BlockNode *block = function->node()->body();
    if (block->nodeAt(0) && block->nodeAt(0)->isNativeCallNode()) {
        block->nodeAt(0)->visit(this);
        print("\n");
    } else {
		function->node()->body()->visit(this);
    }
}
Ejemplo n.º 6
0
ForNode* Parser::parseFor() {
    uint32_t token = _currentTokenIndex;
    ensureKeyword("for");
    ensureToken(tLPAREN);

    if (currentToken() != tIDENT) {
        error("identifier expected");
    }

    const string& varName = currentTokenValue();
    consumeToken();

    ensureKeyword("in");

    AstNode* inExpr = parseExpression();
    ensureToken(tRPAREN);

    BlockNode* forBody = parseBlock(true);
    AstVar* forVar = forBody->scope()->lookupVariable(varName);

    return new ForNode(token, forVar, inExpr, forBody);
}
Ejemplo n.º 7
0
void BlockNode::render( OutputStream *stream, Context *c )
{
  QVariant &variant = c->renderContext()->data( BLOCK_CONTEXT_KEY );
  BlockContext blockContext = variant.value<BlockContext>();

  c->push();

  if ( blockContext.isEmpty() ) {
    m_context = c;
    m_stream = stream;
    c->insert( QLatin1String( "block" ), QVariant::fromValue( static_cast<QObject *>( this ) ) );
    m_list.render( stream, c );
    m_stream = 0;
  } else {
    BlockNode *block = blockContext.pop( m_name );
    variant.setValue( blockContext );
    BlockNode *push = block;
    if ( !block )
      block = this;

    // BIC Make const when render() is const.
    NodeList list = block->m_list;

    block = new BlockNode( block->m_name, 0 );
    block->setNodeList( list );
    block->m_context = c;
    block->m_stream = stream;
    c->insert( QLatin1String( "block" ), QVariant::fromValue( static_cast<QObject *>( block ) ) );
    list.render( stream, c );

    delete block;
    if ( push ) {
      blockContext.push( m_name, push );
      variant.setValue( blockContext );
    }
  }
  c->pop();
}
Ejemplo n.º 8
0
Node* BlockNodeFactory::getNode( const QString &tagContent, Parser *p ) const
{
  const QStringList expr = smartSplit( tagContent );

  if ( expr.size() != 2 ) {
    throw Grantlee::Exception( TagSyntaxError, QLatin1String( "block tag takes one argument" ) );
  }

  const QString blockName = expr.at( 1 );

  QVariant loadedBlocksVariant = p->property( __loadedBlocks );
  QVariantList blockVariantList;

  if ( loadedBlocksVariant.isValid() && loadedBlocksVariant.type() == QVariant::List ) {
    blockVariantList = loadedBlocksVariant.toList();
    QListIterator<QVariant> it( blockVariantList );
    while ( it.hasNext() ) {
      const QString blockNodeName = it.next().toString();

      if ( blockNodeName == blockName ) {
        throw Grantlee::Exception( TagSyntaxError, QString::fromLatin1( "%1 appears more than once." ).arg( blockName ) );
      }
    }
  }
  // Block not already in list.
  blockVariantList.append( blockName );
  loadedBlocksVariant = QVariant( blockVariantList );

  p->setProperty( __loadedBlocks, loadedBlocksVariant );

  BlockNode *n = new BlockNode( blockName, p );
  const NodeList list = p->parse( n, QStringList() << QLatin1String( "endblock" ) << QLatin1String( "endblock " ) + blockName );

  n->setNodeList( list );
  p->removeNextToken();

  return n;
}
Ejemplo n.º 9
0
BlockNode* Parser::parseBlock(bool needBraces, const bool scoped/* = true */) {
    if (needBraces) {
        ensureToken(tLBRACE);
    }

    if (scoped) {
      pushScope();
    }

    BlockNode* block = new BlockNode(_currentTokenIndex,
                                     _currentScope);
    TokenKind sentinel = needBraces ? tRBRACE : tEOF;

     while (currentToken() != sentinel) {
         if (currentToken() == tSEMICOLON) {
             consumeToken();
             continue;
         }
         AstNode* statement = parseStatement();
         // Ignore statements that doesn't result in AST nodes, such
         // as variable or function declaration.
         if (statement != 0) {
             block->add(statement);
         }
     }

    if (scoped) {
      popScope();
    }

     if (needBraces) {
         ensureToken(tRBRACE);
     }

     return block;
}
Ejemplo n.º 10
0
 virtual void deleteAll() {
     block->deleteAll();
 }
Ejemplo n.º 11
0
 virtual void deleteAll() {
     args->deleteAll();
     body->deleteAll();
 }
Ejemplo n.º 12
0
 virtual void deleteAll() {
     cond->deleteAll();
     body->deleteAll();
 }
Ejemplo n.º 13
0
 virtual void deleteAll() {
     var->deleteAll();
     cond->deleteAll();
     body->deleteAll();
 }
Ejemplo n.º 14
0
void ScheduleDialog::drawTimings(DrawProperties *p, BlockNode* node)
{
    int line = blocks_.findIndex(node);
    int y = p->y + line * (BOX_HEIGHT + BOX_YSPACING) + RULER_HEIGHT;
    // if nameWidth is set the name should be drawn within the graph canvas
    if (p->nameWidth == 0) {
        // draw labels
        QCanvasText* text = new QCanvasText(node->model()->name(), labelCanvas);
        text->move(WIDGET_SPACING, y);
        text->show();

        // resize canvas if label doesn't fit.
        if ((int)(text->boundingRect().width() + 2 * WIDGET_SPACING)
            > labelCanvas->width())
        {
            labelCanvas->resize(text->boundingRect().width()
                                + (2 * WIDGET_SPACING), labelCanvas->height());
            labelCanvasView->setFixedWidth(labelCanvas->width() + 4);
        }
    } else {
        // draw labels
        QCanvasText* text = new QCanvasText(node->model()->name(), p->canvas);
        text->move(p->x, y);
        text->show();
    }

    // check if block is configured correctly
    if (node->clock() <= 0) {
        // draw info and skip
        QCanvasRectangle *box = new QCanvasRectangle(p->canvas);
        box->setSize(p->width - p->nameWidth, BOX_HEIGHT + BOX_YSPACING);
        box->setBrush(white);
        box->setPen(lightGray);
        box->move(p->x + p->nameWidth, RULER_HEIGHT - BOX_YSPACING
                  / 2 + line * (BOX_YSPACING + BOX_HEIGHT));
        box->setZ(2);
        box->show();

        QCanvasText *text = new QCanvasText(tr("Missing clock value."),
            p->canvas);
        text->move(p->x + p->nameWidth, y);
        text->setColor(black);
        text->setZ(3);
        text->show();
        return;
    }

    // draw blocks
    int t = node->offset();
    double X = t * p->pixPerNs;
    while (X < p->width - p->nameWidth) {
        // draw block
        QRect thisBlock = calcBlockPosition(p, node, t);
        QCanvasRectangle* box = new FancyRectangle(thisBlock, p->canvas);
        //        box->setBrush(QBrush(white));
        box->setBrush(QBrush(colormanager_->color(node->model())));
        box->setZ(2);
        box->show();

        // draw lines for all connected 'children'
        QPtrList<BlockNode> neighbours = node->neighbours();
        for (QPtrListIterator<BlockNode> it(neighbours); it != 0; ++it) {
            BlockNode *target = *it;

            // skip if child has no clock
            if (target->clock() <= 0) {
                continue;
            }

            // find next start time for the target block
            unsigned int targetTime = target->offset();
            while (targetTime <= t + node->runtime()) {
                targetTime += target->clock();
            }

            // check if this block is the next source for the target block
            if (t + (2 * node->runtime()) + node->clock() < targetTime) {
                continue;
            }

            // calculate position of the target block
            QRect targetBlock = calcBlockPosition(p, target, targetTime);

            // draw a line with arrowhead between this block and the next
            // target block.
            QCanvasLine *line = new ArrowLine(p->canvas);
            int start = thisBlock.x() + (int)rint(node->runtime() * p->pixPerNs * zoom_);
            line->setPoints(start,
                            thisBlock.y() + thisBlock.height(),
                            targetBlock.x(),
                            targetBlock.y());
            line->setZ(1);
            line->show();
        }

        t += node->clock();
        X = rint(t * p->pixPerNs);
    }

    return;
}
Ejemplo n.º 15
0
FunctionNode* Parser::parseFunction() {
    uint32_t tokenIndex = _currentTokenIndex;
    ensureKeyword("function");

    if (currentToken() != tIDENT) {
        error("identifier expected");
    }
    const string& returnTypeName = currentTokenValue();
    VarType returnType = nameToType(returnTypeName);
    if (returnType == VT_INVALID) {
      error("wrong return type");
    }
    consumeToken();

    if (currentToken() != tIDENT) {
        error("name expected");
    }
    const string& name = currentTokenValue();
    consumeToken();

    Signature signature;
    signature.push_back(SignatureElement(returnType, "return"));

    ensureToken(tLPAREN);
    while (currentToken() != tRPAREN) {
        const string& parameterTypeName = currentTokenValue();
        VarType parameterType = nameToType(parameterTypeName);
        if (parameterType == VT_INVALID) {
            error("wrong parameter type");
        }
        consumeToken();
        const string& parameterName = currentTokenValue();
        if (currentToken() != tIDENT) {
            error("identifier expected");
        }
        consumeToken();
        signature.push_back(SignatureElement(parameterType, parameterName));

        if (currentToken() == tCOMMA) {
            consumeToken();
        }
    }
    ensureToken(tRPAREN);

    BlockNode* body = 0;
    pushScope();
    for (uint32_t i = 1; i < signature.size(); i++) {
      const string& name = signature[i].second;
      VarType type = signature[i].first;
      if (!_currentScope->declareVariable(name, type)) {
          error("Formal \"%s\" already declared", name.c_str());
      }
    }
    if ((currentToken() == tIDENT) && currentTokenValue() == "native") {
      consumeToken();
      if (currentToken() != tSTRING) {
          error("Native name expected, got %s", tokenStr(currentToken()));
      }
      pushScope();
      body = new BlockNode(_currentTokenIndex, _currentScope);
      body->add(new NativeCallNode(tokenIndex, currentTokenValue(), signature));
      consumeToken();
      ensureToken(tSEMICOLON);
      body->add(new ReturnNode(0, 0));
      popScope();
    } else {
      body = parseBlock(true, false);
      if (body->nodes() == 0 ||
          !(body->nodeAt(body->nodes() - 1)->isReturnNode())) {
        body->add(new ReturnNode(0, defaultReturnExpr(returnType)));
      }
    }
    popScope();

    if (_currentScope->lookupFunction(name) != 0) {
        error("Function %s already defined", name.c_str());
    }
    FunctionNode* result = new FunctionNode(tokenIndex, name, signature, body);
    _currentScope->declareFunction(result);

    // We don't add function node into AST.
    return 0;
}
Ejemplo n.º 16
0
void Jumpman::onCollision(CollisionEvent event)
{
    Collider* collider = event.myCollider();

    double rollbackTime = event.getCollisionTime() * mDeltaTime;

    float bounce = 1.3f;
    float bounceMin = 0.2f;

    unsigned int reference = collider->getRefNumber();



    if(reference == mFeetNumber)
    {
        //std::cout << " FEET " << std::endl;
        mIsGrounded = true;

         std::vector<glm::vec3> contactPoints = event.getContactPoints();
         float yOverlap = contactPoints[0].y;

         float upVelocity = glm::dot(mOrientation.getUp(), mVelocity);

        if(mVelocity.y < 0)
        {
            mVelocity.y = 0;
        }

        glm::vec3 pos = mOrientation.getPos();
        if(yOverlap - pos.y < 0.3f)
        {
            pos.y = yOverlap+mFeetHeight;
        }

        mOrientation.setPos(pos);

        std::cout << yOverlap << std::endl;

        //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getUp());
        //mOrientation.translate(rollback.x, rollback.y, rollback.z);
    }
    else if(reference == mRayNumber)
    {
        std::vector<glm::vec3> contactPoints = event.getContactPoints();

        //Should only be one point, but just make sure.
        for(int i = 0; i < contactPoints.size(); i++)
        {
            BlockNode* blockNode = (BlockNode*) event.collidedWith()->getMaster();
            mClimable = blockNode->isClimable(contactPoints[i]);
            mClimableCoord = contactPoints[i];
            std::cout << " RAYHIT: "; if(mClimable) std::cout << "brick" << std::endl; else std::cout << "metal" << std::endl;
            std::cout << "     X: " << contactPoints[i].x << " Y: " << contactPoints[i].y <<" Z:" << contactPoints[i].z << std::endl;
        }
    }
    else
    {
        if(reference == mFrontNumber)
        {
            mCanMoveForward = false;
            glm::vec3 inverseForward = -mOrientation.getForward();
            float forwardVelocity = glm::dot(inverseForward, mVelocity);

            if(forwardVelocity > 0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getForward());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= ( ((bounce * forwardVelocity)+bounceMin) * inverseForward) ;
                std::cout << "FRONT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mBackNumber)
        {
            mCanMoveBackward = false;
            glm::vec3 inverseForward = -mOrientation.getForward();
            float forwardVelocity = glm::dot(inverseForward, mVelocity);

            if(forwardVelocity < -0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getForward());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * forwardVelocity)-bounceMin) * inverseForward);
                std::cout << "BACK: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mLeftNumber)
        {
            mCanMoveLeft = false;
            float rightVelocity = glm::dot(mOrientation.getRight(), mVelocity);

            if(rightVelocity < -0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getRight());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * rightVelocity)-bounceMin) * mOrientation.getRight());
                std::cout << "LEFT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mRightNumber)
        {
            mCanMoveRight = false;
            float rightVelocity = glm::dot(mOrientation.getRight(), mVelocity);

            if(rightVelocity > 0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getRight());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * rightVelocity)+bounceMin) * mOrientation.getRight());
                std::cout << "RIGHT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mTopNumber)
        {
            mCanJump = false;
            float upVelocity = glm::dot(mOrientation.getUp(), mVelocity);

            if(upVelocity > 0.0f)
            {
                mBounceVelocity -= (((bounce * upVelocity)-bounceMin) * mOrientation.getUp());
            }
            //std::cout << " TOP " << std::endl;
        }
    }


}