-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathefpp.py2
executable file
·815 lines (700 loc) · 26.1 KB
/
efpp.py2
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
#!/usr/bin/env python
#
# efpp.py:
# Preprocessor for eFortran, a dialect of Modern Fortran.
#
# developed by A. Kageyama (kage@port.kobe-u.ac.jp)
# on 2017.09.17, for cg-mhd project.
# revised on 2018.07.13, for general eFortran codes.
#
# Reference:
# S. Hosoyamada and A. Kageyama,
# "A Dialect of Modern Fortran for Simulations" '
# in Communications in Computer and Information Science,
# vol 946, pages 439-448, 2018 (Proceedings of AsiaSim2018)
#
# Home page:
# /~https://github.com/akageyama/efpp
#
import re
import sys
#=============================================
def block_comment(lines_in):
#=============================================
"""
sample input:
--------------------------
abc def ghijklmn opq
=======
abc def ghijklmn opq
======
abc def ghijklmn opq
abc def ghijklmn opq
======
abc def ghijklmn opq
=======
abc def ghijklmn opq
sample output
--------------------------
abc def ghijklmn opq
!=======
!abc def ghijklmn opq
!! ======
!! abc def ghijklmn opq
!! abc def ghijklmn opq
!! ======
!abc def ghijklmn opq
!=======
abc def ghijklmn opq
--------------------------
"""
output = list()
comment_span_list = list()
comment_depth = 0
comment_block_exit_flag = False
for line in lines_in:
match_obj = re.search(r'^ *===+\s+$', line)
comment_block_exit_flag = False
if match_obj:
span = match_obj.span()
if comment_depth == 0: # Entered the 1st comment block.
comment_span_list.append(span)
comment_depth = 1
else:
if span==comment_span_list[-1]:
# End of the present comment block.
del comment_span_list[-1]
comment_block_exit_flag = True
else: # Entered new (deeper) comment block.
comment_span_list.append(span)
comment_depth += 1
if comment_depth>0:
line = re.sub(r'^', '!'*comment_depth, line)
if comment_block_exit_flag:
comment_depth -= 1
output.append(line)
return output
#=============================================
def read_alias_list_and_make_dict(filename):
#=============================================
"""
input = file 'efpp_alias.list'
output = dictionary 'alias_dict'
Example:
--------<input>-------
> cat efpp_alias.list
"do i bulk" # you can separate the rule to two lines.
=> "do i = 1 , NXPP"
"do i full" => # you can put arrows, here, too.
"do i = 0 , NXPP1"
--------</input>-------
--------<output>-------
alias_dict = {
'do i bulk': 'do i = 1 , NXPP',
'do i full': 'do i = 0 , NXPP1'
}
--------</output>-------
"""
patt_blank_line = r'^\s*$'
# 000 ' ' (blank line)
patt_comment_line = r'^\s*#.*$'
# 000 '# comment ...'
patt_both_left_and_right = r'^\s*\"(.*?)\"\s*=>\s*\"(.*?)\"\s#*.*$'
# 000 '" left" => " right" '
# 000 '" left" => " right" # comment ...'
patt_left_hand_side = r'^\s*\"(.*?)\"\s*=>\s*#*.*$'
# 000 '" left" => '
# 000 '" left" => # comment ...'
patt_right_hand_side = r'^\s*=>\s*\"(.*?)\"\s*#*.*$'
# 000 '=> " right" '
# 000 '=> " right" # comment ...'
patt_left_or_right = r'^\s*\"(.*?)\"\s*#*.*$'
# 000 '" left" '
# 000 '" left" # comment... '
# 000 '" right" '
# 000 '" right" # comment... '
alias_dict = dict()
left = ''
right = ''
with open(filename) as f:
for line in f:
m_blank_line = re.match(patt_blank_line, line)
m_comment_line = re.match(patt_comment_line, line)
m_both_left_and_right = re.match(patt_both_left_and_right, line)
m_left_hand_side = re.match(patt_left_hand_side, line)
m_right_hand_side = re.match(patt_right_hand_side, line)
m_left_or_right = re.match(patt_left_or_right, line)
if m_blank_line or m_comment_line:
continue
elif m_both_left_and_right:
left = m_both_left_and_right.group(1)
right = m_both_left_and_right.group(2)
alias_dict[left] = right
left, right='', ''
elif m_left_hand_side:
left = m_left_hand_side.group(1)
if right:
alias_dict[left] = right
left, right='', ''
elif m_right_hand_side:
right = m_right_hand_side.group(1)
if left:
alias_dict[left] = right
left, right='', ''
elif m_left_or_right:
if left != '':
right = m_left_or_right.group(1)
else:
left = m_left_or_right.group(1)
if left != '' and right !='':
alias_dict[left] = right
left, right='', ''
else:
print("error. unknown pattern.")
sys.exit()
return alias_dict
#=============================================
def replace_period_in_member_accessor(string_in):
#=============================================
string_work1 = replace_characters_sandwiched_by_double_quotes(string_in)
string_work2 = replace_characters_sandwiched_by_single_quotes(string_work1)
string_work3 = remove_characters_in_comment(string_work2)
# Regexp for the period letter '.' used as a member access operator.
pattern = r'[a-zA-Z][a-zA-Z_0-9]*?\)?\.[a-zA-Z][a-zA-Z_0-9]*?'
# array(3).a02.mem01 ==> array(3)%a03%mem01
m = re.search(pattern, string_work3)
ans = string_in
if m:
char_pos = string_in.find('.', m.start(), m.end()) # in the match
string_work = replace_chars_in_string(string_in, char_pos, char_pos, '%')
ans = replace_period_in_member_accessor(string_work)
return ans
#=============================================
def replace_chars_in_string(string_in, pos_stt, pos_end, target_char):
#=============================================
i = pos_stt
char_list = list(string_in)
while i <= pos_end:
char_list[i] = target_char
i += 1
string_out = "".join(char_list)
return string_out
#=============================================
def replace_characters_sandwiched_by_double_quotes(string_in):
#=============================================
ans = string_in
m = re.search(r'\".*?\"', string_in)
if m:
string_tmp = replace_chars_in_string(string_in, m.start(), m.end()-1, 'X')
ans = replace_characters_sandwiched_by_double_quotes(string_tmp) # Recursion
return ans
#=============================================
def replace_characters_sandwiched_by_single_quotes(string_in):
#=============================================
ans = string_in
m = re.search(r'\'.*?\'', string_in)
if m:
string_tmp = replace_chars_in_string(string_in, m.start(), m.end()-1, 'Y')
ans = replace_characters_sandwiched_by_single_quotes(string_tmp) # Recursion
return ans
#=============================================
def remove_characters_in_comment(string_in):
#=============================================
return re.sub(r'!.*', '!', string_in)
#=============================================
def alias_decode(lines_in):
#=============================================
"""
Converts strings. The rule is defined in alias_dict, which
is constructed from a source text named 'efpp_alias.list'.
====<sample of alias_dict>====
alias_dict = {
"type(sfield_t)"
: "real(DR), dimension(0:NXPP1,0:NYPP1,0:NZPP1)"
,
"do i bulk"
: "do i = 1 , NXPP"
,
"do i full"
: "do i = 0 , NXPP1"
,
"do j bulk"
: "do j = 1 , NYPP"
,
"do j full"
: "do j = 0 , NYPP1"
,
"do k bulk"
: "do k = 1 , NZPP"
,
"do k full"
: "do k = 0 , NZPP1"
}
====</sample of alias_dict>====
====<source of the above: efpp_alias.list>====
# since there is no typedef in fortran.
"type(sfield_t)"
=> "real(DR), dimension(0:NXPP1,0:NYPP1,0:NZPP1)"
"do i bulk" # special macro in this code.
=> "do i = 1 , NXPP"
"do i full" =>
"do i = 0 , NXPP1"
"do j bulk" =>
"do j = 1 , NYPP"
"do j full" =>
"do j = 0 , NYPP1"
"do k bulk"
=> "do k = 1 , NZPP"
"do k full"
=> "do k = 0 , NZPP1"
====</source of the above: efpp_alias.list>====
"""
# Default macros
alias_dict = {
"_?_"
: "_BOOLEAN"
,
" char(len="
: " character(len="
,
" <in> "
: ", intent(in) "
,
" <out> "
: ", intent(out) "
,
" <io> "
: ", intent(inout) "
,
" <optin> "
: ", intent(in), optional "
,
" <optout> "
: ", intent(out), optional "
,
" <optio> "
: ", intent(inout), optional "
,
" <const> "
: ", parameter "
}
# Append user-defined macros
alias_dict.update(read_alias_list_and_make_dict('efpp_alias.list'))
output = list()
for line in lines_in:
l = line
for i in alias_dict:
l = l.replace(i,alias_dict[i])
output.append(l)
return output
#=============================================
def subsdiary_call_decode(lines_in):
#=============================================
"""
xyz -call abc() => xyz ;call abc()
-call abc() => call abc()
"""
output = list()
pat = re.compile(r'^(.*) -call +([a-zA-Z].*)')
for line in lines_in:
match = pat.search(line)
if match:
s = match.group(1)
if re.search(r'^\s*$', s):
s += ' call '
else:
s += ' ;call '
s += match.group(2)
s += '\n'
output.append(s)
else:
output.append(line)
return output
#=============================================
def just_once_region(lines_in):
#=============================================
"""
program test
logical :: just_once = .true.
==<just_once>== ! you can put comment here.
call subsub('asdfasdf')
==</just_once>== ! end of just_once region.
end program test
"""
output = list()
pat_begin = re.compile(r'^([^=]+)=+<just_once>=+(.*)$')
pat_end = re.compile(r'^([^=]+)=+</just_once>=+(.*)$')
for line in lines_in:
match_begin = pat_begin.search(line)
match_end = pat_end.search(line)
if match_begin:
s = match_begin.group(1)
s += 'if (just_once) then'
s += ' ' + match_begin.group(2)
s += '\n'
elif match_end:
s = match_end.group(1)
s += 'just_once = .false. ; end if'
s += ' ' + match_end.group(2)
s += '\n'
else:
s = line
output.append(s)
return output
#=============================================
def skip_counter(lines_in):
#=============================================
"""
# program test
# inte(SI) :: ctr=0
# inte(SI) :: i
# do i = 1 , 200
# ===<skip ctr:8>=== ! you can put comment.
# call subsub('asdfasdf',i)
# ===</skip ctr>=== ! end of skip block.
# end do
# end program test
"""
output = list()
pat_begin = re.compile(r'^([^=]+)=+<skip\s+([a-zA-Z][a-zA-Z_0-9]*):(\s*.+)>=+(.*)$')
pat_end = re.compile(r'^([^=]+)=+</skip\s+([a-zA-Z][a-zA-Z_0-9]*)>=+(.*)$')
for line in lines_in:
match_begin = pat_begin.search(line)
match_end = pat_end.search(line)
if match_begin:
s = match_begin.group(1)
s += 'if(mod(' + match_begin.group(2)
s += ',' + match_begin.group(3)
s += ')==0) then' + match_begin.group(4)
s += '\n'
elif match_end:
s = match_end.group(1)
s += 'end if; '
s += match_end.group(2) + ' = '
s += match_end.group(2) + ' + 1'
s += ' ' + match_end.group(3)
s += '\n'
else:
s = line
output.append(s)
return output
#=============================================
def routine_name_macro(lines_in):
#=============================================
"""
module test_m ! <= Count this 'module'
interface gen
module procedure ... ! <= Do not count
! this as a 'module'
end interface
..
contains
subroutine test__sub ! <= Count this as a 'subroutine'
end subroutine test__sub
end module test_m
program main0 ! <= Count this as a 'program'
..
contains
subroutine sub1(...) ! <= Count this as a 'subroutine'
contains
function fun2(...) ! <= Count this as a 'function'
print('__MODFUNC__') ! print('main0/sub1/fun2')
end function fun2
end subroutine sub1
end program main0
"""
this_line_is_in_interface = False
output = list()
pat_program_in = re.compile(r'^(\s*)program\s+([a-zA-Z][a-zA-Z_0-9]*)\s+')
pat_module_in = re.compile(r'^(\s*)module\s+([a-zA-Z][a-zA-Z_0-9]*)\s+')
pat_subroufunc_in = re.compile(r'^(\s*)(elemental\s+)?(subroutine|function)\s+([a-zA-Z][a-zA-Z_0-9]*)[\s\(].*')
pat_interface_in = re.compile(r'^(\s*)interface\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_program_out = re.compile(r'^(\s*)end\s+program\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_module_out = re.compile(r'^(\s*)end\s+module\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_subroufunc_out = re.compile(r'^(\s*)end\s+(subroutine|function)\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_interface_out = re.compile(r'^(\s*)end\s+interface')
lctr = 0 # line counter
name = list()
for line in lines_in:
lctr += 1
match_program_in = pat_program_in.search(line)
match_module_in = pat_module_in.search(line)
match_subroufunc_in = pat_subroufunc_in.search(line)
match_interface_in = pat_interface_in.search(line)
match_program_out = pat_program_out.search(line)
match_module_out = pat_module_out.search(line)
match_subroufunc_out = pat_subroufunc_out.search(line)
match_interface_out = pat_interface_out.search(line)
if match_program_in:
name.append(match_program_in.group(2))
if match_interface_in:
this_line_is_in_interface = True
if match_interface_out:
this_line_is_in_interface = False
if match_module_in:
if not this_line_is_in_interface:
name.append(match_module_in.group(2))
if match_subroufunc_in:
name.append(match_subroufunc_in.group(4))
if match_program_out:
name.pop()
if match_module_out:
name.pop()
if match_subroufunc_out:
name.pop()
if len(name)>0:
progmodule_name = name[0]
line = line.replace('__MODULE__', progmodule_name)
if len(name)==3:
subroufunc_name = name[1] + '/' + name[2]
line = line.replace('__FUNC__', subroufunc_name)
module_plus_subroufunc_name = progmodule_name + '/' + subroufunc_name
line = line.replace('__MODFUNC__', module_plus_subroufunc_name)
elif len(name)==2:
subroufunc_name = name[1]
line = line.replace('__FUNC__', subroufunc_name)
module_plus_subroufunc_name = progmodule_name + '/' + subroufunc_name
line = line.replace('__MODFUNC__', module_plus_subroufunc_name)
line = line.replace('__LINE__', str(lctr))
output.append(line)
return output
#=============================================
def member_access_operator_macro(lines_in):
#=============================================
"""
Replaces "." to "%", for example,
> call mhd.sub.update(mhd.main)
is converted to
> call mhd%sub%update(mhd%main)
"""
"""
a3.y14 = 3.10_DR
grid.x = 1.0_DR
"""
output = list()
for line in lines_in:
line_replaced = replace_period_in_member_accessor(line)
output.append(line_replaced)
return output
#=============================================
def check_implicit_none(filename_in, lines_in):
#=============================================
"""
Check if the line "implicit none" appears.
"""
pat_comment = re.compile(r'^\s*\!.*$')
pat_blank = re.compile(r'^\s*$')
pat_use = re.compile(r'^\s*use\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_implicit_none = re.compile(r'^\s*implicit none\s+')
pat_program = re.compile(r'^\s*program\s+[a-zA-Z][a-zA-Z_0-9]*')
pat_module = re.compile(r'^\s*module\s+[a-zA-Z][a-zA-Z_0-9]*')
search_mode_on_for_implicit_none = False
for line in lines_in:
if pat_comment.search(line) or pat_blank.search(line):
continue # Skip comment lines.
if search_mode_on_for_implicit_none:
if pat_use.search(line):
continue # Skip 'use ***' lines.
elif pat_implicit_none.search(line):
return # O.K. this code is fine.
else:
break # Other line appears before "implicit none"
elif pat_module.search(line) or pat_program.search(line):
search_mode_on_for_implicit_none = True
error_message = 'Error in '+filename_in+': You forgot "implicit none"\n'
sys.stderr.write(error_message)
sys.exit(1)
#=============================================
def kutimer_docode(lines_in):
#=============================================
"""
# Before...
# ___________________________________________
# !{ main}{{STT}}
# call fluid%create(lat) !{ main}{flu cr}
# call fluid%set_initial(lat)
# !{ main}{flu in}
# do loop = 1 , loop_max !{{count}}
# call pdf%shift(lat) !{ main}{pdfsht}
# end do
# call fluid%finalize !{ main}{{END}}
# !{{print}}
#
# After... (You should apply "subsidiary_caller" later.)
# ___________________________________________
# -call kutimer__start(' main')
# call fluid%create(lat) -call kutimer__(' main','flu cr')
# call fluid%set_initial(lat)
# -call kutimer__(' main','flu in')
# do loop = 1 , loop_max -call kutimer__count
# call pdf%shift(lat) -call kutimer__(' main','pdfsht')
# end do
# call fluid%finalize -call kutimer__end(' main')
# -call kutimer__print
#
"""
output = list()
pat_stt = re.compile(r'^(.*)\s+!\{(......)\}\{\{STT\}\}')
pat_cal = re.compile(r'^(.*)\s+!\{(......)\}\{(......)\}')
pat_cnt = re.compile(r'^(.*)\s+!\{\{count\}\}')
pat_end = re.compile(r'^(.*)\s+!\{(......)\}\{\{END\}\}')
pat_pri = re.compile(r'^(.*)\s+!\{\{print\}\}(.*)')
for line in lines_in:
match_stt = pat_stt.search(line)
match_cal = pat_cal.search(line)
match_cnt = pat_cnt.search(line)
match_end = pat_end.search(line)
match_pri = pat_pri.search(line)
if match_stt:
line = match_stt.group(1) + ' '
line += '-call kutimer__start(\'' + match_stt.group(2)
line += '\')' + '\n'
if match_cal:
line = match_cal.group(1) + ' '
line += '-call kutimer__(\'' + match_cal.group(2)
line += '\',\'' + match_cal.group(3)
line += '\')' + '\n'
if match_cnt:
line = match_cnt.group(1) + ' '
line += '-call kutimer__count\n'
if match_end:
line = match_end.group(1) + ' '
line += '-call kutimer__end(\'' + match_end.group(2)
line += '\')' + '\n'
if match_pri:
line = match_pri.group(1) + ' '
line += '-call kutimer__print' + match_pri.group(2) + '\n'
output.append(line)
return output
#=============================================
def operator_decode(lines_in):
#=============================================
"""
"... val += aa" is converted into
"... val = val + aa"
"... val -= aa" is converted into
"... val = val - aa"
"if (xyz>0) xyz *= 2" is converted into
"if (xyz>0) xyz = xyz * 2"
but
"val /= 2" is not converted since
it stands for val does not equal to 2.
"""
output = list()
pat = re.compile(r'(.*)\s+?(\S+)' \
'\s+?([\+\-\*])=\s+?' \
'(.+)$')
for line in lines_in:
match = pat.search(line)
if match:
s = match.group(1) # if (xyz>0)
s += ' ' + match.group(2) # if (xyz>0) xyz
s += ' = ' + match.group(2) # if (xyz>0) xyz = xyz
s += ' ' + match.group(3) # if (xyz>0) xyz = xyz /
s += ' ' + match.group(4) # if (xyz>0) xyz = xyz / 2
s += '\n'
output.append(s)
else:
output.append(line)
return output
#=============================================
def debugp_decode(lines_in):
#=============================================
"""
!debugp val
=>
print *, "\\modname(linenum): ", "val =", val
!debugp "str"
=>
print *, "\\modname(linenum): ", "str"
!debugp "str", val1
=>
print *, "\\modname(linenum): ", "str", "val1 = ", val1
!debugp "str", val1, val2, ...
=>
print *, "\\modname(linenum): ", "str", "val1 = ", val1, "val2 = ", ...
!debugp "str1", val1, "str2", val2, ...
=>
print *, "\\modname(linenum): ", "str1", "val1 = ", val1, "str2", "val2 = ", ...
"""
output = list()
pat = re.compile(r'(.*)!debugp\s+(.*)$')
for line in lines_in:
match = pat.search(line)
if match:
args = match.group(2).split(',')
line = match.group(1)
if line.strip(): # it's not empty.
line += ';'
line += 'print *, '
line += '\"\\\\__MODULE__(__LINE__): \", '
countParenthesis = 0
temp = ''
for arg in args:
a = arg.strip() # put off blanks
if a[0]=='\'' or a[0]=='\"': # string (e.g., 'message')
if a[-1]=='\'' or a[-1]=='\"': # string (e.g., 'say,...)
line += a + ', '
else:
line += a + ', ' + a[0] + ', '
elif a[-1]=='\'' or a[-1]=='\"':# string (e.g., '..., smthng')
line += a[-1] + a + ', '
elif '(' in a or countParenthesis!=0:
if '(' in a:
countParenthesis += a.count('(') - a.count(')')
temp += a + ', '
if countParenthesis == 0:
temp = temp[:-2] # put of the last "comma + space"
line += "\" " + temp + " = \", " + temp + ', '
elif ')' in a:
countParenthesis += a.count('(') - a.count(')')
temp += a + ', '
if countParenthesis == 0:
temp = temp[:-2] # put of the last "comma + space"
line += "\" " + temp + " = \", " + temp + ', '
else:
temp += a + ', '
else:
line += "\" " + a + " = \", " + a + ', '
line = line[:-2] # put of the last "comma + space"
line += '\n'
output.append(line)
return output
#=============================================
def efpp(filename_in):
#=============================================
""" A preprocessor for Fortran 2003.
input: filename_in (e.g., 'main.e03')
output: standard out
"""
with open(filename_in,'r') as f:
lines = f.readlines()
# In the followings, we apply multiple docoders
# to 'lines. Their call-order is basically arbitrary.
# Only exception is that 'kutimer_decode' shoud be
# called before 'subsdiary_call_decode', because
# 'kutimer_decode' generates routine calls such
# as '... -call kutimer__...', which is supposed
# to be processed by 'subsdiary_call_decode'.
# One more condition, 'alias_docode' should be
# called before 'routine_name_macro', __LINE__ etc,
# could be included in 'efpp_alias.list'.
lines = kutimer_docode(lines)
lines = subsdiary_call_decode(lines)
lines = block_comment(lines)
lines = operator_decode(lines)
lines = just_once_region(lines)
lines = skip_counter(lines)
lines = alias_decode(lines)
lines = debugp_decode(lines)
lines = routine_name_macro(lines)
lines = member_access_operator_macro(lines)
check_implicit_none(filename_in, lines)
for l in lines:
print l,
if __name__ == '__main__':
if len(sys.argv)==1:
filename_in = input('enter filename_in name > ')
else:
filename_in = sys.argv[1]
efpp(filename_in)