cs-education / sysbuild

A system programming learning environment in the browser
https://cs-education.github.io/sys/
Other
36 stars 35 forks source link

Auto-include any missing header files across a directory #167

Closed aadilzbhatti closed 8 years ago

aadilzbhatti commented 8 years ago

This file and added code will do two things:

  1. On compile, any missing C library call or system call headers will be included
  2. Add a button to the editor component that will automatically include missing headers

This is useful for beginning C programmers who may not know which functions require which headers. The additions will walk down each directory and subdirectory, parse any .h or .c files, and check to see if any C syntax is present without a respective header at which point the header will be appended to the beginning of the file. The headers are parsed from "headers.min.json" and "syscall_metadata.json" from sysassets.

The AutoIncluder object can be found in "auto-include.js" and is invoked in "play-activity-page.js" and "editor.js". In addition, I updated the Editor HTML to allow for space for an AutoIncluder button.

The other addition which I saw necessary was the use of a Knockout observable to represent the Editor and FileSystem components (I added them alongside the already used ones). This is because often the AutoIncluder script would load before the editor and filesystem. Since it uses its own copy of the editor and filesystem, there was a need to subscribe to an updating observable.

If there is anything else you think I should add (tests are in progress) or restructure, please let me know.

neelabhg commented 8 years ago

Is this ready to be merged?

aadilzbhatti commented 8 years ago

Things are looking good on my side. However, there is one small issue: some C syntax is mapping to invalid header files from "syscall_metadata.json". For example, "write" is pulling a file called "asm/dsp56k.h". I went back to syscall_metadata (line 23,832 to be exact if that doesn't load) and found that "write" is mapped to this file, which isn't in the VM.

I think there are probably other syscalls that have mappings like this (such as the ones in the "write" section). Therefore, I think the scraping to generate "syscall_metadata.json" will need to be adjusted in order to get this mapping correct.

For reference, this is where I found "asm/dsp56k.h" in the man pages. My guess is that "write" is having its man(2) data overwritten when the scraper gets to man(7).

neelabhg commented 8 years ago

Got it. Let's merge this in so your code gets into master, then in a separate pull request you can add a flag variable which can disable this feature for users. Then, once we are confident that the functionality is ok for users, we can enable the feature by toggling the flag.

Are you ok with this getting merged in as it is, or is there anything you'd like to add?

aadilzbhatti commented 8 years ago

Yup, we can merge. I have the flag in there as it is. It's in the editor settings dropdown along with auto-indent and things like that.

neelabhg commented 8 years ago

Great.

angrave commented 8 years ago

Good work guys.

For system programming we want to prioritize normal headers (as defined in) man(2) and man(3).

There are some items that won't be in either man section- e.g. pthread items.

Also, feature/extension:

Do we also want to automatically add #define's required for gcc extensions i.e. not-POSIX standart but standard gcc/Linux calls? e.g. dprintf - http://linux.die.net/man/3/dprintf

Best, Lawrence.

On 7/10/16 10:24 PM, Neelabh Gupta wrote:

Merged #167 https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_cs-2Deducation_sysbuild_pull_167&d=CwMCaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=DvT4PEagC1_uJoK7XYcVznCf9vBnV8AqDdM20MaTLvM&m=d3cXtcrTvaVVrEmssfwWNm_8RzR4IRyb8CerqVXIlwk&s=Oau2I3pMMsmqOlp_eVmyxSR5PfxDubzsX_myB-OLPcc&e=.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_cs-2Deducation_sysbuild_pull_167-23event-2D718236419&d=CwMCaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=DvT4PEagC1_uJoK7XYcVznCf9vBnV8AqDdM20MaTLvM&m=d3cXtcrTvaVVrEmssfwWNm_8RzR4IRyb8CerqVXIlwk&s=22Gkvtf6LIwcpUWCHsw77ty68rzPjjTFKyMYKYKIakI&e=, or mute the thread https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe_AEQu6FFvAXjkl1AQQLED7SNdQNbZflLAks5qUcWVgaJpZM4IXwY-5F&d=CwMCaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=DvT4PEagC1_uJoK7XYcVznCf9vBnV8AqDdM20MaTLvM&m=d3cXtcrTvaVVrEmssfwWNm_8RzR4IRyb8CerqVXIlwk&s=Rn_K15EsGi8VueSrp-a51do63SunJLx0e6O7dPvJpLY&e=.