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

ctags breaks on template instantiations that bitshift in parameters #120

Closed
focalintent opened this issue Feb 24, 2016 · 7 comments
Closed
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@focalintent
Copy link
Contributor

FastLED makes pretty extensive use of templates to do a lot of this work. Some of what's done with templates involves creating bitmasks from template parameters as parameters to other templates. Unfortunately, when the ctags parser sees "1<<X" as a template parameter, it eats itself.

This code demonstrates the problem:

template <int PORT_MASK> class controller { 

};

template <int LANES> class myClass { 
  public:
    void useController(controller<(1<<LANES)-1> & controller);    
};

void setup() { myctagstestfunc(); }
void myctagstestfunc() { }
void loop() {}

Because ctags stops parsing, the prototype for myctagstestfunc() is never created, and the dreaded 'myctagstestfun' was not declared in this scope error (as seen in #68)

@masatake
Copy link

[yamato@x201]~/var/ctags-github% ./ctags --sort=no -o - foo.cpp
controller  foo.cpp /^template <int PORT_MASK> class controller { $/;"  c   file:
myClass foo.cpp /^template <int LANES> class myClass { $/;" c   file:
setup   foo.cpp /^void setup() { myctagstestfunc(); }$/;"   f
myctagstestfunc foo.cpp /^void myctagstestfunc() { }$/;"    f
loop    foo.cpp /^void loop() {}$/;"    f

This is the expected tags output of this issue?

@focalintent
Copy link
Contributor Author

Pretty much, yes.

@masatake
Copy link

The following commit may fix it.
masatake/ctags@9a7ce23

@focalintent
Copy link
Contributor Author

Unfortunately - that commit will most likely fail in the case of:

template <int PORT_MASK> class controller { 
};

controller< 1<<8 > aController;

because the code in the commit that you linked to only ignores the <> characters after an = or when inside of ()'s.

So even with your commit - you should still do the one character lookahead to decide whether or not you've got a bit shift happening. Of course, then there's also having conditional expressions as template parameters which would likely trip up both of our fixes.

@focalintent
Copy link
Contributor Author

Yup - just tried here with

template <int P> class c {};
c< 8 > bVar;
c< 1<<8 > aVar;

and I get:

Xantico:u-ctags dgarcia$ ./ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/x.cpp
ctags: Warning: Unsupported parameter 'T' for "fields" option
bVar    /tmp/x.cpp  /^c< 8 > bVar;$/;"  kind:variable   line:2

aVar does'n't come out - if I add the lookahead/skip in c.c (similar to what's in my pull request in arduino/ctags#7) then I get this output:

template <int P> class c {};
c< 8 > bVar;
c< 1<<8 > aVar;

@focalintent
Copy link
Contributor Author

universal-ctags/ctags#807 for a fix on universal-ctags

@facchinm
Copy link
Member

facchinm commented Mar 4, 2016

Fixed by merging arduino/ctags#7

@facchinm facchinm closed this as completed Mar 4, 2016
@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants