40%option never-interactive
41%option case-insensitive
42%option prefix="fortranscannerYY"
44%option extra-type="struct fortranscannerYY_state *"
48#define YY_TYPEDEF_YY_SCANNER_T
49#define yyguts_t fortranscannerYYguts_t
64#include <unordered_map>
65#include <unordered_set>
81#define DBG_CTX(x) do { } while(0)
84#define YY_NO_UNISTD_H 1
141 "",
"intent(in)",
"intent(out)",
"intent(inout)"
145 "",
"[in]",
"[out]",
"[in,out]"
217 std::map<Entry*,std::map<std::string,SymbolModifiers> >
modifiers;
250static void copyEntry(std::shared_ptr<Entry> dest,
const std::shared_ptr<Entry> &src);
267#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
272#define YY_USER_ACTION yyextra->colNr+=(int)yyleng;
273#define INVALID_ENTRY ((Entry*)0x8)
This class contains the information about the argument of a function or template.
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Represents an unstructured piece of information, about an entity found in the sources.
Abstract interface for outline parsers.
std::vector< std::shared_ptr< Entry > > EntryList
static int getAmpersandAtTheStart(const char *buf, int length)
static const char * directionParam[]
static DString extractFromParens(const DString &name)
static void resolveModuleProcedures(yyscan_t yyscanner, Entry *current_root)
fill empty interface module procedures with info from corresponding module subprogs
static void newLine(yyscan_t yyscanner)
static void popBlockState(yyscan_t yyscanner)
static void addCurrentEntry(yyscan_t yyscanner, bool case_insens)
adds yyextra->current entry to yyextra->current_root and creates new yyextra->current
static void pushBuffer(yyscan_t yyscanner, const DString &buffer)
static int computeIndent(const char *s)
static void addSubprogram(yyscan_t yyscanner, const DString &text)
static void startCommentBlock(yyscan_t yyscanner, bool)
static void addModule(yyscan_t yyscanner, const DString &name=DString(), bool isModule=false)
static void startScope(yyscan_t yyscanner, Entry *scope)
static int getAmpOrExclAtTheEnd(const char *buf, int length, char ch)
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
static void subrHandleCommentBlockResult(yyscan_t yyscanner, const DString &doc, bool brief)
Handle result description as defined after the declaration of the parameter.
static const char * stateToString(int state)
static void popBuffer(yyscan_t yyscanner)
static void addInterface(yyscan_t yyscanner, DString name, InterfaceType type)
static void copyEntry(std::shared_ptr< Entry > dest, const std::shared_ptr< Entry > &src)
used to copy entry to an interface module procedure
static const char * directionStrs[]
static void scanner_abort(yyscan_t yyscanner)
static void pushBlockState(yyscan_t yyscanner, const DString &text)
static void pop_state(yyscan_t yyscanner)
static void resolveTypeBoundProcedures(Entry *scope)
static DString extractBind(const DString &name)
static void updateVariablePrepassComment(yyscan_t yyscanner, int from, int to)
static Argument * getParameter(yyscan_t yyscanner, const DString &name)
static void subrHandleCommentBlock(yyscan_t yyscanner, const DString &doc, bool brief)
Handle parameter description as defined after the declaration of the parameter.
static bool endScope(yyscan_t yyscanner, Entry *scope, bool isGlobalRoot=false)
static const char * getLexerFILE()
static const CommentInPrepass * locatePrepassComment(yyscan_t yyscanner, int from, int to)
static void handleCommentBlock(yyscan_t yyscanner, const DString &doc, bool brief)
static void truncatePrepass(yyscan_t yyscanner, int index)
static void initEntry(yyscan_t yyscanner)
BlockState(DString str, int lineNr)
Holds yyextra->modifiers (ie attributes) for one symbol (variable, function, etc).
SymbolModifiers & operator|=(const SymbolModifiers &mdfs)
DString type
This is only used with function return value.
DString inputStringPrepass
Input string for prepass of line cont. '&'.
std::map< Entry *, std::map< std::string, SymbolModifiers > > modifiers
Holds program scope->symbol name->symbol modifiers.
YY_BUFFER_STATE * includeStack
std::shared_ptr< Entry > last_enum
OutlineParserInterface * thisParser
SymbolModifiers currentModifiers
Accumulated modifiers of current statement, eg variable declaration.
unsigned int inputPositionPrepass
std::shared_ptr< Entry > global_root
std::vector< CommentInPrepass > comments
DString inputStringSemi
Input string after command separator ';'.
EntryList moduleProcedures
CommentScanner commentScanner
int initializerArrayScope
std::stack< BlockState > blockStack
std::shared_ptr< Entry > last_entry
Protection defaultProtection
Protection typeProtection
int mainPrograms
counter for the number of main programs in this file
std::shared_ptr< Entry > current
std::shared_ptr< Entry > file_root
A bunch of utility functions.
285ID [a-z_A-Z%]+{IDSYM}*
286ID_ [a-z_A-Z%]*{IDSYM}*
287OPERATOR_ID (operator{BS}"("{BS}(\.[a-z_A-Z]+\.|"="|"/="|"//"|"=="|"<"|"<="|">"|">="|"+"|"*"|"**"|"/"|"-"){BS}")")
288SUBPROG (subroutine|function)
292BT_ ([ \t]+|[ \t]*"(")
295ARGS_L1a [^()]*"("[^)]*")"[^)]*
296ARGS_L1 ("("{ARGS_L1a}*")")
297ARGS_L2 "("({ARGS_L0}|[^()]|{ARGS_L1a}|{ARGS_L1})*")"
298ARGS {BS}({ARGS_L0}|{ARGS_L1}|{ARGS_L2})
305NUM_TYPE (complex|integer|logical|real)
306LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
308CHAR (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS}))
309TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|ENUMERATOR|{CHAR}|TYPE{ARGS}|CLASS{ARGS}|PROCEDURE{ARGS}?)
311INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")"
312ATTR_SPEC (EXTERNAL|ALLOCATABLE|DIMENSION{ARGS}|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|PRIVATE|PUBLIC|SAVE|TARGET|NOPASS|PASS{ARGS}?|DEFERRED|NON_OVERRIDABLE|CONTIGUOUS|VOLATILE|VALUE)
313LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}((,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})|(,{BS}NAME{BS}"="{BS}"'"(.*)"'"{BS}))?")"
315ATTR_STMT {ATTR_SPEC}|DIMENSION
316EXTERNAL_STMT (EXTERNAL)
319PREFIX ((NON_)?RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,4}((NON_)?RECURSIVE|IMPURE|PURE|ELEMENTAL)?
320SCOPENAME ({ID}{BS}"::"{BS})*
322LINENR {B}*[1-9][0-9]*
323FILEICHAR [a-z_A-Z0-9\x80-\xFF\\:\\\/\-\+=&#@~]
324FILEECHAR [a-z_A-Z0-9\x80-\xFF\-\+=&#@~]
325FILECHARS {FILEICHAR}*{FILEECHAR}+
326HFILEMASK {FILEICHAR}*("."{FILEICHAR}+)+{FILECHARS}*
327VFILEMASK {FILECHARS}("."{FILECHARS})*
328FILEMASK {VFILEMASK}|{HFILEMASK}
342%x SubprogBodyContains
356%x TypedefBodyContains
382<Prepass>^{BS}[&]*{BS}!.*\n {
383 yyextra->lineCountPrepass ++;
386 yyextra->lineCountPrepass ++;
389 yyextra->functionLine =
false;
391 DBG_CTX((stderr,
"---%s", yytext));
395 if (indexEnd>=0 && yytext[indexEnd]!=
'&')
402 if (YY_START == Prepass)
406 yyextra->inputStringPrepass+=(
const char*)(yytext+(indexStart+1));
409 pushBuffer(yyscanner,yyextra->inputStringPrepass);
421 if (YY_START != Prepass)
423 yyextra->comments.clear();
424 yyextra->inputStringPrepass=
DString();
425 yy_push_state(Prepass,yyscanner);
428 size_t length = yyextra->inputStringPrepass.length();
431 yyextra->inputStringPrepass+=(
const char*)(yytext+(indexStart+1));
432 yyextra->lineCountPrepass ++;
435 truncatePrepass(yyscanner,
static_cast<int>(length) + indexEnd - indexStart - 1);
442 if (yytext[0]!=yyextra->stringStartSymbol)
444 yyextra->colNr -= (int)yyleng;
447 if (yy_top_state(yyscanner) == Initialization ||
448 yy_top_state(yyscanner) == ArrayInitializer)
450 yyextra->initializer+=yytext;
454<String>[\x80-\xFF]* |
455<String>. {
if (yy_top_state(yyscanner) == Initialization ||
456 yy_top_state(yyscanner) == ArrayInitializer)
458 yyextra->initializer+=yytext;
462 if (YY_START == StrIgnore)
463 { yyextra->colNr -= (int)yyleng;
466 yy_push_state(YY_START,yyscanner);
467 if (yy_top_state(yyscanner) == Initialization ||
468 yy_top_state(yyscanner) == ArrayInitializer)
470 yyextra->initializer+=yytext;
472 yyextra->stringStartSymbol=yytext[0];
478<*>"!"/([^<>\n]|"<ff>"|"<FF>") {
if (YY_START == String || YY_START == DocCopyBlock)
479 { yyextra->colNr -= (int)yyleng;
484 if ((YY_START != StrIgnore) && (YY_START != String))
486 yy_push_state(YY_START,yyscanner);
488 yyextra->debugStr=
"*!";
489 DBG_CTX((stderr,
"start comment %d\n",yyextra->lineNr));
493 DBG_CTX((stderr,
"end comment %d %s\n",yyextra->lineNr,
qPrint(yyextra->debugStr)));
const char * qPrint(const char *s)
495<StrIgnore>[\x80-\xFF]* |
496<StrIgnore>. { yyextra->debugStr+=yytext; }
501<Start,ModuleBody,SubprogBody>"use"{BS_} {
502 if (YY_START == Start)
506 yy_push_state(ModuleBody,yyscanner);
508 yy_push_state(Use,yyscanner);
511 DBG_CTX((stderr,
"using dir %s\n",yytext));
512 yyextra->current->name=yytext;
513 yyextra->current->name=yyextra->current->name.lower();
514 yyextra->current->fileName = yyextra->fileName;
515 yyextra->current->section=EntryType::makeUsingDir();
516 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
517 yyextra->current->lang = SrcLangExt::Fortran;
521 yyextra->useModuleName=yytext;
522 yyextra->useModuleName=yyextra->useModuleName.lower();
524<Use>,{BS}"ONLY" { BEGIN(UseOnly);
528 yyextra->current->name= yyextra->useModuleName+
"::"+yytext;
529 yyextra->current->name=yyextra->current->name.lower();
530 yyextra->current->fileName = yyextra->fileName;
531 yyextra->current->section=EntryType::makeUsingDecl();
532 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
533 yyextra->current->lang = SrcLangExt::Fortran;
542<Start,ModuleBody,SubprogBody>{
543^{BS}interface{IDSYM}+ { }
545 yy_push_state(InterfaceBody,yyscanner);
550^{BS}abstract{BS_}interface { yyextra->ifType =
IF_ABSTRACT;
551 yy_push_state(InterfaceBody,yyscanner);
556^{BS}interface{BS_}{ID}{ARGS}? { yyextra->ifType =
IF_GENERIC;
557 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1;
558 yy_push_state(InterfaceBody,yyscanner);
562 name =
name.mid(9).stripWhiteSpace().lower();
564 startScope(yyscanner,yyextra->last_entry.get());
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
const char * name(int level)
568<InterfaceBody>^{BS}end{BS}interface({BS_}{ID})? {
572 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr - 1;
581<InterfaceBody>module{BS}procedure { yy_push_state(YY_START,yyscanner);
582 BEGIN(ModuleProcedure);
588 startScope(yyscanner,yyextra->last_entry.get());
591 yyextra->current->section = EntryType::makeFunction();
592 yyextra->current->name =
name;
593 yyextra->moduleProcedures.push_back(yyextra->current);
596<ModuleProcedure>"\n" { yyextra->colNr -= 1;
603<Start>^{BS}{CONTAINS}/({BS}|\n|!|;) {
604 if (YY_START == Start)
607 yy_push_state(ModuleBodyContains,yyscanner);
610<ModuleBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(ModuleBodyContains); }
611<SubprogBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(SubprogBodyContains); }
612<TypedefBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(TypedefBodyContains); }
615<Start>block{BS}data{BS}{ID_} {
617 yy_push_state(BlockData,yyscanner);
618 yyextra->defaultProtection = Protection::Public;
620<Start>module|program{BS_} {
622 if (yytext[0]==
'm' || yytext[0]==
'M')
624 yy_push_state(Module,yyscanner);
628 yy_push_state(Program,yyscanner);
630 yyextra->defaultProtection = Protection::Public;
632<BlockData>^{BS}"end"({BS}(block{BS}data)({BS_}{ID})?)?{BS}/(\n|!|;) {
635 yyextra->defaultProtection = Protection::Public;
638<Start,ModuleBody,ModuleBodyContains>"end"({BS}(module|program)({BS_}{ID})?)?{BS}/(\n|!|;) {
640 if (!
endScope(yyscanner,yyextra->current_root))
644 yyextra->defaultProtection = Protection::Public;
645 if (yyextra->global_scope)
649 yy_push_state(Start,yyscanner);
658 yy_push_state(Start,yyscanner);
676<ModuleBody,TypedefBody,TypedefBodyContains>private/{BS}(\n|"!") {
677 yyextra->defaultProtection = Protection::Private;
678 yyextra->current->protection = yyextra->defaultProtection ;
680<ModuleBody,TypedefBody,TypedefBodyContains>public/{BS}(\n|"!") {
681 yyextra->defaultProtection = Protection::Public;
682 yyextra->current->protection = yyextra->defaultProtection ;
687<ModuleBody>^{BS}type{BS}"=" {}
688<Start,ModuleBody>^{BS}type/[^a-z0-9_] {
689 if (YY_START == Start)
693 yy_push_state(ModuleBody,yyscanner);
696 yy_push_state(Typedef,yyscanner);
697 yyextra->current->protection = Protection::Package;
698 yyextra->typeProtection = Protection::Public;
699 yyextra->typeMode =
true;
707 yyextra->current->spec.setAbstractClass(
true);
711 yyextra->current->extends.emplace_back(basename, Protection::Public, Specifier::Normal);
714 yyextra->current->protection = Protection::Public;
717 yyextra->current->protection = Protection::Private;
719{LANGUAGE_BIND_SPEC} {
723 yyextra->current->section = EntryType::makeClass();
724 yyextra->current->spec.setStruct(
true);
725 yyextra->current->name = yytext;
726 yyextra->current->fileName = yyextra->fileName;
727 yyextra->current->bodyLine = yyextra->lineNr;
728 yyextra->current->startLine = yyextra->lineNr;
731 if (yyextra->current_root &&
732 (yyextra->current_root->section.isClass() ||
733 yyextra->current_root->section.isNamespace()))
735 yyextra->current->name = yyextra->current_root->name +
"::" + yyextra->current->name;
739 if( yyextra->current->protection == Protection::Package )
741 yyextra->current->protection = yyextra->defaultProtection;
743 else if( yyextra->current->protection == Protection::Public )
745 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()] |=
DString(
"public");
747 else if( yyextra->current->protection == Protection::Private )
749 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()] |=
DString(
"private");
753 startScope(yyscanner,yyextra->last_entry.get());
758<TypedefBodyContains>{
759^{BS}PROCEDURE{ARGS}? {
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
763 yyextra->current->spec.setFinal(
true);
778 yyextra->modifiers[yyextra->current_root][
name.lower().str()] |= yyextra->currentModifiers;
779 yyextra->current->section = EntryType::makeFunction();
780 yyextra->current->name =
name;
788 yyextra->current->args =
name.lower();
790 yyextra->current->fileName = yyextra->fileName;
791 yyextra->current->bodyLine = yyextra->lineNr;
792 yyextra->current->startLine = yyextra->lineNr;
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
797 size_t i = tmp.
find(
"=>");
803 if (yyextra->last_entry->type ==
"generic")
811 copyEntry(yyextra->current, yyextra->last_entry);
812 yyextra->current->name = yyextra->last_entry->name;
813 yyextra->current->section = EntryType::makeFunction();
822 yyextra->last_entry->args = tmp;
DString & remove(size_t index, size_t len)
size_t find(char c, size_t pos=0) const
DString left(size_t len) const
827 yyextra->docBlock.clear();
832<TypedefBody,TypedefBodyContains>{
833^{BS}"end"{BS}"type"({BS_}{ID})?{BS}/(\n|!|;) {
834 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr;
835 if (!
endScope(yyscanner,yyextra->current_root))
839 yyextra->typeMode =
false;
842^{BS}"end"{BS}/(\n|!|;) {
843 warn(yyextra->fileName,yyextra->lineNr,
"Found 'END' instead of 'END TYPE'");
844 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr;
845 if (!
endScope(yyscanner,yyextra->current_root))
849 yyextra->typeMode =
false;
#define warn(file, line, fmt,...)
856<SubprogBody,SubprogBodyContains>^{BS}[0-9]*{BS}"end"({BS}{SUBPROG}({BS_}{ID})?)?{BS}/(\n|!|;) {
864 endScope(yyscanner,yyextra->current_root);
865 yyextra->last_entry->endBodyLine = yyextra->lineNr - 1;
867 yyextra->current_root->endBodyLine = yyextra->lineNr - 1;
869 if (!
endScope(yyscanner,yyextra->current_root))
873 yyextra->subrCurrent.pop_back();
882<Start,ModuleBody,TypedefBody,SubprogBody,FEnum>{
883^{BS}{TYPE_SPEC}/{SEPARATE} {
884 yyextra->last_enum.reset();
885 if (YY_START == FEnum)
887 yyextra->argType =
"@";
893 yyextra->current->bodyLine = yyextra->lineNr + 1;
894 yyextra->current->endBodyLine = yyextra->lineNr + yyextra->lineCountPrepass;
896 if (YY_START == Start)
900 yy_push_state(ModuleBody,yyscanner);
902 yy_push_state(AttributeList,yyscanner);
904{EXTERNAL_STMT}/({BS}"::"|{BS_}{ID}) {
906 if (YY_START == Start)
910 yy_push_state(ModuleBody,yyscanner);
915 yy_push_state(AttributeList,yyscanner);
917{ATTR_STMT}/{BS_}{ID} |
918{ATTR_STMT}/{BS}"::" {
920 DBG_CTX((stderr,
"5=========> Attribute statement: %s\n", yytext));
921 if (YY_START == Start)
925 yy_push_state(ModuleBody,yyscanner);
930 yy_push_state(YY_START,yyscanner);
931 BEGIN( AttributeList ) ;
934 if (YY_START == Start)
938 yy_push_state(ModuleBody,yyscanner);
946 yy_push_state(ModuleBody,yyscanner);
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
949^{BS}"type"{BS_}"is"/{BT_} {}
951^{BS}"class"{BS_}"is"/{BT_} {}
952^{BS}"class"{BS_}"default" {}
957{LANGUAGE_BIND_SPEC} {
958 yyextra->currentModifiers |= yytext;
962 char chr = yytext[(int)yyleng-1];
965 yyextra->colNr -= (int)yyleng;
973 unput(yytext[(
int)yyleng-1]);
974 yyextra->currentModifiers |= (tmp);
size_t length() const
Returns the length of the string, not counting the 0-terminator.
bool isId(char c)
Returns true if c is a valid character for an identifier.
989<FVariable>{OPERATOR_ID} {
993 int currentState = YY_START;
995 int outerState = YY_START;
996 yy_push_state(currentState,yyscanner);
997 if( outerState == Start || outerState == ModuleBody )
999 if ((yyextra->current_root) &&
1000 (yyextra->current_root->section.isClass() ||
1001 yyextra->current_root->section.isNamespace()))
1003 name = yyextra->current_root->name +
"::" +
name;
1007 yyextra->modifiers[yyextra->current_root][
name.str()] |= yyextra->currentModifiers;
1015 if ((yyextra->current_root) && yyextra->current_root->section.isNamespace())
1017 name = yyextra->current_root->name +
"::" +
name;
1020 yyextra->modifiers[yyextra->current_root][
name.lower().str()] |= yyextra->currentModifiers;
1021 yyextra->argName=
name;
1024 if (!yyextra->argType.empty() && !yyextra->current_root->section.isFunction())
1027 yyextra->current->section = EntryType::makeVariable();
1028 yyextra->current->name = yyextra->argName;
1029 yyextra->current->type = yyextra->argType;
1030 yyextra->current->fileName = yyextra->fileName;
1031 yyextra->current->bodyLine = yyextra->lineNr;
1032 yyextra->current->startLine = yyextra->lineNr;
1033 if (yyextra->argType ==
"@")
1035 yyextra->current_root->copyToSubEntry(yyextra->current);
1037 yyextra->last_enum = yyextra->current;
1038 yyextra->current_root->parent()->moveToSubEntryAndRefresh(yyextra->current);
1046 else if (!yyextra->argType.empty())
1053 if (!yyextra->docBlock.empty())
1061 yyextra->modifiers[yyextra->current_root][
name.lower().str()].type = yyextra->argType;
1065 if ((yyextra->current_root->name.lower() == yyextra->argName.lower()) ||
1066 (yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower().str()].returnName.lower() == yyextra->argName.lower()))
1068 size_t strt = yyextra->current_root->type.find(
"function");
1077 if ((yyextra->current_root->type.length() - strt - strlen(
"function"))!= 0)
1079 rght = yyextra->current_root->type.
right(yyextra->current_root->type.length() - strt - (
int)strlen(
"function")).
stripWhiteSpace();
1081 yyextra->current_root->type = lft;
1084 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type +=
" ";
1085 yyextra->current_root->type += rght;
1087 if (yyextra->argType.stripWhiteSpace().length() > 0)
1089 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type +=
" ";
1090 yyextra->current_root->type += yyextra->argType.stripWhiteSpace();
1092 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type +=
" ";
1093 yyextra->current_root->type +=
"function";
1094 if (!yyextra->docBlock.empty())
1101 yyextra->current_root->type +=
" " + yyextra->argType.stripWhiteSpace();
1103 yyextra->current_root->type = yyextra->current_root->type.
stripWhiteSpace();
1104 yyextra->modifiers[yyextra->current_root][
name.lower().str()].type = yyextra->current_root->type;
1108 yyextra->modifiers[yyextra->current_root][
name.lower().str()].type = yyextra->argType;
1114 yyextra->current->doc.clear();
1115 yyextra->current->brief.clear();
DString right(size_t len) const
1122 yyextra->modifiers[yyextra->current_root][
name.lower().str()] |= attr;
1129 yy_push_state(YY_START,yyscanner);
1130 yyextra->initializer=
"=";
1131 yyextra->initializerScope = yyextra->initializerArrayScope = 0;
1132 BEGIN(Initialization);
1137 yyextra->docBlock.clear();
1141 yyextra->docBlock.clear();
1142 yyextra->inputStringSemi =
" \n"+
DString(yytext+1);
1144 pushBuffer(yyscanner,yyextra->inputStringSemi);
1147 if (YY_START == FVariable) REJECT;
1148 if (YY_START == String) REJECT;
1149 if (YY_START == StrIgnore) REJECT;
1150 if (YY_START == DocBlock) REJECT;
1151 yyextra->inputStringSemi =
" \n"+
DString(yytext+1);
1153 pushBuffer(yyscanner,yyextra->inputStringSemi);
1156<Initialization,ArrayInitializer>"[" |
1157<Initialization,ArrayInitializer>"(/" { yyextra->initializer+=yytext;
1158 yyextra->initializerArrayScope++;
1159 BEGIN(ArrayInitializer);
1161<ArrayInitializer>"]" |
1162<ArrayInitializer>"/)" { yyextra->initializer+=yytext;
1163 yyextra->initializerArrayScope--;
1164 if (yyextra->initializerArrayScope<=0)
1166 yyextra->initializerArrayScope = 0;
1167 BEGIN(Initialization);
1170<ArrayInitializer>. { yyextra->initializer+=yytext; }
1171<Initialization>"(" { yyextra->initializerScope++;
1172 yyextra->initializer+=yytext;
1174<Initialization>")" { yyextra->initializerScope--;
1175 yyextra->initializer+=yytext;
1177<Initialization>{COMMA} {
if (yyextra->initializerScope == 0)
1181 if (yyextra->last_enum)
1183 yyextra->last_enum->initializer.str(yyextra->initializer.str());
1187 if (yyextra->vtype ==
V_VARIABLE) yyextra->last_entry->initializer.str(yyextra->initializer.str());
1192 yyextra->initializer+=
", ";
1195<Initialization>"\n"|"!" {
1197 if (yyextra->last_enum)
1199 yyextra->last_enum->initializer.str(yyextra->initializer.str());
1203 if (yyextra->vtype ==
V_VARIABLE) yyextra->last_entry->initializer.str(yyextra->initializer.str());
1205 yyextra->colNr -= 1;
1208<Initialization>. { yyextra->initializer+=yytext; }
1210<*>{BS}"enum"{BS}","{BS}"bind"{BS}"("{BS}"c"{BS}")"{BS} {
1211 if (YY_START == Start)
1215 yy_push_state(ModuleBody,yyscanner);
1218 yy_push_state(FEnum,yyscanner);
1219 yyextra->current->protection = yyextra->defaultProtection;
1220 yyextra->typeProtection = yyextra->defaultProtection;
1221 yyextra->typeMode =
true;
1223 yyextra->current->spec.setStruct(
true);
1224 yyextra->current->name.clear();
1225 yyextra->current->args.clear();
1226 yyextra->current->name.sprintf(
"@%d",yyextra->anonCount++);
1228 yyextra->current->section = EntryType::makeEnum();
1229 yyextra->current->fileName = yyextra->fileName;
1230 yyextra->current->startLine = yyextra->lineNr;
1231 yyextra->current->bodyLine = yyextra->lineNr;
1232 if ((yyextra->current_root) &&
1233 (yyextra->current_root->section.isClass() ||
1234 yyextra->current_root->section.isNamespace()))
1236 yyextra->current->name = yyextra->current_root->name +
"::" + yyextra->current->name;
1240 startScope(yyscanner,yyextra->last_entry.get());
1243<FEnum>"end"{BS}"enum" {
1244 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr;
1245 if (!
endScope(yyscanner,yyextra->current_root))
1249 yyextra->typeMode =
false;
1255<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{TYPE_SPEC}{BS}({PREFIX}{BS_})?/{SUBPROG}{BS_} {
1258 addInterface(yyscanner,
"$interface$", yyextra->ifType);
1259 startScope(yyscanner,yyextra->last_entry.get());
1264 yy_push_state(SubprogPrefix,yyscanner);
1267<SubprogPrefix>{BS}{SUBPROG}{BS_} {
1274 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1;
1275 yyextra->current->startLine = yyextra->lineNr;
1278<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{SUBPROG}{BS_} {
1283 addInterface(yyscanner,
"$interface$", yyextra->ifType);
1284 startScope(yyscanner,yyextra->last_entry.get());
1289 yy_push_state(Subprog,yyscanner);
1290 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1;
1291 yyextra->current->startLine = yyextra->lineNr;
1295<Subprog>{ID} { yyextra->current->name = yytext;
1299 if ((yyextra->current_root) &&
1300 (yyextra->current_root->section.isClass() ||
1301 yyextra->current_root->section.isNamespace()))
1303 yyextra->current->name= yyextra->current_root->name +
"::" + yyextra->current->name;
1305 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()].returnName = std::move(returnName);
1310 yyextra->current_root->name,
"$interface$",
DString(yytext).lower());
1313 BEGIN(Parameterlist);
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
1315<Parameterlist>"(" { yyextra->current->args =
"("; }
1317 yyextra->current->args +=
")";
1320 startScope(yyscanner,yyextra->last_entry.get());
DString removeRedundantWhiteSpace(const DString &s)
1323<Parameterlist>{COMMA}|{BS} { yyextra->current->args += yytext;
1327 if (!yyextra->current->argList.empty())
1329 yyextra->current->argList.back().docs = c->
str;
1333<Parameterlist>{ID} {
1337 yyextra->current->args += param;
1341 yyextra->current->argList.
push_back(arg);
1343<Parameterlist>{NOARGS} {
1347 startScope(yyscanner,yyextra->last_entry.get());
1350<SubprogBody>result{BS}\({BS}{ID} {
1351 if (yyextra->functionLine)
1354 result= result.
mid(result.
find(
'(')+1);
1356 yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower().str()].returnName = result;
DString mid(size_t index, size_t len=npos) const
1363<FVariable,SubprogBody,ModuleBody,TypedefBody,TypedefBodyContains>"!<" {
1366 yyextra->current->docLine = yyextra->lineNr;
1367 yyextra->docBlockJavaStyle =
false;
1368 yyextra->docBlock.clear();
1371 yy_push_state(DocBackLine,yyscanner);
1376 if (YY_START == String)
1378 yyextra->colNr -= (int)yyleng;
1383 if ((YY_START != StrIgnore) && (YY_START != String))
1385 yy_push_state(YY_START,yyscanner);
1387 yyextra->debugStr=
"*!";
#define Config_getBool(name)
1392 yyextra->docBlock+=yytext;
1394<DocBackLine>"\n"{BS}"!"("<"|"!"+) {
1395 yyextra->docBlock+=
"\n";
1400 yyextra->colNr -= 1;
1404 std::shared_ptr<Entry> tmp_entry = yyextra->current;
1406 if (yyextra->last_enum)
1408 yyextra->current = yyextra->last_enum;
1412 yyextra->current = yyextra->last_entry;
1416 yyextra->current = std::move(tmp_entry);
1422 else if (yyextra->vtype ==
V_RESULT)
1427 yyextra->docBlock.clear();
DString stripIndentation(const DString &s, bool skipFirstLine)
1430<Start,SubprogBody,ModuleBody,TypedefBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains,TypedefBodyContains,FEnum>^{BS} {
1433<Start,SubprogBody,ModuleBody,TypedefBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains,TypedefBodyContains,FEnum>"!>" {
1434 yy_push_state(YY_START,yyscanner);
1435 yyextra->current->docLine = yyextra->lineNr;
1436 yyextra->docBlockJavaStyle =
false;
1437 if (YY_START==SubprogBody) yyextra->docBlockInBody =
true;
1438 yyextra->docBlock.clear();
1446<DocBlock>({CMD}{CMD}){ID}/[^a-z_A-Z0-9] {
1447 yyextra->docBlock += yytext;
1449<DocBlock>{CMD}("f$"|"f["|"f{"|"f(") {
1450 yyextra->docBlock += yytext;
1451 yyextra->docBlockName=&yytext[1];
1452 if (yyextra->docBlockName.at(1)==
'[')
1454 yyextra->docBlockName.at(1)=
']';
1456 if (yyextra->docBlockName.at(1)==
'{')
1458 yyextra->docBlockName.at(1)=
'}';
1460 if (yyextra->docBlockName.at(1)==
'(')
1462 yyextra->docBlockName.at(1)=
')';
1464 yyextra->fencedSize=0;
1466 BEGIN(DocCopyBlock);
1468<DocBlock>{CMD}"ifile"{B}+"\""[^\n\"]+"\"" {
1469 yyextra->fileName = &yytext[6];
1470 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1471 yyextra->fileName = yyextra->fileName.mid(1,yyextra->fileName.length()-2);
1472 yyextra->docBlock += yytext;
1474<DocBlock>{CMD}"ifile"{B}+{FILEMASK} {
1475 yyextra->fileName = &yytext[6];
1476 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1477 yyextra->docBlock += yytext;
1479<DocBlock>{CMD}"iline"{LINENR}/[\n\.] |
1480<DocBlock>{CMD}"iline"{LINENR}{B} {
1485 warn(yyextra->fileName,yyextra->lineNr,
"Invalid line number '{}' for iline command",yytext);
1489 yyextra->lineNr = nr;
1491 yyextra->docBlock += yytext;
int toInt(bool *ok=nullptr, int base=10) const
1493<DocBlock>{B}*"<"{PRE}">" {
1494 yyextra->docBlock += yytext;
1495 yyextra->docBlockName=
"<pre>";
1496 yyextra->fencedSize=0;
1498 BEGIN(DocCopyBlock);
1500<DocBlock>{B}*"<"<CODE>">" {
1501 yyextra->docBlock += yytext;
1502 yyextra->docBlockName=
"<code>";
1503 yyextra->fencedSize=0;
1505 BEGIN(DocCopyBlock);
1507<DocBlock>{CMD}"startuml"/[^a-z_A-Z0-9\-] {
1508 yyextra->docBlock += yytext;
1509 yyextra->docBlockName=
"uml";
1510 yyextra->fencedSize=0;
1512 BEGIN(DocCopyBlock);
1514<DocBlock>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"manonly"|"rtfonly"|"docbookonly"|"dot"|"msc"|"mermaid"|"code")/[^a-z_A-Z0-9\-] {
1515 yyextra->docBlock += yytext;
1516 yyextra->docBlockName=&yytext[1];
1517 yyextra->fencedSize=0;
1519 BEGIN(DocCopyBlock);
1521<DocBlock>"~~~"[~]* {
1523 yyextra->docBlock += pat;
1524 yyextra->docBlockName=
"~~~";
1525 yyextra->fencedSize=pat.
length();
1527 BEGIN(DocCopyBlock);
1529<DocBlock>"```"[`]*/(".")?[a-zA-Z0-9#_-]+ |
1530<DocBlock>"```"[`]*/"{"[^}]+"}" |
1531<DocBlock>"```"[`]* {
1533 yyextra->docBlock += pat;
1534 yyextra->docBlockName=
"```";
1535 yyextra->fencedSize=pat.
length();
1537 BEGIN(DocCopyBlock);
1539<DocBlock>"\\ilinebr "{BS} {
1541 int extraSpaces = std::max(0,
static_cast<int>(yyleng-9-yyextra->curIndent-2));
1542 indent.
fill(
' ',extraSpaces);
1544 yyextra->docBlock +=
"\\ilinebr ";
1545 yyextra->docBlock += indent;
DString fill(char c, size_t len)
Fills a string with a predefined character.
1548<DocBlock>[^@*`~\/\\\n]+ {
1549 yyextra->docBlock += yytext;
1551<DocBlock>"\n"{BS}"!"(">"|"!"+) {
1552 yyextra->docBlock+=
"\n";
1557 yyextra->colNr -= 1;
1563 yyextra->docBlock += *yytext;
1568<DocCopyBlock>"</"{PRE}">" {
1569 yyextra->docBlock += yytext;
1570 if (yyextra->docBlockName==
"<pre>")
1572 yyextra->docBlockName=
"";
1577<DocCopyBlock>"</"{CODE}">" {
1578 yyextra->docBlock += yytext;
1579 if (yyextra->docBlockName==
"<code>")
1581 yyextra->docBlockName=
"";
1586<DocCopyBlock>{CMD}("f$"|"f]"|"f}"|"f)") {
1587 yyextra->docBlock += yytext;
1588 if (yyextra->docBlockName==&yytext[1])
1590 yyextra->docBlockName=
"";
1595<DocCopyBlock>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endmanonly"|"endrtfonly"|"enddot"|"endmsc"|"endmermaid"|"enduml"|"endcode")/[^a-z_A-Z0-9] {
1596 yyextra->docBlock += yytext;
1597 if (&yytext[4]==yyextra->docBlockName)
1599 yyextra->docBlockName=
"";
1605<DocCopyBlock>^{B}*{COMM} {
1607<DocCopyBlock>"~~~"[~]* {
1609 yyextra->docBlock += pat;
1610 if (yyextra->docBlockName ==
"~~~" && yyextra->fencedSize==pat.
length())
1616<DocCopyBlock>"```"[`]* {
1618 yyextra->docBlock += pat;
1619 if (yyextra->docBlockName ==
"```" && yyextra->fencedSize==pat.
length())
1626<DocCopyBlock>[^<@/\*\]!`~"\$\\\n]+ {
1627 yyextra->docBlock += yytext;
1630 yyextra->docBlock += *yytext;
1634 yyextra->docBlock += *yytext;
1638<Prototype>{BS}{SUBPROG}{BS_} {
1639 BEGIN(PrototypeSubprog);
1641<Prototype,PrototypeSubprog>{BS}{SCOPENAME}?{BS}{ID} {
1644 BEGIN(PrototypeArgs);
1647"("|")"|","|{BS_} { yyextra->current->args += yytext; }
1648{ID} { yyextra->current->args += yytext;
1660 yyextra->debugStr=
"";
1667 if (yyextra->parsingPrototype)
1671 else if ( yyextra->includeStackPtr <= 0 )
1673 if (YY_START!=INITIAL && YY_START!=Start)
1675 DBG_CTX((stderr,
"==== Error: EOF reached in wrong state (end missing)"));
1702 yyextra->lineNr+=yyextra->lineCountPrepass;
1703 yyextra->lineCountPrepass=0;
1704 yyextra->comments.clear();
1715 if (c==
'\t') col+=tabSize-(col%tabSize);
1716 else if (c==
'\n') col=0;
1726 for (
const auto &cip : yyextra->comments)
1730 if (c>=from && c<=to)
1745 yyextra->last_entry->brief = c->
str;
1750 if (parameter) parameter->
docs = c->
str;
1756 for(
int i=0; i<length; i++)
1776 int parseState = Start;
1777 char quoteSymbol = 0;
1779 int commentIndex = -1;
1781 if (ch !=
'\0') parseState = String;
1783 for(
int i=0; i<length && parseState!=Comment; i++)
1787 if (parseState==String)
1789 if (buf[i]==
'\\') i++;
1798 if (buf[i]==quoteSymbol)
1804 else if (parseState==Start)
1806 parseState = String;
1807 quoteSymbol = buf[i];
1813 if (parseState==Start)
1815 parseState = Comment;
1834 return commentIndex;
1843 size_t length = yyextra->inputStringPrepass.length();
1844 for (
size_t i=index+1; i<length; i++) {
1845 if (yyextra->inputStringPrepass[i]==
'!' && i<length-1 && yyextra->inputStringPrepass[i+1]==
'<') {
1846 yyextra->comments.emplace_back(index, yyextra->inputStringPrepass.right(length-i-2));
1849 yyextra->inputStringPrepass.resize(index);
1856 for(
int i=length; i>pos; i--)
1857 contents[i]=contents[i-1];
1867 int prevLineLength=0;
1868 int prevLineAmpOrExclIndex=-1;
1870 char prevQuote =
'\0';
1871 char thisQuote =
'\0';
1872 bool emptyLabel=
true;
1873 bool commented=
false;
1874 bool inSingle=
false;
1875 bool inDouble=
false;
1876 bool inBackslash=
false;
1877 bool fullCommentLine=
true;
1878 bool artificialComment=
false;
1880 int newContentsSize = (int)strlen(contents)+3;
1881 char* newContents = (
char*)malloc(newContentsSize);
1886 sizCont = strlen(contents);
1887 for(
size_t i=0;i<sizCont;i++) {
1889 char c = contents[i];
1890 if (artificialComment && c !=
'\n')
1892 if (c ==
'!' && spaces)
1894 newContents[j++] = c;
1895 artificialComment =
false;
1900 else if (c ==
' ' || c ==
'\t')
continue;
1910 if (j>=newContentsSize-3) {
1911 newContents = (
char*)realloc(newContents, newContentsSize+1000);
1912 newContentsSize = newContentsSize+1000;
1917 if (!fullCommentLine)
1919 prevLineLength=column;
1920 prevLineAmpOrExclIndex=
getAmpOrExclAtTheEnd(&contents[i-prevLineLength+1], prevLineLength,prevQuote);
1921 if (prevLineAmpOrExclIndex == -1) prevLineAmpOrExclIndex = column - 1;
1924 prevLineAmpOrExclIndex = -1;
1930 prevLineLength+=column;
1934 hasContLine[curLine - 1] = 1;
1937 artificialComment=
false;
1939 fullCommentLine=
true;
1944 prevQuote = thisQuote;
1957 newContents[j]=
'\000';
1958 newContentsSize = (int)strlen(newContents);
1959 if (newContents[newContentsSize - 1] !=
'\n')
1962 newContents = (
char*)realloc(newContents, newContentsSize+2);
1963 newContents[newContentsSize] =
'\n';
1964 newContents[newContentsSize + 1] =
'\000';
1970 if ((column <= fixedCommentAfter) && (column!=6) && !commented)
1973 fullCommentLine=
false;
1977 inBackslash = !inBackslash;
1984 inSingle = !inSingle;
1985 if (inSingle) thisQuote = c;
1986 else thisQuote =
'\0';
1994 inDouble = !inDouble;
1995 if (inDouble) thisQuote = c;
1996 else thisQuote =
'\0';
2001 inBackslash =
false;
2008 if ((column <= fixedCommentAfter) && (column!=6))
2016 else if ((c ==
'!') && !inDouble && !inSingle)
2023 if (!commented) fullCommentLine=
false;
2030 if (!commented && (column < 6) && ((c -
'0') >= 0) && ((c -
'0') <= 9))
2034 else if (column==6 && emptyLabel)
2036 if (!commented) fullCommentLine=
false;
2041 if (prevLineAmpOrExclIndex==-1)
2050 if (curLine != 1)
insertCharacter(newContents, j+1, (j+1)-6-prevLineLength+prevLineAmpOrExclIndex+skipped,
'&');
2056 hasContLine[curLine - 1] = 1;
2065 else if ((column > fixedCommentAfter) && !commented)
2076 artificialComment =
true;
2088 if (!commented) fullCommentLine=
false;
2104 newContents = (
char*)realloc(newContents, 2);
2105 newContents[0] =
'\n';
2106 newContents[1] =
'\000';
2108 else if (newContents[j] ==
'\n')
2110 newContents = (
char*)realloc(newContents, j+2);
2111 newContents[j + 1] =
'\000';
2115 newContents = (
char*)realloc(newContents, j+3);
2116 newContents[j + 1] =
'\n';
2117 newContents[j + 2] =
'\000';
2126 static const std::unordered_set<std::string> fortran_C_keywords = {
2127 "character",
"call",
"close",
"common",
"continue",
2128 "case",
"contains",
"cycle",
"class",
"codimension",
2129 "concurrent",
"contiguous",
"critical"
2132 if (*contents !=
'c' && *contents !=
'C')
return false;
2134 const char *c = contents;
2136 while (*c && *c !=
' ') {keyword += *c; c++;}
2137 keyword = keyword.
lower();
2139 return (fortran_C_keywords.find(keyword.
str()) != fortran_C_keywords.end());
2146 bool skipLine=
false;
2152 size_t sizCont = contents.
length();
2153 for (
size_t i=0;i<sizCont;i++)
2157 switch(contents.
at(i))
2164 column += tabSize-1;
2181 if (column==1)
return true;
2182 if (skipLine)
break;
2185 if (column!=6) skipLine=
true;
2188 if (skipLine)
break;
2189 if (column>=7)
return true;
2213 if (yyextra->includeStackCnt <= yyextra->includeStackPtr)
2215 yyextra->includeStackCnt++;
2216 yyextra->includeStack = (YY_BUFFER_STATE *)realloc(yyextra->includeStack, yyextra->includeStackCnt *
sizeof(YY_BUFFER_STATE));
2218 yyextra->includeStack[yyextra->includeStackPtr++] = YY_CURRENT_BUFFER;
2219 yy_switch_to_buffer(yy_scan_string(buffer.
data(),yyscanner),yyscanner);
2228 yyextra->includeStackPtr --;
2229 yy_delete_buffer( YY_CURRENT_BUFFER, yyscanner );
2230 yy_switch_to_buffer( yyextra->includeStack[yyextra->includeStackPtr], yyscanner );
2234static void copyEntry(std::shared_ptr<Entry> dest,
const std::shared_ptr<Entry> &src)
2236 dest->type = src->type;
2237 dest->fileName = src->fileName;
2238 dest->startLine = src->startLine;
2239 dest->bodyLine = src->bodyLine;
2240 dest->endBodyLine = src->endBodyLine;
2241 dest->args = src->args;
2242 dest->argList = src->argList;
2243 dest->doc = src->doc;
2244 dest->docLine = src->docLine;
2245 dest->docFile = src->docFile;
2246 dest->brief = src->brief;
2247 dest->briefLine= src->briefLine;
2248 dest->briefFile= src->briefFile;
2259 if (yyextra->moduleProcedures.empty())
return;
2262 std::map<std::string,std::shared_ptr<Entry>> procMap;
2264 for (
const auto& cf: current_root->
children())
2266 if (!cf->section.isFunction())
2275 procMap.emplace(name.str(), cf);
2281 for (
const auto& ce1: yyextra->moduleProcedures)
2283 if (procMap.find(ce1->name.str())!=procMap.end())
2285 std::shared_ptr<Entry> proc = procMap[ce1->name.str()];
2289 yyextra->moduleProcedures.clear();
2298 extracted.
remove(0, start+1);
2302 size_t length = extracted.
length();
2314 if (parensPart.
length() == 1)
2329 return "bind(C, name=" + parensPart +
")";
2370 else if (mdfString.
contains(
"intent"))
2379 else if (mdfString==
"public")
2383 else if (mdfString==
"private")
2387 else if (mdfString==
"protected")
2391 else if (mdfString==
"optional")
2395 else if (mdfString==
"allocatable")
2399 else if (mdfString==
"external")
2403 else if (mdfString==
"intrinsic")
2407 else if (mdfString==
"parameter")
2411 else if (mdfString==
"pointer")
2415 else if (mdfString==
"target")
2419 else if (mdfString==
"save")
2423 else if (mdfString==
"nopass")
2427 else if (mdfString==
"deferred")
2431 else if (mdfString==
"non_overridable")
2435 else if (mdfString==
"contiguous")
2439 else if (mdfString==
"volatile")
2441 newMdf.
volat =
true;
2443 else if (mdfString==
"value")
2445 newMdf.
value =
true;
2447 else if (mdfString.
contains(
"pass"))
2481 if ((!byTypeName && arg.
name.
lower() == cname) ||
2482 (byTypeName && arg.
type.
lower() == cname)
2497 if (!typeName.
empty()) typeName +=
", ";
2502 if (!typeName.
empty()) typeName +=
", ";
2507 if (!typeName.
empty()) typeName +=
", ";
2508 typeName +=
"optional";
2512 if (!typeName.
empty()) typeName +=
", ";
2513 typeName +=
"allocatable";
2517 if (!typeName.
contains(
"external"))
2519 if (!typeName.
empty()) typeName +=
", ";
2520 typeName +=
"external";
2525 if (!typeName.
empty()) typeName +=
", ";
2526 typeName +=
"intrinsic";
2530 if (!typeName.
empty()) typeName +=
", ";
2531 typeName +=
"parameter";
2535 if (!typeName.
empty()) typeName +=
", ";
2536 typeName +=
"pointer";
2540 if (!typeName.
empty()) typeName +=
", ";
2541 typeName +=
"target";
2545 if (!typeName.
empty()) typeName +=
", ";
2550 if (!typeName.
empty()) typeName +=
", ";
2551 typeName +=
"deferred";
2555 if (!typeName.
empty()) typeName +=
", ";
2556 typeName +=
"non_overridable";
2560 if (!typeName.
empty()) typeName +=
", ";
2561 typeName +=
"nopass";
2565 if (!typeName.
empty()) typeName +=
", ";
2568 typeName +=
"(" + mdfs.
passVar +
")";
2572 if (!typeName.
empty()) typeName +=
", ";
2577 if (!typeName.
empty()) typeName +=
", ";
2578 typeName +=
"public";
2582 if (!typeName.
empty()) typeName +=
", ";
2583 typeName +=
"private";
2587 if (!typeName.
empty()) typeName +=
", ";
2588 typeName +=
"protected";
2592 if (!typeName.
empty()) typeName +=
", ";
2593 typeName +=
"contiguous";
2597 if (!typeName.
empty()) typeName +=
", ";
2598 typeName +=
"volatile";
2602 if (!typeName.
empty()) typeName +=
", ";
2603 typeName +=
"value";
2626 ent->
spec.setFinal(
true);
2630 ent->
virt = Specifier::Pure;
2641 yyextra->current_root= scope;
2643 yyextra->modifiers.emplace(scope, std::map<std::string,SymbolModifiers>());
2646 yyextra->current = std::make_shared<Entry>();
2656 if (yyextra->global_scope == scope)
2658 yyextra->global_scope =
nullptr;
2666 if (yyextra->current_root->parent() || isGlobalRoot)
2668 yyextra->current_root= yyextra->current_root->parent();
2672 fprintf(stderr,
"parse error in end <scopename>\n");
2678 yyextra->current = std::make_shared<Entry>();
2682 std::map<std::string,SymbolModifiers>& mdfsMap = yyextra->modifiers[scope];
2684 if (scope->
section.isFunction())
2687 for (
const auto &kv : mdfsMap)
2701 if (yyextra->modifiers[scope].find(returnName.
str())!=yyextra->modifiers[scope].end())
2703 scope->
type = yyextra->modifiers[scope][returnName.
str()].type;
2708 if (scope->
section.isClass() && scope->
spec.isInterface())
2715 for (
const auto &ce : scope->
children())
2717 if (!ce->section.isFunction())
2721 DString name = ce->name.lower();
2722 if (
size_t ii = name.rfind(
':'); ii!=
DString::npos) name.remove(0, ii+1);
2727 arg->
type =
"external " + ce->type +
"(";
2728 for (
size_t i=0; i<ce->argList.size(); i++)
2734 const Argument &subarg = ce->argList.at(i);
2742 yyextra->modifiers.erase(scope);
2748 if (!scope->
section.isFunction())
2751 for (
const auto &ce : scope->
children())
2753 if (!ce->section.isVariable() && !ce->section.isFunction() && !ce->section.isClass())
2757 if (mdfsMap.find(ce->name.lower().str())!=mdfsMap.end())
2761 if (ce->section.isVariable() || ce->section.isFunction())
2769 yyextra->modifiers.erase(scope);
2783 bool procMapCreated =
false;
2784 std::unordered_map<std::string,std::shared_ptr<Entry>> procMap;
2787 bool interfMapCreated =
false;
2788 std::unordered_map<std::string,std::shared_ptr<Entry>> interfMap;
2791 for (
const auto &ce: scope->
children())
2793 if (!ce->section.isClass())
2797 std::unordered_map<std::string,std::shared_ptr<Entry>> methodMap;
2798 for (
auto &ct: ce->children())
2800 if (!ct->section.isFunction())
2803 if (ct->type==
"generic")
2806 if (ct->virt==Specifier::Pure)
2810 if (!procMapCreated)
2812 for (
const auto &cf: scope->
children())
2814 if (cf->section.isFunction())
2816 procMap.emplace(cf->name.str(), cf);
2819 procMapCreated =
true;
2824 if (procMap.find(implName.
str())!=procMap.end())
2826 std::shared_ptr<Entry> proc = procMap[implName.
str()];
2827 ct->args = proc->args;
2829 if (ct->brief.empty())
2831 ct->brief = proc->brief;
2832 ct->briefLine = proc->briefLine;
2833 ct->briefFile = proc->briefFile;
2835 if (ct->doc.empty())
2837 ct->doc = proc->doc;
2838 ct->docLine = proc->docLine;
2839 ct->docFile = proc->docFile;
2841 methodMap.emplace(ct->name.str(), ct);
2846 for (
auto &ct: ce->children())
2848 if (!ct->section.isFunction())
2851 if (ct->virt != Specifier::Pure)
2855 if (!interfMapCreated)
2857 for(
const auto &cf: scope->
children())
2859 if (cf->section.isClass() && cf->spec.isInterface() && cf->type==
"abstract")
2861 std::shared_ptr<Entry> ci = cf->children().front();
2862 interfMap.emplace(ci->name.str(), ci);
2865 interfMapCreated =
true;
2870 if (interfMap.find(implName.
str())!= interfMap.end() )
2872 std::shared_ptr<Entry> proc = interfMap[implName.
str()];
2873 ct->args = proc->args;
2875 if (ct->brief.empty())
2877 ct->brief = proc->brief;
2878 ct->briefLine = proc->briefLine;
2879 ct->briefFile = proc->briefFile;
2881 if (ct->doc.empty())
2883 ct->doc = proc->doc;
2884 ct->docLine = proc->docLine;
2885 ct->docFile = proc->docFile;
2888 methodMap.emplace(ct->name.str(), ct);
2894 for (
auto &ct: ce->children())
2896 if (!ct->section.isFunction())
2899 if (ct->type!=
"generic")
2903 DString methodName = ct->args;
2904 if (methodMap.find(methodName.
str()) != methodMap.end())
2906 std::shared_ptr<Entry> method = methodMap[methodName.
str()];
2907 ct->args = method->args;
2909 if (ct->brief.empty())
2911 ct->brief = method->brief;
2912 ct->briefLine = method->briefLine;
2913 ct->briefFile = method->briefFile;
2915 if (ct->doc.empty())
2917 ct->doc = method->doc;
2918 ct->docLine = method->docLine;
2919 ct->docFile = method->docFile;
2931 while ( c < max_size && yyextra->inputString[yyextra->inputPosition] )
2933 *buf = yyextra->inputString[yyextra->inputPosition++] ;
2942 yyextra->last_entry.reset();
2948 if (yyextra->typeMode)
2950 yyextra->current->protection = yyextra->typeProtection;
2952 else if (yyextra->current_root && yyextra->current_root->section.isClass() && yyextra->current_root->spec.isInterface())
2954 yyextra->current->protection = Protection::Public;
2956 else if (yyextra->current_root && yyextra->current_root->section.isFunction())
2958 yyextra->current->protection = Protection::Private;
2962 yyextra->current->protection = yyextra->defaultProtection;
2964 yyextra->current->mtype = MethodTypes::Method;
2965 yyextra->current->virt = Specifier::Normal;
2966 yyextra->current->isStatic =
false;
2967 yyextra->current->lang = SrcLangExt::Fortran;
2968 yyextra->commentScanner.initGroupInfo(yyextra->current.get());
2977 if (case_insens) yyextra->current->name = yyextra->current->name.lower();
2979 yyextra->last_entry = yyextra->current;
2980 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
2987 DBG_CTX((stderr,
"0=========> got module %s\n",
qPrint(name)));
2990 yyextra->current->section = EntryType::makeNamespace();
2992 yyextra->current->section = EntryType::makeFunction();
2996 yyextra->current->name = name;
3000 DString fname = yyextra->fileName;
3001 size_t index1 = fname.
rfind(
'/');
3002 size_t index2 = fname.
rfind(
'\\');
3006 if (yyextra->mainPrograms) fname +=
"__" +
DString().
setNum(yyextra->mainPrograms);
3007 yyextra->mainPrograms++;
3009 yyextra->current->name =
substitute(fname,
".",
"_");
3011 yyextra->current->type =
"program";
3012 yyextra->current->fileName = yyextra->fileName;
3013 yyextra->current->bodyLine = yyextra->lineNr;
3014 yyextra->current->startLine = yyextra->lineNr;
3015 yyextra->current->protection = Protection::Public ;
3017 startScope(yyscanner,yyextra->last_entry.get());
3024 DBG_CTX((stderr,
"1=========> got subprog, type: %s\n",
qPrint(text)));
3025 yyextra->subrCurrent.push_back(yyextra->current);
3026 yyextra->current->section = EntryType::makeFunction();
3029 yyextra->current->type +=
" " + subtype;
3033 yyextra->current->virt = Specifier::Virtual;
3035 yyextra->current->fileName = yyextra->fileName;
3036 yyextra->current->bodyLine = yyextra->lineNr;
3037 yyextra->current->startLine = yyextra->lineNr;
3038 yyextra->current->args.
clear();
3039 yyextra->current->argList.clear();
3041 yyextra->docBlock.clear();
3051 if (YY_START == Start)
3055 yy_push_state(ModuleBody,yyscanner);
3058 yyextra->current->section = EntryType::makeClass();
3059 yyextra->current->spec =
TypeSpecifier().setInterface(
true);
3060 yyextra->current->name = name;
3065 yyextra->current->type =
"abstract";
3069 yyextra->current->type =
"generic";
3075 yyextra->current->type =
"";
3079 if ((yyextra->current_root) &&
3080 (yyextra->current_root->section.isClass() ||
3081 yyextra->current_root->section.isNamespace()))
3083 yyextra->current->name= yyextra->current_root->name +
"::" + yyextra->current->name;
3086 yyextra->current->fileName = yyextra->fileName;
3087 yyextra->current->bodyLine = yyextra->lineNr;
3088 yyextra->current->startLine = yyextra->lineNr;
3102 for (
Argument &a:yyextra->current_root->argList)
3120 yyextra->current->briefFile = yyextra->fileName;
3121 yyextra->current->briefLine = yyextra->lineNr;
3125 yyextra->current->docFile = yyextra->fileName;
3126 yyextra->current->docLine = yyextra->lineNr;
3139 if (yyextra->docBlockInBody && hideInBodyDocs)
3141 yyextra->docBlockInBody =
false;
3144 DBG_CTX((stderr,
"call parseCommentBlock [%s]\n",
qPrint(doc)));
3145 int lineNr = brief ? yyextra->current->briefLine : yyextra->current->docLine;
3147 bool needsEntry =
false;
3148 Markdown markdown(yyextra->fileName,lineNr);
3152 while (yyextra->commentScanner.parseCommentBlock(
3153 yyextra->thisParser,
3154 yyextra->docBlockInBody ? yyextra->subrCurrent.back().get() : yyextra->current.get(),
3158 yyextra->docBlockInBody ?
false : brief,
3159 yyextra->docBlockInBody ?
false : yyextra->docBlockJavaStyle,
3160 yyextra->docBlockInBody,
3161 yyextra->defaultProtection,
3168 DBG_CTX((stderr,
"parseCommentBlock position=%d [%s] needsEntry=%d\n",position,doc.
data()+position,needsEntry));
3171 DBG_CTX((stderr,
"parseCommentBlock position=%d [%s] needsEntry=%d\n",position,doc.
data()+position,needsEntry));
3174 yyextra->docBlockInBody =
false;
3185 std::shared_ptr<Entry> tmp_entry = yyextra->current;
3186 yyextra->current = yyextra->subrCurrent.
back();
3189 yyextra->current->inbodyDocs =
"";
3197 int dir1 = yyextra->modifiers[yyextra->current_root][yyextra->argName.lower().str()].direction;
3209 if (!loc_doc.
empty() && (loc_doc.
lower() != yyextra->argName.
lower()))
3212 yyextra->argName +
" " + loc_doc,brief);
3218 warn(yyextra->fileName,yyextra->lineNr,
"Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3219 yyextra->current->name,yyextra->current->args,yyextra->argName);
3221 yyextra->argName +
" " + loc_doc,brief);
3234 yyextra->current = tmp_entry;
3238 yyextra->argName +
" " + loc_doc,brief);
3242 warn(yyextra->fileName,yyextra->lineNr,
"Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3243 yyextra->current->name,yyextra->current->args,yyextra->argName);
3245 yyextra->argName +
" " + loc_doc,brief);
3256 if (!loc_doc.
empty() && (loc_doc.
lower() != yyextra->argName.
lower()))
3259 yyextra->argName +
" " + loc_doc,brief);
3264 warn(yyextra->fileName,yyextra->lineNr,
"Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3265 yyextra->current->name,yyextra->current->args,yyextra->argName);
3267 yyextra->argName +
" " + loc_doc,brief);
3271 else if (!loc_doc.
empty() && (loc_doc.
lower() != yyextra->argName.
lower()))
3274 yyextra->argName +
" " + loc_doc,brief);
3278 yyextra->current = tmp_entry;
3288 std::shared_ptr<Entry> tmp_entry = yyextra->current;
3289 yyextra->current = yyextra->subrCurrent.
back();
3292 yyextra->current->inbodyDocs =
"";
3301 if (!loc_doc.
empty() && (loc_doc.
lower() != yyextra->argName.
lower()))
3307 yyextra->current = std::move(tmp_entry);
3316 char *tmpBuf =
nullptr;
3319 if (fileBuf==
nullptr || fileBuf[0]==
'\0')
return;
3321 yyextra->defaultProtection = Protection::Public;
3322 yyextra->inputString = fileBuf;
3323 yyextra->inputPosition = 0;
3324 yyextra->inputStringPrepass =
nullptr;
3325 yyextra->inputPositionPrepass = 0;
3328 yyextra->current_root = rt.get();
3329 yyextra->global_root = rt;
3333 if (yyextra->isFixedForm)
3335 yyextra->fixedCommentAfter =
Config_getInt(FORTRAN_COMMENT_AFTER);
3336 msg(
"Prepassing fixed form of {}\n", fileName);
3342 yyextra->inputString =
prepassFixedForm(fileBuf,
nullptr,yyextra->fixedCommentAfter);
3351 else if (yyextra->inputString[strlen(fileBuf)-1] !=
'\n')
3353 tmpBuf = (
char *)malloc(strlen(fileBuf)+2);
3354 strcpy(tmpBuf,fileBuf);
3355 tmpBuf[strlen(fileBuf)]=
'\n';
3356 tmpBuf[strlen(fileBuf)+1]=
'\000';
3357 yyextra->inputString = tmpBuf;
3360 yyextra->lineNr= 1 ;
3361 yyextra->fileName = fileName;
3362 msg(
"Parsing file {}...\n",yyextra->fileName);
3364 yyextra->global_scope = rt.get();
3367 yyextra->commentScanner.enterFile(yyextra->fileName,yyextra->lineNr);
3370 yyextra->current = std::make_shared<Entry>();
3371 yyextra->current->lang = SrcLangExt::Fortran;
3372 yyextra->current->name = yyextra->fileName;
3373 yyextra->current->section = EntryType::makeSource();
3374 yyextra->file_root = yyextra->current;
3375 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
3376 yyextra->current->lang = SrcLangExt::Fortran;
3378 fortranscannerYYrestart(
nullptr, yyscanner );
3383 fortranscannerYYlex(yyscanner);
3384 yyextra->commentScanner.leaveFile(yyextra->fileName,yyextra->lineNr);
3386 if (yyextra->global_scope && yyextra->global_scope !=
INVALID_ENTRY)
3388 endScope(yyscanner,yyextra->current_root,
true);
3393 rt->program.str(std::string());
3395 yyextra->moduleProcedures.clear();
3398 free((
char*)tmpBuf);
3399 yyextra->inputString=
nullptr;
3401 if (yyextra->isFixedForm)
3403 free((
char*)yyextra->inputString);
3404 yyextra->inputString=
nullptr;
3437 const char *fileBuf,
3438 const std::shared_ptr<Entry> &root,
3442 yyextra->thisParser =
this;
3451 return extension!=extension.
lower();
3458 yyextra->parsingPrototype =
true;
3460 fortranscannerYYlex(
p->yyscanner);
3461 yyextra->parsingPrototype =
false;
3470 fprintf(stderr,
"********************************************************************\n");
3471 if (yyextra->blockLineNr == -1)
3473 fprintf(stderr,
"Error in file %s line: %d, state: %d(%s)\n",
3478 fprintf(stderr,
"Error in file %s line: %d, state: %d(%s), starting command: '%s' probable line reference: %d\n",
3479 qPrint(yyextra->fileName),yyextra->lineNr,YY_START,
stateToString(YY_START),
qPrint(yyextra->blockString),yyextra->blockLineNr);
3481 fprintf(stderr,
"********************************************************************\n");
3484 while (!yyextra->blockStack.empty()) yyextra->blockStack.pop();
3488 for (
const auto &ce : yyextra->global_root->children())
3490 if (ce == yyextra->file_root) start=
true;
3491 if (start) ce->reset();
3495 (void)yy_top_state(yyscanner);
3504 if ( yyg->yy_start_stack_ptr <= 0 )
3505 warn(yyextra->fileName,yyextra->lineNr,
"Unexpected statement '{}'",yytext );
3507 yy_pop_state(yyscanner);
3513 yyextra->blockString = text;
3514 yyextra->blockLineNr = yyextra->lineNr;
3515 yyextra->blockStack.emplace(yyextra->blockString,yyextra->blockLineNr);
3521 if (yyextra->blockStack.empty())
3523 warn(yyextra->fileName,yyextra->lineNr,
"Internal inconsistency: empty stack while attempting popBlockState");
3527 yyextra->blockStack.pop();
3529 if (yyextra->blockStack.empty())
3531 yyextra->blockString.clear();
3532 yyextra->blockLineNr=-1;
3536 yyextra->blockString=yyextra->blockStack.top().blockString;
3537 yyextra->blockLineNr=yyextra->blockStack.top().blockLineNr;
3542#include "fortranscanner.l.h"
This class represents an function or template argument list.
Clang parser object for a single translation unit, which consists of a source file and the directly o...
DString & setNum(short n)
size_t rfind(char c, size_t pos=npos) const
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
char & at(size_t i)
Returns a reference to the character at index i.
DString & prepend(const char *s)
int contains(char c, bool cs=true) const
char & back()
Returns a reference to the last character.
const std::string & str() const
bool stripPrefix(const DString &prefix)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
bool startsWith(const char *s) const
static bool isFlagSet(const DebugMask mask)
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
static ParserManager * parserManager
const std::vector< std::shared_ptr< Entry > > & children() const
ArgumentList argList
member arguments as a list
EntryType section
entry type (see Sections);
Specifier virt
virtualness of the entry
Protection protection
class protection
TypeSpecifier spec
class/member specifiers
void removeSubEntry(const Entry *e)
bool needsPreprocessing(const DString &extension) const override
Returns true if the language identified by extension needs the C preprocessor to be run before feed t...
void parseInput(const DString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &root, ClangTUParser *clangParser) override
Parses a single input file with the goal to build an Entry tree.
std::unique_ptr< Private > p
~FortranOutlineParser() override
FortranOutlineParser(FortranFormat format=FortranFormat::Unknown)
void parsePrototype(const DString &text) override
Callback function called by the comment block scanner.
Helper class to process markdown formatted text.
DString process(const DString &input, int &startNewlines, bool fromParseInput=false)
DString getParserName(const DString &extension)
Gets the name of the parser associated with given extension.
Wrapper class for a number of boolean properties.
#define Config_getInt(name)
DirIterator end(const DirIterator &) noexcept
const char * prepassFixedForm(const char *contents, int *hasContLine, int fixedCommentAfter)
bool recognizeFixedForm(const DString &contents, FortranFormat format)
FortranFormat convertFileNameFortranParserCode(const DString &fn)
static DString applyModifiers(DString typeName, const SymbolModifiers &mdfs)
const char * prepassFixedForm(const char *contents, int *hasContLine, int fixedCommentAfter)
static void initParser(yyscan_t yyscanner)
bool recognizeFixedForm(const DString &contents, FortranFormat format)
static void insertCharacter(char *contents, int length, int pos, char c)
static Argument * findArgument(Entry *subprog, DString name, bool byTypeName=false)
static bool keyWordsFortranC(const char *contents)
static void parseMain(yyscan_t yyscanner, const DString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &rt, FortranFormat format)
fortranscannerYY_state extra
Private(FortranFormat fmt)
DString getFileNameExtension(const DString &fn)