Skip to content

Commit

Permalink
fixup! fill scope field for module reference tags
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaiKinono committed Jan 15, 2021
1 parent b9e43d9 commit f1bfe7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Units/parser-julia.r/import_module.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Module7 input.jl /^import Module7: func1, func2$/;" kind:module roles:namespace
func1 input.jl /^import Module7: func1, func2$/;" kind:unknown scope:module:Module7 roles:imported
func2 input.jl /^import Module7: func1, func2$/;" kind:unknown scope:module:Module7 roles:imported
MyModule input.jl /^module MyModule$/;" kind:module roles:def
Module8 input.jl /^using Module8,$/;" kind:module roles:used
Module9 input.jl /^ Module9,$/;" kind:module roles:used
Module10 input.jl /^ Module10$/;" kind:module roles:used
Module11 input.jl /^using Module11: func1,$/;" kind:module roles:namespace
Module8 input.jl /^using Module8,$/;" kind:module scope:module:MyModule roles:used
Module9 input.jl /^ Module9,$/;" kind:module scope:module:MyModule roles:used
Module10 input.jl /^ Module10$/;" kind:module scope:module:MyModule roles:used
Module11 input.jl /^using Module11: func1,$/;" kind:module scope:module:MyModule roles:namespace
func1 input.jl /^using Module11: func1,$/;" kind:unknown scope:module:Module11 roles:used
func2 input.jl /^ func2,$/;" kind:unknown scope:module:Module11 roles:used
func3 input.jl /^ func3$/;" kind:unknown scope:module:Module11 roles:used
32 changes: 16 additions & 16 deletions parsers/julia.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ static void addTag (vString* ident, const char* type, const char* arg_list, int
makeTagEntry(&tag);
}

static void addReferenceTag (vString* ident, int kind, int role, unsigned long line, MIOPos pos, vString* scope)
static void addReferenceTag (vString* ident, int kind, int role, unsigned long line, MIOPos pos, vString* scope, int parent_kind)
{
if (kind == K_NONE)
{
Expand All @@ -895,9 +895,9 @@ static void addReferenceTag (vString* ident, int kind, int role, unsigned long l
initRefTagEntry(&tag, vStringValue(ident), kind, role);
tag.lineNumber = line;
tag.filePosition = pos;
if (scope != NULL)
if (parent_kind != K_NONE)
{
tag.extensionFields.scopeKindIndex = K_MODULE;
tag.extensionFields.scopeKindIndex = parent_kind;
tag.extensionFields.scopeName = vStringValue(scope);
}
makeTagEntry(&tag);
Expand Down Expand Up @@ -1218,17 +1218,17 @@ static void parseModule (lexerState *lexer, vString *scope, int parent_kind)
* of "Module", and this function will take it to the end of the entity
* (whitespaces also skipped).
*/
static void parseImportEntity (lexerState *lexer, int token_type)
static void parseImportEntity (lexerState *lexer, vString *scope, int token_type, int parent_kind)
{
if (lexer->cur_c == '.')
{
if (token_type == TOKEN_IMPORT)
{
vString *module_name = vStringNewCopy(lexer->token_str);
addReferenceTag(module_name, K_MODULE, JULIA_MODULE_NAMESPACE, lexer->line, lexer->pos, NULL);
addReferenceTag(module_name, K_MODULE, JULIA_MODULE_NAMESPACE, lexer->line, lexer->pos, scope, parent_kind);
advanceChar(lexer);
advanceToken(lexer, true);
addReferenceTag(lexer->token_str, K_UNKNOWN, JULIA_UNKNOWN_IMPORTED, lexer->line, lexer->pos, module_name);
addReferenceTag(lexer->token_str, K_UNKNOWN, JULIA_UNKNOWN_IMPORTED, lexer->line, lexer->pos, module_name, K_MODULE);
vStringDelete(module_name);
}
else /* if (token_type == TOKEN_USING) */
Expand All @@ -1242,11 +1242,11 @@ static void parseImportEntity (lexerState *lexer, int token_type)
{
if (token_type == TOKEN_IMPORT)
{
addReferenceTag(lexer->token_str, K_MODULE, JULIA_MODULE_IMPORTED, lexer->line, lexer->pos, NULL);
addReferenceTag(lexer->token_str, K_MODULE, JULIA_MODULE_IMPORTED, lexer->line, lexer->pos, scope, parent_kind);
}
else /* if (token_type == TOKEN_USING) */
{
addReferenceTag(lexer->token_str, K_MODULE, JULIA_MODULE_USED, lexer->line, lexer->pos, NULL);
addReferenceTag(lexer->token_str, K_MODULE, JULIA_MODULE_USED, lexer->line, lexer->pos, scope, parent_kind);
}
}
}
Expand All @@ -1256,7 +1256,7 @@ static void parseImportEntity (lexerState *lexer, int token_type)
/* using Module: symbol1, symbol2 */
/* The lexer should be at the end of "Module", and this function will take it
* to the end of the token after this expression (whitespaces also skipped). */
static void parseColonImportExpr (lexerState *lexer, int token_type)
static void parseColonImportExpr (lexerState *lexer, vString *scope, int token_type, int parent_kind)
{
int symbol_role;
if (token_type == TOKEN_IMPORT)
Expand All @@ -1268,7 +1268,7 @@ static void parseColonImportExpr (lexerState *lexer, int token_type)
symbol_role = JULIA_UNKNOWN_USED;
}
vString *name = vStringNewCopy(lexer->token_str);
addReferenceTag(name, K_MODULE, JULIA_MODULE_NAMESPACE, lexer->line, lexer->pos, NULL);
addReferenceTag(name, K_MODULE, JULIA_MODULE_NAMESPACE, lexer->line, lexer->pos, scope, parent_kind);
advanceChar(lexer);
advanceToken(lexer, true);
if (lexer->cur_token == TOKEN_NEWLINE)
Expand All @@ -1277,7 +1277,7 @@ static void parseColonImportExpr (lexerState *lexer, int token_type)
}
while (lexer->cur_token == TOKEN_IDENTIFIER || lexer->cur_token == TOKEN_MACROCALL)
{
addReferenceTag(lexer->token_str, K_UNKNOWN, symbol_role, lexer->line, lexer->pos, name);
addReferenceTag(lexer->token_str, K_UNKNOWN, symbol_role, lexer->line, lexer->pos, name, K_MODULE);
if (lexer->cur_c == ',')
{
advanceChar(lexer);
Expand All @@ -1298,22 +1298,22 @@ static void parseColonImportExpr (lexerState *lexer, int token_type)
/* Import format:
* [ "import" | "using" ] <ident> [: <name>]
*/
static void parseImport (lexerState *lexer, vString *scope, int token_type)
static void parseImport (lexerState *lexer, vString *scope, int token_type, int parent_kind)
{
/* capture the imported name */
advanceToken(lexer, true);
/* import Mod1: symbol1, symbol2 */
/* using Mod1: symbol1, symbol2 */
if (lexer->cur_c == ':')
{
parseColonImportExpr(lexer, token_type);
parseColonImportExpr(lexer, scope, token_type, parent_kind);
}
/* All other situations, like import/using Mod1, Mod2.symbol1, Mod3... */
else
{
while (lexer->cur_token == TOKEN_IDENTIFIER || lexer->cur_token == TOKEN_MACROCALL)
{
parseImportEntity(lexer, token_type);
parseImportEntity(lexer, scope, token_type, parent_kind);
if (lexer->cur_c == ',')
{
advanceChar(lexer);
Expand Down Expand Up @@ -1454,10 +1454,10 @@ static void parseExpr (lexerState *lexer, bool delim, int kind, vString *scope)
parseType(lexer, scope, kind);
break;
case TOKEN_IMPORT:
parseImport(lexer, scope, TOKEN_IMPORT);
parseImport(lexer, scope, TOKEN_IMPORT, kind);
break;
case TOKEN_USING:
parseImport(lexer, scope, TOKEN_USING);
parseImport(lexer, scope, TOKEN_USING, kind);
case TOKEN_IDENTIFIER:
if (lexer->first_token && lexer->cur_c == '.')
{
Expand Down

0 comments on commit f1bfe7b

Please sign in to comment.