@@ -108,6 +108,10 @@ typedef enum {
108108 K_NETTYPE ,
109109} verilogKind ;
110110
111+ typedef enum {
112+ R_MODULE_DECL ,
113+ } verilogModuleRole ;
114+
111115typedef struct {
112116 const char * keyword ;
113117 verilogKind kind ;
@@ -141,11 +145,20 @@ static int Ungetc;
141145static int Lang_verilog ;
142146static 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+
144156static 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+
10521075static 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+
10571085static 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