Community
    • Login

    Function list for C++ do not show constructors

    Scheduled Pinned Locked Moved General Discussion
    function list
    14 Posts 4 Posters 3.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Lycan ThropeL
      Lycan Thrope @PeterJones
      last edited by

      @PeterJones ,
      In light of your points, that even without a return type, it should be recognized as a function, then I guess it is an issue for the C++ functionList file.

      As far as the C functionList regex recognizing it, that would seem normal wouldn’t it, since it ONLY recognizes functions instead of classes? And it is in the correct format for a function so… :-)

      Anyway, maybe one day I’ll really try and wade into that mess…but not today. :-)

      1 Reply Last reply Reply Quote 0
      • Mario KorvaM
        Mario Korva
        last edited by

        Thanks for the answer, I thought nobody cares! And destructors are also missing. And that is serious flaw of the function list functionality for c++. Normally class has more constructors, each with different arguments and all these are missing. The regex for implementing the function list is too complicated for easy customization and I see that this is not only my opinion :)

        Lycan ThropeL rdipardoR 2 Replies Last reply Reply Quote 2
        • Lycan ThropeL
          Lycan Thrope @Mario Korva
          last edited by Lycan Thrope

          @Mario-Korva ,
          That’s probably why I never really got into learning C++. I already knew some C, which I was using to segue into GOC (Geoworks Object C) which was OOP, and I also use dBASE Plus, which is OOP, and C++ just always seemed to be too complicated to me since it’s description of C with Objects seemed like a patchwork fix of sorts. It needs to be simpler, but alas, that is only my opinion, but explains why I never really sought to do more with it, too many rules and variations. :(

          rdipardoR 1 Reply Last reply Reply Quote 0
          • rdipardoR
            rdipardo @Lycan Thrope
            last edited by

            C++ just always seemed to be too complicated to me since it’s description of C with Objects seemed like a patchwork fix of sorts.

            Have you seen what they’ve done with it since 2011?

            It’s true the Win32 API was released when C++ was just ANSI C with some features added, but that was 35 years ago.

            Lycan ThropeL 1 Reply Last reply Reply Quote 0
            • rdipardoR
              rdipardo @Mario Korva
              last edited by rdipardo

              @Mario-Korva, if you want to read an expert’s opinion on how difficult it is to intelligently parse C++ source files, I highly recommend this GitHub discussion: On limitations of Geany for C++

              1 Reply Last reply Reply Quote 3
              • Lycan ThropeL
                Lycan Thrope @rdipardo
                last edited by

                @rdipardo said in Function list for C++ do not show constructors:

                Have you seen what they’ve done with it since 2011?

                To be fair, when I was working to learn C and was taking a crack at C++ in the same stroke, the timeline was 1991, under DOS, about the same time as I was simultaneously trying to learn Assembly, so that might have something to do with it. :-) So your time estimate is about right, it’s been 32 years since I seriously considered learning C++. Feeling old at the moment…give me a sec. ;-)

                rdipardoR 1 Reply Last reply Reply Quote 4
                • rdipardoR
                  rdipardo @Lycan Thrope
                  last edited by

                  Feeling old at the moment…

                  It happens, but the point I was making with the linked GH discussion is that a sprawling regular expression pasted into an XML descriptor should not be considered a function “parser”. It’s just another one of N++'s many technical debts, inherited back when XML was the JSON of Web 1.0.

                  If contemporary C++ is too complex for UCtags (which is a genuine parser), then that’s the end of the matter. Either Geany and N++ get first-class LSP support, or C++ devs with real work to do should look elsewhere.

                  Lycan ThropeL 1 Reply Last reply Reply Quote 4
                  • Lycan ThropeL
                    Lycan Thrope @rdipardo
                    last edited by

                    @rdipardo said in Function list for C++ do not show constructors:

                    If contemporary C++ is too complex for UCtags (which is a genuine parser), then that’s the end of the matter. Either Geany and N++ get first-class LSP support, or C++ devs with real work to do should look elsewhere.

                    Which is why, with few exceptions, someone usually uses the tool from the tool supplier as the best weapon of choice when it comes to the IDE/development of code…and why NPP is better suited for UDL’s of low complexity for customization and general use.

                    I personally have an animus toward LSP’s unless they are going to be freely available and freely usable locally, i.e. download and use the server aspect locally on the computer when not in a network scenario. I get the idea of not wanting to reinvent the wheel, but at the cost of independence and autonomy, too much centralization is not necessarily a good thing IMHO. :-)

                    1 Reply Last reply Reply Quote 3
                    • Mario KorvaM
                      Mario Korva @PeterJones
                      last edited by Mario Korva

                      @PeterJones and others
                      Constructors and destructors do not have return type. Researching Regex sequences of the Function List parser with RegEx101 tool shows that the parser expects functions to have return type. Functions without return type do not appear in the Function List. I changed Regex making return type optional. Change makes constructors without initializer to appear in the Function List but destructors are still missing. The reason is the name of the destructor which starts with tilde ‘~’ which is not the word character. Regex expects function names to be words. Changing the Regex seguence “\w+” to “~?\w+” enables function names to start with tilde. Now destructors are shown also. Constructors with initializer are still missing though. They contain additional code inside initializer between ‘:’ and ‘{’ and the Regex inside mainExpr marks “functions” found inside initalizer too. That confuses the parser and Function List is not built. Regex should skip the code inside the initializer, but I don’t know how to achieve this without regular expression replacement or modification which is not supported inside the parser.
                      I found that changes in overrideMap.xml are ignored, only changes in cpp.xml are being accepted.

                      Example:

                      // ExampleClass.h
                      class ExampleClass
                      {
                        private:
                          int i;
                          int j;
                        public:
                          ExampleClass(int x, int y=0); // ctor1
                          ExampleClass();     // ctor2
                          ~ExampleClass();    // dtor
                          void Method1();
                          int Method2() { return i+j; }
                      };
                      
                      // ExampleClass.cpp
                      #include "ExampleClass.h"
                      
                      // constructor with initializer (ctor1)
                      ExampleClass::ExampleClass(int x, int y) : i(x), j(y)
                      {
                          allocate();
                      }
                      
                      // constructor without initializer (ctor2)
                      ExampleClass::ExampleClass()
                      {
                          i = 0;
                          j = 0;
                          allocate();
                      }
                      
                      // destructor (dtor)
                      ExampleClass::~ExampleClass()
                      {
                          deallocate();
                      }
                      
                      // function not belonging to the class
                      void HelperFunction()
                      {
                          return;
                      }
                      
                      // class method
                      void ExampleClass::Method1()
                      {
                          return;
                      }
                      
                      

                      Function list with modified cpp.xml:
                      ba3429fb-67ec-43cf-80e8-e5701df3f950-image.png

                      I put modified cpp.xml on temporary test location for those who want to test it.

                      I tested modified cpp.xml on my sources and it works for me.

                      Mario KorvaM 1 Reply Last reply Reply Quote 1
                      • Mario KorvaM
                        Mario Korva @Mario Korva
                        last edited by

                        @Mario-Korva

                        Finally I found some time to try to fix C++ Function List parser regex (cpp.xml) to show all constructors.
                        Modification of the mainExpr in the <classRange> element of <parser>:

                        Original expression:

                        mainExpr="(?x)          # use inline comments
                               ...
                               )?
                           	\s*             # trailing whitespace
                           	\{              # class/struct body
                           	"
                        

                        Modified expression:

                        mainExpr="(?x)      # use inline comments
                                ...
                        	    )?
                        		\s*(:[^:]*)?    #<- trailing whitespace and initializers
                        		\{              # class/struct body
                        		"
                        

                        I did equivalent modification of the mainExpr in the <function> element of <parser>. This modification enable that function list shows constructors with initializers.
                        I found also that functions defined with the call convention keyword, for example:

                        void __fastcall function(parameter) { ...
                        

                        are also missing in the function list. This is solved with the addition of the

                        (__[\d\l]+\s+)? #<- call convention __fastcall, __stdcall, etc.
                        

                        immediately after second “# type pointer/reference” part of mainExpr in the same two elements.

                        After this modificatoins the Function List of my C++ source files appears complete! I hope that I didn’t break something.
                        I tried to include modified cpp.xml here, but the post becomes too long.
                        I hope this will be useful for someone.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors