void BlockList::Add(const vec2_t &vertex)
{
    if( _blocks.empty() )
        NewBlock();

    Block* h = _blocks.front();

    if( h->isFull() ) {
        NewBlock();
        h = _blocks.front();
    }

    h->Add( vertex );

    Block* last = _blocks.back();

    //see if we can disgard the last block
    if(last != h && last->XRange().Disjoint(_xrange) ) {
        PopBack();
    }

    // check if _yrange is valid, if not, 
    // initialize with the help of this first y value
    if(isnan(_yrange.Length())) {
        _yrange = Interval(vertex.y, vertex.y);
    }
    else {
        _yrange.Extend( vertex.y );
    }
}
Beispiel #2
0
/*
 *  stmt := '{' (stmt)* '}'
 *		   | command-def
 *		   | const-def
 *         | variable-def
 *		   | expr
 */
Statement* Parser::statement() {
    // Always check for block statements first! Block statements
    // have a weird property: they can be interpreted as expressions
    // in the expression() production rule.
    if(accept(leftbrace)) {
        Block* b = new Block(last.line, error);
        while(sym != rightbrace && sym != finished) {
            b->Add(statement());
        }
        expect(rightbrace);
        return b;
    }
    else if(accept(commandsym)) {
        return commanddef();
    }
    else if(accept(constsym)) {
        return constdef();
    }

    // ROM writing statements
    else if(accept(romsym)) {
        RomWrite* stmt = new RomWrite(last.line, error);
        expect(leftbracket);
        stmt->SetBase(expression());
        expect(rightbracket);
        expect(equals);
        stmt->SetValue(expression());
        return stmt;
    }
    else if(accept(romtblsym)) {
        RomWrite* stmt = new RomWrite(last.line, error);
        expect(leftbracket);
        stmt->SetBase(expression());
        expect(comma);
        stmt->SetSize(expression());
        expect(comma);
        stmt->SetIndex(expression());
        expect(rightbracket);
        expect(equals);
        stmt->SetValue(expression());
        return stmt;
    }
    // Identifiers can also begin expressions, so we have to
    // peek ahead to decide which production rule to apply
    /*else if(sym == identifier) {
    	symbol peeked = lexer->Peek();
    	if(peeked == colon) {
    		accept(identifier);
    		int line = last.line;
    		string name = last.sval;
    		accept(colon);
    		return new Label(line, name, error);
    	}
    	else {
    		return new ExprStmt(last.line, expression(), error);
    	}
    }*/
    // If all else fails, try it as an expression statement
    return new ExprStmt(last.line, expression(), error);
}
void BlockList::NewBlock( const bool copy_last )
{

    Block* b = new DataBlock();

    if( !_blocks.empty() && copy_last ) {
        Block* l = _blocks.front();
        b->Add( l->LastValue() );
    }

    _blocks.push_front(b);

}