Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Variables and prototypes #742

Merged
merged 3 commits into from
Jan 4, 2016
Merged

C++: Variables and prototypes #742

merged 3 commits into from
Jan 4, 2016

Conversation

pragmaware
Copy link
Contributor

Local function prototypes are unlikely and the current code generates many false tags (things that aren't actually prototypes). Silence them. Try to catch variable instantiations in the form 'Type var(params)' instead, which are far more common.

…rates many false tags (things that aren't actually prototypes). Silence them. Try to catch variable instantiations in the form 'Type var(params)' instead, which are far more common.
@masatake
Copy link
Member

Could you rename variables-prototypes-2.cpp.b directory to variables-prototypes-2.cpp.d?
.b is for recording known bugs. Your commit fixes the bug.

https://travis-ci.org/universal-ctags/ctags/jobs/98898723

FIXED:                                 1

    parser-cpp.r/variables-prototypes-2.cpp

@pragmaware
Copy link
Contributor Author

Done.

@masatake
Copy link
Member

After introducing your commit, the result of Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp is
changed. I have to think about this more.

% diff -ruN <(./3d596a4-ctags --c++-kinds=+pl --fields=+S -o - Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp ) <(./deea228-ctags --c++-kinds=+pl --fields=+S -o - Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp )
<s=+S -o - Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp )
--- /proc/self/fd/11    2015-12-31 09:49:22.339998919 +0900
+++ /proc/self/fd/12    2015-12-31 09:49:22.340998890 +0900
@@ -30,33 +30,8 @@
 X9 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^int X9( a && b );                       \/\/variable$/;"  p   file:   signature:( a && b )
 a1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int  a1 = i < 7 ? i : 7;$/;"  l
 a5 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int  a5 = 8;$/;"  l
-a7 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int  a7( short ( *p )( int ) );$/;"   p   file:   signature:( short ( *p )( int ) )
 a8 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    short a8 = i;$/;" l
-b2 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int b2( int ooo, const char* o );       \/\/prototype$/;" p   file:   signature:( int ooo, const char* o )
-b3 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int b3( int( 7 ) );                     \/\/variable$/;"  p   file:   signature:( int( 7 ) )
-c2 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c2( int * h );                      \/\/prototype$/;" p   file:   signature:( int * h )
-c4 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c4( std::map<int> a );              \/\/prototype$/;" p   file:   signature:( std::map<int> a )
-c5 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c5( map<int>  & a );                \/\/prototype$/;" p   file:   signature:( map<int> & a )
-c6 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c6( ooo & a );                      \/\/prototype$/;" p   file:   signature:( ooo & a )
-c7 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c7( int & a );                      \/\/prototype$/;" p   file:   signature:( int & a )
-c8 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c8( map<int> a );                   \/\/prototype$/;" p   file:   signature:( map<int> a )
-c9 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int c9( int a );                        \/\/prototype$/;" p   file:   signature:( int a )
-f1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int f1( SomeType (*p)( int ) );         \/\/prototype$/;" p   file:   signature:( SomeType (p) int ) )
-f3 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int f3( std::map<int> & a );            \/\/prototype$/;" p   file:   signature:( std::map<int> & a )
-g1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int g1( SomeType a );                   \/\/prototype$/;" p   file:   signature:( SomeType a )
-h1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    char h1( const char *a = "a" );         \/\/prototype$/;" p   file:   signature:( const char *a = R )
-h2 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int h2();                               \/\/prototype$/;" p   file:   signature:()
-h3 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    char h3( double );                      \/\/prototype$/;" p   file:   signature:( double )
-h4 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int h4( h u );                          \/\/prototype$/;" p   file:   signature:( h u )
-iii    Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int v5( iii( o ) );                     \/\/variable$/;"  p   file:   signature:(o )
 iii    Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^int V5( iii( o ) );                     \/\/variable$/;"  p   file:   signature:(o )
 j  Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^int D3( *j );                           \/\/variable$/;"  v
 main   Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^int  main( int  argc, char ** argv )$/;"  f   signature:( int argc, char ** argv )
-v6 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int v6( int (*p)( int ) );              \/\/prototype$/;" p   file:   signature:( int (*p)( int ) )
-v8 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int v8( ooo );                          \/\/variable$/;"  p   file:   signature:( ooo )
-w1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int w1 __ARGS (( int a ));              \/\/prototype$/;" p   file:   signature:( int a )
-w2 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int w2 (( a - 5 ) \/ 6 );                \/\/variable$/;" p   file:   signature:( a - 5 ) / 6 
-x1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int x1( a.b );                          \/\/variable$/;"  p   file:   signature:( a.b )
-x3 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int x3( NS::a  b );                     \/\/prototype$/;" p   file:   signature:( NS::a b )
-x4 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int x4( a ^ b );                        \/\/variable $/;" p   file:   signature:( a ^ b )
-x9 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int x9( a && b );                       \/\/variable$/;"  p   file:   signature:( a && b )
+w1 Units/parser-cpp.r/variables-prototypes.cpp.b/input.cpp /^    int w1 __ARGS (( int a ));              \/\/prototype$/;" l

@pragmaware
Copy link
Contributor Author

Yes, it has.
All the "nested" function prototypes are gone but we have gained the local variable declarations in the form of Type name(parameters). The rationale is:

  • The current cpp parser is too hard to fix in order to handle both forms. It would require a lot of tweaking and with multiple languages in place it's simply not feasible.
  • Nested function prototypes are very uncommon (almost no program has them)
  • The current parser finds many false nested function prototypes. Almost everything
    in the form Anything(something) is seen as prototype. This is wrong.
  • Local variable declarations in the form of instantiation are extremely common

So the net result is:

  • Removed many false tags
  • Lost some correct but very uncommon tags
  • Gained many correct common tags

In sum: a gain.

masatake added a commit that referenced this pull request Jan 4, 2016
@masatake masatake merged commit ac891bf into universal-ctags:master Jan 4, 2016
@masatake
Copy link
Member

masatake commented Jan 4, 2016

Fair enough. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants