Skip to content

Commit

Permalink
main: implement R(RefMarker) field
Browse files Browse the repository at this point in the history
This field is printed as R or D; R is for reference tag, and D is for
definition tag. This field is proposed by @shigio in universal-ctags#659 for GNU global.

Example output:

    $ cat input.sh
    source commonFuncs.sh
    foo()
    {
	    return 0
    }
    $ ./ctags -x --_xformat="%R %-16N %4n %-16F %C" --extra=+r --fields=+r input.sh
    D foo                 2 input.sh         foo()
    R commonFuncs.sh      1 input.sh         source commonFuncs.sh

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Nov 20, 2015
1 parent 68a945e commit 21600f0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions Tmain/list-fields.d/input.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdio.h>
struct X {
int i;
};
Expand Down
5 changes: 5 additions & 0 deletions Tmain/list-fields.d/input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source x
function y()
{
}

6 changes: 4 additions & 2 deletions Tmain/list-fields.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ with_field()
local lang=$2
: &&
echo "#$field" &&
$CTAGS --quiet --options=NONE --fields=$field -o - input.$lang
$CTAGS --quiet --options=NONE $3 --fields=$field -o - input.$lang
}

: &&
Expand All @@ -28,4 +28,6 @@ with_field()
with_field sZ java &&
with_field f c &&
with_field S c &&
with_field t c
with_field t c &&
with_field r sh --extra=+r &&
with_field r sh "--extra=+r -x --_xformat=%R/%r"
7 changes: 7 additions & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ l language Language of source file containing tag format-char off
m implementation Implementation information format-char off
n line Line number of tag definition format-char off
r role role format-char off
R NONE Marker(R or D) representing whether tag is definition or reference format-char off
S signature Signature of routine (e.g. prototype or parameter list) format-char off
s NONE Scope of tag definition(WARNING: this doesn't work well as a format letter) format-char on
t typeref Type and name of a variable or typedef format-char on
Expand Down Expand Up @@ -73,3 +74,9 @@ i input.c /^ int i;$/
j input.c /^ int j;$/
main input.c /^int main(void)$/
x input.c /^ struct X x;$/;" typeref:struct:Y::X
#r
x input.sh /^source x$/;" role:generic
y input.sh /^function y()$/
#r
D/
R/generic
13 changes: 13 additions & 0 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const char *renderFieldImplementation (const tagEntryInfo *const tag, vSt
static const char *renderFieldFile (const tagEntryInfo *const tag, vString* b);
static const char *renderFieldPattern (const tagEntryInfo *const tag, vString* b);
static const char *renderFieldRole (const tagEntryInfo *const tag, vString* b);
static const char *renderFieldRefMarker (const tagEntryInfo *const tag, vString* b);

#define DEFINE_FIELD_FULL(L,N, V, H, B, F) { \
.enabled = V, \
Expand Down Expand Up @@ -102,6 +103,9 @@ static fieldDesc fieldDescs [] = {
DEFINE_FIELD ('r', "role", FALSE,
"role",
renderFieldRole),
DEFINE_FIELD ('R', NULL, FALSE,
"Marker(R or D) representing whether tag is definition or reference",
renderFieldRefMarker),
DEFINE_FIELD ('S', "signature", FALSE,
"Signature of routine (e.g. prototype or parameter list)",
renderFieldSignature),
Expand Down Expand Up @@ -414,4 +418,13 @@ static const char *renderFieldPattern (const tagEntryInfo *const tag, vString* b
return vStringValue (b);
}

static const char *renderFieldRefMarker (const tagEntryInfo *const tag, vString* b)
{
static char c[2] = { [1] = '\0' };

c [0] = tag->extensionFields.roleIndex == ROLE_INDEX_DEFINITION? 'D': 'R';

return renderAsIs (b, c);
}

/* vi:set tabstop=4 shiftwidth=4: */
1 change: 1 addition & 0 deletions main/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef enum eFieldType { /* extension field content control */
FIELD_IMPLEMENTATION,
FIELD_LINE_NUMBER,
FIELD_ROLE,
FIELD_REF_MARK,
FIELD_SIGNATURE,
FIELD_SCOPE,
FIELD_TYPE_REF,
Expand Down

0 comments on commit 21600f0

Please sign in to comment.