Skip to content

Commit 34c9f30

Browse files
techeemasatake
authored andcommitted
Fortran: report anonymous tags
Currently anonymous tags aren't reported for Fortran which leaves members of such tags with incorrect scope information. This patch tries to fix this problem.
1 parent 027d6b2 commit 34c9f30

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
lines changed

Units/parser-fortran.r/fortran-abstract-interface.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__anonadfcf4320105 input.f90 /^ abstract interface$/;" i module:test
12
add input.f90 /^ procedure(suba), deferred :: add$/;" M type:atype
23
atype input.f90 /^ type, abstract :: atype$/;" t module:test
34
b input.f90 /^ class(atype) :: self, b$/;" L prototype:suba file:

Units/parser-fortran.r/fortran-bind-c.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__anon73f11bcd0105 input.f90 /^ interface$/;" i module:test_bind_c
12
a input.f90 /^ real/;" k type:atype
23
atype input.f90 /^ type, bind(c) :: atype$/;" t module:test_bind_c
34
global_flag input.f90 /^ integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag$/;" v module:test_bind_c

Units/parser-fortran.r/fortran-enum.d/expected.tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Named4 input.f90 /^ enum*8 Named4$/;" E module:Constants
77
Named5 input.f90 /^ enum(8) :: Named5$/;" E module:Constants
88
Named6 input.f90 /^ enum*8 :: Named6$/;" E module:Constants
99
Named7 input.f90 /^ enum, bind(c) :: Named7$/;" E module:Constants
10+
__anoncfbded350103 input.f90 /^ enum, bind(c) ! unnamed 1$/;" E module:Constants
11+
__anoncfbded350203 input.f90 /^ enum ! unnamed 2$/;" E module:Constants
1012
a input.f90 /^ enumerat/;" N module:Constants
1113
b input.f90 /^ enumerator :: a, b,/;" N module:Constants
1214
black input.f90 /^ enumerator :: red =1, blue, black /;" N module:Constants

Units/parser-fortran.r/fortran-interface.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
+ input.f90 /^ interface operator(+)/;" i module:test_interface
2+
__anon502b83b10105 input.f90 /^ interface ! anonymous interface$/;" i module:test_interface
23
add input.f90 /^ type(atype) function add(/;" P module:test_interface
34
atype input.f90 /^ type atype$/;" t module:test_interface
45
get input.f90 /^ interface get$/;" i module:test_interface

Units/parser-fortran.r/fortran-signature.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__anon06616a720105 input.f90 /^ interface$/;" i module:test_signature
12
a input.f90 /^ integer :: a$/;" L subroutine:fnb file:
23
a input.f90 /^ integer a,/;" L subroutine:suba file:
34
arg input.f90 /^ type(atype) :: arg$/;" L prototype:subb file:

Units/parser-fortran.r/numlib.f90.d/expected.tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__anon1963f93b0305 input.f90 /^ interface$/;" i module:numerical_libraries
2+
__anon1963f93b0405 input.f90 /^ interface$/;" i prototype:b2lsf
13
a2ald input.f90 /^ subroutine a2ald /;" P module:numerical_libraries
24
b2lsf input.f90 /^ subroutine b2lsf /;" P module:numerical_libraries
35
fcn input.f90 /^ subroutine fcn(/;" P prototype:b2lsf

Units/parser-fortran.r/recursive.f95.d/expected.tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__anon8fb642160105 input.f95 /^ $/;" i module:approx
2+
__anon8fb642160205 input.f95 /^ $/;" i module:approx2
13
approx input.f95 /^ MODULE approx$/;" m
24
approx2 input.f95 /^ MODULE approx2$/;" m
35
arcsin input.f95 /^ recursive function arcsin /;" P module:approx

Units/parser-fortran.r/structure.f.d/expected.tags

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
a input.f /^ integer a$/;" k type:anonymous
1+
__anon76fabc930106 input.f /^ structure level3a, level3b$/;" t type:nested
2+
a input.f /^ integer a$/;" k type:__anon76fabc930106
23
clouds input.f /^ character*20 clouds /;" k type:weather
34
clouds input.f /^ character*20 clouds$/;" k type:weather
45
day input.f /^ integer*1 month \/08\/, day /;" k type:weather

Units/parser-fypp.r/run-guest.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
+ input.fy /^ interface operator(+)/;" i line:31 module:test_interface
2+
__anonca2bcf340105 input.fy /^ interface ! anonymous interface$/;" i line:39 module:test_interface
23
add input.fy /^ type(atype) function add(/;" P line:33 module:test_interface
34
atype input.fy /^ type atype$/;" t line:28 module:test_interface
45
debug_code input.fy /^#:def debug_code(code)$/;" m line:4 end:8

parsers/fortran.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ typedef struct sTokenInfo {
209209
struct sTokenInfo *secondary;
210210
unsigned long lineNumber;
211211
MIOPos filePosition;
212+
bool anonymous;
212213
} tokenInfo;
213214

214215
/*
@@ -464,6 +465,7 @@ static tokenInfo *newToken (void)
464465
token->isMethod = false;
465466
token->lineNumber = getInputLineNumber ();
466467
token->filePosition = getInputFilePosition ();
468+
token->anonymous = false;
467469

468470
return token;
469471
}
@@ -484,6 +486,14 @@ static tokenInfo *newTokenFrom (tokenInfo *const token)
484486
return newTokenFromFull (token, true);
485487
}
486488

489+
static tokenInfo *newAnonTokenFrom (tokenInfo *const token, unsigned int uTagKind)
490+
{
491+
tokenInfo *result = newTokenFromFull (token, false);
492+
result->anonymous = true;
493+
anonGenerate (result->string, "__anon", uTagKind);
494+
return result;
495+
}
496+
487497
static void deleteToken (tokenInfo *const token)
488498
{
489499
if (token != NULL)
@@ -535,6 +545,9 @@ static void makeFortranTag (tokenInfo *const token, tagType tag)
535545
if (token->tag == TAG_COMMON_BLOCK)
536546
e.lineNumberEntry = canUseLineNumberAsLocator();
537547

548+
if (token->anonymous)
549+
markTagExtraBit (&e, XTAG_ANONYMOUS);
550+
538551
e.lineNumber = token->lineNumber;
539552
e.filePosition = token->filePosition;
540553
e.isFileScope = isFileScope (token->tag);
@@ -1748,25 +1761,27 @@ static void parseUnionStmt (tokenInfo *const token)
17481761
*/
17491762
static void parseStructureStmt (tokenInfo *const token)
17501763
{
1751-
tokenInfo *name;
1764+
tokenInfo *name = NULL;
17521765
Assert (isKeyword (token, KEYWORD_structure));
17531766
readToken (token);
17541767
if (isType (token, TOKEN_OPERATOR) &&
17551768
strcmp (vStringValue (token->string), "/") == 0)
17561769
{ /* read structure name */
17571770
readToken (token);
17581771
if (isType (token, TOKEN_IDENTIFIER))
1759-
makeFortranTag (token, TAG_DERIVED_TYPE);
1760-
name = newTokenFrom (token);
1772+
{
1773+
name = newTokenFrom (token);
1774+
name->type = TOKEN_IDENTIFIER;
1775+
}
17611776
skipPast (token, TOKEN_OPERATOR);
17621777
}
1763-
else
1778+
if (name == NULL)
17641779
{ /* fake out anonymous structure */
1765-
name = newToken ();
1780+
name = newAnonTokenFrom (token, TAG_COMPONENT);
17661781
name->type = TOKEN_IDENTIFIER;
17671782
name->tag = TAG_DERIVED_TYPE;
1768-
vStringCopyS (name->string, "anonymous");
17691783
}
1784+
makeFortranTag (name, TAG_DERIVED_TYPE);
17701785
while (isType (token, TOKEN_IDENTIFIER))
17711786
{ /* read field names */
17721787
makeFortranTag (token, TAG_COMPONENT);
@@ -1982,29 +1997,27 @@ static void parseInterfaceBlock (tokenInfo *const token)
19821997
tokenInfo *name = NULL;
19831998
Assert (isKeyword (token, KEYWORD_interface));
19841999
readToken (token);
1985-
if (isType (token, TOKEN_IDENTIFIER))
1986-
{
1987-
makeFortranTag (token, TAG_INTERFACE);
1988-
name = newTokenFrom (token);
1989-
}
1990-
else if (isKeyword (token, KEYWORD_assignment) ||
2000+
if (isKeyword (token, KEYWORD_assignment) ||
19912001
isKeyword (token, KEYWORD_operator))
19922002
{
19932003
readToken (token);
19942004
if (isType (token, TOKEN_PAREN_OPEN))
19952005
readToken (token);
19962006
if (isType (token, TOKEN_OPERATOR))
1997-
{
1998-
makeFortranTag (token, TAG_INTERFACE);
19992007
name = newTokenFrom (token);
2000-
}
2008+
}
2009+
else if (isType (token, TOKEN_IDENTIFIER))
2010+
{
2011+
name = newTokenFrom (token);
2012+
name->type = TOKEN_IDENTIFIER;
20012013
}
20022014
if (name == NULL)
20032015
{
2004-
name = newToken ();
2016+
name = newAnonTokenFrom (token, TAG_INTERFACE);
20052017
name->type = TOKEN_IDENTIFIER;
20062018
name->tag = TAG_INTERFACE;
20072019
}
2020+
makeFortranTag (name, TAG_INTERFACE);
20082021
ancestorPush (name);
20092022
while (! isKeyword (token, KEYWORD_end) &&
20102023
! isType (token, TOKEN_EOF))
@@ -2054,15 +2067,17 @@ static void parseEnumBlock (tokenInfo *const token)
20542067
if (isType (token, TOKEN_DOUBLE_COLON))
20552068
readToken (token);
20562069
if (isType (token, TOKEN_IDENTIFIER))
2070+
{
20572071
name = newTokenFrom (token);
2072+
name->type = TOKEN_IDENTIFIER;
2073+
}
20582074
if (name == NULL)
20592075
{
2060-
name = newToken ();
2076+
name = newAnonTokenFrom (token, TAG_ENUM);
20612077
name->type = TOKEN_IDENTIFIER;
20622078
name->tag = TAG_ENUM;
20632079
}
2064-
else
2065-
makeFortranTag (name, TAG_ENUM);
2080+
makeFortranTag (name, TAG_ENUM);
20662081
skipToNextStatement (token);
20672082
ancestorPush (name);
20682083
while (! isKeyword (token, KEYWORD_end) &&

0 commit comments

Comments
 (0)