swtv-kaist / cs458-spring24

7 stars 0 forks source link

[HW 4] Stuck at expanding Macros in task 1? #20

Closed Ahmadsm2005 closed 5 months ago

Ahmadsm2005 commented 5 months ago

Hello! I have two questions.

Question 1: I am solving task 1 in HW 4 but I am stuck in expanding macros. This is the output of my program so far for the example:

function: f2 If ID: 0 Line: 4 Col: 2 Filename: ./example-kcov.h function: f1 If ID: 1 Line: 19 Col: 2 Filename: example-kcov.c function: main If ID: 2 Line: 30 Col: 2 Filename: example-kcov.c If ID: 3 Line: 32 Col: 9 Filename: example-kcov.c For ID: 4 Line: 40 Col: 2 Filename: example-kcov.c While ID: 5 Line: 45 Col: 2 Filename: example-kcov.c Do ID: 6 Line: 50 Col: 2 Filename: example-kcov.c Case ID: 7 Line: 52 Col: 4 Filename: example-kcov.c Case ID: 8 Line: 55 Col: 4 Filename: example-kcov.c ? ID: 9 Line: 56 Col: 16 Filename: example-kcov.c Default ID: 10 Line: 59 Col: 4 Filename: example-kcov.c If ID: 11 Line: 64 Col: 2 Filename: example-kcov.c ? ID: 12 Line: 64 Col: 11 Filename: example-kcov.c ImpDef. ID: 13 Line: 68 Col: 2 Filename: example-kcov.c Case ID: 14 Line: 69 Col: 3 Filename: example-kcov.c Case ID: 15 Line: 72 Col: 3 Filename: example-kcov.c Total number of branches: 26

I am not sure how I should iterate on the original macro. I can iterate on the statement that calls the Macro its self(FOO)(so to be able to get its line number and column) by checking if the current statement is the start of Macro(isMacroID) and getting the expansionrange of the current location of statement. But is there any hint/function/method that can make me iterate on the macro its self(preferably recursively to reach the original statements in case of nested macros)(so it can be processed).

Question 2:

Column number for some items like "?" is different from the example output. But by looking at the code, the ? is actually located in the 16th character of the line and 11th character of the line respectively. In that case, should I worry about it or is it correct?

Jae-Woo-Jung commented 5 months ago

For question2, The ? operation corresponds to "a == 3 ? 1 : 2". This is the dump() of that statement. So, the beginning location is the location of "a", not "?".

image
Ahmadsm2005 commented 5 months ago

Thank you so much! Your answer also hinted me on how to approach question 1 and I have completed it.