Pebaz / RGB

Does 95% of the Work Required to Port C Libraries to Red/System by Converting C Header Files to Red/System Code.
MIT License
14 stars 1 forks source link

Proposal To Create Clean Output Headers #5

Closed Pebaz closed 5 years ago

Pebaz commented 5 years ago

The extremely verbose output from the preprocessor will contain any code from the headers included in the C source file. Fortunately, the preprocessor also says when it switches files:

# 1 "c:/tcc/include/string.h" 1              // Remove Everything between this line:
# 10 "c:/tcc/include/sec_api/string_s.h" 2   // <- This is where it switches to the other file
  extern wchar_t * wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context);
  extern errno_t  _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum);
  etc....
# 12 "./type_class.c" 2                         // And this line:
typedef void* var;
typedef char byte;
# 27 "./type_class.c"

So it should be pretty simple to just parse for the lines that contain the current actual file: ./type_class.c, and remove all lines between them.

Summary

Code outputted from the RGB transpiler will be cleaner and free from extraneous code that comes from including headers in code, resulting in a much more streamlined workflow because the extra code won't have to be deleted by the library porter.