Exemple #1
0
static	pANTLR3_UINT8
insert8	(pANTLR3_STRING string, ANTLR3_UINT32 point, const char * newbit)
{
    ANTLR3_UINT32	len;

    if	(point >= string->len)
    {
        return	string->append(string, newbit);
    }

    len	= (ANTLR3_UINT32)strlen(newbit);

    if	(len == 0)
    {
        return	string->chars;
    }

    if	(string->size < (string->len + len + 1))
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(string->len + len + 1));
        string->size	= string->len + len + 1;
    }

    /* Move the characters we are inserting before, including the delimiter
     */
    ANTLR3_MEMMOVE((void *)(string->chars + point + len), (void *)(string->chars + point), (ANTLR3_UINT32)(string->len - point + 1));

    /* Note we copy the exact number of bytes
     */
    ANTLR3_MEMMOVE((void *)(string->chars + point), newbit, (ANTLR3_UINT32)(len));

    string->len += len;

    return  string->chars;
}
Exemple #2
0
static    pANTLR3_UINT8
setUTF16_UTF16    (pANTLR3_STRING string, const char * chars)
{
    ANTLR3_UINT32   len;
    pANTLR3_UINT16  in;

    /** First, determine the length of the input string
     */
    in	    = (pANTLR3_UINT16)chars;
    len   = 0;

    while   (*in++ != '\0')
    {
        len++;
    }

    if	(string->size < len + 1)
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(len + 1)));
        string->size	= len + 1;
    }

    /* Note we copy one more byte than the strlen in order to get the trailing '\0'
     */
    ANTLR3_MEMMOVE((void *)(string->chars), chars, (ANTLR3_UINT32)((len+1) * sizeof(ANTLR3_UINT16)));
    string->len	    = len;

    return  string->chars;

}
Exemple #3
0
static    pANTLR3_UINT8
appendUTF16_UTF16	(pANTLR3_STRING string, const char * newbit)
{
    ANTLR3_UINT32 len;
    pANTLR3_UINT16  in;

    /** First, determine the length of the input string
     */
    in	    = (pANTLR3_UINT16)newbit;
    len   = 0;

    while   (*in++ != '\0')
    {
        len++;
    }

    if	(string->size < (string->len + len + 1))
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)( sizeof(ANTLR3_UINT16) *(string->len + len + 1) ));
        string->size	= string->len + len + 1;
    }

    /* Note we copy one more byte than the strlen in order to get the trailing delimiter
     */
    ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + string->len), newbit, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(len+1)));
    string->len	+= len;

    return string->chars;
}
Exemple #4
0
/** Creates a new UTF16 string initialized with the UTF16 characters at the
 *  supplied ptr, of pre-determined size.
 * \param[in] factory - Pointer to the string factory that owns the strings
 * \param[in] ptr - Pointer to UTF16 encoded characters
 * \return pointer to the new string
 */
static    pANTLR3_STRING
newPtrUTF16_UTF16	(pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr, ANTLR3_UINT32 size)
{
    pANTLR3_STRING  string;

    string  = factory->newSize(factory, size);

    if	(string == NULL)
    {
        return	NULL;
    }

    if	(size <= 0)
    {
        return	string;
    }

    if	(ptr != NULL)
    {
        ANTLR3_MEMMOVE(string->chars, (const void *)ptr, (size * sizeof(ANTLR3_UINT16)));

        /* Terminate, these strings are usually used for Token streams and printing etc.
        */
        *(((pANTLR3_UINT16)(string->chars)) + size) = '\0';
        string->len = size;
    }

    return  string;
}
Exemple #5
0
static	pANTLR3_COMMON_TOKEN    
newPoolToken	    (pANTLR3_TOKEN_FACTORY factory)
{
    pANTLR3_COMMON_TOKEN    token;

    /* See if we need a new token pool before allocating a new
     * one
     */
    if	(factory->nextToken >= ANTLR3_FACTORY_POOL_SIZE)
    {
	/* We ran out of tokens in the current pool, so we need a new pool
	 */
	newPool(factory);
    }

    /* Assuming everything went well (we are trying for performance here so doing minimal
     * error checking. Then we can work out what the pointer is to the next token.
     */
    token   = factory->pools[factory->thisPool] + factory->nextToken;
    factory->nextToken++;

    /* We have our token pointer now, so we can initialize it to the predefined model.
     */
    ANTLR3_MEMMOVE((void *)token, (const void *)&factory->unTruc, (ANTLR3_UINT64)sizeof(ANTLR3_COMMON_TOKEN));

    /* And we are done
     */
    return  token;
}
Exemple #6
0
static	pANTLR3_UINT8
insertUTF16_UTF16	(pANTLR3_STRING string, ANTLR3_UINT32 point, const char * newbit)
{
    ANTLR3_UINT32	len;
    pANTLR3_UINT16	in;

    if	(point >= string->len)
    {
        return	string->append(string, newbit);
    }

    /** First, determine the length of the input string
     */
    in	    = (pANTLR3_UINT16)newbit;
    len	    = 0;

    while   (*in++ != '\0')
    {
        len++;
    }

    if	(len == 0)
    {
        return	string->chars;
    }

    if	(string->size < (string->len + len + 1))
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len + len + 1)));
        string->size	= string->len + len + 1;
    }

    /* Move the characters we are inserting before, including the delimiter
     */
    ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + point + len), (void *)(((pANTLR3_UINT16)string->chars) + point), (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len - point + 1)));


    /* Note we copy the exact number of characters
     */
    ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + point), newbit, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(len)));

    string->len += len;

    return  string->chars;
}
Exemple #7
0
/// \brief Create an ASCII string stream as input to ANTLR 3, copying the input string.
///
/// This string stream first makes a copy of the string at the supplied pointer
///
/// \param[in] inString	Pointer to the string to be copied as the input stream
/// \param[in] size	Size (in 8 bit ASCII characters) of the input string
/// \param[in] name	NAme to attach the input stream (can be NULL pointer)
///
/// \return
///	- Pointer to new input stream context upon success
///	- One of the ANTLR3_ERR_ defines on error.
///
/// \remark
///  - ANTLR does not alter the input string in any way.
///  - String is slightly incorrect in that the passed in pointer can be to any
///    memory in C version of ANTLR3 of course.
////
pANTLR3_INPUT_STREAM	antlr3NewAsciiStringCopyStream	    (pANTLR3_UINT8 inString, ANTLR3_UINT32 size, pANTLR3_UINT8 name)
{
	// Pointer to the input stream we are going to create
	//
	pANTLR3_INPUT_STREAM    input;

	// Allocate memory for the input stream structure
	//
	input   = (pANTLR3_INPUT_STREAM)
		ANTLR3_MALLOC(sizeof(ANTLR3_INPUT_STREAM));

	if	(input == NULL)
	{
		return	NULL;
	}

	// Indicate that we allocated this input and allocate it
	//
	input->isAllocated	    = ANTLR3_TRUE;
	input->data		    = ANTLR3_MALLOC((size_t)size);

	if	(input->data == NULL)
	{
		return		NULL;
	}

	// Structure was allocated correctly, now we can install the pointer and set the size.
	//
	ANTLR3_MEMMOVE(input->data, (const void *)inString, size);
	input->sizeBuf  = size;

	// Call the common 8 bit ASCII input stream handler
	// initializer type thingy doobry function.
	//
	antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM);


	input->istream->streamName	= input->strFactory->newStr(input->strFactory, name == NULL ? (pANTLR3_UINT8)"-memory-" : name);
	input->fileName				= input->istream->streamName;

	return  input;
}
Exemple #8
0
static    pANTLR3_UINT8
set8	(pANTLR3_STRING string, const char * chars)
{
    ANTLR3_UINT32	len;

    len = (ANTLR3_UINT32)strlen(chars);
    if	(string->size < len + 1)
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(len + 1));
        string->size	= len + 1;
    }

    /* Note we copy one more byte than the strlen in order to get the trailing '\0'
     */
    ANTLR3_MEMMOVE((void *)(string->chars), chars, (ANTLR3_UINT32)(len+1));
    string->len	    = len;

    return  string->chars;

}
Exemple #9
0
static    pANTLR3_UINT8
append8	(pANTLR3_STRING string, const char * newbit)
{
    ANTLR3_UINT32 len;

    len	= (ANTLR3_UINT32)strlen(newbit);

    if	(string->size < (string->len + len + 1))
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(string->len + len + 1));
        string->size	= string->len + len + 1;
    }

    /* Note we copy one more byte than the strlen in order to get the trailing
     */
    ANTLR3_MEMMOVE((void *)(string->chars + string->len), newbit, (ANTLR3_UINT32)(len+1));
    string->len	+= len;

    return string->chars;
}
Exemple #10
0
static	pANTLR3_UINT8
insertUTF16_8	(pANTLR3_STRING string, ANTLR3_UINT32 point, const char * newbit)
{
    ANTLR3_UINT32	len;
    ANTLR3_UINT32	count;
    pANTLR3_UINT16	inPoint;

    if	(point >= string->len)
    {
        return	string->append8(string, newbit);
    }

    len	= (ANTLR3_UINT32)strlen(newbit);

    if	(len == 0)
    {
        return	string->chars;
    }

    if	(string->size < (string->len + len + 1))
    {
        string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len + len + 1)));
        string->size	= string->len + len + 1;
    }

    /* Move the characters we are inserting before, including the delimiter
     */
    ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + point + len), (void *)(((pANTLR3_UINT16)string->chars) + point), (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len - point + 1)));

    string->len += len;

    inPoint = ((pANTLR3_UINT16)(string->chars))+point;
    for	(count = 0; count<len; count++)
    {
        *(inPoint + count) = (ANTLR3_UINT16)(*(newbit+count));
    }

    return  string->chars;
}