Skip to content

Commit

Permalink
[extract] Add some preparatory code for extracting expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed Aug 23, 2023
1 parent e64d7a1 commit c967e3a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ static void reclassifyInOutVariables(ProgramGraphNode *program) {
}

/* ************************** macro ******************************* */
/* Preparing for extract function or macro inside expression */
/* But how do we know this... */
bool isInExpression = false;

static void generateNewMacroCall(ProgramGraphNode *program) {
char name[TMP_STRING_SIZE];
Expand All @@ -611,7 +614,10 @@ static void generateNewMacroCall(ProgramGraphNode *program) {

resultingString[0]=0;

sprintf(resultingString+strlen(resultingString),"\t%s",extractionName);
if (isInExpression)
sprintf(resultingString+strlen(resultingString), "%s", extractionName);
else
sprintf(resultingString+strlen(resultingString), "\t%s", extractionName);

for (p=program; p!=NULL; p=p->next) {
if (p->classification == EXTRACT_VALUE_ARGUMENT
Expand All @@ -628,7 +634,11 @@ static void generateNewMacroCall(ProgramGraphNode *program) {
isFirstArgument = false;
}
}
sprintf(resultingString+strlen(resultingString), "%s);\n", isFirstArgument?"(":"");

if (isInExpression)
sprintf(resultingString+strlen(resultingString), "%s)", isFirstArgument?"(":"");
else
sprintf(resultingString+strlen(resultingString), "%s);\n", isFirstArgument?"(":"");

assert(strlen(resultingString)<EXTRACT_GEN_BUFFER_SIZE-1);
if (options.xref2) {
Expand Down Expand Up @@ -712,9 +722,10 @@ static void generateNewFunctionCall(ProgramGraphNode *program) {
sprintf(resultingString+strlen(resultingString),"\t%s = ", name);
}
} else {
strcat(resultingString, "\t");
if (!isInExpression)
strcat(resultingString, "\t");
}
sprintf(resultingString+strlen(resultingString),"%s",extractionName);
sprintf(resultingString+strlen(resultingString), "%s", extractionName);

for (p=program; p!=NULL; p=p->next) {
if (p->classification == EXTRACT_VALUE_ARGUMENT
Expand All @@ -736,8 +747,13 @@ static void generateNewFunctionCall(ProgramGraphNode *program) {
isFirstArgument = false;
}
}
sprintf(resultingString+strlen(resultingString), "%s);\n", isFirstArgument?"(":"");

if (isInExpression)
sprintf(resultingString+strlen(resultingString), "%s)", isFirstArgument?"(":"");
else
sprintf(resultingString+strlen(resultingString), "%s);\n", isFirstArgument?"(":"");
assert(strlen(resultingString)<EXTRACT_GEN_BUFFER_SIZE-1);

if (options.xref2) {
ppcGenRecord(PPC_STRING_VALUE, resultingString);
} else {
Expand Down

0 comments on commit c967e3a

Please sign in to comment.