forked from OpenResearchComputation/fable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.py
3116 lines (2877 loc) · 98.6 KB
/
read.py
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
from __future__ import division
from fable \
import unsigned_integer_scan, \
identifier_scan, \
find_closing_parenthesis, \
SemanticError
from fable import tokenization
from fable import intrinsics
from fable import equivalence
from fable import utils
import sys
class Error(Exception): pass
class raise_errors_mixin(object):
__slots__ = []
def text_location(O, i):
sl, i = O.stmt_location(i)
if (i is not None and sl.stmt_offs is not None):
i += sl.stmt_offs
return sl, i
def format_error(O, i, msg, prefix=""):
sl, i = O.stmt_location(i)
from libtbx.str_utils import expandtabs_track_columns
t, js = expandtabs_track_columns(s=sl.text)
if (i is None):
ptr = ""
else:
if (i < 0):
j = -i - 1
t += " " * (j - len(t) + 1)
else:
j = js[sl.stmt_offs + i]
ptr = "\n" + "-"*(3+j) + "^"
if (msg is None): intro = ""
else: intro = "%s:\n at " % msg
result = "%s%s:\n |%s|%s" % (
intro, sl.format_file_name_and_line_number(), t, ptr)
if (prefix is None or prefix == ""):
return result
return "\n".join([(prefix + line).rstrip()
for line in result.splitlines()])
def raise_error(O, msg, i=None, ErrorType=None):
if (ErrorType is None): ErrorType = Error
raise ErrorType(O.format_error(i=i, msg=msg))
def raise_syntax_error(O, i=None):
O.raise_error(msg="Syntax error", i=i)
def raise_syntax_error_or_not_implemented(O, i=None):
O.raise_error(msg="Syntax error or not implemented", i=i)
def raise_semantic_error(O, msg=None, i=None):
O.raise_error(msg=msg, i=i, ErrorType=SemanticError)
def raise_internal_error(O, i=None):
O.raise_error(
msg="Sorry: fable internal error", i=i, ErrorType=AssertionError)
class source_line(raise_errors_mixin):
__slots__ = [
"global_line_index",
"file_name",
"line_number",
"text",
"label",
"stmt",
"stmt_offs",
"is_cont",
"index_of_exclamation_mark"]
def format_file_name_and_line_number(O):
return "%s(%d)" % (O.file_name, O.line_number)
def stmt_location(O, i):
return O, i
def __init__(O, global_line_index_generator, file_name, line_number, text):
O.global_line_index = global_line_index_generator.next()
O.file_name = file_name
O.line_number = line_number
O.text = text
O.label = None
O.stmt = ""
O.stmt_offs = None
i = text.find("\t", 0, 6)
if (i >= 0):
soff = i + 1
O.is_cont = False
l = text[:i].strip()
s = text[soff:72]
else:
soff = 6
c = text[5:6]
O.is_cont = (c != " " and c != "\t" and c != "")
l = text[:5].strip()
s = text[6:72]
if (len(l) == 0):
if (len(s) != 0):
O.stmt = s
O.stmt_offs = soff
else:
i = unsigned_integer_scan(code=l)
if (i < 0 or i != len(l)):
O.is_cont = False
else:
if (O.is_cont):
O.raise_error(
msg="A continuation character is illegal on a line with"
" a statement label",
i=-6)
O.label = l
if (len(s) == 0):
O.raise_error(msg="Labelled statement is empty", i=-7)
O.stmt = s
O.stmt_offs = soff
if (not O.is_cont and len(O.stmt.rstrip()) == 0):
O.stmt_offs = None
O.index_of_exclamation_mark = None
class stripped_source_line(raise_errors_mixin):
__slots__ = [
"source_line_cluster",
"label",
"code0_locations",
"start",
"code",
"strings",
"strings_locs",
"string_indices"]
def __init__(O,
source_line_cluster,
code0_locations,
code,
start,
strings,
strings_locs,
string_indices):
if (source_line_cluster is None):
assert code0_locations is None
else:
assert len(source_line_cluster) != 0
assert len(code0_locations) >= start + len(code)
assert len(strings) == len(string_indices)
O.source_line_cluster = source_line_cluster
O.label = None
for sl in O.source_line_cluster:
if (sl.label is not None):
O.label = sl.label
break
O.code0_locations = code0_locations
O.start = start
O.code = code
O.strings = strings
O.strings_locs = strings_locs
O.string_indices = string_indices
def code_with_strings(O):
result = []
j = 0
for c in O.code:
if (c == "'"):
result.append("'" + O.strings[j].replace("'","''") + "'")
j += 1
else:
result.append(c)
assert j == len(O.strings)
return "".join(result)
def stmt_location(O, i):
if (i is None):
return O.source_line_cluster[0], None
if (i < 0):
return O.source_line_cluster[0], i
return O.code0_locations[O.start + i]
def is_comment(O):
return (O.source_line_cluster[0].stmt_offs is None)
def __getitem__(O, key):
if (isinstance(key, slice)):
start, stop, step = key.indices(len(O.code))
assert step == 1
del step
else:
start = key
stop = key + 1
slice_strings = []
slice_strings_locs = []
slice_string_indices = []
for s,locs,si in zip(O.strings, O.strings_locs, O.string_indices):
if (si < start): continue
if (si >= stop): break
slice_strings.append(s)
slice_strings_locs.append(locs)
slice_string_indices.append(si-start)
return stripped_source_line_slice(
source_line_cluster=O.source_line_cluster,
code0_locations=O.code0_locations,
start=O.start+start,
code=O.code[key],
strings=slice_strings,
strings_locs=slice_strings_locs,
string_indices=slice_string_indices)
def raise_if_not_identifier(O):
i = identifier_scan(code=O.code)
if (i < 0 or i != len(O.code)):
O.raise_error("Not an identifier: %s" % repr(O.code), i=0)
def extract_identifier(O):
O.raise_if_not_identifier()
return O.code
def index_of_closing_parenthesis(O, start=0):
i = find_closing_parenthesis(code=O.code, start=start)
if (i < 0):
O.raise_error(msg='Missing a closing ")"', i=max(0, start-1))
return i
def comma_scan(O, start=0):
code = O.code
n = len(code)
i = start
while (i < n):
c = code[i]
if (c == ","):
return i
i += 1
if (c == "("):
i = O.index_of_closing_parenthesis(start=i) + 1
return -1
def get_hollerith_count_index(code):
i = len(code)
while (i != 0):
i -= 1
c = code[i]
digit = "0123456789".find(c)
if (digit < 0):
if (i+1 == len(code)):
return None
if (",(/$".find(c) >= 0):
return i+1
return None
return None
class stripped_source_line_slice(stripped_source_line):
__slots__ = stripped_source_line.__slots__
def strip_spaces_separate_strings(source_line_cluster):
code = []
locs = []
strings = []
strings_locs = []
string_indices = []
ca = code.append
la = locs.append
n_sl = len(source_line_cluster)
i_sl = 0
while (i_sl < n_sl):
sl = source_line_cluster[i_sl]
s = sl.stmt
n = len(s)
i = 0
while (i < n):
c = s[i]
if (c == "!"):
sl.index_of_exclamation_mark = i
break
if (c == "'" or c == '"'):
opening_quote = c
string_indices.append(len(code))
ca("'")
la((sl,i))
i += 1
string_chars = []
string_chars_locs = []
in_string = True
while in_string:
while (i < n):
c = s[i]
ci = i
i += 1
if (c == opening_quote):
if (not s.startswith(opening_quote, i)):
in_string = False
break
i += 1
string_chars.append(c)
string_chars_locs.append((sl,ci))
else:
i_sl += 1
if (i_sl == n_sl):
locs[-1][0].raise_error(
msg="Missing terminating %s character" % opening_quote,
i=locs[-1][1])
sl = source_line_cluster[i_sl]
s = sl.stmt
n = len(s)
i = 0
strings.append("".join(string_chars))
strings_locs.append(string_chars_locs)
elif (" \t".find(c) < 0):
c = c.lower()
if (c == 'h'):
j = get_hollerith_count_index(code)
else:
j = None
if (j is None):
ca(c.lower())
la((sl,i))
i += 1
else:
hollerith_count = int("".join(code[j:]))
del code[j:]
del locs[j:]
string_indices.append(len(code))
ca("'")
la((sl,i))
i += 1
string_chars = []
string_chars_locs = []
while True:
if (i < n):
string_chars.append(s[i])
string_chars_locs.append((sl,i))
i += 1
if (len(string_chars) == hollerith_count):
break
else:
i_sl += 1
if (i_sl == n_sl):
break
sl = source_line_cluster[i_sl]
s = sl.stmt
n = len(s)
i = 0
if (len(string_chars) != hollerith_count):
locs[-1][0].raise_error(
msg="Missing characters for Hollerith constant",
i=locs[-1][1])
strings.append("".join(string_chars))
strings_locs.append(string_chars_locs)
else:
i += 1
i_sl += 1
return stripped_source_line(
source_line_cluster=source_line_cluster,
code0_locations=locs,
code="".join(code),
start=0,
strings=strings,
strings_locs=strings_locs,
string_indices=string_indices)
class fmt_string_stripped(raise_errors_mixin):
__slots__ = ["code", "locs", "strings", "strings_locs", "string_indices"]
def __init__(O, fmt_tok):
ssl = fmt_tok.ssl
i = ssl.string_indices.index(fmt_tok.i_code)
fmt_string = ssl.strings[i]
fmt_string_locs = ssl.strings_locs[i]
assert len(fmt_string) == len(fmt_string_locs)
code = []
O.locs = []
O.strings = []
O.strings_locs = []
O.string_indices = []
ca = code.append
la = O.locs.append
n = len(fmt_string)
have_leading_parenthesis = False
i = 0
while (i < n):
c = fmt_string[i]
loc = fmt_string_locs[i]
if (c == "'" or c == '"'):
if (not have_leading_parenthesis):
raise_must_start()
opening_quote = c
O.string_indices.append(len(code))
ca("'")
la(loc)
i += 1
string_chars = []
string_chars_locs = []
in_string = True
while in_string:
while (i < n):
c = fmt_string[i]
loc = fmt_string_locs[i]
i += 1
if (c == opening_quote):
if (not fmt_string.startswith(opening_quote, i)):
in_string = False
break
i += 1
string_chars.append(c)
string_chars_locs.append(loc)
else:
loc = O.locs[-1]
loc[0].raise_error(
msg='Missing terminating %s within character format'
' specifier "%s"' % (opening_quote, fmt_string),
i=loc[1])
O.strings.append("".join(string_chars))
O.strings_locs.append(string_chars_locs)
else:
if (" \t".find(c) < 0):
if (have_leading_parenthesis):
ca(c.lower())
la(loc)
else:
if (c != "("):
raise_must_start()
have_leading_parenthesis = True
i += 1
def raise_must_start():
fmt_tok.raise_error(msg='Format string must start with "("')
def raise_must_end():
fmt_tok.raise_error(msg='Format string must end with ")"')
if (len(code) == 0):
if (have_leading_parenthesis):
raise_must_end()
raise_must_start()
elif (code[-1] != ")"):
raise_must_end()
code.pop()
O.locs.pop()
O.code = "".join(code)
def stmt_location(O, i):
if (i is None): i = 0
return O.locs[i]
def combine_continuation_lines_and_strip_spaces(source_lines):
result = []
rapp = result.append
n_sl = len(source_lines)
i_sl = 0
while (i_sl < n_sl):
sl = source_lines[i_sl]
if (sl.stmt_offs is None):
rapp(strip_spaces_separate_strings(source_line_cluster=[sl]))
i_sl += 1
else:
assert not sl.is_cont
code_sls = [sl]
k_sl = i_sl
for j_sl in xrange(i_sl+1, n_sl):
sl = source_lines[j_sl]
if (sl.is_cont):
code_sls.append(sl)
k_sl = j_sl
elif (sl.stmt_offs is not None):
break
for j_sl in xrange(i_sl+1, k_sl):
sl = source_lines[j_sl]
if (not sl.is_cont):
rapp(strip_spaces_separate_strings(source_line_cluster=[sl]))
rapp(strip_spaces_separate_strings(source_line_cluster=code_sls))
i_sl = k_sl + 1
return result
def load_includes(global_line_index_generator, stripped_source_lines):
import os.path as op
result = []
for ssl in stripped_source_lines:
if (ssl.code == "include'"):
assert len(ssl.strings) == 1
file_name = ssl.strings[0]
if (op.isabs(file_name)):
file_path = file_name
else:
sl = ssl.code0_locations[-1][0]
file_path = op.join(op.dirname(sl.file_name), file_name)
if (not op.isfile(file_path)):
ssl.raise_semantic_error(msg="Missing include file", i=7)
# TODO potential performance problem if deeply nested includes
result.extend(load(
global_line_index_generator=global_line_index_generator,
file_name=file_path))
else:
result.append(ssl)
return result
def load(global_line_index_generator, file_name, skip_load_includes=False):
source_lines = []
for i_line,line in enumerate(open(file_name).read().splitlines()):
source_lines.append(source_line(
global_line_index_generator=global_line_index_generator,
file_name=file_name,
line_number=i_line+1,
text=line))
stripped_source_lines = combine_continuation_lines_and_strip_spaces(
source_lines=source_lines)
if (skip_load_includes):
return stripped_source_lines
return load_includes(
global_line_index_generator=global_line_index_generator,
stripped_source_lines=stripped_source_lines)
def tokenize_expression(
ssl,
start=0,
stop=None,
allow_commas=False,
allow_equal_signs=False):
result = []
if (stop is None): stop = len(ssl.code)
tokenize_expression_impl(
tokens=result,
tokenizer=tokenization.ssl_iterator(ssl=ssl, start=start, stop=stop),
allow_commas=allow_commas,
allow_equal_signs=allow_equal_signs,
tok_opening_parenthesis=None)
return result
def tokenize_expression_impl(
tokens,
tokenizer,
allow_commas,
allow_equal_signs,
tok_opening_parenthesis):
from tokenization import tk_seq, tk_parentheses
if (allow_commas):
tlist = []
tokens.append(tk_seq(ssl=tokenizer.ssl, i_code=tokenizer.i, value=tlist))
else:
tlist = tokens
tapp = tlist.append
for tok in tokenizer:
if (tok.is_op()):
tv = tok.value
if (tv == "("):
nested_tokens = []
tokenize_expression_impl(
tokens=nested_tokens,
tokenizer=tokenizer,
allow_commas=True,
allow_equal_signs=allow_equal_signs,
tok_opening_parenthesis=tok)
tapp(tk_parentheses(
ssl=tok.ssl, i_code=tok.i_code, value=nested_tokens))
continue
if (tv == ")"):
if (tok_opening_parenthesis is None):
tok.raise_missing_opening()
return
if (tv == ","):
if (not allow_commas):
tok.ssl.raise_syntax_error(i=tok.i_code)
tlist = []
tokens.append(tk_seq(
ssl=tokenizer.ssl, i_code=tokenizer.i, value=tlist))
tapp = tlist.append
continue
if (tv == "="):
if (not allow_equal_signs):
tok.ssl.raise_syntax_error(i=tok.i_code)
tapp(tok)
continue
tapp(tok)
continue
if (tok_opening_parenthesis is not None):
tok_opening_parenthesis.raise_missing_closing()
def indices_of_tokenized_equal_signs(tokens):
result = []
for i,tok in enumerate(tokens):
if (tok.is_op() and tok.value == "="):
result.append(i)
return result
# variable types
class vt_used(object): pass
class vt_scalar(object): pass
class vt_string(object): pass
class vt_array(object): pass
class vt_intrinsic(object): pass
class vt_external(object): pass
class vt_function(object): pass
class vt_subroutine(object): pass
# variable storage
class vs_fproc_name(object): pass
class vs_argument(object): pass
class vs_common(object): pass
class vs_save(object): pass
class vs_local(object): pass
class vs_parameter(object): pass
class fdecl_info(object):
__slots__ = [
"id_tok",
"var_type",
"var_storage",
"data_type",
"size_tokens",
"dim_tokens",
"parameter_assignment_tokens",
"f90_decl",
"is_modified",
"use_count",
"passed_as_arg",
"passed_as_arg_plain"]
def __init__(O,
id_tok,
var_type,
var_storage,
data_type,
size_tokens,
dim_tokens,
f90_decl=None):
assert size_tokens is None or isinstance(size_tokens, list)
assert dim_tokens is None or isinstance(dim_tokens, list)
O.id_tok = id_tok
O.var_type = var_type
O.var_storage = var_storage
O.data_type = data_type
O.size_tokens = size_tokens
O.dim_tokens = dim_tokens
O.parameter_assignment_tokens = None
O.f90_decl = f90_decl
O.is_modified = False
O.use_count = 0
O.passed_as_arg = {}
O.passed_as_arg_plain = {}
def is_used(O): return O.var_type is vt_used
def is_scalar(O): return O.var_type is vt_scalar
def is_string(O): return O.var_type is vt_string
def is_array(O): return O.var_type is vt_array
def is_intrinsic(O): return O.var_type is vt_intrinsic
def is_external(O): return O.var_type is vt_external
def is_function(O): return O.var_type is vt_function
def is_subroutine(O): return O.var_type is vt_subroutine
def is_user_defined_callable(O):
vt = O.var_type
return (vt is vt_external or vt is vt_function or vt is vt_subroutine)
def is_fproc_name(O): return O.var_storage is vs_fproc_name
def is_argument(O): return O.var_storage is vs_argument
def is_common(O): return O.var_storage is vs_common
def is_save(O): return O.var_storage is vs_save
def is_local(O): return O.var_storage is vs_local
def is_parameter(O): return O.var_storage is vs_parameter
def required_parameter_assignment_tokens(O):
result = O.parameter_assignment_tokens
if (result is None):
O.id_tok.raise_internal_error()
return result
def extract_size_tokens(ssl, start):
code = ssl.code
c = code[start]
if (c == "("):
i_clp = ssl.index_of_closing_parenthesis(start=start+1)
return i_clp+1, tokenize_expression(
ssl=ssl,
start=start+1,
stop=i_clp)
i_size = unsigned_integer_scan(code=code, start=start)
if (i_size < 0):
ssl.raise_syntax_error(i=start)
return \
i_size, \
[tokenization.tk_integer(ssl=ssl, i_code=start, value=code[start:i_size])]
data_types = """\
byte
character
complex
doublecomplex
doubleprecision
integer
logical
real
""".splitlines()
def extract_data_type(ssl, start=0, optional=False):
sw = ssl.code.startswith
for data_type in data_types:
if (sw(data_type, start)):
return (
start + len(data_type),
tokenization.tk_identifier(ssl=ssl, i_code=start, value=data_type))
if (not optional):
ssl.raise_syntax_error()
return None, None
def extract_data_type_and_size(ssl, start=0, optional=False):
i_code, data_type = extract_data_type(
ssl=ssl, start=start, optional=optional)
if (optional and i_code is None):
return None, None, None
if (not ssl.code.startswith("*", i_code)):
return i_code, data_type, None
i_code, size_tokens = extract_size_tokens(ssl=ssl, start=i_code+1)
return i_code, data_type, size_tokens
def extract_f90_decl(ssl, start):
code = ssl.code
if (start == len(code)):
ssl.raise_syntax_error(i=start)
i_cc = code.find("::", start)
if (i_cc >= 0):
return i_cc+2, ssl[start:i_cc]
if (code.startswith("(", start)):
i_clp = ssl.index_of_closing_parenthesis(start=start+1)
return i_clp+1, ssl[start+1:i_clp]
return start, None
def extract_fdecl(
result,
ssl,
start,
data_type,
size_tokens,
allow_size,
f90_decl=None):
code = ssl.code
stop = len(code)
def parse_decl(start):
item_size_tokens = None
dim_tokens = None
i_id = identifier_scan(code=code, start=start)
if (i_id < 0):
ssl.raise_syntax_error(i=start)
i_code = i_id
while True:
if (i_code == stop):
break
c = code[i_code]
if (c == ","):
i_code += 1
break
if (c == "("):
if (dim_tokens is not None):
ssl.raise_syntax_error(i=i_code)
i_clp = ssl.index_of_closing_parenthesis(start=i_code+1)
dim_tokens = tokenize_expression(
ssl=ssl,
start=i_code+1,
stop=i_clp,
allow_commas=True)
i_code = i_clp + 1
elif (c == "*"):
if (not allow_size or item_size_tokens is not None):
ssl.raise_syntax_error(i=i_code)
i_code, item_size_tokens = extract_size_tokens(ssl=ssl, start=i_code+1)
else:
ssl.raise_syntax_error(i=i_code)
if (item_size_tokens is None):
item_size_tokens = size_tokens
result.append(fdecl_info(
id_tok=tokenization.tk_identifier(
ssl=ssl, i_code=start, value=code[start:i_id]),
var_type=None,
var_storage=None,
data_type=data_type,
size_tokens=item_size_tokens,
dim_tokens=dim_tokens,
f90_decl=f90_decl))
return i_code
if (ssl.code.startswith(",", start)):
start += 1
while (start < stop):
start = parse_decl(start=start)
def dimensions_are_simple(dim_tokens):
is_star = tokenization.tok_seq_is_star
for tok_seq in dim_tokens:
if (is_star(tok_seq=tok_seq)):
return False
for tok in tok_seq.value:
if (tok.is_op_with(value=":")):
return False
return True
def process_labels_list(ssl, start, stop, len_min, len_max):
if (start == stop):
ssl.raise_syntax_error(i=start)
result = []
code = ssl.code
i = start
while True:
if (len_max is not None and len(result) >= len_max):
ssl.raise_syntax_error(i=i)
j = unsigned_integer_scan(code=code, start=i, stop=stop)
if (j < 0):
ssl.raise_syntax_error(i=i)
result.append(
tokenization.tk_integer(ssl=ssl, i_code=i, value=code[i:j]))
if (j == stop):
break
if (code[j] != ","):
ssl.raise_syntax_error(i=j)
i = j + 1
if (len(result) < len_min):
ssl.raise_syntax_error(i=i)
return result
class executable_info(object):
__slots__ = []
def __init__(O, **ks):
O.key = O.__class__.__name__[3:]
O.ssl = ks["ssl"]
O.start = ks["start"]
for k,v in ks.items():
setattr(O, k, v)
def s4it(O, callback, tokens):
tokenization.search_for_id_tokens(
callback=callback, tokens=tokens, with_next_token=True)
def s4it_slots(O, callback, obj_with_slots):
for s in obj_with_slots.__slots__:
attr = getattr(obj_with_slots, s)
if (attr is not None):
O.s4it(callback, attr)
def set_is_modified(O, fdecl_by_identifier):
pass
def mksl(*names): return ("key", "ssl", "start") + names
class ei_allocate(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass # TODO
class ei_assign(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass # TODO
class ei_assignment(executable_info):
__slots__ = mksl("lhs_tokens", "rhs_tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.lhs_tokens)
O.s4it(callback, O.rhs_tokens)
def set_is_modified(O, fdecl_by_identifier):
assert len(O.lhs_tokens) != 0
id_tok = O.lhs_tokens[0]
if (not id_tok.is_identifier()):
id_tok.raise_syntax_error()
tf = fdecl_by_identifier.get(id_tok.value)
assert tf is not None
tf.is_modified = True
class ei_file_positioning(executable_info):
__slots__ = mksl("io_function", "alist")
def search_for_id_tokens(O, callback):
if (O.alist is not None):
O.s4it_slots(callback, O.alist)
class ei_call(executable_info):
__slots__ = mksl("subroutine_name", "arg_token")
def search_for_id_tokens(O, callback):
callback(O.subroutine_name, O.arg_token)
if (O.arg_token is not None):
O.s4it(callback, O.arg_token.value)
class ei_close(executable_info):
__slots__ = mksl("cllist")
def search_for_id_tokens(O, callback):
O.s4it_slots(callback, O.cllist)
class ei_continue(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_cycle(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_deallocate(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass # TODO
class ei_do(executable_info):
__slots__ = mksl("label", "id_tok", "tokens")
def search_for_id_tokens(O, callback):
callback(O.id_tok, None)
O.s4it(callback, O.tokens)
def set_is_modified(O, fdecl_by_identifier):
fdecl = fdecl_by_identifier[O.id_tok.value]
fdecl.is_modified = True
class ei_dowhile(executable_info):
__slots__ = mksl("label", "cond_tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.cond_tokens)
class ei_else(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_elseif_then(executable_info):
__slots__ = mksl("cond_tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.cond_tokens)
class ei_enddo(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_endif(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_entry(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass # TODO
class ei_exit(executable_info):
__slots__ = mksl()
def search_for_id_tokens(O, callback):
pass
class ei_goto(executable_info):
__slots__ = mksl("label")
def search_for_id_tokens(O, callback):
pass
class ei_goto_computed(executable_info):
__slots__ = mksl("labels", "tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.tokens)
class ei_if(executable_info):
__slots__ = mksl("cond_tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.cond_tokens)
class ei_if_then(executable_info):
__slots__ = mksl("cond_tokens")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.cond_tokens)
class ei_if_arithmetic(executable_info):
__slots__ = mksl("cond_tokens", "labels")
def search_for_id_tokens(O, callback):
O.s4it(callback, O.cond_tokens)
class ei_inquire(executable_info):
__slots__ = mksl("iuflist")
def search_for_id_tokens(O, callback):
O.s4it_slots(callback, O.iuflist)
class ei_open(executable_info):