Esempio n. 1
0
bool Tokenizer::SkipBlock(const wxChar& ch)
{
    // skip blocks () [] {} <>
    wxChar match;
    switch (ch)
    {
        case '(': match = ')'; break;
        case '[': match = ']'; break;
        case '{': match = '}'; break;
        case '<': match = '>'; break;
        default : return false;
    }

    MoveToNextChar();
    int nestLevel = 1; // counter for nested blocks (xxx())
    while (NotEOF())
    {
        while (SkipWhiteSpace() || SkipString() || SkipComment())
            ;

        if (CurrentChar() == ch)
            ++nestLevel;
        else if (CurrentChar() == match)
            --nestLevel;

        MoveToNextChar();

        if (nestLevel == 0)
            break;
    }

    return NotEOF();
}
Esempio n. 2
0
void Tokenizer::SkipToEndConditionPreprocessor()
{
    do
    {
        wxChar ch = CurrentChar();
        if (ch == _T('\'') || ch == _T('"') || ch == _T('/') || ch <= _T(' '))
        {
            while (SkipWhiteSpace() || SkipString() || SkipComment())
                ;
            ch = CurrentChar();
        }

        if (ch == _T('#'))
        {
            MoveToNextChar();
            while (SkipWhiteSpace() || SkipComment())
                ;

            const wxChar current = CurrentChar();
            const wxChar next = NextChar();

            // #if
            if (current == _T('i') && next == _T('f'))
                SkipToEndConditionPreprocessor();

            // #endif
            else if (current == _T('e') && next == _T('n'))
            {
                SkipToEOL(false);
                break;
            }
        }
    }
    while (MoveToNextChar());
}
Esempio n. 3
0
void TFunctionScanner::ReadFunctionArgs(const TChar*& text)
{
	SkipWhiteSpace(text);
	
	if (*text == '(')
	{
		while (*text != ')')
		{
			if (IsString(text))
				SkipString(text);
			else if (IsComment(text))
				SkipComment(text);
			else
				NextChar(text);
		}

		NextChar(text);
		fScanState = kFunctionArgs;
	}
	else
	{
		while (1)
		{
			TChar ch = *text;

			if (IsString(text))
				SkipString(text);
			else if (IsComment(text))
				SkipComment(text);
			else
			{
				NextChar(text);
				
				if (ch == ';')
				{
					fScanState = kTopLevel;
					break;
				}
			}
		}
	}
}
Esempio n. 4
0
// expect we are not in a C-string.
bool Tokenizer::SkipToOneOfChars(const wxChar* chars, bool supportNesting, bool skipPreprocessor, bool skipAngleBrace)
{
    while (NotEOF() && !CharInString(CurrentChar(), chars))
    {
        MoveToNextChar();

        while (SkipString() || SkipComment())
            ;

        // use 'while' here to cater for consecutive blocks to skip (e.g. sometemplate<foo>(bar)
        // must skip <foo> and immediately after (bar))
        // because if we don't, the next block won't be skipped ((bar) in the example) leading to weird
        // parsing results
        bool done = false;
        while (supportNesting && !done)
        {
            switch (CurrentChar())
            {
                case '#':
                    if (skipPreprocessor)
                        SkipToEOL(true);
                    else
                        done = true;
                    break;
                case '{': SkipBlock('{'); break;
                case '(': SkipBlock('('); break;
                case '[': SkipBlock('['); break;
                case '<': // don't skip if << operator
                    if (skipAngleBrace)
                    {
                        if (NextChar() == '<')
                            MoveToNextChar(2); // skip it and also the next '<' or the next '<' leads to a SkipBlock('<');
                        else
                            SkipBlock('<');
                        break;
                    }

                default: done = true; break;
            }
        }

    }

    return NotEOF();
}
Esempio n. 5
0
void RemoveComments(String& l, bool& incomment)
{
	int q = -1;
	int w = -1;
	if(incomment)
		q = w = 0;
	else {
		const char *s = l;
		while(*s) {
			if(*s == '\"')
				s = SkipString(s);
			else
			if(s[0] == '/' && s[1] == '/') {
				q = int(s - ~l);
				SetSpaces(l, q, l.GetCount() - q);
				return;
			}
			else
			if(s[0] == '/' && s[1] == '*') {
				q = int(s - ~l);
				break;
			}
			else
				s++;
		}
		if(q >= 0)
			w = q + 2;
	}
	while(q >= 0) {
		int eq = l.Find("*/", w);
		if(eq < 0) {
			incomment = true;
			SetSpaces(l, q, l.GetCount() - q);
			return;
		}
		SetSpaces(l, q, eq + 2 - q);
		incomment = false;
		q = l.Find("/*");
		w = q + 2;
	}
}
Esempio n. 6
0
void Tokenizer::SkipToNextConditionPreprocessor()
{
    do
    {
        wxChar ch = CurrentChar();
        if (ch == _T('\'') || ch == _T('"') || ch == _T('/') || ch <= _T(' '))
        {
            while (SkipWhiteSpace() || SkipString() || SkipComment())
                ;
            ch = CurrentChar();
        }

        if (ch == _T('#'))
        {
            const unsigned int undoIndex = m_TokenIndex;
            const unsigned int undoLine = m_LineNumber;

            MoveToNextChar();
            while (SkipWhiteSpace() || SkipComment())
                ;

            const wxChar current = CurrentChar();
            const wxChar next = NextChar();

            // #if
            if (current == _T('i') && next == _T('f'))
                SkipToEndConditionPreprocessor();

            // #else #elif #elifdef #elifndef #endif
            else if (current == _T('e') && (next == _T('l') || next == _T('n')))
            {
                m_TokenIndex = undoIndex;
                m_LineNumber = undoLine;
                break;
            }
        }
    }
    while (MoveToNextChar());
}
Esempio n. 7
0
// ParseToMatchingBrace
//------------------------------------------------------------------------------
bool BFFIterator::ParseToMatchingBrace( char openBrace, char closeBrace )
{
    ASSERT( *m_Pos == openBrace );

    do
    {
        m_Pos++;
        SkipWhiteSpaceAndComments();

        // hit a nested brace?
        if ( *m_Pos == openBrace )
        {
            if ( ParseToMatchingBrace( openBrace, closeBrace ) == false )
            {
                return false;
            }
            continue;
        }

        // hit a string?
        if ( ( *m_Pos == '\'' ) || ( *m_Pos == '"' ) )
        {
            SkipString( *m_Pos );
        }

        // hit the close brace?
        if ( *m_Pos == closeBrace )
        {
            return true;
        }

        // a regular charater.... keep searching

    } while ( !IsAtEnd() );

    return false;
}
//
// Thermal sensor notification
//
BOOL CSilo_MISC::ParseXDRVI(CResponse* const pResponse, const char*& rszPointer)
{
    RIL_LOG_VERBOSE("CSilo_MISC::ParseXDRVI() - Enter\r\n");
    BOOL   fRet = FALSE;
    sOEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND* pData = NULL;
    UINT32 nIpcChrGrp;
    UINT32 nIpcChrTempThresholdInd;
    UINT32 nXdrvResult;
    UINT32 nSensorId;
    UINT32 nTemp;

    if (NULL == pResponse)
    {
        RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - pResponse is NULL.\r\n");
        goto Error;
    }

    pResponse->SetUnsolicitedFlag(TRUE);

    // Extract "<IPC_CHR_GRP>"
    if (!ExtractUInt32(rszPointer, nIpcChrGrp, rszPointer))
    {
        RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - Could not parse nIpcChrGrp.\r\n");
        goto Error;
    }

    // Parse <IPC_CHR_TEMP_THRESHOLD_IND>
    if (!SkipString(rszPointer, ",", rszPointer) ||
        !ExtractUInt32(rszPointer, nIpcChrTempThresholdInd, rszPointer))
    {
         RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() -"
                 " Unable to parse <IPC_CHR_TEMP_THRESHOLD_IND>!\r\n");
         goto Error;
    }

    // Parse <xdrv_result>
    if (!SkipString(rszPointer, ",", rszPointer) ||
        !ExtractUInt32(rszPointer, nXdrvResult, rszPointer))
    {
         RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - Unable to parse <xdrv_result>!\r\n");
         goto Error;
    }

    // Parse <temp_sensor_id>
    if (!SkipString(rszPointer, ",", rszPointer) ||
        !ExtractUInt32(rszPointer, nSensorId, rszPointer))
    {
         RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - Unable to parse <temp_sensor_id>!\r\n");
         goto Error;
    }

    // Parse <temp>
    if (!SkipString(rszPointer, ",", rszPointer) ||
        !ExtractUInt32(rszPointer, nTemp, rszPointer))
    {
         RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - Unable to parse <temp>!\r\n");
         goto Error;
    }

    RIL_LOG_INFO("CSilo_MISC::ParseXDRVI - IPC_CHR_GRP: %u, IPC_CHR_TEMP_THRESHOLD_IND: %u,"
            " xdrv_result: %u\r\n", nIpcChrGrp, nIpcChrTempThresholdInd, nXdrvResult);
    RIL_LOG_INFO("CSilo_MISC::ParseXDRVI - temp_sensor_id: %u, temp: %u\r\n", nSensorId, nTemp);

    pData = (sOEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND*)malloc(
            sizeof(sOEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND));
    if (NULL == pData)
    {
        RIL_LOG_CRITICAL("CSilo_MISC::ParseXDRVI() - Could not allocate memory for pData.\r\n");
        goto Error;
    }
    memset(pData, 0, sizeof(sOEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND));

    pData->nCommand = RIL_OEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND;
    pData->nSensorId = nSensorId;
    pData->nTemp = nTemp;

    pResponse->SetResultCode(RIL_UNSOL_OEM_HOOK_RAW);

    if (!pResponse->SetData((void*)pData, sizeof(sOEM_HOOK_RAW_UNSOL_THERMAL_ALARM_IND), FALSE))
    {
        goto Error;
    }

    fRet = TRUE;
Error:
    if (!fRet)
    {
        free(pData);
        pData = NULL;
    }

    RIL_LOG_VERBOSE("CSilo_MISC::ParseXDRVI() - Exit\r\n");
    return fRet;
}
Esempio n. 9
0
wxString Tokenizer::DoGetToken()
{
    int start = m_TokenIndex;
    bool needReplace = false;

    wxString str;
    wxChar   c = CurrentChar();

    if (c == '_' || wxIsalpha(c))
    {
        // keywords, identifiers, etc.

        // operator== is cheaper than wxIsalnum, also MoveToNextChar already includes IsEOF
        while (    ( (c == '_') || (wxIsalnum(c)) )
               &&  MoveToNextChar() )
            c = CurrentChar(); // repeat

        if (IsEOF())
            return wxEmptyString;

        needReplace = true;
        str = m_Buffer.Mid(start, m_TokenIndex - start);
    }
#ifdef __WXMSW__ // This is a Windows only bug!
    // fetch non-English characters, see more details in: http://forums.codeblocks.org/index.php/topic,11387.0.html
    else if (c == 178 || c == 179 || c == 185)
    {
        str = c;
        MoveToNextChar();
    }
#endif
    else if (wxIsdigit(c))
    {
        // numbers
        while (NotEOF() && CharInString(CurrentChar(), _T("0123456789.abcdefABCDEFXxLl")))
            MoveToNextChar();

        if (IsEOF())
            return wxEmptyString;

        str = m_Buffer.Mid(start, m_TokenIndex - start);
    }
    else if ( (c == '"') || (c == '\'') )
    {
        SkipString();
        //Now, we are after the end of the C-string, so return the whole string as a token.
        str = m_Buffer.Mid(start, m_TokenIndex - start);
    }
    else if (c == ':')
    {
        if (NextChar() == ':')
        {
            MoveToNextChar();
            MoveToNextChar();
            // this only copies a pointer, but operator= allocates memory and does a memcpy!
            str.assign(TokenizerConsts::colon_colon);
        }
        else
        {
            MoveToNextChar();
            str.assign(TokenizerConsts::colon);
        }
    }
    else if (c == '<')
    {
        if (m_State&tsSingleAngleBrace)
        {
            if ( !SkipToOneOfChars(  _T(">"), true, true)   )
                return wxEmptyString;
            MoveToNextChar();
            str= m_Buffer.Mid(start, m_TokenIndex - start);
        }
        else
        {
            str = c;
            MoveToNextChar();
        }
    }
    else if (c == '(')
    {
        if (m_State & tsReadRawExpression)
        {
            str = c;
            MoveToNextChar();
        }
        else
        {
            ReadParentheses(str);
        }
    }
    else
    {
        if      (c == '{')
            ++m_NestLevel;
        else if (c == '}')
            --m_NestLevel;

        str = c;
        MoveToNextChar();
    }

    if (m_FirstRemainingLength != 0 && m_BufferLen - m_FirstRemainingLength < m_TokenIndex)
    {
        m_FirstRemainingLength = 0;
        m_IsReplaceParsing = false;
        m_RepeatReplaceCount = 0;
    }

    if (needReplace && m_State ^ tsReadRawExpression)
        MacroReplace(str);

    return str;
}
Esempio n. 10
0
bool TFunctionScanner::ReadFunctionBody(const TChar*& text)
{
	bool result = false;
	SkipWhiteSpace(text);
	
	if (*text == ':')
	{
		// special case constructors
		NextChar(text);
		SkipWhiteSpace(text);
		
		while (*text != '{')
		{
			if (IsString(text))
				SkipString(text);
			else if (IsComment(text))
				SkipComment(text);
			else
				NextChar(text);
		}
	}
	else 
	{
		// skip "const", "throws", etc.
		// also handle K&R style function definitions
		
		while (isalnum(*text) || *text == '_')
		{
			while (isalnum(*text) || *text == '_')
				NextChar(text);
				
			SkipWhiteSpace(text);
			
			// for K&R support (pointer, function and array type arguments) 
			while (*text == '*' || *text == ';' || *text == ',' || 
				   *text == '[' || *text == ']' || *text == '(' || *text == ')')
			{
				NextChar(text);
				SkipWhiteSpace(text);
			}
		}
	}
		
	if (*text == '{')
	{
		NextChar(text);
		int bracketDepth = 1;
		
		while (bracketDepth > 0)
		{
			// need to do this to process comments correctly
			SkipWhiteSpace(text);
			
			TChar ch = *text;
			
			if (IsString(text))
			{
				SkipString(text);
				continue;	// don't call NextChar() since SkipString() already did
			}
			else if (ch == '{')
				++bracketDepth;
			else if (ch == '}')
				--bracketDepth;
			
			NextChar(text);
		}
		
		result = true;
	}
	else if (*text != ';')
		NextChar(text);
	
	fScanState = kTopLevel;
	return result;
}
Esempio n. 11
0
//
// IMS-Register notification
//
BOOL CSilo_IMS::ParseCIREGU(CResponse* const pResponse, const char*& rszPointer)
{
    RIL_LOG_VERBOSE("CSilo_IMS::ParseCIREGU() - Enter\r\n");

    BOOL   fRet     = FALSE;
    UINT32 uiRegInfo = 0;
    char   szExtInfo[MAX_BUFFER_SIZE];
    char   szAlpha[MAX_BUFFER_SIZE];
    int pos = 0;
    sOEM_HOOK_RAW_UNSOL_IMS_REG_STATUS data;

    if (NULL == pResponse)
    {
        RIL_LOG_CRITICAL("CSilo_IMS::ParseCIREGU() - pResponse is NULL.\r\n");
        goto Error;
    }

    pResponse->SetUnsolicitedFlag(TRUE);

    // Throw out the alpha chars if there are any
    (void)ExtractQuotedString(rszPointer, szAlpha, MAX_BUFFER_SIZE, rszPointer);

    // Parse "<reg_info>"
    if (!ExtractUInt32(rszPointer, uiRegInfo, rszPointer))
    {
        RIL_LOG_CRITICAL("CSilo_IMS::ParseCIREGU() - Could not parse IMS registration"
                "status indication\r\n");
        goto Error;
    }

    // Parse ",<ext_info>" if any. Debug purpose only.
    if (SkipString(rszPointer, ",", rszPointer)
            && ExtractUnquotedString(rszPointer, m_cTerminator, szExtInfo,
                    MAX_BUFFER_SIZE, rszPointer))
    {
        RIL_LOG_INFO("CSilo_IMS::ParseCIREGU() - IMS capabilities: %s", szExtInfo);
    }

    data.command = RIL_OEM_HOOK_RAW_UNSOL_IMS_REG_STATUS;
    data.status = uiRegInfo;

    CTE::GetTE().SetImsRegistrationStatus(uiRegInfo);

    RIL_LOG_VERBOSE("CSilo_IMS::ParseCIREGU() - CIREGU=[%d]\r\n", uiRegInfo);

    pResponse->SetResultCode(RIL_UNSOL_OEM_HOOK_RAW);

    if (!pResponse->SetData((void*)&data,
            sizeof(sOEM_HOOK_RAW_UNSOL_IMS_REG_STATUS), TRUE))
    {
        goto Error;
    }

    /*
     * When the IMS registration status change force the framework to query the data
     * registration state by completing RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED.
     */
    RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0);

    fRet = TRUE;
Error:
    RIL_LOG_VERBOSE("CSilo_IMS::ParseCIREGU() - Exit\r\n");
    return fRet;
}