15%option never-interactive
18%option extra-type="struct preYY_state *"
22#define YY_TYPEDEF_YY_SCANNER_T
23#define yyguts_t preYYguts_t
69#define YY_NO_UNISTD_H 1
134 for (
auto &[name,define] : fromMap)
152 if (dpf && includeStack.find(incFile)==includeStack.end())
154 includeStack.insert(incFile);
161 toMap.emplace(name,define);
175 void addInclude(
const std::string &fromFileName,
const std::string &toFileName)
181 it =
m_fileMap.emplace(fromFileName,std::make_unique<DefinesPerFile>(
this)).first;
183 auto &dpf = it->second;
184 dpf->addInclude(toFileName);
193 it =
m_fileMap.emplace(fileName,std::make_unique<DefinesPerFile>(
this)).first;
195 it->second->store(fromMap);
203 auto &dpf = it->second;
204 dpf->retrieve(toMap);
214 return it->second->stored();
224 return it!=
m_fileMap.end() ? it->second.get() :
nullptr;
227 std::unordered_map< std::string, std::unique_ptr<DefinesPerFile> >
m_fileMap;
353static yy_size_t
getFenceSize(
char *txt, yy_size_t leng);
358#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.
368IDSTART [a-z_A-Z\x80-\xFF]
369ID {IDSTART}[a-z_A-Z0-9\x80-\xFF]*
373RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"("
374RAWEND ")"[^ \t\(\)\\]{0,16}\"
375CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
378FORMULA_START {CMD}("f{"|"f$"|"f["|"f(")
379FORMULA_END {CMD}("f}"|"f$"|"f]"|"f)")
380VERBATIM_START {CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly"|"dot"|"msc"|"mermaid"|"startuml"|"code"("{"[^}]*"}")?){BN}+
381VERBATIM_END {CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endmsc"|"endmermaid"|"enduml"|"endcode")
382VERBATIM_LINE {CMD}"noop"{B}+
383LITERAL_BLOCK {FORMULA_START}|{VERBATIM_START}
384LITERAL_BLOCK_END {FORMULA_END}|{VERBATIM_END}
389RulesSharp "<"[^>\n]*">"
390RulesCurly "{"[^{}\n]*"}"
395EscapeRulesCharOpen "\\["|"\<"|"\\{"|"\\("|"\\\""|"\\ "|"\\\\"
396EscapeRulesCharClose "\\]"|"\>"|"\\}"|"\\)"
397EscapeRulesChar {EscapeRulesCharOpen}|{EscapeRulesCharClose}
399DOXYCFG [A-Z][A-Z_0-9]*
414DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
415HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
416OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
417BINARY_INTEGER "0"[bB][01][01']*[01]?
418INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
422DIGIT_SEQ [0-9][0-9']*[0-9]?
423FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
424FP_EXP [eE][+-]?{DIGIT_SEQ}
425DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
426DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
428HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
429HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
430BIN_EXP [pP][+-]?{DIGIT_SEQ}
431HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
432HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
434FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
435FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
436FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
437NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
453%x CopyStringFtnDouble
470%x JavaDocVerbatimCode
504 yyextra->yyColNr+=(int)yyleng;
506 yyextra->potentialDefine=yytext;
509<Start>^("%top{"|"%{") {
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
514<Start>^{Bopt}"cpp_quote"{Bopt}"("{Bopt}\" {
515 if (yyextra->insideIDL)
530<IDLquote>"\""{Bopt}")" {
542 if (!yyextra->isFixedFormFtn) REJECT;
553<Start>^{B}*[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]+{B}*"("[^\)\n]*")"/{BN}{1,10}*[:{] {
555 for (i=(
int)yyleng-1;i>=0;i--)
561<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\(\)\n]*"("[^\)\n]*")"[^\)\n]*")"{B}*\n |
562<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\)\n]*")"{B}*\n |
563<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\(\)\n]*"("[^\)\n]*")"[^\)\n]*")"/{B}*("//"|"/\*") |
564<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\)\n]*")"/{B}*("//"|"/\*") {
567 size_t pos =
name.find(
'(');
569 name=
name.left(pos).stripWhiteSpace();
572 if (skipFuncMacros && !yyextra->insideFtn &&
573 name!=
"Q_PROPERTY" &&
575 (yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
576 yyextra->macroExpansion &&
584 if (yytext[yyleng-1] ==
'\n')
593 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)
600<CopyLine,LexCopyLine>"extern"{BN}*"\""[^\"]+"\""{BN}*("{")? {
602 yyextra->yyLineNr+=text.
contains(
'\n');
int contains(char c, bool cs=true) const
605<CopyLine,LexCopyLine>{RAWBEGIN} {
608 BEGIN(CopyRawString);
DString extractBeginRawStringDelimiter(const char *rawStart)
610<CopyLine,LexCopyLine>"{" {
611 if (yyextra->includeStack.empty())
613 yyextra->curlyCount++;
620<CopyLine,LexCopyLine>"}" {
621 if (yyextra->includeStack.empty() && yyextra->curlyCount>0)
623 yyextra->curlyCount--;
627<CopyLine,LexCopyLine>"'"\\[0-7]{1,3}"'" {
630<CopyLine,LexCopyLine>"'"\\."'" {
633<CopyLine,LexCopyLine>"'"."'" {
636<CopyLine,LexCopyLine>[$]?@\" {
639 BEGIN( CopyStringCs );
641<CopyLine,LexCopyLine>"!".* {
645<CopyLine,LexCopyLine>\" {
653 BEGIN( CopyStringFtnDouble );
656<CopyLine,LexCopyLine>\' {
659 BEGIN( CopyStringFtn );
661<CopyString>[^\"\\\r\n]{1,1000} {
664<CopyStringCs>[^\"\r\n]{1,1000} {
673<CopyString,CopyStringCs>\" {
677<CopyStringFtnDouble>[^\"\\\r\n]{1,1000} {
680<CopyStringFtnDouble>\\. {
683<CopyStringFtnDouble>\" {
687<CopyStringFtn>[^\'\\\r\n]{1,1000} {
697<CopyRawString>{RAWEND} {
DString extractEndRawStringDelimiter(const char *rawEnd)
704<CopyRawString>[^)]{1,1000} {
710<CopyLine,LexCopyLine>{ID}/{BN}{0,80}"(" {
711 yyextra->expectGuard =
false;
721 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
722 yyextra->macroExpansion &&
728 yyextra->roundCount=0;
729 yyextra->defArgsStr=yytext;
740 yyextra->findDefArgContext = CopyLine;
741 BEGIN(FindDefineArgs);
749<CopyLine>{RulesDelim} {
751 yyextra->lexRulesPart = !yyextra->lexRulesPart;
755<CopyLine>{RulesSharp} {
756 if (!yyextra->lexRulesPart) REJECT;
757 if (yyextra->curlyCount) REJECT;
761<RulesPattern>{EscapeRulesChar} {
764<RulesPattern>{RulesCurly} {
767<RulesPattern>{StartDouble} {
769 yyextra->lastContext = YY_START;
772<RulesDouble,RulesRoundDouble>"\\\\" {
775<RulesDouble,RulesRoundDouble>"\\\"" {
780 BEGIN( yyextra->lastContext ) ;
782<RulesRoundDouble>"\"" {
786<RulesDouble,RulesRoundDouble>. {
789<RulesPattern>{StartSquare} {
791 yyextra->lastContext = YY_START;
794<RulesSquare,RulesRoundSquare>{CHARCE} {
797<RulesSquare,RulesRoundSquare>"\\[" |
798<RulesSquare,RulesRoundSquare>"\\]" {
805<RulesRoundSquare>"]" {
809<RulesSquare,RulesRoundSquare>"\\\\" {
812<RulesSquare,RulesRoundSquare>. {
815<RulesPattern>{StartRoundQuest} {
817 yyextra->lastContext = YY_START;
818 BEGIN(RulesRoundQuest);
820<RulesRoundQuest>{nl} {
823<RulesRoundQuest>[^)] {
826<RulesRoundQuest>")" {
828 BEGIN(yyextra->lastContext);
830<RulesPattern>{StartRound} {
831 yyextra->roundCount++;
833 yyextra->lastContext = YY_START;
836<RulesRound>{RulesCurly} {
839<RulesRound>{StartSquare} {
841 BEGIN(RulesRoundSquare);
843<RulesRound>{StartDouble} {
845 BEGIN(RulesRoundDouble);
847<RulesRound>{EscapeRulesChar} {
851 yyextra->roundCount++;
855 yyextra->roundCount--;
857 if (!yyextra->roundCount) BEGIN( yyextra->lastContext ) ;
876<CopyLine,LexCopyLine>{ID} {
879 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
880 yyextra->macroExpansion &&
900<CopyLine,LexCopyLine>"\\"\r?/\n {
903<CopyLine,LexCopyLine>\\. {
906<CopyLine,LexCopyLine>. {
909<CopyLine,LexCopyLine>\n {
916 yyextra->defArgsStr+=
'(';
917 yyextra->roundCount++;
920 yyextra->defArgsStr+=
')';
921 yyextra->roundCount--;
922 if (yyextra->roundCount==0)
926 if (yyextra->findDefArgContext==CopyLine)
929 BEGIN(yyextra->findDefArgContext);
934 yyextra->nospaces=
false;
944<FindDefineArgs>{CHARLIT} {
945 yyextra->defArgsStr+=yytext;
947<FindDefineArgs>{CCS}[*!]? {
948 yyextra->defArgsStr+=yytext;
949 BEGIN(ArgCopyCComment);
951<FindDefineArgs>{CPPC}[/!].*\n/{B}*{CPPC}[/!] {
956 yyextra->defArgsStr+=
DString(
"/**< @brief ")+&yytext[4];
960 yyextra->defArgsStr+=
DString(
"/** @brief ")+&yytext[3];
965 yyextra->defArgsStr+=
DString(
"/**")+&yytext[3];
967 BEGIN(ArgCopyCppComment);
969<FindDefineArgs>{CPPC}[/!].*\n {
972 yyextra->defArgsStr+=
DString(
"/**")+&yytext[3]+
" */";
978 yyextra->defArgsStr+=
DString(
"/**< @brief ")+&yytext[4]+
" */";
982 yyextra->defArgsStr+=
DString(
"/** @brief ")+&yytext[3]+
" */";
986<FindDefineArgs>{CPPC}.*\n {
988 yyextra->defArgsStr+=
DString(
"/*")+&yytext[2]+
" */";
991 yyextra->defArgsStr+=*yytext;
996 yyextra->defArgsStr+=*yytext;
1000 yyextra->defArgsStr+=
' ';
1001 yyextra->yyLineNr++;
1004<FindDefineArgs>"@" {
1005 yyextra->defArgsStr+=
"@@";
1008 yyextra->defArgsStr+=*yytext;
1010<ArgCopyCComment>[^*\n]+ {
1011 yyextra->defArgsStr+=yytext;
1013<ArgCopyCComment>{CCE} {
1014 yyextra->defArgsStr+=yytext;
1015 BEGIN(FindDefineArgs);
1017<ArgCopyCComment>\n {
1018 yyextra->defArgsStr+=yytext;
1019 yyextra->yyLineNr++;
1022 yyextra->defArgsStr+=yytext;
1024<ArgCopyCppComment>^{B}*
1025<ArgCopyCppComment>{CPPC}[/!].*\n/{B}*{CPPC}[/!] {
1026 const char *startContent = &yytext[3];
1027 if (startContent[0]==
'<') startContent++;
1028 yyextra->defArgsStr+=startContent;
1030<ArgCopyCppComment>{CPPC}[/!].*\n {
1031 const char *startContent = &yytext[3];
1032 if (startContent[0]==
'<') startContent++;
1033 yyextra->defArgsStr+=
DString(startContent)+
" */";
1034 BEGIN(FindDefineArgs);
1036<ArgCopyCppComment>. {
1038 yyextra->defArgsStr+=
" */";
1039 BEGIN(FindDefineArgs);
1042 yyextra->defArgsStr+=*yytext;
1043 BEGIN(FindDefineArgs);
1047 yyextra->defArgsStr+=*yytext;
1048 BEGIN(FindDefineArgs);
1051<ReadString>{CPPC}|{CCS} {
1052 yyextra->defArgsStr+=yytext;
1054<ReadString>\\/\r?\n {
1057 yyextra->defArgsStr+=yytext;
1060 yyextra->defArgsStr+=*yytext;
1062<Command>("include"|"import"){B}+/{ID} {
1063 yyextra->isImported = yytext[1]==
'm';
1064 if (yyextra->macroExpansion)
1067<Command>("include"|"import"){B}*[<"] {
1068 yyextra->isImported = yytext[1]==
'm';
1070 c[0]=yytext[yyleng-1];c[1]=
'\0';
1074<Command>("cmake")?"define"{B}+ {
1075 yyextra->potentialDefine +=
substitute(yytext,
"cmake",
" ");
1077 yyextra->yyColNr+=(int)yyleng;
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
1080<Command>"cmakedefine01"{B}+ {
1081 yyextra->potentialDefine +=
substitute(yytext,
"cmakedefine01",
" define ");
1083 yyextra->yyColNr+=(int)yyleng;
1084 BEGIN(CmakeDefName01);
1086<Command>"ifdef"/{B}*"(" {
1088 yyextra->guardExpr.clear();
1089 BEGIN(DefinedExpr2);
1091<Command>"ifdef"/{B}+ {
1094 yyextra->guardExpr.clear();
1095 BEGIN(DefinedExpr1);
1097<Command>"ifndef"/{B}*"(" {
1099 yyextra->guardExpr=
"! ";
1100 BEGIN(DefinedExpr2);
1102<Command>"ifndef"/{B}+ {
1104 yyextra->guardExpr=
"! ";
1105 BEGIN(DefinedExpr1);
1107<Command>"if"/[ \t(!] {
1109 yyextra->guardExpr.clear();
1112<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1115 yyextra->guardExpr.clear();
1121 BEGIN(SkipCPPBlock);
1124<Command>"else"/[^a-z_A-Z0-9\x80-\xFF] {
1128 BEGIN(SkipCPPBlock);
1135<Command>"undef"{B}+ {
1138<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1141 yyextra->guardExpr.clear();
1145<Command>"endif"/[^a-z_A-Z0-9\x80-\xFF] {
1149<Command,IgnoreLine>\n {
1152 yyextra->yyLineNr++;
1154<Command>"pragma"{B}+"once" {
1155 yyextra->expectGuard =
false;
1156 if (yyextra->pragmaSet.find(yyextra->fileName.str())!=yyextra->pragmaSet.end())
1163 yyextra->pragmaSet.insert(yyextra->fileName.data());
1168<PragmaOnce><<EOF>> {
1169 yyextra->expectGuard =
false;
1175<IgnoreLine>\\[\r]?\n {
1177 yyextra->yyLineNr++;
1180<Command>. { yyextra->potentialDefine += yytext[0]==
'\t' ?
'\t' :
' ';
1181 yyextra->yyColNr+=(int)yyleng;
1197 yyextra->guardExpr+=
' ';
1198 yyextra->yyLineNr++;
1200<Guard>"defined"/{B}*"(" {
1201 BEGIN(DefinedExpr2);
1203<Guard>"defined"/{B}+ {
1204 BEGIN(DefinedExpr1);
1206<Guard>"true"/{B}|{B}*[\r]?\n { yyextra->guardExpr+=
"1L"; }
1207<Guard>"false"/{B}|{B}*[\r]?\n { yyextra->guardExpr+=
"0L"; }
1208<Guard>"not"/{B} { yyextra->guardExpr+=
'!'; }
1209<Guard>"not_eq"/{B} { yyextra->guardExpr+=
"!="; }
1210<Guard>"and"/{B} { yyextra->guardExpr+=
"&&"; }
1211<Guard>"or"/{B} { yyextra->guardExpr+=
"||"; }
1212<Guard>"bitand"/{B} { yyextra->guardExpr+=
"&"; }
1213<Guard>"bitor"/{B} { yyextra->guardExpr+=
"|"; }
1214<Guard>"xor"/{B} { yyextra->guardExpr+=
"^"; }
1215<Guard>"compl"/{B} { yyextra->guardExpr+=
"~"; }
1216<Guard>{ID} { yyextra->guardExpr+=yytext; }
1217<Guard>"@" { yyextra->guardExpr+=
"@@"; }
1218<Guard>. { yyextra->guardExpr+=*yytext; }
1232 BEGIN(SkipCPPBlock);
1235<DefinedExpr1,DefinedExpr2>\\\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1237 if (
isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1238 yyextra->guardExpr+=
" 1L ";
1240 yyextra->guardExpr+=
" 0L ";
1241 yyextra->lastGuardName=yytext;
1245 if (
isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1246 yyextra->guardExpr+=
" 1L ";
1248 yyextra->guardExpr+=
" 0L ";
1249 yyextra->lastGuardName=yytext;
1251<DefinedExpr1,DefinedExpr2>\n {
1252 yyextra->yyLineNr++;
1254 BEGIN(SkipCPPBlock);
1259<DefinedExpr1,DefinedExpr2>.
1260<SkipCPPBlock>^{B}*"#" { BEGIN(SkipCommand); }
1261<SkipCPPBlock>^{Bopt}/[^#] { BEGIN(SkipLine); }
1262<SkipCPPBlock>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1264<SkipCommand>"if"(("n")?("def"))?/[ \t(!] {
1269<SkipCommand>"else" {
1278<SkipCommand>("elif"|"else"{B}*"if")/[ \t(!] {
1279 if (yyextra->ifcount==0)
1283 yyextra->guardExpr.clear();
1284 yyextra->lastGuardName.clear();
1289 BEGIN(SkipCPPBlock);
1293<SkipCommand>"endif" {
1294 yyextra->expectGuard =
false;
1296 if (--yyextra->ifcount<0)
1304 yyextra->yyLineNr++;
1305 BEGIN(SkipCPPBlock);
1312<SkipLine>{CHARLIT} { }
1317<SkipString>{CPPC}/[^\n]* {
1319<SkipLine,SkipCommand,SkipCPPBlock>{CPPC}[^\n]* {
1320 yyextra->lastCPPContext=YY_START;
1321 BEGIN(RemoveCPPComment);
1323<SkipString>{CCS}/[^\n]* {
1325<SkipLine,SkipCommand,SkipCPPBlock>{CCS}/[^\n]* {
1326 yyextra->lastCContext=YY_START;
1327 BEGIN(RemoveCComment);
1331 yyextra->yyLineNr++;
1332 BEGIN(SkipCPPBlock);
1334<SkipString>[^"\\\n]+ { }
1340<IncludeID>{ID}{Bopt}/"(" {
1341 yyextra->nospaces=
true;
1342 yyextra->roundCount=0;
1343 yyextra->defArgsStr=yytext;
1344 yyextra->findDefArgContext = IncludeID;
1345 BEGIN(FindDefineArgs);
1348 yyextra->nospaces=
true;
1352<Include>[^\">\n]+[\">] {
1353 yyextra->incName+=yytext;
1354 if (yyextra->isImported)
1364<EndImport>{ENDIMPORTopt}/\n {
1368<EndImport>\\[\r]?"\n" {
1370 yyextra->yyLineNr++;
1374<DefName>{ID}/("\\\n")*"(" {
1376 yyextra->argMap.clear();
1377 yyextra->defArgs = 0;
1378 yyextra->defArgsStr.clear();
1379 yyextra->defText.clear();
1380 yyextra->defLitText.clear();
1381 yyextra->defName = yytext;
1382 yyextra->defVarArgs =
false;
1383 yyextra->defExtraSpacing.clear();
1384 yyextra->defContinue =
false;
1387<DefName>{ID}{B}+"1"/[ \r\t\n] {
1389 yyextra->argMap.clear();
1390 yyextra->defArgs = -1;
1391 yyextra->defArgsStr.clear();
1393 yyextra->defVarArgs =
false;
1396 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1398 DString def = yyextra->potentialDefine +
1401 outputSpaces(yyscanner,yytext+yyextra->defName.length());
1402 yyextra->quoteArg=
false;
1403 yyextra->insideComment=
false;
1404 yyextra->lastGuardName.clear();
1405 yyextra->defText=
"1";
1406 yyextra->defLitText=
"1";
1412 yyextra->defText.clear();
1413 yyextra->defLitText.clear();
1416 yyextra->expectGuard=
false;
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
DString left(size_t len) const
1418<DefName,CmakeDefName01>{ID}/{B}*"\n" {
1419 yyextra->argMap.clear();
1420 yyextra->defArgs = -1;
1421 yyextra->defName = yytext;
1422 yyextra->defArgsStr.clear();
1423 yyextra->defText.clear();
1424 yyextra->defLitText.clear();
1425 yyextra->defVarArgs =
false;
1428 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1430 DString def = yyextra->potentialDefine + yyextra->defName;
1432 yyextra->quoteArg=
false;
1433 yyextra->insideComment=
false;
1434 if (YY_START == CmakeDefName01) yyextra->defText =
"0";
1435 else if (yyextra->insideCS) yyextra->defText=
"1";
1441 yyextra->guardName = yytext;
1442 yyextra->lastGuardName.clear();
1445 yyextra->expectGuard=
false;
1449 yyextra->argMap.clear();
1450 yyextra->defArgs = -1;
1451 yyextra->defArgsStr.clear();
1452 yyextra->defText.clear();
1453 yyextra->defLitText.clear();
1454 yyextra->defName = yytext;
1455 yyextra->defVarArgs =
false;
1456 DString def = yyextra->potentialDefine +
1458 yyextra->defArgsStr ;
1460 yyextra->quoteArg=
false;
1461 yyextra->insideComment=
false;
1465 yyextra->defExtraSpacing+=
"\n";
1466 yyextra->defContinue =
true;
1467 yyextra->yyLineNr++;
1469<DefineArg>{B}* { yyextra->defExtraSpacing+=yytext; }
1470<DefineArg>","{B}* { yyextra->defArgsStr+=yytext; }
1471<DefineArg>"("{B}* { yyextra->defArgsStr+=yytext; }
1472<DefineArg>{B}*")"{B}* {
1474 yyextra->defArgsStr+=yytext;
1475 DString def = yyextra->potentialDefine +
1477 yyextra->defArgsStr +
1478 yyextra->defExtraSpacing ;
1480 yyextra->quoteArg=
false;
1481 yyextra->insideComment=
false;
1485 yyextra->defVarArgs =
true;
1486 yyextra->defArgsStr+=yytext;
1487 yyextra->argMap.emplace(std::string(
"__VA_ARGS__"),yyextra->defArgs);
1490<DefineArg>{ID}{B}*("..."?) {
1493 yyextra->defVarArgs = yytext[yyleng-1]==
'.';
1494 if (yyextra->defVarArgs)
1499 yyextra->defArgsStr+=yytext;
1500 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)
1516<DefineText>{CCS}[^!*] {
1517 yyextra->defLitText+=
' ';
1519 yyextra->lastCContext=YY_START;
1520 yyextra->commentCount=1;
1521 BEGIN(SkipCComment);
1523<DefineText>{CCS}[!*] {
1524 yyextra->defText+=yytext;
1525 yyextra->defLitText+=yytext;
1526 yyextra->lastCContext=YY_START;
1527 yyextra->commentCount=1;
1528 BEGIN(CopyCComment);
1530<DefineText>{CPPC}[!/]? {
1532 yyextra->lastCPPContext=YY_START;
1533 yyextra->defLitText+=
' ';
1534 BEGIN(SkipCPPComment);
1536<SkipCComment>[/]?{CCE} {
1537 if (yytext[0]==
'/')
outputChar(yyscanner,
'/');
1539 if (--yyextra->commentCount<=0)
1541 if (yyextra->lastCContext==Start)
1545 YY_CURRENT_BUFFER->yy_at_bol=1;
1547 BEGIN(yyextra->lastCContext);
1550<SkipCComment>{CPPC}("/")* {
1553<SkipCComment>{CCS} {
1557<SkipCond>{CMD}{CMD} { }
1558<SkipCond>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1560 if (!markdownSupport || !yyextra->isSpecialComment)
1566 yyextra->fenceChar=
'~';
1568 BEGIN(SkipCondVerbatim);
1571<SkipCond>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1573 if (!markdownSupport || !yyextra->isSpecialComment)
1579 yyextra->fenceChar=
'`';
1581 BEGIN(SkipCondVerbatim);
1584<SkipCComment>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1586 if (!markdownSupport || !yyextra->isSpecialComment)
1593 yyextra->fenceChar=
'~';
1595 BEGIN(SkipVerbatim);
1598<SkipCComment>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1600 if (!markdownSupport || !yyextra->isSpecialComment)
1607 yyextra->fenceChar=
'`';
1609 BEGIN(SkipVerbatim);
1612<SkipCComment>{CMD}{VERBATIM_LINE} |
1613<SkipCComment>{CMD}{LITERAL_BLOCK} {
1617<SkipCComment>{VERBATIM_LINE}.*/\n {
1620<SkipCComment>{LITERAL_BLOCK} {
1623 if (yyextra->isSpecialComment)
1626 BEGIN(SkipVerbatim);
1629<SkipCond>{CMD}{CMD}"cond"[ \t]+ {}
1630<SkipCond>{CMD}"cond"/\n |
1631<SkipCond>{CMD}"cond"[ \t]+ {
1635<SkipCComment>"{"[ \t]*"@code"/[ \t\n] {
1637 yyextra->javaBlock=1;
1638 BEGIN(JavaDocVerbatimCode);
1640<SkipCComment>"{"[ \t]*"@literal"/[ \t\n] {
1642 yyextra->javaBlock=1;
1643 BEGIN(JavaDocVerbatimCode);
1645<SkipCComment,SkipCPPComment>{CMD}{CMD}"cond"[ \t\n]+ {
1648<SkipCPPComment>{CMD}"cond"[ \t]+ {
1649 yyextra->ccomment=
true;
1650 yyextra->condCtx=YY_START;
1653<SkipCComment>{CMD}"cond"[ \t]+ {
1654 yyextra->ccomment=
false;
1655 yyextra->condCtx=YY_START;
1658<CondLineC,CondLineCpp>([!()&| \ta-z_A-Z0-9\x80-\xFF.\-]|{CMD}"doxyconfig")+ {
1662 if (YY_START==CondLineC)
1666 yyextra->ccomment=
true;
1670 yyextra->ccomment=
false;
1676 BEGIN(yyextra->condCtx);
1679CondLine>{B}*{CMD}doxyconfig{B}+{DOXYCFG} {
1682<CondLineC,CondLineCpp>. {
1687 if (YY_START==CondLineC)
1691 yyextra->ccomment=
true;
1695 yyextra->ccomment=
false;
1701 BEGIN(yyextra->condCtx);
1704<SkipCComment,SkipCPPComment>{CMD}"cond"{WSopt}/\n {
1705 if (YY_START==SkipCComment)
1707 yyextra->ccomment=
true;
1713 yyextra->ccomment=
false;
1715 yyextra->condCtx=YY_START;
1716 yyextra->condGuardCount=0;
1720<SkipCond>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1721<SkipCond>{VERBATIM_LINE}.*/\n { }
1722<SkipCond>{LITERAL_BLOCK} {
1724 yyextra->yyLineNr+=numNLs;
1725 for (
int i = 0; i < numNLs; i++)
outputChar(yyscanner,
'\n');
1727 BEGIN(SkipCondVerbatim);
1731<SkipCond>"#if"("def")? { yyextra->condGuardCount++; }
1732<SkipCond>"#endif" { yyextra->condGuardCount--; }
1733<SkipCond>[^\/\!*\\@\n#]+ { }
1734<SkipCond>{CPPC}[/!] { yyextra->ccomment=
false; }
1735<SkipCond>{CCS}[*!] { yyextra->ccomment=
true; }
1736<SkipCond,SkipCComment,SkipCPPComment>{CMD}{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1742<SkipCond>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1743 bool oldSkip = yyextra->skip;
1745 if (oldSkip && !yyextra->skip)
1747 if (yyextra->ccomment)
1751 BEGIN(yyextra->condCtx);
1754<SkipCComment,SkipCPPComment>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1755 bool oldSkip = yyextra->skip;
1757 if (oldSkip && !yyextra->skip)
1759 BEGIN(yyextra->condCtx);
1762<SkipCondVerbatim>{LITERAL_BLOCK_END} {
1763 if (yytext[1]==
'f' && yyextra->blockName==&yytext[2])
1767 else if (&yytext[4]==yyextra->blockName)
1772<SkipVerbatim>{LITERAL_BLOCK_END} {
1774 if (yytext[1]==
'f' && yyextra->blockName==&yytext[2])
1776 BEGIN(SkipCComment);
1778 else if (&yytext[4]==yyextra->blockName)
1780 BEGIN(SkipCComment);
1783<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1784 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'~')
1789<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1790 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'`')
1795<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1797 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'~')
1799 BEGIN(SkipCComment);
1802<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1804 if (yyextra->fenceSize==
getFenceSize(yytext,yyleng) && yyextra->fenceChar==
'`')
1806 BEGIN(SkipCComment);
1809<SkipCondVerbatim>{CCE}|{CCS} { }
1810<SkipVerbatim>{CCE}|{CCS} {
1813<JavaDocVerbatimCode>"{" {
1814 if (yyextra->javaBlock==0)
1820 yyextra->javaBlock++;
1824<JavaDocVerbatimCode>"}" {
1825 if (yyextra->javaBlock==0)
1831 yyextra->javaBlock--;
1832 if (yyextra->javaBlock==0)
1835 BEGIN(SkipCComment);
1843<JavaDocVerbatimCode>\n {
1846<JavaDocVerbatimCode>. {
1849<SkipCondVerbatim>[^{*\\@\x06~`\n\/]+ { }
1850<SkipCComment,SkipVerbatim>[^{*\\@\x06~`\n\/]+ {
1853<SkipCComment,SkipVerbatim,SkipCondVerbatim>\n {
1854 yyextra->yyLineNr++;
1857<SkipCondVerbatim>. { }
1858<SkipCComment,SkipVerbatim>. {
1861<CopyCComment>[^*a-z_A-Z\x80-\xFF\n]*[^*a-z_A-Z\x80-\xFF\\\n] {
1862 yyextra->defLitText+=yytext;
1863 yyextra->defText+=
escapeAt(yytext);
1865<CopyCComment>\\[\r]?\n {
1866 yyextra->defLitText+=yytext;
1867 yyextra->defText+=
" ";
1868 yyextra->yyLineNr++;
1869 yyextra->yyMLines++;
1871<CopyCComment>{CCE} {
1872 yyextra->defLitText+=yytext;
1873 yyextra->defText+=yytext;
1874 BEGIN(yyextra->lastCContext);
1877 yyextra->yyLineNr++;
1878 yyextra->defLitText+=yytext;
1879 yyextra->defText+=
' ';
1881<RemoveCComment>{CCE}{B}*"#" {
1882 if (yyextra->lastCContext==SkipCPPBlock)
1891<RemoveCComment>{CCE} { BEGIN(yyextra->lastCContext); }
1892<RemoveCComment>{CPPC}
1893<RemoveCComment>{CCS}
1894<RemoveCComment>[^*\x06\n]+
1895<RemoveCComment>\n { yyextra->yyLineNr++;
outputChar(yyscanner,
'\n'); }
1897<SkipCPPComment>[^\n\/\\@]+ {
1900<SkipCPPComment,RemoveCPPComment>\n {
1902 BEGIN(yyextra->lastCPPContext);
1904<SkipCPPComment>{CCS} {
1907<SkipCPPComment>{CPPC} {
1910<SkipCPPComment>[^\x06\@\\\n]+ {
1916<RemoveCPPComment>{CCS}
1917<RemoveCPPComment>{CPPC}
1918<RemoveCPPComment>[^\x06\n]+
1920<DefineText>"__VA_OPT__("{B}*"##" {
1921 warn(yyextra->fileName,yyextra->yyLineNr,
1922 "'##' may not appear at the beginning of a __VA_OPT__()",
1923 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1924 yyextra->defText+=
"__VA_OPT__(";
1925 yyextra->defLitText+=
"__VA_OPT__(";
#define warn(file, line, fmt,...)
1927<DefineText>"#"/"__VA_OPT__" {
1928 yyextra->defText+=yytext;
1929 yyextra->defLitText+=yytext;
1931<DefineText>"#"/{IDSTART} {
1933 yyextra->quoteArg=
true;
1934 yyextra->idStart=
true;
1935 yyextra->defLitText+=yytext;
1937<DefineText,CopyCComment>{ID} {
1938 yyextra->defLitText+=yytext;
1939 if (YY_START == DefineText)
outputSpaces(yyscanner,yytext);
1940 if (yyextra->quoteArg)
1942 yyextra->defText+=
"\"";
1944 if (yyextra->defArgs>0)
1946 auto it = yyextra->argMap.find(yytext);
1947 if (it!=yyextra->argMap.end())
1950 yyextra->defText+=
'@';
1955 if (yyextra->idStart)
1957 warn(yyextra->fileName,yyextra->yyLineNr,
1958 "'#' is not followed by a macro parameter '{}': '{}'",
1959 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1961 yyextra->defText+=yytext;
1966 yyextra->defText+=yytext;
1968 if (yyextra->quoteArg)
1970 yyextra->defText+=
"\"";
1972 yyextra->quoteArg=
false;
1973 yyextra->idStart=
false;
DString & setNum(short n)
1976 yyextra->defLitText+=yytext;
1977 yyextra->defText+=yytext;
1979<DefineText>\\[\r]?\n {
1980 yyextra->defLitText+=yytext;
1983 yyextra->defText +=
' ';
1984 yyextra->yyLineNr++;
1985 yyextra->yyMLines++;
1989 yyextra->defText = yyextra->defText.stripWhiteSpace();
1990 if (yyextra->defText.startsWith(
"##"))
1992 warn(yyextra->fileName,yyextra->yyLineNr,
1993 "'##' cannot occur at the beginning of a macro definition '{}': '{}'",
1994 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1996 else if (yyextra->defText.endsWith(
"##"))
1998 warn(yyextra->fileName,yyextra->yyLineNr,
1999 "'##' cannot occur at the end of a macro definition '{}': '{}'",
2000 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
2002 else if (yyextra->defText.endsWith(
"#"))
2004 warn(yyextra->fileName,yyextra->yyLineNr,
2005 "expected formal parameter after # in macro definition '{}': '{}'",
2006 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
2008 if (!comment.
empty())
2011 yyextra->defLitText=yyextra->defLitText.left(yyextra->defLitText.length()-comment.
length()-1);
2014 yyextra->defLitText+=yytext;
2017 if (yyextra->includeStack.empty() || yyextra->curlyCount>0)
2021 def=
isDefined(yyscanner,yyextra->defName);
2035 def->
name = yyextra->defName;
2037 def->
nargs = yyextra->defArgs;
2039 def->
lineNr = yyextra->yyLineNr-yyextra->yyMLines;
2044 if (def->
fileName != yyextra->fileName && !yyextra->expandOnlyPredef)
addDefine(yyscanner);
2048 yyextra->argMap.clear();
2049 yyextra->yyLineNr++;
2051 yyextra->lastGuardName.clear();
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
2055 yyextra->defText +=
' ';
2056 yyextra->defLitText+=yytext;
2059 yyextra->defText +=
"##";
2060 yyextra->defLitText+=yytext;
2063 yyextra->defText +=
"@@";
2064 yyextra->defLitText+=yytext;
2068 yyextra->defText += *yytext;
2069 yyextra->defLitText+=yytext;
2070 if (!yyextra->insideComment)
2072 BEGIN(SkipDoubleQuote);
2075<DefineText>{NUMBER} {
2077 yyextra->defText += yytext;
2078 yyextra->defLitText+=yytext;
2082 yyextra->defText += *yytext;
2083 yyextra->defLitText+=yytext;
2084 if (!yyextra->insideComment)
2086 BEGIN(SkipSingleQuote);
2089<SkipDoubleQuote>{CPPC}[/]? {
outputSpaces(yyscanner,yytext);
2090 yyextra->defText += yytext;
2091 yyextra->defLitText+=yytext;
2093<SkipDoubleQuote>{CCS}[*]? {
outputSpaces(yyscanner,yytext);
2094 yyextra->defText += yytext;
2095 yyextra->defLitText+=yytext;
2097<SkipDoubleQuote>\" {
2099 yyextra->defText += *yytext;
2100 yyextra->defLitText+=yytext;
2103<SkipSingleQuote,SkipDoubleQuote>\\. {
2105 yyextra->defText += yytext;
2106 yyextra->defLitText+=yytext;
2108<SkipSingleQuote>\' {
2110 yyextra->defText += *yytext;
2111 yyextra->defLitText+=yytext;
2114<SkipDoubleQuote,SkipSingleQuote>. {
outputSpace(yyscanner,yytext[0]);
2115 yyextra->defText += *yytext;
2116 yyextra->defLitText += *yytext;
2119 yyextra->defText += *yytext;
2120 yyextra->defLitText += *yytext;
2123 TRACE(
"End of include file");
2125 if (yyextra->includeStack.empty())
2127 TRACE(
"Terminating scanner");
2132 if (!yyextra->levelGuard.empty())
2134 if (yyextra->condGuardErrorLine!=0)
2136 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,
"{}",yyextra->condGuardErrorMessage);
2140 warn(yyextra->fileName,yyextra->yyLineNr,
"More #endif's than #if's found.");
2143 DString toFileName = yyextra->fileName;
2144 const std::unique_ptr<FileState> &fs=yyextra->includeStack.
back();
2146 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
2147 yy_switch_to_buffer( fs->bufState, yyscanner );
2148 yy_delete_buffer( oldBuf, yyscanner );
2149 yyextra->yyLineNr = fs->lineNr;
2151 yyextra->inputBuf = fs->oldFileBuf;
2152 yyextra->inputBufPos = fs->oldFileBufPos;
2153 yyextra->curlyCount = fs->curlyCount;
2154 yyextra->levelGuard = fs->levelGuard;
2156 TRACE(
"switching to {}",yyextra->fileName);
2161 lineStr.sprintf(
"# %d \"%s\" 2",yyextra->yyLineNr,
qPrint(yyextra->fileName));
2164 yyextra->includeStack.pop_back();
2187 for (
const auto &kv : yyextra->localDefines)
2189 auto pair = yyextra->contextDefines.insert(kv);
2192 yyextra->contextDefines.erase(pair.first);
2193 yyextra->contextDefines.insert(kv);
2196 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)
2201 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || YY_START==IDLquote || YY_START == PragmaOnce)
2208 yyextra->lastCContext=YY_START;
2209 yyextra->commentCount=1;
2212 yyextra->isSpecialComment =
true;
2213 yyextra->lastGuardName.clear();
2217 yyextra->isSpecialComment =
false;
2219 BEGIN(SkipCComment);
2223 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond ||
getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran || YY_START==IDLquote || YY_START == PragmaOnce)
2227 else if (YY_START==RulesRoundDouble)
2234 yyextra->lastCPPContext=YY_START;
2237 yyextra->isSpecialComment =
true;
2238 yyextra->lastGuardName.clear();
2242 yyextra->isSpecialComment =
false;
2244 BEGIN(SkipCPPComment);
2249 yyextra->yyLineNr++;
2252 yyextra->expectGuard =
false;
2262 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2263 int bytesInBuf =
static_cast<int>(state->inputBuf->size())-state->inputBufPos;
2264 int bytesToCopy = std::min(max_size,bytesInBuf);
2265 memcpy(buf,state->inputBuf->data()+state->inputBufPos,bytesToCopy);
2266 state->inputBufPos+=bytesToCopy;
2272 yy_size_t fenceSize = 0;
2273 for (
size_t i = 0; i < leng; i++)
2275 if (txt[i] !=
' ' && txt[i] !=
'*' && txt[i] !=
'\t')
break;
2278 return leng-fenceSize;
2283 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2288 if (state->yyFileDef==
nullptr)
2294 if (state->yyFileDef && state->yyFileDef->isReference()) state->yyFileDef=
nullptr;
2298 state->isFixedFormFtn =
false;
2299 if (state->insideFtn)
2305 state->isSource = section.isHeader() || section.isSource();
2310 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2311 state->levelGuard.push(
false);
2317 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2319 if (!state->levelGuard.empty())
2321 state->levelGuard.pop();
2325 if (state->condGuardErrorLine!=0)
2327 warn(state->condGuardErrorFileName,state->condGuardErrorLine,
"{}",state->condGuardErrorMessage);
2331 warn(state->fileName,state->yyLineNr,
"More #endif's than #if's found.");
2338 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2339 if (state->levelGuard.empty())
2341 warn(state->fileName,state->yyLineNr,
"Found an #else without a preceding #if.");
2346 return state->levelGuard.top();
2352 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2353 state->levelGuard.top()=value;
2359 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2360 alreadyProcessed =
false;
2361 std::unique_ptr<FileState> fs;
2372 if (state->curlyCount==0)
2377 alreadyProcessed =
true;
2384 alreadyProcessed = std::any_of(
2385 state->includeStack.begin(),
2386 state->includeStack.end(),
2387 [absName](
const std::unique_ptr<FileState> &lfs)
2388 { return lfs->fileName==absName; }
2391 if (alreadyProcessed)
2398 fs = std::make_unique<FileState>();
2407 fs->oldFileBuf = state->inputBuf;
2408 fs->oldFileBufPos = state->inputBufPos;
2416 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2427 else if (alreadyProcessed)
2432 if (localInclude && !state->fileName.empty())
2434 FileInfo fi(state->fileName.str());
2445 else if (alreadyProcessed)
2451 if (state->pathList.empty())
2455 for (
auto path : state->pathList)
2457 DString absName = path+
"/"+fileName;
2467 else if (alreadyProcessed)
2490 if (s.
empty())
return "";
2500 if (i>=0 && s[i]==
'*')
2503 while (i>0 && !(s[i-1]==
'/' && s[i]==
'*')) i--;
2510 return ((s[i+1]==
'*' || s[i+1]==
'!') && s[i+2]==
'<') ? &s[i-1] :
"";
2541 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2543 bool previous = state->boundedExpansion;
2544 state->boundedExpansion =
true;
2546 state->boundedExpansion = previous;
2553 bool inString=
false;
2558 if (!inString && !inChar)
2560 while (i<s.
length() && !inString && !inChar)
2581 while (i<s.
length() && inChar)
2602 while (i<s.
length() && inString)
2629 if (expr.
empty())
return;
2631 std::string e = expr.
str();
2632 static const reg::Ex r(R
"(\s*##\s*)");
2641 const auto &match = *it;
2642 size_t n = match.position();
2643 size_t l = match.length();
2646 bool leftEmpty = n>=2 && e.compare(n-2,2,
"@E")==0 && (n<3 || e[n-3]!=
'@');
2647 bool rightEmpty = e.compare(n+l,2,
"@E")==0;
2648 if (leftEmpty && rightEmpty)
2656 if (e.compare(n+l,2,
"@-")==0) e.erase(n+l,2);
2657 e.replace(n-2,l+2,
" ");
2663 int k=
static_cast<int>(n)-1;
2664 while (k>=0 &&
isId(e[k])) k--;
2665 if (k>0 && e[k]==
'-' && e[k-1]==
'@')
2670 size_t next=e.find_first_not_of(
" \t\r\n",n+l+2);
2671 if (next!=std::string::npos && e.compare(next,2,
"##")==0)
2679 e.replace(n,l+2,
" ");
2684 if (n+l+1<e.length() && e[
static_cast<int>(n+l)]==
'@' && expr[
static_cast<int>(n+l+1)]==
'-')
2691 e=e.substr(0,n)+e.substr(n+l);
2692 int k=
static_cast<int>(n)-1;
2693 while (k>=0 &&
isId(e[k])) k--;
2694 if (k>0 && e[k]==
'-' && e[k-1]==
'@')
2697 e=e.substr(0,k-1)+e.substr(k+1);
2723 while ((cc=
getNextChar(yyscanner,expr,rest,pos))!=EOF && cc!=0)
2742 while ((cc=
getNextChar(yyscanner,expr,rest,pos))!=EOF && cc!=0)
2755 int &cc, uint32_t &j,
int &len)
2757 bool changed =
false;
2762 while ((cc=
getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc!=
'\n' && isspace(cc))
2770 int prevChar =
'\0';
2772 if ((cc=
getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc ==
'*')
2774 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2776 if (cc ==
'/' && prevChar ==
'*')
break;
2779 if (cc != EOF) changed =
true;
2788 if (rest) remaining+=*rest;
2790 std::string readAhead;
2791 auto next = [&]() ->
int
2793 bool fromStream=cursor>=remaining.
length() && !preYYget_extra(yyscanner)->boundedExpansion;
2794 int c=
getNextChar(yyscanner,remaining,
nullptr,cursor);
2795 if (fromStream && c!=EOF && c!=0) readAhead+=
static_cast<char>(c);
2801 while (c!=EOF && c!=0 && c!=
'\n' && isspace(
static_cast<unsigned char>(c))) c=next();
2806 while ((c=next())!=EOF && c!=0 && !(previous==
'*' && c==
'/')) previous=c;
2807 if (c==EOF || c==0)
break;
2811 for (
auto it=readAhead.rbegin();it!=readAhead.rend();++it)
returnCharToStream(yyscanner,*it);
2822 size_t vl = vaStr.
length();
2825 bool hasHash = vo>0 && vaStr.
at(vo-1)==
'#';
2828 result+=vaStr.
mid(vp,vo-vp-1);
2833 result+=vaStr.
mid(vp,vo-vp);
2837 while (bc>0 && ve<vl)
2839 if (vaStr[ve]==
')') bc--;
2840 else if (vaStr[ve]==
'(') bc++;
2844 if (bc==0 && hasOptionalArgs)
2856 result+=vaStr.
mid(vp);
2888 struct MacroArgument
2893 std::map<std::string,MacroArgument> argTable;
2897 size_t expandedPrefixLength=0;
2899 int argCountNonEmpty=0;
2905 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2913 while (!done && (argCount<def->nargs || def->
varArgs) &&
2914 ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2923 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2927 if (c==
'\'' || c==
'\"')
2960 else if (c==
')' || c==
',')
2964 rawArg+=arg.
mid(expandedPrefixLength);
2969 expandedPrefixLength=arg.
length();
2973 rawArg+=arg.
mid(expandedPrefixLength);
2979 argKey.
sprintf(
"@%d",argCount++);
2980 if (c==
',' || !expandedArg.
empty()) argCountNonEmpty++;
2982 argTable.emplace(
toStdString(argKey), MacroArgument{rawArg,expandedArg});
2985 expandedPrefixLength=0;
2996 while (!found && (cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3003 if ((cc=
getNextChar(yyscanner,expr,rest,j))==EOF || cc==0)
break;
3013 while (!found && (cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3020 if ((cc=
getNextChar(yyscanner,expr,rest,j))==EOF || cc==0)
break;
3028 char prevChar =
'\0';
3032 while ((cc=
getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
3036 if (c ==
'/' && prevChar ==
'*')
break;
3049 if (argCount==def->
nargs ||
3060 bool inString=
false;
3070 else if (d.
at(k+1)==
'-')
3079 int l=
static_cast<int>(k)-1;
3081 if (l>=0 && d.
at(l)==
'"') l--;
3082 while (l>=0 && d.
at(l)==
' ') l--;
3083 if (l>0 && d.
at(l)==
'#' && d.
at(l-1)==
'#') hash=
true;
3086 while (k<d.
length() && d.
at(k)>=
'0' && d.
at(k)<=
'9') key+=d.
at(k++);
3090 l=
static_cast<int>(k);
3091 if (l<(
int)d.
length() && d.
at(l)==
'"') l++;
3092 while (l<(
int)d.
length() && d.
at(l)==
' ') l++;
3093 if (l<(
int)d.
length()-1 && d.
at(l)==
'#' && d.
at(l+1)==
'#') hash=
true;
3096 auto it = argTable.find(key.
str());
3097 if (it!=argTable.end())
3099 DString substArg = hash || inString ? it->second.raw : it->second.expanded;
3102 if (!hash && !inString)
3116 if (hash && substArg.
empty())
3127 if (!inString && d.
at(k)==
'\"')
3131 else if (k>2 && inString && d.
at(k)==
'\"' && (d.
at(k-1)!=
'\\' || d.
at(k-2)==
'\\'))
3155 while (p<(
int)expr.
length())
3157 char c=expr.
at(p++);
3162 else if (isalpha(c) || c==
'_')
3172 if (p<(
int)expr.
length()) c=expr.
at(p);
3173 while (p<(
int)expr.
length() && (c!=
'"' || (pc==
'\\' && ppc!=
'\\')))
3181 if (p<(
int)expr.
length()) ++p;
3187 if (p<(
int)expr.
length())
3193 while (p<(
int)expr.
length() && !(pc==
'*' && c==
'/'))
3206#define MAX_EXPANSION_DEPTH 50
3210 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3211 if (!state->nospaces)
3214 char ccPrev = pos==0 || (int)expr.
length()<pos ? state->prevChar : expr.
at(pos-1);
3215 DString leftSpace = ccPrev!=
':' && ccPrev!=
' ' ?
" " :
"";
3218 if (restExpr.
empty())
3220 uint32_t j=(uint32_t)resultExpr.
length();
3221 while ((ccNext=
getNextChar(yyscanner,resultExpr,
nullptr,j))!=EOF && ccNext==
' ') { }
3222 if (ccNext != EOF)
unputChar(yyscanner,resultExpr,
nullptr,j,(
char)ccNext);
3226 ccNext=restExpr.
at(0);
3229 DString rightSpace = ccNext!=
':' && ccNext!=
' ' ?
" " :
"";
3232 resultExpr=leftSpace+resultExpr+rightSpace;
3243 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3250 if (state->expanded.find(expr.
str())!=state->expanded.end() &&
3258 state->expanded.insert(expr.
str());
3262 bool definedTest=
false;
3263 int i=pos, l=0, p=0, len=0;
3268 bool replaced=
false;
3270 macroName=expr.
mid(p,l);
3275 expr=expr.
left(p)+resultExpr+restExpr;
3277 else if (p<2 || !(expr.
at(p-2)==
'@' && expr.
at(p-1)==
'-'))
3279 if (state->expandedDict.find(macroName.
str())==state->expandedDict.end())
3281 bool expanded=
false;
3285 if (yyextra->expandOnlyPredef && def && !def->
isPredefined) def=
nullptr;
3286 if (macroName==
"defined")
3291 else if (definedTest)
3293 if (def) expMacro =
" 1 ";
else expMacro =
" 0 ";
3298 else if (def && def->
nargs==-1)
3307 else if (def && def->
nargs>=0)
3318 resultExpr=expMacro;
3325 state->expandedDict.emplace(
toStdString(macroName),def);
3327 state->expandedDict.erase(
toStdString(macroName));
3336 expr=expr.
left(p)+resultExpr+restExpr;
3338 i=p+
static_cast<int>(resultExpr.
length());
3343 expr=expr.
left(p)+
"@-"+expr.
mid(p);
3355 const Define *def=state->expandedDict.find(macroName.
str())->second;
3363 expr=expr.
left(p)+
"@-"+expr.
mid(p);
3400 if (inputStr==
nullptr)
return inputStr;
3401 char term = *inputStr;
3402 if (
term!=
'\'' &&
term!=
'"')
return inputStr;
3407 while ((c=*inputStr))
3436 static const std::vector<std::string> signs = {
"signed",
"unsigned" };
3437 struct TypeInfo { std::string name;
size_t size; };
3438 static const std::vector<TypeInfo> types = {
3439 {
"short int",
sizeof(
short int) },
3440 {
"long long int",
sizeof(
long long int) },
3441 {
"long int",
sizeof(
long int) },
3442 {
"long long",
sizeof(
long long) },
3443 {
"long double",
sizeof(
long double) },
3444 {
"int",
sizeof(int) },
3445 {
"short",
sizeof(short) },
3446 {
"bool",
sizeof(bool) },
3447 {
"long",
sizeof(long) },
3448 {
"char",
sizeof(char) },
3449 {
"float",
sizeof(float) },
3450 {
"double",
sizeof(double) },
3456 auto process_cast_or_sizeof = [](
const char *p) -> std::pair<const char *,size_t>
3459 while (*q==
' ' || *q==
'\t') q++;
3461 size_t size =
sizeof(int);
3462 for (
const auto &sgn : signs)
3464 if (
dstrncmp(q,sgn.c_str(),sgn.length())==0) { q+=sgn.length(); found=
true; }
3466 if (!found || *q==
' ' || *q==
'\t' || *q==
')')
3468 while (*q==
' ' || *q==
'\t') q++;
3469 for (
const auto &t : types)
3471 if (
dstrncmp(q,t.name.c_str(),t.name.length())==0)
3473 q += t.name.length();
3478 while (*q==
' ' || *q==
'\t') q++;
3479 if (*q==
')')
return std::make_pair(++q,size);
3481 return std::make_pair(
nullptr,0);
3485 if (s.
empty())
return s;
3486 const char *p=s.
data();
3496 const char *q = process_cast_or_sizeof(p+1).first;
3506 const char *q = p+6;
3507 while (*q==
' ' || *q==
'\t') q++;
3510 auto r = process_cast_or_sizeof(q+1);
3527 else if (*(p+1)==
'E')
3533 else if (isdigit(c))
3543 else if (c==
'd' && !inNum)
3554 while ((c=*p) &&
isId(c)) p++;
3557 else if ((isalpha(c) || c==
'_') && !inNum)
3561 while ((c=*p) &&
isId(c)) p++;
3562 while ((c=*p) && isspace((uint8_t)c)) p++;
3569 if (c==
'(') count++;
3573 if (count==0)
break;
3581 while (*p && !(pc==
'*' && c==
'/'))
3598 while (*p && !(pc==
'*' && c==
'/'))
3615 char lc=(char)tolower(c);
3616 if (!
isId(lc) && lc!=
'.' ) inNum=
false;
3628 if (s.
empty())
return s;
3629 const char *p=s.
data();
3644 else if (*(p+1)==
'E')
3658 while (*p && !(pc==
'*' && c==
'/'))
3660 if (*p==
'@' && *(p+1)==
'@')
3703 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3707 state->expanded.clear();
3711 if (e.
empty())
return false;
3713 return state->constExpParser.parse(state->fileName.data(),state->yyLineNr,e.
str(),ee.
str());
3723 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3724 state->prevChar = yyscanner->yytext_r > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ? *(yyscanner->yytext_r-1) : 0;
3726 state->expanded.clear();
3738 if (name ==
"__LINE__")
3742 else if (name ==
"__FILE__")
3745 resultExpr += yyextra->fileName;
3748 else if (name ==
"__DATE__")
3751 resultExpr += __DATE__;
3754 else if (name ==
"__TIME__")
3757 resultExpr += __TIME__;
3765 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3767 def.
name = state->defName;
3769 def.
nargs = state->defArgs;
3771 def.
fileDef = state->yyFileDef;
3772 def.
lineNr = state->yyLineNr-state->yyMLines;
3774 def.
varArgs = state->defVarArgs;
3784 auto it = state->localDefines.find(def.
name.
str());
3785 if (it!=state->localDefines.end())
3787 state->localDefines.erase(it);
3789 state->localDefines.emplace(def.
name.
str(),def);
3794 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3795 if (state->skip)
return;
3800 define.
lineNr = state->yyLineNr - state->yyMLines;
3802 define.
name = state->defName;
3803 define.
args = state->defArgsStr;
3804 define.
fileDef = state->inputFileDef;
3806 DString litText = state->defLitText;
3807 size_t l=litText.
find(
'\n');
3811 litText = litText.
mid(l+1);
3817 const char *p=litText.
data()+k;
3819 while ((c=*p++) && (c==
' ' || c==
'\t')) k++;
3823 if (litTextStripped.
contains(
'\n')>=1)
3832 state->macroDefinitions.push_back(define);
3838 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3839 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=c;
3844 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3845 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=std::string_view(a,len);
3850 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3851 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=a.
str();
3874 if (!yyextra->defContinue)
return;
3875 for (
int i=0; i< (int)yyleng; i++)
3877 if (yytext[i] ==
'\t')
3878 yyextra->defExtraSpacing+=
'\t';
3880 yyextra->defExtraSpacing+=
' ';
3887 yyextra->fenceSize=0;
3889 if (yytext[1]==
'f' && ((c=yytext[2])==
'[' || c==
'{' || c==
'(' || c==
'$'))
3893 case '[': yyextra->blockName=
"]";
break;
3894 case '{': yyextra->blockName=
"}";
break;
3895 case '(': yyextra->blockName=
")";
break;
3896 case '$': yyextra->blockName=
"$";
break;
3899 yyextra->blockName=yyextra->blockName.stripWhiteSpace();
3906 yyextra->blockName=
"uml";
3910 if (
size_t i = bn.
find(
'{');
3912 yyextra->blockName=bn;
3920 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3925 (inc.
at(i)==
' ' || inc.
at(i)==
'"' || inc.
at(i)==
'<')
3930 bool localInclude = s>0 && inc.
at(s-1)==
'"';
3933 while (i<inc.
length() && inc.
at(i)!=
'"' && inc.
at(i)!=
'>') i++;
3935 if (s<inc.
length() && i>s)
3945 DString oldFileName = state->fileName;
3946 FileDef *oldFileDef = state->yyFileDef;
3947 int oldLineNr = state->yyLineNr;
3953 std::unique_ptr<FileState> fs;
3954 bool alreadyProcessed =
false;
3956 fs=
findFile(yyscanner,absIncFileName,localInclude,alreadyProcessed);
3967 for (i=0;i<state->includeStack.size();i++)
3974 if (state->includeStack.empty() && oldFileDef)
3976 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
3981 state->includeRelations.add(
3984 ambig ?
nullptr : incFd,
3993 fs->bufState = YY_CURRENT_BUFFER;
3994 fs->lineNr = oldLineNr;
3995 fs->fileName = oldFileName;
3996 fs->curlyCount = state->curlyCount;
3998 fs->lexRulesPart = state->lexRulesPart;
3999 fs->levelGuard = state->levelGuard;
4000 while (!state->levelGuard.empty()) state->levelGuard.pop();
4001 state->lexRulesPart =
false;
4004 state->includeStack.push_back(std::move(fs));
4014 state->expectGuard=
true;
4015 state->inputBuf = &fs_ptr->
fileBuf;
4016 state->inputBufPos=0;
4017 yy_switch_to_buffer(yy_create_buffer(0,
YY_BUF_SIZE, yyscanner),yyscanner);
4021 if (alreadyProcessed)
4029 if (state->includeStack.empty() && oldFileDef)
4031 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
4036 ii = state->includeRelations.add(absIncFileName,
4038 ambig ?
nullptr : incFd,
4048 for (i=0;i<state->includeStack.size();i++)
4052 if (alreadyProcessed)
4062 if (localInclude && !state->includeStack.empty() && state->curlyCount>0 && !alreadyProcessed)
4064 warn(state->fileName,state->yyLineNr,
"include file {} not found, perhaps you forgot to add its directory to INCLUDE_PATH?",incFileName);
4074 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4077 bool expResult = prs.
parse(state->fileName.data(),state->yyLineNr,sectId.
data());
4078 state->condStack.emplace(std::make_unique<preYY_CondCtx>(state->fileName,state->yyLineNr,sectId,state->skip));
4088 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4089 if (state->condGuardCount>0 && state->condGuardErrorLine==0)
4091 state->condGuardErrorLine = state->yyLineNr;
4092 state->condGuardErrorFileName = state->fileName;
4093 state->condGuardErrorMessage =
"more #if's than #endif's in \\cond..\\endcond section";
4095 else if (state->condGuardCount<0 && state->condGuardErrorLine==0)
4097 state->condGuardErrorLine = state->yyLineNr;
4098 state->condGuardErrorFileName = state->fileName;
4099 state->condGuardErrorMessage =
"more #endif's than #if's in \\cond..\\endcond section";
4103 state->condGuardErrorLine = 0;
4105 if (state->condStack.empty())
4107 warn(state->fileName,state->yyLineNr,
"the \\endcond does not have a corresponding \\cond in this file");
4112 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4113 state->skip=ctx->skip;
4114 state->condStack.pop();
4121 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4122 while (!state->condStack.empty())
4124 state->condStack.pop();
4135 const char *p=text.
data();
4138 if (c==
'@') result+=
"@@";
else result+=c;
4148 case '=':
return '#';
4149 case '/':
return '\\';
4150 case '\'':
return '^';
4151 case '(':
return '[';
4152 case ')':
return ']';
4153 case '!':
return '|';
4154 case '<':
return '{';
4155 case '>':
return '}';
4156 case '-':
return '~';
4170 return expr.
at(pos++);
4172 else if (rest && !rest->
empty())
4179 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4181 int cc=yyinput(yyscanner);
4194 return expr.
at(pos);
4196 else if (rest && !rest->
empty())
4202 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4204 int cc=yyinput(yyscanner);
4222 char cs[2];cs[0]=c;cs[1]=
'\0';
4225 else if (!preYYget_extra(yyscanner)->boundedExpansion)
4238 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4241 auto findDefine = [&undef,&name](
DefineMap &map)
4244 auto it = map.find(name.str());
4257 Define *def = findDefine(state->localDefines);
4258 if (def==
nullptr && !undef)
4260 def = findDefine(state->contextDefines);
4267 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4271 for (
const auto &ds : predefList)
4273 size_t i_equals=ds.find(
'=');
4274 size_t i_obrace=ds.find(
'(');
4275 size_t i_cbrace=ds.find(
')');
4276 bool nonRecursive = i_equals!=std::string::npos && i_equals>0 && ds[i_equals-1]==
':';
4278 if ((i_obrace==0) || (i_equals==0) || (i_equals==1 && ds[i_equals-1]==
':'))
4283 if (i_obrace<i_equals && i_cbrace<i_equals &&
4284 i_obrace!=std::string::npos && i_cbrace!=std::string::npos &&
4288 static const reg::Ex reId(R
"(\a\w*)");
4289 std::map<std::string,int> argMap;
4290 std::string args = ds.substr(i_obrace+1,i_cbrace-i_obrace-1);
4291 bool hasVarArgs = args.find(
"...")!=std::string::npos;
4297 for (; arg_it!=arg_end; ++arg_it)
4299 argMap.emplace(arg_it->
str(),count++);
4303 argMap.emplace(
"__VA_ARGS__",count++);
4307 std::string definition;
4308 std::string in=ds.substr(i_equals+1);
4314 for (; re_it!=re_end; ++re_it)
4316 const auto &match = *re_it;
4317 size_t pi = match.position();
4318 size_t l = match.length();
4319 if (pi>i) definition+=in.substr(i,pi-i);
4321 auto it = argMap.find(match.str());
4322 if (it!=argMap.end())
4324 int argIndex = it->second;
4326 marker.
sprintf(
" @%d ",argIndex);
4327 definition+=marker.
str();
4331 definition+=match.str();
4335 definition+=in.substr(i);
4338 std::string dname = ds.substr(0,i_obrace);
4347 def.
fileDef = state->yyFileDef;
4350 state->contextDefines.emplace(def.
name.
str(),def);
4356 else if (!ds.empty())
4360 if (i_equals==std::string::npos)
4367 int ine=
static_cast<int>(i_equals) - (nonRecursive ? 1 : 0);
4376 def.
fileDef = state->yyFileDef;
4378 state->contextDefines.emplace(def.
name.
str(),def);
4394 YY_EXTRA_TYPE state = preYYget_extra(
p->yyscanner);
4401 preYYlex_init_extra(&
p->state,&
p->yyscanner);
4407 preYYlex_destroy(
p->yyscanner);
4414 YY_EXTRA_TYPE state = preYYget_extra(
p->yyscanner);
4428 state->curlyCount=0;
4429 state->lexRulesPart=
false;
4430 state->nospaces=
false;
4431 state->inputBuf=&input;
4432 state->inputBufPos=0;
4433 state->outputBuf=&output;
4434 state->includeStack.clear();
4435 state->expandedDict.clear();
4436 state->contextDefines.clear();
4437 state->pragmaSet.clear();
4438 state->condGuardCount=0;
4439 state->condGuardErrorLine=0;
4440 while (!state->levelGuard.empty()) state->levelGuard.pop();
4441 while (!state->condStack.empty()) state->condStack.pop();
4445 state->inputFileDef = state->yyFileDef;
4450 state->yyLineNr = 1;
4457 state->guardName.clear();
4458 state->lastGuardName.clear();
4459 state->guardExpr.clear();
4461 preYYlex(yyscanner);
4463 while (!state->condStack.empty())
4465 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4467 if (ctx->sectionId!=
" ") sectionInfo.
sprintf(
" with label '%s' ",
qPrint(ctx->sectionId.stripWhiteSpace()));
4468 warn(ctx->fileName,ctx->lineNr,
"Conditional section{}does not have "
4469 "a corresponding \\endcond command within this file.",sectionInfo);
4470 state->condStack.pop();
4475 if (!state->levelGuard.empty())
4477 if (yyextra->condGuardErrorLine!=0)
4479 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,
"{}",yyextra->condGuardErrorMessage);
4483 warn(state->fileName,state->yyLineNr,
"More #if's than #endif's found (might be in an included file).");
4491 std::string contents;
4499 bool startOfLine =
true;
4500 size_t content_size = output.size() +
4503 contents.reserve(content_size);
4505 while (pos<output.size())
4510 snprintf(lineNrStr,15,
"%05d ",line++);
4511 contents+=lineNrStr;
4513 contents += output[pos];
4514 startOfLine = output[pos]==
'\n';
4519 if (!contents.empty() && contents[contents.length()-1]!=
'\n')
4524 if (yyextra->contextDefines.size()>0)
4528 for (
auto &kv : yyextra->contextDefines)
4532 for (
auto &kv : yyextra->localDefines)
4546 for (
const auto &inc : state->includeRelations)
4548 auto toKind = [](
bool local,
bool imported) ->
IncludeKind
4564 if (inc->fromFileDef)
4566 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4568 if (inc->toFileDef && inc->fromFileDef)
4570 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)