From 21600f02fdd9c5777000af671fb557f5aa2bcf19 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Thu, 12 Nov 2015 04:49:00 +0900 Subject: [PATCH] main: implement R(RefMarker) field 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 #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 --- Tmain/list-fields.d/input.c | 1 + Tmain/list-fields.d/input.sh | 5 +++++ Tmain/list-fields.d/run.sh | 6 ++++-- Tmain/list-fields.d/stdout-expected.txt | 7 +++++++ main/field.c | 13 +++++++++++++ main/field.h | 1 + 6 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Tmain/list-fields.d/input.sh diff --git a/Tmain/list-fields.d/input.c b/Tmain/list-fields.d/input.c index 85752241a5..16ef7b30e8 100644 --- a/Tmain/list-fields.d/input.c +++ b/Tmain/list-fields.d/input.c @@ -1,3 +1,4 @@ +#include struct X { int i; }; diff --git a/Tmain/list-fields.d/input.sh b/Tmain/list-fields.d/input.sh new file mode 100644 index 0000000000..63dd914a47 --- /dev/null +++ b/Tmain/list-fields.d/input.sh @@ -0,0 +1,5 @@ +source x +function y() +{ +} + diff --git a/Tmain/list-fields.d/run.sh b/Tmain/list-fields.d/run.sh index 01de488b03..deda8a988e 100644 --- a/Tmain/list-fields.d/run.sh +++ b/Tmain/list-fields.d/run.sh @@ -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 } : && @@ -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" diff --git a/Tmain/list-fields.d/stdout-expected.txt b/Tmain/list-fields.d/stdout-expected.txt index 7d1bf539c1..9b39f34d11 100644 --- a/Tmain/list-fields.d/stdout-expected.txt +++ b/Tmain/list-fields.d/stdout-expected.txt @@ -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 @@ -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 diff --git a/main/field.c b/main/field.c index 9191344dcd..8f0ff13637 100644 --- a/main/field.c +++ b/main/field.c @@ -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, \ @@ -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), @@ -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: */ diff --git a/main/field.h b/main/field.h index 89460cb13a..6cee544eef 100644 --- a/main/field.h +++ b/main/field.h @@ -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,