Skip to content

Commit fc768e3

Browse files
committed
Fortran,refactor: add structures representing source-form specific parser states
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 325dd43 commit fc768e3

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

parsers/fortran.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,21 @@ typedef struct sTokenInfo {
228228

229229
static langType Lang_fortran;
230230
static int Ungetc;
231-
static unsigned int Column; /* Use only in FixedSourceForm pass */
231+
232232
static fortranPass currentPass;
233233
#define inFreeSourceForm ((currentPass) == PASS_FREE_FORM)
234234
#define inFixedSourceForm ((currentPass) == PASS_FIXED_FORM)
235-
static bool Newline; /* Use only in FreeSourceForm pass */
236-
static bool FreeSourceFormFound; /* Used only in FixedSourceForm pass */
235+
236+
/* State used only in FixedSourceForm pass */
237+
static struct {
238+
unsigned int column;
239+
bool freeSourceFormFound;
240+
} Fixed;
241+
242+
/* State used only in FreeSourceForm pass */
243+
static struct {
244+
bool newline;
245+
} Free;
237246

238247
/* indexed by tagType */
239248
static kindDefinition FortranKinds [] = {
@@ -695,29 +704,29 @@ static int getFixedFormChar (bool parsingString, bool *freeSourceFormFound)
695704
lineType type;
696705
int c = '\0';
697706

698-
if (Column > 0)
707+
if (Fixed.column > 0)
699708
{
700709
#ifdef STRICT_FIXED_FORM
701710
/* EXCEPTION! Some compilers permit more than 72 characters per line.
702711
*/
703-
if (Column > 71)
712+
if (Fixed.column > 71)
704713
c = skipLine ();
705714
else
706715
#endif
707716
{
708717
c = getcFromInputFile ();
709-
++Column;
718+
++Fixed.column;
710719
}
711720
if (c == '\n')
712721
{
713722
newline = true; /* need to check for continuation line */
714-
Column = 0;
723+
Fixed.column = 0;
715724
}
716725
else if (c == '!' && ! parsingString)
717726
{
718727
c = skipLine ();
719728
newline = true; /* need to check for continuation line */
720-
Column = 0;
729+
Fixed.column = 0;
721730
}
722731
else if (c == '&') /* check for free source form */
723732
{
@@ -728,7 +737,7 @@ static int getFixedFormChar (bool parsingString, bool *freeSourceFormFound)
728737
ungetcToInputFile (c2);
729738
}
730739
}
731-
while (Column == 0)
740+
while (Fixed.column == 0)
732741
{
733742
type = getLineType ();
734743
switch (type)
@@ -743,7 +752,7 @@ static int getFixedFormChar (bool parsingString, bool *freeSourceFormFound)
743752
case LTYPE_COMMENT: skipLine (); break;
744753

745754
case LTYPE_EOF:
746-
Column = 6;
755+
Fixed.column = 6;
747756
if (newline)
748757
c = '\n';
749758
else
@@ -754,20 +763,20 @@ static int getFixedFormChar (bool parsingString, bool *freeSourceFormFound)
754763
if (newline)
755764
{
756765
c = '\n';
757-
Column = 6;
766+
Fixed.column = 6;
758767
break;
759768
}
760769
/* fall through to next case */
761770
case LTYPE_CONTINUATION:
762-
Column = 5;
771+
Fixed.column = 5;
763772
do
764773
{
765774
c = getcFromInputFile ();
766-
++Column;
775+
++Fixed.column;
767776
} while (isBlank (c));
768777
if (c == '\n')
769-
Column = 0;
770-
else if (Column > 6)
778+
Fixed.column = 0;
779+
else if (Fixed.column > 6)
771780
{
772781
ungetcToInputFile (c);
773782
c = ' ';
@@ -805,7 +814,7 @@ static int getFreeFormChar (void)
805814
while (isspace (c) && c != '\n');
806815
if (c == '\n')
807816
{
808-
Newline = true;
817+
Free.newline = true;
809818
advanceLine = true;
810819
}
811820
else if (c == '!')
@@ -816,24 +825,24 @@ static int getFreeFormChar (void)
816825
c = '&';
817826
}
818827
}
819-
else if (Newline && (c == '!' || c == '#'))
828+
else if (Free.newline && (c == '!' || c == '#'))
820829
advanceLine = true;
821830
while (advanceLine)
822831
{
823832
while (isspace (c))
824833
c = getcFromInputFile ();
825-
if (c == '!' || (Newline && c == '#'))
834+
if (c == '!' || (Free.newline && c == '#'))
826835
{
827836
c = skipToNextLine ();
828-
Newline = true;
837+
Free.newline = true;
829838
continue;
830839
}
831840
if (c == '&')
832841
c = getcFromInputFile ();
833842
else
834843
advanceLine = false;
835844
}
836-
Newline = (bool) (c == '\n');
845+
Free.newline = (bool) (c == '\n');
837846
return c;
838847
}
839848

@@ -856,7 +865,7 @@ static int getCharFull (bool parsingString, bool *freeSourceFormFound)
856865

857866
static int getChar (void)
858867
{
859-
return getCharFull (false, &FreeSourceFormFound);
868+
return getCharFull (false, &Fixed.freeSourceFormFound);
860869
}
861870

862871
static void ungetChar (const int c)
@@ -924,19 +933,19 @@ static vString *parseNumeric (int c)
924933
static void parseString (vString *const string, const int delimiter)
925934
{
926935
const unsigned long inputLineNumber = getInputLineNumber ();
927-
int c = getCharFull (true, &FreeSourceFormFound);
936+
int c = getCharFull (true, &Fixed.freeSourceFormFound);
928937

929938
while (c != delimiter && c != '\n' && c != EOF)
930939
{
931940
vStringPut (string, c);
932-
c = getCharFull (true, &FreeSourceFormFound);
941+
c = getCharFull (true, &Fixed.freeSourceFormFound);
933942
}
934943
if (c == '\n' || c == EOF)
935944
{
936945
verbose ("%s: unterminated character string at line %lu\n",
937946
getInputFileName (), inputLineNumber);
938947
if (c != EOF && inFixedSourceForm)
939-
FreeSourceFormFound = true;
948+
Fixed.freeSourceFormFound = true;
940949
}
941950
}
942951

@@ -1071,7 +1080,7 @@ static void readToken (tokenInfo *const token)
10711080
else
10721081
{
10731082
skipLine ();
1074-
Column = 0;
1083+
Fixed.column = 0;
10751084
}
10761085
/* fall through to newline case */
10771086
case '\n':
@@ -2669,15 +2678,15 @@ static rescanReason findFortranTags (const unsigned int passCount)
26692678
if (currentPass == INIT_PASS)
26702679
Ungetc = '\0';
26712680
if (inFreeSourceForm)
2672-
Newline = true;
2681+
Free.newline = true;
26732682
if (inFixedSourceForm)
26742683
{
2675-
Column = 0;
2676-
FreeSourceFormFound = false;
2684+
Fixed.column = 0;
2685+
Fixed.freeSourceFormFound = false;
26772686
}
26782687

26792688
parseProgramUnit (token);
2680-
if (inFixedSourceForm && FreeSourceFormFound)
2689+
if (inFixedSourceForm && Fixed.freeSourceFormFound)
26812690
{
26822691
verbose ("%s: not fixed source form; retry as free source form\n",
26832692
getInputFileName ());

0 commit comments

Comments
 (0)