Ejemplo n.º 1
0
void addChar(struct bufferlist * buffer, char c)
{
	if (buffer->last == NULL)
		extendBuffer(buffer);
	if (buffer->last->count >= (BUF_PIECE_SIZE))
		extendBuffer(buffer);
	buffer->last->str[buffer->last->count] = c;
	buffer->last->str[buffer->last->count + 1] = '\0';
	++buffer->last->count;
	++buffer->count;
}
Ejemplo n.º 2
0
_ANTLRTokenPtr ANTLRTokenBuffer::
getToken()
{
	if ( tp <= last )	// is there any buffered lookahead still to be read?
	{
		return *tp++;	// read buffered lookahead
	}
	// out of buffered lookahead, get some more "real"
	// input from getANTLRToken()
	if ( num_markers==0 )
	{
		if( next > threshold )
		{
#ifdef DBG_TBUF
fprintf(stderr,"getToken: next > threshold (high water is %d)\n", threshold-buffer);
#endif
			makeRoom();
		}
	}
	else {
		if ( next > end_of_buffer )
		{
#ifdef DBG_TBUF
fprintf(stderr,"getToken: next > end_of_buffer (size is %d)\n", buffer_size);
#endif
			extendBuffer();
		}
	}
	*next = getANTLRToken();
	(*next)->ref();				// say we have a copy of this pointer in buffer
	last = next;
	next++;
	tp = last;
	return *tp++;
}
Ejemplo n.º 3
0
/*
 * returns the token pointer n positions ahead.
 * This implies that bufferedToken(1) gets the NEXT symbol of lookahead.
 * This is used in conjunction with the ANTLRParser lookahead buffer.
 *
 * No markers are set or anything.  A bunch of input is buffered--that's all.
 * The tp pointer is left alone as the lookahead has not been advanced
 * with getToken().  The next call to getToken() will find a token
 * in the buffer and won't have to call getANTLRToken().
 *
 * If this is called before a consume() is done, how_many_more_i_need is
 * set to 'n'.
 */
_ANTLRTokenPtr ANTLRTokenBuffer::
bufferedToken(int n)
{
//	int how_many_more_i_need = (last-tp < 0) ? n : n-(last-tp)-1;
	int how_many_more_i_need = (tp > last) ? n : n-(last-tp)-1;
	// Make sure that at least n tokens are available in the buffer
#ifdef DBG_TBUF
	fprintf(stderr, "bufferedToken(%d)\n", n);
#endif
	for (int i=1; i<=how_many_more_i_need; i++)
	{
		if ( next > end_of_buffer )	// buffer overflow?
		{
			extendBuffer();
		}
		*next = getANTLRToken();
		(*next)->ref();		// say we have a copy of this pointer in buffer
		last = next;
		next++;
	}
	return tp[n - 1];
}
void ByteStringExtractor::appendChar(char ch) {
  if(m_strLength >= m_bufLength) {
    extendBuffer();
  }
  m_buf[m_strLength++] = ch;
}