Results 1 to 18 of 18

Thread: custom preprocessor?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default custom preprocessor?

    Is there a nice way to implement my own preprocessor (before standard C++ preprocessing) from within qmake framework.

    I envision something like this in the .pro file:

    Qt Code:
    1. SOURCES += file1.cpp
    2. SPECIAL_SOURCES += file2.cpp
    3. include(process_special_sources.pri)
    To copy to clipboard, switch view to plain text mode 

    Here, process_special_sources.pri would somehow preprocess file2.cpp and create special_file2.cpp and add it to the SOURCES variable.

    Does this sound feasible? Is there a better way?

    Thanks!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: custom preprocessor?

    Depends on what you want it to preprocess.
    Why can't you make use of the compiler preprocessor for replacing macros and other stuff?

  3. #3
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default Re: custom preprocessor?

    Quote Originally Posted by marcel View Post
    Depends on what you want it to preprocess.
    I want to preprocess source code. Input is source code, and output is modified source code.

    Quote Originally Posted by marcel View Post
    Why can't you make use of the compiler preprocessor for replacing macros and other stuff?
    Macros aren't flexible enough to do what I want to do. I want to have an external program do custom preprocessing.

    Any ideas?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: custom preprocessor?

    Then you want to do something similar to what moc does.
    Sounds a lot of work. Maybe you can reuse some pars of moc.

  5. #5
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default Re: custom preprocessor?

    Quote Originally Posted by marcel View Post
    Then you want to do something similar to what moc does.
    Sounds a lot of work. Maybe you can reuse some pars of moc.
    Yes, you are right. I want to do something similar to moc. However, the difference is that moc reads the source files and creates new (additional) source files. Whereas I need to modify the source files in place. Aaccording to wysota, Q_OBJECT, signals, slots, etc. are just macros (although they do give information to moc), so there's really no preprocessing that takes place by moc, in the sense that I want.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: custom preprocessor?

    There is no ready functionality to do what you want. That is why I suggested you should reuse some moc parts, such as the code parsing.

    I am aware that you want top modify the same source file, not generate a new one, but as I said, you have to create a new tool to do that. It is better to reuse moc functionality since it clearly works, and you won't have to write new things and test them.

  7. #7
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default Re: custom preprocessor?

    Okay, thanks marcel. I'll look into that. In the meantime if anyone has experience with setting up this type of thing, please let me know.

  8. #8
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default Re: custom preprocessor?

    For information of those who are curious.

    I got the custom preprocessor to work very nicely using only the following code in .pri file!

    Qt Code:
    1. for(file, CHAINLINK_SOURCES) {
    2. system($$(CHAINLINK_DIR)\bin\cpp_preprocessor $${file} CHAINLINK_$${file})
    3. SOURCES += CHAINLINK_$${file}
    4. }
    To copy to clipboard, switch view to plain text mode 

    Then when preprocessing the file I keep the line numbers updated using the #line macro... so that to the user it's seamless, i.e. when there is an error in the source file, the compiler output points to the original source (not the pre-processed source).

    Really quite a simple system... but it opens huge possibilities (which I need to be careful not to abuse )

    Any comments, suggestions?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: custom preprocessor?

    OK, nice, but you should really have mentioned what exactly you need to preprocess .
    I initially thought you had some code+macro constructs that you needed to be expanded to something by a 3rd party preprocessor.

  10. #10
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    43
    Thanked 21 Times in 21 Posts

    Default Re: custom preprocessor?

    Quote Originally Posted by marcel View Post
    OK, nice, but you should really have mentioned what exactly you need to preprocess .
    I initially thought you had some code+macro constructs that you needed to be expanded to something by a 3rd party preprocessor.
    Yes, sorry about that... I didn't want to confuse the issue before the specific problem was solved. Here's what I can do now (and I'll release this software sometime soon). ~~ very exciting ~~


    Qt Code:
    1. //I include this single header /////////////////////
    2. //and link to chainlink_engine library ///////////
    3. #include "chainlink_engine.h"
    4.  
    5. int main(int argc, char *argv[]) {
    6.  
    7. QString str1=argv[1];
    8.  
    9. CHAINLINK(QString str1) {
    10. %in this block I execute arbitrary chainlink (Matlab) commands!
    11. X=1:1000;
    12. Y=sqrt(1:1000);
    13. H=plot(X,Y);
    14. setWindowTitle(H,str1); %I can even use variables passed in from C++
    15. str1=str1+' hello world'; %and even modify these!
    16. }
    17.  
    18. cout << str1; //and see the result in C++
    19.  
    20. //now we are getting somewhere :)
    21.  
    22. return 0;
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 11 Times in 8 Posts

    Default Re: custom preprocessor?

    Maybe a little cheating - name your application moc.exe, rename original moc as i.e. Qtmoc,
    do your tasks in your moc and call qtmoc from inside...

Similar Threads

  1. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  2. picking geometry in qt custom widgets
    By notsonerdysunny in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2007, 23:01
  3. Replies: 1
    Last Post: 5th March 2007, 20:50
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Replies: 4
    Last Post: 1st March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.