Doxygen
Loading...
Searching...
No Matches
fortranscanner.l File Reference
#include <stdint.h>
#include "fortranscanner.h"
#include <algorithm>
#include <map>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "arguments.h"
#include "commentscan.h"
#include "config.h"
#include "debug.h"
#include "doxygen.h"
#include "entry.h"
#include "markdown.h"
#include "message.h"
#include "util.h"
#include "doxygen_lex.h"
#include "fortranscanner.l.h"
Include dependency graph for fortranscanner.l:

Go to the source code of this file.

Classes

struct  BlockState
struct  SymbolModifiers
 Holds yyextra->modifiers (ie attributes) for one symbol (variable, function, etc). More...
struct  CommentInPrepass
struct  fortranscannerYY_state
struct  FortranOutlineParser::Private

Macros

#define YY_TYPEDEF_YY_SCANNER_T
#define yyguts_t   fortranscannerYYguts_t
#define DBG_CTX(x)
#define YY_NO_INPUT   1
#define YY_NO_UNISTD_H   1
#define YY_INPUT(buf, result, max_size)
#define YY_USER_ACTION   yyextra->colNr+=(int)yyleng;
#define INVALID_ENTRY   ((Entry*)0x8)

Typedefs

typedef yyguts_t * yyscan_t

Enumerations

enum  ScanVar { V_IGNORE , V_VARIABLE , V_PARAMETER , V_RESULT }
enum  InterfaceType { IF_NONE , IF_SPECIFIC , IF_GENERIC , IF_ABSTRACT }

Functions

static int getAmpersandAtTheStart (const char *buf, int length)
static int getAmpOrExclAtTheEnd (const char *buf, int length, char ch)
static DString extractFromParens (const DString &name)
static DString extractBind (const DString &name)
static int yyread (yyscan_t yyscanner, char *buf, int max_size)
static void startCommentBlock (yyscan_t yyscanner, bool)
static void handleCommentBlock (yyscan_t yyscanner, const DString &doc, bool brief)
static void subrHandleCommentBlock (yyscan_t yyscanner, const DString &doc, bool brief)
 Handle parameter description as defined after the declaration of the parameter.
static void subrHandleCommentBlockResult (yyscan_t yyscanner, const DString &doc, bool brief)
 Handle result description as defined after the declaration of the parameter.
static void addCurrentEntry (yyscan_t yyscanner, bool case_insens)
 adds yyextra->current entry to yyextra->current_root and creates new yyextra->current
static void addModule (yyscan_t yyscanner, const DString &name=DString(), bool isModule=false)
static void addSubprogram (yyscan_t yyscanner, const DString &text)
static void addInterface (yyscan_t yyscanner, DString name, InterfaceType type)
static Argument * getParameter (yyscan_t yyscanner, const DString &name)
static void scanner_abort (yyscan_t yyscanner)
static void pop_state (yyscan_t yyscanner)
static void pushBlockState (yyscan_t yyscanner, const DString &text)
static void popBlockState (yyscan_t yyscanner)
static void startScope (yyscan_t yyscanner, Entry *scope)
static bool endScope (yyscan_t yyscanner, Entry *scope, bool isGlobalRoot=false)
static void copyEntry (std::shared_ptr< Entry > dest, const std::shared_ptr< Entry > &src)
 used to copy entry to an interface module procedure
static void resolveModuleProcedures (yyscan_t yyscanner, Entry *current_root)
 fill empty interface module procedures with info from corresponding module subprogs
static void resolveTypeBoundProcedures (Entry *scope)
static void truncatePrepass (yyscan_t yyscanner, int index)
static void pushBuffer (yyscan_t yyscanner, const DString &buffer)
static void popBuffer (yyscan_t yyscanner)
static const CommentInPrepass * locatePrepassComment (yyscan_t yyscanner, int from, int to)
static void updateVariablePrepassComment (yyscan_t yyscanner, int from, int to)
static void newLine (yyscan_t yyscanner)
static void initEntry (yyscan_t yyscanner)
static const char * stateToString (int state)
static int computeIndent (const char *s)
static const char * getLexerFILE ()
int yylex (yyscan_t yyscanner)
 fortran parsing states
static void insertCharacter (char *contents, int length, int pos, char c)
const char * prepassFixedForm (const char *contents, int *hasContLine, int fixedCommentAfter)
static bool keyWordsFortranC (const char *contents)
bool recognizeFixedForm (const DString &contents, FortranFormat format)
FortranFormat convertFileNameFortranParserCode (const DString &fn)
static Argument * findArgument (Entry *subprog, DString name, bool byTypeName=false)
static DString applyModifiers (DString typeName, const SymbolModifiers &mdfs)
static void applyModifiers (Argument *arg, const SymbolModifiers &mdfs)
static void applyModifiers (Entry *ent, const SymbolModifiers &mdfs)
static void initParser (yyscan_t yyscanner)
static void parseMain (yyscan_t yyscanner, const DString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &rt, FortranFormat format)

Variables

static const char * directionStrs []
static const char * directionParam []

Macro Definition Documentation

◆ DBG_CTX

#define DBG_CTX ( x)
Value:
do { } while(0)

Definition at line 81 of file fortranscanner.l.

Referenced by addModule(), addSubprogram(), and handleCommentBlock().

◆ INVALID_ENTRY

#define INVALID_ENTRY   ((Entry*)0x8)

Definition at line 273 of file fortranscanner.l.

Referenced by endScope(), and parseMain().

◆ YY_INPUT

#define YY_INPUT ( buf,
result,
max_size )
Value:
result=yyread(yyscanner,buf,max_size);
static int yyread(yyscan_t yyscanner, char *buf, int max_size)

Definition at line 267 of file fortranscanner.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 83 of file fortranscanner.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 84 of file fortranscanner.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 48 of file fortranscanner.l.

◆ YY_USER_ACTION

#define YY_USER_ACTION   yyextra->colNr+=(int)yyleng;

Definition at line 272 of file fortranscanner.l.

◆ yyguts_t

#define yyguts_t   fortranscannerYYguts_t

Definition at line 49 of file fortranscanner.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 51 of file fortranscanner.l.

Enumeration Type Documentation

◆ InterfaceType

Enumerator
IF_NONE 
IF_SPECIFIC 
IF_GENERIC 
IF_ABSTRACT 

Definition at line 87 of file fortranscanner.l.

87{ IF_NONE, IF_SPECIFIC, IF_GENERIC, IF_ABSTRACT };

◆ ScanVar

enum ScanVar
Enumerator
V_IGNORE 
V_VARIABLE 
V_PARAMETER 
V_RESULT 

Definition at line 86 of file fortranscanner.l.

86{ V_IGNORE, V_VARIABLE, V_PARAMETER, V_RESULT};

Function Documentation

◆ addCurrentEntry()

void addCurrentEntry ( yyscan_t yyscanner,
bool case_insens )
static

adds yyextra->current entry to yyextra->current_root and creates new yyextra->current

Definition at line 2974 of file fortranscanner.l.

2975{
2976 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2977 if (case_insens) yyextra->current->name = yyextra->current->name.lower();
2978 //printf("===Adding entry %s to %s\n", qPrint(yyextra->current->name), qPrint(yyextra->current_root->name));
2979 yyextra->last_entry = yyextra->current;
2980 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
2981 initEntry(yyscanner);
#define yyguts_t
Definition code.l:23
static void initEntry(yyscan_t yyscanner)
2982}

References initEntry(), and yyguts_t.

Referenced by addInterface(), addModule(), and handleCommentBlock().

◆ addInterface()

void addInterface ( yyscan_t yyscanner,
DString name,
InterfaceType type )
static

Adds interface to the root entry.

Note
Code was brought to this procedure from the parser, because there was/is idea to use it in several parts of the parser.

Definition at line 3048 of file fortranscanner.l.

3049{
3050 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3051 if (YY_START == Start)
3052 {
3053 addModule(yyscanner);
3054 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
3055 yy_push_state(ModuleBody,yyscanner); //anon program
3056 }
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
static void addModule(yyscan_t yyscanner, const DString &name=DString(), bool isModule=false)
static void pushBlockState(yyscan_t yyscanner, const DString &text)
3057
3058 yyextra->current->section = EntryType::makeClass(); // was EntryType::Interface;
3059 yyextra->current->spec = TypeSpecifier().setInterface(true);
3060 yyextra->current->name = name;
Wrapper class for a number of boolean properties.
Definition types.h:696
const char * name(int level)
Definition latexgen.h:368
3061
3062 switch (type)
3063 {
3064 case IF_ABSTRACT:
3065 yyextra->current->type = "abstract";
3066 break;
@ IF_ABSTRACT
3067
3068 case IF_GENERIC:
3069 yyextra->current->type = "generic";
3070 break;
@ IF_GENERIC
3071
3072 case IF_SPECIFIC:
3073 case IF_NONE:
3074 default:
3075 yyextra->current->type = "";
3076 }
@ IF_NONE
@ IF_SPECIFIC
3077
3078 /* if type is part of a module, mod name is necessary for output */
3079 if ((yyextra->current_root) &&
3080 (yyextra->current_root->section.isClass() ||
3081 yyextra->current_root->section.isNamespace()))
3082 {
3083 yyextra->current->name= yyextra->current_root->name + "::" + yyextra->current->name;
3084 }
3085
3086 yyextra->current->fileName = yyextra->fileName;
3087 yyextra->current->bodyLine = yyextra->lineNr;
3088 yyextra->current->startLine = yyextra->lineNr;
3089 addCurrentEntry(yyscanner,true);
static void addCurrentEntry(yyscan_t yyscanner, bool case_insens)
adds yyextra->current entry to yyextra->current_root and creates new yyextra->current
3090}

References addCurrentEntry(), addModule(), IF_ABSTRACT, IF_GENERIC, IF_NONE, IF_SPECIFIC, pushBlockState(), and yyguts_t.

◆ addModule()

void addModule ( yyscan_t yyscanner,
const DString & name = DString(),
bool isModule = false )
static

Definition at line 2984 of file fortranscanner.l.

2985{
2986 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2987 DBG_CTX((stderr, "0=========> got module %s\n", qPrint(name)));
const char * qPrint(const char *s)
Definition dstring.h:783
#define DBG_CTX(x)
2988
2989 if (isModule)
2990 yyextra->current->section = EntryType::makeNamespace();
2991 else
2992 yyextra->current->section = EntryType::makeFunction();
2993
2994 if (!name.empty())
2995 {
2996 yyextra->current->name = name;
2997 }
2998 else
2999 {
3000 DString fname = yyextra->fileName;
3001 size_t index1 = fname.rfind('/');
3002 size_t index2 = fname.rfind('\\');
3003 size_t index = index1!=DString::npos && index2!=DString::npos ? std::max(index1,index2) :
3004 index1!=DString::npos ? index1 : index2;
3005 if (index!=DString::npos) fname = fname.mid(index+1);
3006 if (yyextra->mainPrograms) fname += "__" + DString().setNum(yyextra->mainPrograms);
3007 yyextra->mainPrograms++;
3008 fname = fname.prepend("__").append("__");
3009 yyextra->current->name = substitute(fname, ".", "_");
3010 }
3011 yyextra->current->type = "program";
3012 yyextra->current->fileName = yyextra->fileName;
3013 yyextra->current->bodyLine = yyextra->lineNr; // used for source reference
3014 yyextra->current->startLine = yyextra->lineNr;
3015 yyextra->current->protection = Protection::Public ;
3016 addCurrentEntry(yyscanner,true);
3017 startScope(yyscanner,yyextra->last_entry.get());
DString & setNum(short n)
Definition dstring.h:552
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
DString & append(char c)
Definition dstring.h:489
DString & prepend(const char *s)
Definition dstring.h:515
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
static void startScope(yyscan_t yyscanner, Entry *scope)
3018}

References addCurrentEntry(), DString::append(), DBG_CTX, DString::mid(), DString::npos, DString::prepend(), qPrint(), DString::rfind(), DString::setNum(), startScope(), substitute(), and yyguts_t.

Referenced by addInterface().

◆ addSubprogram()

void addSubprogram ( yyscan_t yyscanner,
const DString & text )
static

Definition at line 3021 of file fortranscanner.l.

3022{
3023 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
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();
3027 DString subtype = text; subtype=subtype.lower().stripWhiteSpace();
3028 yyextra->functionLine = subtype.find("function")!=DString::npos;
3029 yyextra->current->type += " " + subtype;
3030 yyextra->current->type = yyextra->current->type.stripWhiteSpace();
3031 if (yyextra->ifType == IF_ABSTRACT)
3032 {
3033 yyextra->current->virt = Specifier::Virtual;
3034 }
3035 yyextra->current->fileName = yyextra->fileName;
3036 yyextra->current->bodyLine = yyextra->lineNr; // used for source reference start of body of routine
3037 yyextra->current->startLine = yyextra->lineNr; // used for source reference start of definition
3038 yyextra->current->args.clear();
3039 yyextra->current->argList.clear();
3040 pushBlockState(yyscanner,text);
3041 yyextra->docBlock.clear();
void clear()
Definition dstring.h:214
DString lower() const
Definition dstring.h:326
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
3042}

References DString::clear(), DBG_CTX, DString::find(), IF_ABSTRACT, DString::lower(), DString::npos, pushBlockState(), qPrint(), DString::stripWhiteSpace(), and yyguts_t.

◆ applyModifiers() [1/3]

void applyModifiers ( Argument * arg,
const SymbolModifiers & mdfs )
static

Apply yyextra->modifiers stored in mdfs to the arg argument.

Definition at line 2610 of file fortranscanner.l.

2611{
2612 arg->type = applyModifiers(arg->type, mdfs);
DString type
Definition arguments.h:43
static DString applyModifiers(DString typeName, const SymbolModifiers &mdfs)
2613}

References applyModifiers(), and Argument::type.

◆ applyModifiers() [2/3]

DString applyModifiers ( DString typeName,
const SymbolModifiers & mdfs )
static

Apply yyextra->modifiers stored in mdfs to the typeName string.

Definition at line 2493 of file fortranscanner.l.

2494{
2495 if (!mdfs.dimension.empty())
2496 {
2497 if (!typeName.empty()) typeName += ", ";
2498 typeName += mdfs.dimension;
2499 }
2501 {
2502 if (!typeName.empty()) typeName += ", ";
2503 typeName += directionStrs[mdfs.direction];
2504 }
2505 if (mdfs.optional)
2506 {
2507 if (!typeName.empty()) typeName += ", ";
2508 typeName += "optional";
2509 }
2510 if (mdfs.allocatable)
2511 {
2512 if (!typeName.empty()) typeName += ", ";
2513 typeName += "allocatable";
2514 }
2515 if (mdfs.external)
2516 {
2517 if (!typeName.contains("external"))
2518 {
2519 if (!typeName.empty()) typeName += ", ";
2520 typeName += "external";
2521 }
2522 }
2523 if (mdfs.intrinsic)
2524 {
2525 if (!typeName.empty()) typeName += ", ";
2526 typeName += "intrinsic";
2527 }
2528 if (mdfs.parameter)
2529 {
2530 if (!typeName.empty()) typeName += ", ";
2531 typeName += "parameter";
2532 }
2533 if (mdfs.pointer)
2534 {
2535 if (!typeName.empty()) typeName += ", ";
2536 typeName += "pointer";
2537 }
2538 if (mdfs.target)
2539 {
2540 if (!typeName.empty()) typeName += ", ";
2541 typeName += "target";
2542 }
2543 if (mdfs.save)
2544 {
2545 if (!typeName.empty()) typeName += ", ";
2546 typeName += "save";
2547 }
2548 if (mdfs.deferred)
2549 {
2550 if (!typeName.empty()) typeName += ", ";
2551 typeName += "deferred";
2552 }
2553 if (mdfs.nonoverridable)
2554 {
2555 if (!typeName.empty()) typeName += ", ";
2556 typeName += "non_overridable";
2557 }
2558 if (mdfs.nopass)
2559 {
2560 if (!typeName.empty()) typeName += ", ";
2561 typeName += "nopass";
2562 }
2563 if (mdfs.pass)
2564 {
2565 if (!typeName.empty()) typeName += ", ";
2566 typeName += "pass";
2567 if (!mdfs.passVar.empty())
2568 typeName += "(" + mdfs.passVar + ")";
2569 }
2570 if (!mdfs.bindVar.empty())
2571 {
2572 if (!typeName.empty()) typeName += ", ";
2573 typeName += mdfs.bindVar;
2574 }
2576 {
2577 if (!typeName.empty()) typeName += ", ";
2578 typeName += "public";
2579 }
2580 else if (mdfs.protection == SymbolModifiers::PRIVATE)
2581 {
2582 if (!typeName.empty()) typeName += ", ";
2583 typeName += "private";
2584 }
2585 if (mdfs.protect)
2586 {
2587 if (!typeName.empty()) typeName += ", ";
2588 typeName += "protected";
2589 }
2590 if (mdfs.contiguous)
2591 {
2592 if (!typeName.empty()) typeName += ", ";
2593 typeName += "contiguous";
2594 }
2595 if (mdfs.volat)
2596 {
2597 if (!typeName.empty()) typeName += ", ";
2598 typeName += "volatile";
2599 }
2600 if (mdfs.value)
2601 {
2602 if (!typeName.empty()) typeName += ", ";
2603 typeName += "value";
2604 }
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
int contains(char c, bool cs=true) const
Definition dstring.cpp:85
static const char * directionStrs[]
Protection protection
2605
2606 return typeName;
2607}

References SymbolModifiers::allocatable, SymbolModifiers::bindVar, DString::contains(), SymbolModifiers::contiguous, SymbolModifiers::deferred, SymbolModifiers::dimension, SymbolModifiers::direction, directionStrs, DString::empty(), SymbolModifiers::external, SymbolModifiers::intrinsic, SymbolModifiers::NONE_D, SymbolModifiers::nonoverridable, SymbolModifiers::nopass, SymbolModifiers::optional, SymbolModifiers::parameter, SymbolModifiers::pass, SymbolModifiers::passVar, SymbolModifiers::pointer, SymbolModifiers::PRIVATE, SymbolModifiers::protect, SymbolModifiers::protection, SymbolModifiers::PUBLIC, SymbolModifiers::save, SymbolModifiers::target, SymbolModifiers::value, and SymbolModifiers::volat.

Referenced by applyModifiers(), applyModifiers(), and endScope().

◆ applyModifiers() [3/3]

void applyModifiers ( Entry * ent,
const SymbolModifiers & mdfs )
static

Apply yyextra->modifiers stored in mdfs to the ent entry.

Definition at line 2616 of file fortranscanner.l.

2617{
2618 ent->type = applyModifiers(ent->type, mdfs);
DString type
member type
Definition entry.h:172
2619
2621 ent->protection = Protection::Public;
2622 else if (mdfs.protection == SymbolModifiers::PRIVATE)
2623 ent->protection = Protection::Private;
Protection protection
class protection
Definition entry.h:179
2624
2625 if (mdfs.nonoverridable)
2626 ent->spec.setFinal(true);
2627 if (mdfs.nopass)
2628 ent->isStatic = true;
2629 if (mdfs.deferred)
2630 ent->virt = Specifier::Pure;
Specifier virt
virtualness of the entry
Definition entry.h:190
bool isStatic
static ?
Definition entry.h:184
TypeSpecifier spec
class/member specifiers
Definition entry.h:181
2631}

References applyModifiers(), SymbolModifiers::deferred, Entry::isStatic, SymbolModifiers::nonoverridable, SymbolModifiers::nopass, SymbolModifiers::PRIVATE, Entry::protection, SymbolModifiers::protection, SymbolModifiers::PUBLIC, Entry::spec, Entry::type, and Entry::virt.

◆ computeIndent()

int computeIndent ( const char * s)
inlinestatic

Definition at line 1707 of file fortranscanner.l.

1708{
1709 int col=0;
1710 int tabSize=Config_getInt(TAB_SIZE);
1711 const char *p=s;
1712 char c = 0;
1713 while ((c=*p++))
1714 {
1715 if (c=='\t') col+=tabSize-(col%tabSize);
1716 else if (c=='\n') col=0;
1717 else col++;
1718 }
1719 return col;
#define Config_getInt(name)
Definition config.h:34
1720}

References Config_getInt.

◆ convertFileNameFortranParserCode()

FortranFormat convertFileNameFortranParserCode ( const DString & fn)

Definition at line 2196 of file fortranscanner.l.

2197{
2198 DString ext = getFileNameExtension(fn);
2199 DString parserName = Doxygen::parserManager->getParserName(ext);
static ParserManager * parserManager
Definition doxygen.h:122
DString getParserName(const DString &extension)
Gets the name of the parser associated with given extension.
Definition parserintf.h:268
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4219
2200
2201 if (parserName == "fortranfixed") return FortranFormat::Fixed;
2202 else if (parserName == "fortranfree") return FortranFormat::Free;
2203
2205}

References Fixed, Free, getFileNameExtension(), ParserManager::getParserName(), Doxygen::parserManager, and Unknown.

Referenced by convertCppComments(), and setFileName().

◆ copyEntry()

void copyEntry ( std::shared_ptr< Entry > dest,
const std::shared_ptr< Entry > & src )
static

used to copy entry to an interface module procedure

Definition at line 2234 of file fortranscanner.l.

2235{
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;
2249}

Referenced by resolveModuleProcedures().

◆ endScope()

bool endScope ( yyscan_t yyscanner,
Entry * scope,
bool isGlobalRoot )
static

Ends scope in fortran program: may update subprogram arguments or module variable attributes.

See also
startScope()

Definition at line 2653 of file fortranscanner.l.

2654{
2655 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2656 if (yyextra->global_scope == scope)
2657 {
2658 yyextra->global_scope = nullptr;
2659 return true;
2660 }
2661 if (yyextra->global_scope == INVALID_ENTRY)
2662 {
2663 return true;
2664 }
2665 //cout<<"end scope: "<<scope->name<<endl;
2666 if (yyextra->current_root->parent() || isGlobalRoot)
2667 {
2668 yyextra->current_root= yyextra->current_root->parent(); /* end substructure */
2669 }
2670 else // if (yyextra->current_root != scope)
2671 {
2672 fprintf(stderr,"parse error in end <scopename>\n");
2673 scanner_abort(yyscanner);
2674 return false;
2675 }
#define INVALID_ENTRY
static void scanner_abort(yyscan_t yyscanner)
2676
2677 // create new current with possibly different defaults...
2678 yyextra->current = std::make_shared<Entry>();
2679 initEntry(yyscanner);
2680
2681 // update variables or subprogram arguments with yyextra->modifiers
2682 std::map<std::string,SymbolModifiers>& mdfsMap = yyextra->modifiers[scope];
2683
2684 if (scope->section.isFunction())
2685 {
2686 // iterate all symbol yyextra->modifiers of the scope
2687 for (const auto &kv : mdfsMap)
2688 {
2689 //cout<<it.key()<<": "<<qPrint(it)<<endl;
2690 Argument *arg = findArgument(scope, kv.first);
This class contains the information about the argument of a function or template.
Definition arguments.h:27
EntryType section
entry type (see Sections);
Definition entry.h:171
static Argument * findArgument(Entry *subprog, DString name, bool byTypeName=false)
2691
2692 if (arg)
2693 {
2694 applyModifiers(arg, kv.second);
2695 }
2696 }
2697
2698 // find return type for function
2699 //cout<<"RETURN NAME "<<yyextra->modifiers[yyextra->current_root][scope->name.lower()].returnName<<endl;
2700 DString returnName = yyextra->modifiers[yyextra->current_root][scope->name.lower().str()].returnName.lower();
2701 if (yyextra->modifiers[scope].find(returnName.str())!=yyextra->modifiers[scope].end())
2702 {
2703 scope->type = yyextra->modifiers[scope][returnName.str()].type; // returning type works
2704 applyModifiers(scope, yyextra->modifiers[scope][returnName.str()]); // returning array works
2705 }
const std::string & str() const
Definition dstring.h:645
DString name
member name
Definition entry.h:173
2706
2707 }
2708 if (scope->section.isClass() && scope->spec.isInterface())
2709 { // was INTERFACE_SEC
2710 if (scope->parent() && scope->parent()->section.isFunction())
2711 { // interface within function
2712 // iterate functions of interface and
2713 // try to find types for dummy(ie. argument) procedures.
2714 //cout<<"Search in "<<scope->name<<endl;
2715 for (const auto &ce : scope->children())
2716 {
2717 if (!ce->section.isFunction())
2718 continue;
const std::vector< std::shared_ptr< Entry > > & children() const
Definition entry.h:138
Entry * parent() const
Definition entry.h:133
2719
2720 // remove prefix
2721 DString name = ce->name.lower();
2722 if (size_t ii = name.rfind(':'); ii!=DString::npos) name.remove(0, ii+1);
2723 Argument *arg = findArgument(scope->parent(), name);
2724 if (arg)
2725 {
2726 // set type of dummy procedure argument to interface
2727 arg->type = "external " + ce->type + "(";
2728 for (size_t i=0; i<ce->argList.size(); i++)
2729 {
2730 if (i > 0)
2731 {
2732 arg->type = arg->type + ", ";
2733 }
2734 const Argument &subarg = ce->argList.at(i);
2735 arg->type = arg->type + subarg.type + " " + subarg.name;
2736 }
2737 arg->type = arg->type + ")";
2738 arg->name = name;
2739 }
2740 }
2741 // clear all yyextra->modifiers of the scope
2742 yyextra->modifiers.erase(scope);
2743 scope->parent()->removeSubEntry(scope);
2744 scope = nullptr;
2745 return true;
2746 }
2747 }
2748 if (!scope->section.isFunction())
2749 { // not function section
2750 // iterate variables: get and apply yyextra->modifiers
2751 for (const auto &ce : scope->children())
2752 {
2753 if (!ce->section.isVariable() && !ce->section.isFunction() && !ce->section.isClass())
2754 continue;
DString name
Definition arguments.h:45
void removeSubEntry(const Entry *e)
Definition entry.cpp:172
2755
2756 //cout<<ce->name<<", "<<mdfsMap.contains(ce->name.lower())<<mdfsMap.count()<<endl;
2757 if (mdfsMap.find(ce->name.lower().str())!=mdfsMap.end())
2758 applyModifiers(ce.get(), mdfsMap[ce->name.lower().str()]);
2759
2760 // remove prefix for variable names
2761 if (ce->section.isVariable() || ce->section.isFunction())
2762 {
2763 if (size_t end = ce->name.rfind(':'); end!=DString::npos) ce->name.remove(0, end+1);
2764 }
2765 }
2766 }
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180
2767
2768 // clear all yyextra->modifiers of the scope
2769 yyextra->modifiers.erase(scope);
2770
2771 // resolve procedures in types
static void resolveTypeBoundProcedures(Entry *scope)
2773
2774 return true;
2775}

References applyModifiers(), Entry::children(), end(), findArgument(), initEntry(), INVALID_ENTRY, DString::lower(), Argument::name, Entry::name, DString::npos, Entry::parent(), Entry::removeSubEntry(), resolveTypeBoundProcedures(), scanner_abort(), Entry::section, Entry::spec, DString::str(), Argument::type, Entry::type, and yyguts_t.

Referenced by parseMain().

◆ extractBind()

DString extractBind ( const DString & name)
static

remove useless spaces from bind statement

Definition at line 2311 of file fortranscanner.l.

2312{
2313 DString parensPart = extractFromParens(name);
2314 if (parensPart.length() == 1)
2315 {
2316 return "bind(C)";
2317 }
2318 else
2319 {
2320 //strip 'c'
2321 parensPart = parensPart.mid(1).stripWhiteSpace();
2322 // strip ','
2323 parensPart = parensPart.mid(1).stripWhiteSpace();
2324 // name part
2325 parensPart = parensPart.mid(4).stripWhiteSpace();
2326 // = part
2327 parensPart = parensPart.mid(1).stripWhiteSpace();
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
static DString extractFromParens(const DString &name)
2328
2329 return "bind(C, name=" + parensPart + ")";
2330 }
2331}

References extractFromParens(), DString::length(), DString::mid(), and DString::stripWhiteSpace().

Referenced by SymbolModifiers::operator|=().

◆ extractFromParens()

DString extractFromParens ( const DString & name)
static

Extracts string which resides within parentheses of provided string.

Definition at line 2293 of file fortranscanner.l.

2294{
2295 DString extracted = name;
2296 if (size_t start = extracted.find('('); start!=DString::npos)
2297 {
2298 extracted.remove(0, start+1);
2299 }
2300 if (size_t end = extracted.rfind(')'); end!=DString::npos)
2301 {
2302 size_t length = extracted.length();
2303 extracted.remove(end, length);
2304 }
2305 extracted = extracted.stripWhiteSpace();
DString & remove(size_t index, size_t len)
Definition dstring.h:535
2306
2307 return extracted;
2308}

References end(), DString::find(), DString::length(), DString::npos, DString::remove(), DString::rfind(), and DString::stripWhiteSpace().

Referenced by extractBind(), and SymbolModifiers::operator|=().

◆ findArgument()

Argument * findArgument ( Entry * subprog,
DString name,
bool byTypeName = false )
static

For debugging purposes.

Find argument with given name in subprog entry.

Definition at line 2476 of file fortranscanner.l.

2477{
2478 DString cname(name.lower());
2479 for (Argument &arg : subprog->argList)
2480 {
2481 if ((!byTypeName && arg.name.lower() == cname) ||
2482 (byTypeName && arg.type.lower() == cname)
2483 )
2484 {
2485 return &arg;
2486 }
2487 }
2488 return nullptr;
ArgumentList argList
member arguments as a list
Definition entry.h:194
2489}

References Entry::argList, DString::lower(), Argument::name, and Argument::type.

Referenced by endScope().

◆ getAmpersandAtTheStart()

int getAmpersandAtTheStart ( const char * buf,
int length )
static

Definition at line 1754 of file fortranscanner.l.

1755{
1756 for(int i=0; i<length; i++)
1757 {
1758 switch(buf[i])
1759 {
1760 case ' ':
1761 case '\t':
1762 break;
1763 case '&':
1764 return i;
1765 default:
1766 return -1;
1767 }
1768 }
1769 return -1;
1770}

◆ getAmpOrExclAtTheEnd()

int getAmpOrExclAtTheEnd ( const char * buf,
int length,
char ch )
static

Definition at line 1773 of file fortranscanner.l.

1774{
1775 // Avoid ampersands in string and yyextra->comments
1776 int parseState = Start;
1777 char quoteSymbol = 0;
1778 int ampIndex = -1;
1779 int commentIndex = -1;
1780 quoteSymbol = ch;
1781 if (ch != '\0') parseState = String;
1782
1783 for(int i=0; i<length && parseState!=Comment; i++)
1784 {
1785 // When in string, skip backslashes
1786 // Legacy code, not sure whether this is correct?
1787 if (parseState==String)
1788 {
1789 if (buf[i]=='\\') i++;
1790 }
1791
1792 switch(buf[i])
1793 {
1794 case '\'':
1795 case '"':
1796 // Close string, if quote symbol matches.
1797 // Quote symbol is set iff parseState==String
1798 if (buf[i]==quoteSymbol)
1799 {
1800 parseState = Start;
1801 quoteSymbol = 0;
1802 }
1803 // Start new string, if not already in string or comment
1804 else if (parseState==Start)
1805 {
1806 parseState = String;
1807 quoteSymbol = buf[i];
1808 }
1809 ampIndex = -1; // invalidate prev ampersand
1810 break;
1811 case '!':
1812 // When in string or comment, ignore exclamation mark
1813 if (parseState==Start)
1814 {
1815 parseState = Comment;
1816 commentIndex = i;
1817 }
1818 break;
1819 case ' ': // ignore whitespace
1820 case '\t':
1821 case '\n': // this may be at the end of line
1822 break;
1823 case '&':
1824 ampIndex = i;
1825 break;
1826 default:
1827 ampIndex = -1; // invalidate prev ampersand
1828 }
1829 }
1830
1831 if (ampIndex>=0)
1832 return ampIndex;
1833 else
1834 return commentIndex;
1835}

Referenced by prepassFixedForm().

◆ getLexerFILE()

const char * getLexerFILE ( )
inlinestatic

Definition at line 270 of file fortranscanner.l.

270{return __FILE__;}

◆ getParameter()

Argument * getParameter ( yyscan_t yyscanner,
const DString & name )
static

Get the argument name.

Definition at line 3097 of file fortranscanner.l.

3098{
3099 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3100 // std::cout<<"addFortranParameter(): "<<name<<" DOCS:"<<(docs.empty()?DString("null"):docs)<<"\n";
3101 Argument *ret = nullptr;
3102 for (Argument &a:yyextra->current_root->argList)
3103 {
3104 if (a.name.lower()==name.lower())
3105 {
3106 ret=&a;
3107 //printf("parameter found: %s\n",(const char*)name);
3108 break;
3109 }
3110 } // for
3111 return ret;
3112}

References DString::lower(), Argument::name, and yyguts_t.

Referenced by updateVariablePrepassComment().

◆ handleCommentBlock()

void handleCommentBlock ( yyscan_t yyscanner,
const DString & doc,
bool brief )
static

Definition at line 3132 of file fortranscanner.l.

3133{
3134 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3135 //printf("handleCommentBlock(doc=[%s] brief=%d yyextra->docBlockInBody=%d yyextra->docBlockJavaStyle=%d\n",
3136 // qPrint(doc),brief,yyextra->docBlockInBody,yyextra->docBlockJavaStyle);
3137
3138 bool hideInBodyDocs = Config_getBool(HIDE_IN_BODY_DOCS);
3139 if (yyextra->docBlockInBody && hideInBodyDocs)
3140 {
3141 yyextra->docBlockInBody = false;
3142 return;
3143 }
3144 DBG_CTX((stderr,"call parseCommentBlock [%s]\n",qPrint(doc)));
3145 int lineNr = brief ? yyextra->current->briefLine : yyextra->current->docLine;
3146 int position=0;
3147 bool needsEntry = false;
3148 Markdown markdown(yyextra->fileName,lineNr);
3149 GuardedSectionStack guards;
3150 DString strippedDoc = stripIndentation(doc);
3151 DString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(strippedDoc,lineNr) : strippedDoc;
3152 while (yyextra->commentScanner.parseCommentBlock(
3153 yyextra->thisParser,
3154 yyextra->docBlockInBody ? yyextra->subrCurrent.back().get() : yyextra->current.get(),
3155 processedDoc, // text
3156 yyextra->fileName, // file
3157 lineNr,
3158 yyextra->docBlockInBody ? false : brief,
3159 yyextra->docBlockInBody ? false : yyextra->docBlockJavaStyle,
3160 yyextra->docBlockInBody,
3161 yyextra->defaultProtection,
3162 position,
3163 needsEntry,
3164 Config_getBool(MARKDOWN_SUPPORT),
3165 &guards
3166 ))
3167 {
3168 DBG_CTX((stderr,"parseCommentBlock position=%d [%s] needsEntry=%d\n",position,doc.data()+position,needsEntry));
3169 if (needsEntry) addCurrentEntry(yyscanner,false);
3170 }
3171 DBG_CTX((stderr,"parseCommentBlock position=%d [%s] needsEntry=%d\n",position,doc.data()+position,needsEntry));
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
Helper class to process markdown formatted text.
Definition markdown.h:33
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
#define Config_getBool(name)
Definition config.h:33
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4696
3172
3173 if (needsEntry) addCurrentEntry(yyscanner,false);
3174 yyextra->docBlockInBody = false;
3175}

References addCurrentEntry(), Config_getBool, DString::data(), DBG_CTX, Markdown::process(), qPrint(), stripIndentation(), and yyguts_t.

Referenced by subrHandleCommentBlock(), and subrHandleCommentBlockResult().

◆ initEntry()

void initEntry ( yyscan_t yyscanner)
static

Definition at line 2945 of file fortranscanner.l.

2946{
2947 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2948 if (yyextra->typeMode)
2949 {
2950 yyextra->current->protection = yyextra->typeProtection;
2951 }
2952 else if (yyextra->current_root && yyextra->current_root->section.isClass() && yyextra->current_root->spec.isInterface())
2953 {
2954 yyextra->current->protection = Protection::Public;
2955 }
2956 else if (yyextra->current_root && yyextra->current_root->section.isFunction())
2957 {
2958 yyextra->current->protection = Protection::Private;
2959 }
2960 else
2961 {
2962 yyextra->current->protection = yyextra->defaultProtection;
2963 }
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());
2969}

References yyguts_t.

Referenced by addCurrentEntry(), endScope(), and startScope().

◆ initParser()

void initParser ( yyscan_t yyscanner)
static

Definition at line 2939 of file fortranscanner.l.

2940{
2941 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2942 yyextra->last_entry.reset();
2943}

References yyguts_t.

Referenced by parseMain().

◆ insertCharacter()

void insertCharacter ( char * contents,
int length,
int pos,
char c )
static

Definition at line 1853 of file fortranscanner.l.

1854{
1855 // shift tail by one character
1856 for(int i=length; i>pos; i--)
1857 contents[i]=contents[i-1];
1858 // set the character
1859 contents[pos] = c;
1860}

Referenced by prepassFixedForm().

◆ keyWordsFortranC()

bool keyWordsFortranC ( const char * contents)
static

Definition at line 2124 of file fortranscanner.l.

2125{
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"
2130 };
2131
2132 if (*contents != 'c' && *contents != 'C') return false;
2133
2134 const char *c = contents;
2135 DString keyword;
2136 while (*c && *c != ' ') {keyword += *c; c++;}
2137 keyword = keyword.lower();
2138
2139 return (fortran_C_keywords.find(keyword.str()) != fortran_C_keywords.end());
2140}

References DString::lower(), and DString::str().

Referenced by recognizeFixedForm().

◆ locatePrepassComment()

const static CommentInPrepass * locatePrepassComment ( yyscan_t yyscanner,
int from,
int to )
static

Definition at line 1722 of file fortranscanner.l.

1723{
1724 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1725 //printf("Locate %d-%d\n", from, to);
1726 for (const auto &cip : yyextra->comments)
1727 { // todo: optimize
1728 int c = cip.column;
1729 //printf("Candidate %d\n", c);
1730 if (c>=from && c<=to)
1731 {
1732 // comment for previous variable or parameter
1733 return &cip;
1734 }
1735 }
1736 return nullptr;
1737}

References CommentInPrepass::column, and yyguts_t.

Referenced by updateVariablePrepassComment().

◆ newLine()

void newLine ( yyscan_t yyscanner)
static

Definition at line 1698 of file fortranscanner.l.

1699{
1700 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1701 yyextra->lineNr++;
1702 yyextra->lineNr+=yyextra->lineCountPrepass;
1703 yyextra->lineCountPrepass=0;
1704 yyextra->comments.clear();
1705}

References yyguts_t.

◆ parseMain()

void parseMain ( yyscan_t yyscanner,
const DString & fileName,
const char * fileBuf,
const std::shared_ptr< Entry > & rt,
FortranFormat format )
static

Definition at line 3312 of file fortranscanner.l.

3314{
3315 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3316 char *tmpBuf = nullptr;
3317 initParser(yyscanner);
static void initParser(yyscan_t yyscanner)
3318
3319 if (fileBuf==nullptr || fileBuf[0]=='\0') return;
3320
3321 yyextra->defaultProtection = Protection::Public;
3322 yyextra->inputString = fileBuf;
3323 yyextra->inputPosition = 0;
3324 yyextra->inputStringPrepass = nullptr;
3325 yyextra->inputPositionPrepass = 0;
3326
3327 //yyextra->anonCount = 0; // don't reset per file
3328 yyextra->current_root = rt.get();
3329 yyextra->global_root = rt;
3330
3331 yyextra->isFixedForm = recognizeFixedForm(fileBuf,format);
bool recognizeFixedForm(const DString &contents, FortranFormat format)
3332
3333 if (yyextra->isFixedForm)
3334 {
3335 yyextra->fixedCommentAfter = Config_getInt(FORTRAN_COMMENT_AFTER);
3336 msg("Prepassing fixed form of {}\n", fileName);
3337 //printf("---strlen=%d\n", strlen(fileBuf));
3338 //clock_t start=clock();
#define msg(fmt,...)
Definition message.h:94
3339
3340 //printf("Input fixed form string:\n%s\n", fileBuf);
3341 //printf("===========================\n");
3342 yyextra->inputString = prepassFixedForm(fileBuf, nullptr,yyextra->fixedCommentAfter);
3343 Debug::print(Debug::FortranFixed2Free,0,"======== Fixed to Free format =========\n---- Input fixed form string ------- \n{}\n", fileBuf);
3344 Debug::print(Debug::FortranFixed2Free,0,"---- Resulting free form string ------- \n{}\n", yyextra->inputString);
3345 //printf("Resulting free form string:\n%s\n", yyextra->inputString);
3346 //printf("===========================\n");
@ FortranFixed2Free
Definition debug.h:41
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
const char * prepassFixedForm(const char *contents, int *hasContLine, int fixedCommentAfter)
3347
3348 //clock_t end=clock();
3349 //printf("CPU time used=%f\n", ((double) (end-start))/CLOCKS_PER_SEC);
3350 }
3351 else if (yyextra->inputString[strlen(fileBuf)-1] != '\n')
3352 {
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;
3358 }
3359
3360 yyextra->lineNr= 1 ;
3361 yyextra->fileName = fileName;
3362 msg("Parsing file {}...\n",yyextra->fileName);
3363
3364 yyextra->global_scope = rt.get();
3365 startScope(yyscanner,rt.get()); // implies yyextra->current_root = rt
3366 initParser(yyscanner);
3367 yyextra->commentScanner.enterFile(yyextra->fileName,yyextra->lineNr);
3368
3369 // add entry for the file
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;
3377
3378 fortranscannerYYrestart( nullptr, yyscanner );
3379 {
3380 BEGIN( Start );
3381 }
3382
3383 fortranscannerYYlex(yyscanner);
3384 yyextra->commentScanner.leaveFile(yyextra->fileName,yyextra->lineNr);
3385
3386 if (yyextra->global_scope && yyextra->global_scope != INVALID_ENTRY)
3387 {
3388 endScope(yyscanner,yyextra->current_root, true); // true - global root
3389 }
static bool endScope(yyscan_t yyscanner, Entry *scope, bool isGlobalRoot=false)
3390
3391 //debugCompounds(rt); //debug
3392
3393 rt->program.str(std::string());
3394 //delete yyextra->current; yyextra->current=0;
3395 yyextra->moduleProcedures.clear();
3396 if (tmpBuf)
3397 {
3398 free((char*)tmpBuf);
3399 yyextra->inputString=nullptr;
3400 }
3401 if (yyextra->isFixedForm)
3402 {
3403 free((char*)yyextra->inputString);
3404 yyextra->inputString=nullptr;
3405 }
3406
3407}

References Config_getInt, endScope(), Debug::FortranFixed2Free, initParser(), INVALID_ENTRY, msg, prepassFixedForm(), Debug::print(), recognizeFixedForm(), startScope(), and yyguts_t.

Referenced by FortranOutlineParser::parseInput().

◆ pop_state()

void pop_state ( yyscan_t yyscanner)
inlinestatic

Definition at line 3501 of file fortranscanner.l.

3502{
3503 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3504 if ( yyg->yy_start_stack_ptr <= 0 )
3505 warn(yyextra->fileName,yyextra->lineNr,"Unexpected statement '{}'",yytext );
3506 else
3507 yy_pop_state(yyscanner);
#define warn(file, line, fmt,...)
Definition message.h:97
3508}

References warn, and yyguts_t.

◆ popBlockState()

void popBlockState ( yyscan_t yyscanner)
static

Definition at line 3518 of file fortranscanner.l.

3519{
3520 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3521 if (yyextra->blockStack.empty())
3522 {
3523 warn(yyextra->fileName,yyextra->lineNr,"Internal inconsistency: empty stack while attempting popBlockState");
3524 }
3525 else
3526 {
3527 yyextra->blockStack.pop();
3528 }
3529 if (yyextra->blockStack.empty())
3530 {
3531 yyextra->blockString.clear();
3532 yyextra->blockLineNr=-1;
3533 }
3534 else
3535 {
3536 yyextra->blockString=yyextra->blockStack.top().blockString;
3537 yyextra->blockLineNr=yyextra->blockStack.top().blockLineNr;
3538 }
3539}

References warn, and yyguts_t.

◆ popBuffer()

void popBuffer ( yyscan_t yyscanner)
static

Definition at line 2224 of file fortranscanner.l.

2225{
2226 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2227 DBG_CTX((stderr, "--POP--"));
2228 yyextra->includeStackPtr --;
2229 yy_delete_buffer( YY_CURRENT_BUFFER, yyscanner );
2230 yy_switch_to_buffer( yyextra->includeStack[yyextra->includeStackPtr], yyscanner );
2231}

References DBG_CTX, and yyguts_t.

Referenced by FortranOutlineParser::parsePrototype().

◆ prepassFixedForm()

const char * prepassFixedForm ( const char * contents,
int * hasContLine,
int fixedCommentAfter )

Definition at line 1864 of file fortranscanner.l.

1865{
1866 int column=0;
1867 int prevLineLength=0;
1868 int prevLineAmpOrExclIndex=-1;
1869 int skipped = 0;
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;
1879 bool spaces=true;
1880 int newContentsSize = (int)strlen(contents)+3; // \000, \n (when necessary) and one spare character (to avoid reallocation)
1881 char* newContents = (char*)malloc(newContentsSize);
1882 int curLine = 1;
1883 size_t sizCont;
1884
1885 int j = -1;
1886 sizCont = strlen(contents);
1887 for(size_t i=0;i<sizCont;i++) {
1888 column++;
1889 char c = contents[i];
1890 if (artificialComment && c != '\n')
1891 {
1892 if (c == '!' && spaces)
1893 {
1894 newContents[j++] = c;
1895 artificialComment = false;
1896 spaces = false;
1897 skipped = 0;
1898 continue;
1899 }
1900 else if (c == ' ' || c == '\t') continue;
1901 else
1902 {
1903 spaces = false;
1904 skipped++;
1905 continue;
1906 }
1907 }
1908
1909 j++;
1910 if (j>=newContentsSize-3) { // check for spare characters, which may be eventually used below (by & and '! ')
1911 newContents = (char*)realloc(newContents, newContentsSize+1000);
1912 newContentsSize = newContentsSize+1000;
1913 }
1914
1915 switch(c) {
1916 case '\n':
1917 if (!fullCommentLine)
1918 {
1919 prevLineLength=column;
1920 prevLineAmpOrExclIndex=getAmpOrExclAtTheEnd(&contents[i-prevLineLength+1], prevLineLength,prevQuote);
1921 if (prevLineAmpOrExclIndex == -1) prevLineAmpOrExclIndex = column - 1;
1922 if (skipped)
1923 {
1924 prevLineAmpOrExclIndex = -1;
1925 skipped = 0;
1926 }
1927 }
1928 else
1929 {
1930 prevLineLength+=column;
1931 /* Even though a full comment line is not really a comment line it can be seen as one. An empty line is also seen as a comment line (small bonus) */
1932 if (hasContLine)
1933 {
1934 hasContLine[curLine - 1] = 1;
1935 }
1936 }
1937 artificialComment=false;
1938 spaces=true;
1939 fullCommentLine=true;
1940 column=0;
1941 emptyLabel=true;
1942 commented=false;
1943 newContents[j]=c;
1944 prevQuote = thisQuote;
1945 curLine++;
1946 break;
1947 case ' ':
1948 case '\t':
1949 newContents[j]=c;
1950 break;
1951 case '\000':
1952 if (hasContLine)
1953 {
1954 free(newContents);
1955 return nullptr;
1956 }
1957 newContents[j]='\000';
1958 newContentsSize = (int)strlen(newContents);
1959 if (newContents[newContentsSize - 1] != '\n')
1960 {
1961 // to be on the safe side
1962 newContents = (char*)realloc(newContents, newContentsSize+2);
1963 newContents[newContentsSize] = '\n';
1964 newContents[newContentsSize + 1] = '\000';
1965 }
1966 return newContents;
1967 case '"':
1968 case '\'':
1969 case '\\':
1970 if ((column <= fixedCommentAfter) && (column!=6) && !commented)
1971 {
1972 // we have some special cases in respect to strings and escaped string characters
1973 fullCommentLine=false;
1974 newContents[j]=c;
1975 if (c == '\\')
1976 {
1977 inBackslash = !inBackslash;
1978 break;
1979 }
1980 else if (c == '\'')
1981 {
1982 if (!inDouble)
1983 {
1984 inSingle = !inSingle;
1985 if (inSingle) thisQuote = c;
1986 else thisQuote = '\0';
1987 }
1988 break;
1989 }
1990 else if (c == '"')
1991 {
1992 if (!inSingle)
1993 {
1994 inDouble = !inDouble;
1995 if (inDouble) thisQuote = c;
1996 else thisQuote = '\0';
1997 }
1998 break;
1999 }
2000 }
2001 inBackslash = false;
2002 // fallthrough
2003 case '#':
2004 case 'C':
2005 case 'c':
2006 case '*':
2007 case '!':
2008 if ((column <= fixedCommentAfter) && (column!=6))
2009 {
2010 emptyLabel=false;
2011 if (column==1)
2012 {
2013 newContents[j]='!';
2014 commented = true;
2015 }
2016 else if ((c == '!') && !inDouble && !inSingle)
2017 {
2018 newContents[j]=c;
2019 commented = true;
2020 }
2021 else
2022 {
2023 if (!commented) fullCommentLine=false;
2024 newContents[j]=c;
2025 }
2026 break;
2027 }
2028 // fallthrough
2029 default:
2030 if (!commented && (column < 6) && ((c - '0') >= 0) && ((c - '0') <= 9))
2031 { // remove numbers, i.e. labels from first 5 positions.
2032 newContents[j]=' ';
2033 }
2034 else if (column==6 && emptyLabel)
2035 { // continuation
2036 if (!commented) fullCommentLine=false;
2037 if (c != '0')
2038 { // 0 not allowed as continuation character, see f95 standard paragraph 3.3.2.3
2039 newContents[j]=' ';
static int getAmpOrExclAtTheEnd(const char *buf, int length, char ch)
2040
2041 if (prevLineAmpOrExclIndex==-1)
2042 { // add & just before end of previous line
2043 /* first line is not a continuation line in code, just in snippets etc. */
2044 if (curLine != 1) insertCharacter(newContents, j+1, (j+1)-6-1, '&');
2045 j++;
2046 }
2047 else
2048 { // add & just before end of previous line comment
2049 /* first line is not a continuation line in code, just in snippets etc. */
2050 if (curLine != 1) insertCharacter(newContents, j+1, (j+1)-6-prevLineLength+prevLineAmpOrExclIndex+skipped, '&');
2051 skipped = 0;
2052 j++;
2053 }
2054 if (hasContLine)
2055 {
2056 hasContLine[curLine - 1] = 1;
2057 }
2058 }
2059 else
2060 {
2061 newContents[j]=c; // , just handle like space
2062 }
2063 prevLineLength=0;
2064 }
2065 else if ((column > fixedCommentAfter) && !commented)
2066 {
2067 // first non commented non blank character after position fixedCommentAfter
2068 if (c == '&')
2069 {
2070 newContents[j]=' ';
2071 }
2072 else if (c != '!')
2073 {
2074 // I'm not a possible start of doxygen comment
2075 newContents[j]=' ';
2076 artificialComment = true;
2077 spaces=true;
2078 skipped = 0;
2079 }
2080 else
2081 {
2082 newContents[j]=c;
2083 commented = true;
2084 }
2085 }
2086 else
2087 {
2088 if (!commented) fullCommentLine=false;
2089 newContents[j]=c;
2090 emptyLabel=false;
2091 }
2092 break;
2093 }
2094 }
static void insertCharacter(char *contents, int length, int pos, char c)
2095
2096 if (hasContLine)
2097 {
2098 free(newContents);
2099 return nullptr;
2100 }
2101
2102 if (j==-1) // contents was empty
2103 {
2104 newContents = (char*)realloc(newContents, 2);
2105 newContents[0] = '\n';
2106 newContents[1] = '\000';
2107 }
2108 else if (newContents[j] == '\n') // content ended with newline
2109 {
2110 newContents = (char*)realloc(newContents, j+2);
2111 newContents[j + 1] = '\000';
2112 }
2113 else // content did not end with a newline
2114 {
2115 newContents = (char*)realloc(newContents, j+3);
2116 newContents[j + 1] = '\n';
2117 newContents[j + 2] = '\000';
2118 }
2119 return newContents;
2120}

References getAmpOrExclAtTheEnd(), and insertCharacter().

Referenced by checkContLines(), and parseMain().

◆ pushBlockState()

void pushBlockState ( yyscan_t yyscanner,
const DString & text )
static

Definition at line 3510 of file fortranscanner.l.

3511{
3512 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3513 yyextra->blockString = text;
3514 yyextra->blockLineNr = yyextra->lineNr;
3515 yyextra->blockStack.emplace(yyextra->blockString,yyextra->blockLineNr);
3516}

References yyguts_t.

Referenced by addInterface(), and addSubprogram().

◆ pushBuffer()

void pushBuffer ( yyscan_t yyscanner,
const DString & buffer )
static

Definition at line 2210 of file fortranscanner.l.

2211{
2212 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2213 if (yyextra->includeStackCnt <= yyextra->includeStackPtr)
2214 {
2215 yyextra->includeStackCnt++;
2216 yyextra->includeStack = (YY_BUFFER_STATE *)realloc(yyextra->includeStack, yyextra->includeStackCnt * sizeof(YY_BUFFER_STATE));
2217 }
2218 yyextra->includeStack[yyextra->includeStackPtr++] = YY_CURRENT_BUFFER;
2219 yy_switch_to_buffer(yy_scan_string(buffer.data(),yyscanner),yyscanner);
2220
2221 DBG_CTX((stderr, "--PUSH--%s", qPrint(buffer)));
2222}

References DString::data(), DBG_CTX, qPrint(), and yyguts_t.

Referenced by FortranOutlineParser::parsePrototype().

◆ recognizeFixedForm()

bool recognizeFixedForm ( const DString & contents,
FortranFormat format )

Definition at line 2143 of file fortranscanner.l.

2144{
2145 int column=0;
2146 bool skipLine=false;
2147
2148 if (format == FortranFormat::Fixed) return true;
2149 if (format == FortranFormat::Free) return false;
2150
2151 int tabSize=Config_getInt(TAB_SIZE);
2152 size_t sizCont = contents.length();
2153 for (size_t i=0;i<sizCont;i++)
2154 {
2155 column++;
2156
2157 switch(contents.at(i))
2158 {
2159 case '\n':
2160 column=0;
2161 skipLine=false;
2162 break;
2163 case '\t':
2164 column += tabSize-1;
2165 break;
2166 case ' ':
2167 break;
2168 case '\000':
2169 return false;
2170 case '#':
2171 skipLine=true;
2172 break;
2173 case 'C':
2174 case 'c':
2175 if (column==1)
2176 {
2177 return !keyWordsFortranC(contents.data()+i);
2178 }
2179 // fallthrough
2180 case '*':
2181 if (column==1) return true;
2182 if (skipLine) break;
2183 return false;
2184 case '!':
2185 if (column!=6) skipLine=true;
2186 break;
2187 default:
2188 if (skipLine) break;
2189 if (column>=7) return true;
2190 return false;
2191 }
2192 }
2193 return false;
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
static bool keyWordsFortranC(const char *contents)
2194}

References DString::at(), Config_getInt, DString::data(), Fixed, Free, keyWordsFortranC(), and DString::length().

Referenced by convertCppComments(), FortranCodeParser::parseCode(), parseMain(), and setFileName().

◆ resolveModuleProcedures()

void resolveModuleProcedures ( yyscan_t yyscanner,
Entry * current_root )
static

fill empty interface module procedures with info from corresponding module subprogs

TODO: handle procedures in used modules

Definition at line 2256 of file fortranscanner.l.

2257{
2258 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2259 if (yyextra->moduleProcedures.empty()) return;
2260
2261 // build up map of available functions
2262 std::map<std::string,std::shared_ptr<Entry>> procMap;
2263 {
2264 for (const auto& cf: current_root->children())
2265 {
2266 if (!cf->section.isFunction())
2267 continue;
2268
2269 // remove scope from name
2270 DString name = cf->name;
2271 {
2272 if (size_t end = name.rfind(':') ; end!=DString::npos) name.remove(0, end+1);
2273 }
2274
2275 procMap.emplace(name.str(), cf);
2276 }
2277 }
2278
2279
2280 // for all module procedures
2281 for (const auto& ce1: yyextra->moduleProcedures)
2282 {
2283 if (procMap.find(ce1->name.str())!=procMap.end())
2284 {
2285 std::shared_ptr<Entry> proc = procMap[ce1->name.str()];
2286 copyEntry(ce1, proc);
2287 }
2288 } // for all interface module procedures
2289 yyextra->moduleProcedures.clear();
static void copyEntry(std::shared_ptr< Entry > dest, const std::shared_ptr< Entry > &src)
used to copy entry to an interface module procedure
2290}

References Entry::children(), copyEntry(), end(), DString::npos, and yyguts_t.

◆ resolveTypeBoundProcedures()

void resolveTypeBoundProcedures ( Entry * scope)
static

search for types with type bound procedures (e.g. methods) and try to resolve their arguments

Definition at line 2780 of file fortranscanner.l.

2781{
2782 // map of all subroutines/functions
2783 bool procMapCreated = false;
2784 std::unordered_map<std::string,std::shared_ptr<Entry>> procMap;
2785
2786 // map of all abstract interfaces
2787 bool interfMapCreated = false;
2788 std::unordered_map<std::string,std::shared_ptr<Entry>> interfMap;
2789
2790 // iterate over all types
2791 for (const auto &ce: scope->children())
2792 {
2793 if (!ce->section.isClass())
2794 continue;
2795
2796 // handle non-"generic" non-"deferred" methods, copying the arguments from the implementation
2797 std::unordered_map<std::string,std::shared_ptr<Entry>> methodMap;
2798 for (auto &ct: ce->children())
2799 {
2800 if (!ct->section.isFunction())
2801 continue;
2802
2803 if (ct->type=="generic")
2804 continue;
2805
2806 if (ct->virt==Specifier::Pure)
2807 continue;
2808
2809 // set up the procMap
2810 if (!procMapCreated)
2811 {
2812 for (const auto &cf: scope->children())
2813 {
2814 if (cf->section.isFunction())
2815 {
2816 procMap.emplace(cf->name.str(), cf);
2817 }
2818 }
2819 procMapCreated = true;
2820 }
2821
2822 // found a (non-generic) method
2823 DString implName = ct->args;
2824 if (procMap.find(implName.str())!=procMap.end())
2825 {
2826 std::shared_ptr<Entry> proc = procMap[implName.str()];
2827 ct->args = proc->args;
2828 ct->argList = ArgumentList(proc->argList);
2829 if (ct->brief.empty())
2830 {
2831 ct->brief = proc->brief;
2832 ct->briefLine = proc->briefLine;
2833 ct->briefFile = proc->briefFile;
2834 }
2835 if (ct->doc.empty())
2836 {
2837 ct->doc = proc->doc;
2838 ct->docLine = proc->docLine;
2839 ct->docFile = proc->docFile;
2840 }
2841 methodMap.emplace(ct->name.str(), ct);
2842 }
2843 }
This class represents an function or template argument list.
Definition arguments.h:66
2844
2845 // handle "deferred" methods (pure virtual functions), duplicating with arguments from the target abstract interface
2846 for (auto &ct: ce->children())
2847 {
2848 if (!ct->section.isFunction())
2849 continue;
2850
2851 if (ct->virt != Specifier::Pure)
2852 continue;
2853
2854 // set up the procMap
2855 if (!interfMapCreated)
2856 {
2857 for(const auto &cf: scope->children())
2858 {
2859 if (cf->section.isClass() && cf->spec.isInterface() && cf->type=="abstract")
2860 {
2861 std::shared_ptr<Entry> ci = cf->children().front();
2862 interfMap.emplace(ci->name.str(), ci);
2863 }
2864 }
2865 interfMapCreated = true;
2866 }
2867
2868 // found a (non-generic) method
2869 DString implName = ct->args;
2870 if (interfMap.find(implName.str())!= interfMap.end() )
2871 {
2872 std::shared_ptr<Entry> proc = interfMap[implName.str()];
2873 ct->args = proc->args;
2874 ct->argList = ArgumentList(proc->argList);
2875 if (ct->brief.empty())
2876 {
2877 ct->brief = proc->brief;
2878 ct->briefLine = proc->briefLine;
2879 ct->briefFile = proc->briefFile;
2880 }
2881 if (ct->doc.empty())
2882 {
2883 ct->doc = proc->doc;
2884 ct->docLine = proc->docLine;
2885 ct->docFile = proc->docFile;
2886 }
2887
2888 methodMap.emplace(ct->name.str(), ct);
2889 }
2890 }
2891
2892 // handle "generic" methods (that is function overloading!), duplicating with arguments from the target method of the type
2893 {
2894 for (auto &ct: ce->children())
2895 {
2896 if (!ct->section.isFunction())
2897 continue;
2898
2899 if (ct->type!="generic")
2900 continue;
2901
2902 // found a generic method (already duplicated for each entry by the parser)
2903 DString methodName = ct->args;
2904 if (methodMap.find(methodName.str()) != methodMap.end())
2905 {
2906 std::shared_ptr<Entry> method = methodMap[methodName.str()];
2907 ct->args = method->args;
2908 ct->argList = ArgumentList(method->argList);
2909 if (ct->brief.empty())
2910 {
2911 ct->brief = method->brief;
2912 ct->briefLine = method->briefLine;
2913 ct->briefFile = method->briefFile;
2914 }
2915 if (ct->doc.empty())
2916 {
2917 ct->doc = method->doc;
2918 ct->docLine = method->docLine;
2919 ct->docFile = method->docFile;
2920 }
2921 }
2922 }
2923 }
2924 }
2925}

References Entry::children(), and DString::str().

Referenced by endScope().

◆ scanner_abort()

void scanner_abort ( yyscan_t yyscanner)
static

Definition at line 3467 of file fortranscanner.l.

3468{
3469 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3470 fprintf(stderr,"********************************************************************\n");
3471 if (yyextra->blockLineNr == -1)
3472 {
3473 fprintf(stderr,"Error in file %s line: %d, state: %d(%s)\n",
3474 qPrint(yyextra->fileName),yyextra->lineNr,YY_START,stateToString(YY_START));
3475 }
3476 else
3477 {
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);
3480 }
3481 fprintf(stderr,"********************************************************************\n");
static const char * stateToString(int state)
3482
3483 // empty the stack
3484 while (!yyextra->blockStack.empty()) yyextra->blockStack.pop();
3485
3486 bool start=false;
3487
3488 for (const auto &ce : yyextra->global_root->children())
3489 {
3490 if (ce == yyextra->file_root) start=true;
3491 if (start) ce->reset();
3492 }
3493
3494 // dummy call to avoid compiler warning
3495 (void)yy_top_state(yyscanner);
3496
3497 return;
3498 //exit(-1);
3499}

References qPrint(), stateToString(), and yyguts_t.

Referenced by endScope().

◆ startCommentBlock()

void startCommentBlock ( yyscan_t yyscanner,
bool brief )
static

Definition at line 3115 of file fortranscanner.l.

3116{
3117 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3118 if (brief)
3119 {
3120 yyextra->current->briefFile = yyextra->fileName;
3121 yyextra->current->briefLine = yyextra->lineNr;
3122 }
3123 else
3124 {
3125 yyextra->current->docFile = yyextra->fileName;
3126 yyextra->current->docLine = yyextra->lineNr;
3127 }
3128}

References yyguts_t.

◆ startScope()

void startScope ( yyscan_t yyscanner,
Entry * scope )
static

Starts the new scope in fortran program. Consider using this function when starting module, interface, function or other program block.

See also
endScope()

Definition at line 2637 of file fortranscanner.l.

2638{
2639 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2640 //cout<<"start scope: "<<scope->name<<endl;
2641 yyextra->current_root= scope; /* start substructure */
2642
2643 yyextra->modifiers.emplace(scope, std::map<std::string,SymbolModifiers>());
2644
2645 // create new current with possibly different defaults...
2646 yyextra->current = std::make_shared<Entry>();
2647 initEntry(yyscanner);
2648}

References initEntry(), and yyguts_t.

Referenced by addModule(), and parseMain().

◆ stateToString()

const char * stateToString ( int state)
static

Referenced by scanner_abort().

◆ subrHandleCommentBlock()

void subrHandleCommentBlock ( yyscan_t yyscanner,
const DString & doc,
bool brief )
static

Handle parameter description as defined after the declaration of the parameter.

Definition at line 3179 of file fortranscanner.l.

3180{
3181 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3182 DString loc_doc;
3183 loc_doc = doc.stripWhiteSpace();
3184
3185 std::shared_ptr<Entry> tmp_entry = yyextra->current;
3186 yyextra->current = yyextra->subrCurrent.back(); // temporarily switch to the entry of the subroutine / function
3187
3188 // Still in the specification section so no inbodyDocs yet, but parameter documentation
3189 yyextra->current->inbodyDocs = "";
3190
3191 // strip \\param or @param, so we can do some extra checking. We will add it later on again.
3192 if (loc_doc.stripPrefix("\\param") ||
3193 loc_doc.stripPrefix("@param")
3194 ) loc_doc = loc_doc.stripWhiteSpace();
bool stripPrefix(const DString &prefix)
Definition dstring.h:290
3195
3196 // direction as defined with the declaration of the parameter
3197 int dir1 = yyextra->modifiers[yyextra->current_root][yyextra->argName.lower().str()].direction;
3198 // in description [in] is specified
3199 if (loc_doc.lower().find(directionParam[SymbolModifiers::IN]) == 0)
3200 {
3201 // check if with the declaration intent(in) or nothing has been specified
3204 {
3205 // strip direction
3206 loc_doc = loc_doc.mid(strlen(directionParam[SymbolModifiers::IN]));
3207 loc_doc.stripWhiteSpace();
3208 // in case of empty documentation or (now) just name, consider it as no documentation
3209 if (!loc_doc.empty() && (loc_doc.lower() != yyextra->argName.lower()))
3210 {
3211 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[SymbolModifiers::IN] + " " +
3212 yyextra->argName + " " + loc_doc,brief);
3213 }
3214 }
3215 else
3216 {
3217 // something different specified, give warning and leave error.
3218 warn(yyextra->fileName,yyextra->lineNr, "Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3219 yyextra->current->name,yyextra->current->args,yyextra->argName);
3220 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[dir1] + " " +
3221 yyextra->argName + " " + loc_doc,brief);
3222 }
3223 }
3224 // analogous to the [in] case, here [out] direction specified
3225 else if (loc_doc.lower().find(directionParam[SymbolModifiers::OUT]) == 0)
3226 {
3229 {
3230 loc_doc = loc_doc.mid(strlen(directionParam[SymbolModifiers::OUT]));
3231 loc_doc.stripWhiteSpace();
3232 if (loc_doc.empty() || (loc_doc.lower() == yyextra->argName.lower()))
3233 {
3234 yyextra->current = tmp_entry;
3235 return;
3236 }
3237 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[SymbolModifiers::OUT] + " " +
3238 yyextra->argName + " " + loc_doc,brief);
3239 }
3240 else
3241 {
3242 warn(yyextra->fileName,yyextra->lineNr, "Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3243 yyextra->current->name,yyextra->current->args,yyextra->argName);
3244 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[dir1] + " " +
3245 yyextra->argName + " " + loc_doc,brief);
3246 }
3247 }
3248 // analogous to the [in] case, here [in,out] direction specified
3249 else if (loc_doc.lower().find(directionParam[SymbolModifiers::INOUT]) == 0)
3250 {
3253 {
3254 loc_doc = loc_doc.mid(strlen(directionParam[SymbolModifiers::INOUT]));
3255 loc_doc.stripWhiteSpace();
3256 if (!loc_doc.empty() && (loc_doc.lower() != yyextra->argName.lower()))
3257 {
3258 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[SymbolModifiers::INOUT] + " " +
3259 yyextra->argName + " " + loc_doc,brief);
3260 }
3261 }
3262 else
3263 {
3264 warn(yyextra->fileName,yyextra->lineNr, "Routine: {}{} inconsistency between intent attribute and documentation for parameter {}:",
3265 yyextra->current->name,yyextra->current->args,yyextra->argName);
3266 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[dir1] + " " +
3267 yyextra->argName + " " + loc_doc,brief);
3268 }
3269 }
3270 // analogous to the [in] case; here no direction specified
3271 else if (!loc_doc.empty() && (loc_doc.lower() != yyextra->argName.lower()))
3272 {
3273 handleCommentBlock(yyscanner,DString("\n\n@param ") + directionParam[dir1] + " " +
3274 yyextra->argName + " " + loc_doc,brief);
3275 }
static const char * directionParam[]
static void handleCommentBlock(yyscan_t yyscanner, const DString &doc, bool brief)
3276
3277 // reset yyextra->current back to the part inside the routine
3278 yyextra->current = tmp_entry;
3279}

References DString::back(), directionParam, DString::empty(), DString::find(), handleCommentBlock(), SymbolModifiers::IN, SymbolModifiers::INOUT, DString::lower(), DString::mid(), SymbolModifiers::NONE_D, SymbolModifiers::OUT, DString::stripPrefix(), DString::stripWhiteSpace(), warn, and yyguts_t.

◆ subrHandleCommentBlockResult()

void subrHandleCommentBlockResult ( yyscan_t yyscanner,
const DString & doc,
bool brief )
static

Handle result description as defined after the declaration of the parameter.

Definition at line 3282 of file fortranscanner.l.

3283{
3284 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3285 DString loc_doc;
3286 loc_doc = doc.stripWhiteSpace();
3287
3288 std::shared_ptr<Entry> tmp_entry = yyextra->current;
3289 yyextra->current = yyextra->subrCurrent.back(); // temporarily switch to the entry of the subroutine / function
3290
3291 // Still in the specification section so no inbodyDocs yet, but parameter documentation
3292 yyextra->current->inbodyDocs = "";
3293
3294 // strip \\returns or @returns. We will add it later on again.
3295 if (loc_doc.stripPrefix("\\returns") ||
3296 loc_doc.stripPrefix("\\return") ||
3297 loc_doc.stripPrefix("@returns") ||
3298 loc_doc.stripPrefix("@return")
3299 ) loc_doc = loc_doc.stripWhiteSpace();
3300
3301 if (!loc_doc.empty() && (loc_doc.lower() != yyextra->argName.lower()))
3302 {
3303 handleCommentBlock(yyscanner,DString("\n\n@returns ") + loc_doc,brief);
3304 }
3305
3306 // reset yyextra->current back to the part inside the routine
3307 yyextra->current = std::move(tmp_entry);
3308}

References DString::back(), DString::empty(), handleCommentBlock(), DString::lower(), DString::stripPrefix(), DString::stripWhiteSpace(), and yyguts_t.

◆ truncatePrepass()

void truncatePrepass ( yyscan_t yyscanner,
int index )
static

Definition at line 1840 of file fortranscanner.l.

1841{
1842 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
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]=='<') { // save comment
1846 yyextra->comments.emplace_back(index, yyextra->inputStringPrepass.right(length-i-2));
1847 }
1848 }
1849 yyextra->inputStringPrepass.resize(index);
1850}

References yyguts_t.

◆ updateVariablePrepassComment()

void updateVariablePrepassComment ( yyscan_t yyscanner,
int from,
int to )
static

Definition at line 1739 of file fortranscanner.l.

1740{
1741 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1742 const CommentInPrepass *c = locatePrepassComment(yyscanner,from, to);
1743 if (c && yyextra->vtype == V_VARIABLE)
1744 {
1745 yyextra->last_entry->brief = c->str;
1746 }
1747 else if (c && yyextra->vtype == V_PARAMETER)
1748 {
1749 Argument *parameter = getParameter(yyscanner,yyextra->argName);
1750 if (parameter) parameter->docs = c->str;
1751 }
DString docs
Definition arguments.h:48
@ V_VARIABLE
@ V_PARAMETER
static Argument * getParameter(yyscan_t yyscanner, const DString &name)
static const CommentInPrepass * locatePrepassComment(yyscan_t yyscanner, int from, int to)
1752}

References Argument::docs, getParameter(), locatePrepassComment(), CommentInPrepass::str, V_PARAMETER, V_VARIABLE, and yyguts_t.

◆ yylex()

int yylex ( yyscan_t yyscanner)

fortran parsing states

comment parsing states prototype parsing

Definition at line 378 of file fortranscanner.l.

382 {BS}[&]*{BS}!.*\n { /* skip lines with just comment. Note code was in free format or has been converted to it */
383 yyextra->lineCountPrepass ++;
384 }
385<Prepass>^{BS}\n { /* skip empty lines */
386 yyextra->lineCountPrepass ++;
387 }
388<*>^.*\n { // prepass: look for line continuations
389 yyextra->functionLine = false;
390
391 DBG_CTX((stderr, "---%s", yytext));
392
393 int indexStart = getAmpersandAtTheStart(yytext, (int)yyleng);
394 int indexEnd = getAmpOrExclAtTheEnd(yytext, (int)yyleng, '\0');
395 if (indexEnd>=0 && yytext[indexEnd]!='&') //we are only interested in amp
396 {
397 indexEnd=-1;
398 }
static int getAmpersandAtTheStart(const char *buf, int length)
399
400 if (indexEnd<0)
401 { // ----- no ampersand as line continuation
402 if (YY_START == Prepass)
403 { // last line in "continuation"
404
405 // Only take input after initial ampersand
406 yyextra->inputStringPrepass+=(const char*)(yytext+(indexStart+1));
407
408 //printf("BUFFER:%s\n", (const char*)yyextra->inputStringPrepass);
409 pushBuffer(yyscanner,yyextra->inputStringPrepass);
410 yyextra->colNr = 0;
411 pop_state(yyscanner);
412 }
413 else
414 { // simple line
415 yyextra->colNr = 0;
416 REJECT;
417 }
418 }
419 else
420 { // ----- line with continuation
421 if (YY_START != Prepass)
422 {
423 yyextra->comments.clear();
424 yyextra->inputStringPrepass=DString();
425 yy_push_state(Prepass,yyscanner);
426 }
static void pushBuffer(yyscan_t yyscanner, const DString &buffer)
static void pop_state(yyscan_t yyscanner)
427
428 size_t length = yyextra->inputStringPrepass.length();
429
430 // Only take input after initial ampersand
431 yyextra->inputStringPrepass+=(const char*)(yytext+(indexStart+1));
432 yyextra->lineCountPrepass ++;
433
434 // cut off & and remove following comment if present
435 truncatePrepass(yyscanner,static_cast<int>(length) + indexEnd - indexStart - 1);
436 }
437 }
static void truncatePrepass(yyscan_t yyscanner, int index)
438
439
440 /*------ ignore strings that are not initialization strings */
441<String>\"|\' { // string ends with next quote without previous backspace
442 if (yytext[0]!=yyextra->stringStartSymbol)
443 {
444 yyextra->colNr -= (int)yyleng;
445 REJECT;
446 } // single vs double quote
447 if (yy_top_state(yyscanner) == Initialization ||
448 yy_top_state(yyscanner) == ArrayInitializer)
449 {
450 yyextra->initializer+=yytext;
451 }
452 pop_state(yyscanner);
453 }
454<String>[\x80-\xFF]* |
455<String>. { if (yy_top_state(yyscanner) == Initialization ||
456 yy_top_state(yyscanner) == ArrayInitializer)
457 {
458 yyextra->initializer+=yytext;
459 }
460 }
461<*>\"|\' { /* string starts */
462 if (YY_START == StrIgnore)
463 { yyextra->colNr -= (int)yyleng;
464 REJECT;
465 }; // ignore in simple yyextra->comments
466 yy_push_state(YY_START,yyscanner);
467 if (yy_top_state(yyscanner) == Initialization ||
468 yy_top_state(yyscanner) == ArrayInitializer)
469 {
470 yyextra->initializer+=yytext;
471 }
472 yyextra->stringStartSymbol=yytext[0]; // single or double quote
473 BEGIN(String);
474 }
475
476 /*------ ignore simple comment (not documentation yyextra->comments) */
477
478<*>"!"/([^<>\n]|"<ff>"|"<FF>") { if (YY_START == String || YY_START == DocCopyBlock)
479 { yyextra->colNr -= (int)yyleng;
480 REJECT;
481 } // "!" is ignored in strings
482 // skip comment line (without docu yyextra->comments "!>" "!<" )
483 /* ignore further "!" and ignore yyextra->comments in Strings */
484 if ((YY_START != StrIgnore) && (YY_START != String))
485 {
486 yy_push_state(YY_START,yyscanner);
487 BEGIN(StrIgnore);
488 yyextra->debugStr="*!";
489 DBG_CTX((stderr,"start comment %d\n",yyextra->lineNr));
490 }
491 }
492<StrIgnore>.?/\n { pop_state(yyscanner); // comment ends with endline character
493 DBG_CTX((stderr,"end comment %d %s\n",yyextra->lineNr,qPrint(yyextra->debugStr)));
494 } // comment line ends
495<StrIgnore>[\x80-\xFF]* |
496<StrIgnore>. { yyextra->debugStr+=yytext; }
497
498
499 /*------ use handling ------------------------------------------------------------*/
500
501<Start,ModuleBody,SubprogBody>"use"{BS_} {
502 if (YY_START == Start)
503 {
504 addModule(yyscanner);
505 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
506 yy_push_state(ModuleBody,yyscanner); //anon program
507 }
508 yy_push_state(Use,yyscanner);
509 }
510<Use>{ID} {
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;
518 pop_state(yyscanner);
519 }
520<Use>{ID}/, {
521 yyextra->useModuleName=yytext;
522 yyextra->useModuleName=yyextra->useModuleName.lower();
523 }
524<Use>,{BS}"ONLY" { BEGIN(UseOnly);
525 }
526<UseOnly>{BS},{BS} {}
527<UseOnly>{ID} {
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;
534 }
535<Use,UseOnly>"\n" {
536 yyextra->colNr -= 1;
537 unput(*yytext);
538 pop_state(yyscanner);
539 }
540
541 /* INTERFACE definitions */
542<Start,ModuleBody,SubprogBody>{
543^{BS}interface{IDSYM}+ { /* variable with interface prefix */ }
544^{BS}interface { yyextra->ifType = IF_SPECIFIC;
545 yy_push_state(InterfaceBody,yyscanner);
546 // do not start a scope here, every
547 // interface body is a scope of its own
548 }
549
550^{BS}abstract{BS_}interface { yyextra->ifType = IF_ABSTRACT;
551 yy_push_state(InterfaceBody,yyscanner);
552 // do not start a scope here, every
553 // interface body is a scope of its own
554 }
555
556^{BS}interface{BS_}{ID}{ARGS}? { yyextra->ifType = IF_GENERIC;
557 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1; // we have to be at the line after the definition and we have to take continuation lines into account.
558 yy_push_state(InterfaceBody,yyscanner);
559
560 // extract generic name
562 name = name.mid(9).stripWhiteSpace().lower();
563 addInterface(yyscanner,name, yyextra->ifType);
564 startScope(yyscanner,yyextra->last_entry.get());
565 }
static void addInterface(yyscan_t yyscanner, DString name, InterfaceType type)
566}
567
568<InterfaceBody>^{BS}end{BS}interface({BS_}{ID})? {
569 // end scope only if GENERIC interface
570 if (yyextra->ifType == IF_GENERIC)
571 {
572 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr - 1;
573 }
574 if (yyextra->ifType == IF_GENERIC && !endScope(yyscanner,yyextra->current_root))
575 {
576 yyterminate();
577 }
578 yyextra->ifType = IF_NONE;
579 pop_state(yyscanner);
580 }
#define yyterminate()
581<InterfaceBody>module{BS}procedure { yy_push_state(YY_START,yyscanner);
582 BEGIN(ModuleProcedure);
583 }
584<ModuleProcedure>{ID} { DString name = DString(yytext).lower();
585 if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
586 {
587 addInterface(yyscanner,name, yyextra->ifType);
588 startScope(yyscanner,yyextra->last_entry.get());
589 }
590
591 yyextra->current->section = EntryType::makeFunction();
592 yyextra->current->name = name;
593 yyextra->moduleProcedures.push_back(yyextra->current);
594 addCurrentEntry(yyscanner,true);
595 }
596<ModuleProcedure>"\n" { yyextra->colNr -= 1;
597 unput(*yytext);
598 pop_state(yyscanner);
599 }
600<InterfaceBody>. {}
601
602 /*-- Contains handling --*/
603<Start>^{BS}{CONTAINS}/({BS}|\n|!|;) {
604 if (YY_START == Start)
605 {
606 addModule(yyscanner);
607 yy_push_state(ModuleBodyContains,yyscanner); //anon program
608 }
609 }
610<ModuleBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(ModuleBodyContains); }
611<SubprogBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(SubprogBodyContains); }
612<TypedefBody>^{BS}{CONTAINS}/({BS}|\n|!|;) { BEGIN(TypedefBodyContains); }
613
614 /*------ module handling ------------------------------------------------------------*/
615<Start>block{BS}data{BS}{ID_} { //
616 yyextra->vtype = V_IGNORE;
617 yy_push_state(BlockData,yyscanner);
618 yyextra->defaultProtection = Protection::Public;
619 }
@ V_IGNORE
620<Start>module|program{BS_} { //
621 yyextra->vtype = V_IGNORE;
622 if (yytext[0]=='m' || yytext[0]=='M')
623 {
624 yy_push_state(Module,yyscanner);
625 }
626 else
627 {
628 yy_push_state(Program,yyscanner);
629 }
630 yyextra->defaultProtection = Protection::Public;
631 }
632<BlockData>^{BS}"end"({BS}(block{BS}data)({BS_}{ID})?)?{BS}/(\n|!|;) { // end block data
633 //if (!endScope(yyscanner,yyextra->current_root))
634 // yyterminate();
635 yyextra->defaultProtection = Protection::Public;
636 pop_state(yyscanner);
637 }
638<Start,ModuleBody,ModuleBodyContains>"end"({BS}(module|program)({BS_}{ID})?)?{BS}/(\n|!|;) { // end module
639 resolveModuleProcedures(yyscanner,yyextra->current_root);
640 if (!endScope(yyscanner,yyextra->current_root))
641 {
642 yyterminate();
643 }
644 yyextra->defaultProtection = Protection::Public;
645 if (yyextra->global_scope)
646 {
647 if (yyextra->global_scope != INVALID_ENTRY)
648 {
649 yy_push_state(Start,yyscanner);
650 }
651 else
652 {
653 pop_state(yyscanner); // cannot pop artrificial entry
654 }
655 }
656 else
657 {
658 yy_push_state(Start,yyscanner);
659 yyextra->global_scope = INVALID_ENTRY; // signal that the yyextra->global_scope has already been used.
660 }
661 popBlockState(yyscanner);
662 }
static void resolveModuleProcedures(yyscan_t yyscanner, Entry *current_root)
fill empty interface module procedures with info from corresponding module subprogs
static void popBlockState(yyscan_t yyscanner)
663<Module>{ID} {
664 addModule(yyscanner, DString(yytext), true);
665 pushBlockState(yyscanner,DString("module ")+yytext);
666 BEGIN(ModuleBody);
667 }
668<Program>{ID} {
669 addModule(yyscanner, DString(yytext), false);
670 pushBlockState(yyscanner,DString("program ")+yytext);
671 BEGIN(ModuleBody);
672 }
673
674 /*------- access specification --------------------------------------------------------------------------*/
675
676<ModuleBody,TypedefBody,TypedefBodyContains>private/{BS}(\n|"!") {
677 yyextra->defaultProtection = Protection::Private;
678 yyextra->current->protection = yyextra->defaultProtection ;
679 }
680<ModuleBody,TypedefBody,TypedefBodyContains>public/{BS}(\n|"!") {
681 yyextra->defaultProtection = Protection::Public;
682 yyextra->current->protection = yyextra->defaultProtection ;
683 }
684
685 /*------- type definition -------------------------------------------------------------------------------*/
686
687<ModuleBody>^{BS}type{BS}"=" {}
688<Start,ModuleBody>^{BS}type/[^a-z0-9_] {
689 if (YY_START == Start)
690 {
691 addModule(yyscanner,DString());
692 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
693 yy_push_state(ModuleBody,yyscanner); //anon program
694 }
695
696 yy_push_state(Typedef,yyscanner);
697 yyextra->current->protection = Protection::Package; // invalid in Fortran, replaced below
698 yyextra->typeProtection = Protection::Public;
699 yyextra->typeMode = true;
700 }
701<Typedef>{
702{COMMA} {}
703
704{BS}"::"{BS} {}
705
706abstract {
707 yyextra->current->spec.setAbstractClass(true);
708 }
709extends{ARGS} {
710 DString basename = extractFromParens(yytext).lower();
711 yyextra->current->extends.emplace_back(basename, Protection::Public, Specifier::Normal);
712 }
713public {
714 yyextra->current->protection = Protection::Public;
715 }
716private {
717 yyextra->current->protection = Protection::Private;
718 }
719{LANGUAGE_BIND_SPEC} {
720 /* ignored for now */
721 }
722{ID} { /* type name found */
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;
729
730 /* if type is part of a module, mod name is necessary for output */
731 if (yyextra->current_root &&
732 (yyextra->current_root->section.isClass() ||
733 yyextra->current_root->section.isNamespace()))
734 {
735 yyextra->current->name = yyextra->current_root->name + "::" + yyextra->current->name;
736 }
737
738 // set modifiers to allow adjusting public/private in surrounding module scope
739 if( yyextra->current->protection == Protection::Package )
740 {
741 yyextra->current->protection = yyextra->defaultProtection;
742 }
743 else if( yyextra->current->protection == Protection::Public )
744 {
745 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()] |= DString("public");
746 }
747 else if( yyextra->current->protection == Protection::Private )
748 {
749 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()] |= DString("private");
750 }
751
752 addCurrentEntry(yyscanner,true);
753 startScope(yyscanner,yyextra->last_entry.get());
754 BEGIN(TypedefBody);
755 }
756}
757
758<TypedefBodyContains>{ /* Type Bound Procedures */
759^{BS}PROCEDURE{ARGS}? {
760 yyextra->current->type = DString(yytext).simplifyWhiteSpace().lower();
761 }
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
Definition dstring.cpp:127
762^{BS}final {
763 yyextra->current->spec.setFinal(true);
764 yyextra->current->type = DString(yytext).simplifyWhiteSpace();
765 }
766^{BS}generic {
767 yyextra->current->type = DString(yytext).simplifyWhiteSpace();
768 }
769{COMMA} {
770 }
771{ATTR_SPEC} {
772 yyextra->currentModifiers |= DString(yytext).stripWhiteSpace();
773 }
774{BS}"::"{BS} {
775 }
776{ID} {
777 DString name = yytext;
778 yyextra->modifiers[yyextra->current_root][name.lower().str()] |= yyextra->currentModifiers;
779 yyextra->current->section = EntryType::makeFunction();
780 yyextra->current->name = name;
781 // check for procedure(name)
782 if (yyextra->current->type.find('(')!=DString::npos)
783 {
784 yyextra->current->args = extractFromParens(yyextra->current->type).stripWhiteSpace();
785 }
786 else
787 {
788 yyextra->current->args = name.lower(); // target procedure name if no => is given
789 }
790 yyextra->current->fileName = yyextra->fileName;
791 yyextra->current->bodyLine = yyextra->lineNr;
792 yyextra->current->startLine = yyextra->lineNr;
793 addCurrentEntry(yyscanner,true);
794 }
795{BS}"=>"[^(\n|\!)]* { /* Specific bindings come after the ID. */
796 DString tmp = yytext;
797 size_t i = tmp.find("=>");
798 if (i!=DString::npos)
799 {
800 tmp.remove(0, i+2);
801 }
802 tmp = tmp.simplifyWhiteSpace().lower();
803 if (yyextra->last_entry->type == "generic")
804 {
805 // duplicate entries for each overloaded variant
806 // (parse through medhod1,method2, methodN, ...
807 //printf("Parsing through %s for generic method %s.\n", tmp.data(), last_entry->name.data());
808 i = tmp.find(',');
809 while (i!=DString::npos && i>0)
810 {
811 copyEntry(yyextra->current, yyextra->last_entry);
812 yyextra->current->name = yyextra->last_entry->name;
813 yyextra->current->section = EntryType::makeFunction();
814 yyextra->last_entry->args = tmp.left(i).stripWhiteSpace();
815 //printf("Found %s.\n", last_entry->args.data());
816 addCurrentEntry(yyscanner,true);
817 tmp = tmp.remove(0,i+1).stripWhiteSpace();
818 i = tmp.find(',');
819 }
820 }
821 //printf("Target function: %s\n", tmp.data());
822 yyextra->last_entry->args = tmp;
823 }
DString left(size_t len) const
Definition dstring.h:306
824"\n" {
825 yyextra->currentModifiers = SymbolModifiers();
826 newLine(yyscanner);
827 yyextra->docBlock.clear();
828 }
static void newLine(yyscan_t yyscanner)
Holds yyextra->modifiers (ie attributes) for one symbol (variable, function, etc).
829}
830
831
832<TypedefBody,TypedefBodyContains>{
833^{BS}"end"{BS}"type"({BS_}{ID})?{BS}/(\n|!|;) { /* end type definition */
834 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr;
835 if (!endScope(yyscanner,yyextra->current_root))
836 {
837 yyterminate();
838 }
839 yyextra->typeMode = false;
840 pop_state(yyscanner);
841 }
842^{BS}"end"{BS}/(\n|!|;) { /* incorrect end type definition */
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))
846 {
847 yyterminate();
848 }
849 yyextra->typeMode = false;
850 pop_state(yyscanner);
851 }
852}
853
854 /*------- module/global/typedef variable ---------------------------------------------------*/
855
856<SubprogBody,SubprogBodyContains>^{BS}[0-9]*{BS}"end"({BS}{SUBPROG}({BS_}{ID})?)?{BS}/(\n|!|;) {
857 //
858 // ABSTRACT and specific interfaces are stored
859 // in a scope of their own, even if multiple
860 // are group in one INTERFACE/END INTERFACE block.
861 //
862 if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
863 {
864 endScope(yyscanner,yyextra->current_root);
865 yyextra->last_entry->endBodyLine = yyextra->lineNr - 1;
866 }
867 yyextra->current_root->endBodyLine = yyextra->lineNr - 1;
868
869 if (!endScope(yyscanner,yyextra->current_root))
870 {
871 yyterminate();
872 }
873 yyextra->subrCurrent.pop_back();
874 yyextra->vtype = V_IGNORE;
875 popBlockState(yyscanner);
876 pop_state(yyscanner) ;
877 }
878<BlockData>{
879{ID} {
880 }
881}
882<Start,ModuleBody,TypedefBody,SubprogBody,FEnum>{
883^{BS}{TYPE_SPEC}/{SEPARATE} {
884 yyextra->last_enum.reset();
885 if (YY_START == FEnum)
886 {
887 yyextra->argType = "@"; // enum marker
888 }
889 else
890 {
891 yyextra->argType = DString(yytext).simplifyWhiteSpace().lower();
892 }
893 yyextra->current->bodyLine = yyextra->lineNr + 1;
894 yyextra->current->endBodyLine = yyextra->lineNr + yyextra->lineCountPrepass;
895 /* variable declaration starts */
896 if (YY_START == Start)
897 {
898 addModule(yyscanner);
899 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
900 yy_push_state(ModuleBody,yyscanner); //anon program
901 }
902 yy_push_state(AttributeList,yyscanner);
903 }
904{EXTERNAL_STMT}/({BS}"::"|{BS_}{ID}) {
905 /* external can be a "type" or an attribute */
906 if (YY_START == Start)
907 {
908 addModule(yyscanner);
909 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
910 yy_push_state(ModuleBody,yyscanner); //anon program
911 }
912 DString tmp = yytext;
913 yyextra->currentModifiers |= tmp.stripWhiteSpace();
914 yyextra->argType = DString(yytext).simplifyWhiteSpace().lower();
915 yy_push_state(AttributeList,yyscanner);
916 }
917{ATTR_STMT}/{BS_}{ID} |
918{ATTR_STMT}/{BS}"::" {
919 /* attribute statement starts */
920 DBG_CTX((stderr,"5=========> Attribute statement: %s\n", yytext));
921 if (YY_START == Start)
922 {
923 addModule(yyscanner);
924 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
925 yy_push_state(ModuleBody,yyscanner); //anon program
926 }
927 DString tmp = yytext;
928 yyextra->currentModifiers |= tmp.stripWhiteSpace();
929 yyextra->argType="";
930 yy_push_state(YY_START,yyscanner);
931 BEGIN( AttributeList ) ;
932 }
933"common" {
934 if (YY_START == Start)
935 {
936 addModule(yyscanner);
937 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
938 yy_push_state(ModuleBody,yyscanner); //anon program
939 }
940 }
941{ID} {
942 if (YY_START == Start && DString(yytext).stripWhiteSpace().lower()!="include")
943 {
944 addModule(yyscanner);
945 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
946 yy_push_state(ModuleBody,yyscanner); //anon program
947 }
948 }
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...
Definition stringutil.h:75
949^{BS}"type"{BS_}"is"/{BT_} {}
950^{BS}"type"{BS}"=" {}
951^{BS}"class"{BS_}"is"/{BT_} {}
952^{BS}"class"{BS_}"default" {}
953}
954<AttributeList>{
955{COMMA} {}
956{BS} {}
957{LANGUAGE_BIND_SPEC} {
958 yyextra->currentModifiers |= yytext;
959 }
960{ATTR_SPEC}. { /* update yyextra->current yyextra->modifiers when it is an ATTR_SPEC and not a variable name */
961 /* buyyextra->625519 */
962 char chr = yytext[(int)yyleng-1];
963 if (isId(chr))
964 {
965 yyextra->colNr -= (int)yyleng;
966 REJECT;
967 }
968 else
969 {
970 DString tmp = yytext;
971 tmp = tmp.left(tmp.length() - 1);
972 yyextra->colNr -= 1;
973 unput(yytext[(int)yyleng-1]);
974 yyextra->currentModifiers |= (tmp);
975 }
976 }
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
977"::" { /* end attribute list */
978 BEGIN( FVariable );
979 }
980. { /* unknown attribute, consider variable name */
981 //cout<<"start variables, unput "<<*yytext<<endl;
982 yyextra->colNr -= 1;
983 unput(*yytext);
984 BEGIN( FVariable );
985 }
986}
987
988<FVariable>{BS} {}
989<FVariable>{OPERATOR_ID} { /* parse operator access statements "public :: operator(==)" */
991 /* if variable/type/etc is part of a module, mod name is necessary for output */
992 // get surrounding state
993 int currentState = YY_START;
994 pop_state(yyscanner);
995 int outerState = YY_START;
996 yy_push_state(currentState,yyscanner);
997 if( outerState == Start || outerState == ModuleBody )
998 {
999 if ((yyextra->current_root) &&
1000 (yyextra->current_root->section.isClass() ||
1001 yyextra->current_root->section.isNamespace()))
1002 {
1003 name = yyextra->current_root->name + "::" + name;
1004 }
1005 }
1006 /* remember attributes for the symbol */
1007 yyextra->modifiers[yyextra->current_root][name.str()] |= yyextra->currentModifiers;
1008 }
1009<FVariable>{ID} { /* parse variable declaration */
1010 //cout << "5=========> got variable: " << yyextra->argType << "::" << yytext << endl;
1011 /* work around for bug in DString.replace (DString works) */
1012 DString name=yytext;
1013 name = name.lower();
1014 /* if variable/type/etc is part of a module, mod name is necessary for output */
1015 if ((yyextra->current_root) && yyextra->current_root->section.isNamespace())
1016 {
1017 name = yyextra->current_root->name + "::" + name;
1018 }
1019 /* remember attributes for the symbol */
1020 yyextra->modifiers[yyextra->current_root][name.lower().str()] |= yyextra->currentModifiers;
1021 yyextra->argName= name;
1022
1023 yyextra->vtype= V_IGNORE;
1024 if (!yyextra->argType.empty() && !yyextra->current_root->section.isFunction())
1025 { // new variable entry
1026 yyextra->vtype = V_VARIABLE;
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; // used for source reference
1032 yyextra->current->startLine = yyextra->lineNr;
1033 if (yyextra->argType == "@")
1034 {
1035 yyextra->current_root->copyToSubEntry(yyextra->current);
1036 // add to the scope surrounding the enum (copy!)
1037 yyextra->last_enum = yyextra->current;
1038 yyextra->current_root->parent()->moveToSubEntryAndRefresh(yyextra->current);
1039 initEntry(yyscanner);
1040 }
1041 else
1042 {
1043 addCurrentEntry(yyscanner,true);
1044 }
1045 }
1046 else if (!yyextra->argType.empty())
1047 { // declaration of parameter list: add type for corr. parameter
1048 Argument *parameter = getParameter(yyscanner,yyextra->argName);
1049 if (parameter)
1050 {
1051 yyextra->vtype= V_PARAMETER;
1052 if (!yyextra->argType.empty()) parameter->type=yyextra->argType.stripWhiteSpace();
1053 if (!yyextra->docBlock.empty())
1054 {
1055 subrHandleCommentBlock(yyscanner,yyextra->docBlock,true);
1056 }
1057 }
1058 // save, it may be function return type
1059 if (parameter)
1060 {
1061 yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->argType;
1062 }
1063 else
1064 {
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()))
1067 {
1068 size_t strt = yyextra->current_root->type.find("function");
1069 DString lft;
1070 DString rght;
1071 if (strt != DString::npos)
1072 {
1073 yyextra->vtype = V_RESULT;
1074 lft = "";
1075 rght = "";
1076 if (strt != 0) lft = yyextra->current_root->type.left(strt).stripWhiteSpace();
1077 if ((yyextra->current_root->type.length() - strt - strlen("function"))!= 0)
1078 {
1079 rght = yyextra->current_root->type.right(yyextra->current_root->type.length() - strt - (int)strlen("function")).stripWhiteSpace();
1080 }
1081 yyextra->current_root->type = lft;
1082 if (rght.length() > 0)
1083 {
1084 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type += " ";
1085 yyextra->current_root->type += rght;
1086 }
1087 if (yyextra->argType.stripWhiteSpace().length() > 0)
1088 {
1089 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type += " ";
1090 yyextra->current_root->type += yyextra->argType.stripWhiteSpace();
1091 }
1092 if (yyextra->current_root->type.length() > 0) yyextra->current_root->type += " ";
1093 yyextra->current_root->type += "function";
1094 if (!yyextra->docBlock.empty())
1095 {
1096 subrHandleCommentBlockResult(yyscanner,yyextra->docBlock,true);
1097 }
1098 }
1099 else
1100 {
1101 yyextra->current_root->type += " " + yyextra->argType.stripWhiteSpace();
1102 }
1103 yyextra->current_root->type = yyextra->current_root->type.stripWhiteSpace();
1104 yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->current_root->type;
1105 }
1106 else
1107 {
1108 yyextra->modifiers[yyextra->current_root][name.lower().str()].type = yyextra->argType;
1109 }
1110 }
1111 // any accumulated doc for argument should be emptied,
1112 // because it is handled other way and this doc can be
1113 // unexpectedly passed to the next member.
1114 yyextra->current->doc.clear();
1115 yyextra->current->brief.clear();
1116 }
1117 }
DString right(size_t len) const
Definition dstring.h:311
@ V_RESULT
static void subrHandleCommentBlockResult(yyscan_t yyscanner, const DString &doc, bool brief)
Handle result description as defined after the declaration of the parameter.
static void subrHandleCommentBlock(yyscan_t yyscanner, const DString &doc, bool brief)
Handle parameter description as defined after the declaration of the parameter.
1118<FVariable>{ARGS} { /* dimension of the previous entry. */
1119 DString name(yyextra->argName);
1120 DString attr("dimension");
1121 attr += yytext;
1122 yyextra->modifiers[yyextra->current_root][name.lower().str()] |= attr;
1123 }
1124<FVariable>{COMMA} { //printf("COMMA: %d<=..<=%d\n", yyextra->colNr-(int)yyleng, yyextra->colNr);
1125 // locate !< comment
1126 updateVariablePrepassComment(yyscanner,yyextra->colNr-(int)yyleng, yyextra->colNr);
1127 }
static void updateVariablePrepassComment(yyscan_t yyscanner, int from, int to)
1128<FVariable>{BS}"=" {
1129 yy_push_state(YY_START,yyscanner);
1130 yyextra->initializer="=";
1131 yyextra->initializerScope = yyextra->initializerArrayScope = 0;
1132 BEGIN(Initialization);
1133 }
1134<FVariable>"\n" { yyextra->currentModifiers = SymbolModifiers();
1135 pop_state(yyscanner); // end variable declaration list
1136 newLine(yyscanner);
1137 yyextra->docBlock.clear();
1138 }
1139<FVariable>";".*"\n" { yyextra->currentModifiers = SymbolModifiers();
1140 pop_state(yyscanner); // end variable declaration list
1141 yyextra->docBlock.clear();
1142 yyextra->inputStringSemi = " \n"+DString(yytext+1);
1143 yyextra->lineNr--;
1144 pushBuffer(yyscanner,yyextra->inputStringSemi);
1145 }
1146<*>";".*"\n" {
1147 if (YY_START == FVariable) REJECT; // Just be on the safe side
1148 if (YY_START == String) REJECT; // ";" ignored in strings
1149 if (YY_START == StrIgnore) REJECT; // ";" ignored in regular yyextra->comments
1150 if (YY_START == DocBlock) REJECT; // ";" ignored in documentation blocks
1151 yyextra->inputStringSemi = " \n"+DString(yytext+1);
1152 yyextra->lineNr--;
1153 pushBuffer(yyscanner,yyextra->inputStringSemi);
1154 }
1155
1156<Initialization,ArrayInitializer>"[" |
1157<Initialization,ArrayInitializer>"(/" { yyextra->initializer+=yytext;
1158 yyextra->initializerArrayScope++;
1159 BEGIN(ArrayInitializer); // initializer may contain comma
1160 }
1161<ArrayInitializer>"]" |
1162<ArrayInitializer>"/)" { yyextra->initializer+=yytext;
1163 yyextra->initializerArrayScope--;
1164 if (yyextra->initializerArrayScope<=0)
1165 {
1166 yyextra->initializerArrayScope = 0; // just in case
1167 BEGIN(Initialization);
1168 }
1169 }
1170<ArrayInitializer>. { yyextra->initializer+=yytext; }
1171<Initialization>"(" { yyextra->initializerScope++;
1172 yyextra->initializer+=yytext;
1173 }
1174<Initialization>")" { yyextra->initializerScope--;
1175 yyextra->initializer+=yytext;
1176 }
1177<Initialization>{COMMA} { if (yyextra->initializerScope == 0)
1178 {
1179 updateVariablePrepassComment(yyscanner,yyextra->colNr-(int)yyleng, yyextra->colNr);
1180 pop_state(yyscanner); // end initialization
1181 if (yyextra->last_enum)
1182 {
1183 yyextra->last_enum->initializer.str(yyextra->initializer.str());
1184 }
1185 else
1186 {
1187 if (yyextra->vtype == V_VARIABLE) yyextra->last_entry->initializer.str(yyextra->initializer.str());
1188 }
1189 }
1190 else
1191 {
1192 yyextra->initializer+=", ";
1193 }
1194 }
1195<Initialization>"\n"|"!" { //|
1196 pop_state(yyscanner); // end initialization
1197 if (yyextra->last_enum)
1198 {
1199 yyextra->last_enum->initializer.str(yyextra->initializer.str());
1200 }
1201 else
1202 {
1203 if (yyextra->vtype == V_VARIABLE) yyextra->last_entry->initializer.str(yyextra->initializer.str());
1204 }
1205 yyextra->colNr -= 1;
1206 unput(*yytext);
1207 }
1208<Initialization>. { yyextra->initializer+=yytext; }
1209
1210<*>{BS}"enum"{BS}","{BS}"bind"{BS}"("{BS}"c"{BS}")"{BS} {
1211 if (YY_START == Start)
1212 {
1213 addModule(yyscanner);
1214 pushBlockState(yyscanner,DString(yytext)+" (anonymous program)");
1215 yy_push_state(ModuleBody,yyscanner); //anon program
1216 }
1217
1218 yy_push_state(FEnum,yyscanner);
1219 yyextra->current->protection = yyextra->defaultProtection;
1220 yyextra->typeProtection = yyextra->defaultProtection;
1221 yyextra->typeMode = true;
1222
1223 yyextra->current->spec.setStruct(true);
1224 yyextra->current->name.clear();
1225 yyextra->current->args.clear();
1226 yyextra->current->name.sprintf("@%d",yyextra->anonCount++);
1227
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()))
1235 {
1236 yyextra->current->name = yyextra->current_root->name + "::" + yyextra->current->name;
1237 }
1238
1239 addCurrentEntry(yyscanner,true);
1240 startScope(yyscanner,yyextra->last_entry.get());
1241 BEGIN( FEnum ) ;
1242 }
1243<FEnum>"end"{BS}"enum" {
1244 yyextra->last_entry->parent()->endBodyLine = yyextra->lineNr;
1245 if (!endScope(yyscanner,yyextra->current_root))
1246 {
1247 yyterminate();
1248 }
1249 yyextra->typeMode = false;
1250 pop_state(yyscanner);
1251 }
1252 /*------ fortran subroutine/function handling ------------------------------------------------------------*/
1253 /* Start is initial condition */
1254
1255<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{TYPE_SPEC}{BS}({PREFIX}{BS_})?/{SUBPROG}{BS_} {
1256 if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
1257 {
1258 addInterface(yyscanner,"$interface$", yyextra->ifType);
1259 startScope(yyscanner,yyextra->last_entry.get());
1260 }
1261
1262 // TYPE_SPEC is for old function style function result
1263 yyextra->current->type = DString(yytext).stripWhiteSpace().lower();
1264 yy_push_state(SubprogPrefix,yyscanner);
1265 }
1266
1267<SubprogPrefix>{BS}{SUBPROG}{BS_} {
1268 // Fortran subroutine or function found
1269 yyextra->vtype = V_IGNORE;
1270 DString result=yytext;
1271 result=result.stripWhiteSpace();
1272 addSubprogram(yyscanner,result);
1273 BEGIN(Subprog);
1274 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1; // we have to be at the line after the definition and we have to take continuation lines into account.
1275 yyextra->current->startLine = yyextra->lineNr;
1276 }
static void addSubprogram(yyscan_t yyscanner, const DString &text)
1277
1278<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{SUBPROG}{BS_} {
1279 // Fortran subroutine or function found
1280 yyextra->vtype = V_IGNORE;
1281 if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
1282 {
1283 addInterface(yyscanner,"$interface$", yyextra->ifType);
1284 startScope(yyscanner,yyextra->last_entry.get());
1285 }
1286
1287 DString result = DString(yytext).stripWhiteSpace();
1288 addSubprogram(yyscanner,result);
1289 yy_push_state(Subprog,yyscanner);
1290 yyextra->current->bodyLine = yyextra->lineNr + yyextra->lineCountPrepass + 1; // we have to be at the line after the definition and we have to take continuation lines into account.
1291 yyextra->current->startLine = yyextra->lineNr;
1292 }
1293
1294<Subprog>{BS} { /* ignore white space */ }
1295<Subprog>{ID} { yyextra->current->name = yytext;
1296 //cout << "1a==========> got " << yyextra->current->type << " " << yytext << " " << yyextra->lineNr << endl;
1297 DString returnName = yyextra->current->name.lower();
1298 /* if type is part of a module, mod name is necessary for output */
1299 if ((yyextra->current_root) &&
1300 (yyextra->current_root->section.isClass() ||
1301 yyextra->current_root->section.isNamespace()))
1302 {
1303 yyextra->current->name= yyextra->current_root->name + "::" + yyextra->current->name;
1304 }
1305 yyextra->modifiers[yyextra->current_root][yyextra->current->name.lower().str()].returnName = std::move(returnName);
1306
1307 if (yyextra->ifType == IF_ABSTRACT || yyextra->ifType == IF_SPECIFIC)
1308 {
1309 yyextra->current_root->name = substitute(
1310 yyextra->current_root->name, "$interface$", DString(yytext).lower());
1311 }
1312
1313 BEGIN(Parameterlist);
1314 }
1315<Parameterlist>"(" { yyextra->current->args = "("; }
1316<Parameterlist>")" {
1317 yyextra->current->args += ")";
1318 yyextra->current->args = removeRedundantWhiteSpace(yyextra->current->args);
1319 addCurrentEntry(yyscanner,true);
1320 startScope(yyscanner,yyextra->last_entry.get());
1321 BEGIN(SubprogBody);
1322 }
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
1323<Parameterlist>{COMMA}|{BS} { yyextra->current->args += yytext;
1324 const CommentInPrepass *c = locatePrepassComment(yyscanner,yyextra->colNr-(int)yyleng, yyextra->colNr);
1325 if (c)
1326 {
1327 if (!yyextra->current->argList.empty())
1328 {
1329 yyextra->current->argList.back().docs = c->str;
1330 }
1331 }
1332 }
1333<Parameterlist>{ID} {
1334 //yyextra->current->type not yet available
1335 DString param = DString(yytext).lower();
1336 // std::cout << "3=========> got parameter " << param << "\n";
1337 yyextra->current->args += param;
1338 Argument arg;
1339 arg.name = param;
1340 arg.type = "";
1341 yyextra->current->argList.push_back(arg);
1342 }
void push_back(char c)
Definition dstring.h:202
1343<Parameterlist>{NOARGS} {
1344 newLine(yyscanner);
1345 //printf("3=========> without parameterlist \n");
1346 addCurrentEntry(yyscanner,true);
1347 startScope(yyscanner,yyextra->last_entry.get());
1348 BEGIN(SubprogBody);
1349 }
1350<SubprogBody>result{BS}\‍({BS}{ID} {
1351 if (yyextra->functionLine)
1352 {
1353 DString result= yytext;
1354 result= result.mid(result.find('(')+1);
1355 result= result.stripWhiteSpace();
1356 yyextra->modifiers[yyextra->current_root->parent()][yyextra->current_root->name.lower().str()].returnName = result;
1357 }
1358 //cout << "=====> got result " << result << endl;
1359 }
1360
1361 /*---- documentation yyextra->comments --------------------------------------------------------------------*/
1362
1363<FVariable,SubprogBody,ModuleBody,TypedefBody,TypedefBodyContains>"!<" { /* backward docu comment */
1364 if (yyextra->vtype != V_IGNORE)
1365 {
1366 yyextra->current->docLine = yyextra->lineNr;
1367 yyextra->docBlockJavaStyle = false;
1368 yyextra->docBlock.clear();
1369 yyextra->docBlockJavaStyle = Config_getBool(JAVADOC_AUTOBRIEF);
1370 startCommentBlock(yyscanner,false);
1371 yy_push_state(DocBackLine,yyscanner);
1372 }
1373 else
1374 {
1375 /* handle out of place !< comment as a normal comment */
1376 if (YY_START == String)
1377 {
1378 yyextra->colNr -= (int)yyleng;
1379 REJECT;
1380 } // "!" is ignored in strings
1381 // skip comment line (without docu yyextra->comments "!>" "!<" )
1382 /* ignore further "!" and ignore yyextra->comments in Strings */
1383 if ((YY_START != StrIgnore) && (YY_START != String))
1384 {
1385 yy_push_state(YY_START,yyscanner);
1386 BEGIN(StrIgnore);
1387 yyextra->debugStr="*!";
1388 }
1389 }
1390 }
static void startCommentBlock(yyscan_t yyscanner, bool)
1391<DocBackLine>.* { // contents of yyextra->current comment line
1392 yyextra->docBlock+=yytext;
1393 }
1394<DocBackLine>"\n"{BS}"!"("<"|"!"+) { // comment block (next line is also comment line)
1395 yyextra->docBlock+="\n"; // \n is necessary for lists
1396 newLine(yyscanner);
1397 }
1398<DocBackLine>"\n" { // comment block ends at the end of this line
1399 //cout <<"3=========> comment block : "<< yyextra->docBlock << endl;
1400 yyextra->colNr -= 1;
1401 unput(*yytext);
1402 if (yyextra->vtype == V_VARIABLE)
1403 {
1404 std::shared_ptr<Entry> tmp_entry = yyextra->current;
1405 // temporarily switch to the previous entry
1406 if (yyextra->last_enum)
1407 {
1408 yyextra->current = yyextra->last_enum;
1409 }
1410 else
1411 {
1412 yyextra->current = yyextra->last_entry;
1413 }
1414 handleCommentBlock(yyscanner,stripIndentation(yyextra->docBlock),true);
1415 // switch back
1416 yyextra->current = std::move(tmp_entry);
1417 }
1418 else if (yyextra->vtype == V_PARAMETER)
1419 {
1420 subrHandleCommentBlock(yyscanner,yyextra->docBlock,true);
1421 }
1422 else if (yyextra->vtype == V_RESULT)
1423 {
1424 subrHandleCommentBlockResult(yyscanner,yyextra->docBlock,true);
1425 }
1426 pop_state(yyscanner);
1427 yyextra->docBlock.clear();
1428 }
1429
1430<Start,SubprogBody,ModuleBody,TypedefBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains,TypedefBodyContains,FEnum>^{BS} {
1431 yyextra->curIndent = computeIndent(yytext);
1432 }
static int computeIndent(const char *s)
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();
1439 yyextra->docBlockJavaStyle = Config_getBool(JAVADOC_AUTOBRIEF);
1440 startCommentBlock(yyscanner,false);
1441 BEGIN(DocBlock);
1442 //cout << "start DocBlock " << endl;
1443 }
1444
1445
1446<DocBlock>({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command
1447 yyextra->docBlock += yytext;
1448 }
1449<DocBlock>{CMD}("f$"|"f["|"f{"|"f(") {
1450 yyextra->docBlock += yytext;
1451 yyextra->docBlockName=&yytext[1];
1452 if (yyextra->docBlockName.at(1)=='[')
1453 {
1454 yyextra->docBlockName.at(1)=']';
1455 }
1456 if (yyextra->docBlockName.at(1)=='{')
1457 {
1458 yyextra->docBlockName.at(1)='}';
1459 }
1460 if (yyextra->docBlockName.at(1)=='(')
1461 {
1462 yyextra->docBlockName.at(1)=')';
1463 }
1464 yyextra->fencedSize=0;
1465 pushBlockState(yyscanner,yytext);
1466 BEGIN(DocCopyBlock);
1467 }
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;
1473 }
1474<DocBlock>{CMD}"ifile"{B}+{FILEMASK} {
1475 yyextra->fileName = &yytext[6];
1476 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1477 yyextra->docBlock += yytext;
1478 }
1479<DocBlock>{CMD}"iline"{LINENR}/[\n\.] |
1480<DocBlock>{CMD}"iline"{LINENR}{B} {
1481 bool ok = false;
1482 int nr = DString(&yytext[6]).toInt(&ok);
1483 if (!ok)
1484 {
1485 warn(yyextra->fileName,yyextra->lineNr,"Invalid line number '{}' for iline command",yytext);
1486 }
1487 else
1488 {
1489 yyextra->lineNr = nr;
1490 }
1491 yyextra->docBlock += yytext;
1492 }
int toInt(bool *ok=nullptr, int base=10) const
Definition dstring.cpp:191
1493<DocBlock>{B}*"<"{PRE}">" {
1494 yyextra->docBlock += yytext;
1495 yyextra->docBlockName="<pre>";
1496 yyextra->fencedSize=0;
1497 pushBlockState(yyscanner,yytext);
1498 BEGIN(DocCopyBlock);
1499 }
1500<DocBlock>{B}*"<"<CODE>">" {
1501 yyextra->docBlock += yytext;
1502 yyextra->docBlockName="<code>";
1503 yyextra->fencedSize=0;
1504 pushBlockState(yyscanner,yytext);
1505 BEGIN(DocCopyBlock);
1506 }
1507<DocBlock>{CMD}"startuml"/[^a-z_A-Z0-9\-] { // verbatim command
1508 yyextra->docBlock += yytext;
1509 yyextra->docBlockName="uml";
1510 yyextra->fencedSize=0;
1511 pushBlockState(yyscanner,yytext);
1512 BEGIN(DocCopyBlock);
1513 }
1514<DocBlock>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"manonly"|"rtfonly"|"docbookonly"|"dot"|"msc"|"mermaid"|"code")/[^a-z_A-Z0-9\-] { // verbatim command
1515 yyextra->docBlock += yytext;
1516 yyextra->docBlockName=&yytext[1];
1517 yyextra->fencedSize=0;
1518 pushBlockState(yyscanner,yytext);
1519 BEGIN(DocCopyBlock);
1520 }
1521<DocBlock>"~~~"[~]* {
1522 DString pat = yytext;
1523 yyextra->docBlock += pat;
1524 yyextra->docBlockName="~~~";
1525 yyextra->fencedSize=pat.length();
1526 pushBlockState(yyscanner,yytext);
1527 BEGIN(DocCopyBlock);
1528 }
1529<DocBlock>"```"[`]*/(".")?[a-zA-Z0-9#_-]+ |
1530<DocBlock>"```"[`]*/"{"[^}]+"}" |
1531<DocBlock>"```"[`]* {
1532 DString pat = yytext;
1533 yyextra->docBlock += pat;
1534 yyextra->docBlockName="```";
1535 yyextra->fencedSize=pat.length();
1536 pushBlockState(yyscanner,yytext);
1537 BEGIN(DocCopyBlock);
1538 }
1539<DocBlock>"\\ilinebr "{BS} {
1540 DString indent;
1541 int extraSpaces = std::max(0,static_cast<int>(yyleng-9-yyextra->curIndent-2));
1542 indent.fill(' ',extraSpaces);
1543 //printf("extraSpaces=%d\n",extraSpaces);
1544 yyextra->docBlock += "\\ilinebr ";
1545 yyextra->docBlock += indent;
1546 }
DString fill(char c, size_t len)
Fills a string with a predefined character.
Definition dstring.h:278
1547
1548<DocBlock>[^@*`~\/\\\n]+ { // any character that isn't special
1549 yyextra->docBlock += yytext;
1550 }
1551<DocBlock>"\n"{BS}"!"(">"|"!"+) { // comment block (next line is also comment line)
1552 yyextra->docBlock+="\n"; // \n is necessary for lists
1553 newLine(yyscanner);
1554 }
1555<DocBlock>"\n" { // comment block ends at the end of this line
1556 //cout <<"3=========> comment block : "<< yyextra->docBlock << endl;
1557 yyextra->colNr -= 1;
1558 unput(*yytext);
1559 handleCommentBlock(yyscanner,stripIndentation(yyextra->docBlock),true);
1560 pop_state(yyscanner);
1561 }
1562<DocBlock>. { // command block
1563 yyextra->docBlock += *yytext;
1564 }
1565
1566 /* ---- Copy verbatim sections ------ */
1567
1568<DocCopyBlock>"</"{PRE}">" { // end of a <pre> block
1569 yyextra->docBlock += yytext;
1570 if (yyextra->docBlockName=="<pre>")
1571 {
1572 yyextra->docBlockName="";
1573 popBlockState(yyscanner);
1574 BEGIN(DocBlock);
1575 }
1576 }
1577<DocCopyBlock>"</"{CODE}">" { // end of a <code> block
1578 yyextra->docBlock += yytext;
1579 if (yyextra->docBlockName=="<code>")
1580 {
1581 yyextra->docBlockName="";
1582 popBlockState(yyscanner);
1583 BEGIN(DocBlock);
1584 }
1585 }
1586<DocCopyBlock>{CMD}("f$"|"f]"|"f}"|"f)") {
1587 yyextra->docBlock += yytext;
1588 if (yyextra->docBlockName==&yytext[1])
1589 {
1590 yyextra->docBlockName="";
1591 popBlockState(yyscanner);
1592 BEGIN(DocBlock);
1593 }
1594 }
1595<DocCopyBlock>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endmanonly"|"endrtfonly"|"enddot"|"endmsc"|"endmermaid"|"enduml"|"endcode")/[^a-z_A-Z0-9] { // end of verbatim block
1596 yyextra->docBlock += yytext;
1597 if (&yytext[4]==yyextra->docBlockName)
1598 {
1599 yyextra->docBlockName="";
1600 popBlockState(yyscanner);
1601 BEGIN(DocBlock);
1602 }
1603 }
1604
1605<DocCopyBlock>^{B}*{COMM} { // start of a comment line, just ignore the comment indicator and leading whitespace
1606 }
1607<DocCopyBlock>"~~~"[~]* {
1608 DString pat = yytext;
1609 yyextra->docBlock += pat;
1610 if (yyextra->docBlockName == "~~~" && yyextra->fencedSize==pat.length())
1611 {
1612 popBlockState(yyscanner);
1613 BEGIN(DocBlock);
1614 }
1615 }
1616<DocCopyBlock>"```"[`]* {
1617 DString pat = yytext;
1618 yyextra->docBlock += pat;
1619 if (yyextra->docBlockName == "```" && yyextra->fencedSize==pat.length())
1620 {
1621 popBlockState(yyscanner);
1622 BEGIN(DocBlock);
1623 }
1624 }
1625
1626<DocCopyBlock>[^<@/\*\‍]!`~"\$\\\n]+ { // any character that is not special
1627 yyextra->docBlock += yytext;
1628 }
1629<DocCopyBlock>\n { // newline
1630 yyextra->docBlock += *yytext;
1631 newLine(yyscanner);
1632 }
1633<DocCopyBlock>. { // any other character
1634 yyextra->docBlock += *yytext;
1635 }
1636
1637 /*-----Prototype parsing -------------------------------------------------------------------------*/
1638<Prototype>{BS}{SUBPROG}{BS_} {
1639 BEGIN(PrototypeSubprog);
1640 }
1641<Prototype,PrototypeSubprog>{BS}{SCOPENAME}?{BS}{ID} {
1642 yyextra->current->name = DString(yytext).lower();
1643 yyextra->current->name.stripWhiteSpace();
1644 BEGIN(PrototypeArgs);
1645 }
1646<PrototypeArgs>{
1647"("|")"|","|{BS_} { yyextra->current->args += yytext; }
1648{ID} { yyextra->current->args += yytext;
1649 Argument a;
1650 a.name = DString(yytext).lower();
1651 yyextra->current->argList.push_back(a);
1652 }
1653}
1654
1655 /*------------------------------------------------------------------------------------------------*/
1656
1657<*>"\n" {
1658 newLine(yyscanner);
1659 //if (yyextra->debugStr.stripWhiteSpace().length() > 0) cout << "ignored text: " << yyextra->debugStr << " state: " <<YY_START << endl;
1660 yyextra->debugStr="";
1661 }
1662
1663
1664 /*---- error: EOF in wrong state --------------------------------------------------------------------*/
1665
1666<*><<EOF>> {
1667 if (yyextra->parsingPrototype)
1668 {
1669 yyterminate();
1670 }
1671 else if ( yyextra->includeStackPtr <= 0 )
1672 {
1673 if (YY_START!=INITIAL && YY_START!=Start)
1674 {
1675 DBG_CTX((stderr,"==== Error: EOF reached in wrong state (end missing)"));
1676 scanner_abort(yyscanner);
1677 }
1678 yyterminate();
1679 }
1680 else
1681 {
1682 popBuffer(yyscanner);
1683 }
1684 }
static void popBuffer(yyscan_t yyscanner)
1685<*>{LOG_OPER} { // Fortran logical comparison keywords
1686 }
1687<*>. {
1688 //yyextra->debugStr+=yytext;
1689 //printf("I:%c\n", *yytext);
1690 } // ignore remaining text
1691
1692 /**********************************************************************************/
1693 /**********************************************************************************/
1694 /**********************************************************************************/
1695%%

◆ yyread()

int yyread ( yyscan_t yyscanner,
char * buf,
int max_size )
static

Definition at line 2927 of file fortranscanner.l.

2928{
2929 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2930 int c=0;
2931 while ( c < max_size && yyextra->inputString[yyextra->inputPosition] )
2932 {
2933 *buf = yyextra->inputString[yyextra->inputPosition++] ;
2934 c++; buf++;
2935 }
2936 return c;
2937}

References yyguts_t.

Variable Documentation

◆ directionParam

const char* directionParam[]
static
Initial value:
=
{
"", "[in]", "[out]", "[in,out]"
}

Definition at line 143 of file fortranscanner.l.

Referenced by subrHandleCommentBlock().

◆ directionStrs

const char* directionStrs[]
static
Initial value:
=
{
"", "intent(in)", "intent(out)", "intent(inout)"
}

Definition at line 139 of file fortranscanner.l.

Referenced by applyModifiers().