예제 #1
0
int TokensTree::AddToken(Token* newToken,int forceidx)
{
    if(!newToken)
        return -1;

    const cc_string & name = newToken->m_Name;

    static TokenIdxSet tmp_tokens = TokenIdxSet();
    // tmp_tokens.clear();

    // Insert the token's name and the token in the (inserted?) list
    size_t idx2 = m_Tree.AddItem(name,tmp_tokens,false);
    TokenIdxSet& curlist = m_Tree.GetItemAtPos(idx2);

    int newitem = AddTokenToList(newToken,forceidx);
    curlist.insert(newitem);
    m_FilesMap[newToken->m_FileIdx].insert(newitem);

    // Add Token (if applicable) to the namespaces indexes
    if(newToken->m_ParentIndex < 0)
    {
        newToken->m_ParentIndex = -1;
        m_GlobalNameSpace.insert(newitem);
        if(newToken->m_TokenKind == tkNamespace)
            m_TopNameSpaces.insert(newitem);
    }

    // All done!
    return newitem;
}
예제 #2
0
int TokenTree::AddToken(Token* newToken, int forceIdx)
{
    if (!newToken)
        return -1;

    const wxString & name = newToken->m_Name;

    static TokenIdxSet tmpTokens = TokenIdxSet();

    // Insert the token's name and the token in the (inserted?) list
    size_t tokenIdx = m_Tree.AddItem(name, tmpTokens);
    TokenIdxSet& curList = m_Tree.GetItemAtPos(tokenIdx);

    int newItem = AddTokenToList(newToken, forceIdx);
    curList.insert(newItem);

    size_t fIdx = newToken->m_FileIdx;
    m_FileMap[fIdx].insert(newItem);

    // Add Token (if applicable) to the namespaces indexes
    if (newToken->m_ParentIndex < 0)
    {
        newToken->m_ParentIndex = -1;
        m_GlobalNameSpaces.insert(newItem);
        if (newToken->m_TokenKind == tkNamespace)
            m_TopNameSpaces.insert(newItem);
    }

    // All done!
    return newItem;
}
예제 #3
0
bool Lex::Run(const char * fileName) {
    std::ifstream fileP(fileName);
    Trastition trans = {State_start, State_start, Event_space};
    std::string buffer = "";
    char current;

    CreateTable();

    while(!fileP.eof()){
        fileP.get(current);
        buffer += current;

        trans.currentEvent = GetEventType(current);
        trans.prevState = trans.currentState;
        trans.currentState = tableTransition[trans.currentEvent][trans.currentState];

        // Ошибка
        if(trans.currentState == State_error)
        {
            console->LogError("Лексический анализатор", "Cчитан неизвестный символ");
            exit(1);
        }


        // Создание токена
        if(trans.currentState == State_createToken)
        {
            buffer.erase(buffer.length() - 1);
            AddTokenToList(buffer, GetTokenByState(trans.prevState));
            trans = {State_start, State_start, Event_space};
            buffer.clear();
        }

    }

    if(trans.currentState == State_createToken)
    {
        AddTokenToList(buffer, GetTokenByState(trans.prevState));
        trans = {State_start, State_start, Event_space};
        buffer.clear();
    }

    LogTokenList();
    fileP.close();
    return  true;
}
예제 #4
0
파일: extractfuncs.c 프로젝트: basecq/q2dos
/*
=================
GetFunctionNamesFromFile
=================
*/
void GetFunctionNamesFromFile (char *filename)
{
	source_t	*source;
	token_t		token, lasttoken;
	int			indent = 0, brace;
	int			isStatic = 0;
	tokenList_t	*listHead;

	// filter some files out
	if ( !Q_stricmp( filename, "bg_lib.c" ) ) {
		return;
	}

	listHead = NULL;
	source = LoadSourceFile( filename );
	if ( !source ) {
		Error( "error opening %s", filename );
		return;
	}

//	printf("loaded %s\n", filename);
//	if (!PC_ReadToken(source, &lasttoken))
//	{
//		FreeSource(source);
//		return;
//	} //end if
	while ( 1 )
	{
		if ( !PC_ReadToken( source, &token ) ) {
			break;
		}
		AddTokenToList( &listHead, &token );
		if ( token.type == TT_PUNCTUATION )
		{
			switch ( token.string[0] )
			{
			case ';':
				isStatic = 0;
				break;
			case '{':
				indent++;
				break;
			case '}':
				indent--;
				if ( indent < 0 )
					indent = 0;
				break;
			case '(':
				if ( indent <= 0 && lasttoken.type == TT_NAME )
				{
					StripTokenList( listHead );

					brace = 1;
					while ( PC_ReadToken( source, &token ) )
					{
						AddTokenToList( &listHead, &token );
						if ( token.string[0] == '(' ) {
							brace++;
						}
						else if ( token.string[0] == ')' )
						{
							brace--;
							if ( brace <= 0 )
							{
								if ( !PC_ReadToken( source, &token ) ) {
									break;
								}
								if ( token.string[0] == '{' ) {
									indent++;
									if ( !isStatic && MayScrewUp( lasttoken.string ) ) {
										AddFunctionName( lasttoken.string, filename, listHead );
									}
								}	//end if
								break;
							}	//end if
						}	//end if
					}	//end while
				}	//end if
				break;
			}	//end switch
		}	//end if
		if ( token.type == TT_NAME )
		{
			if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) {
				isStatic = 1;
			}
		}
		memcpy( &lasttoken, &token, sizeof( token_t ) );
	} //end while	
	FreeSource( source );
} //end of the function GetFunctionNamesFromFile
예제 #5
0
파일: extractfuncs.c 프로젝트: basecq/q2dos
/*
=================
GetTypeNamesFromFile

Knightmare- this gets structs / vars of a given type
=================
*/
void GetTypeNamesFromFile (char *filename, char *typeName)
{
	source_t	*source;
	token_t		token, lasttoken;
	int			indent = 0;//, brace;
	int			isStatic = 0;
	int			isExtern = 0;
	tokenList_t	*listHead;

	printf("BANANE!\n");

	listHead = NULL;
	source = LoadSourceFile( filename );
	if ( !source ) {
		Error( "error opening %s", filename );
		return;
	}

	while ( 1 )
	{
		if ( !PC_ReadToken( source, &token ) ) {
			break;
		}
		if ( token.type == TT_PUNCTUATION )
		{
			switch ( token.string[0] )
			{
			case ';':
				isStatic = 0;
				isExtern = 0;
				break;
			case '{':
				indent++;
				break;
			case '}':
				indent--;
				if ( indent < 0 )
					indent = 0;
				break;
			}
		}
		if ( token.type == TT_NAME )
		{	// type declarations for pointer table must be non-static, non-extern, and global in scope
			if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) {
				isStatic = 1;
			}
			if ( token.string[0] == 'e' && !strcmp( token.string, "extern" ) ) {
				isExtern = 1;
			}
			if ( !isStatic && !isExtern && indent == 0 && !strcmp(token.string, typeName) )
			{
				if ( PC_ReadToken( source, &token ) )
				{
					if ( token.type == TT_NAME )
					{
						if (listHead)
							listHead->next = NULL;
						listHead = NULL;
						AddTokenToList( &listHead, &token );
						AddFunctionName( token.string, filename, listHead );
					}
				}
			}
		}
		memcpy( &lasttoken, &token, sizeof( token_t ) );
	}
	FreeSource( source );
}