resinator icon indicating copy to clipboard operation
resinator copied to clipboard

Custom preprocessor

Open squeek502 opened this issue 2 years ago • 7 comments

This would be a solution for the "Unavoidable divergences from the Windows RC compiler" which are all preprocessor related.

Most notably, it would be necessary for UTF-16 support.

This would likely be a large undertaking. A starting point might be to fork arocc.


EDIT: Experimenting with this here: https://github.com/squeek502/preresinator

squeek502 avatar Sep 20 '23 05:09 squeek502

Some notes on potential UTF-16 handling I had locally that are relevant:

  • Convert UTF-16 files to UTF-8
  • Surround converted files with
    #pragma code_page(65001)
    // file contents
    #pragma code_page(DEFAULT)
    

Need to ensure that the generated #pragma code_page lines aren't ignored due to them being part of an included file

  • Could do something like using #line 1 "<built-in>" and then documenting that such lines should not be ignored even if they are 'within' an included file
  • Can't really do something like putting the generated #pragma code_page's in the 'root' file since that wouldn't handle the case of an included file including a UTF-16 file
  • Could do something like (where root-file.rc is the root file and file.rc is any arbitrary included file)
    #line 1 "root-file.rc" // note that the 1 here is a totally fake line number since the following line is not part of the original file at all
    #pragma code_page(65001)
    #line 1 "file.rc"
    // file.rc contents
    

Also need to keep https://squeek502.github.io/resinator/windows/input-and-output-code-pages.html in mind. What rc.exe does is encode the output of the preprocessor as UTF-16, having already handled all the #pragma code_pages and done things like replaced invalid codepoints with <U+FFFD>, etc. This type of approach may end up being necessary to reach full compatibility without resinator specific behavior in the preprocessed output.

squeek502 avatar Oct 21 '23 03:10 squeek502