15%option never-interactive
18%option extra-type="struct preYY_state *"
22#define YY_TYPEDEF_YY_SCANNER_T
68#define YY_NO_UNISTD_H 1
133 for (
auto &[name,define] : fromMap)
151 if (dpf && includeStack.find(incFile)==includeStack.end())
153 includeStack.insert(incFile);
160 toMap.emplace(name,define);
174 void addInclude(
const std::string &fromFileName,
const std::string &toFileName)
180 it =
m_fileMap.emplace(fromFileName,std::make_unique<DefinesPerFile>(
this)).first;
182 auto &dpf = it->second;
183 dpf->addInclude(toFileName);
192 it =
m_fileMap.emplace(fileName,std::make_unique<DefinesPerFile>(
this)).first;
194 it->second->store(fromMap);
202 auto &dpf = it->second;
203 dpf->retrieve(toMap);
213 return it->second->stored();
223 return it!=
m_fileMap.end() ? it->second.get() :
nullptr;
226 std::unordered_map< std::string, std::unique_ptr<DefinesPerFile> >
m_fileMap;
352static yy_size_t
getFenceSize(
char *txt, yy_size_t leng);
357#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
constant expression parser used for the C preprocessor
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
A class representing a macro definition.
Local class used to hold the defines for a single file.
void addInclude(const std::string &fileName)
DefinesPerFile(DefineManager *parent)
Creates an empty container for defines.
void retrieveRec(DefineMap &toMap, StringUnorderedSet &includeStack)
void store(const DefineMap &fromMap)
StringUnorderedSet m_includedFiles
void retrieve(DefineMap &toMap)
Class that manages the defines available while preprocessing files.
bool alreadyProcessed(const std::string &fileName) const
void addInclude(const std::string &fromFileName, const std::string &toFileName)
void store(const std::string &fileName, const DefineMap &fromMap)
std::unordered_map< std::string, std::unique_ptr< DefinesPerFile > > m_fileMap
void retrieve(const std::string &fileName, DefineMap &toMap)
DefinesPerFile * find(const std::string &fileName) const
Helper function to return the DefinesPerFile object for a given file name.
A model of a file symbol.
Container class representing a vector of objects with keys.
std::stack< bool > BoolStack
std::unordered_set< std::string > StringUnorderedSet
std::vector< std::string > StringVector
std::map< std::string, int > IntMap
std::vector< Define > DefineList
List of all macro definitions.
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Portable versions of functions that are platform dependent.
static DString expandMacro(yyscan_t yyscanner, const DString &name)
static DString extractTrailingComment(const DString &s)
std::map< std::string, Define > DefineMap
A dictionary of managed Define objects.
static void setCaseDone(yyscan_t yyscanner, bool value)
static void addMacroDefinition(yyscan_t yyscanner)
static void decrLevel(yyscan_t yyscanner)
static void addDefine(yyscan_t yyscanner)
static void determineBlockName(yyscan_t yyscanner)
static DString expandStandardMacro(yyscan_t yyscanner, const DString &name)
static bool computeExpression(yyscan_t yyscanner, const DString &expr)
static void incrLevel(yyscan_t yyscanner)
static void outputSpaces(yyscan_t yyscanner, char *s)
static void endCondSection(yyscan_t yyscanner)
static DString escapeAt(const DString &text)
static std::mutex g_globalDefineMutex
static void outputChar(yyscan_t yyscanner, char c)
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
static char resolveTrigraph(char c)
static const char * stateToString(int state)
static void outputString(yyscan_t yyscanner, const DString &s)
static void setFileName(yyscan_t yyscanner, const DString &name)
static DefineManager g_defineManager
static void startCondSection(yyscan_t yyscanner, const DString §Id)
static yy_size_t getFenceSize(char *txt, yy_size_t leng)
static std::mutex g_updateGlobals
static bool otherCaseDone(yyscan_t yyscanner)
static void outputArray(yyscan_t yyscanner, const char *a, yy_size_t len)
static void extraSpacing(yyscan_t yyscanner)
static const char * getLexerFILE()
static void outputSpace(yyscan_t yyscanner, char c)
static Define * isDefined(yyscan_t yyscanner, const DString &name)
Returns a reference to a Define object given its name or 0 if the Define does not exist.
static std::mutex g_debugMutex
static void readIncludeFile(yyscan_t yyscanner, const DString &inc)
Some helper functions for std::string.
const std::string * oldFileBuf
PreIncludeInfo(const DString &fn, FileDef *srcFd, FileDef *dstFd, const DString &iName, bool loc, bool imp)
preYY_CondCtx(const DString &file, int line, const DString &id, bool b)
StringUnorderedSet expanded
LinkedMap< PreIncludeInfo > includeRelations
DString condGuardErrorMessage
StringUnorderedSet pragmaSet
ConstExpressionParser constExpParser
std::unordered_map< std::string, Define * > expandedDict
std::deque< std::unique_ptr< FileState > > includeStack
std::stack< std::unique_ptr< preYY_CondCtx > > condStack
const std::string * inputBuf
DString condGuardErrorFileName
DefineList macroDefinitions
A bunch of utility functions.
367IDSTART [a-z_A-Z\x80-\xFF]
368ID {IDSTART}[a-z_A-Z0-9\x80-\xFF]*
372RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"("
373RAWEND ")"[^ \t\(\)\\]{0,16}\"
374CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
377FORMULA_START {CMD}("f{"|"f$"|"f["|"f(")
378FORMULA_END {CMD}("f}"|"f$"|"f]"|"f)")
379VERBATIM_START {CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly"|"dot"|"msc"|"mermaid"|"startuml"|"code"("{"[^}]*"}")?){BN}+
380VERBATIM_END {CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endmsc"|"endmermaid"|"enduml"|"endcode")
381VERBATIM_LINE {CMD}"noop"{B}+
382LITERAL_BLOCK {FORMULA_START}|{VERBATIM_START}
383LITERAL_BLOCK_END {FORMULA_END}|{VERBATIM_END}
388RulesSharp "<"[^>\n]*">"
389RulesCurly "{"[^{}\n]*"}"
394EscapeRulesCharOpen "\\["|"\<"|"\\{"|"\\("|"\\\""|"\\ "|"\\\\"
395EscapeRulesCharClose "\\]"|"\>"|"\\}"|"\\)"
396EscapeRulesChar {EscapeRulesCharOpen}|{EscapeRulesCharClose}
398DOXYCFG [A-Z][A-Z_0-9]*
413DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
414HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
415OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
416BINARY_INTEGER "0"[bB][01][01']*[01]?
417INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
421DIGIT_SEQ [0-9][0-9']*[0-9]?
422FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
423FP_EXP [eE][+-]?{DIGIT_SEQ}
424DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
425DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
427HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
428HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
429BIN_EXP [pP][+-]?{DIGIT_SEQ}
430HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
431HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
433FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
434FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
435FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
436NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
452%x CopyStringFtnDouble
469%x JavaDocVerbatimCode
503 yyextra->yyColNr+=(int)yyleng;
505 yyextra->potentialDefine=yytext;
508<Start>^("%top{"|"%{") {
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
513<Start>^{Bopt}"cpp_quote"{Bopt}"("{Bopt}\" {
514 if (yyextra->insideIDL)
529<IDLquote>"\""{Bopt}")" {
541 if (!yyextra->isFixedFormFtn) REJECT;
552<Start>^{B}*[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]+{B}*"("[^\)\n]*")"/{BN}{1,10}*[:{] {
554 for (i=(
int)yyleng-1;i>=0;i--)
560<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\(\)\n]*"("[^\)\n]*")"[^\)\n]*")"{B}*\n |
561<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\)\n]*")"{B}*\n |
562<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\(\)\n]*"("[^\)\n]*")"[^\)\n]*")"/{B}*("//"|"/\*") |
563<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\)\n]*")"/{B}*("//"|"/\*") {
566 size_t pos =
name.find(
'(');
568 name=
name.left(pos).stripWhiteSpace();
571 if (skipFuncMacros && !yyextra->insideFtn &&
572 name!=
"Q_PROPERTY" &&
574 (yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
575 yyextra->macroExpansion &&
583 if (yytext[yyleng-1] ==
'\n')
592 for (i=(
int)yyleng-1;i>=0;i--)
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
#define Config_getBool(name)
const char * name(int level)
599<CopyLine,LexCopyLine>"extern"{BN}*"\""[^\"]+"\""{BN}*("{")? {
601 yyextra->yyLineNr+=text.
contains(
'\n');
int contains(char c, bool cs=true) const
604<CopyLine,LexCopyLine>{RAWBEGIN} {
607 BEGIN(CopyRawString);
DString extractBeginRawStringDelimiter(const char *rawStart)
609<CopyLine,LexCopyLine>"{" {
610 if (yyextra->includeStack.empty())
612 yyextra->curlyCount++;
619<CopyLine,LexCopyLine>"}" {
620 if (yyextra->includeStack.empty() && yyextra->curlyCount>0)
622 yyextra->curlyCount--;
626<CopyLine,LexCopyLine>"'"\\[0-7]{1,3}"'" {
629<CopyLine,LexCopyLine>"'"\\."'" {
632<CopyLine,LexCopyLine>"'"."'" {
635<CopyLine,LexCopyLine>[$]?@\" {
638 BEGIN( CopyStringCs );
640<CopyLine,LexCopyLine>"!".* {
644<CopyLine,LexCopyLine>\" {
652 BEGIN( CopyStringFtnDouble );
655<CopyLine,LexCopyLine>\' {
658 BEGIN( CopyStringFtn );
660<CopyString>[^\"\\\r\n]{1,1000} {
663<CopyStringCs>[^\"\r\n]{1,1000} {
672<CopyString,CopyStringCs>\" {
676<CopyStringFtnDouble>[^\"\\\r\n]{1,1000} {
679<CopyStringFtnDouble>\\. {
682<CopyStringFtnDouble>\" {
686<CopyStringFtn>[^\'\\\r\n]{1,1000} {
696<CopyRawString>{RAWEND} {
DString extractEndRawStringDelimiter(const char *rawEnd)
703<CopyRawString>[^)]{1,1000} {
709<CopyLine,LexCopyLine>{ID}/{BN}{0,80}"(" {
710 yyextra->expectGuard =
false;
720 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
721 yyextra->macroExpansion &&
727 yyextra->roundCount=0;
728 yyextra->defArgsStr=yytext;
739 yyextra->findDefArgContext = CopyLine;
740 BEGIN(FindDefineArgs);
748<CopyLine>{RulesDelim} {
750 yyextra->lexRulesPart = !yyextra->lexRulesPart;
754<CopyLine>{RulesSharp} {
755 if (!yyextra->lexRulesPart) REJECT;
756 if (yyextra->curlyCount) REJECT;
760<RulesPattern>{EscapeRulesChar} {
763<RulesPattern>{RulesCurly} {
766<RulesPattern>{StartDouble} {
768 yyextra->lastContext = YY_START;
771<RulesDouble,RulesRoundDouble>"\\\\" {
774<RulesDouble,RulesRoundDouble>"\\\"" {
779 BEGIN( yyextra->lastContext ) ;
781<RulesRoundDouble>"\"" {
785<RulesDouble,RulesRoundDouble>. {
788<RulesPattern>{StartSquare} {
790 yyextra->lastContext = YY_START;
793<RulesSquare,RulesRoundSquare>{CHARCE} {
796<RulesSquare,RulesRoundSquare>"\\[" |
797<RulesSquare,RulesRoundSquare>"\\]" {
804<RulesRoundSquare>"]" {
808<RulesSquare,RulesRoundSquare>"\\\\" {
811<RulesSquare,RulesRoundSquare>. {
814<RulesPattern>{StartRoundQuest} {
816 yyextra->lastContext = YY_START;
817 BEGIN(RulesRoundQuest);
819<RulesRoundQuest>{nl} {
822<RulesRoundQuest>[^)] {
825<RulesRoundQuest>")" {
827 BEGIN(yyextra->lastContext);
829<RulesPattern>{StartRound} {
830 yyextra->roundCount++;
832 yyextra->lastContext = YY_START;
835<RulesRound>{RulesCurly} {
838<RulesRound>{StartSquare} {
840 BEGIN(RulesRoundSquare);
842<RulesRound>{StartDouble} {
844 BEGIN(RulesRoundDouble);
846<RulesRound>{EscapeRulesChar} {
850 yyextra->roundCount++;
854 yyextra->roundCount--;
856 if (!yyextra->roundCount) BEGIN( yyextra->lastContext ) ;
875<CopyLine,LexCopyLine>{ID} {
878 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
879 yyextra->macroExpansion &&
899<CopyLine,LexCopyLine>"\\"\r?/\n {
902<CopyLine,LexCopyLine>\\. {
905<CopyLine,LexCopyLine>. {
908<CopyLine,LexCopyLine>\n {
915 yyextra->defArgsStr+=
'(';
916 yyextra->roundCount++;
919 yyextra->defArgsStr+=
')';
920 yyextra->roundCount--;
921 if (yyextra->roundCount==0)
925 if (yyextra->findDefArgContext==CopyLine)
928 BEGIN(yyextra->findDefArgContext);
933 yyextra->nospaces=
false;
943<FindDefineArgs>{CHARLIT} {
944 yyextra->defArgsStr+=yytext;
946<FindDefineArgs>{CCS}[*!]? {
947 yyextra->defArgsStr+=yytext;
948 BEGIN(ArgCopyCComment);
950<FindDefineArgs>{CPPC}[/!].*\n/{B}*{CPPC}[/!] {
955 yyextra->defArgsStr+=
DString(
"/**< @brief ")+&yytext[4];
959 yyextra->defArgsStr+=
DString(
"/** @brief ")+&yytext[3];
964 yyextra->defArgsStr+=
DString(
"/**")+&yytext[3];
966 BEGIN(ArgCopyCppComment);
968<FindDefineArgs>{CPPC}[/!].*\n {
971 yyextra->defArgsStr+=
DString(
"/**")+&yytext[3]+
" */";
977 yyextra->defArgsStr+=
DString(
"/**< @brief ")+&yytext[4]+
" */";
981 yyextra->defArgsStr+=
DString(
"/** @brief ")+&yytext[3]+
" */";
985<FindDefineArgs>{CPPC}.*\n {
987 yyextra->defArgsStr+=
DString(
"/*")+&yytext[2]+
" */";
990 yyextra->defArgsStr+=*yytext;
995 yyextra->defArgsStr+=*yytext;
999 yyextra->defArgsStr+=
' ';
1000 yyextra->yyLineNr++;
1003<FindDefineArgs>"@" {
1004 yyextra->defArgsStr+=
"@@";
1007 yyextra->defArgsStr+=*yytext;
1009<ArgCopyCComment>[^*\n]+ {
1010 yyextra->defArgsStr+=yytext;
1012<ArgCopyCComment>{CCE} {
1013 yyextra->defArgsStr+=yytext;
1014 BEGIN(FindDefineArgs);
1016<ArgCopyCComment>\n {
1017 yyextra->defArgsStr+=yytext;
1018 yyextra->yyLineNr++;
1021 yyextra->defArgsStr+=yytext;
1023<ArgCopyCppComment>^{B}*
1024<ArgCopyCppComment>{CPPC}[/!].*\n/{B}*{CPPC}[/!] {
1025 const char *startContent = &yytext[3];
1026 if (startContent[0]==
'<') startContent++;
1027 yyextra->defArgsStr+=startContent;
1029<ArgCopyCppComment>{CPPC}[/!].*\n {
1030 const char *startContent = &yytext[3];
1031 if (startContent[0]==
'<') startContent++;
1032 yyextra->defArgsStr+=
DString(startContent)+
" */";
1033 BEGIN(FindDefineArgs);
1035<ArgCopyCppComment>. {
1037 yyextra->defArgsStr+=
" */";
1038 BEGIN(FindDefineArgs);
1041 yyextra->defArgsStr+=*yytext;
1042 BEGIN(FindDefineArgs);
1046 yyextra->defArgsStr+=*yytext;
1047 BEGIN(FindDefineArgs);
1050<ReadString>{CPPC}|{CCS} {
1051 yyextra->defArgsStr+=yytext;
1053<ReadString>\\/\r?\n {
1056 yyextra->defArgsStr+=yytext;
1059 yyextra->defArgsStr+=*yytext;
1061<Command>("include"|"import"){B}+/{ID} {
1062 yyextra->isImported = yytext[1]==
'm';
1063 if (yyextra->macroExpansion)
1066<Command>("include"|"import"){B}*[<"] {
1067 yyextra->isImported = yytext[1]==
'm';
1069 c[0]=yytext[yyleng-1];c[1]=
'\0';
1073<Command>("cmake")?"define"{B}+ {
1074 yyextra->potentialDefine +=
substitute(yytext,
"cmake",
" ");
1076 yyextra->yyColNr+=(int)yyleng;
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
1079<Command>"cmakedefine01"{B}+ {
1080 yyextra->potentialDefine +=
substitute(yytext,
"cmakedefine01",
" define ");
1082 yyextra->yyColNr+=(int)yyleng;
1083 BEGIN(CmakeDefName01);
1085<Command>"ifdef"/{B}*"(" {
1087 yyextra->guardExpr.clear();
1088 BEGIN(DefinedExpr2);
1090<Command>"ifdef"/{B}+ {
1093 yyextra->guardExpr.clear();
1094 BEGIN(DefinedExpr1);
1096<Command>"ifndef"/{B}*"(" {
1098 yyextra->guardExpr=
"! ";
1099 BEGIN(DefinedExpr2);
1101<Command>"ifndef"/{B}+ {
1103 yyextra->guardExpr=
"! ";
1104 BEGIN(DefinedExpr1);
1106<Command>"if"/[ \t(!] {
1108 yyextra->guardExpr.clear();
1111<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1114 yyextra->guardExpr.clear();
1120 BEGIN(SkipCPPBlock);
1123<Command>"else"/[^a-z_A-Z0-9\x80-\xFF] {
1127 BEGIN(SkipCPPBlock);
1134<Command>"undef"{B}+ {
1137<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1140 yyextra->guardExpr.clear();
1144<Command>"endif"/[^a-z_A-Z0-9\x80-\xFF] {
1148<Command,IgnoreLine>\n {
1151 yyextra->yyLineNr++;
1153<Command>"pragma"{B}+"once" {
1154 yyextra->expectGuard =
false;
1155 if (yyextra->pragmaSet.find(yyextra->fileName.str())!=yyextra->pragmaSet.end())
1162 yyextra->pragmaSet.insert(yyextra->fileName.data());
1167<PragmaOnce><<EOF>> {
1168 yyextra->expectGuard =
false;
1174<IgnoreLine>\\[\r]?\n {
1176 yyextra->yyLineNr++;
1179<Command>. { yyextra->potentialDefine += yytext[0]==
'\t' ?
'\t' :
' ';
1180 yyextra->yyColNr+=(int)yyleng;
1196 yyextra->guardExpr+=
' ';
1197 yyextra->yyLineNr++;
1199<Guard>"defined"/{B}*"(" {
1200 BEGIN(DefinedExpr2);
1202<Guard>"defined"/{B}+ {
1203 BEGIN(DefinedExpr1);
1205<Guard>"true"/{B}|{B}*[\r]?\n { yyextra->guardExpr+=
"1L"; }
1206<Guard>"false"/{B}|{B}*[\r]?\n { yyextra->guardExpr+=
"0L"; }
1207<Guard>"not"/{B} { yyextra->guardExpr+=
'!'; }
1208<Guard>"not_eq"/{B} { yyextra->guardExpr+=
"!="; }
1209<Guard>"and"/{B} { yyextra->guardExpr+=
"&&"; }
1210<Guard>"or"/{B} { yyextra->guardExpr+=
"||"; }
1211<Guard>"bitand"/{B} { yyextra->guardExpr+=
"&"; }
1212<Guard>"bitor"/{B} { yyextra->guardExpr+=
"|"; }
1213<Guard>"xor"/{B} { yyextra->guardExpr+=
"^"; }
1214<Guard>"compl"/{B} { yyextra->guardExpr+=
"~"; }
1215<Guard>{ID} { yyextra->guardExpr+=yytext; }
1216<Guard>"@" { yyextra->guardExpr+=
"@@"; }
1217<Guard>. { yyextra->guardExpr+=*yytext; }
1231 BEGIN(SkipCPPBlock);
1234<DefinedExpr1,DefinedExpr2>\\\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1236 if (
isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1237 yyextra->guardExpr+=
" 1L ";
1239 yyextra->guardExpr+=
" 0L ";
1240 yyextra->lastGuardName=yytext;
1244 if (
isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1245 yyextra->guardExpr+=
" 1L ";
1247 yyextra->guardExpr+=
" 0L ";
1248 yyextra->lastGuardName=yytext;
1250<DefinedExpr1,DefinedExpr2>\n {
1251 yyextra->yyLineNr++;
1253 BEGIN(SkipCPPBlock);
1258<DefinedExpr1,DefinedExpr2>.
1259<SkipCPPBlock>^{B}*"#" { BEGIN(SkipCommand); }
1260<SkipCPPBlock>^{Bopt}/[^#] { BEGIN(SkipLine); }
1261<SkipCPPBlock>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1263<SkipCommand>"if"(("n")?("def"))?/[ \t(!] {
1268<SkipCommand>"else" {
1277<SkipCommand>("elif"|"else"{B}*"if")/[ \t(!] {
1278 if (yyextra->ifcount==0)
1282 yyextra->guardExpr.clear();
1283 yyextra->lastGuardName.clear();
1288 BEGIN(SkipCPPBlock);
1292<SkipCommand>"endif" {
1293 yyextra->expectGuard =
false;
1295 if (--yyextra->ifcount<0)
1303 yyextra->yyLineNr++;
1304 BEGIN(SkipCPPBlock);
1311<SkipLine>{CHARLIT} { }
1316<SkipString>{CPPC}/[^\n]* {
1318<SkipLine,SkipCommand,SkipCPPBlock>{CPPC}[^\n]* {
1319 yyextra->lastCPPContext=YY_START;
1320 BEGIN(RemoveCPPComment);
1322<SkipString>{CCS}/[^\n]* {
1324<SkipLine,SkipCommand,SkipCPPBlock>{CCS}/[^\n]* {
1325 yyextra->lastCContext=YY_START;
1326 BEGIN(RemoveCComment);
1330 yyextra->yyLineNr++;
1331 BEGIN(SkipCPPBlock);
1333<SkipString>[^"\\\n]+ { }
1339<IncludeID>{ID}{Bopt}/"(" {
1340 yyextra->nospaces=
true;
1341 yyextra->roundCount=0;
1342 yyextra->defArgsStr=yytext;
1343 yyextra->findDefArgContext = IncludeID;
1344 BEGIN(FindDefineArgs);
1347 yyextra->nospaces=
true;
1351<Include>[^\">\n]+[\">] {
1352 yyextra->incName+=yytext;
1353 if (yyextra->isImported)
1363<EndImport>{ENDIMPORTopt}/\n {
1367<EndImport>\\[\r]?"\n" {
1369 yyextra->yyLineNr++;
1373<DefName>{ID}/("\\\n")*"(" {
1375 yyextra->argMap.clear();
1376 yyextra->defArgs = 0;
1377 yyextra->defArgsStr.clear();
1378 yyextra->defText.clear();
1379 yyextra->defLitText.clear();
1380 yyextra->defName = yytext;
1381 yyextra->defVarArgs =
false;
1382 yyextra->defExtraSpacing.clear();
1383 yyextra->defContinue =
false;
1386<DefName>{ID}{B}+"1"/[ \r\t\n] {
1388 yyextra->argMap.clear();
1389 yyextra->defArgs = -1;
1390 yyextra->defArgsStr.clear();
1392 yyextra->defVarArgs =
false;
1395 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1397 DString def = yyextra->potentialDefine +
1400 outputSpaces(yyscanner,yytext+yyextra->defName.length());
1401 yyextra->quoteArg=
false;
1402 yyextra->insideComment=
false;
1403 yyextra->lastGuardName.clear();
1404 yyextra->defText=
"1";
1405 yyextra->defLitText=
"1";
1411 yyextra->defText.clear();
1412 yyextra->defLitText.clear();
1415 yyextra->expectGuard=
false;
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
DString left(size_t len) const
1417<DefName,CmakeDefName01>{ID}/{B}*"\n" {
1418 yyextra->argMap.clear();
1419 yyextra->defArgs = -1;
1420 yyextra->defName = yytext;
1421 yyextra->defArgsStr.clear();
1422 yyextra->defText.clear();
1423 yyextra->defLitText.clear();
1424 yyextra->defVarArgs =
false;
1427 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1429 DString def = yyextra->potentialDefine + yyextra->defName;
1431 yyextra->quoteArg=
false;
1432 yyextra->insideComment=
false;
1433 if (YY_START == CmakeDefName01) yyextra->defText =
"0";
1434 else if (yyextra->insideCS) yyextra->defText=
"1";
1440 yyextra->guardName = yytext;
1441 yyextra->lastGuardName.clear();
1444 yyextra->expectGuard=
false;
1448 yyextra->argMap.clear();
1449 yyextra->defArgs = -1;
1450 yyextra->defArgsStr.clear();
1451 yyextra->defText.clear();
1452 yyextra->defLitText.clear();
1453 yyextra->defName = yytext;
1454 yyextra->defVarArgs =
false;
1455 DString def = yyextra->potentialDefine +
1457 yyextra->defArgsStr ;
1459 yyextra->quoteArg=
false;
1460 yyextra->insideComment=
false;
1464 yyextra->defExtraSpacing+=
"\n";
1465 yyextra->defContinue =
true;
1466 yyextra->yyLineNr++;
1468<DefineArg>{B}* { yyextra->defExtraSpacing+=yytext; }
1469<DefineArg>","{B}* { yyextra->defArgsStr+=yytext; }
1470<DefineArg>"("{B}* { yyextra->defArgsStr+=yytext; }
1471<DefineArg>{B}*")"{B}* {
1473 yyextra->defArgsStr+=yytext;
1474 DString def = yyextra->potentialDefine +
1476 yyextra->defArgsStr +
1477 yyextra->defExtraSpacing ;
1479 yyextra->quoteArg=
false;
1480 yyextra->insideComment=
false;
1484 yyextra->defVarArgs =
true;
1485 yyextra->defArgsStr+=yytext;
1486 yyextra->argMap.emplace(std::string(
"__VA_ARGS__"),yyextra->defArgs);
1489<DefineArg>{ID}{B}*("..."?) {
1492 yyextra->defVarArgs = yytext[yyleng-1]==
'.';
1493 if (yyextra->defVarArgs)
1498 yyextra->defArgsStr+=yytext;
1499 yyextra->argMap.emplace(
toStdString(argName),yyextra->defArgs);
size_t length() const
Returns the length of the string, not counting the 0-terminator.
std::string toStdString(const DString &s)
1515<DefineText>{CCS}[^!*] {
1516 yyextra->defLitText+=
' ';
1518 yyextra->lastCContext=YY_START;
1519 yyextra->commentCount=1;
1520 BEGIN(SkipCComment);
1522<DefineText>{CCS}[!*] {
1523 yyextra->defText+=yytext;
1524 yyextra->defLitText+=yytext;
1525 yyextra->lastCContext=YY_START;
1526 yyextra->commentCount=1;
1527 BEGIN(CopyCComment);
1529<DefineText>{CPPC}[!/]? {
1531 yyextra->lastCPPContext=YY_START;
1532 yyextra->defLitText+=
' ';
1533 BEGIN(SkipCPPComment);
1535<SkipCComment>[/]?{CCE} {
1536 if (yytext[0]==
'/')
outputChar(yyscanner,
'/');
1538 if (--yyextra->commentCount<=0)
1540 if (yyextra->lastCContext==Start)
1544 YY_CURRENT_BUFFER->yy_at_bol=1;
1546 BEGIN(yyextra->lastCContext);
1549<SkipCComment>{CPPC}("/")* {
1552<SkipCComment>{CCS} {
1556<SkipCond>{CMD}{CMD} { }
1557<SkipCond>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1559 if (!markdownSupport || !yyextra->isSpecialComment)
1565 yyextra->fenceChar=
'~';
1567 BEGIN(SkipCondVerbatim);
1570<SkipCond>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1572 if (!markdownSupport || !yyextra->isSpecialComment)
1578 yyextra->fenceChar=
'`';
1580 BEGIN(SkipCondVerbatim);
1583<SkipCComment>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1585 if (!markdownSupport || !yyextra->isSpecialComment)
1592 yyextra->fenceChar=
'~';
1594 BEGIN(SkipVerbatim);
1597<SkipCComment>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1599 if (!markdownSupport || !yyextra->isSpecialComment)
1606 yyextra->fenceChar=
'`';
1608 BEGIN(SkipVerbatim);
1611<SkipCComment>{CMD}{VERBATIM_LINE} |
1612<SkipCComment>{CMD}{LITERAL_BLOCK} {
1616<SkipCComment>{VERBATIM_LINE}.*/\n {
1619<SkipCComment>{LITERAL_BLOCK} {
1622 if (yyextra->isSpecialComment)
1625 BEGIN(SkipVerbatim);
1628<SkipCond>{CMD}{CMD}"cond"[ \t]+ {}
1629<SkipCond>{CMD}"cond"/\n |
1630<SkipCond>{CMD}"cond"[ \t]+ {
1634<SkipCComment>"{"[ \t]*"@code"/[ \t\n] {
1636 yyextra->javaBlock=1;
1637 BEGIN(JavaDocVerbatimCode);
1639<SkipCComment>"{"[ \t]*"@literal"/[ \t\n] {
1641 yyextra->javaBlock=1;
1642 BEGIN(JavaDocVerbatimCode);
1644<SkipCComment,SkipCPPComment>{CMD}{CMD}"cond"[ \t\n]+ {
1647<SkipCPPComment>{CMD}"cond"[ \t]+ {
1648 yyextra->ccomment=
true;
1649 yyextra->condCtx=YY_START;
1652<SkipCComment>{CMD}"cond"[ \t]+ {
1653 yyextra->ccomment=
false;
1654 yyextra->condCtx=YY_START;
1657<CondLineC,CondLineCpp>([!()&| \ta-z_A-Z0-9\x80-\xFF.\-]|{CMD}"doxyconfig")+ {
1661 if (YY_START==CondLineC)
1665 yyextra->ccomment=
true;
1669 yyextra->ccomment=
false;
1675 BEGIN(yyextra->condCtx);
1678CondLine>{B}*{CMD}doxyconfig{B}+{DOXYCFG} {
1681<CondLineC,CondLineCpp>. {
1686 if (YY_START==CondLineC)
1690 yyextra->ccomment=
true;
1694 yyextra->ccomment=
false;
1700 BEGIN(yyextra->condCtx);
1703<SkipCComment,SkipCPPComment>{CMD}"cond"{WSopt}/\n {
1704 if (YY_START==SkipCComment)
1706 yyextra->ccomment=
true;
1712 yyextra->ccomment=
false;
1714 yyextra->condCtx=YY_START;
1715 yyextra->condGuardCount=0;
1719<SkipCond>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1720<SkipCond>{VERBATIM_LINE}.*/\n { }
1721<SkipCond>{LITERAL_BLOCK} {
1723 yyextra->yyLineNr+=numNLs;
1724 for (
int i = 0; i < numNLs; i++)
outputChar(yyscanner,
'\n');
1726 BEGIN(SkipCondVerbatim);
1730<SkipCond>"#if"("def")? { yyextra->condGuardCount++; }
1731<SkipCond>"#endif" { yyextra->condGuardCount--; }
1732<SkipCond>[^\/\!*\\@\n#]+ { }
1733<SkipCond>{CPPC}[/!] { yyextra->ccomment=
false; }
1734<SkipCond>{CCS}[*!] { yyextra->ccomment=
true; }
1735<SkipCond,SkipCComment,SkipCPPComment>{CMD}{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1741<SkipCond>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1742 bool oldSkip = yyextra->skip;
1744 if (oldSkip && !yyextra->skip)
1746 if (yyextra->ccomment)
1750 BEGIN(yyextra->condCtx);
1753<SkipCComment,SkipCPPComment>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1754 bool oldSkip = yyextra->skip;
1756 if (oldSkip && !yyextra->skip)
1758 BEGIN(yyextra->condCtx);
1761<SkipCondVerbatim>{LITERAL_BLOCK_END} {
1762 if (yytext[1]==
'f' && yyextra->blockName==&yytext[2])
1766 else if (&yytext[4]==yyextra->blockName)
1771<SkipVerbatim>{LITERAL_BLOCK_END} {
1773 if (yytext[1]==
'f' && yyextra->blockName==&yytext[2])
1775 BEGIN(SkipCComment);
1777 else if (&yytext[4]==yyextra->blockName)
1779 BEGIN(SkipCComment);
1782<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1783 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'~')
1788<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1789 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'`')
1794<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1796 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'~')
1798 BEGIN(SkipCComment);
1801<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1803 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'`')
1805 BEGIN(SkipCComment);
1808<SkipCondVerbatim>{CCE}|{CCS} { }
1809<SkipVerbatim>{CCE}|{CCS} {
1812<JavaDocVerbatimCode>"{" {
1813 if (yyextra->javaBlock==0)
1819 yyextra->javaBlock++;
1823<JavaDocVerbatimCode>"}" {
1824 if (yyextra->javaBlock==0)
1830 yyextra->javaBlock--;
1831 if (yyextra->javaBlock==0)
1834 BEGIN(SkipCComment);
1842<JavaDocVerbatimCode>\n {
1845<JavaDocVerbatimCode>. {
1848<SkipCondVerbatim>[^{*\\@\x06~`\n\/]+ { }
1849<SkipCComment,SkipVerbatim>[^{*\\@\x06~`\n\/]+ {
1852<SkipCComment,SkipVerbatim,SkipCondVerbatim>\n {
1853 yyextra->yyLineNr++;
1856<SkipCondVerbatim>. { }
1857<SkipCComment,SkipVerbatim>. {
1860<CopyCComment>[^*a-z_A-Z\x80-\xFF\n]*[^*a-z_A-Z\x80-\xFF\\\n] {
1861 yyextra->defLitText+=yytext;
1862 yyextra->defText+=
escapeAt(yytext);
1864<CopyCComment>\\[\r]?\n {
1865 yyextra->defLitText+=yytext;
1866 yyextra->defText+=
" ";
1867 yyextra->yyLineNr++;
1868 yyextra->yyMLines++;
1870<CopyCComment>{CCE} {
1871 yyextra->defLitText+=yytext;
1872 yyextra->defText+=yytext;
1873 BEGIN(yyextra->lastCContext);
1876 yyextra->yyLineNr++;
1877 yyextra->defLitText+=yytext;
1878 yyextra->defText+=
' ';
1880<RemoveCComment>{CCE}{B}*"#" {
1881 if (yyextra->lastCContext==SkipCPPBlock)
1890<RemoveCComment>{CCE} { BEGIN(yyextra->lastCContext); }
1891<RemoveCComment>{CPPC}
1892<RemoveCComment>{CCS}
1893<RemoveCComment>[^*\x06\n]+
1894<RemoveCComment>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1896<SkipCPPComment>[^\n\/\\@]+ {
1899<SkipCPPComment,RemoveCPPComment>\n {
1901 BEGIN(yyextra->lastCPPContext);
1903<SkipCPPComment>{CCS} {
1906<SkipCPPComment>{CPPC} {
1909<SkipCPPComment>[^\x06\@\\\n]+ {
1915<RemoveCPPComment>{CCS}
1916<RemoveCPPComment>{CPPC}
1917<RemoveCPPComment>[^\x06\n]+
1919<DefineText>"__VA_OPT__("{B}*"##" {
1920 warn(yyextra->fileName,yyextra->yyLineNr,
1921 "'##' may not appear at the beginning of a __VA_OPT__()",
1922 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1923 yyextra->defText+=
"__VA_OPT__(";
1924 yyextra->defLitText+=
"__VA_OPT__(";
#define warn(file, line, fmt,...)
1926<DefineText>"#"/"__VA_OPT__" {
1927 yyextra->defText+=yytext;
1928 yyextra->defLitText+=yytext;
1930<DefineText>"#"/{IDSTART} {
1932 yyextra->quoteArg=
true;
1933 yyextra->idStart=
true;
1934 yyextra->defLitText+=yytext;
1936<DefineText,CopyCComment>{ID} {
1937 yyextra->defLitText+=yytext;
1938 if (YY_START == DefineText)
outputSpaces(yyscanner,yytext);
1939 if (yyextra->quoteArg)
1941 yyextra->defText+=
"\"";
1943 if (yyextra->defArgs>0)
1945 auto it = yyextra->argMap.find(yytext);
1946 if (it!=yyextra->argMap.end())
1949 yyextra->defText+=
'@';
1954 if (yyextra->idStart)
1956 warn(yyextra->fileName,yyextra->yyLineNr,
1957 "'#' is not followed by a macro parameter '{}': '{}'",
1958 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1960 yyextra->defText+=yytext;
1965 yyextra->defText+=yytext;
1967 if (yyextra->quoteArg)
1969 yyextra->defText+=
"\"";
1971 yyextra->quoteArg=
false;
1972 yyextra->idStart=
false;
DString & setNum(short n)
1975 yyextra->defLitText+=yytext;
1976 yyextra->defText+=yytext;
1978<DefineText>\\[\r]?\n {
1979 yyextra->defLitText+=yytext;
1982 yyextra->defText +=
' ';
1983 yyextra->yyLineNr++;
1984 yyextra->yyMLines++;
1988 yyextra->defText = yyextra->defText.stripWhiteSpace();
1989 if (yyextra->defText.startsWith(
"##"))
1991 warn(yyextra->fileName,yyextra->yyLineNr,
1992 "'##' cannot occur at the beginning of a macro definition '{}': '{}'",
1993 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1995 else if (yyextra->defText.endsWith(
"##"))
1997 warn(yyextra->fileName,yyextra->yyLineNr,
1998 "'##' cannot occur at the end of a macro definition '{}': '{}'",
1999 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
2001 else if (yyextra->defText.endsWith(
"#"))
2003 warn(yyextra->fileName,yyextra->yyLineNr,
2004 "expected formal parameter after # in macro definition '{}': '{}'",
2005 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
2007 if (!comment.
empty())
2010 yyextra->defLitText=yyextra->defLitText.left(yyextra->defLitText.length()-comment.
length()-1);
2013 yyextra->defLitText+=yytext;
2016 if (yyextra->includeStack.empty() || yyextra->curlyCount>0)
2020 def=
isDefined(yyscanner,yyextra->defName);
2034 def->
name = yyextra->defName;
2036 def->
nargs = yyextra->defArgs;
2038 def->
lineNr = yyextra->yyLineNr-yyextra->yyMLines;
2043 if (def->
fileName != yyextra->fileName && !yyextra->expandOnlyPredef)
addDefine(yyscanner);
2047 yyextra->argMap.clear();
2048 yyextra->yyLineNr++;
2050 yyextra->lastGuardName.clear();
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
2054 yyextra->defText +=
' ';
2055 yyextra->defLitText+=yytext;
2058 yyextra->defText +=
"##";
2059 yyextra->defLitText+=yytext;
2062 yyextra->defText +=
"@@";
2063 yyextra->defLitText+=yytext;
2067 yyextra->defText += *yytext;
2068 yyextra->defLitText+=yytext;
2069 if (!yyextra->insideComment)
2071 BEGIN(SkipDoubleQuote);
2074<DefineText>{NUMBER} {
2076 yyextra->defText += yytext;
2077 yyextra->defLitText+=yytext;
2081 yyextra->defText += *yytext;
2082 yyextra->defLitText+=yytext;
2083 if (!yyextra->insideComment)
2085 BEGIN(SkipSingleQuote);
2088<SkipDoubleQuote>{CPPC}[/]? {
outputSpaces(yyscanner,yytext);
2089 yyextra->defText += yytext;
2090 yyextra->defLitText+=yytext;
2092<SkipDoubleQuote>{CCS}[*]? {
outputSpaces(yyscanner,yytext);
2093 yyextra->defText += yytext;
2094 yyextra->defLitText+=yytext;
2096<SkipDoubleQuote>\" {
2098 yyextra->defText += *yytext;
2099 yyextra->defLitText+=yytext;
2102<SkipSingleQuote,SkipDoubleQuote>\\. {
2104 yyextra->defText += yytext;
2105 yyextra->defLitText+=yytext;
2107<SkipSingleQuote>\' {
2109 yyextra->defText += *yytext;
2110 yyextra->defLitText+=yytext;
2113<SkipDoubleQuote,SkipSingleQuote>. {
outputSpace(yyscanner,yytext[0]);
2114 yyextra->defText += *yytext;
2115 yyextra->defLitText += *yytext;
2118 yyextra->defText += *yytext;
2119 yyextra->defLitText += *yytext;
2122 TRACE(
"End of include file");
2124 if (yyextra->includeStack.empty())
2126 TRACE(
"Terminating scanner");
2131 if (!yyextra->levelGuard.empty())
2133 if (yyextra->condGuardErrorLine!=0)
2135 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,
"{}",yyextra->condGuardErrorMessage);
2139 warn(yyextra->fileName,yyextra->yyLineNr,
"More #endif's than #if's found.");
2142 DString toFileName = yyextra->fileName;
2143 const std::unique_ptr<FileState> &fs=yyextra->includeStack.
back();
2145 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
2146 yy_switch_to_buffer( fs->bufState, yyscanner );
2147 yy_delete_buffer( oldBuf, yyscanner );
2148 yyextra->yyLineNr = fs->lineNr;
2150 yyextra->inputBuf = fs->oldFileBuf;
2151 yyextra->inputBufPos = fs->oldFileBufPos;
2152 yyextra->curlyCount = fs->curlyCount;
2153 yyextra->levelGuard = fs->levelGuard;
2155 TRACE(
"switching to {}",yyextra->fileName);
2160 lineStr.sprintf(
"# %d \"%s\" 2",yyextra->yyLineNr,
qPrint(yyextra->fileName));
2163 yyextra->includeStack.pop_back();
2186 for (
const auto &kv : yyextra->localDefines)
2188 auto pair = yyextra->contextDefines.insert(kv);
2191 yyextra->contextDefines.erase(pair.first);
2192 yyextra->contextDefines.insert(kv);
2195 yyextra->localDefines.clear();
char & back()
Returns a reference to the last character.
const std::string & str() const
static bool isFlagSet(const DebugMask mask)
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
const char * qPrint(const char *s)
2200 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || YY_START==IDLquote || YY_START == PragmaOnce)
2207 yyextra->lastCContext=YY_START;
2208 yyextra->commentCount=1;
2211 yyextra->isSpecialComment =
true;
2212 yyextra->lastGuardName.clear();
2216 yyextra->isSpecialComment =
false;
2218 BEGIN(SkipCComment);
2222 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond ||
getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran || YY_START==IDLquote || YY_START == PragmaOnce)
2226 else if (YY_START==RulesRoundDouble)
2233 yyextra->lastCPPContext=YY_START;
2236 yyextra->isSpecialComment =
true;
2237 yyextra->lastGuardName.clear();
2241 yyextra->isSpecialComment =
false;
2243 BEGIN(SkipCPPComment);
2248 yyextra->yyLineNr++;
2251 yyextra->expectGuard =
false;
2261 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2262 int bytesInBuf =
static_cast<int>(state->inputBuf->size())-state->inputBufPos;
2263 int bytesToCopy = std::min(max_size,bytesInBuf);
2264 memcpy(buf,state->inputBuf->data()+state->inputBufPos,bytesToCopy);
2265 state->inputBufPos+=bytesToCopy;
2271 yy_size_t fenceSize = 0;
2272 for (
size_t i = 0; i < leng; i++)
2274 if (txt[i] !=
' ' && txt[i] !=
'*' && txt[i] !=
'\t')
break;
2277 return leng-fenceSize;
2282 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2287 if (state->yyFileDef==
nullptr)
2293 if (state->yyFileDef && state->yyFileDef->isReference()) state->yyFileDef=
nullptr;
2297 state->isFixedFormFtn =
false;
2298 if (state->insideFtn)
2304 state->isSource = section.isHeader() || section.isSource();
2309 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2310 state->levelGuard.push(
false);
2316 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2318 if (!state->levelGuard.empty())
2320 state->levelGuard.pop();
2324 if (state->condGuardErrorLine!=0)
2326 warn(state->condGuardErrorFileName,state->condGuardErrorLine,
"{}",state->condGuardErrorMessage);
2330 warn(state->fileName,state->yyLineNr,
"More #endif's than #if's found.");
2337 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2338 if (state->levelGuard.empty())
2340 warn(state->fileName,state->yyLineNr,
"Found an #else without a preceding #if.");
2345 return state->levelGuard.top();
2351 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2352 state->levelGuard.top()=value;
2358 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2359 alreadyProcessed =
false;
2360 std::unique_ptr<FileState> fs;
2371 if (state->curlyCount==0)
2376 alreadyProcessed =
true;
2383 alreadyProcessed = std::any_of(
2384 state->includeStack.begin(),
2385 state->includeStack.end(),
2386 [absName](
const std::unique_ptr<FileState> &lfs)
2387 { return lfs->fileName==absName; }
2390 if (alreadyProcessed)
2397 fs = std::make_unique<FileState>();
2406 fs->oldFileBuf = state->inputBuf;
2407 fs->oldFileBufPos = state->inputBufPos;
2415 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2426 else if (alreadyProcessed)
2431 if (localInclude && !state->fileName.empty())
2433 FileInfo fi(state->fileName.str());
2444 else if (alreadyProcessed)
2450 if (state->pathList.empty())
2454 for (
auto path : state->pathList)
2456 DString absName = path+
"/"+fileName;
2466 else if (alreadyProcessed)
2489 if (s.
empty())
return "";
2499 if (i>=0 && s[i]==
'*')
2502 while (i>0 && !(s[i-1]==
'/' && s[i]==
'*')) i--;
2509 return ((s[i+1]==
'*' || s[i+1]==
'!') && s[i+2]==
'<') ? &s[i-1] :
"";
2540 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2542 bool previous = state->boundedExpansion;
2543 state->boundedExpansion =
true;
2545 state->boundedExpansion = previous;
2552 bool inString=
false;
2557 if (!inString && !inChar)
2559 while (i<s.
length() && !inString && !inChar)
2580 while (i<s.
length() && inChar)
2601 while (i<s.
length() && inString)
2628 if (expr.
empty())
return;
2630 std::string e = expr.
str();
2631 static const reg::Ex r(R
"(\s*##\s*)");
2640 const auto &match = *it;
2641 size_t n = match.position();
2642 size_t l = match.length();
2645 bool leftEmpty = n>=2 && e.compare(n-2,2,
"@E")==0 && (n<3 || e[n-3]!=
'@');
2646 bool rightEmpty = e.compare(n+l,2,
"@E")==0;
2647 if (leftEmpty && rightEmpty)
2655 if (e.compare(n+l,2,
"@-")==0) e.erase(n+l,2);
2656 e.replace(n-2,l+2,
" ");
2662 int k=
static_cast<int>(n)-1;
2663 while (k>=0 &&
isId(e[k])) k--;
2664 if (k>0 && e[k]==
'-' && e[k-1]==
'@')
2669 size_t next=e.find_first_not_of(
" \t\r\n",n+l+2);
2670 if (next!=std::string::npos && e.compare(next,2,
"##")==0)
2678 e.replace(n,l+2,
" ");
2683 if (n+l+1<e.length() && e[
static_cast<int>(n+l)]==
'@' && expr[
static_cast<int>(n+l+1)]==
'-')
2690 e=e.substr(0,n)+e.substr(n+l);
2691 int k=
static_cast<int>(n)-1;
2692 while (k>=0 &&
isId(e[k])) k--;
2693 if (k>0 && e[k]==
'-' && e[k-1]==
'@')
2696 e=e.substr(0,k-1)+e.substr(k+1);
2714 struct yyguts_t * yyg = (
struct yyguts_t*)yyscanner;
2722 while ((cc=
getNextChar(yyscanner,expr,rest,pos))!=EOF && cc!=0)
2741 while ((cc=
getNextChar(yyscanner,expr,rest,pos))!=EOF && cc!=0)
2754 int &cc, uint32_t &j,
int &len)
2756 bool changed =
false;
2761 while ((cc=
getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc!=
'\n' && isspace(cc))
2769 int prevChar =
'\0';
2771 if ((cc=
getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc ==
'*')
2773 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2775 if (cc ==
'/' && prevChar ==
'*')
break;
2778 if (cc != EOF) changed =
true;
2787 if (rest) remaining+=*rest;
2789 std::string readAhead;
2790 auto next = [&]() ->
int
2792 bool fromStream=cursor>=remaining.
length() && !preYYget_extra(yyscanner)->boundedExpansion;
2793 int c=
getNextChar(yyscanner,remaining,
nullptr,cursor);
2794 if (fromStream && c!=EOF && c!=0) readAhead+=
static_cast<char>(c);
2800 while (c!=EOF && c!=0 && c!=
'\n' && isspace(
static_cast<unsigned char>(c))) c=next();
2805 while ((c=next())!=EOF && c!=0 && !(previous==
'*' && c==
'/')) previous=c;
2806 if (c==EOF || c==0)
break;
2810 for (
auto it=readAhead.rbegin();it!=readAhead.rend();++it)
returnCharToStream(yyscanner,*it);
2821 size_t vl = vaStr.
length();
2824 bool hasHash = vo>0 && vaStr.
at(vo-1)==
'#';
2827 result+=vaStr.
mid(vp,vo-vp-1);
2832 result+=vaStr.
mid(vp,vo-vp);
2836 while (bc>0 && ve<vl)
2838 if (vaStr[ve]==
')') bc--;
2839 else if (vaStr[ve]==
'(') bc++;
2843 if (bc==0 && hasOptionalArgs)
2855 result+=vaStr.
mid(vp);
2887 struct MacroArgument
2892 std::map<std::string,MacroArgument> argTable;
2896 size_t expandedPrefixLength=0;
2898 int argCountNonEmpty=0;
2904 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2912 while (!done && (argCount<def->nargs || def->
varArgs) &&
2913 ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2922 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2926 if (c==
'\'' || c==
'\"')
2959 else if (c==
')' || c==
',')
2963 rawArg+=arg.
mid(expandedPrefixLength);
2968 expandedPrefixLength=arg.
length();
2972 rawArg+=arg.
mid(expandedPrefixLength);
2978 argKey.
sprintf(
"@%d",argCount++);
2979 if (c==
',' || !expandedArg.
empty()) argCountNonEmpty++;
2981 argTable.emplace(
toStdString(argKey), MacroArgument{rawArg,expandedArg});
2984 expandedPrefixLength=0;
2995 while (!found && (cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3002 if ((cc=
getNextChar(yyscanner,expr,rest,j))==EOF || cc==0)
break;
3012 while (!found && (cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3019 if ((cc=
getNextChar(yyscanner,expr,rest,j))==EOF || cc==0)
break;
3027 char prevChar =
'\0';
3031 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3035 if (c ==
'/' && prevChar ==
'*')
break;
3048 if (argCount==def->
nargs ||
3059 bool inString=
false;
3069 else if (d.
at(k+1)==
'-')
3078 int l=
static_cast<int>(k)-1;
3080 if (l>=0 && d.
at(l)==
'"') l--;
3081 while (l>=0 && d.
at(l)==
' ') l--;
3082 if (l>0 && d.
at(l)==
'#' && d.
at(l-1)==
'#') hash=
true;
3085 while (k<d.
length() && d.
at(k)>=
'0' && d.
at(k)<=
'9') key+=d.
at(k++);
3089 l=
static_cast<int>(k);
3090 if (l<(
int)d.
length() && d.
at(l)==
'"') l++;
3091 while (l<(
int)d.
length() && d.
at(l)==
' ') l++;
3092 if (l<(
int)d.
length()-1 && d.
at(l)==
'#' && d.
at(l+1)==
'#') hash=
true;
3095 auto it = argTable.find(key.
str());
3096 if (it!=argTable.end())
3098 DString substArg = hash || inString ? it->second.raw : it->second.expanded;
3101 if (!hash && !inString)
3115 if (hash && substArg.
empty())
3126 if (!inString && d.
at(k)==
'\"')
3130 else if (k>2 && inString && d.
at(k)==
'\"' && (d.
at(k-1)!=
'\\' || d.
at(k-2)==
'\\'))
3154 while (p<(
int)expr.
length())
3156 char c=expr.
at(p++);
3161 else if (isalpha(c) || c==
'_')
3171 if (p<(
int)expr.
length()) c=expr.
at(p);
3172 while (p<(
int)expr.
length() && (c!=
'"' || (pc==
'\\' && ppc!=
'\\')))
3180 if (p<(
int)expr.
length()) ++p;
3186 if (p<(
int)expr.
length())
3192 while (p<(
int)expr.
length() && !(pc==
'*' && c==
'/'))
3205#define MAX_EXPANSION_DEPTH 50
3209 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3210 if (!state->nospaces)
3213 char ccPrev = pos==0 || (int)expr.
length()<pos ? state->prevChar : expr.
at(pos-1);
3214 DString leftSpace = ccPrev!=
':' && ccPrev!=
' ' ?
" " :
"";
3217 if (restExpr.
empty())
3219 uint32_t j=(uint32_t)resultExpr.
length();
3220 while ((ccNext=
getNextChar(yyscanner,resultExpr,
nullptr,j))!=EOF && ccNext==
' ') { }
3221 if (ccNext != EOF)
unputChar(yyscanner,resultExpr,
nullptr,j,(
char)ccNext);
3225 ccNext=restExpr.
at(0);
3228 DString rightSpace = ccNext!=
':' && ccNext!=
' ' ?
" " :
"";
3231 resultExpr=leftSpace+resultExpr+rightSpace;
3241 struct yyguts_t * yyg = (
struct yyguts_t*)yyscanner;
3242 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3249 if (state->expanded.find(expr.
str())!=state->expanded.end() &&
3257 state->expanded.insert(expr.
str());
3261 bool definedTest=
false;
3262 int i=pos, l=0, p=0, len=0;
3267 bool replaced=
false;
3269 macroName=expr.
mid(p,l);
3274 expr=expr.
left(p)+resultExpr+restExpr;
3276 else if (p<2 || !(expr.
at(p-2)==
'@' && expr.
at(p-1)==
'-'))
3278 if (state->expandedDict.find(macroName.
str())==state->expandedDict.end())
3280 bool expanded=
false;
3284 if (yyextra->expandOnlyPredef && def && !def->
isPredefined) def=
nullptr;
3285 if (macroName==
"defined")
3290 else if (definedTest)
3292 if (def) expMacro =
" 1 ";
else expMacro =
" 0 ";
3297 else if (def && def->
nargs==-1)
3306 else if (def && def->
nargs>=0)
3317 resultExpr=expMacro;
3324 state->expandedDict.emplace(
toStdString(macroName),def);
3326 state->expandedDict.erase(
toStdString(macroName));
3335 expr=expr.
left(p)+resultExpr+restExpr;
3337 i=p+
static_cast<int>(resultExpr.
length());
3342 expr=expr.
left(p)+
"@-"+expr.
mid(p);
3354 const Define *def=state->expandedDict.find(macroName.
str())->second;
3362 expr=expr.
left(p)+
"@-"+expr.
mid(p);
3399 if (inputStr==
nullptr)
return inputStr;
3400 char term = *inputStr;
3401 if (
term!=
'\'' &&
term!=
'"')
return inputStr;
3406 while ((c=*inputStr))
3435 static const std::vector<std::string> signs = {
"signed",
"unsigned" };
3436 struct TypeInfo { std::string name;
size_t size; };
3437 static const std::vector<TypeInfo> types = {
3438 {
"short int",
sizeof(
short int) },
3439 {
"long long int",
sizeof(
long long int) },
3440 {
"long int",
sizeof(
long int) },
3441 {
"long long",
sizeof(
long long) },
3442 {
"long double",
sizeof(
long double) },
3443 {
"int",
sizeof(int) },
3444 {
"short",
sizeof(short) },
3445 {
"bool",
sizeof(bool) },
3446 {
"long",
sizeof(long) },
3447 {
"char",
sizeof(char) },
3448 {
"float",
sizeof(float) },
3449 {
"double",
sizeof(double) },
3455 auto process_cast_or_sizeof = [](
const char *p) -> std::pair<const char *,size_t>
3458 while (*q==
' ' || *q==
'\t') q++;
3460 size_t size =
sizeof(int);
3461 for (
const auto &sgn : signs)
3463 if (
dstrncmp(q,sgn.c_str(),sgn.length())==0) { q+=sgn.length(); found=
true; }
3465 if (!found || *q==
' ' || *q==
'\t' || *q==
')')
3467 while (*q==
' ' || *q==
'\t') q++;
3468 for (
const auto &t : types)
3470 if (
dstrncmp(q,t.name.c_str(),t.name.length())==0)
3472 q += t.name.length();
3477 while (*q==
' ' || *q==
'\t') q++;
3478 if (*q==
')')
return std::make_pair(++q,size);
3480 return std::make_pair(
nullptr,0);
3484 if (s.
empty())
return s;
3485 const char *p=s.
data();
3495 const char *q = process_cast_or_sizeof(p+1).first;
3505 const char *q = p+6;
3506 while (*q==
' ' || *q==
'\t') q++;
3509 auto r = process_cast_or_sizeof(q+1);
3526 else if (*(p+1)==
'E')
3532 else if (isdigit(c))
3542 else if (c==
'd' && !inNum)
3553 while ((c=*p) &&
isId(c)) p++;
3556 else if ((isalpha(c) || c==
'_') && !inNum)
3560 while ((c=*p) &&
isId(c)) p++;
3561 while ((c=*p) && isspace((uint8_t)c)) p++;
3568 if (c==
'(') count++;
3572 if (count==0)
break;
3580 while (*p && !(pc==
'*' && c==
'/'))
3597 while (*p && !(pc==
'*' && c==
'/'))
3614 char lc=(char)tolower(c);
3615 if (!
isId(lc) && lc!=
'.' ) inNum=
false;
3627 if (s.
empty())
return s;
3628 const char *p=s.
data();
3643 else if (*(p+1)==
'E')
3657 while (*p && !(pc==
'*' && c==
'/'))
3659 if (*p==
'@' && *(p+1)==
'@')
3702 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3706 state->expanded.clear();
3710 if (e.
empty())
return false;
3712 return state->constExpParser.parse(state->fileName.data(),state->yyLineNr,e.
str(),ee.
str());
3721 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
3722 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3723 state->prevChar = yyscanner->yytext_r > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ? *(yyscanner->yytext_r-1) : 0;
3725 state->expanded.clear();
3735 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
3737 if (name ==
"__LINE__")
3741 else if (name ==
"__FILE__")
3744 resultExpr += yyextra->fileName;
3747 else if (name ==
"__DATE__")
3750 resultExpr += __DATE__;
3753 else if (name ==
"__TIME__")
3756 resultExpr += __TIME__;
3764 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3766 def.
name = state->defName;
3768 def.
nargs = state->defArgs;
3770 def.
fileDef = state->yyFileDef;
3771 def.
lineNr = state->yyLineNr-state->yyMLines;
3773 def.
varArgs = state->defVarArgs;
3783 auto it = state->localDefines.find(def.
name.
str());
3784 if (it!=state->localDefines.end())
3786 state->localDefines.erase(it);
3788 state->localDefines.emplace(def.
name.
str(),def);
3793 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3794 if (state->skip)
return;
3799 define.
lineNr = state->yyLineNr - state->yyMLines;
3801 define.
name = state->defName;
3802 define.
args = state->defArgsStr;
3803 define.
fileDef = state->inputFileDef;
3805 DString litText = state->defLitText;
3806 size_t l=litText.
find(
'\n');
3810 litText = litText.
mid(l+1);
3816 const char *p=litText.
data()+k;
3818 while ((c=*p++) && (c==
' ' || c==
'\t')) k++;
3822 if (litTextStripped.
contains(
'\n')>=1)
3831 state->macroDefinitions.push_back(define);
3837 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3838 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=c;
3843 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3844 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=std::string_view(a,len);
3849 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3850 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=a.
str();
3872 struct yyguts_t * yyg = (
struct yyguts_t*)yyscanner;
3873 if (!yyextra->defContinue)
return;
3874 for (
int i=0; i< (int)yyleng; i++)
3876 if (yytext[i] ==
'\t')
3877 yyextra->defExtraSpacing+=
'\t';
3879 yyextra->defExtraSpacing+=
' ';
3885 struct yyguts_t * yyg = (
struct yyguts_t*)yyscanner;
3886 yyextra->fenceSize=0;
3888 if (yytext[1]==
'f' && ((c=yytext[2])==
'[' || c==
'{' || c==
'(' || c==
'$'))
3892 case '[': yyextra->blockName=
"]";
break;
3893 case '{': yyextra->blockName=
"}";
break;
3894 case '(': yyextra->blockName=
")";
break;
3895 case '$': yyextra->blockName=
"$";
break;
3898 yyextra->blockName=yyextra->blockName.stripWhiteSpace();
3905 yyextra->blockName=
"uml";
3909 if (
size_t i = bn.
find(
'{');
3911 yyextra->blockName=bn;
3919 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3924 (inc.
at(i)==
' ' || inc.
at(i)==
'"' || inc.
at(i)==
'<')
3929 bool localInclude = s>0 && inc.
at(s-1)==
'"';
3932 while (i<inc.
length() && inc.
at(i)!=
'"' && inc.
at(i)!=
'>') i++;
3934 if (s<inc.
length() && i>s)
3944 DString oldFileName = state->fileName;
3945 FileDef *oldFileDef = state->yyFileDef;
3946 int oldLineNr = state->yyLineNr;
3952 std::unique_ptr<FileState> fs;
3953 bool alreadyProcessed =
false;
3955 fs=
findFile(yyscanner,absIncFileName,localInclude,alreadyProcessed);
3966 for (i=0;i<state->includeStack.size();i++)
3973 if (state->includeStack.empty() && oldFileDef)
3975 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
3980 state->includeRelations.add(
3983 ambig ?
nullptr : incFd,
3991 struct yyguts_t * yyg = (
struct yyguts_t*)yyscanner;
3992 fs->bufState = YY_CURRENT_BUFFER;
3993 fs->lineNr = oldLineNr;
3994 fs->fileName = oldFileName;
3995 fs->curlyCount = state->curlyCount;
3997 fs->lexRulesPart = state->lexRulesPart;
3998 fs->levelGuard = state->levelGuard;
3999 while (!state->levelGuard.empty()) state->levelGuard.pop();
4000 state->lexRulesPart =
false;
4003 state->includeStack.push_back(std::move(fs));
4013 state->expectGuard=
true;
4014 state->inputBuf = &fs_ptr->
fileBuf;
4015 state->inputBufPos=0;
4016 yy_switch_to_buffer(yy_create_buffer(0,
YY_BUF_SIZE, yyscanner),yyscanner);
4020 if (alreadyProcessed)
4028 if (state->includeStack.empty() && oldFileDef)
4030 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
4035 ii = state->includeRelations.add(absIncFileName,
4037 ambig ?
nullptr : incFd,
4047 for (i=0;i<state->includeStack.size();i++)
4051 if (alreadyProcessed)
4061 if (localInclude && !state->includeStack.empty() && state->curlyCount>0 && !alreadyProcessed)
4063 warn(state->fileName,state->yyLineNr,
"include file {} not found, perhaps you forgot to add its directory to INCLUDE_PATH?",incFileName);
4073 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4076 bool expResult = prs.
parse(state->fileName.data(),state->yyLineNr,sectId.
data());
4077 state->condStack.emplace(std::make_unique<preYY_CondCtx>(state->fileName,state->yyLineNr,sectId,state->skip));
4087 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4088 if (state->condGuardCount>0 && state->condGuardErrorLine==0)
4090 state->condGuardErrorLine = state->yyLineNr;
4091 state->condGuardErrorFileName = state->fileName;
4092 state->condGuardErrorMessage =
"more #if's than #endif's in \\cond..\\endcond section";
4094 else if (state->condGuardCount<0 && state->condGuardErrorLine==0)
4096 state->condGuardErrorLine = state->yyLineNr;
4097 state->condGuardErrorFileName = state->fileName;
4098 state->condGuardErrorMessage =
"more #endif's than #if's in \\cond..\\endcond section";
4102 state->condGuardErrorLine = 0;
4104 if (state->condStack.empty())
4106 warn(state->fileName,state->yyLineNr,
"the \\endcond does not have a corresponding \\cond in this file");
4111 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4112 state->skip=ctx->skip;
4113 state->condStack.pop();
4120 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4121 while (!state->condStack.empty())
4123 state->condStack.pop();
4134 const char *p=text.
data();
4137 if (c==
'@') result+=
"@@";
else result+=c;
4147 case '=':
return '#';
4148 case '/':
return '\\';
4149 case '\'':
return '^';
4150 case '(':
return '[';
4151 case ')':
return ']';
4152 case '!':
return '|';
4153 case '<':
return '{';
4154 case '>':
return '}';
4155 case '-':
return '~';
4169 return expr.
at(pos++);
4171 else if (rest && !rest->
empty())
4178 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4180 int cc=yyinput(yyscanner);
4193 return expr.
at(pos);
4195 else if (rest && !rest->
empty())
4201 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4203 int cc=yyinput(yyscanner);
4221 char cs[2];cs[0]=c;cs[1]=
'\0';
4224 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4237 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4240 auto findDefine = [&undef,&name](
DefineMap &map)
4243 auto it = map.find(name.str());
4256 Define *def = findDefine(state->localDefines);
4257 if (def==
nullptr && !undef)
4259 def = findDefine(state->contextDefines);
4266 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4270 for (
const auto &ds : predefList)
4272 size_t i_equals=ds.find(
'=');
4273 size_t i_obrace=ds.find(
'(');
4274 size_t i_cbrace=ds.find(
')');
4275 bool nonRecursive = i_equals!=std::string::npos && i_equals>0 && ds[i_equals-1]==
':';
4277 if ((i_obrace==0) || (i_equals==0) || (i_equals==1 && ds[i_equals-1]==
':'))
4282 if (i_obrace<i_equals && i_cbrace<i_equals &&
4283 i_obrace!=std::string::npos && i_cbrace!=std::string::npos &&
4287 static const reg::Ex reId(R
"(\a\w*)");
4288 std::map<std::string,int> argMap;
4289 std::string args = ds.substr(i_obrace+1,i_cbrace-i_obrace-1);
4290 bool hasVarArgs = args.find(
"...")!=std::string::npos;
4296 for (; arg_it!=arg_end; ++arg_it)
4298 argMap.emplace(arg_it->
str(),count++);
4302 argMap.emplace(
"__VA_ARGS__",count++);
4306 std::string definition;
4307 std::string in=ds.substr(i_equals+1);
4313 for (; re_it!=re_end; ++re_it)
4315 const auto &match = *re_it;
4316 size_t pi = match.position();
4317 size_t l = match.length();
4318 if (pi>i) definition+=in.substr(i,pi-i);
4320 auto it = argMap.find(match.str());
4321 if (it!=argMap.end())
4323 int argIndex = it->second;
4325 marker.
sprintf(
" @%d ",argIndex);
4326 definition+=marker.
str();
4330 definition+=match.str();
4334 definition+=in.substr(i);
4337 std::string dname = ds.substr(0,i_obrace);
4346 def.
fileDef = state->yyFileDef;
4349 state->contextDefines.emplace(def.
name.
str(),def);
4355 else if (!ds.empty())
4359 if (i_equals==std::string::npos)
4366 int ine=
static_cast<int>(i_equals) - (nonRecursive ? 1 : 0);
4375 def.
fileDef = state->yyFileDef;
4377 state->contextDefines.emplace(def.
name.
str(),def);
4393 YY_EXTRA_TYPE state = preYYget_extra(
p->yyscanner);
4400 preYYlex_init_extra(&
p->state,&
p->yyscanner);
4406 preYYlex_destroy(
p->yyscanner);
4413 YY_EXTRA_TYPE state = preYYget_extra(
p->yyscanner);
4414 struct yyguts_t *yyg = (
struct yyguts_t*)
p->yyscanner;
4427 state->curlyCount=0;
4428 state->lexRulesPart=
false;
4429 state->nospaces=
false;
4430 state->inputBuf=&input;
4431 state->inputBufPos=0;
4432 state->outputBuf=&output;
4433 state->includeStack.clear();
4434 state->expandedDict.clear();
4435 state->contextDefines.clear();
4436 state->pragmaSet.clear();
4437 state->condGuardCount=0;
4438 state->condGuardErrorLine=0;
4439 while (!state->levelGuard.empty()) state->levelGuard.pop();
4440 while (!state->condStack.empty()) state->condStack.pop();
4444 state->inputFileDef = state->yyFileDef;
4449 state->yyLineNr = 1;
4456 state->guardName.clear();
4457 state->lastGuardName.clear();
4458 state->guardExpr.clear();
4460 preYYlex(yyscanner);
4462 while (!state->condStack.empty())
4464 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4466 if (ctx->sectionId!=
" ") sectionInfo.
sprintf(
" with label '%s' ",
qPrint(ctx->sectionId.stripWhiteSpace()));
4467 warn(ctx->fileName,ctx->lineNr,
"Conditional section{}does not have "
4468 "a corresponding \\endcond command within this file.",sectionInfo);
4469 state->condStack.pop();
4474 if (!state->levelGuard.empty())
4476 if (yyextra->condGuardErrorLine!=0)
4478 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,
"{}",yyextra->condGuardErrorMessage);
4482 warn(state->fileName,state->yyLineNr,
"More #if's than #endif's found (might be in an included file).");
4490 std::string contents;
4498 bool startOfLine =
true;
4499 size_t content_size = output.size() +
4502 contents.reserve(content_size);
4504 while (pos<output.size())
4509 snprintf(lineNrStr,15,
"%05d ",line++);
4510 contents+=lineNrStr;
4512 contents += output[pos];
4513 startOfLine = output[pos]==
'\n';
4518 if (!contents.empty() && contents[contents.length()-1]!=
'\n')
4523 if (yyextra->contextDefines.size()>0)
4527 for (
auto &kv : yyextra->contextDefines)
4531 for (
auto &kv : yyextra->localDefines)
4545 for (
const auto &inc : state->includeRelations)
4547 auto toKind = [](
bool local,
bool imported) ->
IncludeKind
4563 if (inc->fromFileDef)
4565 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4567 if (inc->toFileDef && inc->fromFileDef)
4569 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
Copyright (C) 1997-2026 by Dimitri van Heesch.
bool parse(const DString &fileName, int lineNr, const DString &expr)
parses and evaluates the given expression.
DString mid(size_t index, size_t len=npos) const
DString substr(size_t pos=0, size_t count=npos) const
Returns a substring of length count starting at pos.
char & at(size_t i)
Returns a reference to the character at index i.
DString right(size_t len) const
size_t size() const
Returns the length of the string, not counting the 0-terminator.
DString & prepend(const char *s)
size_t find(char c, size_t pos=0) const
DString & sprintf(const char *format,...)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
bool endsWith(const char *s) const
static StringUnorderedSet expandAsDefinedSet
static FileNameLinkedMap * inputNameLinkedMap
static DefinesPerFileList macroDefinitions
static FileNameLinkedMap * includeNameLinkedMap
Wrapper class for the Entry type.
static EntryType guessSection(const DString &name)
virtual DString absFilePath() const =0
Minimal replacement for QFileInfo.
bool match(const PatternList &patList, bool caseSenseNames, PatternElem *elem=nullptr, PatternGet getter=[](const std::string &s){ return s;}) const
Match the file name against a list of patterns.
std::string dirPath(bool absPath=true) const
std::string absFilePath() const
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
void processFile(const DString &fileName, const std::string &input, std::string &output)
void addSearchDir(const DString &dir)
std::unique_ptr< Private > p
Class representing a regular expression.
Class to iterate through matches.
std::string str() const
Return a string representing the matching part.
#define Config_getList(name)
DirIterator end(const DirIterator &) noexcept
#define AUTO_TRACE_ADD(...)
bool isId(char c)
Returns true if c is a valid character for an identifier.
int dstrncmp(const char *str1, const char *str2, size_t len)
bool recognizeFixedForm(const DString &contents, FortranFormat format)
FortranFormat convertFileNameFortranParserCode(const DString &fn)
bool isAbsolutePath(const DString &fileName)
static void addSeparatorsIfNeeded(yyscan_t yyscanner, const DString &expr, DString &resultExpr, DString &restExpr, int pos)
static std::unique_ptr< FileState > checkAndOpenFile(yyscan_t yyscanner, const DString &fileName, bool &alreadyProcessed)
static std::unique_ptr< FileState > findFile(yyscan_t yyscanner, const DString &fileName, bool localInclude, bool &alreadyProcessed)
#define MAX_EXPANSION_DEPTH
static DString stringize(const DString &s)
static void processConcatOperators(DString &expr)
static void skipCommentMacroName(yyscan_t yyscanner, const DString &expr, DString *rest, int &cc, uint32_t &j, int &len)
static int getNextId(const DString &expr, int p, int *l)
static void unputChar(yyscan_t yyscanner, const DString &expr, DString *rest, uint32_t &pos, char c)
static void expandArgument(yyscan_t yyscanner, DString &arg, int level)
static bool isFunctionMacroCall(yyscan_t yyscanner, const DString &expr, DString *rest, int pos)
static void returnCharToStream(yyscan_t yyscanner, char c)
static int getCurrentChar(yyscan_t yyscanner, const DString &expr, DString *rest, uint32_t pos)
static const char * processUntilMatchingTerminator(const char *inputStr, DString &result)
Process string or character literal.
static void forceEndCondSection(yyscan_t yyscanner)
static DString expandVAOpt(const DString &vaStr, bool hasOptionalArgs)
static void addTillEndOfComment(yyscan_t yyscanner, const DString &expr, DString *rest, uint32_t &pos, char term, DString &arg)
static bool replaceFunctionMacro(yyscan_t yyscanner, const DString &expr, DString *rest, int pos, int &len, const Define *def, DString &result, int level)
static DString removeMarkers(const DString &s)
static void addTillEndOfString(yyscan_t yyscanner, const DString &expr, DString *rest, uint32_t &pos, char term, DString &arg)
static int getNextChar(yyscan_t yyscanner, const DString &expr, DString *rest, uint32_t &pos)
static void initPredefined(yyscan_t yyscanner, const DString &fileName)
static DString removeIdsAndMarkers(const DString &s)
static bool expandExpression(yyscan_t yyscanner, DString &expr, DString *rest, int pos, int level)
void addTerminalCharIfMissing(std::string &s, char c)
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
bool readInputFile(const DString &fileName, std::string &contents, const ReadInputFileOptions &options)
read a file name fileName and optionally filter and transcode it
bool useCaseSenseNames()
Returns true if the names of the symbols can be case sensitive.
DString determineAbsoluteIncludeName(const DString &curFile, const DString &incFileName)