Skip to content

Commit

Permalink
SystemVerilog: utilize symbol table to distinguish typedef from port
Browse files Browse the repository at this point in the history
Close universal-ctags#2413.

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Feb 27, 2020
1 parent 3b5f843 commit 01bbfa1
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions parsers/verilog.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ static void createTag (tokenInfo *const token)
{
tagEntryInfo tag;
verilogKind kind;
int corkIndex;

/* Determine if kind is prototype */
if (currentContext->prototype)
Expand Down Expand Up @@ -646,7 +647,10 @@ static void createTag (tokenInfo *const token)
tag.extensionFields.inheritance = vStringValue (token->inheritance);
verbose ("Class %s extends %s\n", vStringValue (token->name), tag.extensionFields.inheritance);
}
makeTagEntry (&tag);
corkIndex = makeTagEntry (&tag);
if (isInputLanguage (Lang_systemverilog))
registerEntry (corkIndex);

if (isXtagEnabled(XTAG_QUALIFIED_TAGS) && currentContext->kind != K_UNDEFINED)
{
vString *const scopedName = vStringNew ();
Expand All @@ -657,7 +661,9 @@ static void createTag (tokenInfo *const token)
tag.name = vStringValue (scopedName);

markTagExtraBit (&tag, XTAG_QUALIFIED_TAGS);
makeTagEntry (&tag);
corkIndex = makeTagEntry (&tag);
if (isInputLanguage (Lang_systemverilog))
registerEntry (corkIndex);

vStringDelete (scopedName);
}
Expand Down Expand Up @@ -1124,6 +1130,26 @@ static void processClass (tokenInfo *const token)
}
}

static bool find_typedef (unsigned int corkIndex,
tagEntryInfo *entry, void *data)
{
if (entry->kindIndex == K_TYPEDEF)
{
*(bool *)data = true;
return false;
}
return true;
}

static bool isTypedef (tokenInfo* token)
{
bool t = false;
if (vStringLength (token->name) > 0)
foreachEntriesInScope (CORK_NIL, vStringValue (token->name),
find_typedef, &t);
return t;
}

static void tagNameList (tokenInfo* token, int c)
{
verilogKind localKind;
Expand Down Expand Up @@ -1160,7 +1186,8 @@ static void tagNameList (tokenInfo* token, int c)
readIdentifier (token, c);
localKind = getKindForToken (token);
/* Create tag in case name is not a known kind ... */
if (localKind == K_UNDEFINED)
if (localKind == K_UNDEFINED
&& !(isInputLanguage (Lang_systemverilog) && isTypedef (token)))
{
createTag (token);
}
Expand Down Expand Up @@ -1384,5 +1411,6 @@ extern parserDefinition* SystemVerilogParser (void)
def->extensions = extensions;
def->parser = findVerilogTags;
def->initialize = initializeSystemVerilog;
def->useCork = CORK_QUEUE|CORK_SYMTAB;
return def;
}

0 comments on commit 01bbfa1

Please sign in to comment.