Accessing GCC’s Abstract Syntax Tree with a GCC Plugin
Recently I was given the task of transposing the Abstract Syntax Tree (AST) from GCC to another file format (such as json or xml). To do this I needed a way to access the AST and so I used GCC's plugin system where you can apply customizations to the compilation. In this blog post I will start using GCC's API to create the plugin accordingly. This focuses on accessing the AST itself, there are other ways, such as accessing the gimple representation, which comes later in GCC's compilation process. Check out this article to get started with GCC's plugin system.
How to Write a C++ Test Framework
A long time ago I had a question about how Googletest or Catch2 implement their macros to run all the unit tests they write. While writing the implementation for CWT-Cucumber: A C++ Cucumber Interpreter, I needed the same mechanism to achieve this particular behaviour. Registering functions before main is executed. In this article I write a proof of concept for a C++ test framework.
[C++] Start Using Cucucmber Part 2. This Time With CWT-Cucumber
I have implemented a Cucumber interpreter in C++20. CWT-Cucumber: A C++ Cucumber interpreter is my project for this and except for the rules I have implemented all Cucumber features to the best of my knowledge. In addition, there is a Conan recipe to create a Conan package. This means that there is now a native C++ Cucumber interpreter available without third party dependencies.
[C++] Lets Review my Article on Type Erasure
Someone pointed out that my type erasure example in the other article was broken and called a destructor twice. I investigated this and modified the example, adding an emplace method. In the end it still seems understandable to me, so lets check out this C++ Type Erasure.
Crafting a Cucumber Interpreter in C/C++
I created a C/C++ Cucumber interpreter, based on “Crafting Interpreters” by Robert Nystrom. It compiles a feature file into byte code which is then executed by a vm. The interpreter implementation is C and there are no third party libraries needed to compile and use it. In addition I created C++ bindings to make it easier to use. Check out this article for my initial thoughts and check out the GitHub repository with the project and its examples.
My Sphinx Best Practice Guide for Multi-version Documentation in Different Languages
This is my personal best practice and guide so far about Sphinx documentations. We create a Sphinx documentation from scratch, add some C++ and JavaScript source code documentation, include doxygen and finally publish it on GitHub pages. In the first place it looks quite a lot but after working some time with it this is a really good and nice looking way to have a documentation.
[C++] Exploring the Potential About a std::find Wrapper
In my last example i started to create something similar to C++23 std::optional's .andthen(..) / .orelse(..) for std::find / std::find_if. I tried to achieve something similiar and write a bit less code with this. Unfortunately it turned out it does not improve my code. But it wasn’t for nothing, because I got one use case with maps where I could at least use my approach.
[C++] A find-Function to Append .and_then(..).or_else(..) in C++
Finding values in C++ containers can make large if statements or checking iterators often at end(). With C++23's std::optional there are new wrapper functions like .and_then(..). You can pass a lambda and it will only be called if there is a value. I try to do the same with find, which frees me from always checking an iterator.
[C++] Breaking Dependencies With Templates
In this article we go over an easy example to create a static interface. Instead of using a interface with virtual methods, we use a template. This gives flexibility and creates an easy way to change the interface. It also removes the dynamic polymorphism. For the clients we use template meta programming and concepts to check if the interface signatures are correct.
[C++] A std::tuple To Concatenate Validation Criteria
I recently had this problem that I need to store multiple validation functions which returned a bool and I didn’t want to use std::vector or any other runtime container. Concatenating if statements weren’t a good solution either. Ultimately I came up with a solution where I used std::tuple in combination with std::apply
[C++] Rendering An OpenGL Framebuffer Into A Dear ImGui Window
This is a basic example of how to render a triangle into a framebuffer with OpenGL / GLFW and display this in a Dear ImGui window. This is a basic example in C++, which renders a green triangle into a framebuffer and creates a texture of it. Finally this will be displayed in a Dear ImGui window.
[C++] User-Defined Literals To Handle Units
Create a good notation to convert units, like seconds or ms. I used C++11 User-Defined Literals and a specific time type to handle my time units. This approach can also be applied to other units, like meters. Now the code appears more clear because I have a specific notation to distinguish times and can also compare my values correctly without casting it on clients side.
[C++] Use EnTT When You Need An ECS
EnTT is an open-source, header-only entity component system library for C++. Most likely there aren’t many reasons to an ECS by your own, so don’t waste time on any details and make fast progress by using this third party library. In this article I integrate in my SDL ECS example EnTT and refactor this project.
[C++] An Entity-Component-System From Scratch
ECS is the abbreviation for Entity Component System. Here we’ll create an ECS from scratch with a SDL example in C++. We create a window and we’ll be able to render characters to it. By adding components we are also able to move this character arounde by pressing A, S, D and W. So let’s get started with Entity Component Systems with a C++ example.
[C++] CRTP For Mixin Classes
I had an article about CRTP and C++20 concepts for static polymorphic behaviour. This demonstrated that concepts can replace CRTP but this doesn’t mean that we don’t need CRTP anymore. In this article we create a strong type and extend it with different “Skills” by using CRTP.
[C++] Combine Type Erasure And Strategies
In this example we combine type erasure with a strategy like pattern. We continue with a character type from my first article about type erasure and we’ll add a rendering method to them without modifying the concrete classes. This increases encapsulation on our example and demonstrates how powerful this combination could be.
[C++] Use Type Erasure To Get Dynamic Polymorphic Behavior
This is a simple and short example to understand the idea of type erasure. In this article we create a simple class which can erase your concrete types and illustrates the general behavior and what it requres to have polymorphic behavior at runtime. For a more comprehensive understanding and include tests, I recommend watching Klaus Iglbergers talk about this topic from CppCon 2022.
[C++] Genetic Algorithm
In this article we’ll take a look on a genetic algorithm. We’ll use this algorithm to find a certain string value. We take a look over the theory of this algorithm and then implment this in C++. In the coding example the population and the individual are represented by an own class which we then use to find our target value.
[Typescript/C++]: Coroutines: What are they and what we have in C++20
Coroutines are available with C++20. Unfortunately they aren’t ready to use like in other languages. We still need a generator type, which we implement and create a first, fairly simple coroutine. But before we do so, we take a look on Typescript to understand what coroutines are and how they are implemented there.
Windows Docker Container for MSVC Builds with Conan in Gitlab
Let’s set up a Windows build using Microsoft Visual Studio Compiler and Conan in Gitlab. We’ll use Windows Docker Containers to run our builds with Gitlab Runner. This is a guide to get started with Windows Docker builds with a Gitlab Runner. Ultimately we store all Conan packages directly on the host to reduce the build time.