Check Your Understanding

This purpose of this practical is to test your understanding of working with some complex types with ROSE. You will implement a simple tool that traverses the AST and looks for a complex type.

This is an “open-book” exercise and you may use the terminal and any resources. The ROSE API may be particularly useful.


Implement a ROSE translator that traverses the AST and prints the SAGE data type (e.g., SgTypeInt) and name for each const type-qualified variable. Use a standard pre-order traversal (rather than the Query Library). Run your translator with the following input code:

#include <cstdint>
#include <cmath>

const int foo = 632356;

void bar() {
	const float PI = 3.1415926;
	float x = atan2(3 * PI, 2);

int main(int argc, char* argv[]) {
	return 0;

Save your output to a file called const_output.txt in the ${ROSE_SRC}/practicals directory. The expected output is below. Please format it exactly as shown.

Found a const type-qualified variable: foo (SgTypeInt)
Found a const type-qualified variable: PI (SgTypeFloat)

Setting Up The Environment

Some starter code and a corresponding makefile is available for your usage. The following commands will obtain the skeleton source code for your translator constTypeModifier and save it to the ${ROSE_SRC}/practicals directory. The corresponding makefile is also saved to ${ROSE_BUILD}/practicals, as well as the input source code above as const_input.cxx in the same directory. Finally, the expected output is saved as a text file in order to be compared against the output generated by your implementation.

mkdir ${ROSE_BUILD}/practicals && cd "$_"
mkdir ${ROSE_SRC}/practicals && cd "$_"

Make your changes directly to the constTypeModifier.C source file and insert your code following the comment "Insert your tool code here!". Vim, nano, and emacs are available within the terminal. Note we have provided an implementation for saving your output to file. When you are done, exit the text editor and return to the terminal.


There are two steps to evaluating your implementation: building the translator itself, and testing it with the input code above. With respect to the latter, your translator will be evaluated with the input code and the resulting output will be compared against the expected output above. If they match, you will have completed and passed the practical; otherwise, you should return to your implementation and make sure it is correct. Please be sure to format your output exactly as the expected output.

To build your translator (without evaluation), run the following command.

cd ${ROSE_BUILD}/practicals

Your translator should report no errors (it may report warnings, but those can generally be ignored) if implemented correctly and an executable file named constTypeModifier should appear in the working directory.

Once you are ready, you should now run your implementation with the input code, and check its output, via

./constTypeModifier const_input.cxx
cat const_output.txt

If you obtain the expected output listed in the problem task description, you are ready for the formal evaluation. To do this, run command

make check

If PASSED is output, congratulations! You have completed the practical.