/
fortranscanner.l
2561 lines (2323 loc) · 90.4 KB
/
fortranscanner.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: fundamental; indent-tabs-mode: 1; -*- */
/*****************************************************************************
* Parser for Fortran90 F subset
*
* Copyright (C) by Anke Visser
* based on the work of Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
/* Developer notes.
*
* - Consider using startScope(), endScope() functions with module, program,
* subroutine or any other scope in fortran program.
*
* - Symbol modifiers (attributes) are collected using SymbolModifiers |= operator during
* substructure parsing. When substructure ends all modifiers are applied to actual
* entries in applyModifiers() functions.
*
* - How case insensitiveness should be handled in code?
* On one side we have arg->name and entry->name, on another side modifierMap[name].
* In entries and arguments case is the same as in code, in modifier map case is lowered and
* then it is compared to lowered entry/argument names.
*
* - Do not like constructs like aa{BS} or {BS}bb. Should try to handle blank space
* with separate rule?: It seems it is often necessary, because we may parse something like
* "functionA" or "MyInterface". So constructs like `(^|[ \t])interface({BS_}{ID})?/[ \t\n]'
* are desired.
*
* - Must track yyLineNr when using REJECT, unput() or similar commands.
*/
%{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <qarray.h>
#include <qstack.h>
#include <qregexp.h>
#include <unistd.h>
#include <qfile.h>
#include <qmap.h>
#include "fortranscanner.h"
#include "entry.h"
#include "message.h"
#include "config.h"
#include "doxygen.h"
#include "util.h"
#include "defargs.h"
#include "language.h"
#include "commentscan.h"
#include "fortrancode.h"
#include "pre.h"
#include "arguments.h"
// Toggle for some debugging info
//#define DBG_CTX(x) fprintf x
#define DBG_CTX(x) do { } while(0)
#define YY_NEVER_INTERACTIVE 1
#define YY_NO_INPUT 1
enum ScanVar { V_IGNORE, V_VARIABLE, V_PARAMETER, V_RESULT};
enum InterfaceType { IF_NONE, IF_SPECIFIC, IF_GENERIC, IF_ABSTRACT };
// {{{ ----- Helper structs -----
//! Holds modifiers (ie attributes) for one symbol (variable, function, etc)
struct SymbolModifiers {
enum Protection {NONE_P, PUBLIC, PRIVATE};
enum Direction {NONE_D, IN, OUT, INOUT};
//!< This is only used with function return value.
QCString type, returnName;
Protection protection;
Direction direction;
bool optional;
bool protect;
QCString dimension;
bool allocatable;
bool external;
bool intrinsic;
bool parameter;
bool pointer;
bool target;
bool save;
bool deferred;
bool nonoverridable;
bool nopass;
bool pass;
bool contiguous;
bool volat; /* volatile is a reserverd name */
QCString passVar;
SymbolModifiers() : type(), returnName(), protection(NONE_P), direction(NONE_D),
optional(FALSE), protect(FALSE), dimension(), allocatable(FALSE),
external(FALSE), intrinsic(FALSE), parameter(FALSE),
pointer(FALSE), target(FALSE), save(FALSE), deferred(FALSE), nonoverridable(FALSE),
nopass(FALSE), pass(FALSE), contiguous(FALSE), volat(FALSE), passVar() {}
SymbolModifiers& operator|=(const SymbolModifiers &mdfs);
SymbolModifiers& operator|=(QCString mdfrString);
};
//ostream& operator<<(ostream& out, const SymbolModifiers& mdfs);
static const char *directionStrs[] =
{
"", "intent(in)", "intent(out)", "intent(inout)"
};
static const char *directionParam[] =
{
"", "[in]", "[out]", "[in,out]"
};
// }}}
/* -----------------------------------------------------------------
*
* statics
*/
static ParserInterface *g_thisParser;
static const char * inputString;
static int inputPosition;
static bool isFixedForm;
static QCString inputStringPrepass; ///< Input string for prepass of line cont. '&'
static QCString inputStringSemi; ///< Input string after command separetor ';'
static unsigned int inputPositionPrepass;
static int lineCountPrepass = 0;
static QList<Entry> subrCurrent;
struct CommentInPrepass {
int column;
QCString str;
CommentInPrepass(int column, QCString str) : column(column), str(str) {}
};
static QList<CommentInPrepass> comments;
YY_BUFFER_STATE *include_stack = NULL;
int include_stack_ptr = 0;
int include_stack_cnt = 0;
static QFile inputFile;
static QCString yyFileName;
static int yyLineNr = 1 ;
static int yyColNr = 0 ;
static Entry* current_root = 0 ;
static Entry* global_root = 0 ;
static Entry* file_root = 0 ;
static Entry* current = 0 ;
static Entry* last_entry = 0 ;
static ScanVar v_type = V_IGNORE; // type of parsed variable
static QList<Entry> moduleProcedures; // list of all interfaces which contain unresolved
// module procedures
static QCString docBlock;
static QCString docBlockName;
static bool docBlockInBody = FALSE;
static bool docBlockJavaStyle;
static MethodTypes mtype;
static bool gstat;
static Specifier virt;
static QCString debugStr;
static QCString result; // function result
static Argument *parameter; // element of parameter list
static QCString argType; // fortran type of an argument of a parameter list
static QCString argName; // last identifier name in variable list
static QCString initializer; // initial value of a variable
static int initializerArrayScope; // number if nested array scopes in initializer
static int initializerScope; // number if nested function calls in initializer
static QCString useModuleName; // name of module in the use statement
static Protection defaultProtection;
static Protection typeProtection;
static int typeMode = false;
static InterfaceType ifType = IF_NONE;
static bool functionLine = FALSE;
static char stringStartSymbol; // single or double quote
static bool parsingPrototype = FALSE; // see parsePrototype()
//! Accumulated modifiers of current statement, eg variable declaration.
static SymbolModifiers currentModifiers;
//! Holds program scope->symbol name->symbol modifiers.
static QMap<Entry*,QMap<QCString,SymbolModifiers> > modifiers;
//-----------------------------------------------------------------------------
static int yyread(char *buf,int max_size);
static void startCommentBlock(bool);
static void handleCommentBlock(const QCString &doc,bool brief);
static void subrHandleCommentBlock(const QCString &doc,bool brief);
static void subrHandleCommentBlockResult(const QCString &doc,bool brief);
static void addCurrentEntry(int case_insens);
static void addModule(const char *name, bool isModule=FALSE);
static void addSubprogram(const char *text);
static void addInterface(QCString name, InterfaceType type);
static Argument *getParameter(const QCString &name);
static void scanner_abort();
static void startScope(Entry *scope);
static bool endScope(Entry *scope, bool isGlobalRoot=FALSE);
//static bool isTypeName(QCString name);
static void resolveModuleProcedures(QList<Entry> &moduleProcedures, Entry *current_root);
static int getAmpersandAtTheStart(const char *buf, int length);
static int getAmpOrExclAtTheEnd(const char *buf, int length);
static void truncatePrepass(int index);
static void pushBuffer(QCString &buffer);
static void popBuffer();
//static void extractPrefix(QCString& text);
static QCString extractFromParens(const QCString name);
static CommentInPrepass* locatePrepassComment(int from, int to);
static void updateVariablePrepassComment(int from, int to);
static void newLine();
//-----------------------------------------------------------------------------
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
#define YY_USER_ACTION yyColNr+=(int)yyleng;
//-----------------------------------------------------------------------------
%}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
IDSYM [a-z_A-Z0-9]
NOTIDSYM [^a-z_A-Z0-9]
SEPARATE [:, \t]
ID [a-z_A-Z%]+{IDSYM}*
ID_ [a-z_A-Z%]*{IDSYM}*
PP_ID {ID}
LABELID [a-z_A-Z]+[a-z_A-Z0-9\-]*
SUBPROG (subroutine|function)
B [ \t]
BS [ \t]*
BS_ [ \t]+
COMMA {BS},{BS}
ARGS_L0 ("("[^)]*")")
ARGS_L1a [^()]*"("[^)]*")"[^)]*
ARGS_L1 ("("{ARGS_L1a}*")")
ARGS_L2 "("({ARGS_L0}|[^()]|{ARGS_L1a}|{ARGS_L1})*")"
ARGS {BS}({ARGS_L0}|{ARGS_L1}|{ARGS_L2})
NOARGS {BS}"\n"
NUM_TYPE (complex|integer|logical|real)
LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
KIND {ARGS}
CHAR (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS}))
TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|{CHAR}|TYPE{ARGS}|CLASS{ARGS}|PROCEDURE{ARGS}?)
INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")"
ATTR_SPEC (EXTERNAL|ALLOCATABLE|DIMENSION{ARGS}|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|PRIVATE|PUBLIC|SAVE|TARGET|NOPASS|PASS{ARGS}?|DEFERRED|NON_OVERRIDABLE|CONTIGUOUS|VOLATILE)
ACCESS_SPEC (PRIVATE|PUBLIC)
LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")"
/* Assume that attribute statements are almost the same as attributes. */
ATTR_STMT {ATTR_SPEC}|DIMENSION|{ACCESS_SPEC}
EXTERNAL_STMT (EXTERNAL)
CONTAINS CONTAINS
PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|IMPURE|PURE|ELEMENTAL)?
SCOPENAME ({ID}{BS}"::"{BS})*
%option noyywrap
%option stack
%option caseless
/*%option debug */
//---------------------------------------------------------------------------------
/** fortran parsing states */
%x Subprog
%x SubprogPrefix
%x Parameterlist
%x SubprogBody
%x SubprogBodyContains
%x Start
%x Comment
%x Module
%x Program
%x ModuleBody
%x ModuleBodyContains
%x AttributeList
%x Variable
%x Initialization
%x ArrayInitializer
%x Typedef
%x TypedefBody
%x TypedefBodyContains
%x InterfaceBody
%x StrIgnore
%x String
%x Use
%x UseOnly
%x ModuleProcedure
%x Prepass
/** comment parsing states */
%x DocBlock
%x DocBackLine
%x EndDoc
%x BlockData
/** prototype parsing */
%x Prototype
%x PrototypeSubprog
%x PrototypeArgs
%%
/*-----------------------------------------------------------------------------------*/
<*>^.*\n { // prepass: look for line continuations
functionLine = FALSE;
DBG_CTX((stderr, "---%s", yytext));
int indexStart = getAmpersandAtTheStart(yytext, (int)yyleng);
int indexEnd = getAmpOrExclAtTheEnd(yytext, (int)yyleng);
if (indexEnd>=0 && yytext[indexEnd]!='&') //we are only interested in amp
indexEnd=-1;
if(indexEnd<0){ // ----- no ampersand as line continuation
if(YY_START == Prepass) { // last line in "continuation"
// Only take input after initial ampersand
inputStringPrepass+=(const char*)(yytext+(indexStart+1));
//printf("BUFFER:%s\n", (const char*)inputStringPrepass);
pushBuffer(inputStringPrepass);
yyColNr = 0;
yy_pop_state();
} else { // simple line
yyColNr = 0;
REJECT;
}
} else { // ----- line with continuation
if(YY_START != Prepass) {
comments.setAutoDelete(TRUE);
comments.clear();
yy_push_state(Prepass);
}
int length = inputStringPrepass.length();
// Only take input after initial ampersand
inputStringPrepass+=(const char*)(yytext+(indexStart+1));
lineCountPrepass ++;
// cut off & and remove following comment if present
truncatePrepass(length+indexEnd-(indexStart+1));
}
}
/*------ ignore strings that are not initialization strings */
<*>"\\\\" { if (yy_top_state() == Initialization
|| yy_top_state() == ArrayInitializer)
initializer+=yytext;
}
<*>"\\\""|\\\' { if (yy_top_state() == Initialization
|| yy_top_state() == ArrayInitializer)
initializer+=yytext;
}
<String>\"|\' { // string ends with next quote without previous backspace
if (yytext[0]!=stringStartSymbol) { yyColNr -= (int)yyleng; REJECT; } // single vs double quote
if (yy_top_state() == Initialization
|| yy_top_state() == ArrayInitializer)
initializer+=yytext;
yy_pop_state();
}
<String>. { if (yy_top_state() == Initialization
|| yy_top_state() == ArrayInitializer)
initializer+=yytext;
}
<*>\"|\' { /* string starts */
if (YY_START == StrIgnore) { yyColNr -= (int)yyleng; REJECT; }; // ignore in simple comments
yy_push_state(YY_START);
if (yy_top_state() == Initialization
|| yy_top_state() == ArrayInitializer)
initializer+=yytext;
stringStartSymbol=yytext[0]; // single or double quote
BEGIN(String);
}
/*------ ignore simple comment (not documentation comments) */
<*>"!"/[^<>\n] { if (YY_START == String) { yyColNr -= (int)yyleng; REJECT; } // "!" is ignored in strings
// skip comment line (without docu comments "!>" "!<" )
/* ignore further "!" and ignore comments in Strings */
if ((YY_START != StrIgnore) && (YY_START != String))
{
yy_push_state(YY_START);
BEGIN(StrIgnore);
debugStr="*!";
DBG_CTX((stderr,"start comment %d\n",yyLineNr));
}
}
<StrIgnore>.?/\n { yy_pop_state(); // comment ends with endline character
DBG_CTX((stderr,"end comment %d %s\n",yyLineNr,debugStr.data()));
} // comment line ends
<StrIgnore>. { debugStr+=yytext; }
/*------ use handling ------------------------------------------------------------*/
<Start,ModuleBody,SubprogBody>"use"{BS_} {
if(YY_START == Start)
{
addModule(NULL);
yy_push_state(ModuleBody); //anon program
}
yy_push_state(Use);
}
<Use>{ID} {
DBG_CTX((stderr,"using dir %s\n",yytext));
current->name=yytext;
current->fileName = yyFileName;
current->section=Entry::USINGDIR_SEC;
current_root->addSubEntry(current);
current = new Entry;
current->lang = SrcLangExt_Fortran;
yy_pop_state();
}
<Use>{ID}/, {
useModuleName=yytext;
}
<Use>,{BS}"ONLY" { BEGIN(UseOnly);
}
<UseOnly>{BS},{BS} {}
<UseOnly>{ID} {
current->name= useModuleName+"::"+yytext;
current->fileName = yyFileName;
current->section=Entry::USINGDECL_SEC;
current_root->addSubEntry(current);
current = new Entry ;
current->lang = SrcLangExt_Fortran;
}
<Use,UseOnly>"\n" {
yyColNr -= 1;
unput(*yytext);
yy_pop_state();
}
/* INTERFACE definitions */
<Start,ModuleBody,SubprogBody>{
^{BS}interface{IDSYM}+ { /* variable with interface prefix */ }
^{BS}interface { ifType = IF_SPECIFIC;
yy_push_state(InterfaceBody);
// do not start a scope here, every
// interface body is a scope of its own
}
^{BS}abstract{BS_}interface { ifType = IF_ABSTRACT;
yy_push_state(InterfaceBody);
// do not start a scope here, every
// interface body is a scope of its own
}
^{BS}interface{BS_}{ID}{ARGS}? { ifType = IF_GENERIC;
current->bodyLine = yyLineNr + lineCountPrepass + 1; // we have to be at the line after the definition and we have to take continuation lines into account.
yy_push_state(InterfaceBody);
// extract generic name
QCString name = QCString(yytext).stripWhiteSpace();
name = name.right(name.length() - 9).stripWhiteSpace().lower();
addInterface(name, ifType);
startScope(last_entry);
}
}
<InterfaceBody>^{BS}end{BS}interface({BS_}{ID})? {
// end scope only if GENERIC interface
last_entry->parent()->endBodyLine = yyLineNr - 1;
if (ifType == IF_GENERIC && !endScope(current_root))
yyterminate();
ifType = IF_NONE;
yy_pop_state();
}
<InterfaceBody>module{BS}procedure { yy_push_state(YY_START);
BEGIN(ModuleProcedure);
}
<ModuleProcedure>{ID} { if (ifType == IF_ABSTRACT || ifType == IF_SPECIFIC)
{
addInterface(yytext, ifType);
startScope(last_entry);
}
current->section = Entry::FUNCTION_SEC ;
current->name = yytext;
moduleProcedures.append(current);
addCurrentEntry(1);
}
<ModuleProcedure>"\n" { yyColNr -= 1;
unput(*yytext);
yy_pop_state();
}
<InterfaceBody>. {}
/*-- Contains handling --*/
<Start>^{BS}{CONTAINS}/({BS}|\n|!) {
if(YY_START == Start)
{
addModule(NULL);
yy_push_state(ModuleBodyContains); //anon program
}
}
<ModuleBody>^{BS}{CONTAINS}/({BS}|\n|!) { BEGIN(ModuleBodyContains); }
<SubprogBody>^{BS}{CONTAINS}/({BS}|\n|!) { BEGIN(SubprogBodyContains); }
<TypedefBody>^{BS}{CONTAINS}/({BS}|\n|!) { BEGIN(TypedefBodyContains); }
/*------ module handling ------------------------------------------------------------*/
<Start>block{BS}data{BS}{ID_} { //
v_type = V_IGNORE;
yy_push_state(BlockData);
defaultProtection = Public;
}
<Start>module|program{BS_} { //
v_type = V_IGNORE;
if(yytext[0]=='m' || yytext[0]=='M')
yy_push_state(Module);
else
yy_push_state(Program);
defaultProtection = Public;
}
<BlockData>^{BS}"end"({BS}(block{BS}data)({BS_}{ID})?)?{BS}/(\n|!) { // end block data
//if (!endScope(current_root))
// yyterminate();
defaultProtection = Public;
yy_pop_state();
}
<Start,ModuleBody,ModuleBodyContains>^{BS}"end"({BS}(module|program)({BS_}{ID})?)?{BS}/(\n|!) { // end module
resolveModuleProcedures(moduleProcedures, current_root);
if (!endScope(current_root))
yyterminate();
defaultProtection = Public;
yy_pop_state();
}
<Module>{ID} {
addModule(yytext, TRUE);
BEGIN(ModuleBody);
}
<Program>{ID} {
addModule(yytext, FALSE);
BEGIN(ModuleBody);
}
/*------- access specification --------------------------------------------------------------------------*/
<ModuleBody>private/{BS}(\n|"!") { defaultProtection = Private;
current->protection = defaultProtection ;
}
<ModuleBody>public/{BS}(\n|"!") { defaultProtection = Public;
current->protection = defaultProtection ;
}
/*------- type definition -------------------------------------------------------------------------------*/
<Start,ModuleBody>^{BS}type/[^a-z0-9_] {
if(YY_START == Start)
{
addModule(NULL);
yy_push_state(ModuleBody); //anon program
}
yy_push_state(Typedef);
current->protection = defaultProtection;
typeProtection = defaultProtection;
typeMode = true;
}
<Typedef>{
{COMMA} {}
{BS}"::"{BS} {}
abstract {
current->spec |= Entry::AbstractClass;
}
extends{ARGS} {
QCString basename = extractFromParens(yytext);
current->extends->append(new BaseInfo(basename, Public, Normal));
}
public {
current->protection = Public;
typeProtection = Public;
}
private {
current->protection = Private;
typeProtection = Private;
}
{LANGUAGE_BIND_SPEC} {
/* ignored for now */
}
{ID} { /* type name found */
current->section = Entry::CLASS_SEC;
current->spec |= Entry::Struct;
current->name = yytext;
current->fileName = yyFileName;
current->bodyLine = yyLineNr;
current->startLine = yyLineNr;
/* if type is part of a module, mod name is necessary for output */
if ((current_root) &&
(current_root->section == Entry::CLASS_SEC
|| current_root->section == Entry::NAMESPACE_SEC))
{
current->name = current_root->name + "::" + current->name;
}
addCurrentEntry(1);
startScope(last_entry);
BEGIN(TypedefBody);
}
}
<TypedefBodyContains>{ /* Type Bound Procedures */
^{BS}PROCEDURE{ARGS}? {
current->type = QCString(yytext).simplifyWhiteSpace();
}
^{BS}final {
current->spec |= Entry::Final;
current->type = QCString(yytext).simplifyWhiteSpace();
}
^{BS}generic {
current->type = QCString(yytext).simplifyWhiteSpace();
}
{COMMA} {
}
{ATTR_SPEC} {
currentModifiers |= QCString(yytext);
}
{BS}"::"{BS} {
}
{ID} {
QCString name = yytext;
modifiers[current_root][name.lower()] |= currentModifiers;
current->section = Entry::FUNCTION_SEC;
current->name = name;
current->fileName = yyFileName;
current->bodyLine = yyLineNr;
current->startLine = yyLineNr;
addCurrentEntry(1);
}
{BS}"=>"[^(\n|\!)]* { /* Specific bindings come after the ID. */
last_entry->args = yytext;
}
"\n" {
currentModifiers = SymbolModifiers();
newLine();
docBlock.resize(0);
}
}
<TypedefBody,TypedefBodyContains>{
^{BS}"end"{BS}"type"({BS_}{ID})?{BS}/(\n|!) { /* end type definition */
last_entry->parent()->endBodyLine = yyLineNr;
if (!endScope(current_root))
yyterminate();
typeMode = false;
yy_pop_state();
}
}
/*------- module/global/typedef variable ---------------------------------------------------*/
<SubprogBody,SubprogBodyContains>^{BS}[0-9]*{BS}"end"({BS}{SUBPROG}({BS_}{ID})?)?{BS}/(\n|!) {
//
// ABSTRACT and specific interfaces are stored
// in a scope of their own, even if multiple
// are group in one INTERFACE/END INTERFACE block.
//
last_entry->endBodyLine = yyLineNr - 1;
if (ifType == IF_ABSTRACT || ifType == IF_SPECIFIC)
endScope(current_root);
if (!endScope(current_root))
yyterminate();
subrCurrent.remove(0u);
yy_pop_state() ;
}
<BlockData>{
{ID} {
}
}
<Start,ModuleBody,TypedefBody,SubprogBody>{
^{BS}{TYPE_SPEC}/{SEPARATE} {
current->bodyLine = yyLineNr + 1;
current->endBodyLine = yyLineNr + lineCountPrepass;
/* variable declaration starts */
if(YY_START == Start)
{
addModule(NULL);
yy_push_state(ModuleBody); //anon program
}
argType = QCString(yytext).simplifyWhiteSpace().lower();
yy_push_state(AttributeList);
}
/* Dimitri: macro expansion should already be done during preprocessing not here!
^{BS}{PP_ID}{KIND}? { // check for preprocessor symbol expand to type
QCString str = yytext;
str = str.stripWhiteSpace();
//DefineDict* defines = getGlobalDefineDict();
QCString name;
int index = str.find("(");
if (index != -1)
name = str.left(index).stripWhiteSpace();
else
name = str;
Define *define = 0; //(*defines)[name];
if (define != 0 && isTypeName(define->definition))
{
argType = str;
yy_push_state(AttributeList);
}
else
{
yyColNr -= (int)yyleng;
REJECT;
}
}
*/
{EXTERNAL_STMT}/({BS}"::"|{BS_}{ID}) {
/* external can be a "type" or an attribute */
if(YY_START == Start)
{
addModule(NULL);
yy_push_state(ModuleBody); //anon program
}
QCString tmp = yytext;
currentModifiers |= tmp.stripWhiteSpace();
argType = QCString(yytext).simplifyWhiteSpace().lower();
yy_push_state(AttributeList);
}
{ATTR_STMT}/{BS_}{ID} |
{ATTR_STMT}/{BS}"::" {
/* attribute statement starts */
DBG_CTX((stderr,"5=========> Attribute statement: %s\n", yytext));
QCString tmp = yytext;
currentModifiers |= tmp.stripWhiteSpace();
argType="";
yy_push_state(YY_START);
BEGIN( AttributeList ) ;
}
{ID} {
}
^{BS}"type"{BS_}"is"/{BS_} { }
^{BS}"type"{BS}"=" { }
}
<AttributeList>{
{COMMA} {}
{BS} {}
{ATTR_SPEC}. { /* update current modifiers when it is an ATTR_SPEC and not a variable name */
/* bug_625519 */
QChar chr = yytext[(int)yyleng-1];
if (chr.isLetter() || chr.isDigit() || (chr == '_'))
{
yyColNr -= (int)yyleng;
REJECT;
}
else
{
QCString tmp = yytext;
tmp = tmp.left(tmp.length() - 1);
yyColNr -= 1;
unput(yytext[(int)yyleng-1]);
currentModifiers |= (tmp);
}
}
"::" { /* end attribute list */
BEGIN( Variable );
}
. { /* unknown attribute, consider variable name */
//cout<<"start variables, unput "<<*yytext<<endl;
yyColNr -= 1;
unput(*yytext);
BEGIN( Variable );
}
}
<Variable>{BS} { }
<Variable>{ID} { /* parse variable declaration */
//cout << "5=========> got variable: " << argType << "::" << yytext << endl;
/* work around for bug in QCString.replace (QCString works) */
QCString name=yytext;
name = name.lower();
/* remember attributes for the symbol */
modifiers[current_root][name.lower()] |= currentModifiers;
argName= name;
v_type= V_IGNORE;
if (!argType.isEmpty() && current_root->section!=Entry::FUNCTION_SEC)
{ // new variable entry
v_type = V_VARIABLE;
current->section = Entry::VARIABLE_SEC;
current->name = argName;
current->type = argType;
current->fileName = yyFileName;
current->bodyLine = yyLineNr; // used for source reference
current->startLine = yyLineNr;
addCurrentEntry(1);
}
else if (!argType.isEmpty())
{ // declaration of parameter list: add type for corr. parameter
parameter = getParameter(argName);
if (parameter)
{
v_type= V_PARAMETER;
if (!argType.isNull()) parameter->type=argType.stripWhiteSpace();
if (!docBlock.isNull())
{
subrHandleCommentBlock(docBlock,TRUE);
}
}
// save, it may be function return type
if (parameter)
{
modifiers[current_root][name.lower()].type = argType;
}
else
{
if ((current_root->name.lower() == argName.lower()) ||
(modifiers[current_root->parent()][current_root->name.lower()].returnName.lower() == argName.lower()))
{
int strt = current_root->type.find("function");
QCString lft;
QCString rght;
if (strt != -1)
{
v_type = V_RESULT;
lft = "";
rght = "";
if (strt != 0) lft = current_root->type.left(strt).stripWhiteSpace();
if ((current_root->type.length() - strt - strlen("function"))!= 0)
{
rght = current_root->type.right(current_root->type.length() - strt - strlen("function")).stripWhiteSpace();
}
current_root->type = lft;
if (rght.length() > 0)
{
if (current_root->type.length() > 0) current_root->type += " ";
current_root->type += rght;
}
if (argType.stripWhiteSpace().length() > 0)
{
if (current_root->type.length() > 0) current_root->type += " ";
current_root->type += argType.stripWhiteSpace();
}
if (current_root->type.length() > 0) current_root->type += " ";
current_root->type += "function";
if (!docBlock.isNull())
{
subrHandleCommentBlockResult(docBlock,TRUE);
}
}
else
{
current_root->type += " " + argType.stripWhiteSpace();
}
current_root->type = current_root->type.stripWhiteSpace();
modifiers[current_root][name.lower()].type = current_root->type;
}
else
{
modifiers[current_root][name.lower()].type = argType;
}
}
// any accumulated doc for argument should be emptied,
// because it is handled other way and this doc can be
// unexpectedly passed to the next member.
current->doc.resize(0);
current->brief.resize(0);
}
}
<Variable>{ARGS} { /* dimension of the previous entry. */
QCString name(argName);
QCString attr("dimension");
attr += yytext;
modifiers[current_root][name.lower()] |= attr;
}
<Variable>{COMMA} { //printf("COMMA: %d<=..<=%d\n", yyColNr-(int)yyleng, yyColNr);
// locate !< comment
updateVariablePrepassComment(yyColNr-(int)yyleng, yyColNr);
}
<Variable>{BS}"=" {
yy_push_state(YY_START);
initializer="=";
initializerScope = initializerArrayScope = 0;
BEGIN(Initialization);
}
<Variable>"\n" { currentModifiers = SymbolModifiers();
yy_pop_state(); // end variable declaration list
newLine();
docBlock.resize(0);
}
<Variable>";".*"\n" { currentModifiers = SymbolModifiers();
yy_pop_state(); // end variable declaration list
docBlock.resize(0);
inputStringSemi =(const char*)(QCString(" \n") + QCString(yytext+1)).data();
yyLineNr--;
pushBuffer(inputStringSemi);
}
<*>";".*"\n" {
if (YY_START == Variable) REJECT; // Just be on the safe side
if (YY_START == String) REJECT; // ";" ignored in strings
if (YY_START == StrIgnore) REJECT; // ";" ignored in regular comments
inputStringSemi =(const char*)(QCString(" \n") + QCString(yytext+1)).data();
yyLineNr--;
pushBuffer(inputStringSemi);
}
<Initialization,ArrayInitializer>"[" |
<Initialization,ArrayInitializer>"(/" { initializer+=yytext;
initializerArrayScope++;
BEGIN(ArrayInitializer); // initializer may contain comma
}
<ArrayInitializer>"]" |
<ArrayInitializer>"/)" { initializer+=yytext;
initializerArrayScope--;
if(initializerArrayScope<=0)
{
initializerArrayScope = 0; // just in case
BEGIN(Initialization);
}
}
<ArrayInitializer>. { initializer+=yytext; }
<Initialization>"(" { initializerScope++;
initializer+=yytext;
}
<Initialization>")" { initializerScope--;
initializer+=yytext;
}
<Initialization>{COMMA} { if (initializerScope == 0)
{
updateVariablePrepassComment(yyColNr-(int)yyleng, yyColNr);
yy_pop_state(); // end initialization
if (v_type == V_VARIABLE) last_entry->initializer= initializer;
}
else
initializer+=", ";
}
<Initialization>"\n"|"!" { //|
yy_pop_state(); // end initialization
if (v_type == V_VARIABLE) last_entry->initializer= initializer;
yyColNr -= 1;
unput(*yytext);
}
<Initialization>. { initializer+=yytext; }
/*------ fortran subroutine/function handling ------------------------------------------------------------*/
/* Start is initial condition */
<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{TYPE_SPEC}{BS}({PREFIX}{BS_})?/{SUBPROG}{BS_} {
if (ifType == IF_ABSTRACT || ifType == IF_SPECIFIC)
{
addInterface("$interface$", ifType);
startScope(last_entry);
}
// TYPE_SPEC is for old function style function result
result = QCString(yytext).stripWhiteSpace().lower();
current->type = result;
yy_push_state(SubprogPrefix);
}
<SubprogPrefix>{BS}{SUBPROG}{BS_} {
// Fortran subroutine or function found
v_type = V_IGNORE;
result=yytext;
result=result.stripWhiteSpace();
addSubprogram(result);
BEGIN(Subprog);
}
<Start,ModuleBody,SubprogBody,InterfaceBody,ModuleBodyContains,SubprogBodyContains>^{BS}({PREFIX}{BS_})?{SUBPROG}{BS_} {
// Fortran subroutine or function found
v_type = V_IGNORE;
if (ifType == IF_ABSTRACT || ifType == IF_SPECIFIC)
{
addInterface("$interface$", ifType);
startScope(last_entry);
}