Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

Intergrate the nativeparser_base to our parsertest project

(1/7) > >>

ollydbg:
When review our CC code, I see that the core type matching code is:

--- Code: ---    // find all other matches
    std::queue<ParserComponent> components;
    BreakUpComponents(actual_search, components);

    m_LastAISearchWasGlobal = components.size() <= 1;
    if (!components.empty())
        m_LastAIGlobalSearch = components.front().component;

    ResolveExpression(tree, components, *search_scope, result, caseSensitive, isPrefix);

    if (s_DebugSmartSense)
        CCLogger::Get()->DebugLog(F(_T("AI() AI leave, returned %d results"),result.size()));

    return result.size();

--- End code ---
The components is the statement when user write.
The ResolveExpression is in Nativeparser_base now. So, I think we can safely add the nativeparser_base to our parsertest project.

I see that the class Nativeparser_base is quite nice for testing. It does not contains UI related code. (simply remove #include <cbstyledtextctrl.h> in the cpp file)

I'm going to write the test for the ResolveExpression.(mostly after the parsing stage)

E.g.


--- Code: ---class A
{
public:
int m_Member1;
int m_Member2;
};

class B:public A
{
};

B obj;


--- End code ---

Now, we have a expression "obj.m_Member1".
The initial search scope is the -1 (the global namespace)

Running the function: ResolveExpression should return the one exact matches, which is the Token "m_Member1".
So, this is only the start point, later we can test more complex expressions or more classes in the hierarchy or template related code.

I'm starting the work on my local git repos. :) I will report any progress here in this thread.

ollydbg:
Ok, it works nice.

Copy nativeparser_base.h and nativeparser_base.cpp to the parser folder.

I have add some code snippet in frame.cpp

--- Code: ---    //Here we are going to test the expression solving algorithm

    NativeParserTest nativeParserTest;

    wxString exp = _T("obj.m_Member1");

    TokenIdxSet searchScope;
    searchScope.insert(-1);

    TokenIdxSet result;

    TokensTree *tree = ParserTest::Get()->GetTokensTree();

    nativeParserTest.TestExpression(exp,
                                    tree,
                                    searchScope,
                                    result );

    wxLogMessage(_T("Result have %d matches"), result.size());


    for (TokenIdxSet::iterator it=result.begin(); it!=result.end(); ++it)
    {
        Token* token = tree->at(*it);
        if (token)
        {
            wxString log;
            log << token->GetTokenKindString() << _T(" ")
                << token->DisplayName()        << _T("\t[")
                << token->m_Line               << _T(",")
                << token->m_ImplLine           << _T("]");
            CCLogger::Get()->Log(log);
        }
    }

--- End code ---

And here is the class declaration and implementation:

--- Code: ---#ifndef NATIVEPARSERTEST_H
#define NATIVEPARSERTEST_H

#include "nativeparser_base.h"

class NativeParserTest : public NativeParserBase
{
public:
    NativeParserTest();
    ~NativeParserTest();
    bool TestExpression(wxString& expression,
                        TokensTree * tree,
                        const TokenIdxSet& searchScope,
                        TokenIdxSet&   result);
};

#endif //NATIVEPARSERTEST_H

--- End code ---



--- Code: ---#include <sdk.h>

#ifndef CB_PRECOMP
#endif

#include "nativeparsertest.h"

#include "parser/cclogger.h"



#define CC_NATIVEPARSERTEST_DEBUG_OUTPUT 0

#if CC_GLOBAL_DEBUG_OUTPUT == 1
    #undef CC_NATIVEPARSERTEST_DEBUG_OUTPUT
    #define CC_NATIVEPARSERTEST_DEBUG_OUTPUT 1
#elif CC_GLOBAL_DEBUG_OUTPUT == 2
    #undef CC_NATIVEPARSERTEST_DEBUG_OUTPUT
    #define CC_NATIVEPARSERTEST_DEBUG_OUTPUT 2
#endif

#ifdef CC_PARSER_TEST
//    #define ADDTOKEN(format, args...) \
//            CCLogger::Get()->AddToken(F(format, ##args))
//    #define TRACE(format, args...) \
//            CCLogger::Get()->DebugLog(F(format, ##args))
//    #define TRACE2(format, args...) \
//            CCLogger::Get()->DebugLog(F(format, ##args))

    #define ADDTOKEN(format, args...) \
            wxLogMessage(F(format, ##args))
    #define TRACE(format, args...) \
            wxLogMessage(F(format, ##args))
    #define TRACE2(format, args...) \
            wxLogMessage(F(format, ##args))
#else
    #if CC_NATIVEPARSERTEST_DEBUG_OUTPUT == 1
        #define ADDTOKEN(format, args...) \
                CCLogger::Get()->AddToken(F(format, ##args))
        #define TRACE(format, args...) \
            CCLogger::Get()->DebugLog(F(format, ##args))
        #define TRACE2(format, args...)
    #elif CC_NATIVEPARSERTEST_DEBUG_OUTPUT == 2
        #define ADDTOKEN(format, args...) \
                CCLogger::Get()->AddToken(F(format, ##args))
        #define TRACE(format, args...)                                              \
            do                                                                      \
            {                                                                       \
                if (g_EnableDebugTrace)                                             \
                    CCLogger::Get()->DebugLog(F(format, ##args));                   \
            }                                                                       \
            while (false)
        #define TRACE2(format, args...) \
            CCLogger::Get()->DebugLog(F(format, ##args))
    #else
        #define ADDTOKEN(format, args...)
        #define TRACE(format, args...)
        #define TRACE2(format, args...)
    #endif
#endif


extern bool s_DebugSmartSense;

NativeParserTest::NativeParserTest( )
{

}
NativeParserTest::~NativeParserTest()
{

}
bool NativeParserTest::TestExpression(wxString& expression,
                                      TokensTree * tree,
                                      const TokenIdxSet& searchScope,
                                      TokenIdxSet&   result)
{
    // find all other matches
    std::queue<ParserComponent> components;
    BreakUpComponents(expression, components);

    ResolveExpression(tree, components, searchScope, result, true, false);

    if (s_DebugSmartSense)
        CCLogger::Get()->DebugLog(F(_T("NativeParserTest::TestExpression , returned %d results"),result.size()));

    return true;
}

--- End code ---

The test code is in my previous post, and I can see the final result:

--- Quote ---...
000033. NativeParserTest::TestExpression , returned 1 results
000034. variable int A::m_Member1   [5,0]
...

--- End quote ---
:) :) :)

EDIT:
I add the diff file, so it is test only patch.(Note, the diff file contains my other part of changes to CC, like adding some comments, re-direct the TRACE message to standard console, so I can still see these messages when the app hit a breakpoint.....)
The patch is generated by git, but I think using the patch command under msys, it can directly apply the change on a SVN trunk.
BTW: Maybe, some EOL should be changed after patching, because my git use Linux-style EOL.

MortenMacFly:

--- Quote from: ollydbg on July 07, 2012, 03:37:02 am ---The ResolveExpression is in Nativeparser_base now. So, I think we can safely add the nativeparser_base to our parsertest project.
[...]
I see that the class Nativeparser_base is quite nice for testing. It does not contains UI related code.

--- End quote ---
That was the overall goal of this re-factoring. ;-)


--- Quote from: ollydbg on July 07, 2012, 04:33:00 am ---Ok, it works nice.
[...]
I add the diff file, so it is test only patch.

--- End quote ---
Good to know - I didn't have the time to test, but I believe there is even more we can transfer to the test project, if we include a cbStyledTextCtrl into it.

MortenMacFly:

--- Quote from: ollydbg on July 07, 2012, 04:33:00 am ---The patch is generated by git, but I think using the patch command under msys, it can directly apply the change on a SVN trunk.

--- End quote ---
Nope, doesn't work here. So I cannot try. Maybe you can do a proper svn diff-based patch. Its easy: just transfer the changes to the svn controlled folder and do a svn diff > patch in the root folder of Code::Blocks's sources.

Jenna:
I also use git for my local repo and creating svn compatible  patches needs just one more step: see http://abombss.com/blog/2007/12/10/creating-patches-for-subversion-from-git/, or use the attached python script (if it works on windows).
It's not created by me, I found it somewhere in the internet (do not recall where).

Navigation

[0] Message Index

[#] Next page

Go to full version