def test12(self): '''test named type pointer entry and lookup''' drvdType = fs.DrvdTypeDecl(['t'], [], [fs._NoInit('bar')]) self.typetab.getType(drvdType, self.symtab) drvdTypePtr = fs.DrvdTypeDecl(['t'], ['pointer'], [fs._NoInit('foo')]) typeid1 = self.typetab.getType(drvdTypePtr, self.symtab) typeid2 = self.typetab.lookupType(drvdTypePtr, self.symtab) ae(typeid1, self.typetab.type_counter - 1) ae(typeid1, typeid2)
def makeSubroutinizedMaxvalOrMinval(newUnit,aKey,aTypeClass,indent,aRanks): newUnit.uinfo = fs.SubroutineStmt(__makeNameImpl(aKey,aTypeClass,aRanks), ['a','r'], lead=indent) mods=[App('intent',['in'])] dArgs=[Zslice() for i in xrange(1,aRanks[0]+1)] if aRanks[0]>0 : mods.append(App('dimension',dArgs)) newUnit.decls.append(aTypeClass(None, mods, ['a'], lead=indent+' ')) newUnit.decls.append(aTypeClass(None, [App('intent',['out'])], ['r'], lead=indent+' ')) newUnit.decls.append(fs.IntegerStmt(None, None, [fs._NoInit(App('i',aRanks))], lead=indent+' ')) locVersion = (aKey=='maxval') and 'maxloc' \ or 'minloc' newUnit.execs.append(fs.AssignStmt('i', App(locVersion,['a']), lead=indent+' ')) newUnit.execs.append(fs.AssignStmt('r', App('a',[(App('i',[r])) for r in xrange(1,aRanks[0]+1)]), lead=indent+' ')) newUnit.end.append(fs.EndSubroutineStmt(lead=indent))
def convertFunctionOrEntryStmt(theStmt, theUnit): DebugManager.debug( 10 * '-' + '>' + 'called function2subroutine.convertFunctionOrEntryStmt on ' + str(theStmt)) if (not (isinstance(theStmt, fs.FunctionStmt) or isinstance(theStmt, fs.EntryStmt))): raise FunToSubError(sys._getframe().f_code.co_name + ': convertFunctionOrEntryStmt called for ' + str(theStmt)) if theStmt.result is None: outParam = fs._NoInit(theStmt.name.lower()) else: outParam = fs._NoInit(theStmt.result.lower()) args = [] for arg in theStmt.args: symtabEntry = theUnit.symtab.lookup_name(arg) if (symtabEntry and isinstance(symtabEntry.entryKind, SymtabEntry.FunctionEntryKind) and symtabEntry.origin == "dummy"): args.append(fe.copyExp(name_init + arg.lower())) else: args.append(fe.copyExp(arg)) args.append(outParam) name = name_init + theStmt.name.lower() if isinstance(theStmt, fs.FunctionStmt): convertedStmt = fs.SubroutineStmt(name, args, theStmt.qualifiers, lead=theStmt.lead) else: convertedStmt = fs.EntryStmt(name, args, lead=theStmt.lead) global ourConvertedScopedNameList scopedName = '' funUnitParent = theUnit.parent while (funUnitParent): scopedName = funUnitParent.uinfo.name + ':' + scopedName funUnitParent = funUnitParent.parent scopedName += theStmt.name ourConvertedScopedNameList.append(scopedName.lower()) if (wasReferencedBeforeSeen(scopedName)): raise FunToSubError( sys._getframe().f_code.co_name + ': function ' + theStmt.name + ' was referenced before we saw this definition and the reference was not subroutinized; try to move up the definition before the reference' ) return (outParam, convertedStmt)
def test4(self): 'decl with ! comment' ae = self.assertEquals a_ = self.assert_ l1 = 'real :: x(:) ! here comes the comment' f1 = Ffile.here(l1, True) ll = list(f1.lines) ae(repr(pps(ll[0].line)), repr(RealStmt([], [], [_NoInit(App('x', [':']))])))
def test9(self): '''test named type lookup''' drvdType = fs.DrvdTypeDecl(['t'], [], [fs._NoInit('bar')]) typeid1 = self.typetab.getType(drvdType, self.symtab) typeid2 = self.typetab.lookupType(drvdType, self.symtab) ae(typeid1, typeid2)
def test8(self): '''test named type entry''' drvdType = fs.DrvdTypeDecl(['t'], [], [fs._NoInit('bar')]) typeid = self.typetab.getType(drvdType, self.symtab) ae(typeid, 12)