For five weeks in row we have been working on the enhancement of the code. I really don’t know why it’s taking that much time. Is that what usually happens in any project developing?! Feel like we are in infinite loop… Hopefully we will reach the “break;” statement soon. Lol !!

Code Auto-Completion:

Anyway, this week I was working on adding the AUTO-Completion feature to our code editor. Our code editor is based on Code-mirror JavaScript editor which is rich with so many addons and API that have already been used to enhance the coding experience in the project. However, when it comes to auto-Completion feature, CodeMirror has only auto-completion addons for certain language just like JavaScript, xml, and html. But the good news is that you can always build your own for the language you want. Moreover, you can always use the codemirror functionality of auto-completion to display your results on the editor. In the following lines I’ll try to explain to you the progress I made so far and the steps I followed to get our C++ code completion kinda work.
Let’s start first with the front end. By using codeMirror show-hint addon the auto-completion capability can be accessed. The addon has function called “showhint” which takes the editor instance and other function called “gethint” as parameters. (refer to codemirror manual for more info) and in return the widget will be displayed with the contents that have been returned by “gethint()”. The “gethint” function can be defined by you (otherwise default values will be used ) and it should return the array of strings that represents the completions.
So the question now from where can  the “gethint” function get those C++ completions? In order to get intelligent auto-completion an intelligent system is needed indeed. The system should provide the completion of user built classes and function plus the C++ standard libraries ones therefore this kind of system should parse the C++ code and define its structure and block and … . Don’t worry..! We don’t have to do that from scratch since there’s some helpful tool such as CLANG. CLANG is front end compiler that has the functionality of autocompletion and all you have to do is to provide the incomplete code and the position where you want the autocompletion to take place using the following command line.

clang -fsyntax-only -Xclang -code-completion-macros -Xclang -code-completion-at=xxxx.cpp:line:ch line.cpp

This compiling command will return the list of possible completion in such form:
COMPLETION: puts :[#int#]puts(<#const char *__s#>)

and all you have to do is to parse this output and then return it back to the browser. The whole system is now partially working. The hint drop box does appear with the right completions whenever the user presses CTRL-Right yet more javaScript code is needed to make it much user friendlier.

More modules!

I also had to build more wrappers modules for our project- Ethernet and SDCard – Building the wrappers for those two modules was not an issue but integrating them in the system was what confused me. Unlike others modules those two should only be instantiated once in the whole system, which means there has to be a way to limit the multi-declaration for their C++ classes, and they can only be connected to specific pins in the FPGA. These pins are not limited only to those modules ports and can be also used by others modules as well, .. hmm Does that somehow necessitate the creation function of the top module to check for the availability of those ports whenever the user instantiate any Ethernet or SDCard ?

Logging messages

Logging messages are needed to help you keep track of your system operations. They are really useful for debugging as well and whenever the system crashes. This week I worked also in adding these logging messages to my code using witty function WT::log() . Different logging messages were implemented. Some show errors and other show info while other only show the warning messages .

That is it for this week… Stay safe 🙂


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.