mortbopet / Ripes

A graphical processor simulator and assembly editor for the RISC-V ISA
https://ripes.me/
MIT License
2.49k stars 270 forks source link

Input Type always set to `Assembly` on startup #356

Open federicovilla55 opened 4 months ago

federicovilla55 commented 4 months ago

I have noticed that each time I open a C file in the Ripes GUI, after I save it and open it again, the same file appears in the Source Code section of the Editor tab, but the Input Type is always set to Assembly.


The Ripes.config file, which saves the settings of Ripes, contains the parameter input_type which stores an integer representing an element of the enumeration:

https://github.com/mortbopet/Ripes/blob/878087332afa3558dc8ca657f80a16ecdcf82818/src/assembler/program.h#L17-L28

When I close the simulator with a C file open in the editor tab, the field input_type = 1 is saved in the Ripes.config, indicating that the last opened file (whose source code is in the sourcecode field of the Ripes.config file) was a C file.

The problem is the next time Ripes is opened, that value is changed in input_type = 0, which means that the file is always considered an Assembly.

Looking at the code, the option input_type is modified by the method EditTab::sourceTypeChanged() and is set as follows:

https://github.com/mortbopet/Ripes/blob/878087332afa3558dc8ca657f80a16ecdcf82818/src/edittab.cpp#L255-L276

So when opening the simulator the input type is set as default as m_ui->setCInput has not been checked yet.

In the EditTab constructor before the m_ui are toggled the following methods are called:

https://github.com/mortbopet/Ripes/blob/878087332afa3558dc8ca657f80a16ecdcf82818/src/edittab.cpp#L112-L113

Those methods (that have a direct or indirect call to the method sourceTypeChanged()) change the input type to Assembly.

I suppose that those methods should not modify the input type, as it should be done in the constructor a few lines after:

https://github.com/mortbopet/Ripes/blob/878087332afa3558dc8ca657f80a16ecdcf82818/src/edittab.cpp#L127-L139


My proposal for the problem: