Skip to content

Commit e11dbdb

Browse files
committed
Handling of #pragma once
The handling of the `#pragma once` was different from the handling of a file with the `#ifndef` guard construction, making, especially when nested include files were in e.g. a namespace, very slow.
1 parent d2de45e commit e11dbdb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/pre.l

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ struct preYY_state
306306
DefineMap localDefines; // macros defined in this file
307307
DefineList macroDefinitions;
308308
LinkedMap<PreIncludeInfo> includeRelations;
309+
StringVector pragmaList;
309310

310311
int lastContext = 0;
311312
bool lexRulesPart = false;
@@ -448,6 +449,7 @@ WSopt [ \t\r]*
448449
%x RulesRoundSquare
449450
%x RulesRound
450451
%x RulesRoundQuest
452+
%x PragmaOnce
451453

452454
%%
453455

@@ -1063,6 +1065,21 @@ WSopt [ \t\r]*
10631065
}
10641066
<Command>"pragma"{B}+"once" {
10651067
yyextra->expectGuard = FALSE;
1068+
if (std::find(yyextra->pragmaList.begin(), yyextra->pragmaList.end(), yyextra->fileName.data()) != yyextra->pragmaList.end())
1069+
{
1070+
outputChar(yyscanner,'\n');
1071+
BEGIN(PragmaOnce);
1072+
}
1073+
else
1074+
{
1075+
yyextra->pragmaList.push_back(yyextra->fileName.data());
1076+
}
1077+
}
1078+
<PragmaOnce>. {}
1079+
<PragmaOnce>\n {}
1080+
<PragmaOnce><<EOF>> {
1081+
yyextra->expectGuard = FALSE;
1082+
BEGIN(Start);
10661083
}
10671084
<Command>{ID} { // unknown directive
10681085
BEGIN(IgnoreLine);
@@ -2048,7 +2065,7 @@ WSopt [ \t\r]*
20482065
}
20492066
<*>{CCS}/{CCE} |
20502067
<*>{CCS}[*!]? {
2051-
if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || YY_START==IDLquote)
2068+
if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || YY_START==IDLquote || YY_START == PragmaOnce)
20522069
{
20532070
REJECT;
20542071
}
@@ -2070,7 +2087,7 @@ WSopt [ \t\r]*
20702087
}
20712088
}
20722089
<*>{CPPC}[/!]? {
2073-
if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran || YY_START==IDLquote)
2090+
if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran || YY_START==IDLquote || YY_START == PragmaOnce)
20742091
{
20752092
REJECT;
20762093
}
@@ -4015,6 +4032,7 @@ void Preprocessor::processFile(const QCString &fileName,const std::string &input
40154032
state->includeStack.clear();
40164033
state->expandedDict.clear();
40174034
state->contextDefines.clear();
4035+
state->pragmaList.clear();
40184036
while (!state->condStack.empty()) state->condStack.pop();
40194037

40204038
setFileName(yyscanner,fileName);

0 commit comments

Comments
 (0)