I have an update from this past Thursday: the port from blocks to text works. It was easier than I imagined.
Robot club was Thursday and I had a chance to meet with the developer. I told her about the research I did and how I thought it would let her switch to V5 text. She wanted to try it, so we fed her .v5blocks file into the filter. I opened the result in a text editor for her to look at. She immediately recognized variables she had named. A little bit of the code in the .cpp files was framework written by v5Blocks, but the vast majority was code she recognized as her own.
The code V5Blocks wrote involved include files, initialization code, naming of subsystem functions, and subsystem task management. I explained these parts of the code to the developer. The task start-stop code neede a little reformatting , but the code was otherwise well-formatted and readable straight out of the filter.
I explained to the developer what refactoring meant and how that was what we were doing. I explained how the smart move was to make no changes that are not absolutely necessary to get the code to build, download and run in V5 Text. She was OK with that so we started the real work of cutting and pasting the exported V5 Blocks code into an empty V5 Text project.
The exported V5Blocks file is one large
.cpp file. The V5 text file is two
.h files and two
.cpp files. To do the port we copied code into the V5 text
main.cpp. We ignored all of the
include statements in the source file. We copied all of the initialization code and every function definition from the source file except for
main(). To address the important parts of the
main, we copied all the lines within
main() from the source file and pasted them into the target file’s
main.h below the
vexcodeInit(); line. When the cut-and-paste work was done, the V5Text showed no parsing errors–the red squiggly lines.
The ported code built, downloaded and worked on the first try. In their testing, the team found one bug: the text they were writing to the brain’s screen was not formatted correctly. It was a minor bug. Before I left that day the developer was already modifying the Text code and sending revisions to the 'bot.
The entire session with the developer took 2 hours, but this was mostly a conversation about refactoring code, function naming conventions, and task management. The technical work was about 20 minutes of reading code and cut-and-paste. It was a good experience.
Many thanks to @sankeydd for the tip that the CPP code was embedded in the
.v5blocks files. That was the critical info I needed to make this happen.