Browse files

Fortran: fix handling of preprocessor directives on the first line

Fix a race initialization leading to incorrect handling of preprocessor
directives on the first input line.

Test case contributed by Adam Hirst, thanks.
  • Loading branch information...
1 parent 9871799 commit e47d45eb281a968b733241aab431c045d61569f9 @b4n b4n committed Feb 22, 2014
Showing with 30 additions and 6 deletions.
  1. +7 −6 tagmanager/ctags/fortran.c
  2. +1 −0 tests/ctags/Makefile.am
  3. +17 −0 tests/ctags/preprocessor.f90
  4. +5 −0 tests/ctags/preprocessor.f90.tags
View
13 tagmanager/ctags/fortran.c
@@ -208,6 +208,7 @@ static unsigned int Column = 0;
static boolean FreeSourceForm = FALSE;
static boolean ParsingString;
static tokenInfo *Parent = NULL;
+static boolean NewLine = TRUE;
static unsigned int contextual_fake_count = 0;
/* indexed by tagType */
@@ -725,7 +726,6 @@ static int skipToNextLine (void)
static int getFreeFormChar (boolean inComment)
{
- static boolean newline = TRUE;
boolean advanceLine = FALSE;
int c = fileGetc ();
@@ -740,7 +740,7 @@ static int getFreeFormChar (boolean inComment)
while (isspace (c) && c != '\n');
if (c == '\n')
{
- newline = TRUE;
+ NewLine = TRUE;
advanceLine = TRUE;
}
else if (c == '!')
@@ -751,24 +751,24 @@ static int getFreeFormChar (boolean inComment)
c = '&';
}
}
- else if (newline && (c == '!' || c == '#'))
+ else if (NewLine && (c == '!' || c == '#'))
advanceLine = TRUE;
while (advanceLine)
{
while (isspace (c))
c = fileGetc ();
- if (c == '!' || (newline && c == '#'))
+ if (c == '!' || (NewLine && c == '#'))
{
c = skipToNextLine ();
- newline = TRUE;
+ NewLine = TRUE;
continue;
}
if (c == '&')
c = fileGetc ();
else
advanceLine = FALSE;
}
- newline = (boolean) (c == '\n');
+ NewLine = (boolean) (c == '\n');
return c;
}
@@ -2289,6 +2289,7 @@ static boolean findFortranTags (const unsigned int passCount)
FreeSourceForm = (boolean) (passCount > 1);
contextual_fake_count = 0;
Column = 0;
+ NewLine = TRUE;
exception = (exception_t) setjmp (Exception);
if (exception == ExceptionEOF)
retry = FALSE;
View
1 tests/ctags/Makefile.am
@@ -194,6 +194,7 @@ test_sources = \
objectivec_protocol.mm \
Package.pm \
php5_5_class_kw.php \
+ preprocessor.f90 \
procedure_pointer_module.f90 \
procpoint.f90 \
property.cs \
View
17 tests/ctags/preprocessor.f90
@@ -0,0 +1,17 @@
+#include
+! preprocessor directives on line 1 (and only line 1) cause breakage
+module Invisible
+
+ integer :: nope
+
+contains
+
+ function SpillsOutside
+ ! ...
+ end function SpillsOutside
+
+end module Invisible
+
+program Main
+! ...
+end program Main
View
5 tests/ctags/preprocessor.f90.tags
@@ -0,0 +1,5 @@
+# format=tagmanager
+Invisible�256�0
+Main�2048�0
+SpillsOutside�16�Invisible�0
+nope�16384�Invisible�0

0 comments on commit e47d45e

Please sign in to comment.