kunaltyagi / nsiqcppstyle

Cpp style checker in python
GNU General Public License v2.0
25 stars 24 forks source link

Add a tool to show which callback functions are invoked for given source code #41

Closed mosherubin closed 2 years ago

mosherubin commented 2 years ago

This pull request is the implementation of issue 34 ("Provide a tool to show which callback functions are invoked for given source code"). The current development branch, "issue_34", is branched off of the "feature_2022_06_24_add_new_rule_callbacks" branch. This is because I didn't want to wait until "feature2022..." was merged - I wanted to move forward.

Here are the relevant changes:

Closes #34


This section will track what the TOOL's updated output looks like.

Input C++ source code

// Your First C++ Program

#include <iostream>

class foo
{
    static void bar();
};

int main() {
    std::cout << "Hello World!";
    return 0;
}

void foo::bar()
{
}

TOOL output

D:\nsiqcppstyle>trace-callbacks.bat "D:\Junk\NsiqCppStyle\issue_34\hello-world.cpp"
nsiqcppstyle: N'SIQ Cpp Style ver 0.3.0.1

======================================================================================
=  Analyzing hello-world.cpp
======================================================================================
  -  TOOL_trace_nsiqcppstyle_callbacks is applied.
======================================================================================
Legend: LexToken contain six fields: (type, value, lineno, column, lexpos, inactive, pp)

SessionStart  ()
Filter Scope "default" is applied.
Current Filter Setting (Following is applied sequentially)
  1. \.cvs\ is excluded
  2. \.svn\ is excluded

Current File extension and Language Settings
  C/C++=h,cxx,c,hxx,hh,m,mm,hpp,cc,cpp

======================================================================================
Processing:  D:\Junk\NsiqCppStyle\issue_34\hello-world.cpp
FileStart     (lexer, filename='hello-world.cpp', dirname='D:\Junk\NsiqCppStyle\issue_34')
--------------------------------------------------
Line          (lexer, line='// Your First C++ Program', lineNumber=1)
Comment       (lexer, token=LexToken(CPPCOMMENT,'// Your First C++ Program',1,1,0, False, None))
--------------------------------------------------
Line          (lexer, line='#include <iostream>', lineNumber=3)
Preprocess    (lexer,
               contextStack (empty),
               token=LexToken(PREPROCESSOR,'#include',3,1,27, False, True))
Preprocess    (lexer,
               contextStack (empty),
               token=LexToken(LT,'<',3,10,36, False, True))
Preprocess    (lexer,
               contextStack (empty),
               token=LexToken(ID,'iostream',3,11,37, False, True))
Preprocess    (lexer,
               contextStack (empty),
               token=LexToken(GT,'>',3,19,45, False, True))
--------------------------------------------------
Line          (lexer, line='class foo', lineNumber=5)
TypeName      (lexer,
               typeName='CLASS',
               typeFullName='foo',
               decl='False'
               contextStack (empty),
               typeContext='CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)')
Token         (lexer,
               contextStack (empty),
               token=LexToken(TYPE,'class',5,1,48, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(ID,'foo',5,7,54, False, None))
--------------------------------------------------
Line          (lexer, line='{', lineNumber=6)
TypeScope     (lexer,
               contextStack (1))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(LBRACE,'{',6,1,58, False, None))
--------------------------------------------------
Line          (lexer, line='    static void bar();', lineNumber=7)
TypeScope     (lexer,
               contextStack (1))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(STATIC,'static',7,2,61, False, None))
TypeScope     (lexer,
               contextStack (1))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(VOID,'void',7,9,68, False, None))
FunctionName  (lexer,
               fullName='bar',
               decl='True',
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
                   context='None')
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(FUNCTION,'bar',7,14,73, False, None))
TypeScope     (lexer,
               contextStack (2))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
                   PARENBLOCK, '', 76, 77
Token         (lexer,
               contextStack (2),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
                   PARENBLOCK, '', 76, 77
               token=LexToken(LPAREN,'(',7,17,76, False, None))
TypeScope     (lexer,
               contextStack (1))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(RPAREN,')',7,18,77, False, None))
TypeScope     (lexer,
               contextStack (1))
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
Token         (lexer,
               contextStack (1),
                   CLASS_BLOCK, 'foo', LexToken(LBRACE,'{',6,1,58, False, None), LexToken(RBRACE,'}',8,1,80, False, None)
               token=LexToken(SEMI,';',7,19,78, False, None))
--------------------------------------------------
Line          (lexer, line='};', lineNumber=8)
Token         (lexer,
               contextStack (empty),
               token=LexToken(RBRACE,'}',8,1,80, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(SEMI,';',8,2,81, False, None))
--------------------------------------------------
Line          (lexer, line='int main() {', lineNumber=10)
Token         (lexer,
               contextStack (empty),
               token=LexToken(INT,'int',10,1,84, False, None))
FunctionName  (lexer,
               fullName='main',
               decl='False',
               contextStack (empty),
                   context='FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)')
Token         (lexer,
               contextStack (empty),
               token=LexToken(FUNCTION,'main',10,5,88, False, None))
Token         (lexer,
               contextStack (1),
                   PARENBLOCK, '', 92, 93
               token=LexToken(LPAREN,'(',10,9,92, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(RPAREN,')',10,10,93, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(LBRACE,'{',10,12,95, False, None))
--------------------------------------------------
Line          (lexer, line='    std::cout << "Hello World!";', lineNumber=11)
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(ID,'std',11,5,101, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(DOUBLECOLON,'::',11,8,104, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(ID,'cout',11,10,106, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(LSHIFT,'<<',11,15,111, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(STRING,'"Hello World!"',11,18,114, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(SEMI,';',11,32,128, False, None))
--------------------------------------------------
Line          (lexer, line='    return 0;', lineNumber=12)
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(RETURN,'return',12,5,134, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(NUMBER,'0',12,12,141, False, None))
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'main', LexToken(LBRACE,'{',10,12,95, False, None), LexToken(RBRACE,'}',13,1,144, False, None)
               token=LexToken(SEMI,';',12,13,142, False, None))
--------------------------------------------------
Line          (lexer, line='}', lineNumber=13)
Token         (lexer,
               contextStack (empty),
               token=LexToken(RBRACE,'}',13,1,144, False, None))
--------------------------------------------------
Line          (lexer, line='void foo::bar()', lineNumber=15)
Token         (lexer,
               contextStack (empty),
               token=LexToken(VOID,'void',15,1,147, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(ID,'foo',15,6,152, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(DOUBLECOLON,'::',15,9,155, False, None))
FunctionName  (lexer,
               fullName='foo::bar',
               decl='False',
               contextStack (empty),
                   context='FUNCTION_BLOCK, 'foo::bar', LexToken(LBRACE,'{',16,1,163, False, None), LexToken(RBRACE,'}',17,1,165, False, None)')
Token         (lexer,
               contextStack (empty),
               token=LexToken(FUNCTION,'bar',15,11,157, False, None))
Token         (lexer,
               contextStack (1),
                   PARENBLOCK, '', 160, 161
               token=LexToken(LPAREN,'(',15,14,160, False, None))
Token         (lexer,
               contextStack (empty),
               token=LexToken(RPAREN,')',15,15,161, False, None))
--------------------------------------------------
Line          (lexer, line='{', lineNumber=16)
FunctionScope (lexer,
               contextStack (1))
                   FUNCTION_BLOCK, 'foo::bar', LexToken(LBRACE,'{',16,1,163, False, None), LexToken(RBRACE,'}',17,1,165, False, None)
Token         (lexer,
               contextStack (1),
                   FUNCTION_BLOCK, 'foo::bar', LexToken(LBRACE,'{',16,1,163, False, None), LexToken(RBRACE,'}',17,1,165, False, None)
               token=LexToken(LBRACE,'{',16,1,163, False, None))
--------------------------------------------------
Line          (lexer, line='}', lineNumber=17)
Token         (lexer,
               contextStack (empty),
               token=LexToken(RBRACE,'}',17,1,165, False, None))
FileEnd       (lexer, filename='hello-world.cpp', dirname='D:\Junk\NsiqCppStyle\issue_34')
Project       (targetName='D:\Junk\NsiqCppStyle\issue_34\hello-world.cpp')

=================================== Summary Report ===================================
 ** Total Available Rules     : 48
 ** Total Applied Rules       : 1
 ** Total Violated Rules      : 0
 ** Total Errors Occurs       : 0
 ** Total Analyzed Files      : 1
 ** Total Violated Files Count: 0
 ** Build Quality             : 100.00%

================================ Violated Rule Details ===============================

================================ Violated File Details ===============================
SessionEnd    ()

D:\nsiqcppstyle>
mosherubin commented 2 years ago

Linux script trace-callbacks.sh written and pushed.

kunaltyagi commented 2 years ago

Needs a history cleanup

mosherubin commented 2 years ago

I resolved the conflict in nsiqcppstyle_checker.py (line 894), you should be able to resolve it on your side.

Your comment "Needs a history cleanup" is, unfortunately, too brief and doesn't help me. I had a problem last time, and do not know how to do it this time either. The reason for the history issue now is because it took so long to get feedback on PR #35 that I had to create branch issue_34 by branching off of PR #35. I'd appreciate if you could do the cleanup on your side, or walk me through the exact steps needed on my side (I prefer the former to save time). :-)

mosherubin commented 2 years ago

I was able to resolve the conflict, and am awaiting your merge into master.

mosherubin commented 2 years ago

Regarding your comment above:

I think the output of the current TOOL isn't same as https://github.com/kunaltyagi/nsiqcppstyle/issues/34. Please add a sample output in the PR description (1st comment of the PR), and we'll keep it updated as the PR progresses.

Done.

kunaltyagi commented 2 years ago

2 minor items :) 🚀 soon