Skip to content

Commit 3e09622

Browse files
committed
Verilog: extract module names used for defining instances as reference tags
This one is conceptually based on universal-ctags/ctags@master...my2817:ctags:master reported and written by @my2817 at universal-ctags#3469. The test case is also taken from universal-ctags#3469 submitted by @my2817.
1 parent 6009dc5 commit 3e09622

File tree

7 files changed

+83
-7
lines changed

7 files changed

+83
-7
lines changed

Tmain/list-roles.d/stdout-expected.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Ruby L/library required on loaded by "require"
9292
Ruby L/library requiredRel on loaded by "require_relative" method
9393
Sh h/heredoc endmarker on end marker
9494
Sh s/script loaded on loaded
95+
SystemVerilog m/module decl on declaring instances
9596
SystemdUnit u/unit After on referred in After key
9697
SystemdUnit u/unit Before on referred in Before key
9798
SystemdUnit u/unit RequiredBy on referred in RequiredBy key
@@ -108,6 +109,7 @@ Vera d/macro condition off used in part of #if/
108109
Vera d/macro undef on undefined
109110
Vera h/header local on local header
110111
Vera h/header system on system header
112+
Verilog m/module decl on declaring instances
111113

112114
#
113115
# all.*
@@ -202,6 +204,7 @@ Ruby L/library required on loaded by "require"
202204
Ruby L/library requiredRel on loaded by "require_relative" method
203205
Sh h/heredoc endmarker on end marker
204206
Sh s/script loaded on loaded
207+
SystemVerilog m/module decl on declaring instances
205208
SystemdUnit u/unit After on referred in After key
206209
SystemdUnit u/unit Before on referred in Before key
207210
SystemdUnit u/unit RequiredBy on referred in RequiredBy key
@@ -218,6 +221,7 @@ Vera d/macro condition off used in part of #if/
218221
Vera d/macro undef on undefined
219222
Vera h/header local on local header
220223
Vera h/header system on system header
224+
Verilog m/module decl on declaring instances
221225

222226
#
223227
# C.*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--sort=no
2+
--extras=+r
3+
--fields=+r
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test input.v /^module test (\/*AUTOARG*\/);$/;" m roles:def
2+
i_a input.v /^ input i_a, i_b;$/;" p module:test roles:def
3+
i_b input.v /^ input i_a, i_b;$/;" p module:test roles:def
4+
o_c input.v /^ output o_c;$/;" p module:test roles:def
5+
int1 input.v /^ ref1 int1 ();$/;" i module:test typeref:module:ref1 roles:def
6+
ref1 input.v /^ ref1 int1 ();$/;" m module:test roles:decl
7+
int2 input.v /^ ref1 int2 ();$/;" i module:test typeref:module:ref1 roles:def
8+
ref1 input.v /^ ref1 int2 ();$/;" m module:test roles:decl
9+
int3 input.v /^ int3 ();$/;" i module:test typeref:module:ref3 roles:def
10+
ref3 input.v /^ ref3 # (.A (aaa),$/;" m module:test roles:decl
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Taken from #3469 submitted by @my2817
2+
module test (/*AUTOARG*/);
3+
input i_a, i_b;
4+
output o_c;
5+
6+
ref1 int1 ();
7+
ref1 int2 ();
8+
ref3 # (.A (aaa),
9+
.B (bbb))
10+
int3 ();
11+
12+
endmodule // test

docs/man/ctags-lang-verilog.7.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ Note that ``prototype`` (``Q``) is disabled by default.
8484
r register yes no 0 NONE variable data types
8585
t task yes no 0 NONE tasks
8686
87+
A supported role for the ``module`` kind
88+
........................................
89+
90+
.. code-block:: console
91+
92+
$ ctags --list-roles=Verilog.module
93+
#KIND(L/N) NAME ENABLED DESCRIPTION
94+
m/module defInstance on defining instances
95+
8796
Supported Language Specific Fields
8897
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8998

man/ctags-lang-verilog.7.rst.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ Note that ``prototype`` (``Q``) is disabled by default.
8484
r register yes no 0 NONE variable data types
8585
t task yes no 0 NONE tasks
8686

87+
A supported role for the ``module`` kind
88+
........................................
89+
90+
.. code-block:: console
91+
92+
$ ctags --list-roles=Verilog.module
93+
#KIND(L/N) NAME ENABLED DESCRIPTION
94+
m/module defInstance on defining instances
95+
8796
Supported Language Specific Fields
8897
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8998

parsers/verilog.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ typedef enum {
108108
K_NETTYPE,
109109
} verilogKind;
110110

111+
typedef enum {
112+
R_MODULE_DECL,
113+
} verilogModuleRole;
114+
111115
typedef struct {
112116
const char *keyword;
113117
verilogKind kind;
@@ -141,11 +145,20 @@ static int Ungetc;
141145
static int Lang_verilog;
142146
static int Lang_systemverilog;
143147

148+
static roleDefinition VerilogModuleRoles [] = {
149+
{ true, "decl", "declaring instances" },
150+
};
151+
152+
static roleDefinition SystemVerilogModuleRoles [] = {
153+
{ true, "decl", "declaring instances" },
154+
};
155+
144156
static kindDefinition VerilogKinds [] = {
145157
{ true, 'c', "constant", "constants (define, parameter, specparam)" },
146158
{ true, 'e', "event", "events" },
147159
{ true, 'f', "function", "functions" },
148-
{ true, 'm', "module", "modules" },
160+
{ true, 'm', "module", "modules",
161+
.referenceOnly = false, ATTACH_ROLES(VerilogModuleRoles) },
149162
{ true, 'n', "net", "net data types" },
150163
{ true, 'p', "port", "ports" },
151164
{ true, 'r', "register", "variable data types" },
@@ -158,7 +171,8 @@ static kindDefinition SystemVerilogKinds [] = {
158171
{ true, 'c', "constant", "constants (define, parameter, specparam, enum values)" },
159172
{ true, 'e', "event", "events" },
160173
{ true, 'f', "function", "functions" },
161-
{ true, 'm', "module", "modules" },
174+
{ true, 'm', "module", "modules",
175+
.referenceOnly = false, ATTACH_ROLES(SystemVerilogModuleRoles) },
162176
{ true, 'n', "net", "net data types" },
163177
{ true, 'p', "port", "ports" },
164178
{ true, 'r', "register", "variable data types" },
@@ -949,7 +963,7 @@ static int dropEndContext (tokenInfo *const token, int c)
949963
}
950964

951965

952-
static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, tokenInfo *const typeref)
966+
static void createTagFull (tokenInfo *const token, verilogKind kind, int role, tokenInfo *const typeref)
953967
{
954968
tagEntryInfo tag;
955969

@@ -981,7 +995,10 @@ static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, toke
981995
}
982996

983997
/* Create tag */
984-
initTagEntry (&tag, vStringValue (token->name), kind);
998+
if (role == ROLE_DEFINITION_INDEX)
999+
initTagEntry (&tag, vStringValue (token->name), kind);
1000+
else
1001+
initRefTagEntry (&tag, vStringValue (token->name), kind, role);
9851002
tag.lineNumber = token->lineNumber;
9861003
tag.filePosition = token->filePosition;
9871004

@@ -1011,7 +1028,8 @@ static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, toke
10111028

10121029
makeTagEntry (&tag);
10131030

1014-
if (isXtagEnabled (XTAG_QUALIFIED_TAGS) && currentContext->kind != K_UNDEFINED)
1031+
if (isXtagEnabled (XTAG_QUALIFIED_TAGS) && currentContext->kind != K_UNDEFINED
1032+
&& role == ROLE_DEFINITION_INDEX)
10151033
{
10161034
vString *const scopedName = vStringNew ();
10171035

@@ -1027,7 +1045,7 @@ static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, toke
10271045
}
10281046

10291047
/* Push token as context if it is a container */
1030-
if (container)
1048+
if (container && role == ROLE_DEFINITION_INDEX)
10311049
{
10321050
createContext (kind, token->name);
10331051

@@ -1037,7 +1055,7 @@ static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, toke
10371055
for (unsigned int i = 0; i < ptrArrayCount (tagContents); i++)
10381056
{
10391057
tokenInfo *content = ptrArrayItem (tagContents, i);
1040-
createTagWithTypeRef (content, content->kind, NULL);
1058+
createTagFull (content, content->kind, ROLE_DEFINITION_INDEX, NULL);
10411059
}
10421060

10431061
/* Drop temporary contexts */
@@ -1049,11 +1067,21 @@ static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, toke
10491067
vStringClear (token->inheritance);
10501068
}
10511069

1070+
static void createTagWithTypeRef (tokenInfo *const token, verilogKind kind, tokenInfo *const typeref)
1071+
{
1072+
createTagFull (token, kind, ROLE_DEFINITION_INDEX, typeref);
1073+
}
1074+
10521075
static void createTag (tokenInfo *const token, verilogKind kind)
10531076
{
10541077
createTagWithTypeRef (token, kind, NULL);
10551078
}
10561079

1080+
static void createRefTag (tokenInfo *const token, verilogKind kind, int role)
1081+
{
1082+
createTagFull (token, kind, role, NULL);
1083+
}
1084+
10571085
static int skipBlockName (tokenInfo *const token, int c)
10581086
{
10591087
if (c == ':')
@@ -1873,6 +1901,7 @@ static int tagIdsInDataDecl (tokenInfo* token, int c, verilogKind kind)
18731901
tokenSaved->kind = K_MODULE; // for typeRef field
18741902
verbose ("find instance: %s with kind %s\n", vStringValue (token->name), getNameForKind (K_INSTANCE));
18751903
createTagWithTypeRef (token, K_INSTANCE, tokenSaved);
1904+
createRefTag (tokenSaved, K_MODULE, R_MODULE_DECL);
18761905
}
18771906
}
18781907
c = skipMacro (c, token); // `ifdef, `else, `endif, etc. (before comma)

0 commit comments

Comments
 (0)