Menu

#724 Code completion parser not handling one weird extern construction

Undefined
fixed
ollydbg
Undefined
2018-10-03
2018-08-16
TSM
No

Here is a piece of code from one of ImageMagick headers.

extern WandExport void
    ClearMagickWand(MagickWand *),
    MagickWandGenesis(void),
    MagickWandTerminus(void),
    *MagickRelinquishMemory(void *),
...

In this case, MagickWandGenesis is recognized not as a function, but as a return type for MagickWandTerminus. This is clearly wrong.

Discussion

  • ollydbg

    ollydbg - 2018-08-16
    • labels: --> CodeCompletion
     
  • ollydbg

    ollydbg - 2018-08-16

    What does "WandExport" means? a type?

     
    • TSM

      TSM - 2018-08-16

      No, that's probably function attribute. On windows it discloses for compiling DLLs properly.

       
  • ollydbg

    ollydbg - 2018-08-16

    So, do you mean like this:

    extern __declspec(dllexport) void f1(int*), f2(), f3(float);
    
     
    • TSM

      TSM - 2018-08-16

      yep, something like that
      just skip attributes i.e. every token between extern and something that has semicolon or comma after it and process every next token as function name until semicolon

       
    • Gokul Krishnan

      Gokul Krishnan - 2018-09-25

      We need to handle comma as a terminator for function declarations (in HandleFunction()). It's not enough to support this case, but it's a start. Here's a preliminary patch.

       
      • ollydbg

        ollydbg - 2018-09-25

        Hello, Huki, long time no see.
        Thanks for the patch, I will see I can take some time to test your patch this week.

        I'm always thinking how to improve our CodeCompletion's Parser and Tokenizer. This is not a simple task.

         
        • Gokul Krishnan

          Gokul Krishnan - 2018-09-25

          Yep, good to be back. :)

          Good news is I was able to finish rest of the changes needed to support function declaration lists. See the cc_fixes branch in my repo:
          https://github.com/gk7huki/codeblocks_sf/commits/cc_fixes

          The following patterns should now be supported:
          
          
          * function declarations list
            void f1(int*), *f2(), f3(float);
            -> void f1(int*);
            -> void *f2();
            -> void f3(float);
          
          
          * function ptr declarations list
            void (*f1)(int*), *(*f2)() = XXX, (*f3)(float) = YYY;
          
          
          * obj list with constructor
            MyClass obj1(), obj2(), obj3();
          

          I also added some tests.

           
  • ollydbg

    ollydbg - 2018-09-25
    • assigned_to: ollydbg
     
  • ollydbg

    ollydbg - 2018-09-26
     
  • ollydbg

    ollydbg - 2018-09-26

    Hi, huki, thanks for the patches and the test files.

    I just did a simple test (running the CCTest project on the file new cc test file), and the result is good! 100% PASS.

    See below:

    ********************************************************
      Testing in file: D:\code\cb\cb_sf_git\clean-trunk-for-commit\src\plugins\codecompletion\testing\cc_function_decl_list.cpp
    ********************************************************
    
    + PASS: obj3.  m_a
    + PASS: obj2.  m_a
    + PASS: obj1.  m_a
    + PASS: fp  fp1
    + PASS: fp  fp2
    + PASS: fp  fp3
    + PASS: Func  Func1
    + PASS: Func  Func2
    + PASS: f3  f3
    + PASS: f2  f2
    + PASS: f1  f1
    --------------------------------------------------------
    Total 11 tests, 11 PASS, 0 FAIL
    --------------------------------------------------------
    

    About the test file, here is the modified cc test file:

    // Sourceforge ticket #724
    // https://sourceforge.net/p/codeblocks/tickets/724/
    
    extern __declspec(dllexport) void f1(int*), *f2(), f3(float);
    
    extern unsigned int Func1(int*), *Func2(char);
    
    unsigned int  (*fp1)(int*) = Func1,
                 *(*fp2)(char) = Func2,
                  (*fp3)();
    
    class MyClass
    {
        int m_a;
    
        // ctor
        MyClass(int a) : m_a(a) {}
    };
    
    MyClass obj1(2), obj2(20), obj3(7);
    
    
    
    
    //f1      //f1
    //f2      //f2
    //f3      //f3
    //Func    //Func1,Func2
    //fp      //fp1,fp2,fp3
    //obj1.   //m_a
    //obj2.   //m_a
    //obj3.   //m_a
    

    The cc test file has some special "rules" which is desinged by me several years ago. The test line should only be put in the last lines of the source file.

    For a test case:

    //Func    //Func1,Func2
    

    This means when user type "Func", and request for a code suggestion, the suggesting list should contains the "Func1" and "Func2".

    I will review the detailed changes as soon as I can.

     
  • ollydbg

    ollydbg - 2018-10-03
    • status: open --> fixed
     

Log in to post a comment.

MongoDB Logo MongoDB