Skip to content

Commit

Permalink
CPreProcessor: don't use isTagExtra() to pick up tags for adding them…
Browse files Browse the repository at this point in the history
… to a signature string

The original code scanned corkQueue to pick up tags for making
signature string. To avoid adding unwanted tags to the signature
string, isTagExtra was used (522de3f).

However, filtering with isTagExtra was too aggressive; tags extracted
by the CPreProcessor parser running as a part of guest parser were
rejected.

This change uses an intArray. Instead of filtering candidate items in
the corkQueue, the CPreProcessor collects tags for parameters to
the intArray. The parameters are parts of a signature, not candidates.
Therefore we don't need "filtering" anymore.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 4, 2023
1 parent 07c8b54 commit e8ea347
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ static void makeIncludeTag (const char *const name, bool systemHeader)
}
}

static void makeParamTag (vString *name, short nth, bool placeholder)
static int makeParamTag (vString *name, short nth, bool placeholder)
{
bool standing_alone = doesCPreProRunAsStandaloneParser(CPREPRO_MACRO);

Expand All @@ -890,15 +890,17 @@ static void makeParamTag (vString *name, short nth, bool placeholder)
if (placeholder)
markTagAsPlaceholder (e, placeholder);
}
return r;
}

static void regenreateSignatureFromParameters (vString * buffer, int from, int to)
static void makeSignatureStringFromParameters (vString * buffer, intArray *parameters)
{
vStringPut(buffer, '(');
for (int pindex = from; pindex < to; pindex++)
for (size_t i = 0; i < intArrayCount (parameters); i++)
{
int pindex = intArrayItem (parameters, i);
tagEntryInfo *e = getEntryInCorkQueue (pindex);
if (e && !isTagExtra (e))
if (e)
{
vStringCatS (buffer, e->name);
vStringPut (buffer, ',');
Expand Down Expand Up @@ -939,6 +941,7 @@ static int directiveDefine (const int c, bool undef)

if (p == '(')
{
intArray *params = intArrayNew ();
vString *param = vStringNew ();
int param_start = (int)countEntryInCorkQueue();
do {
Expand All @@ -953,7 +956,8 @@ static int directiveDefine (const int c, bool undef)

if (vStringLength (param) > 0)
{
makeParamTag (param, nth++, vStringChar(param, 0) == '.');
int r = makeParamTag (param, nth++, vStringChar(param, 0) == '.');
intArrayAdd (params, r);
vStringClear (param);
}
if (p == '\\')
Expand All @@ -965,12 +969,13 @@ static int directiveDefine (const int c, bool undef)
if (p == ')')
{
vString *signature = vStringNew ();
regenreateSignatureFromParameters (signature, param_start, param_end);
makeSignatureStringFromParameters (signature, params);
r = makeDefineTag (vStringValue (Cpp.directive.name), vStringValue (signature), undef);
vStringDelete (signature);
}
else
r = makeDefineTag (vStringValue (Cpp.directive.name), NULL, undef);
intArrayDelete (params);

tagEntryInfo *e = getEntryInCorkQueue (r);
if (e)
Expand Down

0 comments on commit e8ea347

Please sign in to comment.