Skip to content

Commit

Permalink
Merge pull request #4174 from masatake/main--revise-xref-output
Browse files Browse the repository at this point in the history
main: FIX the way to print boolean typed parser specific fields correctly in {xref,ctags} output
  • Loading branch information
masatake authored Jan 11, 2025
2 parents 7ed02a4 + 8df3449 commit 35c5c97
Show file tree
Hide file tree
Showing 49 changed files with 292 additions and 72 deletions.
4 changes: 0 additions & 4 deletions Tmain/json-output-boolean-fields.d/stdout-expected.txt

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions Tmain/json-output-typed-fields.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static int local;
int global;
File renamed without changes.
6 changes: 6 additions & 0 deletions Tmain/json-output-typed-fields.d/input.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============================================
TITLE
==============================================

section
-------
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ if is_feature_available "${CTAGS}" json; then
${CTAGS} --quiet --options=NONE -o - \
--output-format=json \
--language-force=CTagsSelfTest input.ctst
${CTAGS} --quiet --options=NONE -o - \
--output-format=json \
--fields-RestructuredText=+'{overline}' input.rst
${CTAGS} --quiet --options=NONE -o - \
--output-format=json \
input.c
fi
11 changes: 11 additions & 0 deletions Tmain/json-output-typed-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{"_type": "tag", "name": "atag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker"}
{"_type": "tag", "name": "btag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "bField": true}
{"_type": "tag", "name": "ctag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "bField": true}
{"_type": "tag", "name": "dtag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "sbField": "val"}
{"_type": "tag", "name": "etag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "sbField": false}
{"_type": "tag", "name": "ftag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "sField": "val"}
{"_type": "tag", "name": "gtag", "path": "input.ctst", "pattern": "/^f$/", "kind": "fieldMaker", "sField": ""}
{"_type": "tag", "name": "TITLE", "path": "input.rst", "pattern": "/^TITLE$/", "kind": "title", "overline": true}
{"_type": "tag", "name": "section", "path": "input.rst", "pattern": "/^section$/", "kind": "subtitle", "scope": "TITLE", "scopeKind": "title"}
{"_type": "tag", "name": "global", "path": "input.c", "pattern": "/^int global;$/", "typeref": "typename:int", "kind": "variable"}
{"_type": "tag", "name": "local", "path": "input.c", "pattern": "/^static int local;$/", "file": true, "typeref": "typename:int", "kind": "variable"}
File renamed without changes.
8 changes: 0 additions & 8 deletions Tmain/tags-output-boolean-fields.d/run.sh

This file was deleted.

4 changes: 0 additions & 4 deletions Tmain/tags-output-boolean-fields.d/stdout-expected.txt

This file was deleted.

2 changes: 2 additions & 0 deletions Tmain/tags-output-typed-fields.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static int local;
int global;
File renamed without changes.
6 changes: 6 additions & 0 deletions Tmain/tags-output-typed-fields.d/input.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============================================
TITLE
==============================================

section
-------
17 changes: 17 additions & 0 deletions Tmain/tags-output-typed-fields.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright: 2016 Masatake YAMATO
# License: GPL-2

CTAGS=$1

${CTAGS} --quiet --options=NONE -o - \
--output-format=u-ctags \
--language-force=CTagsSelfTest input.ctst

${CTAGS} --quiet --options=NONE -o - \
--output-format=u-ctags \
--fields-RestructuredText=+'{overline}' \
input.rst

${CTAGS} --quiet --options=NONE -o - \
--output-format=u-ctags \
input.c
11 changes: 11 additions & 0 deletions Tmain/tags-output-typed-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
atag input.ctst /^f$/;" f
btag input.ctst /^f$/;" f bField:
ctag input.ctst /^f$/;" f bField:
dtag input.ctst /^f$/;" f sbField:val
etag input.ctst /^f$/;" f sbField:
ftag input.ctst /^f$/;" f sField:val
gtag input.ctst /^f$/;" f sField:
TITLE input.rst /^TITLE$/;" H overline:
section input.rst /^section$/;" h title:TITLE
global input.c /^int global;$/;" v typeref:typename:int
local input.c /^static int local;$/;" v typeref:typename:int file:
8 changes: 0 additions & 8 deletions Tmain/xformat-boolean-fields.d/run.sh

This file was deleted.

4 changes: 0 additions & 4 deletions Tmain/xformat-boolean-fields.d/stdout-expected.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions Tmain/xref-output-typed-fields.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static int local;
int global;
File renamed without changes.
6 changes: 6 additions & 0 deletions Tmain/xref-output-typed-fields.d/input.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============================================
TITLE
==============================================

section
.......
19 changes: 19 additions & 0 deletions Tmain/xref-output-typed-fields.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright: 2016 Masatake YAMATO
# License: GPL-2

CTAGS=$1

echo '# input.ctst'
${CTAGS} --quiet --options=NONE -o - \
--output-format=xref --_xformat='%{name} -> b=%{CTagsSelfTest.bField},sb=%{CTagsSelfTest.sbField},s=%{CTagsSelfTest.sField}' \
--language-force=CTagsSelfTest input.ctst

echo '# input.rst'
${CTAGS} --quiet --options=NONE -o - \
--output-format=xref --_xformat='%{name} -> %{RestructuredText.overline}' \
input.rst

echo '# input.c'
${CTAGS} --quiet --options=NONE -o - \
--output-format=xref --_xformat='%{name} -> %{file}' \
input.c
14 changes: 14 additions & 0 deletions Tmain/xref-output-typed-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# input.ctst
atag -> b=-,sb=,s=
btag -> b=bField,sb=,s=
ctag -> b=bField,sb=,s=
dtag -> b=-,sb=val,s=
etag -> b=-,sb=-,s=
ftag -> b=-,sb=,s=val
gtag -> b=-,sb=,s=
# input.rst
TITLE -> overline
section -> -
# input.c
global -> -
local -> file
24 changes: 8 additions & 16 deletions main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,15 @@ extern void resetTagCorkState (tagEntryInfo *const tag,
*
* Interpretation of VALUE
* -----------------------
* For FIELDTYPE_STRING:
* Both json writer and xref writer print it as-is.
*
* For FIELDTYPE_STRING|FIELDTYPE_BOOL:
* If VALUE points "" (empty C string), the json writer prints it as
* false, and the xref writer prints it as -.
* If VALUE points a non-empty C string, Both json writer and xref
* writers print it as-is.
*
* For FIELDTYPE_BOOL
* The json writer always prints true.
* The xref writer always prints the name of field.
* Set "" explicitly though the value pointed by VALUE is not referred,
*
*
* The other data type and the combination of types are not implemented yet.
* The VALUE is interpreted very differently depending on the output
* format: ctags, xref, and json. See field.h.
*
* WARNING: updating the VALUE
* ---------------------------
* In the current implementation, there is no way to update the value
* for a given field or detach the value from the given field.
* For the same combination of TAG and FTYPE, you can call the
* attachParser* function only once.
*/
extern void attachParserField (tagEntryInfo *const tag, fieldType ftype, const char* value);
extern void attachParserFieldToCorkEntry (int index, fieldType ftype, const char* value);
Expand Down
55 changes: 32 additions & 23 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ static bool doesContainAnyCharInInput (const tagEntryInfo *const tag, const char
static bool doesContainAnyCharInFieldScope (const tagEntryInfo *const tag, const char *value, const char *chars);
static bool doesContainAnyCharInSignature (const tagEntryInfo *const tag, const char *value, const char *chars);

static bool isTyperefFieldAvailable (const tagEntryInfo *const tag);
static bool isFileFieldAvailable (const tagEntryInfo *const tag);
static bool isInheritsFieldAvailable (const tagEntryInfo *const tag);
static bool isAccessFieldAvailable (const tagEntryInfo *const tag);
static bool isImplementationFieldAvailable (const tagEntryInfo *const tag);
static bool isSignatureFieldAvailable (const tagEntryInfo *const tag);
static bool isExtrasFieldAvailable (const tagEntryInfo *const tag);
static bool isXpathFieldAvailable (const tagEntryInfo *const tag);
static bool isEndFieldAvailable (const tagEntryInfo *const tag);
static bool isEpochAvailable (const tagEntryInfo *const tag);
static bool isNthAvailable (const tagEntryInfo *const tag);
static bool isTyperefFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isFileFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isInheritsFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isAccessFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isImplementationFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isSignatureFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isExtrasFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isXpathFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isEndFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isEpochAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);
static bool isNthAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef);

static EsObject* getFieldValueForName (const tagEntryInfo *, const fieldDefinition *);
static EsObject* setFieldValueForName (tagEntryInfo *, const fieldDefinition *, const EsObject *);
Expand Down Expand Up @@ -614,7 +614,8 @@ extern unsigned char getFieldLetter (fieldType type)
extern bool doesFieldHaveValue (fieldType type, const tagEntryInfo *tag)
{
if (getFieldObject(type)->def->isValueAvailable)
return getFieldObject(type)->def->isValueAvailable(tag);
return getFieldObject(type)->def->isValueAvailable(tag,
getFieldObject(type)->def);
else
return true;
}
Expand Down Expand Up @@ -1164,43 +1165,43 @@ static const char *renderFieldNth (const tagEntryInfo *const tag,
#undef buf_len
}

static bool isTyperefFieldAvailable (const tagEntryInfo *const tag)
static bool isTyperefFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.typeRef [0] != NULL
&& tag->extensionFields.typeRef [1] != NULL)? true: false;
}

static bool isFileFieldAvailable (const tagEntryInfo *const tag)
static bool isFileFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return tag->isFileScope? true: false;
}

static bool isInheritsFieldAvailable (const tagEntryInfo *const tag)
static bool isInheritsFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.inheritance != NULL)? true: false;
}

static bool isAccessFieldAvailable (const tagEntryInfo *const tag)
static bool isAccessFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.access != NULL)? true: false;
}

static bool isImplementationFieldAvailable (const tagEntryInfo *const tag)
static bool isImplementationFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.implementation != NULL)? true: false;
}

static bool isSignatureFieldAvailable (const tagEntryInfo *const tag)
static bool isSignatureFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields.signature != NULL)? true: false;
}

static bool isExtrasFieldAvailable (const tagEntryInfo *const tag)
static bool isExtrasFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return isTagExtra (tag);
}

static bool isXpathFieldAvailable (const tagEntryInfo *const tag)
static bool isXpathFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
#ifdef HAVE_LIBXML
return (tag->extensionFields.xpath != NULL)? true: false;
Expand All @@ -1209,19 +1210,19 @@ static bool isXpathFieldAvailable (const tagEntryInfo *const tag)
#endif
}

static bool isEndFieldAvailable (const tagEntryInfo *const tag)
static bool isEndFieldAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->extensionFields._endLine != 0)? true: false;
}

static bool isEpochAvailable (const tagEntryInfo *const tag)
static bool isEpochAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
return (tag->kindIndex == KIND_FILE_INDEX)
? true
: false;
}

static bool isNthAvailable (const tagEntryInfo *const tag)
static bool isNthAvailable (const tagEntryInfo *const tag, const fieldDefinition *fdef CTAGS_ATTR_UNUSED)
{
Assert (tag->langType >= NO_NTH_FIELD);
return (tag->extensionFields.nth != NO_NTH_FIELD)? true: false;
Expand Down Expand Up @@ -1315,6 +1316,11 @@ static const char* defaultRenderer (const tagEntryInfo *const tag CTAGS_ATTR_UNU
return renderEscapedString (value, tag, buffer);
}

static bool isValueAvailableGeneric (const tagEntryInfo *const e, const fieldDefinition *fdef)
{
return getParserFieldValueForType(e, fdef->ftype)? true: false;
}

extern int defineField (fieldDefinition *def, langType language)
{
fieldObject *fobj;
Expand Down Expand Up @@ -1347,6 +1353,9 @@ extern int defineField (fieldDefinition *def, langType language)
if (! def->dataType)
def->dataType = FIELDTYPE_STRING;

if (def->isValueAvailable == NULL)
def->isValueAvailable = isValueAvailableGeneric;

fobj->def = def;

fobj->buffer = NULL;
Expand Down
Loading

0 comments on commit 35c5c97

Please sign in to comment.