@@ -383,6 +383,12 @@ class ActionStmt(AliasNode):
383383
384384class AcImpliedDo (AliasNode ):
385385 _fields_spec = ["acImpliedDo" ,"impliedDoVariable" ,"expression" ]
386+
387+ class SFExprList (AliasNode ):
388+ _fields_spec = ["expression" , "DOUBLECOLON" , "COLON" ]
389+
390+ class SubscriptTripletTail (AliasNode ):
391+ _fields_spec = ["expression" , "DOUBLECOLON" , "COLON" ]
386392
387393
388394
@@ -631,6 +637,10 @@ def visit_ActionStmt(self, node):
631637 return ActionStmt .from_spec (node )
632638 def visit_AcImpliedDo (self , node ):
633639 return AcImpliedDo .from_spec (node )
640+ def visit_SFExprList (self , node ):
641+ return SFExprList .from_spec (node )
642+ def visit_SubscriptTripletTail (self , node ):
643+ return SubscriptTripletTail .from_spec (node )
634644
635645class AstTransformer ():
636646 def __init__ (self , tree , code :str = None ,comments : str = None , env = None ):
@@ -642,7 +652,6 @@ def __init__(self, tree, code :str = None ,comments: str=None, env=None):
642652 self .type_env = Env (dict (list (TYPED_API .items ())), None )
643653 self .type_env ['arrays' ]= {}
644654 self .code : str = code
645- print (self .type_env ['arrays' ])
646655 if self .code :
647656 self .codelines = self .code .split ("\n " )
648657
@@ -1144,21 +1153,23 @@ def visit_typedeclarationstmt(self, node, typeSpec, entityDeclList, DOUBLECOLON,
11441153 if attrSpecSeq :
11451154 self .attr = {}
11461155 attr = self .visit (attrSpecSeq )
1147- if attr and "DIMENSION" in attr and "ALLOCATABLE" in attr and attr ["DIMENSION" ] == [":" ]:
1156+
1157+ #if attr and "DIMENSION" in attr and "ALLOCATABLE" in attr and attr["DIMENSION"] == [":"]:
1158+ if attr and ("allocatable" in attr or "ALLOCATABLE" in attr ):
11481159 typ = "list"
11491160 pseudo_type = ["list" , elemtype_ ]
11501161 else :
11511162 typ = elemtype_
11521163 pseudo_type = elemtype_
11531164 for j in names :
11541165 zj = {"type" :typ , "name" : str (j ["name" ]), "pseudo_type" :pseudo_type }
1155- if "dim" in j :
1166+ if "dim" in j and typ != "list" :
11561167 zj ["type" ] = "array"
11571168 zj ["dim" ] = j ["dim" ]
11581169 zj ["elts" ] = j ["elts" ]
11591170 zj ["pseudo_type" ] = ["array" , elemtype_ ]
11601171 self .type_env ['arrays' ].update ({zj ["name" ]: zj ["elts" ] })
1161- elif attr and "DIMENSION" in attr and "ALLOCATABLE" not in attr :
1172+ elif attr and "DIMENSION" in attr and ( "ALLOCATABLE" not in attr and "allocatable" not in attr ) :
11621173 zj ["type" ] = "array"
11631174 zj ["dim" ] = len (attr ["DIMENSION" ])
11641175 zj ["elts" ] = attr ["DIMENSION" ]
@@ -1172,8 +1183,8 @@ def visit_typedeclarationstmt(self, node, typeSpec, entityDeclList, DOUBLECOLON,
11721183 return res
11731184
11741185 def visit_attrspecseq (self , node , attrSpecSeq ,attrSpec ,comments , location ):
1175- if "DIMENSION" in dir (attrSpec ) : self .attr .update ({"DIMENSION" : self .visit (attrSpec .arraySpec )})
1176- elif "INTENT" in dir (attrSpec ): self .attr .update ({"INTENT" : self .visit (attrSpec .intentSpec )})
1186+ if ( "DIMENSION" in dir (attrSpec ) or "dimmension" in dir ( attrSpec ) ) : self .attr .update ({"DIMENSION" : self .visit (attrSpec .arraySpec )})
1187+ elif ( "INTENT" in dir (attrSpec ) or "intent" in dir ( attrSpec ) ): self .attr .update ({"INTENT" : self .visit (attrSpec .intentSpec )})
11771188 else : self .attr .update ({self .visit (attrSpec ):None })
11781189
11791190 if attrSpecSeq :
@@ -1241,17 +1252,17 @@ def visit_assignmentstmt(self, node, label, NAME, sFExprListRef, substringRange,
12411252 "value" : self .visit (expression ),
12421253 "pseudo_type" :"VOID" ,
12431254 "comments" :comments }
1244- if isinstance (res ["target" ]["pseudo_type" ], list ) and res ["target" ]["pseudo_type" ][0 ]== "array" and res ["value" ]["type " ] in ["int" , "float" , "str" , "bool" ]:
1245- type_ = res ["value" ]["type " ]
1246- res ["value" ] = {'type' : 'array' ,
1255+ if isinstance (res ["target" ]["pseudo_type" ], list ) and ( res ["target" ]["pseudo_type" ][0 ]== "array" or res [ "target" ][ "pseudo_type" ][ 0 ] == "list" ) and res ["value" ]["pseudo_type " ] in ["int" , "float" , "str" , "bool" ]:
1256+ type_ = res ["value" ]["pseudo_type " ]
1257+ res ["value" ] = {'type' : res [ "target" ][ "pseudo_type" ][ 0 ] ,
12471258 'elements' : {'type' : 'binary_op' ,
12481259 'op' : '*' ,
12491260 'left' : {'type' : 'list' ,
12501261 'pseudo_type' : ['list' , type_ ],
12511262 'elements' : [res ["value" ]]},
12521263 'right' : self .type_env ['arrays' ][res ["target" ]["name" ]],
12531264 'pseudo_type' : ['list' , type_ ]},
1254- 'pseudo_type' : [ 'array' , type_ ] }
1265+ 'pseudo_type' : type_ }
12551266 if self .recursive and str (NAME )== self .out :
12561267 return {"type" :"implicit_return" ,
12571268 "value" : res ["value" ],
@@ -1279,6 +1290,7 @@ def visit_sfexprlistref(self, node,sFExprList, commaSectionSubscript,comments, l
12791290 return self .visit (sFExprList )
12801291 else :
12811292 return self .translate_list (commaSectionSubscript )
1293+
12821294
12831295 def visit_expression (self , node , level5Expr , expression , definedBinaryOp , comments ,location ):
12841296 if definedBinaryOp :
@@ -1946,12 +1958,34 @@ def visit_sectionsubscriptlist(self, node,sectionSubscript, comments,location ):
19461958
19471959 def visit_sectionsubscript (self , node , expression ,subscriptTripletTail ,comments ,location ):
19481960 if expression :
1961+ res = self .visit (expression )
1962+ #print("uuuuuuuuu", res)
19491963 if subscriptTripletTail :
1950- pass
1964+ r = self .visit (subscriptTripletTail )
1965+ #print("uuuuuuuuu2", r)
1966+ if "args" in r and r ["colon" ]== 1 :
1967+ res2 = {"sliceindex" :[res , r ["args" ][0 ]]}
1968+ return res2
1969+ else :
1970+ print (f" visit_sectionsubscript not implemented at { location } " )
19511971 else :
1952- return self . visit ( expression )
1972+ return res
19531973 else :
19541974 return self .visit (subscriptTripletTail )
1975+
1976+ def visit_subscripttriplettail (self , node , expression , COLON , DOUBLECOLON , comments , location ):
1977+ if expression :
1978+ res = self .visit (expression )
1979+ if COLON :
1980+ if len (res )== 1 :
1981+ return {"args" :res , "colon" :1 }
1982+ else :
1983+ return {"args" :res , "colon" :2 }
1984+ elif DOUBLECOLON :
1985+ return {"args" :res , "colon" :3 }
1986+ else :
1987+ return {"colon" :3 }
1988+
19551989
19561990
19571991 def visit_functionarglist (self , node , functionArg , functionArgList ,sectionSubscriptList ,comments , location ):
@@ -2001,16 +2035,25 @@ def translate_func(self, name, args, location):
20012035 return z
20022036 id_type = self .type_env [name ]
20032037 if id_type and isinstance (id_type , list ):
2038+ args = args [0 ][0 ]
2039+ if "sliceindex" in args :
2040+ res = {'type' : 'sliceindex' ,
2041+ 'receiver' : {'type' : 'local' ,
2042+ 'name' : name ,
2043+ 'pseudo_type' : id_type },
2044+ 'message' : 'sliceindex' ,
2045+ 'args' : [args ["sliceindex" ][0 ],args ["sliceindex" ][1 ]],
2046+ 'pseudo_type' : id_type }
2047+ return res
20042048 return {'type' : 'index' ,
20052049 'sequence' : {'type' : 'local' ,
20062050 'name' : name ,
20072051 'pseudo_type' : id_type },
2008- 'index' : args [ 0 ][ 0 ] ,
2052+ 'index' : args ,
20092053 'pseudo_type' : id_type [- 1 ] }
20102054
20112055 else :
20122056 fname = name
2013- print (name , "jjhhhhhhhhh" )
20142057 c = self .type_env .top ['functions' ]
20152058 if fname in c :
20162059 pseudo_type = c [fname ][- 1 ]
@@ -2377,6 +2420,19 @@ def visit_arrayconstructor(self, node, OBRACKETSLASH, CBRACKETSLASH, acValueList
23772420 def visit_acimplieddo (self , node , acImpliedDo ,impliedDoVariable ,expression , comments , location ):
23782421 print ("akklll" , location )
23792422 return
2423+
2424+ def visit_sfexprlist (self , node , expression , COLON , DOUBLECOLON , comments , location ):
2425+ res = self .visit (expression )
2426+ if not COLON and not DOUBLECOLON :
2427+ return res
2428+ elif COLON and expression :
2429+ print ("uiiiiiiii" , "TODO" ) #TODO
2430+
2431+
2432+
2433+
2434+
2435+
23802436
23812437
23822438
0 commit comments