def _makeFunctionSymtabEntry(aFunctionStmt, localSymtab): if aFunctionStmt.ty is not None: typeId = globalTypeTable.getType( aFunctionStmt.ty[0](aFunctionStmt.ty[1], [], []), localSymtab) else: typeId = None return SymtabEntry(SymtabEntry.FunctionEntryKind(), typetab_id=typeId)
def test4(self): 'scalar * range w open lbound' ae = self.assertEquals theTypeId = globalTypeTable.getType(RealStmt([],[],['x']),theSymtab) theSymtab.enter_name('x',SymtabEntry(SymtabEntry.VariableEntryKind, type=RealStmt,typetab_id=theTypeId)) stmt = 'real, dimension(2,3) :: y' ps = pps(stmt) theTypeId = globalTypeTable.getType(ps,theSymtab) theSymtab.enter_name('y', SymtabEntry(SymtabEntry.VariableEntryKind, type=RealStmt, dimensions=['2','3'], typetab_id=theTypeId)) e1 = ep('x * y(1,:2)') ae(str(expressionShape(e1,theSymtab,lineNumber=0)), str([Ops(':','1','2')]))
def _processExternalStmt(anExternalStmt, curr): localSymtab = curr.val.symtab DebugManager.debug('[Line ' + str(anExternalStmt.lineNumber) + ']: stmt2unit._processExternalStmt: called on "' + str(anExternalStmt) + '" with localSymtab ' + str(localSymtab)) for aProcedureName in anExternalStmt.procedureNames: try: theSymtabEntry = localSymtab.lookup_name(aProcedureName) if not theSymtabEntry: # first guess - assume it is an external subroutine newSymtabEntry = SymtabEntry( SymtabEntry.SubroutineEntryKind(), typetab_id=globalTypeTable.getType(anExternalStmt, localSymtab), origin='external') localSymtab.enter_name(aProcedureName, newSymtabEntry) DebugManager.debug( '\tprocedure NOT already present in symbol table -- adding ' + newSymtabEntry.debug(aProcedureName)) else: DebugManager.debug('\tprocedure already has SymtabEntry' + theSymtabEntry.debug(aProcedureName)) # if the entry has a type, we know it's a function newEntryKind = theSymtabEntry.typetab_id and SymtabEntry.FunctionEntryKind \ or SymtabEntry.SubroutineEntryKind theSymtabEntry.enterEntryKind(newEntryKind()) except SymtabError, e: # add lineNumber and symbol name to any SymtabError we encounter e.lineNumber = e.lineNumber or anExternalStmt.lineNumber e.symbolName = e.symbolName or aProcedureName raise e
def test1(self): 'scalar * subscripted array' ae = self.assertEquals theTypeId = globalTypeTable.getType(RealStmt([],[],['x']),theSymtab) theSymtab.enter_name('x',SymtabEntry(SymtabEntry.VariableEntryKind, type=RealStmt,typetab_id=theTypeId)) stmt = 'real, dimension(2,3) :: y' ps = pps(stmt) theTypeId = globalTypeTable.getType(ps,theSymtab) theSymtab.enter_name('y', SymtabEntry(SymtabEntry.VariableEntryKind, type=RealStmt, dimensions=['2','3'], typetab_id=theTypeId)) e1 = ep('x * y(1,:)') ae(expressionShape(e1,theSymtab,lineNumber=0), ['3'])
def _processTypedeclStmt(aTypeDeclStmt, curr): 'type declaration -- record type in symbol table' localSymtab = curr.val.symtab newType = (aTypeDeclStmt.__class__, aTypeDeclStmt.mod) newLength = None DebugManager.debug('[Line ' + str(aTypeDeclStmt.lineNumber) + ']: ' + sys._getframe().f_code.co_name + ' for ' + repr(aTypeDeclStmt) + ' with default dimensions ' + str(aTypeDeclStmt.dimension)) access = None inDrvdTypeDefn = curr.val._in_drvdType for anAttribute in aTypeDeclStmt.attrs: if isinstance( anAttribute, str) and anAttribute.lower() in Symtab.ourSpecificAccessKWs: access = anAttribute.lower() for aDecl in aTypeDeclStmt.decls: DebugManager.debug('\tProcessing decl ' + repr(aDecl) + ' ... ', newLine=False) (name, newDimensions) = typesep(aDecl, aTypeDeclStmt.dimension) if inDrvdTypeDefn: name = inDrvdTypeDefn + ":" + name try: # set the length for character statements if (aTypeDeclStmt.kw_str == 'character'): newLength = aTypeDeclStmt.mod and aTypeDeclStmt.mod[0] \ or 1 # extract the name and length for character declarations such as "character foo*7" if (isinstance(aDecl, fs._NoInit) or isinstance(aDecl, fs._AssignInit)): if (isinstance(aDecl.lhs, fe.Ops) and aDecl.lhs.op == '*'): DebugManager.debug( '(recognized as a character statement with asterisk length specification) ... ', newLine=False) name = aDecl.lhs.a1 newLength = aDecl.lhs.a2 theSymtabEntry = localSymtab.lookup_name_local(name) if isinstance(aDecl, fs._AssignInit): theTmpDeclStmt = aTypeDeclStmt.__class__( aTypeDeclStmt.get_mod(), aTypeDeclStmt.get_attrs(), [aDecl.lhs]) else: theTmpDeclStmt = aTypeDeclStmt.__class__( aTypeDeclStmt.get_mod(), aTypeDeclStmt.get_attrs(), [aDecl]) if theSymtabEntry: # already in symtab -> enter new information (taking exception to any conflicts) DebugManager.debug( 'decl "' + str(aDecl) + '" already present in local symbol table as ' + str(theSymtabEntry.debug(name))) theSymtabEntry.enterType(newType, localSymtab) if (theSymtabEntry.dimensions and (newDimensions is None)): theTmpDeclStmt.dimension = theSymtabEntry.dimensions else: theSymtabEntry.enterDimensions(newDimensions) theSymtabEntry.enterLength(newLength) if (isinstance(aDecl, fs._PointerInit) or isinstance(aDecl, fs._AssignInit) and localSymtab.isConstInit(aDecl.rhs)): theSymtabEntry.enterConstInit( localSymtab.getConstInit(aDecl.rhs)) if inDrvdTypeDefn: theSymtabEntry.enterDrvdTypeName(inDrvdTypeDefn) # for function/subroutine entries, also update this information in the parent symbol table if localSymtab.parent and theSymtabEntry.entryKind.__class__ in ( SymtabEntry.FunctionEntryKind, SymtabEntry.SubroutineEntryKind ) and not (theSymtabEntry.origin == 'external'): parentSymtabEntry = localSymtab.parent.lookup_name_local( name) if (not parentSymtabEntry): localSymtab.replicateEntry(name, 'local', name, localSymtab.parent, replicatingUp=True) DebugManager.debug( '[Line ' + str(aTypeDeclStmt.lineNumber) + ']: new PARENT unit symtab entry (see above)') else: localSymtab.augmentParentEntry(theSymtabEntry, parentSymtabEntry, name) DebugManager.debug( '[Line ' + str(aTypeDeclStmt.lineNumber) + ']: updated PARENT unit symtab entry ' + parentSymtabEntry.debug(name)) typetab_id = globalTypeTable.getType(theTmpDeclStmt, localSymtab) theSymtabEntry.typetab_id = typetab_id else: # no symtab entry -> create one if aTypeDeclStmt.parameter: newSymtabEntry = SymtabEntry( SymtabEntry.VariableEntryKind(), type=newType, dimensions=newDimensions, length=newLength, origin='local', access=access) else: newSymtabEntry = SymtabEntry( SymtabEntry.GenericEntryKind(), type=newType, dimensions=newDimensions, length=newLength, origin='local', access=access) if (isinstance(aDecl, fs._PointerInit) or isinstance(aDecl, fs._AssignInit) and localSymtab.isConstInit(aDecl.rhs)): newSymtabEntry.enterConstInit( localSymtab.getConstInit(aDecl.rhs)) elif aTypeDeclStmt.parameter and isinstance( aDecl, fs._AssignInit): newSymtabEntry.enterConstInit(aDecl.rhs) if inDrvdTypeDefn: newSymtabEntry.enterDrvdTypeName(inDrvdTypeDefn) localSymtab.enter_name(name, newSymtabEntry) typetab_id = globalTypeTable.getType(theTmpDeclStmt, localSymtab) newSymtabEntry.typetab_id = typetab_id DebugManager.debug( 'decl "' + str(aDecl) + '" NOT already present in symbol table => adding ' + str(newSymtabEntry.debug(name))) unitSymbolEntry = localSymtab.lookup_name_level(curr.val.name())[0] if (unitSymbolEntry and isinstance(unitSymbolEntry.entryKind, SymtabEntry.FunctionEntryKind) and unitSymbolEntry.genericInfo and unitSymbolEntry.genericInfo.genericName): genericSymbolEntry = localSymtab.lookup_name( unitSymbolEntry.genericInfo.genericName) if (genericSymbolEntry is None): raise SymtabError('cannot find generic ' + unitSymbolEntry.genericInfo.genericName + ' for specific ' + curr.val.name() + ' entry: ' + unitSymbolEntry.debug(curr.val.name())) if (genericSymbolEntry.genericInfo is None or (not curr.val.name().lower() in genericSymbolEntry.genericInfo.resolvableTo)): raise SymtabError( 'no info available for specific ' + curr.val.name() + ' in generic entry: ' + genericSymbolEntry.debug( unitSymbolEntry.genericInfo.genericName)) specificFormalArgs = localSymtab.lookup_name( unitSymbolEntry.genericInfo.genericName ).genericInfo.resolvableTo[curr.val.name().lower()] if (specificFormalArgs is None): raise SymtabError( 'no arguments set for specific ' + curr.val.name() + ' under generic ' + unitSymbolEntry.genericInfo.genericName + ' entry: ' + localSymtab.lookup_name( unitSymbolEntry.genericInfo.genericName).debug( unitSymbolEntry.genericInfo.genericName)) if name.lower() in specificFormalArgs: se = localSymtab.lookup_name_local(name) specificFormalArgs[name.lower()] = (se.typetab_id, se.dimensions) DebugManager.debug('recorded type in ' + str(id(specificFormalArgs)) + str(specificFormalArgs)) except SymtabError, e: # add lineNumber and symbol name to any SymtabError we encounter e.lineNumber = e.lineNumber or aTypeDeclStmt.lineNumber e.symbolName = e.symbolName or name raise e